OpenGL Blend Modes vs Shader Blending

polyclick picture polyclick · Jul 24, 2012 · Viewed 13k times · Source

I'm currently doing some research on OpenGL and Shaders but I can't seem to figure out if there are any fundamental differences between blending using the glBlendMode or writing your own blend modes in a shader.

What are the reasons to choose the former or the latter? Are there any performance bottlenecks by choosing the one over the other? Or is this just a matter of personal preference?

Answer

Tim picture Tim · Jul 24, 2012

Traditional blending with glBlendFunc can't be replicated in a shader. Blending requires sampling the destination framebuffer before modifying it, which isn't something that can be done on current hardware.

Currently you can only pass along a color, and choose one of a limited selection of blending modes (glBlendFunc/glBlendEquation) which will be applied by the GPU's rasterizer before writing to framebuffer.