Question by
dandepeched · Sep 27, 2018 at 07:20 PM ·
shadersoptimizationshader programmingshader writinggradient
Shader optimization: 3 color gradient with 2 middle points
Hi, I am new in shader programming. I'm trying to adopt @JonathanCzeck solution for my purposes (https://answers.unity.com/questions/1108472/3-color-linear-gradient-shader.html)
The only difference is that I need to persist 2nd color for some width, so I introduce _Middle2 property and use it like this:
half4 color = lerp(_ColorBot, _ColorMid, IN.texcoord.y / _Middle1) * step(IN.texcoord.y, _Middle1);
if (IN.texcoord.y / _Middle1 > 1 && IN.texcoord.y / _Middle2 < 1)
{
color += _ColorMid;
}
color += lerp(_ColorMid, _ColorTop,
(IN.texcoord.y - _Middle2) / (1 - _Middle2)) * (1 - step(IN.texcoord.y, _Middle2));
I was wondering if there is more optimal way to persist _ColorMid without using if statement.
Comment
Your answer
Follow this Question
Related Questions
Explain me this light-shader please 0 Answers
Translucent Transparent Diffuse Sprite Shader Edit 1 Answer
Add fog to vertex shader 0 Answers
A Blend Shader That Uses Vertex Information 0 Answers
Shader - SV_Target 1 Answer