What I try is to calculate a light position in the space of normalized device coordinates.
For example: I have a light at position (5.0, 5.0f, -5.0, 0.0), which is behind the camera, but in coordinates before the perspecive projection. How is this light mapped in to post-perspective space (the space of normalized device coordinates)?
What I think is, that I just have to multiply this position with a projection matrix to get the correct position. But I guess that’s wrong. What do you guys think?
I hope some of you understand what I want.
First of all this light is not “behind the camera”. If you have the w-component set to 0.0 it’s a directional light. Compare your setting with the default below!
Check out the manual for glLightfv for GL_POSITION and it’s manipulation by matrices:
“The params parameter contains four integer or floating-point values that specify the position of the light in homogeneous object coordinates. Both integer and floating-point values are mapped directly. Neither integer nor floating-point values are clamped.
The position is transformed by the modelview matrix when glLight is called (just as if it were a point), and it is stored in eye coordinates. If the w component of the position is 0.0, the light is treated as a directional source. Diffuse and specular lighting calculations take the lights direction, but not its actual position, into account, and attenuation is disabled. Otherwise, diffuse and specular lighting calculations are based on the actual location of the light in eye coordinates, and attenuation is enabled. The default position is (0,0,1,0); thus, the default light source is directional, parallel to, and in the direction of the –z axis.”