Transforms, normals, and lighting
I have an object under the scale transformation <1,2,1>. The shape and location of the object is correct, but lighting is not. Specifically, the diffuse shading of the object appears to move when the camera rotates. When the scale is changed to <1,1,1> this does not occur.
I am doing the following in my code:
- Transform ray by inverse matrix of the transformation
- Test intersection
- Transform intersection point by transformation (return to world coordinates)
- Transform surface normal by inverse matrix
- Light as normal
The lighting model works fine, and the shape of the object is correct. The matrix math is fine. As near as I can tell, the problem is with the surface normal, but I can''t figure out what the problem IS. Any insight would be greatly appreciated!
Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]
If you are using OpenGL, scalling messes up with the normals, so you should glEnable(GL_NORMALIZE);
Height Map Editor
Height Map Editor
December 05, 2002 06:20 PM
See this thread: http://www.gamedev.net/community/forums/topic.asp?topic_id=124638
Unfortunately I''m using a custom rendering engine at the moment, so I can''t make use of DirectX or OpenGL. Transforming normals is a piece of cake with either one :-)
I''m now transforming the normal by the inverse transposed matrix as suggested in the thread linked to in the anonymous post above [thanks btw]. This seems to have some effect on the lighting but its still off. I did find a bug in the point->world transform code I was using, so now I''ll see if a similar problem is present in the normal->world transforms.
Thanks again for the input.
I''m now transforming the normal by the inverse transposed matrix as suggested in the thread linked to in the anonymous post above [thanks btw]. This seems to have some effect on the lighting but its still off. I did find a bug in the point->world transform code I was using, so now I''ll see if a similar problem is present in the normal->world transforms.
Thanks again for the input.
Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]
December 06, 2002 05:48 AM
>I''m now transforming the normal by the inverse transposed matrix as suggested in the thread...
But didn''t you transform the normal using the inverse matrix before? In that case I think you should try the transposed but non inverse matrix instead.
But didn''t you transform the normal using the inverse matrix before? In that case I think you should try the transposed but non inverse matrix instead.
quote:
Original post by Anonymous Poster
>I''m now transforming the normal by the inverse transposed matrix as suggested in the thread...
But didn''t you transform the normal using the inverse matrix before? In that case I think you should try the transposed but non inverse matrix instead.
Tried the transposed pure matrix; still the same incorrectness. I don''t know if the bug is actually in the transform code; I''m beginning to suspect that it is a sign issue somewhere else in the code, because it behaves like the normal is pointing the wrong way. Agh!
Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]
Someone mentioned the transpose and the inverse matrix... I assume they mean that the inverse of a rotation matrix is the transpose (correct). But that''s not the inverse of a scale matrix, the inverse is another scale matrix scale factors 1/x, 1/y, 1/z.
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
December 13, 2002 05:53 AM
>I assume they mean that the inverse of a rotation matrix is the transpose (correct).
No, that was not what was meant. The inverse of any (invertable) transformation matrix can be found using standard methods. The question was how to apply a transformation matrix to a normal vector.
No, that was not what was meant. The inverse of any (invertable) transformation matrix can be found using standard methods. The question was how to apply a transformation matrix to a normal vector.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement