I am working through Jason McKesson’s openGL tutorial and am having trouble with chapter 3 fragment shaders.
http://arcsynthesis.org/gltut/Positioning/Tut03%20Multiple%20Shaders.html
Currently a triangle is drawn and moves in a circle. The color changes gradually from white to green and then jumps to white again.
I am trying to make the color change smoothly to green and back.
Here is the modified frag shader.
#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 == 1.0f) myFlag = !myFlag; //this flag is not getting 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
}
I believe my problem is the conditional statement where my flag is set.
Please advise.