Vfxgraph: Strategies For Making One Graph Handle Multiple "particle Systems"?

I’m trying to make an example of using only one graph for handling multiple particle systems of the same type, resulting in much less draw calls than if I had 1 graph per system. This article mentions the FPS Sample does something like this for its projectiles. I feel like this is probably very simple to pull off but I’m too new to VFXGraph to figure it out.

So here’s the example I’m working with:

I have this fire VFXGraph that basically just spawns billboard smoke quads from a point in the world, with an upward velocity. It’s more or less the same as the graph in this video. Now I want to make this graph be able to support multiple positions in the world where the particles can emanate from, so that I can have many fires without the overhead of having each individual fire be a different VFXGraph instance

The part I’m having trouble with is:

  • How do I pass an array of realtime-modifyable-by-script positions to the graph?
  • How do I handle the “for each of those positions, spawn the particles from there” logic?

For point #1, I tried storing positions in a Texture2D parameter, but the problem is that all "Vector3"s in my texture are clamped to the 0-1 range, so they can’t properly represent world positions. Then I messed around with point caches, but I couldn’t figure out how to modify its points by script

For point #2, I have no idea

Bump, I’d love to know about this type of thing too!

This video goes over a similar topic if not exactly what’s asked. Not a lot of people got to see it though

1 Like

Unless I’m mistaken, the limitation of that approach is that they can’t have one graph spawn multiple new effects per frame; they are limited to maximum one new effect per frame. Trying to call myGraph.SendEvent() multiple times per frame will only result in your graph processing the last of the events you sent (again, unless I’m mistaken)

I did end up finding a solution to my problem though. Here’s a demo where each bullet hit VFX is handled by a single VFXGraph in the scene:

https://www.youtube.com/watch?v=OeyAatktPnQ

We have to find a way to not only send events to our VFXGraph like they did in the video, but potentially send a group of events to a graph all in the same update. I did this by making my graph hold 2 special parameters:

  • SCount: the number of new spawn events this frame
  • STex: a texture whose pixels contain the spawn information of each new event: pos, rot, intensity, etc…

Then I made myself a custom “SampleTextureForSpawnData” node that makes it easy to retrieve the data of a specific event based on a particle’s spawn index:

Now in my VFXGraph, I use “SCount” to figure out how many particles to spawn, and “SampleTextureForSpawnData” for getting the spawn position/direction/intensity/etc… of each new particle, based on which event they belong to

In code, all I do now is “serialize” all of my spawn requests to a texture (STex), pass it to the VFXGraph along with SCount, and tell the VFXGraph to do its OnPlay event. I’ve attached the system that does this to this post, for those who want to study it. Keep in mind this is a DOTS system but DOTS doesn’t matter for this use case

7542508–931852–VFXManagerSystem.cs (6.31 KB)

5 Likes

^^ it’s a terribly awkward & cumbersome workflow though

But there are 2 things being added to VFXGraph that will help:

  • Graphics Buffer support: I haven’t had the chance to test this yet, but this allows you to upload arrays of data structures instead of having to deal with a texture. This feature should already be in 2021.2
  • Effect Instancing: This sounds like it’ll be an automagical solution to the problem, but I have no idea if it’ll perform as well as a manually-handled single-graph solution. It sounds like it still involves spawning new VFXGraph gameobjects everytime, which I assume would probably be less efficient than the approach I described. Pooling might be able to mitigate this a bit

I really just wish we could send queues of events to a graph instead. I wonder if @PaulDemeulenaere has thoughts on whether this feature could be made possible, or if effect instancing would be just as good

3 Likes

Hi @PhilSA the above is exactly what i was looking for and could form a really good basis for handling my visual effects going forward (particularly as im using dots and can’t work out how to control point cloud interface with that).

I have implemented a version of what you’ve done but i cant get it to work using “UnityEngine.Experimental.Rendering.GraphicsFormat.R32G32B32A32_SFloat”, the texture generation works nicely but vfx graph doesn’t generate anything when using sample texture 2d. Using RGBA32 it generates something but of course the location isn’t correct, from the randomness i can see its doing the right thing.

I notice you use a node called Sample Texture 2d Pixel, is this a custom sub graph to deal with the format above or could it be my editor version and VFX versions of 2020.3.18 and 10.6 respectively are incompatible/do not have ‘sample texture 2d pixel’. Thank you for any help, it will definetely improve my games VFX handling if i can get it to work!

EDIT: Dont worry, worked it out! It all works fine in my version when using ‘Sample Attribute Map’. System looks like it works really well and i’ll post some results if I can complete my vision! Thank you very much for sharing the system Phil!

Old thread but i implemented your approach slightly modified @PhilSA . Ignoring the first 20 seconds or so, the thrusters, missile trails, explosions are all handled in single gameobjects with VFX graph attached with generated texture input. The texture holds, position, current velocity, size and/or engine power. Works relatively well since before i was updating VFX graphs per object. Would be good to have a native solution in 2021 unity.

1 Like

VFX graph attached with generated texture input. The texture holds, position, current velocity, size, and/or engine power. Works relatively well since before i was updating VFX graphs per object. Would be good to have a native solution in 2022 unity. https://apkseagle.com/cricket-league-mod-apk/

For anyone coming late to the party, Effect Instancing is in 2022 LTS and as far as I can tell - it does cut down on the draw calls if you have lots of entities that share exactly the same VFX.