Derivation of OpenGL normal vector transformation matrix

Source: Internet
Author: User

When lighting was enabled in OpenGL, the normal vectors was used to determine how much light was received at the specified V Ertex or surface. This lighting processing was performed at the eye coordinate space, therefore, normal vectors in object coordinates was also TR Ansformed to eye coordinates with Gl_modelview matrix.

When the illumination function is activated in OpenGL, the normal vector determines how much light is received by the vertex or surface. The light treatment process is in eye coordinate space, so the normal vector also needs to be converted to the eye coordinate space using gl_modelview .


However, normals vectors is transformed in different the 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'll be (0,2,0). But the normal should is remain same as (1,0,0), not (1,2,0).

However, the normal vector and vertex, each transformation matrix is not exactly the same, can not be simply multiplied by Gl_modelview. For example, the vector vector (1,0,0) of vertex vertex (0,0,0), if the Gl_modelview matrix translates only two cells along the y-axis, the vertex coordinates become (0,2,0), but the normal vector remains (1,0,0) instead of (1,2,0).

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


OpenGL Normal Vector

Imagine a triangle polygon with 3 vertices; V1-v2-v3, and the normal of this surface is as a homogeneous plane. (for Euclidean space, the normal is.) If we think of the triangle as a homogeneous plane, then the plane equation becomes; (by replacing X, Y, Z to x/w, y/w, z/w, then multiplying w on both sides)

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

The equivalent matrix form of the plane equation is;

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

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

Therefore, transforming normal from the object space to the eye space with the Gl_modelview matrix M is;

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

Derivation of OpenGL normal vector transformation matrix

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.