This text isn't going to be long. The thing is, I was taught on this very subject in my Computer Science degree, called IDI (Interacció i Disseny d'Interfícies, "Interaction and Interface Design"), that in order to compute the dot product of the normal vector of the model's vertex and the directional vector from the vertex to the light source, one does an Inverse of transpose of the View matrix times Geometric Transformations matrix and apply it to the normal vector, then everything magically turns out well. Also, all the teachers always repeated one single sentence after introducing this: don't ask me why is it, it is maths. Well, I am a mathematician, innit! The logic behind it is much simpler than it looks like, after I put a moment on it and figured it out.
The thing is, we have:
And clearly doing a direct dot product between these would produce utter trash. So, that's why we need the inverse of the blah blah blah to come into play.
Let's define:
We essentially want to "reverse the VM and GT" to send the direction vector to the normal vector's Model Space, and make a dot product there. So we would like to do:
Now, how to "reverse the VM and GT" to the Direction to send that to the MS? Easy-peasy. Just multiply it to the inverses of VM and of GT:
Now we put it all back to the original dot product:
Since the transpose of the transpose is identity (and we are just able to group the \(VM\) and the \(GT\) to the left-side \(Normal\) because matrix multiplication is associative, which I find really beautiful):
This is already very similar to what we wanted, right? Just need one tiny last touch: the inverse of transpose equals to the transpose of the inverse for all invertible matrices. So,
From which we got the magical Inverse of the transpose of \(VM\) times \(GT\). Now if we do the dot product of this and the direction vector, we get exactly what we wanted. Math is fascinating, isn't it?
Time flies by as you're not taking action.
Click for another sentence