Advanced Rendering Question.

Started by
0 comments, last by Itayl 21 years, 11 months ago
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
Advertisement
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 PolygonsglEnable(GL_DEPTH_TEST); // Enable Depth-TesingglDepthMask(GL_TRUE); // Also Enable Depth-Writingdraw_my_opaque_objects();glEnable(GL_BLEND); // Now Draw Translucent PolygonsglBlendFunc(GL_ONE, GL_ONE); // Use Additive BlendingglDepthMask(GL_FALSE); // Disable Depth-Writingdraw_my_fire_particles();  


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.

This topic is closed to new replies.

Advertisement