Silly Blending Question

Started by
3 comments, last by xerodsm 15 years, 9 months ago
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.
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
Orin Tresnjak | Graphics ProgrammerBethesda Game StudiosStandard Disclaimer: My posts represent my opinions and not those of Bethesda/Zenimax, etc.
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);?
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.
Orin Tresnjak | Graphics ProgrammerBethesda Game StudiosStandard Disclaimer: My posts represent my opinions and not those of Bethesda/Zenimax, etc.
Well I tried quite a number of combinations with no luck... I decided to write a shader to do the blending for me.

This topic is closed to new replies.

Advertisement