MCPcopy Create free account
hub / github.com/esengine/esengine / valueNoise2D

Function valueNoise2D

packages/particle/src/modules/NoiseModule.ts:24–39  ·  view source on GitHub ↗
(x: number, y: number)

Source from the content-addressed store, hash-verified

22 * Simplified value noise using bilinear interpolation, returns value in [-1, 1] range
23 */
24export 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 * 噪声模块 - 添加随机扰动

Callers 2

updateFunction · 0.90
updateMethod · 0.85

Calls 1

noiseHashFunction · 0.85

Tested by

no test coverage detected