Jump to content

  • Log In with Google      Sign In   
  • Create Account

particles and depth testing


Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
6 replies to this topic

#1   Members   -  Reputation: 196

Like
0Likes
Like

Posted 06 January 2014 - 10:55 AM

First question:

 

My particle systems currently supports a few blend modes. For example: Additive, multiplicative or alpha blending.

 

Everything works fine so far, yet I am struggling with the actual understanding.

 

Lets take additive blending as an example and assume we are drawing two particles. Either Particle 1 (P1) or Particle 2 (P2) is drawn first. Which leads to one of the images shown below:

 

alpha_blending.png

 

On the right side is how it should look. The left side is how it shouldn't. The problem here is even though I use additive blending, which is for itself order independent, the output merger does some depth testing magic which results in the image shown on the left. The area T overlaps P2 and all fragments of P2 being removed (or never drawn). 

 

My question is why or how the output merger exactly performs that depth test. And how that error on the left side of the image can occur. I mean it is clear that it is the drawing order that causes the problem but how the rasterizer does the depth test per fragment is a mystery. 

 

I also know that if I disable depth write for my particles everything works fine since no fragments getting rejected.

----

 

Second question:

 

So far I have disabled depth writing for all blend modes but alpha blending. Since they are order independent blend modes. But now I am wondering if I even need depth writing for alpha blending. In fact I wonder if I ever need depth writing for any blend mode? Maybe it has some performance advantages?


Edited by me_12, 06 January 2014 - 11:49 AM.


#2   Crossbones+   -  Reputation: 7525

Like
1Likes
Like

Posted 06 January 2014 - 11:35 AM


I also know that if I disable depth write for my particles everything works fine since no fragments getting rejected.

 

Yes, that's typically what you want to do. Disable depth write for drawing particles. Particles usually need alpha-blending, and the depth buffer doesn't exactly work well with that (since it only holds a single depth value).



#3   Crossbones+   -  Reputation: 24090

Like
2Likes
Like

Posted 07 January 2014 - 04:09 PM

But now I am wondering if I even need depth writing for alpha blending. In fact I wonder if I ever need depth writing for any blend mode? Maybe it has some performance advantages?

Particles should be treated like any other translucent object. Generally that implies depth-writing is disabled. Enabling it often results in artifacts, particularly when translucent objects overlap.

Where performance is concerned, you should be batching as many particles from a single emitter as you can into a single draw call. An updating bounding box around that entire set of particles improves culling and gives you reasonable sorting (back-to-front) capabilities. That means you are sorting by close-together groups of individual particles rather than by individual particles, which means you don’t sort on a per-particle basis (highly discouraged for real-time applications) but close enough.


L. Spiro

#4   Members   -  Reputation: 196

Like
0Likes
Like

Posted 07 January 2014 - 05:22 PM

Thank you for your replies.

 

Where performance is concerned, you should be batching as many particles from a single emitter as you can into a single draw call. An updating bounding box around that entire set of particles improves culling and gives you reasonable sorting (back-to-front) capabilities. That means you are sorting by close-together groups of individual particles rather than by individual particles, which means you don’t sort on a per-particle basis (highly discouraged for real-time applications) but close enough.

 

I am always drawing all particles per emitter in a single draw call. I never heard about using bounding boxes for particle sorting, but it sounds interesting.

 

Anyways, what I meant with performance is that, if I have the particles sorted anyways for an order dependent blending like alpha blending,I might as well activate depth writing. This would not produce any artifacts since the particles are drawn in correct order. Yet I still wonder if it has any advantage? Like maybe some fragments getting rejected in step 1 and don't have to be blended in step 2?



#5   Moderators   -  Reputation: 48680

Like
3Likes
Like

Posted 07 January 2014 - 05:29 PM

The output merger does some depth testing magic... 
My question is why or how the output merger exactly performs that depth test. And how that error on the left side of the image can occur. I mean it is clear that it is the drawing order that causes the problem but how the rasterizer does the depth test per fragment is a mystery.

It's the same as 'regular' depth buffer operation: The quad with the red texture is drawn first, it writes it's depth value to the depth buffer for every pixel in the quad. The green quad is drawn second, some of it's fragments fail the depth test because they are behind the red quad.

Anyways, what I meant with performance is that, if I have the particles sorted anyways for an order dependent blending like alpha blending,I might as well activate depth writing. This would not produce any artifacts since the particles are drawn in correct order. Yet I still wonder if it has any advantage?

If your triangles are all already pre-sorted from back-to-front, then enabling/disabling depth testing will make no difference to the final rendering as you mention, but performance wise:
* Disabling depth testing means that the depth buffer doesn't have to be read/written, which slightly reduces your bandwidth per-pixel (save a 24bit read+write per pixel).
* Disabling depth writing means that the depth buffer doesn't have to be written, which (even more) slightly reduces your bandwidth per-pixel (save a 24bit write per pixel).
* Enabling depth testing will also enable "early Z" / "HiZ" on modern GPU's (assuming that alpha-testing or shader discard/clip statements aren't used -- these features kill early Z). This allows the depth test to occur before the pixel shader is executed (technically the GPU is supposed to waste time executing the pixel shader, then throwing away the results if the depth-test fails -- 'early Z' fixes this), and the pixel shader is skipped if that pixel doesn't have to be drawn. However, this is only an advantage when rendering opaque geometry from front-to-back -- it is of no use when rendering translucent geometry from back-to-front.

Edited by Hodgman, 07 January 2014 - 05:37 PM.


#6   Members   -  Reputation: 196

Like
0Likes
Like

Posted 08 January 2014 - 04:23 AM

* Disabling depth testing means that the depth buffer doesn't have to be read/written, which slightly reduces your bandwidth per-pixel (save a 24bit read+write per pixel).
* Disabling depth writing means that the depth buffer doesn't have to be written, which (even more) slightly reduces your bandwidth per-pixel (save a 24bit write per pixel).
* Enabling depth testing will also enable "early Z" / "HiZ" on modern GPU's (assuming that alpha-testing or shader discard/clip statements aren't used -- these features kill early Z). This allows the depth test to occur before the pixel shader is executed (technically the GPU is supposed to waste time executing the pixel shader, then throwing away the results if the depth-test fails -- 'early Z' fixes this), and the pixel shader is skipped if that pixel doesn't have to be drawn. However, this is only an advantage when rendering opaque geometry from front-to-back -- it is of no use when rendering translucent geometry from back-to-front.

 

Oh nice! Thank you that is what I was waiting for.



#7   Members   -  Reputation: 10500

Like
2Likes
Like

Posted 08 January 2014 - 04:56 AM

* Disabling depth testing means that the depth buffer doesn't have to be read/written, which slightly reduces your bandwidth per-pixel (save a 24bit read+write per pixel).
* Disabling depth writing means that the depth buffer doesn't have to be written, which (even more) slightly reduces your bandwidth per-pixel (save a 24bit write per pixel).


I'm pretty certain that on anything released in the last few years this would be a 32bit read/write; certainly on GCN as depth and stencil are stored seperately so a D24_S8 format takes up the same memory as a D32_S8 one where depth and stencil are stored as seperate chunks of memory.

(Which doesn't dispute your points, just highlights the extra savings).




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.




PARTNERS