Jump to content
  • Advertisement
Sign in to follow this  
xerodsm

Silly Blending Question

This topic is 3650 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

I swear I've been searching... somehow I just can't get the solution. I'm making smoke for my game and I've got the masking to work just fine. I'm using: glBlendFunc(GL_DST_COLOR,GL_ZERO); // draw masked image and then glBlendFunc(GL_ZERO,GL_ZERO); // draw textured image But the problem is I want the smoke to fade with my alpha value. It seems to be ignoring the alpha value wherever I put it. I hope this makes sense. I want my smoke to be masked AND respond to alpha values so I can fade it in and out. Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
You're not actually telling the blending function to USE your alpha value anywhere. You have to put GL_SRC_ALPHA (or GL_DST_ALPHA, I guess) into one of those computations in order for alpha to be utilized.

Also, that second blend function doesn't draw anything, no? (Src0*0)+(Src1*0)=0

Share this post


Link to post
Share on other sites
You're totally right, that was my mistake, the second blend function is actually...

glBlendFunc(GL_ONE,GL_ONE);

And you're right about me not using my alpha value anywhere, my question is, where would I use it?

Like for the second part should I be using:
glBlendFunc(GL_ONE,GL_SRC_ALPHA);?

Share this post


Link to post
Share on other sites
Well, GL_SRC_ALPHA, GL_ONE is probably what you want, but yeah. That would give you additive blending--can you see why? The math comes to (Src*Alpha)+Dst. GL_ONE, GL_ONE will just add them (which also probably ends up being brighter than you want). The drawback to additive blending (either way) is that when the numbers get big (either from bright colors or from multiple layers) the result tends to get 'blown out' or pure white.

The other very common blend mode is GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, which would interpolate the two values instead of adding src on top of dst. (Src*Alpha)+(Dst*(1-Alpha)) But when you do this you have to render back to front because the results depend on order.

Share this post


Link to post
Share on other sites
Well I tried quite a number of combinations with no luck... I decided to write a shader to do the blending for me.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!