PDA

View Full Version : Light position



Lee_Jennifer_82
11-08-2015, 01:13 PM
Suppose, I've defined models/ objects and light position in my program. Models will undergo modelview transformation and light position will undergo view transformation. Is it right?
Sometimes I also found light position directly defined in view or eye coordinate.
It would be good if some one explains a bit.
Thanks!

GClements
11-08-2015, 09:17 PM
Suppose, I've defined models/ objects and light position in my program. Models will undergo modelview transformation and light position will undergo view transformation. Is it right?
There is no "view" transformation, only model-view and projection.

A position passed to glLight(GL_POSITION) is transformed by the current model-view matrix, and the resulting eye-space position is stored and used for subsequent lighting calculations.

Lee_Jennifer_82
11-09-2015, 07:00 PM
Thank you! But sometimes models (objects) go through local transformation like rotation, scaling etc, before camera or view transformation, but in this case lights only need to go through camera/ view transformation. In this case we need to separate the two matrices. Isn't it?

GClements
11-09-2015, 11:34 PM
Thank you! But sometimes models (objects) go through local transformation like rotation, scaling etc, before camera or view transformation, but in this case lights only need to go through camera/ view transformation. In this case we need to separate the two matrices. Isn't it?
When using the legacy matrix functions, it's fairly typical to start by setting up the viewing transformation (i.e. the transformation from "world" space to eye space), then render the objects. If an object has any local transformations, these are bracketed by glPushMatrix() and glPopMatrix(), so that the basic viewing transformation is restored after each top-level object.

In that situation, a "world-space" light position can after the "view" transformation has been set but before rendering any objects.

It's also possible to treat a light as an object, or attach a light to an object. If the light position is set when additional transformations are in effect, those transformations will affect the transformation of the light position to eye space, i.e. the light's position will be interpreted in the coordinate system which is in effect at the time of the glLight() call.

However, you can't just set the light position while rendering the object to which it is attached, because you typically need to set all of the light positions before rendering any of the objects.