Bump mapping bump mapping

Started by
8 comments, last by Muncher 19 years, 4 months ago
Hi, why is it when moving around a bump-mapped poly/model with gluLookAt() it affects the lighting of the poly/model.... Cheers Paul
Advertisement
How are you sending your light data? are you using shaders/programs or GL_DOT3_RGB? we need more info before we can help

Twixn
I am Me...you cant argue with THAT can you!!!
do you render the light sources before camera movements? this may cause the problem. if not, please give more info..
+-+-+-+-+-STR
soz for the lack of info...

the deal is that im rendering a non moving world (which, for testing is just a cube) the light is fixed and is supplied to the cG shader that bump maps the world using normal maps. The thing is, that when i move around using gluLookAt, the shading on the object changes as i move... i have no idea why.
And yes, i am rendering the world before i move around

Paul
are u using the 'glstate' to get ur light data? as that pre-transforms the light position into viewspace...making it behave as u described if used in a shader 'as-is'.

Twixn
I am Me...you cant argue with THAT can you!!!
no, i'm actually not sure what glstate is. My light position (there is only 1) is just hardcoded as at position 0,20,0 this is then fed to the shader that transforms it into texture space to compute the lighting for each bump.

Should i be transforming the light position somehow??

Cheers for the help so far :)
Paul
i see the same problem with classic opengl lighting(not shader) when i was beginning opengl. that was because of my render order. so, i was using the camera matrix with lights. i change position of the locate_lights() function to after camera.look(); function and the problem has been solved. can it be a problem like this? try to push and pop matrices when you locate the lights.
maybe your cube position is changing? render a model(eg. a sphere) to the light position and see what happens...

and it may be a problem with shader...??
+-+-+-+-+-STR
The problem is that you need to do your calculations(compute the light vector) in the same space. I assume you transform the vertices with modelview, so they are in eye space. Meanwwhile, the light position (0,20,0) is in worldspace. When you move the camera, the vertex position changes, but the light pos stays fixed, and that's why the lighting changes.

When you compute the vertex-to-light vector, you need both the vertex and light pos to be in the same space. Just don't transform the vertices, so they will both (vertex&light pos) be in worldspace. Then, transform the calculated lightvector with the TBN matrix to get it in tangent space. The T,B,N vectors also need to be in world space. Of course,after that, you will transform the vertices with the MVP matrix to give correct output in the vertex shader.
Doh, i tried moving the lightPos into eye space, and although the results are a little better, the lighting still changes drastically when the camera moves.

Then i tried moving the positioning of the light to after the look() and marking its position with a point. The light does stay fixed in the same position when the camera moves, so thats not the problem... maybe i should post some code...

Paul
Ahhhh, got it!

Thanks to all your replies, i the light position and the vertex were in two different coordinate systems, exactly as mikeman said :) I reverted to lighting in object space and the problem went away :)

Cheers all! you rocks!
Muncher

This topic is closed to new replies.

Advertisement