Object Space Lightnig

Started by
4 comments, last by Lopez 17 years, 11 months ago
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?
Advertisement
Shouldn't you transform the light position with the INVERSE of object modelview matrix?
Cheers... How do I do that?
Quote:Original post by Lopez
Cheers... How do I do that?


Are you using GLSL? If so
uniform mat4 gl_ModelViewMatrixInverse;



HTH

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.

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.

This topic is closed to new replies.

Advertisement