I'm working on a post-processing GLSL (ES) fragment shader for 2D shock waves. It's easy to distort the texture a bit in a circle and it already works for single shock waves. Now I need support for multiple waves at the same time, my ideas:
1st idea: Do post-processing (bind FBO -> bind previous texture -> draw call) for every wave. Easy implementation, but a lot state changes and draw calls.
2nd idea: Add data texture with all information for all waves and a single uniform with the number waves, so I can do something like that:
uniform int count;
uniform sampler2D dataTex;
const float dataTexSize = 32;
[...]
vec4 pixel;
for(int i = 0; i < count; i++)
{
vec2 dataTexPos = vec2(i / dataTexSize, 0);
pixel += shockwave(texture2D(dataTex, dataTexPos));
}
pixel /= float(count);
[...]
But apparently GPUs don't like loops with a non-constant expression and the driver cannot unroll.
Is there a best practice to give shaders a "dynamic amount of work" ? My OpenGL version is 2.0 ES.