GLSL and Shadertoy shader skills for Claude Code, Codex, Cursor, Copilot and Gemini CLI. 186 functions, SDF raymarching, procedural terrain, water, clouds and generative art, with a bundler, checker and 11 examples.
Python agent-skillsclaude-codecodexcomputer-graphicscursorgemini-cligenerative-artgithub-copilotglslnoiseprocedural-artprocedural-generationraymarchingshadersshadertoysigned-distance-functionsterrain-generationwebglwebgl2
Add noise learning progression and practical shader use cases (#1)
Gökay Aydoğanc2e192385a75
diff --git a/CREDITS.md b/CREDITS.mdindex 3c89c03..c8d8750 100644--- a/CREDITS.md+++ b/CREDITS.md@@ -30,6 +30,11 @@ default to CC BY-NC-SA 3.0, which is incompatible with MIT.| Simplex noise and its analytic gradient | Stefan Gustavson, "Simplex noise demystified" (2005); Gustavson and McEwan, "Tiling simplex noise and flow noise in two and three dimensions", JCGT 11(1), 2022 | papers; math reimplemented, the psrdnoise reference code is not used || Flow noise (rotating gradients) | Perlin and Neyret, "Flow Noise", SIGGRAPH 2001 technical sketch | math || Turbulence | Ken Perlin, "An Image Synthesizer", SIGGRAPH 1985 | math |+| Gradient-noise learning reference | [Ken Perlin, improved noise](https://cs.nyu.edu/~perlin/noise/) | reference only; fixed-permutation Java code not copied |+| Noise progression: fBm, ridges, cellular construction, domain warping | [Gonzalez Vivo and Lowe, The Book of Shaders, chapters 12](https://thebookofshaders.com/12/) and [13](https://thebookofshaders.com/13/) | explanatory sources; no source code copied |+| External noise code catalog | [Gustavson / Ashima, webgl-noise](https://github.com/stegu/webgl-noise), [psrdnoise](https://github.com/stegu/psrdnoise), [Auburn, FastNoise Lite](https://github.com/Auburn/FastNoiseLite) | MIT alternatives linked in the use-case guide; not vendored |+| Billow terminology | [libnoise Billow documentation](https://libnoise.sourceforge.net/docs/classnoise_1_1module_1_1Billow.html) | reference only; code not copied; local weighted [0,1] billow differs |+| Hybrid terrain height and designed river composition | this repository, `hybridTerrainHeight` / `noise-terrain-map.glsl` | original MIT composition; not a claim to implement Musgrave's hybrid multifractal or hydrological erosion || Sum-of-sines water with sharpened crests, deep-water dispersion | Mark Finch, "Effective Water Simulation from Physical Models", GPU Gems (2004), chapter 1 | math || Filtering vanished normal detail into roughness | Toksvig, "Mipmapping Normal Maps" (2005); Olano and Baker, "LEAN Mapping" (I3D 2010) | math || Four-arc (Moss) egg | classical compass construction | geometry |diff --git a/README.md b/README.mdindex 5f915bf..3205913 100644--- a/README.md+++ b/README.md@@ -2,7 +2,7 @@A skill that teaches coding agents to write procedural GLSL shaders that compile on the first try and lookintentional. It works with Claude Code, Codex, Cursor, Copilot, Gemini and others. It pairs a shader-craft-workflow with a **verified GLSL building-block library**: 179 functions across 18 modules, each one compiled in+workflow with a **verified GLSL building-block library**: 180 functions across 18 modules, each one compiled inWebGL2 and numerically tested on the GPU. A bundler inlines exactly the functions a shader uses, so the resultpastes straight into Shadertoy.@@ -90,7 +90,7 @@ What the commands do:| Module | Highlights ||---|---|| `hash` | PCG integer hashes (`pcg3d`, `pcg4d`): bit-exact across GPUs, no sine; safe integer-input float wrappers |-| `noise` | value and gradient noise with analytic derivatives, fBm, eroded fBm, ridged fBm, two-level domain warp, curl noise, Voronoi (F1/F2, exact borders, smooth), interleaved-gradient and R2 dithering |+| `noise` | value, gradient and 2D simplex noise with analytic derivatives, fBm, eroded/ridged/billow fBm, two-level domain warp, hybrid terrain height, curl noise, Voronoi (F1/F2, borders, smooth), interleaved-gradient and R2 dithering || `pattern` | box-filtered checker, grid and stripes (alias-free with no supersampling), hex grid with edge distance, Truchet || `sdf3d` | 22 primitives including exact capped cone, round cone, cut and hollow spheres, death star, hex prism, link, gyroid, 3D Bézier tube || `sdf2d` | 16 primitives including vesica, moon, heart, star, regular polygon, rounded box with per-corner radii, quadratic Bézier |@@ -105,14 +105,46 @@ What the commands do:The full catalog with signatures, exactness and uses is[`references/library-index.md`](skills/shader-art-coding/references/library-index.md).+## Noise: from a first field to a game use case++The [noise learning guide](skills/shader-art-coding/references/noise-use-cases.md) covers all ten entries in the+Noise Learning Progression reference: what each means, where its code lives, when to use it, tuning, and links to+author-maintained external implementations. It includes eleven compile-checked recipes and two complete shaders.++| Technique | Call the library | Use it for |+|---|---|---|+| Perlin-style gradient | `gradientNoise`, `gradientNoiseD` | Broad hills, weather masks, surface normals |+| Voronoi | `voronoiBorder`, `smoothVoronoi` | Rock plates, constant-width cracks, cell walls |+| Simplex | `simplexNoise`, `simplexNoiseD` | Ripples, rotating-gradient flow, churning lava |+| Fractal / fBm | `fbm`, `erodedFbm` | Multiscale terrain, clouds, slope-damped detail |+| Domain warp | `warpedFbm` | Marble, agate, distorted terrain and cloud bands |+| Value | `valueNoise`, `valueNoiseD` | Cheap smooth masks; quantize inputs for retro blocks |+| Cellular / Worley | `voronoi` F1/F2 and cell IDs | Biome regions, foam, per-stone variation |+| Ridged | `ridgedFbm` | Mountain crests, canyons, rocky veins |+| Billow | `billowFbm` | Puffy smoke, cumulus lobes, rounded terrain |+| Hybrid | `hybridTerrainHeight` | Bounded heightmaps combining warped hills, ridges and cells |++These functions are in [`noise.glsl`](skills/shader-art-coding/glsl/noise.glsl). Voronoi and Worley refer to the+same cellular family here; fBm and domain warping compose base fields. Simplex performance depends on implementation+and target hardware. The guide distinguishes smooth value noise from blocky hashes and designed river masks from+hydrological simulation.++| [](gallery/noise-progression.glsl) | [](gallery/noise-terrain-map.glsl) |+|---|---|+| Top: gradient, Voronoi borders, simplex, fBm, marble warp. Bottom: smooth value, F2−F1 cellular, ridged, billow, hybrid. | Putting it together: warped hills, ridged mountains, cellular breakup, slope-based materials and a designed river channel. |++Click a preview for the standalone Shadertoy shader. Editable sources:+[`noise-progression.glsl`](skills/shader-art-coding/templates/noise-progression.glsl) and+[`noise-terrain-map.glsl`](skills/shader-art-coding/templates/noise-terrain-map.glsl).+## Verification| Check | Where | What it proves ||---|---|---|| Lint + drift | `glsl_tools.py check` | docs and tags on every function, module order, no WebGL1 or sine-hash patterns, reference snippets identical to the library || glslang compile | CI (`checks.yml`) | every library module, reference snippet and template compiles as GLSL ES 3.00 |-| WebGL2 compile | `tests/` harness | all 147 units compile under ANGLE, which also enforces WebGL-only rules |-| GPU property tests | `tests/properties.py` | 84 tests × 16,384 samples: Lipschitz, exactness, signs, brute-force curve distance, derivatives, divergence, ranges, round trips |+| WebGL2 compile | `tests/` harness | all 160 units compile under ANGLE, which also enforces WebGL-only rules |+| GPU property tests | `tests/properties.py` | 85 tests × 16,384 samples: Lipschitz, exactness, signs, brute-force curve distance, derivatives, divergence, ranges, round trips || Renders | harness + gallery | every template renders with no NaNs and no black frames; images saved to `gallery/` || Skill effect | `evals/` (`claude plugin eval`, paid, manual) | output-rule adherence with the skill vs without it on 6 shader tasks, plus no false triggers on 3 near-miss tasks; see [evals/README.md](evals/README.md) |diff --git a/gallery/noise-progression.glsl b/gallery/noise-progression.glslnew file mode 100644index 0000000..ba75c3c--- /dev/null+++ b/gallery/noise-progression.glsl@@ -0,0 +1,391 @@+// Ten noise studies, matching the learning progression in references/noise-use-cases.md.+// Top row, left to right: Perlin-style gradient, Voronoi borders, simplex, fBm, domain warp.+// Bottom row: smooth value, Worley F1/F2, ridged, billow, hybrid terrain height.+// Base noise and layered noise deliberately look different: a single octave is not a cloud texture.+// @render time=2.0+#define DEBUG_MODE 0 // 0 grayscale | 3 tile IDs | 5 unclipped scalar false color++// Library code below is bundled from shader-skills (MIT): https://github.com/gokayfem/shader-skills+// ---- shader-skills library: common ----+const float TAU = 6.28318530717959;+// Clamp to [0,1].+float saturate(float x) { return clamp(x, 0.0, 1.0); }+vec3 saturate(vec3 x) { return clamp(x, 0.0, 1.0); }+// Squared length.+float dot2(vec2 v) { return dot(v, v); }+float dot2(vec3 v) { return dot(v, v); }+// 2D rotation matrix. `rot2(a) * v` rotates v counter-clockwise by a radians. (cos, sin) is renormalized because GLSL ES leaves trig precision undefined: on SwiftShader and some mobile GPUs a raw cos/sin pair is far enough from unit length that rotations stop preserving distances.+mat2 rot2(float a) {+ vec2 cs = normalize(vec2(cos(a), sin(a)));+ return mat2(cs.x, cs.y, -cs.y, cs.x);+}++// ---- shader-skills library: hash ----+// PCG-style 1D integer hash.+uint pcgHash(uint v) {+ uint state = v * 747796405u + 2891336453u;+ uint word = ((state >> ((state >> 28u) + 4u)) ^ state) * 277803737u;+ return (word >> 22u) ^ word;+}+// 3D integer hash, three decorrelated outputs.+uvec3 pcg3d(uvec3 v) {+ v = v * 1664525u + 1013904223u;+ v.x += v.y * v.z;+ v.y += v.z * v.x;+ v.z += v.x * v.y;+ v ^= v >> 16u;+ v.x += v.y * v.z;+ v.y += v.z * v.x;+ v.z += v.x * v.y;+ return v;+}+// Map a uint to [0,1) using the top 24 bits, so the result can never round up to 1.0.+float uintToUnit(uint h) { return float(h >> 8u) * (1.0 / 16777216.0); }+vec2 uintToUnit(uvec2 h) { return vec2(h >> 8u) * (1.0 / 16777216.0); }+vec3 uintToUnit(uvec3 h) { return vec3(h >> 8u) * (1.0 / 16777216.0); }+vec4 uintToUnit(uvec4 h) { return vec4(h >> 8u) * (1.0 / 16777216.0); }+// Random float in [0,1) for an integer-valued 2D input.+float hash12(vec2 p) {+ uvec2 q = uvec2(ivec2(floor(p)));+ return uintToUnit(pcgHash(q.x + pcgHash(q.y)));+}+// Random float in [0,1) for an integer-valued 3D input.+float hash13(vec3 p) {+ uvec3 q = uvec3(ivec3(floor(p)));+ return uintToUnit(pcgHash(q.x + pcgHash(q.y + pcgHash(q.z))));+}+// Random vec2 in [0,1)^2 for an integer-valued 2D input.+vec2 hash22(vec2 p) {+ ivec2 q = ivec2(floor(p));+ return uintToUnit(pcg3d(uvec3(q.x, q.y, 0x2545u))).xy;+}+// Random vec3 in [0,1)^3 for an integer-valued 3D input.+vec3 hash33(vec3 p) { return uintToUnit(pcg3d(uvec3(ivec3(floor(p))))); }++// ---- shader-skills library: noise ----+// Quintic fade 6t^5 - 15t^4 + 10t^3: C2-continuous interpolation weights for lattice noise.+vec2 quinticFade(vec2 f) { return f * f * f * (f * (f * 6.0 - 15.0) + 10.0); }+vec3 quinticFade(vec3 f) { return f * f * f * (f * (f * 6.0 - 15.0) + 10.0); }+// Derivative of quinticFade: 30 t^2 (t - 1)^2.+vec2 quinticFadeDeriv(vec2 f) { return 30.0 * f * f * (f * (f - 2.0) + 1.0); }+vec3 quinticFadeDeriv(vec3 f) { return 30.0 * f * f * (f * (f - 2.0) + 1.0); }+// 2D value noise with analytic derivatives. Returns vec3(value, d/dx, d/dy).+vec3 valueNoiseD(vec2 p) {+ vec2 i = floor(p), f = fract(p);+ vec2 u = quinticFade(f), du = quinticFadeDeriv(f);+ float a = hash12(i);+ float b = hash12(i + vec2(1.0, 0.0));+ float c = hash12(i + vec2(0.0, 1.0));+ float d = hash12(i + vec2(1.0, 1.0));+ float k1 = b - a, k2 = c - a, k3 = a - b - c + d;+ return vec3(a + k1 * u.x + k2 * u.y + k3 * u.x * u.y,+ du * vec2(k1 + k3 * u.y, k2 + k3 * u.x));+}+// 2D value noise.+float valueNoise(vec2 p) { return valueNoiseD(p).x; }+// 3D value noise.+float valueNoise(vec3 p) {+ vec3 i = floor(p), f = fract(p);+ vec3 u = quinticFade(f);+ return mix(mix(mix(hash13(i + vec3(0, 0, 0)), hash13(i + vec3(1, 0, 0)), u.x),+ mix(hash13(i + vec3(0, 1, 0)), hash13(i + vec3(1, 1, 0)), u.x), u.y),+ mix(mix(hash13(i + vec3(0, 0, 1)), hash13(i + vec3(1, 0, 1)), u.x),+ mix(hash13(i + vec3(0, 1, 1)), hash13(i + vec3(1, 1, 1)), u.x), u.y), u.z);+}+// Unit gradient for a 2D lattice point.+vec2 latticeGradient(vec2 cell) {+ float a = TAU * hash12(cell);+ return vec2(cos(a), sin(a));+}+// 2D gradient (Perlin-style) noise with analytic derivatives. Returns vec3(value, d/dx, d/dy). Gradient noise has less grid-aligned blockiness than value noise. Prefer it for fBm.+vec3 gradientNoiseD(vec2 p) {+ vec2 i = floor(p), f = fract(p);+ vec2 u = quinticFade(f), du = quinticFadeDeriv(f);+ vec2 ga = latticeGradient(i);+ vec2 gb = latticeGradient(i + vec2(1.0, 0.0));+ vec2 gc = latticeGradient(i + vec2(0.0, 1.0));+ vec2 gd = latticeGradient(i + vec2(1.0, 1.0));+ float va = dot(ga, f);+ float vb = dot(gb, f - vec2(1.0, 0.0));+ float vc = dot(gc, f - vec2(0.0, 1.0));+ float vd = dot(gd, f - vec2(1.0, 1.0));+ float k = va - vb - vc + vd;+ float value = va + u.x * (vb - va) + u.y * (vc - va) + u.x * u.y * k;+ vec2 deriv = ga + u.x * (gb - ga) + u.y * (gc - ga) + u.x * u.y * (ga - gb - gc + gd)+ + du * (vec2(vb - va, vc - va) + u.yx * k);+ return vec3(value, deriv);+}+// 2D gradient noise.+float gradientNoise(vec2 p) { return gradientNoiseD(p).x; }+// 2D simplex noise with analytic gradient. Returns vec3(value, d/dx, d/dy). Sums three radial kernels (0.5 - r^2)^4 on a triangular lattice instead of blending four square-cell corners, so it has fewer axis-aligned artifacts than gradientNoise. rotation (radians) spins every lattice gradient: animating it gives flow noise that churns in place instead of sliding (Perlin and Neyret 2001). Scaled so |value| <= 1 exactly.+vec3 simplexNoiseD(vec2 p, float rotation) {+ const float SKEW = 0.36602540378; // (sqrt(3) - 1) / 2: square lattice -> triangle lattice+ const float UNSKEW = 0.21132486541; // (3 - sqrt(3)) / 6+ vec2 cell = floor(p + (p.x + p.y) * SKEW);+ vec2 d0 = p - cell + (cell.x + cell.y) * UNSKEW;+ vec2 o = (d0.x > d0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0); // which of the cell's two triangles holds p+ vec2 corners[3] = vec2[3](cell, cell + o, cell + 1.0);+ vec2 offsets[3] = vec2[3](d0, d0 - o + UNSKEW, d0 - 1.0 + 2.0 * UNSKEW);+ mat2 spin = rot2(rotation);+ vec3 sum = vec3(0.0);+ for (int k = 0; k < 3; k++) {+ vec2 d = offsets[k];+ float t = max(0.5 - dot(d, d), 0.0);+ vec2 g = spin * latticeGradient(corners[k]);+ float gd = dot(g, d);+ float t3 = t * t * t;+ // value t^4 (g.d); gradient t^4 g - 8 t^3 (g.d) d+ sum += vec3(t3 * t * gd, t3 * t * g - 8.0 * t3 * gd * d);+ }+ return 99.2 * sum; // 1 / max over the simplex of sum t^4 |d|+}+vec3 simplexNoiseD(vec2 p) { return simplexNoiseD(p, 0.0); }+// 2D simplex noise.+float simplexNoise(vec2 p) { return simplexNoiseD(p, 0.0).x; }+// Dot product of a hashed 3D gradient with the offset to its lattice corner.+float latticeGradDot(vec3 cell, vec3 corner, vec3 f) {+ vec3 g = hash33(cell + corner) * 2.0 - 1.0;+ return dot(g, f - corner);+}+// 3D gradient noise.+float gradientNoise(vec3 p) {+ vec3 i = floor(p), f = fract(p);+ vec3 u = quinticFade(f);+ return mix(mix(mix(latticeGradDot(i, vec3(0, 0, 0), f), latticeGradDot(i, vec3(1, 0, 0), f), u.x),+ mix(latticeGradDot(i, vec3(0, 1, 0), f), latticeGradDot(i, vec3(1, 1, 0), f), u.x), u.y),+ mix(mix(latticeGradDot(i, vec3(0, 0, 1), f), latticeGradDot(i, vec3(1, 0, 1), f), u.x),+ mix(latticeGradDot(i, vec3(0, 1, 1), f), latticeGradDot(i, vec3(1, 1, 1), f), u.x), u.y), u.z);+}+// 3D gradient noise with analytic derivatives. Returns vec4(value, d/dx, d/dy, d/dz); value equals gradientNoise(p). The trilinear blend is expanded as a polynomial in the fade weights, so the gradient is the same blend of the corner gradients plus the chain-rule term of the fade.+vec4 gradientNoiseD(vec3 p) {+ vec3 i = floor(p), f = fract(p);+ vec3 u = quinticFade(f), du = quinticFadeDeriv(f);+ vec3 g000 = hash33(i) * 2.0 - 1.0;+ vec3 g100 = hash33(i + vec3(1, 0, 0)) * 2.0 - 1.0;+ vec3 g010 = hash33(i + vec3(0, 1, 0)) * 2.0 - 1.0;+ vec3 g110 = hash33(i + vec3(1, 1, 0)) * 2.0 - 1.0;+ vec3 g001 = hash33(i + vec3(0, 0, 1)) * 2.0 - 1.0;+ vec3 g101 = hash33(i + vec3(1, 0, 1)) * 2.0 - 1.0;+ vec3 g011 = hash33(i + vec3(0, 1, 1)) * 2.0 - 1.0;+ vec3 g111 = hash33(i + vec3(1, 1, 1)) * 2.0 - 1.0;+ float v000 = dot(g000, f);+ float v100 = dot(g100, f - vec3(1, 0, 0));+ float v010 = dot(g010, f - vec3(0, 1, 0));+ float v110 = dot(g110, f - vec3(1, 1, 0));+ float v001 = dot(g001, f - vec3(0, 0, 1));+ float v101 = dot(g101, f - vec3(1, 0, 1));+ float v011 = dot(g011, f - vec3(0, 1, 1));+ float v111 = dot(g111, f - vec3(1, 1, 1));+ // value = v000 + kx u.x + ky u.y + kz u.z + kxy u.x u.y + kyz u.y u.z + kzx u.z u.x + kxyz u.x u.y u.z+ float kx = v100 - v000, ky = v010 - v000, kz = v001 - v000;+ float kxy = v000 - v100 - v010 + v110;+ float kyz = v000 - v010 - v001 + v011;+ float kzx = v000 - v100 - v001 + v101;+ float kxyz = -v000 + v100 + v010 - v110 + v001 - v101 - v011 + v111;+ float value = v000 + kx * u.x + ky * u.y + kz * u.z+ + kxy * u.x * u.y + kyz * u.y * u.z + kzx * u.z * u.x + kxyz * u.x * u.y * u.z;+ vec3 grad = g000 + (g100 - g000) * u.x + (g010 - g000) * u.y + (g001 - g000) * u.z+ + (g000 - g100 - g010 + g110) * u.x * u.y+ + (g000 - g010 - g001 + g011) * u.y * u.z+ + (g000 - g100 - g001 + g101) * u.z * u.x+ + (-g000 + g100 + g010 - g110 + g001 - g101 - g011 + g111) * u.x * u.y * u.z+ + du * vec3(kx + kxy * u.y + kzx * u.z + kxyz * u.y * u.z,+ ky + kxy * u.x + kyz * u.z + kxyz * u.x * u.z,+ kz + kyz * u.y + kzx * u.x + kxyz * u.x * u.y);+ return vec4(value, grad);+}+const int FBM_MAX_OCTAVES = 12;+// Fractional Brownian motion over 2D gradient noise. Each octave is rotated to hide lattice alignment. persistence 0.5 is the classic look (H = 1). Lower is smoother, higher is rougher.+float fbm(vec2 p, int octaves, float lacunarity, float persistence) {+ const mat2 octaveRotation = mat2(0.8, 0.6, -0.6, 0.8);+ float sum = 0.0, amp = 1.0, norm = 0.0;+ for (int i = 0; i < FBM_MAX_OCTAVES; i++) {+ if (i >= octaves) break;+ sum += amp * gradientNoise(p);+ norm += amp;+ amp *= persistence;+ p = lacunarity * (octaveRotation * p) + vec2(17.13, -3.71);+ }+ return 1.4 * sum / norm;+}+// 2D fBm with the usual defaults (lacunarity 2.01 so octave peaks never re-align, persistence 0.5).+float fbm(vec2 p, int octaves) { return fbm(p, octaves, 2.01, 0.5); }+// fBm over 3D gradient noise.+float fbm(vec3 p, int octaves, float lacunarity, float persistence) {+ const mat3 octaveRotation = mat3(0.00, 0.80, 0.60,+ -0.80, 0.36, -0.48,+ -0.60, -0.48, 0.64);+ float sum = 0.0, amp = 1.0, norm = 0.0;+ for (int i = 0; i < FBM_MAX_OCTAVES; i++) {+ if (i >= octaves) break;+ sum += amp * gradientNoise(p);+ norm += amp;+ amp *= persistence;+ p = lacunarity * (octaveRotation * p) + vec3(17.13, -3.71, 5.29);+ }+ return sum / norm;+}+// Ridged multifractal: inverted |noise| creates sharp crests; each octave is weighted by the previous one, so detail gathers along ridges.+float ridgedFbm(vec2 p, int octaves) {+ const mat2 octaveRotation = mat2(0.8, 0.6, -0.6, 0.8);+ float sum = 0.0, amp = 0.5, weight = 1.0, norm = 0.0;+ for (int i = 0; i < FBM_MAX_OCTAVES; i++) {+ if (i >= octaves) break;+ float n = 1.0 - abs(gradientNoise(p) * 1.4);+ n *= n;+ sum += amp * n * weight;+ norm += amp;+ weight = clamp(n * 2.0, 0.0, 1.0);+ amp *= 0.5;+ p = 2.01 * (octaveRotation * p) + vec2(17.13, -3.71);+ }+ return sum / norm;+}+// Billowy multifractal: |noise| per octave makes puffy rounded lobes split by sharp creases (the inverse of ridgedFbm). Each octave is weighted by the previous one, so detail gathers on the lobes while the creases stay clean.+float billowFbm(vec2 p, int octaves) {+ const mat2 octaveRotation = mat2(0.8, 0.6, -0.6, 0.8);+ float sum = 0.0, amp = 0.5, weight = 1.0, norm = 0.0;+ for (int i = 0; i < FBM_MAX_OCTAVES; i++) {+ if (i >= octaves) break;+ float n = abs(gradientNoise(p) * 1.4);+ n = n * (2.0 - n); // round the lobe tops, keep the creases sharp+ sum += amp * n * weight;+ norm += amp;+ weight = clamp(n * 1.5, 0.0, 1.0);+ amp *= 0.5;+ p = 2.01 * (octaveRotation * p) + vec2(17.13, -3.71);+ }+ return sum / norm;+}+float billowFbm(vec3 p, int octaves) {+ const mat3 octaveRotation = mat3(0.00, 0.80, 0.60,+ -0.80, 0.36, -0.48,+ -0.60, -0.48, 0.64);+ float sum = 0.0, amp = 0.5, weight = 1.0, norm = 0.0;+ for (int i = 0; i < FBM_MAX_OCTAVES; i++) {+ if (i >= octaves) break;+ float n = min(abs(gradientNoise(p)) * 1.4, 1.0);+ n = n * (2.0 - n);+ sum += amp * n * weight;+ norm += amp;+ weight = clamp(n * 1.5, 0.0, 1.0);+ amp *= 0.5;+ p = 2.01 * (octaveRotation * p) + vec3(17.13, -3.71, 5.29);+ }+ return sum / norm;+}+// Two-level domain warp f(p + s*r), r = fbm(p + s*q), q = fbm(p). Writes the intermediate warp vectors so they can drive color. Cost is 5 fBm calls.+float warpedFbm(vec2 p, float strength, int octaves, out vec2 q, out vec2 r) {+ q = vec2(fbm(p, octaves), fbm(p + vec2(3.1, 7.4), octaves));+ r = vec2(fbm(p + strength * q + vec2(9.7, 2.6), octaves),+ fbm(p + strength * q + vec2(6.3, 1.9), octaves));+ return fbm(p + strength * r, octaves);+}+// Cellular (Worley/Voronoi) noise. Returns vec4(F1, F2, nearestCell.xy). F1 = distance to nearest feature point, F2 = second nearest. nearestCell is integer-valued, so hash it for per-cell randomness. jitter in [0,1] (0 = regular grid). Searches 3x3 cells. F2 can be slightly off at jitter 1.+vec4 voronoi(vec2 p, float jitter) {+ vec2 ip = floor(p), fp = fract(p);+ float f1 = 8.0, f2 = 8.0;+ vec2 nearest = vec2(0.0);+ for (int j = -1; j <= 1; j++)+ for (int i = -1; i <= 1; i++) {+ vec2 g = vec2(float(i), float(j));+ vec2 r = g + jitter * hash22(ip + g) - fp;+ float d = dot(r, r);+ if (d < f1) { f2 = f1; f1 = d; nearest = ip + g; }+ else if (d < f2) { f2 = d; }+ }+ return vec4(sqrt(f1), sqrt(f2), nearest);+}+// Exact distance to Voronoi cell borders, found in two passes: nearest point, then nearest bisector. Returns vec3(borderDistance, vectorToNearestPoint). Unlike F2-F1, the border distance is a true distance, so lines have constant width.+vec3 voronoiBorder(vec2 p, float jitter) {+ vec2 ip = floor(p), fp = fract(p);+ vec2 mg = vec2(0.0), mr = vec2(0.0);+ float md = 8.0;+ for (int j = -1; j <= 1; j++)+ for (int i = -1; i <= 1; i++) {+ vec2 g = vec2(float(i), float(j));+ vec2 r = g + jitter * hash22(ip + g) - fp;+ float d = dot(r, r);+ if (d < md) { md = d; mr = r; mg = g; }+ }+ md = 8.0;+ for (int j = -2; j <= 2; j++)+ for (int i = -2; i <= 2; i++) {+ vec2 g = mg + vec2(float(i), float(j));+ vec2 r = g + jitter * hash22(ip + g) - fp;+ if (dot2(mr - r) > 1e-5) {+ md = min(md, dot(0.5 * (mr + r), normalize(r - mr)));+ }+ }+ return vec3(md, mr);+}+// Bounded hybrid terrain recipe: broad gradient fBm, warped ridged detail and cellular breakup. This is an artistic composition, not Musgrave's named hybrid-multifractal algorithm. Coordinates are warped before all three fields are sampled; octaves is clamped to [1, FBM_MAX_OCTAVES].+float hybridTerrainHeight(vec2 p, int octaves) {+ int count = clamp(octaves, 1, FBM_MAX_OCTAVES);+ vec2 warp = vec2(fbm(p * 0.35, count), fbm(p * 0.35 + vec2(19.1, -7.3), count));+ vec2 q = p + 0.8 * warp;+ float broad = 0.5 + 0.5 * fbm(q * 0.45, count);+ float ridges = ridgedFbm(q * 1.7, count);+ float cells = 1.0 - clamp(voronoi(q * 2.5, 0.75).x, 0.0, 1.0);+ return clamp(0.45 * broad + 0.45 * ridges + 0.10 * cells, 0.0, 1.0);+}++// ---- shader-skills library: color ----+// Cosine palette a + b * cos(2 pi (c t + d)). Output is display-like (sRGB-ish), so decode it for albedo. Integer c values loop seamlessly over t in [0,1].+vec3 cosinePalette(float t, vec3 a, vec3 b, vec3 c, vec3 d) {+ return a + b * cos(TAU * (c * t + d));+}++// ---- shader-skills library: post ----+// Triangular-PDF dither of +-1 LSB for 8-bit output. Add AFTER linearToSrgb, right before writing fragColor.+vec3 ditherTPDF(vec2 fragCoord, int frame) {+ vec2 r = hash22(vec2(floor(fragCoord) + 7919.0 * float(frame % 1024)));+ return vec3((r.x + r.y - 1.0) / 255.0);+}++// ---- shader ----+const float SCALE = 5.0;+const int OCTAVES = 5;++float noiseStudy(int id, vec2 p, float px) {+ if (id == 0) return 0.5 + 0.7 * gradientNoise(p);+ if (id == 1) return 1.0 - smoothstep(0.0, 0.13 + px, voronoiBorder(p, 0.85).x);+ if (id == 2) return 0.5 + 0.5 * simplexNoise(p);+ if (id == 3) return 0.5 + 0.5 * fbm(p, OCTAVES);+ if (id == 4) {+ vec2 q, r;+ float f = warpedFbm(p * 0.6, 1.5, 3, q, r);+ return 0.5 + 0.5 * sin(p.x * 2.0 + 6.0 * f);+ }+ if (id == 5) return valueNoise(p);+ if (id == 6) {+ vec4 cell = voronoi(p, 0.85);+ return saturate(1.8 * (cell.y - cell.x));+ }+ if (id == 7) return ridgedFbm(p, OCTAVES);+ if (id == 8) return billowFbm(p, OCTAVES);+ return hybridTerrainHeight(p, OCTAVES);+}++void mainImage(out vec4 fragColor, in vec2 fragCoord) {+ vec2 board = fragCoord / iResolution.xy * vec2(5.0, 2.0);+ ivec2 tile = ivec2(floor(board));+ int id = tile.x + (1 - tile.y) * 5;+ vec2 local = fract(board);+ vec2 p = local * SCALE + vec2(1.23, 4.56);+ float px = SCALE * 5.0 / iResolution.x;+ float f = noiseStudy(id, p, px);+ vec3 col = vec3(saturate(f)); // grayscale values are already display values+#if DEBUG_MODE == 3+ col = cosinePalette(float(id) / 10.0, vec3(0.5), vec3(0.4), vec3(1.0), vec3(0.0,0.3,0.6));+#elif DEBUG_MODE == 5+ col = vec3(max(f,0.0), max(-f,0.0), max(f-1.0,0.0));+#endif+ vec2 edge = min(local,1.0-local);+ float frame = smoothstep(0.01,0.025,min(edge.x,edge.y));+ col = mix(vec3(0.035), col, frame);+ // The small white ticks identify columns 1–5 without font/texture dependencies.+ float tick = step(0.965,local.y) * step(0.1,local.x) * step(local.x,0.1+0.03*float(tile.x+1));+ col = mix(col,vec3(0.9),tick);+ fragColor = vec4(col + ditherTPDF(fragCoord,iFrame),1.0);+}diff --git a/gallery/noise-progression.png b/gallery/noise-progression.pngnew file mode 100644index 0000000..e02347dBinary files /dev/null and b/gallery/noise-progression.png differdiff --git a/gallery/noise-terrain-map.glsl b/gallery/noise-terrain-map.glslnew file mode 100644index 0000000..e6f0148--- /dev/null+++ b/gallery/noise-terrain-map.glsl@@ -0,0 +1,284 @@+// Putting noise together: warped broad hills + ridged mountains + cellular breakup,+// with a separate warped contour used as an artistic river mask. No erosion or hydrology simulation.+// A top-down relief map keeps the composition legible and the height/mask debug views directly comparable.+// @render time=2.0+#define DEBUG_MODE 0 // 0 shaded biome map | 1 height | 2 normals | 5 river mask++// Library code below is bundled from shader-skills (MIT): https://github.com/gokayfem/shader-skills+// ---- shader-skills library: common ----+const float TAU = 6.28318530717959;++// ---- shader-skills library: hash ----+// PCG-style 1D integer hash.+uint pcgHash(uint v) {+ uint state = v * 747796405u + 2891336453u;+ uint word = ((state >> ((state >> 28u) + 4u)) ^ state) * 277803737u;+ return (word >> 22u) ^ word;+}+// 3D integer hash, three decorrelated outputs.+uvec3 pcg3d(uvec3 v) {+ v = v * 1664525u + 1013904223u;+ v.x += v.y * v.z;+ v.y += v.z * v.x;+ v.z += v.x * v.y;+ v ^= v >> 16u;+ v.x += v.y * v.z;+ v.y += v.z * v.x;+ v.z += v.x * v.y;+ return v;+}+// Map a uint to [0,1) using the top 24 bits, so the result can never round up to 1.0.+float uintToUnit(uint h) { return float(h >> 8u) * (1.0 / 16777216.0); }+vec2 uintToUnit(uvec2 h) { return vec2(h >> 8u) * (1.0 / 16777216.0); }+vec3 uintToUnit(uvec3 h) { return vec3(h >> 8u) * (1.0 / 16777216.0); }+vec4 uintToUnit(uvec4 h) { return vec4(h >> 8u) * (1.0 / 16777216.0); }+// Random float in [0,1) for an integer-valued 2D input.+float hash12(vec2 p) {+ uvec2 q = uvec2(ivec2(floor(p)));+ return uintToUnit(pcgHash(q.x + pcgHash(q.y)));+}+// Random vec2 in [0,1)^2 for an integer-valued 2D input.+vec2 hash22(vec2 p) {+ ivec2 q = ivec2(floor(p));+ return uintToUnit(pcg3d(uvec3(q.x, q.y, 0x2545u))).xy;+}+// Random vec3 in [0,1)^3 for an integer-valued 3D input.+vec3 hash33(vec3 p) { return uintToUnit(pcg3d(uvec3(ivec3(floor(p))))); }++// ---- shader-skills library: noise ----+// Quintic fade 6t^5 - 15t^4 + 10t^3: C2-continuous interpolation weights for lattice noise.+vec2 quinticFade(vec2 f) { return f * f * f * (f * (f * 6.0 - 15.0) + 10.0); }+vec3 quinticFade(vec3 f) { return f * f * f * (f * (f * 6.0 - 15.0) + 10.0); }+// Derivative of quinticFade: 30 t^2 (t - 1)^2.+vec2 quinticFadeDeriv(vec2 f) { return 30.0 * f * f * (f * (f - 2.0) + 1.0); }+vec3 quinticFadeDeriv(vec3 f) { return 30.0 * f * f * (f * (f - 2.0) + 1.0); }+// Unit gradient for a 2D lattice point.+vec2 latticeGradient(vec2 cell) {+ float a = TAU * hash12(cell);+ return vec2(cos(a), sin(a));+}+// 2D gradient (Perlin-style) noise with analytic derivatives. Returns vec3(value, d/dx, d/dy). Gradient noise has less grid-aligned blockiness than value noise. Prefer it for fBm.+vec3 gradientNoiseD(vec2 p) {+ vec2 i = floor(p), f = fract(p);+ vec2 u = quinticFade(f), du = quinticFadeDeriv(f);+ vec2 ga = latticeGradient(i);+ vec2 gb = latticeGradient(i + vec2(1.0, 0.0));+ vec2 gc = latticeGradient(i + vec2(0.0, 1.0));+ vec2 gd = latticeGradient(i + vec2(1.0, 1.0));+ float va = dot(ga, f);+ float vb = dot(gb, f - vec2(1.0, 0.0));+ float vc = dot(gc, f - vec2(0.0, 1.0));+ float vd = dot(gd, f - vec2(1.0, 1.0));+ float k = va - vb - vc + vd;+ float value = va + u.x * (vb - va) + u.y * (vc - va) + u.x * u.y * k;+ vec2 deriv = ga + u.x * (gb - ga) + u.y * (gc - ga) + u.x * u.y * (ga - gb - gc + gd)+ + du * (vec2(vb - va, vc - va) + u.yx * k);+ return vec3(value, deriv);+}+// 2D gradient noise.+float gradientNoise(vec2 p) { return gradientNoiseD(p).x; }+// Dot product of a hashed 3D gradient with the offset to its lattice corner.+float latticeGradDot(vec3 cell, vec3 corner, vec3 f) {+ vec3 g = hash33(cell + corner) * 2.0 - 1.0;+ return dot(g, f - corner);+}+// 3D gradient noise.+float gradientNoise(vec3 p) {+ vec3 i = floor(p), f = fract(p);+ vec3 u = quinticFade(f);+ return mix(mix(mix(latticeGradDot(i, vec3(0, 0, 0), f), latticeGradDot(i, vec3(1, 0, 0), f), u.x),+ mix(latticeGradDot(i, vec3(0, 1, 0), f), latticeGradDot(i, vec3(1, 1, 0), f), u.x), u.y),+ mix(mix(latticeGradDot(i, vec3(0, 0, 1), f), latticeGradDot(i, vec3(1, 0, 1), f), u.x),+ mix(latticeGradDot(i, vec3(0, 1, 1), f), latticeGradDot(i, vec3(1, 1, 1), f), u.x), u.y), u.z);+}+// 3D gradient noise with analytic derivatives. Returns vec4(value, d/dx, d/dy, d/dz); value equals gradientNoise(p). The trilinear blend is expanded as a polynomial in the fade weights, so the gradient is the same blend of the corner gradients plus the chain-rule term of the fade.+vec4 gradientNoiseD(vec3 p) {+ vec3 i = floor(p), f = fract(p);+ vec3 u = quinticFade(f), du = quinticFadeDeriv(f);+ vec3 g000 = hash33(i) * 2.0 - 1.0;+ vec3 g100 = hash33(i + vec3(1, 0, 0)) * 2.0 - 1.0;+ vec3 g010 = hash33(i + vec3(0, 1, 0)) * 2.0 - 1.0;+ vec3 g110 = hash33(i + vec3(1, 1, 0)) * 2.0 - 1.0;+ vec3 g001 = hash33(i + vec3(0, 0, 1)) * 2.0 - 1.0;+ vec3 g101 = hash33(i + vec3(1, 0, 1)) * 2.0 - 1.0;+ vec3 g011 = hash33(i + vec3(0, 1, 1)) * 2.0 - 1.0;+ vec3 g111 = hash33(i + vec3(1, 1, 1)) * 2.0 - 1.0;+ float v000 = dot(g000, f);+ float v100 = dot(g100, f - vec3(1, 0, 0));+ float v010 = dot(g010, f - vec3(0, 1, 0));+ float v110 = dot(g110, f - vec3(1, 1, 0));+ float v001 = dot(g001, f - vec3(0, 0, 1));+ float v101 = dot(g101, f - vec3(1, 0, 1));+ float v011 = dot(g011, f - vec3(0, 1, 1));+ float v111 = dot(g111, f - vec3(1, 1, 1));+ // value = v000 + kx u.x + ky u.y + kz u.z + kxy u.x u.y + kyz u.y u.z + kzx u.z u.x + kxyz u.x u.y u.z+ float kx = v100 - v000, ky = v010 - v000, kz = v001 - v000;+ float kxy = v000 - v100 - v010 + v110;+ float kyz = v000 - v010 - v001 + v011;+ float kzx = v000 - v100 - v001 + v101;+ float kxyz = -v000 + v100 + v010 - v110 + v001 - v101 - v011 + v111;+ float value = v000 + kx * u.x + ky * u.y + kz * u.z+ + kxy * u.x * u.y + kyz * u.y * u.z + kzx * u.z * u.x + kxyz * u.x * u.y * u.z;+ vec3 grad = g000 + (g100 - g000) * u.x + (g010 - g000) * u.y + (g001 - g000) * u.z+ + (g000 - g100 - g010 + g110) * u.x * u.y+ + (g000 - g010 - g001 + g011) * u.y * u.z+ + (g000 - g100 - g001 + g101) * u.z * u.x+ + (-g000 + g100 + g010 - g110 + g001 - g101 - g011 + g111) * u.x * u.y * u.z+ + du * vec3(kx + kxy * u.y + kzx * u.z + kxyz * u.y * u.z,+ ky + kxy * u.x + kyz * u.z + kxyz * u.x * u.z,+ kz + kyz * u.y + kzx * u.x + kxyz * u.x * u.y);+ return vec4(value, grad);+}+const int FBM_MAX_OCTAVES = 12;+// Fractional Brownian motion over 2D gradient noise. Each octave is rotated to hide lattice alignment. persistence 0.5 is the classic look (H = 1). Lower is smoother, higher is rougher.+float fbm(vec2 p, int octaves, float lacunarity, float persistence) {+ const mat2 octaveRotation = mat2(0.8, 0.6, -0.6, 0.8);+ float sum = 0.0, amp = 1.0, norm = 0.0;+ for (int i = 0; i < FBM_MAX_OCTAVES; i++) {+ if (i >= octaves) break;+ sum += amp * gradientNoise(p);+ norm += amp;+ amp *= persistence;+ p = lacunarity * (octaveRotation * p) + vec2(17.13, -3.71);+ }+ return 1.4 * sum / norm;+}+// 2D fBm with the usual defaults (lacunarity 2.01 so octave peaks never re-align, persistence 0.5).+float fbm(vec2 p, int octaves) { return fbm(p, octaves, 2.01, 0.5); }+// fBm over 3D gradient noise.+float fbm(vec3 p, int octaves, float lacunarity, float persistence) {+ const mat3 octaveRotation = mat3(0.00, 0.80, 0.60,+ -0.80, 0.36, -0.48,+ -0.60, -0.48, 0.64);+ float sum = 0.0, amp = 1.0, norm = 0.0;+ for (int i = 0; i < FBM_MAX_OCTAVES; i++) {+ if (i >= octaves) break;+ sum += amp * gradientNoise(p);+ norm += amp;+ amp *= persistence;+ p = lacunarity * (octaveRotation * p) + vec3(17.13, -3.71, 5.29);+ }+ return sum / norm;+}+// Ridged multifractal: inverted |noise| creates sharp crests; each octave is weighted by the previous one, so detail gathers along ridges.+float ridgedFbm(vec2 p, int octaves) {+ const mat2 octaveRotation = mat2(0.8, 0.6, -0.6, 0.8);+ float sum = 0.0, amp = 0.5, weight = 1.0, norm = 0.0;+ for (int i = 0; i < FBM_MAX_OCTAVES; i++) {+ if (i >= octaves) break;+ float n = 1.0 - abs(gradientNoise(p) * 1.4);+ n *= n;+ sum += amp * n * weight;+ norm += amp;+ weight = clamp(n * 2.0, 0.0, 1.0);+ amp *= 0.5;+ p = 2.01 * (octaveRotation * p) + vec2(17.13, -3.71);+ }+ return sum / norm;+}+// Cellular (Worley/Voronoi) noise. Returns vec4(F1, F2, nearestCell.xy). F1 = distance to nearest feature point, F2 = second nearest. nearestCell is integer-valued, so hash it for per-cell randomness. jitter in [0,1] (0 = regular grid). Searches 3x3 cells. F2 can be slightly off at jitter 1.+vec4 voronoi(vec2 p, float jitter) {+ vec2 ip = floor(p), fp = fract(p);+ float f1 = 8.0, f2 = 8.0;+ vec2 nearest = vec2(0.0);+ for (int j = -1; j <= 1; j++)+ for (int i = -1; i <= 1; i++) {+ vec2 g = vec2(float(i), float(j));+ vec2 r = g + jitter * hash22(ip + g) - fp;+ float d = dot(r, r);+ if (d < f1) { f2 = f1; f1 = d; nearest = ip + g; }+ else if (d < f2) { f2 = d; }+ }+ return vec4(sqrt(f1), sqrt(f2), nearest);+}+// Bounded hybrid terrain recipe: broad gradient fBm, warped ridged detail and cellular breakup. This is an artistic composition, not Musgrave's named hybrid-multifractal algorithm. Coordinates are warped before all three fields are sampled; octaves is clamped to [1, FBM_MAX_OCTAVES].+float hybridTerrainHeight(vec2 p, int octaves) {+ int count = clamp(octaves, 1, FBM_MAX_OCTAVES);+ vec2 warp = vec2(fbm(p * 0.35, count), fbm(p * 0.35 + vec2(19.1, -7.3), count));+ vec2 q = p + 0.8 * warp;+ float broad = 0.5 + 0.5 * fbm(q * 0.45, count);+ float ridges = ridgedFbm(q * 1.7, count);+ float cells = 1.0 - clamp(voronoi(q * 2.5, 0.75).x, 0.0, 1.0);+ return clamp(0.45 * broad + 0.45 * ridges + 0.10 * cells, 0.0, 1.0);+}++// ---- shader-skills library: color ----+// Exact sRGB decode (EOTF): encoded [0,1] -> linear.+vec3 srgbToLinear(vec3 c) {+ c = max(c, 0.0);+ return mix(c / 12.92, pow((c + 0.055) / 1.055, vec3(2.4)), step(0.04045, c));+}+// Exact sRGB encode (OETF): linear -> display [0,1]. Apply exactly once, after tonemapping. pow(c, 1/2.2) is visibly wrong near black (0.001 encodes to 0.013 here vs 0.043 with 2.2).+vec3 linearToSrgb(vec3 c) {+ c = max(c, 0.0);+ return mix(c * 12.92, 1.055 * pow(c, vec3(1.0 / 2.4)) - 0.055, step(0.0031308, c));+}++// ---- shader-skills library: tonemap ----+// AgX: log encoding plus a sigmoid inside an inset/outset gamut. Mid-grey 0.18 maps to about 0.5 display. Minimal implementation after Troy Sobotka's AgX and Benjamin Wrensch's polynomial fit (both MIT).+vec3 tonemapAgX(vec3 c) {+ const mat3 inset = mat3(0.842479062253094, 0.0423282422610123, 0.0423756549057051,+ 0.0784335999999992, 0.878468636469772, 0.0784336,+ 0.0792237451477643, 0.0791661274605434, 0.879142973793104);+ const mat3 outset = mat3(1.19687900512017, -0.0528968517574562, -0.0529716355144438,+ -0.0980208811401368, 1.15190312990417, -0.0980434501171241,+ -0.0990297440797205, -0.0989611768448433, 1.15107367264116);+ const float minEv = -12.47393, maxEv = 4.026069;+ c = inset * max(c, 0.0);+ c = clamp((log2(max(c, 1e-10)) - minEv) / (maxEv - minEv), 0.0, 1.0);+ vec3 x2 = c * c, x4 = x2 * x2;+ c = 15.5 * x4 * x2 - 40.14 * x4 * c + 31.96 * x4 - 6.868 * x2 * c + 0.4298 * x2 + 0.1191 * c - 0.00232;+ c = outset * c;+ return pow(max(c, 0.0), vec3(2.2));+}++// ---- shader-skills library: post ----+// Triangular-PDF dither of +-1 LSB for 8-bit output. Add AFTER linearToSrgb, right before writing fragColor.+vec3 ditherTPDF(vec2 fragCoord, int frame) {+ vec2 r = hash22(vec2(floor(fragCoord) + 7919.0 * float(frame % 1024)));+ return vec3((r.x + r.y - 1.0) / 255.0);+}++// ---- shader ----+const int OCTAVES = 5;+const float WORLD_SCALE = 5.0;+const float RIVER_WIDTH = 0.10;++vec2 terrainMapFields(vec2 p) {+ float h = hybridTerrainHeight(p, OCTAVES);+ float bend = 0.9 * fbm(vec2(p.y * 0.36, 2.7), 4);+ float riverDistance = abs(p.x - bend);+ float river = 1.0 - smoothstep(RIVER_WIDTH, RIVER_WIDTH + 0.075, riverDistance);+ h = mix(h, 0.19, river);+ return vec2(h, river);+}++void mainImage(out vec4 fragColor, in vec2 fragCoord) {+ vec2 uv = (2.0 * fragCoord - iResolution.xy) / iResolution.y;+ vec2 p = uv * WORLD_SCALE;+ vec2 field = terrainMapFields(p);+ float e = 2.0 * WORLD_SCALE / iResolution.y;+ vec2 slope = vec2(terrainMapFields(p+vec2(e,0.0)).x-terrainMapFields(p-vec2(e,0.0)).x,+ terrainMapFields(p+vec2(0.0,e)).x-terrainMapFields(p-vec2(0.0,e)).x) / (2.0*e);+ vec3 n = normalize(vec3(-slope.x,0.7,-slope.y));+ float hills = smoothstep(0.38,0.63,field.x);+ float rock = smoothstep(0.58,0.78,field.x) * smoothstep(0.2,0.75,length(slope));+ vec3 land = mix(srgbToLinear(vec3(0.32,0.42,0.20)),srgbToLinear(vec3(0.61,0.57,0.35)),hills);+ land = mix(land,srgbToLinear(vec3(0.57,0.56,0.50)),rock);+ float diffuse = max(dot(n,normalize(vec3(-0.5,0.9,0.3))),0.0);+ vec3 col = land * (0.3 + 1.2 * diffuse);+ float bank = 1.0 - smoothstep(0.02,0.11,abs(field.y-0.4));+ col = mix(col,srgbToLinear(vec3(0.64,0.58,0.37)),bank*0.65);+ vec3 water = mix(vec3(0.01,0.12,0.15),vec3(0.05,0.31,0.36),0.5+0.5*sin(p.y*7.0+p.x*3.0));+ col = mix(col,water,field.y);+#if DEBUG_MODE == 1+ col = vec3(field.x);+#elif DEBUG_MODE == 2+ col = n*0.5+0.5;+#elif DEBUG_MODE == 5+ col = vec3(field.y);+#else+ col = linearToSrgb(tonemapAgX(col*1.2));+#endif+ fragColor = vec4(col+ditherTPDF(fragCoord,iFrame),1.0);+}diff --git a/gallery/noise-terrain-map.png b/gallery/noise-terrain-map.pngnew file mode 100644index 0000000..b1b6b75Binary files /dev/null and b/gallery/noise-terrain-map.png differdiff --git a/skills/shader-art-coding/SKILL.md b/skills/shader-art-coding/SKILL.mdindex 276a881..5bf1b03 100644--- a/skills/shader-art-coding/SKILL.md+++ b/skills/shader-art-coding/SKILL.md@@ -77,6 +77,7 @@ Read only what the task needs:| `references/library-index.md` | choosing functions: every library function with signature, exactness and uses || `references/sdf-library-guide.md` | modeling: exactness tiers, blends, neighbor-checked repetition, deformation limits, WebGL pitfalls || `references/rendering-pipeline.md` | lighting rigs, shadows/AO, sky and fog, volumes, tonemapping, AA, performance |+| `references/noise-use-cases.md` | choosing Perlin/value/simplex/cellular noise, fBm/ridged/billow/warp/hybrid recipes, game use cases and primary-source code links || `references/shader-workflow.md` | planning a complex shader end to end; review checklist || `references/composition-and-debugging.md` | the image reads poorly, or something is visually wrong || `references/formula-cookbook.md` | multi-step recipes: modular cell lattices, terrain synthesis, organic composition |@@ -86,7 +87,7 @@ Read only what the task needs:Templates in `templates/` are complete, render-verified starting points (gallery in the repository README):`raymarch-sdf.glsl`, `terrain.glsl`, `ocean.glsl`, `volumetric-clouds.glsl`, `sdf-2d-poster.glsl`,-`pattern-swatches.glsl`.+`pattern-swatches.glsl`, `noise-progression.glsl`, `noise-terrain-map.glsl`.## Output expectationsdiff --git a/skills/shader-art-coding/glsl/noise.glsl b/skills/shader-art-coding/glsl/noise.glslindex da9b2a2..00775b1 100644--- a/skills/shader-art-coding/glsl/noise.glsl+++ b/skills/shader-art-coding/glsl/noise.glsl@@ -426,6 +426,22 @@ float smoothVoronoi(vec2 p, float k) {return -log2(acc) / k;}+/// Bounded hybrid terrain recipe: broad gradient fBm, warped ridged detail and cellular breakup.+/// This is an artistic composition, not Musgrave's named hybrid-multifractal algorithm. Coordinates are+/// warped before all three fields are sampled; octaves is clamped to [1, FBM_MAX_OCTAVES].+/// @use game heightmaps, rocky islands, biome elevation masks, alien terrain+/// @range [0,1]+/// @see https://thebookofshaders.com/13/ (octaves, ridges and warping); https://thebookofshaders.com/12/ (cells)+float hybridTerrainHeight(vec2 p, int octaves) {+ int count = clamp(octaves, 1, FBM_MAX_OCTAVES);+ vec2 warp = vec2(fbm(p * 0.35, count), fbm(p * 0.35 + vec2(19.1, -7.3), count));+ vec2 q = p + 0.8 * warp;+ float broad = 0.5 + 0.5 * fbm(q * 0.45, count);+ float ridges = ridgedFbm(q * 1.7, count);+ float cells = 1.0 - clamp(voronoi(q * 2.5, 0.75).x, 0.0, 1.0);+ return clamp(0.45 * broad + 0.45 * ridges + 0.10 * cells, 0.0, 1.0);+}+/// Interleaved gradient noise: cheap per-pixel noise whose 3x3 neighborhoods are nearly stratified. Not a hash./// pixel must be integer pixel coordinates (floor(fragCoord)). The frame overload animates it for accumulation and TAA./// @use removing banding before 8-bit output, jittering ray start offsets, stochastic transparencydiff --git a/skills/shader-art-coding/references/library-index.md b/skills/shader-art-coding/references/library-index.mdindex 25b3462..105e396 100644--- a/skills/shader-art-coding/references/library-index.md+++ b/skills/shader-art-coding/references/library-index.md@@ -89,6 +89,7 @@ noise: value, gradient and simplex noise (2D/3D, analytic derivatives), fBm, tur- `vec4 voronoi(vec2 p, float jitter)` - Cellular (Worley/Voronoi) noise. Returns vec4(F1, F2, nearestCell.xy). F1 = distance to nearest feature point, F2 = second nearest. nearestCell is integer-valued, so hash it for per-cell randomness. jitter in [0,1] (0 = regular grid). Searches 3x3 cells. F2 can be slightly off at jitter 1. *Use: cells, scales, stones, cracked mud (F2-F1), caustics, foam, sparkles.* Range F1 in [0, ~1.2].- `vec3 voronoiBorder(vec2 p, float jitter)` - Exact distance to Voronoi cell borders, found in two passes: nearest point, then nearest bisector. Returns vec3(borderDistance, vectorToNearestPoint). Unlike F2-F1, the border distance is a true distance, so lines have constant width. *Use: cell walls, stained glass leading, cracked earth, giraffe and leaf-vein patterns, crackle glaze.*- `float smoothVoronoi(vec2 p, float k)` - Smooth Voronoi: a soft-min of distances to feature points. Cells become blobs with no creases. k controls smoothness (large = sharper; around 8-32). Searches 5x5 cells so low k has no seams. *Use: organic cell clusters, bubbles, lumpy surfaces, skin pores.*+- `float hybridTerrainHeight(vec2 p, int octaves)` - Bounded hybrid terrain recipe: broad gradient fBm, warped ridged detail and cellular breakup. This is an artistic composition, not Musgrave's named hybrid-multifractal algorithm. Coordinates are warped before all three fields are sampled; octaves is clamped to [1, FBM_MAX_OCTAVES]. *Use: game heightmaps, rocky islands, biome elevation masks, alien terrain.* Range [0,1].- `float interleavedGradientNoise(vec2 pixel)` / `float interleavedGradientNoise(vec2 pixel, int frame)` - Interleaved gradient noise: cheap per-pixel noise whose 3x3 neighborhoods are nearly stratified. Not a hash. pixel must be integer pixel coordinates (floor(fragCoord)). The frame overload animates it for accumulation and TAA. *Use: removing banding before 8-bit output, jittering ray start offsets, stochastic transparency.* Range [0,1).- `float r2Dither(vec2 pixel)` - R2 low-discrepancy dither mask (plastic-constant sequence), folded by a triangle wave for an even spread. *Use: ordered dithering without textures, posterized and retro looks, sample offsets.* Range [0,1).diff --git a/skills/shader-art-coding/references/noise-use-cases.md b/skills/shader-art-coding/references/noise-use-cases.mdnew file mode 100644index 0000000..3b213ca--- /dev/null+++ b/skills/shader-art-coding/references/noise-use-cases.md@@ -0,0 +1,295 @@+# Noise learning progression and use cases++A code-backed companion to the ten entries in the **Noise Learning Progression** reference image. The image is a+learning aid, not a specification: base noise, octave accumulation, coordinate transformations and material recipes+are different layers. Start with a scalar field, inspect it, then compose it for a particular subject.++## Contents++- [Find the code](#find-the-code)+- [What the labels mean](#what-the-labels-mean)+- [Ten small recipes](#ten-small-recipes)+- [Putting it together](#putting-it-together)+- [Complete shaders and previews](#complete-shaders-and-previews)+- [Tuning and production use](#tuning-and-production-use)+- [Primary sources and external code](#primary-sources-and-external-code)++## Find the code++All local implementations are in [`../glsl/noise.glsl`](../glsl/noise.glsl). Hashes come from+[`../glsl/hash.glsl`](../glsl/hash.glsl). The snippets below call the tested library; bundle them before use.++| Image entry | Local GLSL | Dimensions shipped | Practical use cases |+|---|---|---|---|+| Perlin noise | `gradientNoise`, `gradientNoiseD` | 2D, 3D | Broad hills, wind/weather masks, roughness breakup; analytic derivatives for normals |+| Voronoi noise | `voronoi`, `voronoiBorder`, `smoothVoronoi` | 2D | Rock plates, cracks, cell walls, stained glass, regions |+| Simplex noise | `simplexNoise`, `simplexNoiseD` | 2D | Ripples, flowing lava, animated surface detail; rotating gradients for churning flow |+| Fractal noise / fBm | `fbm`, `erodedFbm` | 2D, 3D fBm; 2D eroded | Multiscale terrain, cloud/dirt masks, rocky detail; slope-damped landscape detail |+| Domain warping | `warpedFbm` | 2D | Marble, agate, distorted cloud bands, alien terrain; use returned `q`/`r` for color |+| Value noise | `valueNoise`, `valueNoiseD` | 2D, 3D values; 2D derivatives | Cheap smooth masks, soft blotches; quantized coordinates for retro blocks |+| Cellular / Worley | `voronoi` F1/F2 and cell ID | 2D | Foam/cells, biome regions, scales, per-stone variation |+| Ridged noise | `ridgedFbm` | 2D | Mountain crests, canyons, veins, rocky heightfields |+| Billow noise | `billowFbm` | 2D, 3D | Puffy smoke, cumulus-like lobes, foam clumps, rounded terrain |+| Hybrid noise | `hybridTerrainHeight` | 2D | Bounded game heightmaps mixing broad hills, warped ridges and cellular detail |++Need a missing dimension, tiling, or different cellular metrics? See the external code table below. A 2D-only+function should not be advertised as a volumetric 3D implementation.++## What the labels mean++- **Perlin-style is gradient noise.** This library uses PCG-hashed gradients and a quintic interpolation curve;+ it does not reproduce the exact samples from Perlin's fixed-permutation reference implementation.+- **Voronoi and Worley overlap.** They describe the same nearest-feature-point family here, not two independent+ algorithms to add together. F1, F2, region IDs, F2−F1 and exact border distance produce different appearances.+- **fBm is an octave recipe**, not a separate base noise. More octaves add frequency bands; they do not add+ erosion, drainage, or a physically simulated cloud.+- **Domain warping transforms coordinates:** evaluate `f(p + strength * warp(p))`. It can distort any base field.+ A river-shaped mask or cave threshold still needs a separate shaping/carving step.+- **Simplex is not universally faster or smoother.** Lattice geometry and evaluation cost differ; benchmark the+ specific implementation, dimension and target GPU. Neither base algorithm automatically produces a layered cloud.+- **Value noise can be smooth.** The library interpolates random corner values with a quintic fade. Blocky values+ come from omitting interpolation or deliberately quantizing the coordinates.+- **Billow and ridges reshape signed noise per octave.** Taking `abs` after the entire fBm sum gives a different+ field. This library's billow also rounds lobes and weights later octaves.+- **Hybrid is a composition strategy.** `hybridTerrainHeight` is this repository's artistic bounded mixture. It is+ not an implementation of Musgrave's specific hybrid-multifractal recurrence.++## Ten small recipes++Each function is a separate usable recipe. Inputs are world/texture coordinates, not pixel coordinates. The normal+shader bundler resolves all library dependencies. Samples intended as masks are clamped into [0,1]; height, density+and material values can then use their own units. These examples are compile-checked with the references.++### 1. Perlin-style: broad hills++Start with one octave so scale is easy to understand. A low frequency controls large landforms. Multiply the+returned value by the desired world-space height. Use `gradientNoiseD` when analytical slope is needed.++```glsl+float studyBroadHills(vec2 world) {+ return clamp(0.5 + 0.7 * gradientNoise(world * 0.35), 0.0, 1.0);+}+```++### 2. Voronoi: constant-width cracks++Use distance to the cell border, not just F2−F1, when a crack must keep a consistent width. `pixelWidth` and+`crackWidth` below are in cell-coordinate units. For a sample at `world * 3.0`, scale its footprint by 3 too.++```glsl+float studyCracks(vec2 world, float crackWidth, float pixelWidth) {+ float border = voronoiBorder(world * 3.0, 0.85).x;+ float aa = max(pixelWidth * 3.0, 0.0001);+ return 1.0 - smoothstep(crackWidth - aa, crackWidth + aa, border);+}+```++Mix a dark crack material with a per-cell rock color. Extruding or displacing this mask creates actual geometry;+the noise alone is only a scalar texture.++### 3. Simplex: churning water or lava++Rotate the lattice gradients to change the pattern in place. The `.yz` derivatives can perturb a normal. This is+flow-like animation; it does not solve fluid dynamics or conserve transported material.++```glsl+vec3 studyChurningSurface(vec2 world, float time) {+ return simplexNoiseD(world * 2.0, time * 0.3);+}+```++The returned gradient is with respect to the scaled input. Multiply `.yz` by 2.0 for derivatives with respect to+`world`. Add more octaves explicitly if the surface needs multiple detail scales.++### 4. fBm: cloud coverage++Combine several frequency bands, then threshold the result into a coverage mask. For a volume, sample the 3D+`fbm` overload and multiply it by a height profile before integrating density and light.++```glsl+float studyCloudCoverage(vec2 world, float time) {+ float n = 0.5 + 0.5 * fbm(world * 0.8 + vec2(time * 0.03, 0.0), 5);+ return smoothstep(0.43, 0.65, n);+}+```++Use `erodedFbm` for a terrain-specific slope-damped look. Its result suggests erosion visually; it is not a+simulation of rainfall, sediment transport or drainage.++### 5. Domain warp: marble veins++Warp the field, then feed it into a band pattern. This gives controllable veins rather than assuming the warped+scalar itself looks like marble. Stronger warp and extra octaves cost more and can alias.++```glsl+float studyMarbleVeins(vec2 world) {+ vec2 q, r;+ float field = warpedFbm(world * 1.2, 3.0, 5, q, r);+ float bands = 0.5 + 0.5 * sin(world.x * 4.0 + 8.0 * field);+ return smoothstep(0.25, 0.8, bands);+}+```++Blend cream/charcoal materials with this mask. Use `q` and `r` separately for mineral color variation. The complete+`pattern-swatches.glsl` template demonstrates a colored warped material.++### 6. Value: smooth masks and retro blocks++Compare the interpolated field against deliberately blocky cells. `hash12` takes integer cell IDs. The blocky+version is intentionally discontinuous and unsuitable for smooth geometric displacement.++```glsl+vec2 studyValueVariants(vec2 world) {+ return vec2(valueNoise(world * 4.0), hash12(floor(world * 4.0)));+}+```++Use the first channel for cheap roughness or weather masks; use the second for per-tile random colors, pixel art+or quick region prototypes. A hash and interpolated value noise have different spatial continuity.++### 7. Cellular / Worley: regions and foam++The same point distribution can drive several effects. `voronoi(...).zw` is a cell ID for stable region choices;+`.x` is F1, `.y` is F2. F2−F1 is useful for stylized boundaries but is not exact border distance.++```glsl+vec3 studyCellularChannels(vec2 world) {+ vec4 cell = voronoi(world * 3.0, 0.85);+ float region = hash12(cell.zw);+ float foam = 1.0 - smoothstep(0.03, 0.16, cell.y - cell.x);+ return vec3(clamp(cell.x, 0.0, 1.0), foam, region);+}+```++The fast 3×3 search is a neighborhood approximation; F2 can miss a candidate at high jitter, as documented on+`voronoi`. Use `voronoiBorder` for the library's two-pass boundary treatment. For Manhattan/Chebyshev metrics or+3D cellular fields, inspect FastNoise Lite's implementation instead of silently reinterpreting Euclidean F1/F2.++### 8. Ridged: mountain crests++Use `ridgedFbm` as a terrain detail layer or as a thresholded vein mask. The inverted absolute-value construction+creates crests; octave weighting gathers fine detail along them.++```glsl+float studyMountainCrests(vec2 world) {+ return ridgedFbm(world * 1.6, 6);+}+```++Mix this with a lower-frequency base so every region is not equally mountainous. Displacement still needs normals,+bounded march steps and distance-dependent detail filtering.++### 9. Billow: puffy density++Use the 3D overload for a solid density field. Combine it with a vertical envelope and a threshold. The envelope+below is zero outside a chosen cloud layer; the result still needs volume integration to look like a cloud.++```glsl+float studyPuffyDensity(vec3 world) {+ float layer = smoothstep(0.0, 0.4, world.y) * (1.0 - smoothstep(1.4, 2.0, world.y));+ return layer * smoothstep(0.08, 0.4, billowFbm(world * 0.9, 5));+}+```++See `volumetric-clouds.glsl` for a complete lighting/integration pipeline; this recipe supplies an alternative+density shape, not a replacement for that pipeline.++### 10. Hybrid: a reusable terrain height++The new library helper warps coordinates, combines broad fBm, ridged detail and cellular breakup, then clamps+the artistic height into [0,1]. It clamps octave count to [1,12] so zero octaves cannot divide by zero.++```glsl+float studyHybridHeight(vec2 world) {+ return hybridTerrainHeight(world * 0.8, 5);+}+```++This is a practical recipe with editable weights, not a universal definition of hybrid noise. Bake it into a game+heightmap or multiply it by a vertical scale for geometry. Biome/material masks should use slope as well as height.++## Putting it together++Build fields with separate jobs: broad hills for silhouette, ridges for mountains, cells for material breakup,+warping for less regular placement, and a shaped contour for a river. Adding every field with equal weight tends+to make a busy surface with no visual hierarchy.++```glsl+vec2 studyTerrainAndRiver(vec2 world) {+ float height = hybridTerrainHeight(world, 5);+ float bend = 0.9 * fbm(vec2(world.y * 0.36, 2.7), 4);+ float riverDistance = abs(world.x - bend);+ float water = 1.0 - smoothstep(0.10, 0.175, riverDistance);+ height = mix(height, 0.19, water);+ return vec2(height, water);+}+```++The river is a designed warped channel; it does not find downhill drainage. Noise cannot promise a traversable+game level, connected cave system or physically valid river network without additional constraints.++## Complete shaders and previews++- [`../templates/noise-progression.glsl`](../templates/noise-progression.glsl): ten grayscale tiles, matching+ the table's order. Top row: gradient, Voronoi borders, simplex, fBm, marble warp. Bottom: smooth value, F2−F1+ cellular, ridged, billow, hybrid height. White ticks identify columns 1–5. These are representative studies, not+ reconstructions of the image's exact random seeds or artistic treatment.+- [`../templates/noise-terrain-map.glsl`](../templates/noise-terrain-map.glsl): a colored relief map with rocky+ elevations, slope-dependent material, a sandy bank and a carved turquoise river. Debug modes expose height,+ normals and the water mask.+- Existing templates `terrain.glsl`, `volumetric-clouds.glsl`, `pattern-swatches.glsl` show full terrain, cloud and+ material pipelines. Generated standalone code and PNG previews live in the repository's `gallery/` directory.++From the repository root, bundle a complete shader:++```sh+python3 skills/shader-art-coding/scripts/glsl_tools.py bundle skills/shader-art-coding/templates/noise-progression.glsl -o noise-progression.glsl+python3 skills/shader-art-coding/scripts/glsl_tools.py check noise-progression.glsl+```++Paste the bundled output into Shadertoy. For WebGL 2, use the uniform/main wrapper in the test harness; the+templates deliberately follow the repo's Shadertoy interface, without custom uniforms or a `#version` directive.++## Tuning and production use++| Control | Effect | Starting point / caution |+|---|---|---|+| Input frequency | Feature size | Multiply coordinates; larger numbers make smaller features |+| Octaves | Number of detail bands | 4–6 to start; reduce distant or tiny detail; existing octave helpers expect at least 1 |+| Lacunarity | Frequency multiplier per octave | About 2; noninteger values and rotations reduce aligned repetition |+| Persistence | Amplitude multiplier per octave | About 0.5; larger values add roughness; do not feed negative/nonfinite values |+| Warp strength | Amount of coordinate displacement | 0 for comparison; about 1–3 for exploration; steep warps need filtering |+| Jitter | Cell irregularity | [0,1]; smaller is more regular; changing it moves feature points |+| Threshold / smoothstep | Occupancy and transition | Separate scalar fields from their masks; never use equal smoothstep edges |+| World-space scale | Geometric height or density | Keep normalized noise distinct from meters or extinction coefficients |++For normals, account for the input frequency in the chain rule. For raymarching, noise-displaced or warped fields+are generally not exact SDFs: bound derivatives or use conservative steps. For materials, evaluate colors in linear+space, tonemap HDR once, then encode to sRGB once. Grayscale previews here intentionally display normalized values+directly, so the scalar distributions remain easy to compare.++For games, evaluate in stable world/chunk coordinates to avoid seams, bake expensive static combinations when+appropriate, and use LOD for distant octaves. Do not assume this library's noise tiles at arbitrary periods.++## Primary sources and external code++The local library stays original MIT code. These are primary sources and independently usable implementations,+not vendored dependencies. Preserve each project's notices if reusing its actual code; an article being readable+does not grant permission to copy its shader. Links checked 2026-10-18.++| Technique | Author-maintained source / actual code | Terms and role |+|---|---|---|+| Classic Perlin | [Ken Perlin's improved-noise reference](https://cs.nyu.edu/~perlin/noise/) and [Gustavson's classicnoise2D.glsl](https://github.com/stegu/webgl-noise/blob/master/src/classicnoise2D.glsl) | Perlin page is the algorithm reference; webgl-noise code is MIT, with different sample values from this repo |+| Simplex | [webgl-noise noise2D.glsl](https://github.com/stegu/webgl-noise/blob/master/src/noise2D.glsl), [psrdnoise](https://github.com/stegu/psrdnoise) | MIT implementations; rotating/periodic and higher-dimensional variants differ from this repo's API |+| Voronoi / Worley | [Gustavson's cellular2D.glsl](https://github.com/stegu/webgl-noise/blob/master/src/cellular2D.glsl), [FastNoise Lite GLSL](https://github.com/Auburn/FastNoiseLite/blob/master/GLSL/FastNoiseLite.glsl) | MIT; cellular return modes and distance metrics vary |+| Value | [FastNoise Lite GLSL](https://github.com/Auburn/FastNoiseLite/blob/master/GLSL/FastNoiseLite.glsl) | MIT; value and value-cubic implementations |+| fBm, ridges, warping | [The Book of Shaders, chapter 13](https://thebookofshaders.com/13/) and [FastNoise Lite GLSL](https://github.com/Auburn/FastNoiseLite/blob/master/GLSL/FastNoiseLite.glsl) | Author-written explanation; MIT code alternative in FastNoise Lite; no book code copied here |+| Cellular construction | [The Book of Shaders, chapter 12](https://thebookofshaders.com/12/) | Author-written explanation of feature points, nearest distances and borders; no code copied |+| Billow | [libnoise Billow documentation](https://libnoise.sourceforge.net/docs/classnoise_1_1module_1_1Billow.html) | Explains absolute-value-per-octave billow; its signed/scaled output differs from this library's [0,1] weighted variant |+| Domain warp theory | [Quilez: domain warping](https://iquilezles.org/articles/warp/) | Existing library technique credit; article URL retained, direct retrieval unavailable during this update; chapter 13 above provides an accessible explanation |+| Hybrid composition | `hybridTerrainHeight` and the terrain-map template in this repo | Original MIT example composing the cited primitives; no single canonical algorithm matches the image's generic label |++For external code covering multiple host languages, [FastNoise Lite](https://github.com/Auburn/FastNoiseLite) ships+Perlin, value, cellular, fractal modes and domain warping. Its OpenSimplex2 variants should not be described as the+same implementation as classic simplex. [webgl-noise](https://stegu.github.io/webgl-noise/) also ships classic and+simplex 3D/4D variants. Their performance claims refer to their own code and tests, not this repository.diff --git a/skills/shader-art-coding/references/subject-routing.md b/skills/shader-art-coding/references/subject-routing.mdindex d15965e..90a4559 100644--- a/skills/shader-art-coding/references/subject-routing.md+++ b/skills/shader-art-coding/references/subject-routing.md@@ -25,6 +25,8 @@ section with the formulas. The formula files use geometry-first names; this tabl| sea, ocean, lake surface | heightfield trace in a wave slab + Fresnel reflection | `ocean.glsl` || clouds, smoke, fog volumes, nebulae, fire | volume integration | `volumetric-clouds.glsl` || texture, material swatch, wallpaper | 2D procedural pattern | `pattern-swatches.glsl` |+| comparing noise families / learning noise | 2D scalar-field board | `noise-progression.glsl`; `noise-use-cases.md` |+| game heightmap, biome map, designed river | 2D height + separate masks | `noise-terrain-map.glsl`; `hybridTerrainHeight`; `noise-use-cases.md` |## Characters and creaturesdiff --git a/skills/shader-art-coding/templates/noise-progression.glsl b/skills/shader-art-coding/templates/noise-progression.glslnew file mode 100644index 0000000..b43ec03--- /dev/null+++ b/skills/shader-art-coding/templates/noise-progression.glsl@@ -0,0 +1,51 @@+// Ten noise studies, matching the learning progression in references/noise-use-cases.md.+// Top row, left to right: Perlin-style gradient, Voronoi borders, simplex, fBm, domain warp.+// Bottom row: smooth value, Worley F1/F2, ridged, billow, hybrid terrain height.+// Base noise and layered noise deliberately look different: a single octave is not a cloud texture.+// @render time=2.0+#define DEBUG_MODE 0 // 0 grayscale | 3 tile IDs | 5 unclipped scalar false color+const float SCALE = 5.0;+const int OCTAVES = 5;++float noiseStudy(int id, vec2 p, float px) {+ if (id == 0) return 0.5 + 0.7 * gradientNoise(p);+ if (id == 1) return 1.0 - smoothstep(0.0, 0.13 + px, voronoiBorder(p, 0.85).x);+ if (id == 2) return 0.5 + 0.5 * simplexNoise(p);+ if (id == 3) return 0.5 + 0.5 * fbm(p, OCTAVES);+ if (id == 4) {+ vec2 q, r;+ float f = warpedFbm(p * 0.6, 1.5, 3, q, r);+ return 0.5 + 0.5 * sin(p.x * 2.0 + 6.0 * f);+ }+ if (id == 5) return valueNoise(p);+ if (id == 6) {+ vec4 cell = voronoi(p, 0.85);+ return saturate(1.8 * (cell.y - cell.x));+ }+ if (id == 7) return ridgedFbm(p, OCTAVES);+ if (id == 8) return billowFbm(p, OCTAVES);+ return hybridTerrainHeight(p, OCTAVES);+}++void mainImage(out vec4 fragColor, in vec2 fragCoord) {+ vec2 board = fragCoord / iResolution.xy * vec2(5.0, 2.0);+ ivec2 tile = ivec2(floor(board));+ int id = tile.x + (1 - tile.y) * 5;+ vec2 local = fract(board);+ vec2 p = local * SCALE + vec2(1.23, 4.56);+ float px = SCALE * 5.0 / iResolution.x;+ float f = noiseStudy(id, p, px);+ vec3 col = vec3(saturate(f)); // grayscale values are already display values+#if DEBUG_MODE == 3+ col = cosinePalette(float(id) / 10.0, vec3(0.5), vec3(0.4), vec3(1.0), vec3(0.0,0.3,0.6));+#elif DEBUG_MODE == 5+ col = vec3(max(f,0.0), max(-f,0.0), max(f-1.0,0.0));+#endif+ vec2 edge = min(local,1.0-local);+ float frame = smoothstep(0.01,0.025,min(edge.x,edge.y));+ col = mix(vec3(0.035), col, frame);+ // The small white ticks identify columns 1–5 without font/texture dependencies.+ float tick = step(0.965,local.y) * step(0.1,local.x) * step(local.x,0.1+0.03*float(tile.x+1));+ col = mix(col,vec3(0.9),tick);+ fragColor = vec4(col + ditherTPDF(fragCoord,iFrame),1.0);+}diff --git a/skills/shader-art-coding/templates/noise-terrain-map.glsl b/skills/shader-art-coding/templates/noise-terrain-map.glslnew file mode 100644index 0000000..b638206--- /dev/null+++ b/skills/shader-art-coding/templates/noise-terrain-map.glsl@@ -0,0 +1,47 @@+// Putting noise together: warped broad hills + ridged mountains + cellular breakup,+// with a separate warped contour used as an artistic river mask. No erosion or hydrology simulation.+// A top-down relief map keeps the composition legible and the height/mask debug views directly comparable.+// @render time=2.0+#define DEBUG_MODE 0 // 0 shaded biome map | 1 height | 2 normals | 5 river mask+const int OCTAVES = 5;+const float WORLD_SCALE = 5.0;+const float RIVER_WIDTH = 0.10;++vec2 terrainMapFields(vec2 p) {+ float h = hybridTerrainHeight(p, OCTAVES);+ float bend = 0.9 * fbm(vec2(p.y * 0.36, 2.7), 4);+ float riverDistance = abs(p.x - bend);+ float river = 1.0 - smoothstep(RIVER_WIDTH, RIVER_WIDTH + 0.075, riverDistance);+ h = mix(h, 0.19, river);+ return vec2(h, river);+}++void mainImage(out vec4 fragColor, in vec2 fragCoord) {+ vec2 uv = (2.0 * fragCoord - iResolution.xy) / iResolution.y;+ vec2 p = uv * WORLD_SCALE;+ vec2 field = terrainMapFields(p);+ float e = 2.0 * WORLD_SCALE / iResolution.y;+ vec2 slope = vec2(terrainMapFields(p+vec2(e,0.0)).x-terrainMapFields(p-vec2(e,0.0)).x,+ terrainMapFields(p+vec2(0.0,e)).x-terrainMapFields(p-vec2(0.0,e)).x) / (2.0*e);+ vec3 n = normalize(vec3(-slope.x,0.7,-slope.y));+ float hills = smoothstep(0.38,0.63,field.x);+ float rock = smoothstep(0.58,0.78,field.x) * smoothstep(0.2,0.75,length(slope));+ vec3 land = mix(srgbToLinear(vec3(0.32,0.42,0.20)),srgbToLinear(vec3(0.61,0.57,0.35)),hills);+ land = mix(land,srgbToLinear(vec3(0.57,0.56,0.50)),rock);+ float diffuse = max(dot(n,normalize(vec3(-0.5,0.9,0.3))),0.0);+ vec3 col = land * (0.3 + 1.2 * diffuse);+ float bank = 1.0 - smoothstep(0.02,0.11,abs(field.y-0.4));+ col = mix(col,srgbToLinear(vec3(0.64,0.58,0.37)),bank*0.65);+ vec3 water = mix(vec3(0.01,0.12,0.15),vec3(0.05,0.31,0.36),0.5+0.5*sin(p.y*7.0+p.x*3.0));+ col = mix(col,water,field.y);+#if DEBUG_MODE == 1+ col = vec3(field.x);+#elif DEBUG_MODE == 2+ col = n*0.5+0.5;+#elif DEBUG_MODE == 5+ col = vec3(field.y);+#else+ col = linearToSrgb(tonemapAgX(col*1.2));+#endif+ fragColor = vec4(col+ditherTPDF(fragCoord,iFrame),1.0);+}diff --git a/tests/properties.py b/tests/properties.pyindex eca75d6..3bb9d58 100644--- a/tests/properties.py+++ b/tests/properties.py@@ -213,6 +213,17 @@ PROPERTIES = [if (isnan(b2) || b2 < 0.0 || b2 > 1.0) f |= 4;if (isnan(b3) || b3 < 0.0 || b3 > 1.0) f |= 8;return f;""", {}),+ ("hybridTerrainHeight: finite bounded output and safe octave limits", """+ vec2 p = (a.xy - 0.5) * 80.0;+ int count = 1 + int(b.x * 12.0);+ float h = hybridTerrainHeight(p, count);+ float low = hybridTerrainHeight(p, 0);+ float high = hybridTerrainHeight(p, 99);+ int f = 0;+ if (isnan(h) || isinf(h) || h < 0.0 || h > 1.0) f |= 1;+ if (isnan(low) || abs(low - hybridTerrainHeight(p, 1)) > 1e-6) f |= 2;+ if (isnan(high) || abs(high - hybridTerrainHeight(p, 12)) > 1e-6) f |= 4;+ return f;""", {}),("noise and fbm ranges", """vec2 p = (a.xy - 0.5) * 200.0;vec3 q = (a.xyz - 0.5) * 50.0;