torstai 29. maaliskuuta 2012

Gaussian blur for gles2.0

For box2dlights I needed soft shadows and initial guess was blur is the key. Problem was that Gaussian blur can be really heavy especially on mobile devices where GPU memory bandwith can be really low.
I tried many different tricks but it was just too slow. Thankfully I didn't sleep at signal processing lectures and I didn't wasted my time any of those brute force implemenations but instead used separated exis kernel from start. But for getting enough blur I needed at least 9x9 kernel which mean 18 samples and that was still too many. Then I found this efficient-gaussian-blur-with-linear-sampling and method was almoust fast enough but on some devices it just hit against brick wall(namely powerVR gpu's)
Then I realized that I need to calculate texture coordinates on vertex shader and pass those at varyings to prevent "dependant" texture reads on this problematic gpu's.
Full source of shader is here
Using it is really easy just pass fbo sizes as uniform and which pass is nex as another uniform. shader.setUniformf("dir", 1f, 0f); correspond a horizontal pass. This way you can use one shader for both pass and any fbo size without touching there shader code.
Gaussian blur is one basic post proces effect that is used everywhere I have used this shader with good results for basic blurring, bloom, SSAO, VSM,  2d water rendering.. etc. So it's really important have quality and performant shader for this.

Ei kommentteja:

Lähetä kommentti