9 Replies Latest reply on Jul 3, 2017 2:31 AM by dwitczak

    OpenGL - early return statement in FS doesn't work as expected

    einzuweitesfeld

      I have the following Fragment Shader:

       

      #version 450

      uniform int umsch;//umschalten

      layout(location = 0)   out vec4 Helligkeit;

       

      void main( void ){

        do {

          if(umsch != 0){

            Helligkeit = vec4(0.0, 1.0, 1.0, 1.0);

            return;

          }

          //break;

        } while(false);

        Helligkeit = vec4(0.5f);

        return;

      }

       

      where umsch a uniform variable that I can toggle via the OpenGL API by a keystroke.

       

      Now, if I'm not completely crazy then it shouldn't make a difference whether the break statement is there or not. But (in the FS) it does.

      When the break statement is uncommented then I can't achieve an early return from the FS. But early returns are allowed in the FS according to the GLSL spec.

      I can achieve the desired result if I toggle a flag inside the if body and check for it later.

       

      I have the most recent drivers and checked the code on an HD5870 and a RX480 card. My operating system is Windows 7 64bit.