[Niagara 5.3] Sorting Mini Tutorial

Sorting in Niagara

The way sorting works for particles in Niagara is obscure and not well explained. This article is meant as a basic introduction into how sorting works for Niagara and some of the techniques that are available for sorting.

Note : All elements in the scene will be compared to the depth buffer (unless opted out of) before drawing, so translucent elements will draw behind opaque elements correctly no matter which of the following options you use.

High level overview

Niagara has 3 layers of sorting : Particle, Emitter and Component.
Each of these elements can be sorted between each other but none can be sorted outside of their scope. For example a Particle can sort between 2 of itā€™s own emitter, but cannot sort in between 2 particles of a different emitter, nor can an emitter be sorted in between emitters of a different component.

It can be useful to think of components as systems, just keep in mind that these settings happen on the component level, and can as such be different for 2 components using the same system.

image


Particle Sorting

(Sort Mode)

Particle sorting can be set using Sort Mode in the Sorting Settings (part of NiagaraRenderer). By default particles will simply be drawn by the order they are found in the buffer. This is highly unpredictable, but if your particle donā€™t overlap a lot this is usually not an issue.
View Depth and View Distance render by distance to the camera plane, and distance to the camera position respectively.
Custom Ascending and Descending use the value set in Custom Sorting Binding to sort particles. Default is age (so it will be the same as cascadeā€™s sort by age mode), but any arbitrary value can be used (for example sorting by size etcā€¦)

It is important to note that even if a sort value of a particle in this emitter is larger than one in another emitter, this particle will still sort below it if that emitter has a larger sort order hint


Emitter Sorting

(Sort Order Hint)

By default emitters will be drawn by creation order (not activation order, but order by which they have been added to the system). This is completely arbitrary. You can change this behavior by setting the sort order hint.

Emitters with larger sort order hints are draw later and as such on top of emitters with lower sort order hints. (higher number = on top)
This sorting only happens within the component, so even if the sort order hint of an emitter in this component is higher than one in a different component, that other componentā€™s emitters will still draw on top of that component is drawn later.


Component Sorting

All components in unreal engine that have translucent elements will have their translucent elements rendered from back to front. This means that as long as the objects position is somewhat relevant to the actual position of the pixels, closer translucent objects will draw in front of further translucent objects.

You can fiddle with this using the Translucency Sort Distance Offset and Translucency Sort Priority parameters of the component.

Translucency Sort Distance Offset will draw elements as if they were placed further or closer to the camera.
Translucency Sort Priority will draw any element with a higher priority after elements with lower priority (and as such, always on top)


Conclusion

It can be valuable to have a good grasp on the limitations of this system as they will vastly improve your ability to plan out feasibility of the look of an effect. Some things, like complex intersecting translucent geometry simply isnā€™t possibly unless every pixel is sorted individually, so try and plan effects around these kinds of limitations.

If you have any questions, corrections or suggestions, feel free to leave them in this thread.

41 Likes

Nice tutorial, thanks for the clarification, Iā€™m trying to sort my emitters so that they render in front of each other, but the sort order isnā€™t working even though I adjusted the sort hint order accordingly, any ideas what the issue might be? Btw my emitters is a mesh with an opaque material, no translucent mats or anything like that, Iā€™m asking in case there is a limitation

Edit: the issue is solved, this only works on transparent materials

@Niels Thanks for posts like this, some things are really not well explained so far and things like this help to understand faster.

1 Like

Does this work in UE4.27? I tried to change the sort order hint, but it seems like the colors are being multiplied. Iā€™ve created two translucent ribbons, and the main ribbon has a noise that subtracts some parts of itself (itā€™s animated). I want to have a second ribbon playing from behind, but it seems to be playing in front all the time, even when I tried the sort order hints 1 for the main and 2 for the second, and vice versa.
Thanks!

Should work in 4.27 yeah. Any chance you could share some more about how youā€™ve set this up?
Please keep in mind that this only works on elements with translucent materials. Not masked

Yeah, sure.
Both are translucent. The orange one should be in front and the yellow one should render from behind.
Orange Sort order hint: 1
Yellow: 2
i tried 0-1, 2-1 but yellow is never behind


Are there any sorting optimisations for opaque material sprites? Ie sorting front to back, and discarding sprites that will be occluded?

Iā€™m using masked materials which makes it trickier to tell if a particle will be occluded, but maybe there are still some approaches. Iā€™m thinking of dense ā€˜cloudsā€™ of particles where the centre of the cloud is completed occluded.

Sorting on opaque materials (inc. masked) happens per fragment. The sorting settings will have no influence on the look

Hi @Niels!

I wasnā€™t thinking about look - it was a partly formed thought about performance optimisation more to do with occlusion than sorting (I realised once youā€™d replied :slight_smile: )- something like culling occluded particle geometry we know isnā€™t visible to avoid processing the fragments at all

Maybe this already happens when using opaque materials?

Yes, in unreal, if the early depth pass is enabled (which it is by default), fragments occluded by opaque materials will not be drawn

Couple questions
It probably will depend what youā€™re making but if you make a heavy system with a lot of emitters, would you suggest adjusting the sort order hint to ā€œmost impactful emitterā€ first down to the least?

My other question was is it worth always using the ā€œSort Modeā€ in games and not ever having it set to ā€œNoneā€ to improve performance, and if this is the case, what would you recommend?

if you make a heavy system with a lot of emitters, would you suggest adjusting the sort order hint to ā€œmost impactful emitterā€ first down to the least?

Not really, it ends up drawing all the elements either way, changing sort order only changes when it draws it.

My other question was is it worth always using the ā€œSort Modeā€ in games and not ever having it set to ā€œNoneā€ to improve performance, and if this is the case, what would you recommend?

Sort Mode: ā€œNoneā€ doesnā€™t mean we donā€™t order at all, it just means you donā€™t have a particular preference on the order the particles get drawn in (so that likely means it just uses buffer order).
I doubt itā€™s ever worth going in and setting it to none when other modes would look better, but yeah, if you donā€™t need it itā€™s likely marginally better to leave it on none so no sorting step is necessary.

1 Like