Wednesday, December 12, 2012

Normals and the World Inverse Transpose Matrix

On the last assignment and in the exam review, there was a question about the world inverse transpose matrix.  I perused a bunch of online material on this issue, and thought this discussion had a good explanation:
The purpose of transforming a normal by the world matrix is to rotate it so that it's a direction in world-space.  This is typically done by only using the 3x3 portion of the world matrix, since this includes all of the rotation data and none of translation (you don't want to translate a normal). 

The 3x3 portion of the matrix also can contain scaling data.  When it contains scaling data, the normal is scaled by the scaling factor.  As long as the scale is uniform (which means that xScale == yScale == zScale), the scaling is okay provided your normalize the resultant normal vector before using it.  However if the scale is non-uniform, this won't work.  The solution in the case of non-uniform scaling is to calculatate the inverse transpose outside the shader, pass it in, and then transform normals (and also tangents/bitangents, if necessary) by that matrix.

So in summary:  if you're using no scaling or uniform scaling in your world matrix you can use the world matrix, if you're using non-uniform scaling then you need to use the inverse transpose.
So, in part 4 of the last assignment, changing the scaling of the sphere to be non-uniform caused the normals to be incorrect until you used the inverse transpose world matrix instead of the world matrix.

Monday, December 10, 2012

Tutorial: Tuesday at 1pm

Our informal tutorial is going to be Tuesday at 1pm.  I will edit this post with a room as soon I have one.  Be sure to submit questions ahead of time so I can prepare the best answers possible. :)

Update: We will meet at my lab, 5317 HP, at 1pm.

Monday, December 3, 2012

Exam Review Tutorial

If you are interested in attending a review session, please fill in the poll linked to below.  Only choose times you know you can attend. I need at least five people to make it worthwhile.

Tutorial Scheduling Poll

Also, please submit questions or topics you would like to be covered in the tutorial so I can prepare good answers for you ahead of time.  You can submit as many times as you like, but be specific, and only ask the most important things (otherwise I'll run out of time to help you with them!).

Tutorial Questions Form