Edge blending

Hi,
I have a rather simple shader which linearly darkens colors to realize edge blending. Let’s look at it for the left side:

fixed4 frag(v2f i) : SV_Target
{
    fixed4 color = tex2D(_MainTex, i.uv);
    color.rgb = (i.uv.x / xlen) * step(i.uv.x, xlen) * color.rgb + color.rgb * step(xlen + 0.0001, i.uv.x);
    return color;
}

where xlen is the width of the blending area. Unfortunately there’s a visual impression of a slightly brighter area at the lower side of the gradient (s. attachement).
I can’t get rid of it :frowning: and I would be very grateful for an explanation, why this area is there and what I could do against it.

BTW, I needed to add 0.0001 for the part of the unchanged color, because for some values of xlen there was an unblended line (really, really bright) - is there another way to solve that doubling?

Thanks!

do return saturate(color); at the end to ensure it stays in 0-1 range.

Hi,

well, I checked that “line” with a color picker - it’s not really brighter. It’s only a visual impression, I’d say. Especially if the gradient ends inside a somewhat mono colored, not too dark, area.

Nevertheless, I tried “return saturate”, but nothing in this visual impression changed. There is, however, no need for this mentioned “0.0001” anymore when I use saturate in the color.rgb assignment. Thank you for bringing my attention to it!

But still - any idea how I could improve the quality of the gradient? I tried to use lerp, but the brighter line is still there :frowning: