Transform point to light coordinates?

glBeatriz's icon

I'm running through some examples of the orange book (uberlight shader)
How do you do this in GLSL?

Transform a point into World Coordinates = gl_ModelViewMatrix * gl_Vertex; (right)?
Transform a point into Light Coordinates = .....?

I think I need to create a transformation matrix which converts the vectors from the identity matrix into the vectors of the light coordinates...?

efe's icon

I am not sure if i understand the question, something like this?
vec3 normals = normalize(gl_NormalMatrix * gl_Normal);
vec 3 lightDir = normalize(vec3(gl_LightSource[0].position));

and then get their dot product:
dot(normal, lightDir);

is that what you need?

Also remember that the view it is just a type of modeling applied to the eye coordinates.

glBeatriz's icon

Hi Emmanuel, thanks for your reply. No, what I'm looking for is how to obtain the transformation matrix to express vertices in "lighting space": that is,if I am not wrong, the identity matrix whose axes have the origin in the light source.

The same way that gl_Vertex is passed in the application in Model Coordinates, and gl_ModelViewMatrix transforms this vertex into World Coordinates, then Lighting Coordinates, how do you obtain this transformation matrix?

This uberlight shader from the orange book needs to express the points in lighting space...

efe's icon

Hey Bea:
I see. As far as I understand these are the only built-in uniforms that describe the transformation state of a matrix( with their inverse and transposition in the case of the first 4):
gl_ModelViewMatrix
gl_ModelViewProjectionMatrix
gl_ProjectionMatrix
gl_TextureMatrix[gl_MaxTextureCoords]
gl_NormalMatrix

check the struct that describes gl_LightSourceParameters, one of the members is the light position. Maybe on later implementations of glsl there is something to retrieve such coordinates, not sure about it.

For sure this seems to be a question for the openGL forum!

efe's icon