Blending filters

Started by
2 comments, last by illuzion 22 years, 6 months ago
Hi At the moment I''m writing a particle engine, and apart from one thing it works fine. Each particle is drawn to the screen using a triangle fan, with the center being brightly coloured with an alpha of 1 and the edges having an alpha of 0. I use glColor3f(), and the 1 and 0 values are hard-coded so I know they really are there. With depth-testing turned off, I can use either glBlendFunc(GL_SRC_ALPHA, GL_ONE) or glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA) and it will draw the way I want (I''ve only tested it against a black background, but it looks OK) - each particle a bright spark with the edges fading away. When there are a lot of them together it becomes white. Unfortunately, with depth-testing turned on, I can see the edges of each particle - the parts that are supposed to be completely transparent aren''t. It looks pretty bad. So what I need is depth-testing turned on so the particles look ok compared to everything around them, and depth-testing turned off so the particles blend together properly. Help! I''ve tried fiddling with glDepthFunc and glBlendFunc - not every combination, of course.. If I use glDepthFunc(GL_ALWAYS) then it looks ok again but I think that''s also equivalent to having depth testing turned off So can anyone tell me what I''m doing wrong or what functions etc I should use? Thanks - dave.
Advertisement
Enable depth testing, but disable depth buffer updates.
How do I do that? I didn''t know you could disable writing to the depth buffer... they will still need drawn properly compared to other objects though?

> How do I do that?

Easy:

   glEnable(GL_DEPTH_TEST);   // Enable depth testing   glDepthFunc(GL_LESS);      // type of depth testing   // ... render your opaque objects here ...   glDepthMask(GL_FALSE);     // Disable depth buffer writes   // --- render translucent objects ...   glDepthMask(GL_TRUE);      // Enable depth writes 


> I didn''t know you could disable writing to the depth buffer... they will still need drawn properly compared to other objects though?

Sure, it''s a standard trick used to render transparent objects. They will be correctly depth buffered against the opaque ones (since the depth test is still active), but they won''t mess the zbuffer values anymore, since you made the zbuffer read-only.

This topic is closed to new replies.

Advertisement