Sign in to follow this  

Dealing with normals

This topic is 3592 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

Hi everyone, I have a set of vertices and normals in my vertex declaration. In the shader, I apply some transformations to the vertices (translation + non-uniform scale). What do I need to do with my normals so they stay correct? I assume all I'd need to do is to apply the scale and normalize them again, is this correct? How would that be done? I was thinking of something like this: normalize(mul((float3x3)world, normal)); Is this correct? The float3x3 is there so I don't take translation into account.

Share this post


Link to post
Share on other sites
Technically, you should be multiplying your normals by the inverse transpose of the transformations you apply to the vertices. Whatever scale you apply to the model, this applies the inverse scale to the normals. The inverse transpose is the general solution, however you can probably "hack" in a solution that isolates rotation and scaling and does that manually so you don't have the calculate the inverse transpose directly. It's up to you.

Share this post


Link to post
Share on other sites
I understand what you need inverse matrices for (reversing the transformations), but why is the transposed matrix necessary?

Shouldn't my float3x3 work as well for this particular case where no rotation and shearing is applied?

Share this post


Link to post
Share on other sites
Quote:
Original post by FoxHunter2
I understand what you need inverse matrices for (reversing the transformations), but why is the transposed matrix necessary?

Shouldn't my float3x3 work as well for this particular case where no rotation and shearing is applied?


The reference that S1CA suggests explains everything, but here is the bottom line: the reason you need to compute the inverse transpose is that your transformation includes shearing.

If a transform contains only rotation and translation then the inverse transpose is the same as the original (as far as normals are concerned), so you you don't have to do anything.

If it contains uniform scaling, then you could remove the scaling and use the resulting matrix, or you could use the original and then normalize.

Share this post


Link to post
Share on other sites

This topic is 3592 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