Skip to content Skip to sidebar Skip to footer

Directional Lighting Is Not Constant In Opengl Es 2.0/3.0

Problem: The direction of the directional light changes when the position of the object changes. I watched posts with a similar problem: Directional light in worldSpace is dependen

Solution 1:

The vector has to be multiplied to the matrix from the right. See GLSL Programming/Vector and Matrix Operations.

vec3 lightVector = lightDirection * mat3(u_vMatrix);

vec3 lightVector = mat3(u_vMatrix) * lightDirection;

If you want to dot the light calculations in view space, then the normal vecotr has to be transformed form object (model) space to view space by the model view matrix and the light direction hss to be transformed form world space to view space, by the view matrix. For instance:

voidmain() {
    vec3  modelViewNormal = mat3(u_mvMatrix) * a_normal;
    vec3  lightVector     = mat3(u_vMatrix) * lightDirection;
    float diffuseFactor   = max(dot(modelViewNormal, -lightVector), 0.0);

    // [...]
} 

Post a Comment for "Directional Lighting Is Not Constant In Opengl Es 2.0/3.0"