Jump to content
  • Advertisement
Sign in to follow this  
FlyinDeath

OpenGL How can I use depth test without changing the depth buffer?

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

I'm currently implementing a particle system with alpha blending. When depth test is disabled, everything works fine. But when depth test is enabled, the textures all messed up. I've tried the alpha test method but the result is not quite good. I've also found some articles stating that drawing in reverse order will have the best visual effect, but it will need to sort all particles for every single frame, which doesn't sound good when hundreds of particles need to be sorted. So I'm looking for a way to draw particles with depth test without modifying the values in depth buffer. Is it achievable in OpenGL? Or is there a better alternative?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by LilBudyWizer
Use glDepthMask.
That will just give you incorrect results, you still want the depth test you just want the particles to be correctly ordered.
RenderScene();

glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

// 1. sort by Z
// 2. render particles in order of:
// furthest away to closest to camera/eye.
RenderParticlesByZ();
you probably iterate the list of particles per frame at least once, you could do a simple counting sort (or radix) to order the Z values loosely.

EDIT:
this just came to mind; i'm not sure if it will work but its worth a try. Render the particles to the frame buffer but disable color writes then re-draw the particles with color write & alpha blending on and the depth buffer off. so something like this:
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
RenderParticles();
glDepthMask(GL_FALSE);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
RenderParticles();
glDepthMask(GL_TRUE);

Share this post


Link to post
Share on other sites
It seems that glDepthMask will prevent depth buffer from changing while still performing depth test. Anyway thanx alot to you both :D

Share this post


Link to post
Share on other sites
silvermane, I think you're confusing disabling writes with turning off the depth test. If you just try to draw a decal on a polygon you get some of the pixels of the decal and some of the polygon because of rounding errors. They should both be the same depth, but they aren't. If you turn off the depth write then it writes the colors for both of them in the order you tell it to. Then you turn off the color buffer and write the depth values. You don't want to overlay the image you drew, but you want the correct depth values for the rest of your rendering.

Writing the depth values then the colors would pretty well require that you turn off depth testing for writing the colors. The only time you should turn off depth testing is when the stencil buffer is set to keep you from writing where you shouldn't.

Share this post


Link to post
Share on other sites
Hey LilBudyWizer, yea i think i see what you're saying; FlyinDeath you can ignore my "EDIT:" solution - like it said, it was just a stab in the dark [wink]. I found a particle system example over at GLFW and they simply disable depth-write and draw the particles..

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!