Sign in to follow this  
MarkyMark

understanding glBlendFunc ops

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this