顶点着色器和片段着色器中的gl_Color和gl_FrontColor之间是什么关系 [英] What is the relationship between gl_Color and gl_FrontColor in both vertex and fragment shaders

查看:664
本文介绍了顶点着色器和片段着色器中的gl_Color和gl_FrontColor之间是什么关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有传递顶点和片段着色器.

I have pass-through vertex and fragment shaders.

顶点着色器

void main(void)
{
    gl_TexCoord[0] = gl_MultiTexCoord0;
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}

片段着色器

void main(void)
{
    gl_FragColor = gl_Color;
}

那些产生空的渲染(黑色而不是像glClearBuffer那样的背景色).

Those produce empty rendering (black not background color like glClearBuffer does).

如果我修改顶点着色器以将gl_FrontColor设置为gl_Color,它的确会呈现不变的OpenGl缓冲区...这是传递着色器的预期行为.

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;
}

我很困惑,如何在顶点着色器中设置gl_FrontColor可以改变片段1中gl_Color的值?我想念的是什么?

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 ?

推荐答案

gl_Color在不同的地方表示不同的意思.

gl_Color means different things in different places.

在顶点着色器中,gl_Color表示用户传递的主要的每个顶点颜色属性.可以使用glColor*调用或glColorPointer获取的数组数据进行设置.

In the vertex shader, gl_Color represents the primary per-vertex color attribute passed by the user. This is set using glColor* calls or array data fetched by glColorPointer.

在片段着色器中,gl_Color表示要渲染的三角形的面的插值颜色.请记住,三角形具有正面和背面.如果启用脸部剔除,则不会渲染一种或另一种(或两者)的所有脸部.但是,如果关闭人脸剔除,则会同时渲染两面.

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.

基于三角形的特定面具有不同的每个顶点输出值通常很有用.原色具有正面颜色和背面颜色,代表正面三角形和背面三角形的颜色.这些顶点着色器的输出是gl_FrontColorgl_BackColor.

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 and gl_BackColor.

如果要进行双面渲染,则需要设置这两个值,以便片段着色器的gl_Color输入表示任何含义.如果只进行正面渲染,则只需设置gl_FrontColor.

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 set gl_FrontColor.

这篇关于顶点着色器和片段着色器中的gl_Color和gl_FrontColor之间是什么关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆