Jump to content
  • Advertisement
Sign in to follow this  
MarkyMark

understanding glBlendFunc ops

This topic is 4827 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
You realize that, because the fragment shader can't read from the frame buffer, you can't actually do alpha blending in the shader?

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!