View Full Version : Z-test without afecting the z-buffer

03-28-2004, 03:57 AM
Can I use glDepthMask to draw smoke (as particles) when I don't wanna sort they?:

glBindTexture(GL_TEXTURE_2D, GLuint);
// draw particles (not from back-to-front)


Will be all particles blended visibly.
(Sorry - Language problems)

03-28-2004, 04:02 AM
Well, what happens if you try it? If it works, then it works. If it doesn't work, then it doesn't work.

Some blending functions require depth soring, others don't. Since you didn't say what function you use, I can't say if you have to sort or not.

03-28-2004, 04:13 AM
I haven't it tested, I'm now in a internet coffe (I don't have web at home). I wrote to this page because I see this function 1st time in my life and I don't know exatcly what how work it.
I use glBlendFunc(GL_SRC_ALPHA, GL_ONE);

03-28-2004, 04:22 AM
Oh, yeah, I forget. How can I sort my particles quick. They are struct types:
struct Particle {
GLfloat x, y, z; // position
GLfloat vx, vy, vz; // vector
... };
And they're stored in a std::set object.

03-28-2004, 04:23 AM
Additive blending doesn't need sorting, so it should work by disabling depth writes and just draw everything.

03-28-2004, 04:29 AM
One more question. If my particles are black and alpha is in range 0-255 (in texture). Will be they visible in the scene (as a black smoke)?

03-28-2004, 04:47 AM
With that blending function; no. You're adding zero (black) to the frame buffer, which does nothing to the color in the frame buffer.

I'm not sure I remember correct, but I think you can do it with interpolation instead of additive blending; glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA). This blending function usually requires sorting to work properly, but in this case you can get it to work without sorting. I did it like this before, and it worked great. This way, you can use the alpha channel as the thickness of the smoke, and the color channel as the color of the smoke.

03-28-2004, 05:06 AM
Ok, thanks. And what if I use:

03-28-2004, 05:31 AM
That is like having blending disabled. GL_ZERO will cause nothing of the frame buffer to show through the smoke, independent of the alpha value.

I suggest you take a real look at the blending operation; what the blending equation really does and how the blending factors affect the equation. the Red Book (http://www.parallab.uib.no/SGI_bookshelves/SGI_Developer/books/OpenGL_PG/sgi_html/index.html) , chapter 7, is a good start.