如何在四边形的正面和背面放置不同的颜色 [英] How put different colors at front and back sides of quad

查看:66
本文介绍了如何在四边形的正面和背面放置不同的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上,我的问题在标题中.我对着色器和缓冲区使用了现代opengl"方法,但我想知道是否存在以一种四边形的两侧获得不同颜色的方法.

Actually, my question is in header. I use "modern opengl" approach with shaders and buffers and I wonder is it exist any way to get different colors on two sides of one quad.

所需结果(背面和正面)

推荐答案

GLSL提供了内置的gl_FrontFacing变量,该变量确定片段是朝前的片段还是朝后的片段(如果为true,则为true正面)例如如果是四边形正面的一部分或四边形背面的一部分.

GLSL provides the built-in gl_FrontFacing variable that determines if the fragment is a front-facing fragment or a back-facing fragment (is true if front facing) e.g. if it is a fragment of the front side of the quad or a fragment of the back side of the quad.

然后在片段着色器中,您可以检查此变量并为每个面方向设置相应的颜色:

Within the fragment shader you can then check for this variable and set the corresponding colors per face direction:

if(gl_FrontFacing)
{
    outColor = color1;
}
else    // Fragment is back facing fragment
{
    outColor = color2;
}

这篇关于如何在四边形的正面和背面放置不同的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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