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.
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)
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.
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.
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.
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.
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:
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!