Java中的frontcolor,顶点着色器和片段着色器中的gl_Color和gl_FrontColor之间是什么关系...

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 ?

解决方案

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 using glColor* calls or array data fetched by glColorPointer.

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值