If you are not interested in finding out how we calculate the Normal matrix and just want the answer, feel free to jump to the end of this section. Otherwise, stick around to see some linear algebra in action!
Let's start with the mathematical definition of perpendicularity. Two vectors are perpendicular if their dot product is 0. In our example, this will be:
Here, S is the surface vector and can be calculated as the difference of two vertices, as shown in the diagram at the beginning of this section.
Let M be the Model-View matrix. We can use M to transform S as follows:
This is because S is the difference ...