OpenGL Normal Vector Transformation



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 ofplane equations, which are perpendicular to the planes.

OpenGL Normal Vector
OpenGL Normal Vector

Imagine a triangle polygon with 3 vertices; v1-v2-v3, and the normal of this surface is as ahomogeneous plane.(For Euclidean space, the normal is .) If we think of the triangle as a homogeneous plane, then theplane 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 is also true when we substitute these vertices to the equation. For example, for, it satisfies;

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 matrixM-1M in between;
(the following equation is still equivalent to the above because M-1M is identity matrix.)

As you can see, the right part of the above equation is transforming vertex to eye space, and the left part is going to be 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 object space to eye space with GL_MODELVIEW matrixM is;
Transforming Normal

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

 

(因为 这里OpenGL 的 矩阵 与 向量的 乘法,是矩阵前面,如果是矩阵在后面的,就可以通过转置, 变会矩阵在前面的乘法 ,因为 OpenGL 矩阵乘法就是要 矩阵在前面,所以需要要把 后乘 的 变成 前 乘)

(AB)转置= B转置 * A转置

 

参考:

http://www.songho.ca/opengl/gl_normaltransform.html

 





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值