我在着色器书中遇到了这个 2D 噪声函数
float noise(vec2 st) {
vec2 integerPart = floor(st);
vec2 fractionalPart = fract(st);
float s00 = random(integerPart);
float s01 = random(integerPart + vec2(0.0, 1.0));
float s10 = random(integerPart + vec2(1.0, 0.0));
float s11 = random(integerPart + vec2(1.0, 1.0));
float dx1 = s10 - s00;
float dx2 = s11 - s01;
float dy1 = s01 - s00;
float dy2 = s11 - s10;
float alpha = smoothstep(0.0, 1.0, fractionalPart.x);
float beta = smoothstep(0.0, 1.0, fractionalPart.y);
return s00 + alpha * dx1 + (1 - alpha) * beta * dy1 + alpha * beta * dy2;
}
这个函数的作用很清楚:它在正方形的顶点生成四个随机数,然后对它们进行插值。我发现困难的是理解为什么插值(s00 + alpha * dx1 + (1 - alpha) * beta * dy1 + alpha * beta * dy2
表达式)有效。当 x 和 y 值似乎不是对称的时,它是如何对这四个值进行插值的?