OpenGL Normal Vector Transformation

Related Topics: OpenGL Transformation, Plane Equation

When lighting is enabled in OpenGL, the normal vectors are used to determine how much light is received at the specified vertex or surface. This lighting processing is performed at eye coordinate space, therefore, normal vectors in object coordinates are also transformed to eye coordinates with GL_MODELVIEW matrix.

However, normals vectors are transformed in different way as vertices do. We cannot simply multiply GL_MODELVIEW matrix and normal. Consider a normal vector (1,0,0) at vertex (0,0,0). If GL_MODELVIEW matrix is simply translating 2 unit up along Y-axis, then the vertex coordinates will be (0,2,0). But, the normal should be remain same as (1,0,0), not (1,2,0).

In order to understand how normal vectors are transformed to eye space, think the normals as coefficients of plane equations, which are perpendicular to the planes.

OpenGL Normal Vector
OpenGL Surface Normal Vector

Imagine a triangle polygon with 3 vertices; v1-v2-v3, and the normal of this surface is 4D normal vector as a homogeneous plane. (For Euclidean space, the normal is 3D normal vector.) If we think of the triangle as a homogeneous plane, then the plane equation becomes;
plane equation in 4D

Since 3 vertices lie on this plane, the plane equation is also true when we substitute these vertices to the equation. For example, for a vector on a plane, it satisfies;
a vector on plane equation

The equivalent matrix form of the plane equation is;
matrix form of plane equation

The plane equation is multiplying the transposed normal (nT) and the vertex together.
Now, we modify the above equation to acquire normal vector transformation formula by inserting GL_MODELVIEW matrix M-1M in between;
(The following equation is still equivalent to the above because M-1M is identity matrix.)
matrix form of plane equation

As you can see, the right part of the above equation view matrix is transforming vertex to eye space, and the left part normal transfor is going to be the normal vector in eye space because the plane equation is also transformed. It reads as "The transformed vertex view matrix lies on the transformed plane normal transform in eye coordinates space".

Therefore, transforming normal from object space to eye space with GL_MODELVIEW matrix M is;
Transforming Normal

Or, by converting pre-multiplication to post-multiplication form, we get;
Transforming normals

Hide Comments
comments powered by Disqus