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


Advanced Rendering Question.

Recommended Posts

Itayl    122
Hi all, I have a problem. I am rendering a scene using OpenGL and I have opaque objects and a "fire" particle effect. For the opaque objects I use depth test and for the particle effect I use alpha blending. The problem is that the particle effect is always visible even when it is supposed to be hidden by opaque objects. I understand that I need to perform z-sorting the to render the objects in the correct order. My question: What is the best way to achieve the desired effect ? How can I perform z-sorting - what is the fastest way ? Can I use OpenGL Z-Buffer or Accumulation buffer for that ? Can I use glAlphaFunc() for this purpose ? Please assist

Share this post

Link to post
Share on other sites
vincoof    514
First of all, it''s not an "advanced" question. Sorry to tell it directly, but it''s a newbie question. And the answer lies within any OpenGL FAQ.

Because your objects are NOT opaque, you''re most likely to render your particles using additive blending, and in this case there''s NO need to sort depth.
But you have to render your opaque objects first with depth-testing enabled, and then you have to render your fire particles with depth-testing enabled but with depth-writing DISABLED.
Here''s an example :

glDisable(GL_BLEND); // Draw Opaque Polygons

glEnable(GL_DEPTH_TEST); // Enable Depth-Tesing

glDepthMask(GL_TRUE); // Also Enable Depth-Writing

glEnable(GL_BLEND); // Now Draw Translucent Polygons

glBlendFunc(GL_ONE, GL_ONE); // Use Additive Blending

glDepthMask(GL_FALSE); // Disable Depth-Writing


Note that this works without depth-sorting because fire effects should be rendered with additive blending.
Additive blending works very well with lighting effects (fire, thunder, flares...) but if you want to draw other translucent objects you may need to sort depth.

Share this post

Link to post
Share on other sites