Calculating the Normal Matrix

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 ...

Get Real-Time 3D Graphics with WebGL 2 - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.