I am working on a custom light shader for my terrain. I do already have the implemented the normal and diffuse texture and it is displayed correctly. But I do not understand how to calculate the light with the directional light source.
Currently I have this in my fragment shader. I did only paste the part calculating the light. lightPos is the same as g_LightPostion, directly passed from the vertex shader. If i replace it by vec3(0.0, 1.0, 0.0) it works correctly, including the normals.
vec2 light; if(lightPos.w == -1) //Directional Light light = computeLighting(normal, vec3(0.0, -1.0, 0.0), lightPos.xyz, 1.0, 0.0) ; else light = computeLighting(normal, vec3(0.0, -1.0, 0.0), vec3(0.0, 1.0, 0.0), 1.0, 0.0) ; gl_FragColor = diffuseColor * light.x;
This results in the following:
I don’t understand why this is happening.
Regarding the tutorial the .w value of the directional light should be -1. It obviously is because if it wasn’t the code with the light direction would not be called.
The xyz values should be the light’s direction. For any reason I don’t understand this isn’t happening as I expected it. Can someone please explain me where I went wrong in my thoughts?
EDIT: The black parts are from the viewport background, if I set the background to blue it is blue.