• Advertisement
Sign in to follow this  

diffuse light calculation

This topic is 3655 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Why isn't the lightPos[0] in the code below transformed by gl_ModelViewMatrix before the subtraction with the transformed vertex V in the vertex shader code below?
uniform vec3 lightPos[1];
...
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;

vec3 N = normalize(gl_NormalMatrix * gl_Normal);
vec4 V = glModelViewMatrix * gl_Vertex;
vec3 L = normalize(lightPos[0] - V.xyz);
...


Correct me if I'm wrong but isn't V in camera space while lightPos[0] is left in world space, thus wouldn't it be wrong to subtract the 2 values?

Share this post


Link to post
Share on other sites
Advertisement
I think lightPos[0] has already been transformed to view space as an optimization to prevent it from being redundantly calculated all the time in the vertex shader for each vertex. That was not mentioned in the code.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement