# Particles Depth Problem

This topic is 2147 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have two different particles, the first one is fire (near the camera) and the other one is black smoke (far away from the camera).

When I look at the fire which is near the camera, the fire begin to clip and I can see the smoke instead of the fire, even the fire is closer (I should see the fire since its depth is much closer).

Here is what I have in my Shader technique:

ALPHABLENDENABLE        = TRUE;
SRCBLEND                = SRCALPHA;
DESTBLEND               = INVSRCALPHA;
ZWRITEENABLE            = FALSE;
ZENABLE                 = TRUE;
PixelShader             = compile ps_3_0 PSProgram();

How to fix that?

##### Share on other sites

If you want the two particle systems to composite correctly, then you need to sort them based on their distance from the camera. You need to draw the smoke first since it's further way, and draw the fire second.

##### Share on other sites

@MJP: I'm rendering all the particles belonging to the same texture with one draw call.

So If I have 4 emitters using one texture and 6 emitters using another texture, for performance, I render the 4 with one draw call and the 6 with another draw call.

How do I fix that problem while I still render the 10 emitters with only 2 draw calls?

Another problem:

Lets say I have the fire close to the camera and the smoke far away from the camera, the smoke generate and then it move towards the camera (becoming closer than the fire)

In that case I would have a problem, I won't see the smoke since I'm sorting according to the distance of emitters (The smoke emitter depth is far but the smoke particles depth became closer than the fire when they moved)

##### Share on other sites

If sorting by emitter isn't practical, then you only have two other options:

A. Sort by particle

or

B. Sort by pixel

Sorting by particle isn't very difficult if you do it on the CPU, but it won't scale up to many thousands of particles. Sorting on the GPU is doable, but not easy to write (especially if you don't have access to DX11 compute shaders). Either method won't let you sort between draw calls.

Sorting by pixel requires using some sort of OIT (Order Independent Transparency) technique. These techniques tend to be expensive and complicated, even with a DX11 feature set. However they can produce a perfect result for arbitrary geometry, although usually only up to a certain amount of overlapping pixels.

I wish there were better options, but there really aren't. It's still a major pain point games. You can see transparency sorting issues all over the place in just about any modern game, even the big-budget games.

##### Share on other sites

Thanks MJP

One last depth problem:

When I disable soft particles, the particles appears in front of the camera ALL THE TIME even if they are very far away and I have many buildings much closer, I can still see the particles (while I shouldn't).

• 13
• 18
• 29
• 11
• 27