Sign in to follow this  
Lopez

Object Space Lightnig

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
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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this