Applying More Than One Shader Effect

Started by bogieman987, December 20, 2014, 20:08:31

Previous topic - Next topic

bogieman987

Hi,

I was wondering how exactly do I go about doing multiple effects, for eg: bloom, ao and aa in a single pass (I understand that some effects may require going through it again, but I mean so that a single frame is completely rendered with all effects applied).

I understand somewhat the use of a framebuffer and such, but when I do these, do I just render to the non default framebuffer, change shader program, render to non default framebuffer again (or seperate one), change shader program, render to non default framebuffer and so on until I've gone through all the shaders and effects?

I just never really knew how it works, tutorials always tend to show a single effect, not how to combine them.
Will soon be an Oracle Certified Associate :D

Kai

Hi,

I would say, it depends on the kind of shader effects you are doing.

There are basically only two kinds:
- Those that depend on values of adjacent pixels
- Those that only depend on the value of the "current" pixel

For example, a high-pass filter necessary for bloom belongs to the second kind.
Then, the gaussian blur filter applied afterwards belongs to the first.
For bloom, you would also most likely want to downsample the image before applying the high-pass and blur filters. This can simply be done with mipmapping generation without shaders.

The classification in "depends on adjacent pixels" and "does not depend on those" is useful, since a shader invocation of a fragment shader is with respect to the pixel/texel currently being computed.

In principle, you can compute any number of effects within the same pass and same framebuffer (FBO) and composite the results within the same shader.

But, for effects that depend on the values of adjacent pixels, you would want to store the result of that effect in a framebuffer.
This is because subsequent effects also requiring access to adjacent pixels want to sample those pixels again.
If you do not store the result of the first effect in a framebuffer, then you would need to compute the effect of the first shader for all accessed texels within the second shader again.

So, storing the result for the first effect will safe you compute resources at the cost of bandwidth.

When effects are independent of each other, such as doing high-pass filter and at the same time screen space ambient occlusion, you can use Multiple Render Targets (MRT) by binding multiple textures to your FBO and write the results of both effects to their respective textures.

Hope, that helps!
- Kai

EDIT: confused low-pass and high-pass (this always happens with me :-); also of course high-pass is "current texel only" and gaussian blur is "with adjacent texels", so corrected that above.

bogieman987

Thanks for the detailed answer, it has definitely helped.
Will soon be an Oracle Certified Associate :D