[英]how to reuse same vertex shader to draw different gl_Position
我正在阅读有关现代OpenGL的这些教程 。 在第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_Positions?
顶点着色器不渲染三角形。 或多维数据集。 管他呢。 他们只是在顶点上执行操作。 该顶点是否是三角形,线带,立方体,擎天柱等的一部分。 不在乎。
顶点着色器将一个顶点输入并写出一个顶点。 对象由多个顶点组成。 因此,当您发出渲染命令时,该命令中的每个顶点都会进入VS。 VS为接收到的每个顶点编写一个顶点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.