Как-то так решил.
public struct BarycentricInterpolateColor
{
BaricentricLinearV bar;
public Vector3 color;
public Vector3 c ;
private Vector3 dfx;
private Vector3 dfy;
public BaricentricInterpolateColor(Vector2 p0, Vector2 p1, Vector2 p2,Vector3 cv0,Vector3 cv1,Vector3 cv2 )
{
bar = new BaricentricLinearV(p0, p1, p2);
var p= new Vector2(0,0);
var w0 = (p1.Y - p2.Y) * (p.X - p2.X) + (p2.X - p1.X) * (p.Y - p2.Y);
var w1 = (p2.Y - p0.Y) * (p.X - p2.X) + (p0.X - p2.X) * (p.Y - p2.Y);
var d = (p1.Y - p2.Y) * (p0.X - p2.X) + (p2.X - p1.X) * (p0.Y - p2.Y);
w0 /= d;
w1 /= d;
var w2 = 1f - w0 - w1;
// находим вектора для решения уравнения f(x,y) = kx*x+ky*y + c
var b = (cv0 * w0 + cv1 * w1 + cv2 * w2);
color = b;
c = b;
dfx = (cv0 * (p1.Y - p2.Y) + cv1 * (p2.Y - p0.Y) + cv2 * (1f- (p1.Y - p0.Y) ))/d;
dfy = (cv0 * (p2.X - p1.X) + cv1 * (p0.X - p2.X) + cv2 * (1f -(-p1.X + p0.X)))/d;
}
public void Setup(Vector2 leftTop )
{
bar.Setup(leftTop);
color = dfy*leftTop.Y + c;
}
public bool IsInsideSafe
{
get
{
unsafe
{
return bar.IsInsideSafe;
}
}
}
public void IncX()
{
bar.IncX();
color += dfx;
}
public void IncY()
{
bar.IncY();
color += dfy;
}
}