# Object Space Lightnig

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

## 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 on other sites
Shouldn't you transform the light position with the INVERSE of object modelview matrix?

##### Share on other sites
Cheers... How do I do that?

##### Share on other sites
Quote:
 Original post by LopezCheers... How do I do that?

Are you using GLSL? If so
uniform mat4 gl_ModelViewMatrixInverse;

HTH

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

• 11
• 20
• 12
• 10
• 34
• ### Forum Statistics

• Total Topics
631399
• Total Posts
2999854
×