diff options
author | pommicket <pommicket@gmail.com> | 2023-08-22 15:06:25 -0400 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2023-08-22 15:06:25 -0400 |
commit | 555f5f982efa85e9ba53b8506f4c8c186aac1677 (patch) | |
tree | b0b1b5f9b994cafa3a6d5af1c48781b9e50e6c54 /fractiform.js | |
parent | 06cfd9c0c769e58f6189ec97d4c35f0db6d732b0 (diff) |
worley noise
Diffstat (limited to 'fractiform.js')
-rw-r--r-- | fractiform.js | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/fractiform.js b/fractiform.js index eeb65b3..3ade087 100644 --- a/fractiform.js +++ b/fractiform.js @@ -6,8 +6,6 @@ TODO: - settings: - enable/disable auto-update - resolution -- widgets: - - worley noise */ const APP_ID = 'fractiform'; @@ -866,6 +864,46 @@ float perlin(vec3 x, vec3 freq) { return p * 0.5 + 0.5; } `, + ` +//! .name: Worley noise +//! .description: n-dimensional Worley noise +//! .category: noise +//! p.name: x +//! p.id: x +//! p.default: .pos +//! freq.default: 8 +//! .require: wnoise + +float worley(vec2 p, vec2 freq) { + p *= freq; + vec2 f = floor(p); + float sqd = 1.0; + for (float dx = -1.0; dx <= +1.0; dx += 1.0) { + for (float dy = -1.0; dy <= +1.0; dy += 1.0) { + vec2 g = f + vec2(dx, dy); + vec2 c = g + vec2(wnoise(g), wnoise(vec3(g, 1.0))); + sqd = min(sqd, dot(c - p, c - p)); + } + } + return sqrt(sqd); +} + +float worley(vec3 p, vec3 freq) { + p *= freq; + vec3 f = floor(p); + float sqd = 1.0; + for (float dx = -1.0; dx <= +1.0; dx += 1.0) { + for (float dy = -1.0; dy <= +1.0; dy += 1.0) { + for (float dz = -1.0; dz <= +1.0; dz += 1.0) { + vec3 g = f + vec3(dx, dy, dz); + vec3 c = g + vec3(wnoise(g), wnoise(vec4(g, 1.0)), wnoise(vec4(g, 2.0))); + sqd = min(sqd, dot(c - p, c - p)); + } + } + } + return sqrt(sqd); +} +`, ]; function auto_update_enabled() { |