我正在将GL_POINTS输入到几何着色器中。从每一点来看,我都在创造一个简单的四边形。这是有效的,但是当我旋转我的View矩阵时,我也想要四边形旋转。
如果我使用直通顶点着色器,并设置我的几何着色器,如下所示:
void outputQuadFromPoint( vec4 pt ) {
float distanceX = 0.01; // OpenGL space
float distanceY = 0.01;
vec4 v1 = vec4( pt.x - distanceX, pt.y + distanceY, pt.z, 1.0 );
vec4 v2 = vec4( pt.x - distanceX, pt.y - distanceY, pt.z, 1.0 );
vec4 v3 = vec4( pt.x + distanceX, pt.y + distanceY, pt.z, 1.0 );
vec4 v4 = vec4( pt.x + distanceX, pt.y - distanceY, pt.z, 1.0 );
vec4 rv1 = Projection * View * v1;
vec4 rv2 = Projection * View * v2;
vec4 rv3 = Projection * View * v3;
vec4 rv4 = Projection * View * v4;
gl_Position = rv1;
EmitVertex();
...
EndPrimitive();
}
我一无所获。然而这是有效的(除了没有四轮旋转)。
void outputQuadFromPoint( vec4 pt ) {
float distanceX = 10.0; // screen space pixels
float distanceY = 10.0;
pt = Projection * View * pt;
vec4 v1 = vec4( pt.x - distanceX, pt.y + distanceY, pt.z, 1.0 );
vec4 v2 = vec4( pt.x - distanceX, pt.y - distanceY, pt.z, 1.0 );
vec4 v3 = vec4( pt.x + distanceX, pt.y + distanceY, pt.z, 1.0 );
vec4 v4 = vec4( pt.x + distanceX, pt.y - distanceY, pt.z, 1.0 );
gl_Position = v1;
EmitVertex();
...
EndPrimitive();
}
我知道我误解了一些东西,但为什么可以应用Projection&查看输入点的变换,然后计算四边形,但不计算GL空间中的四边形,然后应用屏幕变换?