我试图从6个点生成一个立方体(每个点代表一个边,然后2个额外值,如果它旋转到面向x或y轴,z轴不需要一个,因为它就像那样默认情况下)。当我尝试将gl_Position值乘以mat4旋转矩阵以使立方体的边正确旋转时出现问题。它甚至不会出现故障,它根本不会显示面(当我没有矩阵乘以值时会这样做。)
继承我的几何着色器:
layout(points) in;
layout(triangle_strip, max_vertices = 4) out;
in vec3 gFacePos[];
out vec2 texCoord;
mat4 xtrans = mat4( //rotate on the x axis
1.0, 0.0, 0.0, 0.0,
0.0, 0.0, -1.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 0.0, 1.0
);
mat4 ytrans = mat4( //rotate on y
0.0, 0.0, 1.0, 0.0,
0.0, 1.0, 0.0, 0.0,
-1.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 1.0
);
mat4 rtrans = (gFacePos[0].x * xtrans) + (gFacePos[0].y * ytrans); //figure out what the current point wants to rotate on
void main() { //this whole thing makes a square at the requested point
gl_Position = gl_in[0].gl_Position + vec4(-0.5, 0.5, 0.0, 0.0);
gl_Position *= rtrans; //these break it
texCoord = vec2(0.0, 0.0);
EmitVertex();
gl_Position = gl_in[0].gl_Position + vec4(0.5, 0.5, 0.0, 0.0);
gl_Position *= rtrans;
texCoord = vec2(1.0, 0.0);
EmitVertex();
gl_Position = gl_in[0].gl_Position + vec4(-0.5, -0.5, 0.0, 0.0);
gl_Position *= rtrans;
texCoord = vec2(0.0, 1.0);
EmitVertex();
gl_Position = gl_in[0].gl_Position + vec4(0.5, -0.5, 0.0, 0.0);
gl_Position *= rtrans;
texCoord = vec2(1.0, 1.0);
EmitVertex();
EndPrimitive();
}
片段和顶点非常标准(顶点上有一些基本的相机内容)。