- Home /
Question by
jister · Oct 05, 2016 at 06:16 PM ·
c#vectormathfcolor.lerp
Lerp Color between 4 corners
Given 4 color values at each corner of a quad. how would i lerp between them so that i start with the right color and end with the right color at each corner?
Comment
Best Answer
Answer by elenzil · Oct 05, 2016 at 06:24 PM
this is known as Bilinear Interpolation, and 3D hardware does it literally all the time.
if you want to do it yourself, it might look something like this: (not tested)
assuming a coordinate system something like this,
with a different color at each corner,
what's the color at u, v ?
0, 1 1, 1
*-----------------------*
| |
| |
| * |
| u, v |
| |
| |
| |
| |
*-----------------------*
0, 0 1, 0
Color bilinear(Color[,] corners, Vector2 uv) {
Color cTop = Color.lerp(corners[0, 1], corners[1, 1], uv.x);
Color cBot = Color.lerp(corners[0, 0], corners[1, 0], uv.x);
Color cUV = Color.lerp(cBot, cTop, uv.y);
return cUV;
}
Your answer
Follow this Question
Related Questions
Math help if possible, angle calculation 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Flip over an object (smooth transition) 3 Answers
Wrong rotation while moving 1 Answer