#### Archived

This topic is now archived and is closed to further replies.

# Transforming normals in a vertex shader

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

## Recommended Posts

#c[0-3]  = modelview-projection matrix
#c[4-7]  = modelview inverse transpose
#c[8-11]  = modelview

#Transform the vertex to clip space.
DP4	o[HPOS].x, c[0], v[OPOS];
DP4	o[HPOS].y, c[1], v[OPOS];
DP4	o[HPOS].z, c[2], v[OPOS];
DP4	o[HPOS].w, c[3], v[OPOS];

#Transform the vertex to eye space.
DP4	R4.x, c[8], v[OPOS];
DP4	R4.y, c[9], v[OPOS];
DP4	R4.z, c[10], v[OPOS];

#Transform the normal to eye space.
DP3	R0.x, c[4], v[NRML];
DP3	R0.y, c[5], v[NRML];
DP3	R0.z, c[6], v[NRML];

This from a vertex shader tutorial I found. I don''t understand why the vertex normal is being transformed by the the modelview matrix while the normal is being transformed by the inverse of the modelview matrix to bring them both into eyespace. Shouldn''t they both be transformed by the modelview matrix as is what happens when using conventional OpenGL?

##### Share on other sites
In fixed function pipeline normals are transformed by inverse transpose of modelview matrix. Look at paper "Mathematics Of PerPixel Lighting" by nVidia for a great explanation why this is so.

You should never let your fears become the boundaries of your dreams.

##### Share on other sites
This just isn''t making sense to me .

but just seems to defy logic (well, my logic anyway).

In the nvidia paper it says:

Translation: A doesn''t affect normal
Rotation : Is applied to normals just like it is to position
Scale : Affects normals the opposite of the way it affects position

If modelview matrix doesn''t contain any scaling just rotation and translation
why do I still have to use the inverse transpose of it when transforming normals?

Actually, isn''t the inverse transpose just the same as the original matrix when
dealing with rotation matrics?

Damn, I''m confused.

##### Share on other sites
When you don''t have any nonuniform scaling (and no translation) you can simply transform the vertex and the normal by the same matrix. In general you can do this iff M^T = M^-1, which is always true for rotations.

1. 1
2. 2
3. 3
4. 4
Rutin
11
5. 5

• 12
• 19
• 10
• 14
• 10
• ### Forum Statistics

• Total Topics
632666
• Total Posts
3007719
• ### Who's Online (See full list)

There are no registered users currently online

×