Skip to main content
GameDev.net gamedev.net
🔒 Locked

diffuse light calculation

Started by miminawewe Feb 22, 2008 at 4:18 AM 0 replies 1k views
Original Post
miminawewe
miminawewe
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?
miminawewe
miminawewe
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.