understanding glBlendFunc ops

Started by
3 comments, last by Promit 18 years, 11 months ago
Hi .I want to simulate some of the glBlendFunc operations in a fragment shader that I will be writing to tint the underlying texture(amongst other things), but I would like to know how they work , not least because it will make the process easier. What I don't understand from the documentation for glBlendFunc is how the source and destinitation scalefactors works as quoted below: GL_ONE............... S:(1,1,1,1)...D:(1,1,1,1) GL_SRC_COLOR..........S:(R s / k R , G s / k G , B s / k B , A s / k A ) D:(R s / k R , G s / k G , B s / k B , A s / k A ) where kR,kG,kB = max number of colours per channel. ( e.g 255 for 24 bit image ) etc... with the final equations being Rs = min(kr,RssR + Rd+dR) etc. GL_ONE is obvious enough since its just doing additive blending,but I don't understand the logic behind the calculation of the scale factors for the other blend funcs. Can someone enlighten me. Mark
Advertisement
http://uk.geocities.com/sloppyturds/stuff/opengl_blending.zip
You realize that, because the fragment shader can't read from the frame buffer, you can't actually do alpha blending in the shader?
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Quote:Original post by Promit
You realize that, because the fragment shader can't read from the frame buffer, you can't actually do alpha blending in the shader?



I intend to use a fragment shader with a texture copied from the framebuffer
using glCopyTexImage2D. Although I'm new to shaders, I've had a look
at some demos that do image processing in this way, which makes me think its
possible. Am I right.


Mark
Yeah, that will work, although it will be a bit more expensive.

Anyway, basically what you have in alpha blending is a source color and a destination color. Source is the incoming fragment, and Dest is what's in the framebuffer. So in this case, Source is what you would normally give as the color output, and Dest is the pixel that you look up from the shader. Blending simply involves combining these in various ways.

For example, ONE, ONE will make Result = 1 * Source + 1 * Dest. SRC_ALPHA, ONE_MINUS_SRC_ALPHA does Result = SourceAlpha * Source + (1 - SourceAlpha) * Dest. I don't really like how the documentation on OGL blending is written. This way of looking at it is far simpler and more intuitive.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.

This topic is closed to new replies.

Advertisement