Blending woes
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
------------------------------
turn blending off when drawing those objects.
glEnable(GL_BLEND);
glBlendFunc(...);
// draw blended objects
glDisable(GL_BLEND);
// draw non-blended objects
- Mike
glEnable(GL_BLEND);
glBlendFunc(...);
// draw blended objects
glDisable(GL_BLEND);
// draw non-blended objects
- Mike
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.
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement