Mapping color gradient to MainTexture RGB channels?

Hi!
I’m trying to do something “simple” : mapping a gradient to one of the RGB channels of the MainTexture.
However, by default, the “ColorMapping > GradientMapped” option of the Render Quad block seems to be locked to the MainTexture’s alpha channel, which is… not what I need.

I’m using the cloud texture from the VFXGraph sample assets. It has distinct RGB / Alpha channels.
9895509--1428741--Capture d’écran 2024-05-28 210312.png9895509--1428744--Capture d’écran 2024-06-18 090452.png

The MainTexture’s RGB channels seem to be used only when “ColorMapping” is set to “Default.”

Setting it to “GradientMapped” (with a simple white-grey gradient) means only the alpha channel of the texture ever gets used. (The shadow in the lower-right corner of the sprite is not visible anymore)

Is there something I’m missing?

No, you’re not missing anything. The default mode, will use the Main Texture color directly and multiply it by per-particle Color attribute value.
When using the Gradient map mode, the Alpha channel of the Main Texture fetches the color from the Gradient, which is also multiplied by the particle color.

I guess that in your case, you’ll want to be able to specify independently which channel to use for the Gradient mapping and which one to use for Alpha. Unfortunately, at the moment the only solution for this would be to create a custom ShaderGraph.

Here is a simple one that would allow you to define a gradient in ShaderGraph, but also to set a Main Texture and which channel is used to sample the Gradient.
9900066--1429839--upload_2024-6-20_15-38-24.png9900066--1429842--Unity_vgUpapCUkb.gif

One thing to note is that while this shader is pretty simple, it could become bigger if you need to implement the regular functionality that can be found in the built-in VFX Graph shader (output) like Soft particles, Frame Blending etc…

Also, the ShaderGraph Gradients cannot be exposed and modified externally of the ShaderGraph. In other words, while the texture and other properties can be exposed and modified in a VFX Graph, the gradient from a shader graph cannot.

To bypass this limitation, instead of using a sample gradient, a solution could be to sample a texture with a gradient baked in. While you could create that gradient texture in Krita, Photoshop, or other DCC, multiple free and paid tools are available on GitHub or the Unity Store that allow you to create texture thanks to a gradient.

I’ve modified the ShaderGraph shown above slightly so that we sample a texture instead of a gradient. We need two coordinates, U and V. The Main texture channel value will be used to fetch the color on the X-axis.
And I’ve created an other exposed parameter that allows to change change the Y value. This allows us to bake several gradients in one texture so that we can choose which to use.

9900066--1429896--upload_2024-6-20_16-35-28.png

9900066--1429902--Unity_gsHoBMFY95_0000-0114_1000x553.gif

Overall, creating a custom ShaderGraph should give you the control that you need over the channel and let you implement other custom features tailored to your needs. They’re a lot of synergy between VFXGraph and ShaderGraph and I encourage you to give it a try.

I hope this will be valuable. Have a fantastic day.

Wow! That was very informative. Thanks a lot! I’ll definitely take a closer look at everything you outlined.

sorry for a bump :(, your example looks awesome but I can’t find gradient index nodes or color channel nodes, are the hidden somewhere ?

The Shader Graph node doesn’t exist. I’ve just created them for the illustration purposes.
You can either create a dedicated subgraph or just use a regular Enum Keyword.

The channel selector is just this: an enum keyword exposed property.

With this setup, you can then set which channel to use in VFX Graph with a dropdown.

And in my souvenir, the Gradient Index was the same. An enum keyword with predefined values to sample the correct gradient in a gradient texture.

The value set in the Gradient Index enum corresponds to the UV.y value. But you could also use a Flipbook UV like so:

Now, you are not forced to use Keyword Enum. They just allow you to create some convenient UI.
While convenient, you will only be allowed to make variations per VFX instances.

If you want to make per-particle variation, like each particle using a random gradient index, then you should use a regular float like so:


In VFX Graph, the float would appear as a regular float field, but the principle is the same: setting the value to 0-1-2-3 selects a gradient.

I hope this helps. Great day to you.

Got it, that makes a lot more sense now. Thanks for taking the time to explain it so clearly. I’ll give this a try and see how it goes. Really appreciate the help, have a great day!