Search code examples
opengl-esshaderinvariants

What is an invariant varying in OpenGL Shader Language


I was reading the OpenGL ES 2 Shading Language specification (PDF), when I went through this code:

      invariant varying mediump vec3 Color;

I think understand the invariance concept, but the meaning of an "invariant varying" seems quite puzzling to me.

Can someone explain to me the meaning and why this is useful ?


Solution

  • invariant is a keyword to inform the shader optimiser that the optimiser should keep in mind that the output of the variable for the same input in 2 different times should be the same. Some optimisation usually gives different results in different times, based on many factors. This keyword will make sure optimiser avoids using those techniques in this particular variable.