How to make gradient editor for shader?

Hi all, particle system can not get the color life time by code,So I want to add gradient editor value for shader ,How can get it?
Thanks advance!

Shaders don’t take gradients as inputs. You might be able to get a MaterialPropertyDrawer to do what you want, but I don’t have experience with those and I assume it’s a lot of work.

yes ,i want to know how make the gradient in MaterialPropertyDrawer

There is no API exposed to render such gradient UI. You could use Reflection though, the internal methods are called EditorGUI.GradientField and EditorGUILayout.GradientField .

Hello, this is an old thread but just in case someone came across:

You can (kind of) achieve your workflow: using a Gradient as a shader parameter – by generating a one-pixel-height 2D texture asset out of your Gradient and passing it to your material’s texture property, which you can automate by creating your own script as either MonoBehavior or ScriptableObject.

I don’t have a code here, but I’ve made a script like that before. Essentially you need to know how to (1) read a Gradient and convert it into a 2D texture, (2) create a 2D texture asset in the project, (3) hook the asset into the material’s texture property and (4) write a Editor script to show a button in the script’s inspector to do that.

My point is that the workflow is definitely possible with some overhead in setting up the tool to do so. I hope this helps.

Hello, I’ve made tool trying to solve this problem - GitHub - mitay-walle/com.mitay-walle.gradient-texture: Unity Gradient Texture generator

1 Like

Stuff like this should just be a thing anyway why do I have to write it myself

1 Like