【发布时间】:2023-04-06 19:29:01
【问题描述】:
我正在阅读这些关于现代 OpenGL 的 tutorials。在教程 5 中,有一个练习可以在立方体之外绘制一个额外的三角形。我的理解是我可以重用相同的顶点着色器来绘制多个三角形(即立方体的三角形和一个额外的独立三角形)。我的问题是顶点着色器是
#version 330 core
// Input vertex data, different for all executions of this shader.
layout(location = 0) in vec3 vertexPosition_modelspace;
layout(location = 1) in vec3 vertexColor;
layout(location = 2) in vec3 vertexTriangle_modelspace;
// Output data ; will be interpolated for each fragment.
out vec3 fragmentColor;
// Values that stay constant for the whole mesh.
uniform mat4 MVP;
void main(){
// Output position of the vertex, in clip space : MVP * position
gl_Position = MVP * vec4(vertexPosition_modelspace,1); // Cube
//gl_Position = MVP * vec4(vertexTriangle_modelspace,1); // Triangle
// The color of each vertex will be interpolated
// to produce the color of each fragment
fragmentColor = vertexColor;
}
它只绘制了一个gl_Position 和最后一个。一个顶点着色器可以输出多个gl_Position吗?
【问题讨论】:
-
我假设你知道顶点着色器是为每个单独的顶点运行的,所以只需要输出一个位置。
-
@MohamadElghawi,谢谢。作为一种魅力。我走错方向了