Hi everyone, hoping to get some help with transparency sorting in our VFX system.
We’re trying to address a longstanding issue with how our particles layer with our sprites in our top-down 2D game. Our VFX system relies on instantiating single particle systems (now Visual Effect components) and telling them to emit single particles at specific positions when needed.
The issue we’re having is that all particles from a given emitter are either entirely behind or entirely in front of all sprites on the same sorting layer. Our sprites are sorted along the z-axis, as configured in the 2D renderer component, and we’d like our particles to play by the same rules. This would, for example, allow a bomb blast that goes off in a patch of grass to be interleaved correctly between the clumps of grass - behind some, in front of others.
Is this possible with either the legacy system or the new visual graph system using this single-emitter strategy? Or are we consigned to pay the overhead of having a whole new emitter instance at the correct position, just to emit a single correctly-layered particle? The concern there is obviously that we may need many 100s of emitter instances, which seems like it’s going to quickly blow through our budgets.
Morning.
You got a bunch of Sorting options when using VFXGraph.
On the “per-particle” level you can find the options in the Inspector when selecting the “Output” of your System.
By default it’s using the Distance to camera, and as it said the Particles are sorted within the same system based on the Distance to the camera.
But you can also use the other options like, based on Lifetime with “Youngest in Front”, or the “Custom” mode to sort the Particles as you like.
When in “Custom” mode , a new Float input can be used in the “Output Context”, allowing you to Set the Sorting.
You can use the “ParticlesID”, or make some math based on the Position, or use any custom particle Attribute. It really depend on what you need.
Now, Each system can have multiple “Output Context”.
But there’s no notion of Camera distance per Output as the Bound are handle globally per System.
So you can have sorting issues like these:
You still can “force” the Output Sorting, in the Inspector by changing the “Sort Priority” Option:
Each VFXGraph should be properly Sorted based on their Bounding Box.
On the example below you can see that I’ve changed the bounding Box, position resulting in a an incorrect Sorting between VFXGraph components.
To finish on the Sorting Options , two other options can be leveraged:
The “Output Render Order” of a VFXGraph asset , where you can reorder the Sorting of the different Outputs:
I’m hoping that this overview of the Sorting parameters will help you in your Sorting Quest.
Sadly I’m still lacking experience with URP and 2D renderer so I hope my answer won’t be too generic.
If you still have issues, don’t hesitate to post again and I will poke someone with more experience on this subject.
Have a great day
Hi OrsenFavrel, thank you for the extremely detailed response! Easily the most detail I’ve ever gotten on these forums.
These ordering features seem to be in a newer version of Visual Graph than I’m on, but they’re great to know about.
As I dug further into the problem, I hit a wall I could not get over through traditional means. Our layering landscape is too complex to be handled by any of the default Distance to Camera/Ortho/Perspective/Custom Axis/etc sorting options and we have no alternative but to continue sorting manually by using the sortingOrder property. This has worked great for us but makes the problem of layering in particles even more tricky.
However, with some creative use of the depth buffer, I think I’ve solved the problem. Our in-game entities move along the X and Z axis, but if I add a Y element proportional to their Z value (e.g. lower Y value towards the top of the screen) and make them write to the depth buffer, I can then turn on LEqual for my particle depth buffer test (also being sure to emit particles according to this same Y-axis rule) and viola! Particles now appear to sort correctly among a complex group of sprites, each with a different sortingOrder.
This solution seems to have checked all the boxes; explicit layering control via sortingOrder, and the ability to emit single particles where needed from a single emitter and have them layer correctly with everything else. Our game gets really bombastic and I know we will be unable to afford a huge Visual Effect instance count on low-end systems, so this was key.
Well I’m glad to hear that you found a solution to your issue. If by any chance at some point in time, you expose in detail your problem and how you solved it to the world (Blog Post, Twitter thread etc…) I’ll be happy to read/watch it.
The problem I’m having is that none of the sorting modes in the output block seem to be making the individual particles be sorted based on their Y position, as the rest of the objects in the project.
For now it looks that all the particles are rendered in the same positio, either all in front of my character or all behind it.
Maybe the custom option is the solution but I have no idea where to begin. I don’t even know if the particles have an individual pivot or center that the renderer could use to sort them among the other elements.