| 22 | * Simplified value noise using bilinear interpolation, returns value in [-1, 1] range |
| 23 | */ |
| 24 | export function valueNoise2D(x: number, y: number): number { |
| 25 | const ix = Math.floor(x); |
| 26 | const iy = Math.floor(y); |
| 27 | const fx = x - ix; |
| 28 | const fy = y - iy; |
| 29 | |
| 30 | const n00 = noiseHash(ix, iy); |
| 31 | const n10 = noiseHash(ix + 1, iy); |
| 32 | const n01 = noiseHash(ix, iy + 1); |
| 33 | const n11 = noiseHash(ix + 1, iy + 1); |
| 34 | |
| 35 | // 双线性插值 | Bilinear interpolation |
| 36 | const nx0 = n00 + (n10 - n00) * fx; |
| 37 | const nx1 = n01 + (n11 - n01) * fx; |
| 38 | return (nx0 + (nx1 - nx0) * fy) * 2 - 1; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * 噪声模块 - 添加随机扰动 |