- Home /
Shader Graph | How to create gradient from scratch
I want to create a gradient using 3 colors. I can blend between 2 colors using a lerp & position parameter. How can I add a 3rd (4th, 5th) color as well?
I also tried a second method, in wich I try to create a mask for each color, but I'm stuck there as well. Unity should just make the gradient parametre exposable in the material properties panel already...
Is it not possible to expose gradients in the inspector? You definitely can for VFX graphs, and I imagine they use almost the same inspector plumbing. That's pretty bizarre.
Answer by launzone · Oct 26, 2020 at 06:52 PM
Hey @smirlianos, I stumbled upon this thread because I was trying to do the same thing in shader graph. I had to dig out some old shader code that a friend of mine developed and translated it into nodes. Here is a blogpost about the original shader code from my friend Hang. It looks kind of complicated but it is actually just simple steps, just a lot of them:
This is a kind of rigid approach, it only works for linear gradients with exactly 3 colors and the middle color is at 0.5
I made a simple sketch to try to explain it:
Basically you give an input value (x) from 0-1 that controls which point of the gradient you are evaluating. Then for each of the colors you have to do some calculations to figure out what the colors current value (y) should be. At the end you add the 3 separate colors together. Hope that helps!
Your answer
Follow this Question
Related Questions
Unity 2020.2 Shader Graph update issue 0 Answers
How to do billboard shader with Shadergraph 5 Answers
procedurally generated gradient 2 Answers
How to draw GL Lines over GameObjects/Images? 1 Answer
ShaderGraph Material Color change. 0 Answers