Skip to main content
GameDev.net gamedev.net
🔒 Locked

Object Space Lightnig

Started by Lopez May 17, 2006 at 6:45 AM 4 replies 650+ views
Original Post
Lopez
Lopez
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?
Lopez
Lopez
Cheers... How do I do that?
MARS_999
MARS_999
Quote:
Original post by Lopez
Cheers... How do I do that?


Are you using GLSL? If so
uniform mat4 gl_ModelViewMatrixInverse;



HTH
Demus79
Demus79

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.

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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.