• Advertisement
Sign in to follow this  

Help! Overlapping blended particles artefact

This topic is 4149 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. I'm having problems with my 3D particle engine. I know that I have to sort the particles based on their distance from the camera in order to render them properly, and I've done that, and it seems to work fine. However, it seems that when two or more particles are the same distance from the camera, and are overlapping, they flicker, and it's like there's no way to determine which should be drawn first, because after all, one isn't in front of or behind the other. I'm also billboarding the sprites, and I thought there may have been a problem with my billboarding code, but it works fine on everything else I've billboarded, so I'm pretty sure it's not that. I've tried experimenting with BlendFunc and AlphaFunc to get rid of the problem (I am familiar with how they both work, but I was just trying anything I could). Help would be appreciated!

Share this post


Link to post
Share on other sites
Advertisement
Disable writing to the depth buffer when dealing with particles (but keep depth testing on as per normal) This will stop the Z-fighting.

If you really need to have depth writing on as well, then render depth and colour in two seperate passes (disable depth, enable colour, render, disable colour, enable depth, render again).

Share this post


Link to post
Share on other sites
Not sure if your useing openGL but this code works wonders for me:



glDepthMask(false); // turn off depth writing
glEnable(GL_BLEND); // enable blend
glBlendFunc(GL_SRC_ALPHA, GL_ONE);

mgrPtcls->render(); // draw your stuff

glDisable(GL_BLEND);
glDepthMask(true);



*Also if your useing that blending mode you don't need to sort your particles as they all just add together nicely :P Just draw them last after the rest of your map/entities and it all just works.

Share this post


Link to post
Share on other sites
@ kaysik: That only works if your particles are designed to glow / make the scene brighter. i.e. it will add up to white, and often you want to use particles to represent smoke etc which doesnt 'add' but instead has to be alpha/inv-alpha blended. And for that to look 100% correct *has* to be sorted (even though that is impractical for large scale systems)

Share this post


Link to post
Share on other sites
Quote:
Original post by Exorcist
@ kaysik: That only works if your particles are designed to glow / make the scene brighter.


Correct - like I said "if you use that blending mode you don't have to sort", so obviously it follows "if you don't use that blending mode you DO need to sort". The 'glDepthMask(false);' call however will fix his problems of z-fighting, and the code I posted will still work fine if his particles are sorted, no matter what blending he uses.

As most simple particles systems usually only use additive blending modes (in my personal experience anyway) I thought I'd point out that he didn't have to sort if thats all he needed, but I never suggested he shouldn't ever sort - mearly that if his system is only additive its a nice speedup and simplification.

Share this post


Link to post
Share on other sites
Thanks guys, your help was perfect. The glDepthMask function is exactly what I needed, for now, anyway, but thank you all anyway.

[Edited by - industrion on October 9, 2006 7:03:12 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement