transforming vertex normals

Started by
11 comments, last by chipmunk1886 20 years, 8 months ago
"A normal is a vector representing a plane." <-- we'll use this.

So I take "0.85355, -0.14645, 0.50000", a normal, which is a vector representing a plane. I plug those vector values in to the corresponding x, y, and z spots in an identity matrix (along the right hand side, as above), viola, I have a 4x4 matrix representation of that normal/vector.

Then I can rotate the normal through regular matrix transformation, resulting in a transformed normal. As long as I don't get it confused with regular 'worldspace' vectors, and handle it properly, it should be fine, afaik.

Basically, my thinking is, if it is a vector in any sense, I can transform it like a vector.

As I said, I know there is a better way to do this, but that's for somebody else to tell me.

All tolled, it looks like the method that chipmunk is using is correct.

[edited by - wudan on August 19, 2003 9:43:57 AM]
Advertisement
I kinda see how you got there, but I'm not sure why.

Transformation of a point P by a 4X4 matrix M:

 P' = M * P [x']       [x] [y'] = M * [y] [z']       [z] [1]        [1] 


Transformation of a normal N by (e.g. the same) 4X4 matrix M:

 N' = (MT)-1 * N [x']        [x] [y'] = (MT)-1 * [y] [z']        [z] [0]         [0] 


(I might have the T,-1 inside out)

However, if M is orthogonal then MT = M-1
so (MT)-1 = M and you can do

 N' = M * N 


Which is what the OP was trying to do.


[edited by - JuNC on August 19, 2003 11:28:36 AM]
I haven''t read the whole thing but i guess what you might be doing wrong is transforming the normals using the same MV matrix that you are using for vertex transformationg. That''s wrong... i am sure someone have already mentioned it above... you should not TRANSLATE the normals. Only the rotational components of the MV matrix should be used.. ie. ONLY the top-left 3x3 part of the 4x4 matrix. Just leave out the last column and last row of the 4x4 matrix and use the remaining 3x3 matrix.

in OGL vertex shader this is achieved by

DP3 NormalVector.x NormalVector ModelViewMat[0]
DP3 NormalVector.y NormalVector ModelViewMat[1]
DP3 NormalVector.z NormalVector ModelViewMat[2]

Notice.. we r doing a DP3 (3 component dot product).
Z

This topic is closed to new replies.

Advertisement