我正在浏览http://arcsynthesis.org/gltut/Positioning/Tut03%20More%20Power%20To%20The%20Shaders.html上的教程
我目前正在学习创建一个三角形,将其沿圆形方向移动并逐渐将颜色从白色变为绿色。一个完整的循环后颜色会跳回白色。我试图使颜色逐渐从白色变为绿色并返回。我设置颜色更改方向的条件语句似乎永远不会评估为真,因此我的更改永远不会生效。
这是我的片段着色器。
#version 330
out vec4 outputColor;
uniform float fragLoopDuration; //5.0f
uniform float time;
const vec4 firstColor = vec4(1.0f, 1.0f, 1.0f, 1.0f);
const vec4 secondColor = vec4(0.0f, 1.0f, 0.0f, 1.0f);
void main()
{
bool myFlag = false; //flag will indicate which direction color change will take.
float currTime = mod(time, fragLoopDuration);
float currLerp = currTime / fragLoopDuration; //currLerp range = (0.0f-1.0f)
if (currLerp == 0.9f) myFlag = !myFlag; //this flag is not geting triggered.
if (myFlag) outputColor = mix(secondColor, firstColor, currLerp * -1.0f + 1.0f); //green to white
if (!myFlag) outputColor = mix(firstColor, secondColor, currLerp); //white to green
}