顶点着色器和片段着色器中的 gl_Color 和 gl_FrontColor 之间的关系是什么
我有直通顶点和片段着色器。
顶点着色器
void main(void)
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
片段着色器
void main(void)
{
gl_FragColor = gl_Color;
}
它们产生空渲染(黑色而不是像glClearBuffer那样的背景色)。
如果我修改顶点着色器以将 gl_FrontColor 设置为 gl_Color,它会渲染未触及的 OpenGL 缓冲区...这是直通着色器的预期行为。
void main(void)
{
gl_FrontColor = gl_Color; //Added line
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
我很困惑,顶点着色器中的 gl_FrontColor 设置如何可以更改片段一中的 gl_Color 的值?我缺少什么?
I have pass-through vertex and fragment shaders.
vertex shader
void main(void)
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
fragment shader
void main(void)
{
gl_FragColor = gl_Color;
}
Those produce empty rendering (black not background color like glClearBuffer does).
If I modify the vertex shader to set the gl_FrontColor to gl_Color it does render untouched OpenGl buffer ... with is the expected behavior of pass-through shaders.
void main(void)
{
gl_FrontColor = gl_Color; //Added line
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
I am confused, how settings the gl_FrontColor in the vertex shader can change the value of the gl_Color in the fragment one ? What I am missing ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
gl_Color
在不同的地方有不同的含义。在顶点着色器中,
gl_Color
表示用户传递的主要每顶点颜色属性。这是使用glColor*
调用或由glColorPointer
获取的数组数据来设置的。在片段着色器中,
gl_Color
表示正在渲染的三角形面的插值颜色。请记住,三角形有正面和背面。如果启用面剔除,则不会渲染一种或另一种(或两者)的所有面。但是,如果关闭面剔除,则两侧都会被渲染。根据三角形的特定面具有不同的每个顶点输出值通常很有用。原色具有正面颜色和背面颜色,代表正面三角形和背面三角形的颜色。这些的顶点着色器输出是
gl_FrontColor
和gl_BackColor
。如果您正在进行双面渲染,则需要设置这两个值,以便片段着色器的
gl_Color
输入具有任何含义。如果你只做正面渲染,那么你只需要设置gl_FrontColor
即可。gl_Color
means different things in different places.In the vertex shader,
gl_Color
represents the primary per-vertex color attribute passed by the user. This is set usingglColor*
calls or array data fetched byglColorPointer
.In the fragment shader,
gl_Color
represents the interpolated color for the facing of the triangle being rendered. Remember that triangles have a front-face and a back-face. If you enable face culling, then all faces of one kind or the other (or both) are not rendered. However, if you turn off face culling, then both sides are rendered.It is often useful to have different per-vertex output values based on the particular facing of the triangle. The primary color has a front color and a back color, representing the color for front-facing triangles and back-facing triangles. The vertex shader outputs for these are
gl_FrontColor
andgl_BackColor
.If you are doing two-sided rendering, you will need to set both of these values in order for the fragment shader's
gl_Color
input to mean anything. If you are only doing front-face rendering, then you only need to setgl_FrontColor
.gl_Color 是您在源中传递给顶点的颜色,因此它是一个属性。
gl_FrontColor(以及 BackColor)是根据您看到的基元的哪一侧在片段着色器中设置 gl_Color 的变量。所以如果你看到前面的 gl_Color 将等于 gl_FrontColor...
gl_Color is the Color you passed in your source to the vertices, so it is an attribute.
gl_FrontColor (and also BackColor) are varyings that set the gl_Color in the fragmentshader depending on which side of the primitive you see. So if you see front gl_Color will be equal to gl_FrontColor...