Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Help with beginner fragment shader code

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2012
    Posts
    2

    Help with beginner fragment shader code

    I am working through Jason McKesson's openGL tutorial and am having trouble with chapter 3 fragment shaders.
    http://arcsynthesis.org/gltut/Positi...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.

    Code :
    #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.

  2. #2
    Junior Member Newbie
    Join Date
    Mar 2012
    Posts
    2

    Re: Help with beginner fragment shader code


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •