void main(void)
{
vec4 clipCoord = glModelViewProjectionmatrix * gl_Vertex;
gl_Position = clipCoord;
gl_FrontColor = gl_Color;
vec3 ndc = clipCoord.xyz / clipCoord.w;
So the clipCoord
is just doing standard fixed pipeline transforms. Why do I divide by w
, and what do I get from this?
所以clipCoord只是在做标准的固定管道变换。为什么要除以w,从这里得到什么?
1 个解决方案
#1
35
W is the fourth coordinate of a three dimensional vertex; This vertex is called homogeneous vertex coordinate.
W是三维顶点的第四个坐标;这个顶点称为齐次顶点坐标。
In few words, the W component is a factor wich divide the other vector components. When W is 1.0, the homogeneous vertex coordinates are "normalized". To compare two vertices, you should normalize the W value to 1.0.
简而言之,W分量是一个分解其他向量分量的因子。当W为1.0时,齐次顶点坐标是“标准化的”。要比较两个顶点,应该将W值规范化为1.0。
Think to the vertex (1,1,1,1). Now increase the W value (w > 1.0). The normalized position is scaling! and it is going to the origin. Think to the vertex (1,1,1,1). Now decrease the W value (W < 1.0). The normalized position is going to an infinite point.
考虑顶点(1,1,1,1)现在增加W值(W > 1.0)。标准化的位置是缩放!它会到原点。考虑顶点(1,1,1,1)现在降低W值(W < 1.0)。归一化的位置是无限的。
Apart from scaling vertex coordinates, the W coordinate is necessary since you have to multiply a 4x4 matrix (the model view and/or the projection matrices) with a 4x1 matrix (the vertex).
除了缩放顶点坐标之外,W坐标是必要的,因为你必须用一个4x1矩阵(顶点)乘以4x4矩阵(模型视图和/或投影矩阵)。
Of course, the Red Book is the definite guide:
当然,红皮书是明确的指南:
红书附录
#1
35
W is the fourth coordinate of a three dimensional vertex; This vertex is called homogeneous vertex coordinate.
W是三维顶点的第四个坐标;这个顶点称为齐次顶点坐标。
In few words, the W component is a factor wich divide the other vector components. When W is 1.0, the homogeneous vertex coordinates are "normalized". To compare two vertices, you should normalize the W value to 1.0.
简而言之,W分量是一个分解其他向量分量的因子。当W为1.0时,齐次顶点坐标是“标准化的”。要比较两个顶点,应该将W值规范化为1.0。
Think to the vertex (1,1,1,1). Now increase the W value (w > 1.0). The normalized position is scaling! and it is going to the origin. Think to the vertex (1,1,1,1). Now decrease the W value (W < 1.0). The normalized position is going to an infinite point.
考虑顶点(1,1,1,1)现在增加W值(W > 1.0)。标准化的位置是缩放!它会到原点。考虑顶点(1,1,1,1)现在降低W值(W < 1.0)。归一化的位置是无限的。
Apart from scaling vertex coordinates, the W coordinate is necessary since you have to multiply a 4x4 matrix (the model view and/or the projection matrices) with a 4x1 matrix (the vertex).
除了缩放顶点坐标之外,W坐标是必要的,因为你必须用一个4x1矩阵(顶点)乘以4x4矩阵(模型视图和/或投影矩阵)。
Of course, the Red Book is the definite guide:
当然,红皮书是明确的指南:
红书附录