Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining Light Coordinates

I took a Computer Graphics exam a couple of days ago which had extra credit question like the following:

A light can be defined in one of two ways. It can be defined in world coordinates, e.g. a street light, or in the viewer (eye coordinates), e.g., a head-lamp worn by a miner. In either case the viewpoint can freely change. Describe how the light should be transformed different in these two cases.

Since I won't get to see the results of this until after spring break, I thought I would ask here.

It seems like the analogies being used are misleading - could you not define a light source that is located at the viewers eye in world coordinates just as well as you could in eye coordinates? I've been doing some research on how OpenGL handles light, and it seems as though it always uses eye coordinates - the ModelView matrix would be applied to any light in world coordinates.

In that case the answer may just be that you would have to transform light defined in world coordinates into eye coordinates using something like the ModelView matrix, while light defined in eye coordinates would only need to be transformed by the projection matrix.

Then again I could be totally under thinking (or over thinking this).

Another thought I had is that it determines which way you render shadows, but that has more to do with the location of the light and its type (point, directional, emission, etc) than what coordinates it is represented in.

Any ideas?

like image 243
Zachary Wright Avatar asked Mar 11 '10 19:03

Zachary Wright


People also ask

What is glLightfv?

glLightfv(GL_LIGHT0, GL_POSITION, lightpos); This says that a light exists in the direction (0.5, 1., 1.). This is a vector.

How can we use lighting in OpenGL?

Enabling Lighting With OpenGL, you need to explicitly enable (or disable) lighting. If lighting isn't enabled, the current color is simply mapped onto the current vertex, and no calculations concerning normals, light sources, the lighting model, and material properties are performed.


2 Answers

The light's position is transformed by the modelview matrix that was active at the moment the light was defined.

If the modelview matrix was identity at that point, you'll get the light in eye coordinates.

If the modelview matrix was the inverse of your camera matrix, you'll get the light in world space.

like image 75
Thomas Avatar answered Oct 07 '22 19:10

Thomas


In the case of the street light, the world coordinates will stay constant when the viewpoint moves.

In the case of the head-lamp, the eye coordinates will stay constant when the viewpoint moves.

like image 43
Chris Lercher Avatar answered Oct 07 '22 18:10

Chris Lercher