I want to get the pixelcolor by interpolarating between 3 colors based on the models world Y position and the key height for the colors. I could use if statements, but that is a no-go on shader coding.
float _HeightMiddle = 10.0; //color = c0 at y=0 to c1 at y=10
float _HeightMax = 200.0; //color = c1 at y=10 to c2 at y=200
fixed4 frag (v2f i) : SV_Target {
fixed4 c0 = fixed4(0.4, 0.4, 0.4, 1);
fixed4 c1 = fixed4(0, 1, 1, 0.8);
fixed4 c2 = fixed4(0, 1, 1, 0.2);
fixed4 col = lerp(c0, lerp(c1, c2, i.worldPos.y / 200), i.worldPos.y / 10);
return col;
}
But this gives wrong colors (using the colors above, the pixels on ground a.k.a. c0 are red instead of mig-grey).
Also somehow the shader produces different results when using variables so I hardcoded them.