Search Unity

Particle system draw order with two particle systems

Discussion in 'General Graphics' started by Michael55, Jun 22, 2017.

  1. Michael55

    Michael55

    Joined:
    Jun 15, 2017
    Posts:
    10
    I have two particle systems (A and B) and I need to have them drawn sorted by distance. I have sort by distance enabled under the particle system's renderer tab. However, Unity will always draw particle system A before B or B before A. But I need the particles to be sorted.

    This gif is not mine but it illustrates the problem well:
    https://media.giphy.com/media/l41lNtmqe2huxPDe8/giphy.gif
    Either the black smoke is in front of all the dust or the black smoke is behind all the dust. But both are incorrect, the black smoke should be in middle of the dust, sorted by distance.

    I would appreciate any help.
     
  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    Sorting by distance is for the particles within a single system.

    For transparent Game objects, the center of their bounding boxes determines the draw order. (Ordered by distance from the camera)

    For particles, this can be overridden using the Sorting Fudge option.
     
  3. ifurkend

    ifurkend

    Joined:
    Sep 4, 2012
    Posts:
    350
    I have already explained on answers.unity.com, there is no way to have multiple extremely close objects with accurate depth rendering (z-fighting), this is more obvious for translucent objects.
     
  4. Michael55

    Michael55

    Joined:
    Jun 15, 2017
    Posts:
    10
    Sorting fudge enables me to have either have particle system A be drawn in front of particel system B or the other way around. But I need the particles from the two particle systems to be mixed.

    This should not have anything to do with depth rendering/z-fighting since transparent shaders do not write to the z-buffer. This is merely an issue of draw order - all particles should be drawn in depth order instead of first drawing particle system A in depth order and then particle system B in depth order on top of that. Faking the effect as you suggested is a possibility but being able to do it directly would give more consistent results. The login button on Unity Answers just redirects me to the index page without logging me in for whatever reason.

    If this is not possible in Unity by default, I guess it would be possible to disable the renderer from each particle system and write a new renderer which draws the particles from several particle systems in depth order. The only problem I can see with this is that a shared material with instancing would have to be used to not end up with a separate draw call for each particle.
     
  5. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    If you want the particles to be mixed together, yet sorted correctly per-particle, then you will require a more advanced rendering solution than anything that Unity offers out of the box.

    I'm not sure what good advice I can offer you .. you could try to use commutative blend modes (additive/subtractive), which don't require sorting, but I suspect that is no use for the types of effects you are creating.

    Or perhaps split your large dust effect up into multiple smaller systems, which may reduce the problem sufficiently.

    Or, as you suggest, do your own combining of multiple systems in script, and attempt to find an efficient way to sort/render it.
     
  6. Stephanommg

    Stephanommg

    Joined:
    Aug 18, 2014
    Posts:
    88
    Is this still a reality in 2022? No built-in solution or workaround?
     
  7. metaobjects

    metaobjects

    Joined:
    Jun 13, 2020
    Posts:
    4
    I had the same issue as this and resolved it by having a single ParticleSystem and using the Emit() method to manually emit particles from multiple different locations.
     
    Jomity and richardkettlewell like this.