Below is a section from an online tutorial
The OpenGL specification states that when a light position is set it is automatically converted to eye space coordinates, i.e. camera coordinates. We can assume that the light position stays normalized when automatically converted to eye space. This will be true if we the upper left 3x3 sub matrix of the modelview matrix is orthogonal (this is ensured if we set the camera using gluLookAt, and we don’t use scales in our application).
The above “light position” means the direction of the light because it’s a drectional light. My question is even if we don’t use scale in the matrix, won’t the translation operation let the originaly normalized drection umnormalized?
My second question is that the normal specified by glNormal will be affected by the ModelView matrix?
thanks a lot~~!
AFAIK the normals will only change or be incorrect if you glScale on the polygons you are scaling and then you need to call glEnable(GL_RESCALE_NORMALIZE)
if you use uniform scaling (eg glScale(2,2,2)) then enable GL_RESCALE_NORMALIZE,
- if you use non-uniform scaling (eg glScale(1,4,2)) then enable GL_NORMALIZE.
The rescale_normalize will help OpenGL be faster due to uniform scaling of the normals where the non uniform scaling will take more math to rescale and hence longer to finish… For the light issue I dont’ know about that maybe someone else can help, but if you are asking if translating the lightposition will take it out normalized it shouldn’t but maybe it would if you were using your own matricies instead of OpenGL’s… Like I said don’t quote me on that Light portion someone else should help you out with that.
glScale(2,2,2) is uniform, because it scales the same value along every axis. (2,0,0) is not uniform, it scales by 2 along x, and it “scales by 0” along the other axes, so it’s really a projection
To answer the original questions:
A directional light has it’s w-component set to 0, so it is not affected by the translation part of the matrix (try multiplying the vector (x,y,z,0) with a matrix, you’ll see the translation parts get multiplied by 0).
The normals will be multiplied by the inverse transpose of the upper 3x3 part of the modelview matrix.
okay Overmind, I thought uniform has something to do with the magnitude so (2,0,0) would be divided by 2 because its magnitude is 2. I believed it because all normals have to be unit length.
thanks for that point.
Thanks a lot!! You guys really helped.