• Advertisement

Archived

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

Blending filters

This topic is 6055 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

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.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Enable depth testing, but disable depth buffer updates.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster

> 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.

Share this post


Link to post
Share on other sites

  • Advertisement