Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎲 GameMaker

equally blended problem

Started by prunkdump Feb 23, 2009 at 3:32 PM 5 replies 1.1k views
Original Post
prunkdump
prunkdump
My problem is very simple. I have a scene composed by multiple textured GL_QUADS and I want to equally blend them. 1)the sequence: glBlendEquation(GL_FUNC_ADD) glBlendFunc(GL_ONE,GL_ZERO); draw(obj_A); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); draw(obj_B) doesn't work because obj_B is blended with the background. 2)the sequence: glBlendColor(0.0,0.0,0.0,0.5); glBlendEquationSeparate(GL_FUNC_ADD,GL_MAX); glBlendFuncSeparate(GL_ONE_MINUS_DST_ALPHA,GL_DST_ALPHA,GL_CONSTANT_ALPHA,GL_DST_ALPHA); draw(obj_A); draw(obj_B); may work but is not implemented on my graphic card (need 2.0) Is there exist a simple way to achieve this? Thanks.
dpadam450
dpadam450
I dont understand what your asking. and if obj_B is rendered on top of obj_A, then how is it blending with the background?

If you want 2 quads on top of each other to be not blending with the background, but blended with each other (.5 of each), then just do

glDisable(GL_BLEND);
Draw obj_A

glEnable( GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(1,1,1,.5);
Draw obj_B

which is basically what you have, excpet you didnt setup SRC_ALPHA but again I dont really know what your problem is.
NBA2K, Madden, Maneater, Killing Floor, Sims 
prunkdump
prunkdump
The obj_B is not on top of obj_A, one part of it is over the background!

I don't want to obj_A and obj_B seems translucent, I want melt them like a single object. ( as Enblend http://enblend.sourceforge.net/ )

dpadam450
dpadam450
I really cant think of a good way to do that. If using shaders I could bust something out. I really dont know, try GL_ONE, GL_ONE

I dont remember how its done in hardware but im thinking:

1*black + 1*color = color //no background problems

1*old_image_color + 1*new_image_color = blended

only problem is I think the first one works, but the second equation, you have addative blending, rather than mixed blending (.5 of each).
NBA2K, Madden, Maneater, Killing Floor, Sims 
prunkdump
prunkdump
You have understood my problem!

I need to thread the background differently: no blending over the background, mixed blending over obj_A.

But I don't know if I can do this without generating alpha mask or texture shading programming.
Lord_Evil
Lord_Evil
You could try to set the background alpha to 0 and then use

glBlendEquation(GL_FUNC_ADD)
glBlendFunc(GL_ONE,GL_ZERO);
draw(obj_A);
glBlendFunc(GL_ONE_MINUS_DST_ALPHA,GL_DST_ALPHA);
draw(obj_B)

i.e. first have object A fill the front buffer's alpha channel with a value you want (like 0.5) where object A is drawn, 0 elsewhere. Then draw object B and use the alpha values of the front buffer for blending -> fb * 0.5 + B * (1-0.5) where object A was drawn and fb * 0 + B * (1-0) elsewhere.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
prunkdump
prunkdump
Yes!!! it works!!

Doesn't need glBlendFunc(GL_ONE,GL_ZERO), simply:

glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_ONE_MINUS_DST_ALPHA,GL_DST_ALPHA);
glColor4f(1.0, 1.0, 1.0, 0.5);
draw(obj_A);
draw(obj_B);
draw(obj_C);
...

Thanks a lot!!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.