Archived

This topic is now archived and is closed to further replies.

Blending woes

This topic is 5883 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 am using blending but am having some serious problems with a few objects that overlap but shouldn''t be blended. If two things have an alpha value of 1.0f how do I make one simple overlap the other one and not blend? Jason Mickela ICQ : 873518 E-Mail: jmickela@sbcglobal.net ------------------------------ "Evil attacks from all sides but the greatest evil attacks from within." Me ------------------------------

Share this post


Link to post
Share on other sites
Everybody keeps saying that you should draw the opaque objects first. Then draw the blended objects from furthest to nearest. There''s some kind of logic behind that, but I have no idea what it is.

Share this post


Link to post
Share on other sites
Well here''s the procedure:
1) Turn on the depth buffer, depth writes and depth testing. (The latter two are enabled by default if the depth buffer is enabled.)
2) Turn of blending and draw all your opaque objects, preferably in front-to-back order but that''s not necessary.
3) Disable depth writes.
4) Turn on bledning and draw all transparent objects in a back-to-front order. Order is very important here!

Now here''s the logic.
Drawing your opaque objects from front-to-back decreases the amount of unnecessarily rendered pixels. If you render a cube in the background, and then another object in the foreground that obscures it, then you wouldn''t need to draw all those cube pixels.
When blending, we don''t want to write to the depth buffer because transparent pixels should not obscure other pixels entirely. We do keep depth testing enabled because we do want transparent pixels to be obscured by opaque pixels.
The rendering in front-to-back order is necessary for proper blending. If a destination pixel is in front of your pixel to be rendered, you''ll need another blending function than when it''s the other way around. This is not possible in OpenGL in a single pass, so it is better to sort your objects to prevent it from happening.

Did that help?

Dirk =[Scarab]= Gerrits

Share this post


Link to post
Share on other sites