- Home /
Color lerping with multiple fractions
I'm making a script to blend between 2 sprites' textures, and I've got one value which I am using to control the blending, which is based on how far from the edge of the texture the pixel is. My problem is that I want to add a bias to say how much I want each sprite to affect the final result. I can't figure out a way of doing it with Color.Lerp()
. Here is my attempt at fixing the problem using my own custom interpolation:(pixels1[loc] * (1 - bias) * (1 - frac) + pixels2[loc] * bias * frac) / 2
This produces a darkened edge at one side of the image. My method, however, is producing the correct amount of blending, other than the brightness being incorrect.!
Here are examples with the bias at 0 and 0.5.
[1]: /storage/temp/113946-half.png
Answer by AlexDavies · Mar 29, 2018 at 08:21 PM
Nevermind. I managed to get it working with this code:
(pixels1[loc] * (1 - bias) * (1 - frac) + pixels2[loc] * bias * frac) / ((1 - bias) * (1 - frac) + bias * frac);