0
\$\begingroup\$

I am attempting to convert this rainbow shader into just using three colors. I thought I would be able to set the three colors in the shader file, but I can't understand how to link them through the shader helper file.

shader: https://hastebin.com/uworiduluc.cs
Shader helper: https://hastebin.com/kifezufegi.cs

fixed4 frag(fragmentInput i) : SV_TARGET
{
    fixed2 lPos = i.localPosition / _Spread;
    half time = _Time.y * _Speed / _Spread;
    half timeWithOffset = time + _TimeOffset;
    fixed sine = sin(timeWithOffset);
    fixed cosine = cos(timeWithOffset);

    fixed hue = (-lPos.y) / 2.0;
    hue += time;

    while (hue < 0.0) hue += 1.0;
        while (hue > 1.0) hue -= 1.0;
            fixed4 hsl = fixed4(hue, _Saturation, _Luminosity, 1.0);

    return HSLtoRGB(hsl);
}

I added these properties at the top

_Color3 ("Top", Color) = (1,1,0,1)    
_Color2 ("Middle", Color) = (1,1,0,1)
_Color1 ("Bottom", Color) = (1,1,0,1)

But I am not sure where I can add them into the code to have them be the colors that are used.

\$\endgroup\$
  • \$\begingroup\$ Please assume every link will not be clicked, or will not work (sooner or later, everything rots). Embed a minimal complete verifiable example of the code you need help with in your question itself. This will help you get answers significantly faster. \$\endgroup\$ – DMGregory Oct 10 '19 at 17:08
  • \$\begingroup\$ Hue is the varying parameter that causes the rainbow effect. It ranges from [0,1] inclusive, so you could consider it to represent the endpoints of your gradient. Have you tried linear interpolation between your colors i.e. Color1-Color2 in the range hue=[0,0.5] and Color2-Color3 in the range hue=[0.5,1.0]? \$\endgroup\$ – Kyy13 Oct 11 '19 at 4:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.