• Advertisement
Sign in to follow this  

Object Space Lightnig

This topic is 4296 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

HI, I've got some objects in a scene that use a shader for rendering. The object has it's own 4x4 modelview matrix. When I light the model in the shader, it's lit as if it were at the origin, and rotations aren't taken into account. I presume that i need to have the light in object space. I have tried multiplying the light position by thet objects modelview matrix, but this doesn't sseem to work - any ideas anyone?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Shouldn't you transform the light position with the INVERSE of object modelview matrix?

Share this post


Link to post
Share on other sites
Quote:
Original post by Lopez
Cheers... How do I do that?


Are you using GLSL? If so

uniform mat4 gl_ModelViewMatrixInverse;




HTH

Share this post


Link to post
Share on other sites

The model view matrix is transforming a vector from the object space to the world space.

So to get something from world space to the object space you need the inverse of the model view matrix. That'll transform a vector from the world space back to the object space.

You'll find source for inversing a matrix from the net.

Share this post


Link to post
Share on other sites
I've got the objects transform matrix from the tokamak rigid body, I calculate the inverse of that, and pass it to the vertex shader...



uniform mat4 matrix;
...

main()
...
vec4 mv_Vertex = gl_ModelViewMatrix * gl_Vertex;
vec4 lightEye = matrix * gl_LightSource[0].position;
vec4 lightVec =lightEye - mv_Vertex;
g_lightVec = lightVec * TBN_Matrix;
...






But the lighting still seems awry.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement