fragment shader performance

I am developing a game for iPhone 5. I am seeing significant performance drop with few fragment shaders.

I simplified the problem with a test. I have couple of triangles with most simple vertex & fragment shaders possible.

I have 3 variations of fragment shader

  1. gl_FragColor = u_vCorlor; // uniform
  2. gl_FragColor = v_vColor; // varying
  3. gl_FragColor = gl_FragCoord;

    If #1 is the 100fps performance, #2 is 50% less performance and #3 is 75% less performance.

    There is significant performance concern with a small change in fragment shader. could someone please suggest how to optimize shaders?



Hi Deva,

1) gl_FragColor = u_vCorlor; // uniform

This will be very efficient, as the uniform value is known before the fragment shader is executed. The GPU merely needs to take the uniform value & assign it as the pixel's colour.

2) gl_FragColor = v_vColor; // varying

This operation is a little more expensive, as it relies on varying values to be interpolated before a value can be assigned as the pixel colour. However, this is still quite fast as varyings are calculated before the fragment shader is executed.

3) gl_FragColor = gl_FragCoord;

This operation is using a fragment specific value, which means it will only be executed when the fragment shader runs. This is why it's the slowest of the three examples you've given.

Once your fragment shaders are padded out with more work, I expect the differences between these variations to become negligible. Minimal tests like this have the tendency to highlight bottlenecks that would never be hit by most graphics applications as the GPU will be able to hide these very small latencies when it has more work to process.