PDA

View Full Version : Blur: 3 passes



Utumno
12-01-2016, 05:35 AM
Hello OpenGL gurus,

OpenGL ES 3.0 here. I am trying to implement blurring.

AFAIK, the recommended approach is as follows:

1) render the scene as you would normally do, but to a offscreen texture
2) render a quad , textured with the texture we have just created in the previous step, using a 'empty' vertex shader and a fragment shader which applies a 'horizontal' blur. Direct this to another offscreen texture.
3) again, do the same like above, but blur vertically and direct the output to wherever it is supposed to end up to (in my case, the screen).

Fair enough, I think I understand. The doubt is, couldn't the 1)-2)-3) procedure above be sped up? To me , it looks like actually running a full shader program for steps 2) and 3) is overkill - we don't need to do any vertex shading then, all we actually need to do in both steps seems to be

1) set up input texture
2) set up the output (either another texture in case of 2) or screen in case of 3) )
3) send the blur kernel (1D array of weights adding up to 1.0 like [0.125,0.175,0.200,0.200,0.175,0.125] )
4) run a simple fragment shader on this texture which blurs either horizontally or vertically, depending on the step

Seems to me this would be an obvious simplification and speedup. Can we do that in OpenGL? Running only fragment shaders rather than the whole program?

GClements
12-01-2016, 06:00 AM
You can't eliminate the vertex shader, but for rendering a quad you're only dealing with four vertices, so the overhead is negligible.