Sign in to follow this  
miminawewe

diffuse light calculation

Recommended Posts

miminawewe    121
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
miminawewe    121
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this