View Full Version : Light vector for per-pixel lighting
12-30-2003, 12:10 PM
Hello my friends,
I'm starting to implement dot3 bump mapping, and things went almost well, except that every time the camera moves, the light does as well. My opinion for this is:
Since I'm using the model-view projection inverse to tranform my light vector from eye-space to object space, every camera change reflects on light vector.
Is this correct ?
In any case, how should I proceed to obtain correct per-pixel lighting for static positioned lights ?
Thanks in advance and sorry if this question is better suited for beginers forum
Domo Arigato gosaimasu
[This message has been edited by Arashikage (edited 01-04-2004).]
12-30-2003, 12:22 PM
My guess is that your computations are not all in the same space. You say you are doing bump mapping so I assume you have a normal map of some kind. So the question about that is, what space is your normal map in? Tangent space? Object space? etc? You mention that your light vector is being transformed into object space (oh btw, you should use the modelview inverse, NOT the modelview projection inverse for this). Now if your normal map is in tanget space, then you would have to take your object space light vector and transform it into tangent space. Computing the dot3 with a tangent space normal map and an object space light vector would give you some freaky results.
[This message has been edited by SirKnight (edited 12-30-2003).]
12-30-2003, 02:47 PM
Assuming your normal map is in tangent space (as they are normally), you have to do:
- compute the vector from the light to the vertex (or simply use the light vector if you do not have positional, but directional lights)
- transform this to tangent space, to do so, it first must be transformed to object space (modelview matrix), and inside of object space, transform it to the vertex' tangent space (tnb marix).
you might already know this:
but it is not at all affected by the camera position/projection matrix.
12-30-2003, 02:58 PM
hm I just thought: when positioning the camera with gluLookAt(...) has effect on the modelview matrix, then, using this matrix for computing the object space vector simply is not the right way. OR you have to do so BEFORE calling gluLookAt() (or whatever you do to place the camera):
then it should be working.
Or you do not use the modelview matrix of OpenGL but use your own, which only contains the postion of the object in the world, and neglecting the camera position.
01-04-2004, 01:24 PM
Thanks for the replies my friends. Now things work fine. I just shouldn't use the multiplication i was doing(i was wrong on the previous post, i was mult. by inverse modelview only). I can transform light vector to Tangent space without it.
Thanks once more !
Domo arigato !
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.