Sign in to follow this  

Bump mapping bump mapping

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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...??

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

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