Given the polynomial coefficients of a 4 * 4 polynomial surface,
f(x,y) = p00 + p10*x + p01*y + p20*x^2 + p11*x*y + p02*y^2 + p30*x^3 + p21*x^2*y + p12*x*y^2 + p03*y^3 + p40*x^4 + p31*x^3*y + p22*x^2*y^2 + p13*x*y^3 + p04*y^4
how to conveniently compute f(x, y) in a shader?
If we just do a multiplication of 2 vectors each consists of 15 elements, it’s easy to make mistakes when composing the vectors. So I did a practice to use matrix to represent the equation for a 2 * 2 polynomial:
f(x,y) = p00 + p10*x + p01*y + p20*x^2 + p11*x*y + p02*y^2 =
Much cleaner right? Now we can use a generic matrix to represent a n * n polynomial:
f(x, y) = YPX,
where P is a (n + 1) * (n + 1) matrix of the coefficients:
P = [p_00, p_10, p_20, ............., p_n0
p_01, p_11, p_21, ......, p_(n-1)1, 0
p_02, p_12, p_22, ..., p_(n-2)2, 0, 0
p_0n, 0, 0, ......................, 0],
Y is a 1 * (n + 1) vector for y values:
Y = [1, y, y^2, ..., y^n],
X is a (n + 1) * 1 vector for x values:
X = [1, x, x^2, ..., x^n]^T.