Particle changes color as depending on the color of the earth

I need my VFX graphene particles to have the same color as the ground they emit from.
example the ground is red then the particles are also red, the ground is yellow then the particles are yellow"
can it be done inside the vfx graph

You can use script pass a color value to a color property of the VFX Graph.

Morning. There are plenty of way to do this. To change the particle’s color, you need to set the Particle’s color attribute value. Several blocks allow you to do so:

Set Color, Set Color Over Life, Multiply Color or even Set Color from Map. You can use one or a combination of those block to define your particle color.

Now, to use the same VFX and drive the particle’s color at the instance level, you need to expose a property.

For this, you need to:

  • Open the Blackboard.

  • In the Blackboard, click the “+” button and choose a “Color” property

  • Drag and drop this Color Property in the Graph

  • Plug it to the desired Color block.

Now, in your scene, you should be able to drive the Color on a per-instance level. The exposed property can be modified in the inspector when you select a VFX in your hierarchy.

Now you can be even further so that you’re able to pre-define a set of colors for each of your cities and just pick the city on the VFX instead of colors. Here two solutions that could be practical to use in production.

Solution 1:

Create an Uint property set to “Enum” mode so that you use it to switch between color:

  • Create an Uint property thanks to the Blackboard and give it a name.
  • Set the Uint Mode to Enum.
  • Create your Enum values.
  • Drag and drop it to your Graph.
  • Use the Uint property to drive a Switch operator.
  • Make sure that your switch is set to Color (Upper-left cogwheel)
  • Use your switch output to drive your Color.

Now you have one place to define your City Color, and you just choose the “City Faction” for each VFX instance in the hierarchy.


To can go even further by converting those operators to a Subgraph. This will allow you to reuse your Subgraph in a different VFX asset and still be able to make a change to the subgraph that will be propagated to all VFX using this subgraph.

Solution 2:

The second solution is pretty similar to the first one. It’s relying on a Uint in Enum mode.
But instead of using a switch operator, you can sample a Gradient texture. You can embed this logic Inside a Subgraph to propagate all your changes. And you can still edit and propagate color changes to your city by just editing your gradient texture with a dedicated Unity tools or inside your DCC (Krita, Photoshop, etc…) without even opening your subgraph like in the first solution.

I hope that this will help you and give you ideas to organize your VFX Setup.

Have a lovely day !

1 Like

I was reluctant to mention this solution has they are many scenarios where it would fail…
But for the sake of completeness, let me describe a third Solution.

The idea here would be to fetch the SceneColor buffer to get “Ground Color”. This has many limitations:

  • The ground can be occluded, which means that you won’t get exactly the color that you want.
  • it can fail if transparency is involved.
  • You’re getting the Scene Color and not the Base color, so it can get tricky if you’re using Lit particles. You’ll need to create a Custom Pass, or Extra camera setup that would only render the Albedo…
  • Things would get even more tricky in URP.

Now that the warning has been said, let’s jump in:

  • We’re Getting the Color of the Main Camera thanks to the Operator Position (Depth).


    This Operator has some extra settings in the Inspector that allow you to Inherit the Scene Color.
    image

  • In the Initialize Context, we can use this color and use it to set the Particle Color attribute when the particles are just born:

  • We need’s to set the UVs coordinate to know where to sample from. For this we can use an handy operator called World to Viewport Point. This operator transforms a position into viewport space, which is precisely what we need. (XY = UV, and Z = Depth)

  • Finally, we just need to wire a World Space position to know where to sample from. You can use the Particle’s position, but in my case I decided to use the VFX instance’s pivot position.

Unity_ts1tsb5V2g_0000-0085_750x540

As you can see, the particles are properly catching the color of the Ground when they are born. But If something is occluding, you’ll get this color instead. A solution could be to set up a dedicated Camera that will only capture the Ground. You would be able to use it thanks to the Position Depth Operator in Custom Mode.

Now, base on your project, this solution might work for you. But to be honest, I wouldn’t recommend this solution in production. The Previous one should be more scalable and art directable.