Skip to content

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.

Initial shader skills package

gokayfem6dbf98f494c1
diff --git a/.claude/CLAUDE.md b/.claude/CLAUDE.md
new file mode 100644
index 0000000..06feeb9
--- /dev/null
+++ b/.claude/CLAUDE.md
@@ -0,0 +1,8 @@
+# Claude Project Instructions
+
+Read:
+
+- `prompts/universal-system-prompt.md`
+- `prompts/claude-project-instructions.md`
+
+Use the references in `skills/codex/shader-art-coding/references/` as the shader knowledge base.
diff --git a/.cursor/rules/shader-art-coding.mdc b/.cursor/rules/shader-art-coding.mdc
new file mode 100644
index 0000000..f48cc72
--- /dev/null
+++ b/.cursor/rules/shader-art-coding.mdc
@@ -0,0 +1,24 @@
+---
+description: Procedural shader art coding rules for GLSL, Shadertoy, SDF, heightfield, material, and atmospheric shaders
+globs:
+ - "**/*.frag"
+ - "**/*.glsl"
+ - "shaders/**"
+alwaysApply: false
+---
+
+Read `prompts/universal-system-prompt.md` and relevant references in `skills/codex/shader-art-coding/references/`.
+
+Use Shadertoy-compatible GLSL by default. Keep `mainImage(out vec4 fragColor, in vec2 fragCoord)`.
+
+Use `iDebugMode`:
+
+- `0`: final render
+- `1`: scalar field / SDF contours
+- `2`: normals
+- `3`: material IDs
+- `4`: step count / depth
+- `5`: masks / density
+- `6`: lighting terms
+
+Use formal mathematical helper names for reusable code. Run `npm run check` after substantial shader changes.
diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md
new file mode 100644
index 0000000..3703578
--- /dev/null
+++ b/.github/copilot-instructions.md
@@ -0,0 +1,8 @@
+# Copilot Instructions
+
+This repo is a procedural shader art instruction pack.
+
+- Use `prompts/universal-system-prompt.md` for global shader behavior.
+- Use `skills/codex/shader-art-coding/references/` for formulas and GLSL snippets.
+- Use `iDebugMode` branches for formula verification.
+- Prefer formal mathematical naming for reusable helpers.
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..e71883a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,7 @@
+.env
+.research/
+tmp/
+*.mp4
+*.mp3
+*.wav
+*.webm
diff --git a/CLAUDE.md b/CLAUDE.md
new file mode 100644
index 0000000..535fb48
--- /dev/null
+++ b/CLAUDE.md
@@ -0,0 +1,5 @@
+# Claude Instructions
+
+Read `prompts/claude-project-instructions.md` and `prompts/universal-system-prompt.md`.
+
+Use this repository as a procedural shader art instruction library. For shader implementation, use debug modes and the formal formula-code references.
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..9c70bdc
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2026 gokayfem
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..fc48529
--- /dev/null
+++ b/README.md
@@ -0,0 +1,54 @@
+# Shader Skills
+
+Platform-neutral procedural shader intelligence for LLM coding agents.
+
+This repository packages the same shader-craft knowledge for multiple assistants:
+
+- Codex skill: `skills/codex/shader-art-coding`
+- Universal prompt: `prompts/universal-system-prompt.md`
+- Claude project instructions: `CLAUDE.md` and `.claude/CLAUDE.md`
+- Cursor rules: `.cursor/rules/shader-art-coding.mdc`
+- GitHub Copilot instructions: `.github/copilot-instructions.md`
+- ChatGPT/GPT builder instructions: `prompts/chatgpt-custom-gpt-instructions.md`
+- Gemini/Gems instructions: `prompts/gemini-gems-instructions.md`
+
+The references are written as formal mathematical construction manuals: implicit surfaces, SDF operators, heightfields, scalar masks, material fields, atmospheric coverage, and debug views.
+
+## Debug Modes
+
+Use `iDebugMode` in serious shaders:
+
+- `0`: final render
+- `1`: scalar field / SDF contours
+- `2`: normals
+- `3`: material IDs
+- `4`: step count / depth
+- `5`: masks / density
+- `6`: lighting terms
+
+## Recommended Agent Workflow
+
+Give your assistant one of the adapter prompts, then ask it to:
+
+1. Read the universal instructions.
+2. Pick relevant references only.
+3. Produce shader code using formal equation-code construction.
+4. Include debug modes for formula verification.
+5. Iterate on formulas, not guesses.
+
+Example:
+
+```text
+Use the shader-art-coding instructions in this repo. Create a Shadertoy GLSL shader using formal SDF and heightfield construction, and explain the debug modes.
+```
+
+## Repository Layout
+
+```text
+prompts/ Platform-neutral and platform-specific prompts
+skills/codex/shader-art-coding/ Installed Codex skill package
+```
+
+## License
+
+MIT
diff --git a/prompts/chatgpt-custom-gpt-instructions.md b/prompts/chatgpt-custom-gpt-instructions.md
new file mode 100644
index 0000000..b431b6b
--- /dev/null
+++ b/prompts/chatgpt-custom-gpt-instructions.md
@@ -0,0 +1,25 @@
+# ChatGPT / Custom GPT Instructions: Shader Skills
+
+You are a procedural shader engineering assistant. Use the files in this repository as your knowledge base.
+
+Primary instruction file:
+
+```text
+prompts/universal-system-prompt.md
+```
+
+Reference directory:
+
+```text
+skills/codex/shader-art-coding/references/
+```
+
+When answering:
+
+- Decompose the visual target into formal mathematical fields.
+- Produce Shadertoy-compatible GLSL by default.
+- Include debug modes and tuning constants.
+- Explain equation-code relationships.
+- Include validation and debugging guidance appropriate to the user's target runtime.
+
+Use formal reusable terminology. Avoid naming reusable formulas after scene objects unless the user’s requested subject requires it.
diff --git a/prompts/claude-project-instructions.md b/prompts/claude-project-instructions.md
new file mode 100644
index 0000000..b4b8559
--- /dev/null
+++ b/prompts/claude-project-instructions.md
@@ -0,0 +1,16 @@
+# Claude Project Instructions: Shader Skills
+
+Use this repository as a procedural shader art knowledge base.
+
+First read:
+
+1. `prompts/universal-system-prompt.md`
+2. The relevant files in `skills/codex/shader-art-coding/references/`
+
+When asked to create or improve a shader:
+
+- Use formal mathematical decomposition: domains, scalar fields, implicit surfaces, masks, IDs, material fields, lighting, and post-processing.
+- Use `iDebugMode` for debug views.
+- Explain what each debug mode verifies.
+
+Avoid copying third-party shader code. Use original implementations based on the reference formulas.
diff --git a/prompts/copilot-instructions.md b/prompts/copilot-instructions.md
new file mode 100644
index 0000000..448f014
--- /dev/null
+++ b/prompts/copilot-instructions.md
@@ -0,0 +1,13 @@
+# GitHub Copilot Instructions: Shader Skills
+
+This repository contains platform-neutral shader art instructions.
+
+For shader code:
+
+- Prefer Shadertoy-compatible GLSL.
+- Use formal helper names for domains, implicit fields, masks, IDs, material fields, and lighting terms.
+- Add debug branches using `iDebugMode`.
+- Keep raymarch loops bounded.
+- Avoid copying external shader source.
+
+Use `skills/codex/shader-art-coding/references/` for equation-code patterns.
diff --git a/prompts/cursor-rules.md b/prompts/cursor-rules.md
new file mode 100644
index 0000000..613475a
--- /dev/null
+++ b/prompts/cursor-rules.md
@@ -0,0 +1,10 @@
+# Cursor Rules: Shader Skills
+
+Apply these rules to shader work in this repository.
+
+- Read `prompts/universal-system-prompt.md` before writing shader code.
+- Read only relevant references from `skills/codex/shader-art-coding/references/`.
+- Preserve Shadertoy-style `mainImage`.
+- Use `iDebugMode` for inspectable intermediate fields.
+- Use formal mathematical names for reusable helpers.
+- Do not introduce texture dependencies unless requested.
diff --git a/prompts/gemini-gems-instructions.md b/prompts/gemini-gems-instructions.md
new file mode 100644
index 0000000..ba3caf1
--- /dev/null
+++ b/prompts/gemini-gems-instructions.md
@@ -0,0 +1,16 @@
+# Gemini / Gems Instructions: Shader Skills
+
+Act as a procedural shader art coding expert using this repository as your instruction pack.
+
+Load:
+
+- `prompts/universal-system-prompt.md`
+- Task-relevant references from `skills/codex/shader-art-coding/references/`
+
+Default behavior:
+
+- Produce Shadertoy-compatible GLSL.
+- Use formal mathematical naming for reusable formulas.
+- Include `iDebugMode` branches for scalar fields, normals, IDs, depth/steps, masks, and lighting.
+- Prefer original formula-code couples from the references.
+- Include validation and debugging guidance appropriate to the user's target runtime.
diff --git a/prompts/universal-system-prompt.md b/prompts/universal-system-prompt.md
new file mode 100644
index 0000000..1d8d019
--- /dev/null
+++ b/prompts/universal-system-prompt.md
@@ -0,0 +1,68 @@
+# Universal Shader Art Coding Instructions
+
+You are a procedural shader art coding agent. Use this instruction pack when writing, improving, debugging, explaining, porting, or art-directing GLSL, Shadertoy, WebGL, SDF raymarching, heightfield, procedural texture, material, or mathematical drawing shaders.
+
+## Core Behavior
+
+Treat shader work as visual engineering:
+
+1. Define the intended image as formal fields: coordinate domains, implicit surfaces, scalar masks, material IDs, density fields, lighting terms, and post-process transforms.
+2. Choose the simplest rendering model that can express the image:
+ - 2D analytic fields for flat graphic forms and masks.
+ - SDF raymarching for implicit geometry and modular/organic 3D structures.
+ - Heightfield marching for scalar terrain-like surfaces.
+ - Coverage/density fields for atmosphere, volumes, or clumped detail.
+ - Fullscreen post-processing for feedback, transitions, and color transforms.
+3. Build the shader in inspectable stages: coordinates, primitive field, material ID, lighting, atmosphere, detail, color grade.
+4. Add debug modes before adding complexity.
+5. Prefer original compact formulas and readable helper functions.
+6. Explain formulas by the visual control they expose: scale, thickness, softness, frequency, density, curvature, phase, or material separation.
+
+## Required Output Quality
+
+When producing a complete Shadertoy shader:
+
+- Include `void mainImage(out vec4 fragColor, in vec2 fragCoord)`.
+- Normalize coordinates with aspect preservation:
+
+```glsl
+vec2 uv = (2.0*fragCoord - iResolution.xy) / iResolution.y;
+```
+
+- Keep loops bounded by compile-time constants.
+- Include debug support via `iDebugMode` or an equivalent constant.
+- Avoid texture dependencies unless the user provides texture inputs.
+- Include a short tuning guide for important constants.
+
+## Debug Mode Convention
+
+- `0`: final render
+- `1`: scalar field / SDF contours
+- `2`: normals
+- `3`: material IDs
+- `4`: step count / depth
+- `5`: masks / density fields
+- `6`: lighting terms
+
+## Reference Selection
+
+Use the references in `skills/codex/shader-art-coding/references/` as platform-neutral knowledge:
+
+- `shader-workflow.md`: end-to-end workflow.
+- `math-patterns.md`: coordinate and shaping formulas.
+- `rendering-patterns.md`: raymarching, normals, lighting, fog, tonemapping.
+- `composition-and-debugging.md`: visual hierarchy and formula verification.
+- `formula-cookbook.md`: visually verified formula stacks.
+- `formula-code-couples-sdf.md`: implicit geometry equation-code pairs.
+- `formula-code-couples-terrain.md`: heightfield/density/atmosphere equation-code pairs.
+- `formula-code-couples-materials.md`: material/color/polish equation-code pairs.
+- `glsl-snippets.md`: reusable Shadertoy-compatible snippets.
+
+Read only the relevant references for the user’s task.
+
+## Style Rules
+
+- Use formal mathematical names in reusable references and explanations.
+- Avoid scene-specific names for reusable operators. Prefer names like `radialRowCellSpace`, `bilobedCarrier`, `coverageMask`, `interstitialShell`, `sparseSpotField`, `upwardAccumulation`, and `anisotropicStrandField`.
+- Scene labels are allowed only when directly answering a user’s requested subject.
+- Do not copy source code from external videos or shaders. Distill techniques into original formulas and implementations.
diff --git a/skills/codex/shader-art-coding/SKILL.md b/skills/codex/shader-art-coding/SKILL.md
new file mode 100644
index 0000000..de1d078
--- /dev/null
+++ b/skills/codex/shader-art-coding/SKILL.md
@@ -0,0 +1,56 @@
+---
+name: shader-art-coding
+description: Expert procedural shader art and GLSL/Shadertoy coding guidance. Use when Codex needs to write, improve, debug, explain, port, critique, or art-direct fragment shaders, raymarching shaders, signed-distance-field scenes, procedural heightfields, mathematical organic/object drawing, noise/fbm/domain-warp effects, lighting/material shaders, or compact real-time visual code.
+---
+
+# Shader Art Coding
+
+## Operating Mode
+
+Treat shader work as visual engineering. Start from the intended image, choose the smallest mathematical representation that can produce it, then grow the shader through inspectable stages.
+
+For every substantial shader task:
+
+1. State the visual target, camera/framing, dominant forms, material families, and motion.
+2. Choose the rendering approach:
+ - 2D analytic drawing for icons, posters, stylized flat scenes, UI effects, and compact masks.
+ - Heightfield marching for scalar heightfields, sky radiance fields, fluids, density layers, and atmosphere.
+ - SDF raymarching for sculpted 3D forms, modular structures, organic carriers, tunnels, and abstract scenes.
+ - Fullscreen post/effect shader for transitions, glitches, feedback, color, and image processing.
+3. Build the first visible image quickly: coordinates, background, one primitive, one light or color ramp.
+4. Add debug views before adding complexity: distance field, IDs, normals, layer masks, step count, depth, material index, and noise octave contribution.
+5. Refine in this order: proportions, composition, material separation, lighting, atmosphere, color grading, antialiasing, performance.
+6. Prefer original compact helpers over copied shader code. Explain non-obvious formulas with the visual control they create.
+
+## Reference Routing
+
+Read only what the current task needs:
+
+- `references/shader-workflow.md`: end-to-end process, task decomposition, build order, and review checklist.
+- `references/math-patterns.md`: coordinates, shaping functions, SDFs, repetition, noise, fbm, domain warping, and palettes.
+- `references/rendering-patterns.md`: raymarching, normals, AO, soft shadows, materials, fog, tonemapping, and antialiasing.
+- `references/composition-and-debugging.md`: visual hierarchy, debug modes, readable iterations, and shader critique.
+- `references/formula-cookbook.md`: visually checked formula stacks for radial modular repetition, heightfield synthesis, implicit organic composition, volumetric density, atmospheric fields, and material breakup.
+- `references/formula-code-couples-sdf.md`: equation-to-GLSL pairs for implicit primitives, booleans, smoothing, local transforms, contour debugging, radial-cell lattices, bilateral feature fields, anisotropic strand fields, and shell intersections.
+- `references/formula-code-couples-heightfield.md`: equation-to-GLSL pairs for polynomial height patches, octave synthesis, finite-difference normals, horizon visibility, density fields, atmospheric coverage, accumulation masks, and distance LOD.
+- `references/formula-code-couples-materials.md`: equation-to-GLSL pairs for palettes, scalar material masks, lighting terms, sparse stochastic spots, ID-based albedo variation, composition overlays, antialiasing, tonemapping, and temporal polish.
+- `references/glsl-snippets.md`: original Shadertoy-compatible helper snippets and a compact complete template.
+
+## Output Expectations
+
+When writing shader code:
+
+- Produce Shadertoy-compatible GLSL unless the user asks for another target.
+- Include `mainImage(out vec4 fragColor, in vec2 fragCoord)` for complete Shadertoy shaders.
+- Use stable coordinate normalization: center coordinates and preserve aspect ratio.
+- Keep loops bounded by compile-time constants.
+- Include 1-3 debug switches or clearly described places to inspect intermediate fields.
+- Avoid texture dependencies unless the user provides textures or explicitly wants them.
+- Finish with a short visual tuning guide: which constants control scale, softness, color, lighting, and motion.
+
+When improving an existing shader:
+
+- Identify the current rendering model and the likely bottlenecks.
+- Preserve the user's intent and public interface.
+- Improve one layer at a time: correctness, readability, visual quality, then speed.
+- Call out risky changes such as altered coordinate scale, changed material IDs, or loop count increases.
diff --git a/skills/codex/shader-art-coding/agents/openai.yaml b/skills/codex/shader-art-coding/agents/openai.yaml
new file mode 100644
index 0000000..03efb07
--- /dev/null
+++ b/skills/codex/shader-art-coding/agents/openai.yaml
@@ -0,0 +1,4 @@
+interface:
+ display_name: "Shader Art Coding"
+ short_description: "Procedural shader math and GLSL craft"
+ default_prompt: "Use $shader-art-coding to design and implement a polished Shadertoy GLSL shader."
diff --git a/skills/codex/shader-art-coding/references/composition-and-debugging.md b/skills/codex/shader-art-coding/references/composition-and-debugging.md
new file mode 100644
index 0000000..c86d563
--- /dev/null
+++ b/skills/codex/shader-art-coding/references/composition-and-debugging.md
@@ -0,0 +1,100 @@
+# Composition and Debugging
+
+## Composition Rules for Procedural Shaders
+
+Make the image readable before making it detailed:
+
+- Use one dominant silhouette or value mass.
+- Reserve high contrast for the focal area.
+- Separate foreground, midground, and background by value and saturation.
+- Use atmosphere, scale, and texture frequency to show depth.
+- Let repeated elements vary in size, color, angle, or phase.
+- Keep large forms stable; animate small details unless the scene is about motion.
+
+For bilateral organic carrier scenes:
+
+- Establish dominant/secondary lobe proportions first.
+- Use symmetry only as a starting point; break it with pose, anisotropic strands, shell layers, or expression parameters.
+- Detail focal bilateral features more than distant or peripheral shapes.
+- Use material contrast to separate subsurface, woven, filament, metallic, accumulation, or prop materials.
+
+For heightfield scenes:
+
+- Build the heightfield silhouette first.
+- Place the sun and horizon early.
+- Use distance fog before adding tiny density-field details.
+- Use instance/material IDs for variation but keep clump structure coherent.
+
+For constructed objects:
+
+- Define the base primitive and repetition system.
+- Keep local coordinates and cell IDs available for color variation.
+- Add seams, interstitial fields, bevels, or edge wear after the major tiling reads correctly.
+
+## Debugging Ritual
+
+When a shader fails visually, inspect fields instead of guessing:
+
+1. Show coordinates as color.
+2. Show the raw mask or distance.
+3. Show object/material IDs.
+4. Show normals.
+5. Show depth or raymarch step count.
+6. Show lighting terms separately.
+7. Re-enable composition in layers.
+
+Do not debug a full shaded image when the broken term can be displayed directly.
+
+## Formula Verification From Visual Sources
+
+When learning from a video, screenshot, or visual derivation, sample more than the final frame:
+
+- Early frames reveal the primitive and coordinate system.
+- Middle frames reveal IDs, local coordinates, repetition, and masking.
+- Late frames reveal material, lighting, and detail breakup.
+- Final frames often reveal temporal polish: subtle camera drift, procedural background blur, atmospheric motion, or tiny pose changes.
+- Top-ranked code/formula frames often overrepresent final code, so also inspect chronological sheets.
+
+Record the verified formula families, not copied source. For each family, capture:
+
+- visual stage,
+- coordinate space,
+- scalar/vector field,
+- IDs retained,
+- visible debug output,
+- final material/rendering use.
+
+This prevents the common mistake of remembering the final image but missing the controllable formulas that built it.
+
+## Common Failure Modes
+
+- Aspect distortion: coordinates divide by `iResolution.x` and `iResolution.y` inconsistently.
+- Dead noise: high-frequency noise is added before the large form works.
+- Mushy SDFs: smooth unions use a radius larger than the feature scale.
+- Lost material IDs: geometry distance and material assignment are separated incorrectly.
+- Shadow acne: epsilon is too small or not scaled by hit distance.
+- Flat composition: all objects have similar value and saturation.
+- Expensive loops: nested fbm inside raymarching inside shadow calls.
+- Temporal shimmer: noise or thresholds change abruptly with time or distance.
+
+## Quality Passes
+
+Run these passes in order:
+
+- Shape pass: show only silhouettes and major masks.
+- Value pass: convert mentally to grayscale; focal contrast should survive.
+- Material pass: each material should be identifiable under simple light.
+- Light pass: key direction, fill, shadow softness, and rim are deliberate.
+- Atmosphere pass: distance, scale, and depth are clear.
+- Motion pass: animation has stable phase and loops if requested.
+- Performance pass: reduce octaves, step counts, shadow calls, and repeated map evaluations.
+
+## Response Pattern for Codex
+
+When presenting a shader, include:
+
+- What the shader renders.
+- The complete code or the precise patch.
+- Debug controls or intermediate fields.
+- Tuning knobs.
+- Performance notes if raymarching, fbm, shadows, or volumetrics are involved.
diff --git a/skills/codex/shader-art-coding/references/formula-code-couples-materials.md b/skills/codex/shader-art-coding/references/formula-code-couples-materials.md
new file mode 100644
index 0000000..c67fd11
--- /dev/null
+++ b/skills/codex/shader-art-coding/references/formula-code-couples-materials.md
@@ -0,0 +1,756 @@
+# Formula-Code Couples: Materials, Color, Composition, and Polish
+
+Use this file when the task needs equation-to-code translation for color ramps, masks, material layering, lighting, antialiasing, composition overlays, texture-like detail, or final polish.
+
+Each couple has:
+
+- Equation: the compact mathematical idea.
+- GLSL: an original Shadertoy-friendly implementation.
+- Visual result: what should appear when the formula is correct.
+- Debug view: the simplest way to inspect it.
+
+## 1. Smoothstep Mask
+
+Equation:
+
+```text
+m = S(a, b, x)
+```
+
+GLSL:
+
+```glsl
+float softMask(float a, float b, float x) {
+ return smoothstep(a, b, x);
+}
+```
+
+Visual result:
+
+A soft transition from black to white. This is the base for almost every controllable material boundary.
+
+Debug view:
+
+```glsl
+fragColor = vec4(vec3(softMask(a, b, x)), 1.0);
+```
+
+## 2. Derivative Antialiasing
+
+Equation:
+
+```text
+w = fwidth(x)
+m = smoothstep(edge - w, edge + w, x)
+```
+
+GLSL:
+
+```glsl
+float aaStep(float edge, float x) {
+ float w = fwidth(x);
+ return smoothstep(edge - w, edge + w, x);
+}
+```
+
+Visual result:
+
+Sharp analytic masks become clean instead of stair-stepped.
+
+Debug view:
+
+Compare `step(edge, x)` and `aaStep(edge, x)` side by side.
+
+## 3. Fill Mask From SDF
+
+Equation:
+
+```text
+fill = smoothstep(w, -w, d)
+```
+
+GLSL:
+
+```glsl
+float sdfFill(float d) {
+ float w = fwidth(d);
+ return smoothstep(w, -w, d);
+}
+```
+
+Visual result:
+
+A filled 2D shape with antialiased edges.
+
+Debug view:
+
+Show `vec3(sdfFill(d))`.
+
+## 4. Stroke Mask From SDF
+
+Equation:
+
+```text
+stroke = smoothstep(width+w, width-w, |d|)
+```
+
+GLSL:
+
+```glsl
+float sdfStroke(float d, float width) {
+ float w = fwidth(d);
+ return smoothstep(width + w, width - w, abs(d));
+}
+```
+
+Visual result:
+
+A clean outline or ring around a shape.
+
+Debug view:
+
+Show stroke alone before compositing.
+
+## 5. Cosine Palette
+
+Equation:
+
+```text
+color(t) = a + b cos(2pi(c t + d))
+```
+
+GLSL:
+
+```glsl
+vec3 palette(float t, vec3 a, vec3 b, vec3 c, vec3 d) {
+ return a + b*cos(6.2831853*(c*t + d));
+}
+```
+
+Visual result:
+
+Smooth repeating color harmonies useful for abstract shaders, heatmaps, irises, skies, and debug colors.
+
+Debug view:
+
+Render `palette(uv.x, ...)` as a horizontal strip.
+
+## 6. Warm Light, Cool Shadow
+
+Equation:
+
+```text
+color = albedo * (ambient + diffuse * warm) + shadowTint * (1-diffuse)
+```
+
+GLSL:
+
+```glsl
+vec3 warmCoolDiffuse(vec3 albedo, vec3 n, vec3 l) {
+ float ndl = max(dot(n, l), 0.0);
+ vec3 warm = vec3(1.08, 0.92, 0.72);
+ vec3 cool = vec3(0.35, 0.45, 0.70);
+ return albedo * (0.18*cool + ndl*warm);
+}
+```
+
+Visual result:
+
+Objects feel lit by sunlight rather than gray diffuse light.
+
+Debug view:
+
+Show `vec3(ndl)` and then the warm/cool shaded output.
+
+## 7. Fresnel Rim
+
+Equation:
+
+```text
+F = (1 + dot(n, rd))^p
+```
+
+GLSL:
+
+```glsl
+float fresnelRim(vec3 n, vec3 rd, float power) {
+ return pow(clamp(1.0 + dot(n, rd), 0.0, 1.0), power);
+}
+```
+
+Visual result:
+
+A soft rim highlight near silhouettes, useful for subsurface, waxy, crystalline, reflective, or stylized material regions.
+
+Debug view:
+
+Show rim as grayscale; it should hug the silhouette.
+
+## 8. Normal-View Localized Warmth Mask
+
+Equation:
+
+```text
+mask = regionMask * max(dot(n, -view), 0)^p
+```
+
+GLSL:
+
+```glsl
+float normalViewWarmth(vec3 n, vec3 viewDir, float regionMask) {
+ float facing = pow(clamp(dot(n, -viewDir), 0.0, 1.0), 2.0);
+ return regionMask * facing;
+}
+```
+
+Visual result:
+
+Soft localized warmth on selected convex material regions.
+
+Debug view:
+
+Show the localized warmth mask over a neutral albedo.
+
+## 9. Sparse Stochastic Spot Field
+
+Equation:
+
+```text
+cell = floor(uv N)
+q = fract(uv N)-1/2
+spot = exp(-k ||q||^2 / r)
+spot *= step(threshold, hash(cell))
+```
+
+GLSL:
+
+```glsl
+float sparseSpotField(vec2 uv) {
+ vec2 cell = floor(uv*25.0);
+ vec2 q = fract(uv*25.0) - 0.5;
+ float r = 0.08 + 0.12*hash12(cell);
+ float spot = exp(-24.0*dot(q, q) / r);
+ return spot * step(0.78, hash12(cell + 19.1));
+}
+```
+
+Visual result:
+
+Sparse stochastic spots on a mapped surface. They should appear only inside a deliberate region mask.
+
+Debug view:
+
+Show sparse spots as black dots on white before material mixing.
+
+## 10. Radial-Cell ID Albedo Variation
+
+Equation:
+
+```text
+color = mix(C1, C2, hash(id))
+```
+
+GLSL:
+
+```glsl
+vec3 cellIdAlbedo(vec2 id) {
+ float h = hash12(id);
+ return mix(vec3(0.42, 0.10, 0.06), vec3(0.86, 0.28, 0.14), h);
+}
+```
+
+Visual result:
+
+Individual modular cells vary in albedo while remaining one material family.
+
+Debug view:
+
+Render cell IDs as colors before lighting.
+
+## 11. Local Cell Grain
+
+Equation:
+
+```text
+grain = fbm(localUV * frequency + seed)
+color *= a + b grain
+```
+
+GLSL:
+
+```glsl
+vec3 applyCellGrain(vec3 color, vec2 localUv, vec2 id) {
+ float seed = 13.0*hash12(id);
+ float grain = fbm(localUv*18.0 + seed);
+ return color * (0.78 + 0.32*grain);
+}
+```
+
+Visual result:
+
+Rough local-coordinate detail that stays attached to each modular cell.
+
+Debug view:
+
+Show grain only in local coordinates. If it swims or crosses interstitial boundaries, the coordinate space is wrong.
+
+## 12. Interstitial Boundary Mask
+
+Equation:
+
+```text
+mask = smoothstep(edge0, edge1, distanceFromMortar)
+```
+
+GLSL:
+
+```glsl
+float interstitialToCellMask(float distFromInterstitial) {
+ return smoothstep(0.02, 0.08, distFromInterstitial);
+}
+```
+
+Visual result:
+
+Clean transition from an interstitial material to a cell material.
+
+Debug view:
+
+Show the mask as grayscale; the interstitial field should be continuous.
+
+## 13. Material Lambda Mix
+
+Equation:
+
+```text
+C = C0(1-lambda) + C1 lambda
+```
+
+GLSL:
+
+```glsl
+vec3 lambdaMix(vec3 a, vec3 b, float lambda) {
+ return mix(a, b, clamp(lambda, 0.0, 1.0));
+}
+```
+
+Visual result:
+
+Any material blend becomes inspectable through one scalar control.
+
+Debug view:
+
+Always show `lambda` alone first.
+
+## 14. Multi-Material Weighted Sum
+
+Equation:
+
+```text
+C = sum_i w_i C_i / sum_i w_i
+```
+
+GLSL:
+
+```glsl
+vec3 weightedMaterial(vec3 c0, vec3 c1, vec3 c2, vec3 w) {
+ w = max(w, vec3(0.0));
+ return (c0*w.x + c1*w.y + c2*w.z) / max(0.001, w.x + w.y + w.z);
+}
+```
+
+Visual result:
+
+Three-channel material blends remain normalized and controllable.
+
+Debug view:
+
+Show `w` as RGB.
+
+## 15. Edge Wear
+
+Equation:
+
+```text
+wear = smoothstep(a, b, abs(distanceToEdge))
+```
+
+GLSL:
+
+```glsl
+float edgeWear(float bevelDistance, float noiseValue) {
+ float edge = smoothstep(0.0, 0.08, bevelDistance);
+ return clamp((1.0 - edge) + 0.25*noiseValue, 0.0, 1.0);
+}
+```
+
+Visual result:
+
+Lighter worn edges on any beveled or high-contact material.
+
+Debug view:
+
+Show wear mask before using it in albedo or roughness.
+
+## 16. Dirt or Stain Gravity Bias
+
+Equation:
+
+```text
+stain = noise(worldXZ) * smoothstep(top, bottom, y)
+```
+
+GLSL:
+
+```glsl
+float verticalStain(vec3 p) {
+ float flow = smoothstep(0.7, -0.4, p.y);
+ float breakup = fbm(vec2(p.x*1.7, p.z*1.7));
+ return flow * smoothstep(0.35, 0.8, breakup);
+}
+```
+
+Visual result:
+
+Weathering, moss, or grime collects downward rather than randomly everywhere.
+
+Debug view:
+
+Show stain as a mask over a neutral material.
+
+## 17. Specular Lobe
+
+Equation:
+
+```text
+spec = max(dot(reflect(-l,n), -rd), 0)^shininess
+```
+
+GLSL:
+
+```glsl
+float specularLobe(vec3 n, vec3 l, vec3 rd, float shininess) {
+ vec3 r = reflect(-l, n);
+ return pow(max(dot(r, -rd), 0.0), shininess);
+}
+```
+
+Visual result:
+
+Controlled highlights on glossy, wet, polished, crystalline, or reflective material regions.
+
+Debug view:
+
+Show specular alone. If it covers the whole object, shininess is too low or normals are wrong.
+
+## 18. Radial Chromatic Ring Field
+
+Equation:
+
+```text
+r = ||uv||
+a = atan(y,x)
+iris = palette(r + noise(a,r))
+```
+
+GLSL:
+
+```glsl
+vec3 radialRingColor(vec2 uv) {
+ float r = length(uv);
+ float a = atan(uv.y, uv.x);
+ float fibers = 0.5 + 0.5*sin(34.0*a + 8.0*fbm(vec2(r*5.0, a)));
+ vec3 inner = vec3(0.16, 0.08, 0.03);
+ vec3 outer = vec3(0.55, 0.32, 0.12);
+ vec3 col = mix(inner, outer, smoothstep(0.08, 0.45, r));
+ col += 0.18*fibers*(1.0 - smoothstep(0.35, 0.48, r));
+ return col;
+}
+```
+
+Visual result:
+
+Radial chromatic detail with an inner disk and outer ring.
+
+Debug view:
+
+Render the radial ring field in 2D before mapping it onto a surface.
+
+## 19. Composition Thirds Overlay
+
+Equation:
+
+```text
+line = smoothstep(width, 0, |uv.x - k|)
+```
+
+GLSL:
+
+```glsl
+float lineAt(float x, float k, float w) {
+ return smoothstep(w, 0.0, abs(x - k));
+}
+
+vec3 thirdsOverlay(vec2 uv, vec3 col) {
+ float l = 0.0;
+ l = max(l, lineAt(uv.x, -1.0/3.0, 0.006));
+ l = max(l, lineAt(uv.x, 1.0/3.0, 0.006));
+ l = max(l, lineAt(uv.y, -1.0/3.0, 0.006));
+ l = max(l, lineAt(uv.y, 1.0/3.0, 0.006));
+ return mix(col, vec3(1.0, 0.85, 0.1), 0.5*l);
+}
+```
+
+Visual result:
+
+Temporary composition guides to place focal objects and horizon.
+
+Debug view:
+
+Use only during composition, then remove or gate behind a debug constant.
+
+## 20. Golden Ratio Overlay
+
+Equation:
+
+```text
+phi^-1 = 0.618...
+```
+
+GLSL:
+
+```glsl
+vec3 goldenOverlay(vec2 uv, vec3 col) {
+ float g = 0.6180339;
+ float l = 0.0;
+ l = max(l, lineAt(uv.x, -g, 0.005));
+ l = max(l, lineAt(uv.x, g, 0.005));
+ l = max(l, lineAt(uv.y, -g, 0.005));
+ l = max(l, lineAt(uv.y, g, 0.005));
+ return mix(col, vec3(0.2, 0.9, 1.0), 0.45*l);
+}
+```
+
+Visual result:
+
+Subtle framing guides for dominant silhouettes, horizons, and focal masses.
+
+Debug view:
+
+Toggle with `#define DEBUG_COMPOSITION 1`.
+
+## 21. Tonemap
+
+Equation:
+
+```text
+y = x / (1 + x)
+```
+
+GLSL:
+
+```glsl
+vec3 tonemap(vec3 x) {
+ x = max(x, 0.0);
+ return x / (1.0 + x);
+}
+```
+
+Visual result:
+
+Bright lighting compresses gracefully instead of clipping.
+
+Debug view:
+
+Compare before/after on a high-contrast light.
+
+## 22. Gamma to sRGB
+
+Equation:
+
+```text
+srgb = linear^(1/2.2)
+```
+
+GLSL:
+
+```glsl
+vec3 toSRGB(vec3 x) {
+ return pow(max(x, 0.0), vec3(1.0/2.2));
+}
+```
+
+Visual result:
+
+Colors look less dark/muddy in standard display output.
+
+Debug view:
+
+Apply as the final step only.
+
+## 23. Cheap Dithering
+
+Equation:
+
+```text
+color += hash(pixel) / 255
+```
+
+GLSL:
+
+```glsl
+vec3 cheapDither(vec3 col, vec2 fragCoord) {
+ float h = hash12(fragCoord);
+ return col + (h - 0.5) / 255.0;
+}
+```
+
+Visual result:
+
+Reduced banding in smooth gradients, fog, and sky.
+
+Debug view:
+
+Zoom into gradients; dithering should be barely visible.
+
+## 24. Slow Procedural Motion
+
+Equation:
+
+```text
+offset(t) = A (noise(wt + seed) - 1/2)
+```
+
+GLSL:
+
+```glsl
+float slowNoise(float t, float seed) {
+ return fbm(vec2(0.13*t, seed));
+}
+
+vec3 subtleCameraOffset(float t) {
+ return 0.01*vec3(
+ slowNoise(t, 1.0) - 0.5,
+ slowNoise(t, 2.0) - 0.5,
+ slowNoise(t, 3.0) - 0.5
+ );
+}
+```
+
+Visual result:
+
+Camera or subject breathes subtly. Motion should feel alive, not unstable.
+
+Debug view:
+
+Print/plot the offset mentally: it should be low amplitude and low frequency.
+
+## 25. Looping Time Phase
+
+Equation:
+
+```text
+phase = 2pi fract(t / duration)
+```
+
+GLSL:
+
+```glsl
+float loopPhase(float t, float duration) {
+ return 6.2831853 * fract(t / duration);
+}
+```
+
+Visual result:
+
+Reusable loop control for periodic field motion, aperture changes, flow, or camera orbit.
+
+Debug view:
+
+Animate `sin(phase)` and confirm it loops without a jump.
+
+## 26. Temporal Aperture Pulse Mask
+
+Equation:
+
+```text
+blink = smooth pulse over phase
+```
+
+GLSL:
+
+```glsl
+float aperturePulseAmount(float t) {
+ float ph = fract(t / 4.0);
+ float close = smoothstep(0.02, 0.05, ph);
+ float open = smoothstep(0.11, 0.16, ph);
+ return close * (1.0 - open);
+}
+```
+
+Visual result:
+
+A parameter closes briefly and reopens, useful for any aperture-like animated feature.
+
+Debug view:
+
+Show aperture openness as a number or mask before driving geometry.
+
+## 27. Background Blur Weight
+
+Equation:
+
+```text
+color' = sum_i w_i color(uv + offset_i) / sum_i w_i
+```
+
+GLSL:
+
+```glsl
+vec3 tinyBlur(sampler2D tex, vec2 uv, vec2 px) {
+ vec3 c = vec3(0.0);
+ float wsum = 0.0;
+ for (int i = -2; i <= 2; i++) {
+ float w = 1.0 - abs(float(i))/3.0;
+ c += w * texture(tex, uv + px*float(i)).rgb;
+ wsum += w;
+ }
+ return c / wsum;
+}
+```
+
+Visual result:
+
+Soft background or post-effect blur when texture input is available. For pure procedural scenes, use distance/fog instead.
+
+Debug view:
+
+Compare blurred and original background side by side.
+
+## 28. Material Debug Router
+
+Equation:
+
+```text
+debugMode selects scalar/vector field
+```
+
+GLSL:
+
+```glsl
+vec3 debugMaterialRouter(int mode, vec3 col, vec3 n, float mat, float depth, float mask) {
+ if (mode == 1) return 0.5 + 0.5*n;
+ if (mode == 2) return vec3(fract(mat*0.37), fract(mat*0.61), fract(mat*0.83));
+ if (mode == 3) return vec3(depth * 0.03);
+ if (mode == 4) return vec3(mask);
+ return col;
+}
+```
+
+Visual result:
+
+A shader that can be inspected without rewriting code.
+
+Debug view:
+
+This is itself the debug view; keep it cheap and removable.
diff --git a/skills/codex/shader-art-coding/references/formula-code-couples-sdf.md b/skills/codex/shader-art-coding/references/formula-code-couples-sdf.md
new file mode 100644
index 0000000..ed0a270
--- /dev/null
+++ b/skills/codex/shader-art-coding/references/formula-code-couples-sdf.md
@@ -0,0 +1,848 @@
+# Formula-Code Couples: Implicit Geometry and SDF Operators
+
+Use this file when the task needs equation-to-code translation for implicit primitives, smooth composition, local coordinate transforms, modular radial structures, bilateral feature fields, anisotropic strand fields, shell intersections, or mathematical sculpting.
+
+Each couple has:
+
+- Equation: the compact mathematical idea.
+- GLSL: an original Shadertoy-friendly implementation.
+- Visual result: what should appear when the formula is correct.
+- Debug view: the simplest way to inspect it.
+
+## 1. Sphere SDF
+
+Equation:
+
+```text
+d(p) = ||p - c|| - r
+```
+
+GLSL:
+
+```glsl
+float sdSphere(vec3 p, vec3 c, float r) {
+ return length(p - c) - r;
+}
+```
+
+Visual result:
+
+A perfectly round volume. Normal debug should show a smooth radial rainbow with no seams.
+
+Debug view:
+
+```glsl
+vec3 debugSphere(vec3 p) {
+ float d = sdSphere(p, vec3(0.0), 1.0);
+ return vec3(0.5 + 0.5*cos(80.0*d));
+}
+```
+
+## 2. Ellipsoid Approximation
+
+Equation:
+
+```text
+k0 = ||p / r||
+k1 = ||p / r^2||
+d(p) = k0(k0 - 1) / k1
+```
+
+GLSL:
+
+```glsl
+float sdEllipsoid(vec3 p, vec3 r) {
+ float k0 = length(p / r);
+ float k1 = length(p / (r*r));
+ return k0 * (k0 - 1.0) / k1;
+}
+```
+
+Visual result:
+
+A soft stretched sphere suitable for any anisotropic lobe, capsule-like mass, soft shell, ovoid inclusion, or rounded protrusion.
+
+Debug view:
+
+```glsl
+vec3 debugEllipsoid(vec3 p) {
+ float d = sdEllipsoid(p, vec3(0.7, 1.0, 0.55));
+ return mix(vec3(fract(16.0*d)), vec3(1.0, 0.25, 0.1), smoothstep(0.02, 0.0, abs(d)));
+}
+```
+
+## 3. Box SDF
+
+Equation:
+
+```text
+q = abs(p) - b
+d(p) = ||max(q, 0)|| + min(max(qx, qy, qz), 0)
+```
+
+GLSL:
+
+```glsl
+float sdBox(vec3 p, vec3 b) {
+ vec3 q = abs(p) - b;
+ return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);
+}
+```
+
+Visual result:
+
+A rectangular implicit solid with correct exterior edge distances and negative inside distance.
+
+Debug view:
+
+```glsl
+vec3 debugBox(vec3 p) {
+ float d = sdBox(p, vec3(0.8, 0.25, 0.35));
+ return vec3(smoothstep(0.08, -0.02, d));
+}
+```
+
+## 4. Rounded Box
+
+Equation:
+
+```text
+d_round(p) = d_box(p, b - r) - r
+```
+
+GLSL:
+
+```glsl
+float sdRoundBox(vec3 p, vec3 b, float r) {
+ vec3 q = abs(p) - (b - vec3(r));
+ return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0) - r;
+}
+```
+
+Visual result:
+
+A rectangular implicit solid with bevel-like soft edges. Use when a hard-edged element needs a finite edge radius.
+
+Debug view:
+
+```glsl
+vec3 debugRoundBox(vec3 p) {
+ float d = sdRoundBox(p, vec3(0.8, 0.25, 0.35), 0.05);
+ return vec3(0.5 + 0.5*cos(70.0*d));
+}
+```
+
+## 5. Capsule
+
+Equation:
+
+```text
+h = clamp(dot(p-a, b-a) / dot(b-a, b-a), 0, 1)
+d(p) = ||p - a - h(b-a)|| - r
+```
+
+GLSL:
+
+```glsl
+float sdCapsule(vec3 p, vec3 a, vec3 b, float r) {
+ vec3 pa = p - a;
+ vec3 ba = b - a;
+ float h = clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0);
+ return length(pa - ba*h) - r;
+}
+```
+
+Visual result:
+
+A swept segment with rounded endpoints. Use for any path-aligned tube, connector, appendage, rail, filament, or strap-like element.
+
+Debug view:
+
+```glsl
+vec3 debugCapsule(vec3 p) {
+ float d = sdCapsule(p, vec3(-0.6, 0.0, 0.0), vec3(0.6, 0.3, 0.0), 0.12);
+ return mix(vec3(0.1), vec3(0.9), smoothstep(0.03, -0.03, d));
+}
+```
+
+## 6. Torus and Tube
+
+Equation:
+
+```text
+q = ( ||p_xz|| - R, p_y )
+d(p) = ||q|| - r
+```
+
+GLSL:
+
+```glsl
+float sdTorus(vec3 p, vec2 t) {
+ vec2 q = vec2(length(p.xz) - t.x, p.y);
+ return length(q) - t.y;
+}
+```
+
+Visual result:
+
+A ring or continuous circular tube. Useful for any annular rim, orbital band, circular seam, or toroidal connector.
+
+Debug view:
+
+```glsl
+vec3 debugTorus(vec3 p) {
+ float d = sdTorus(p, vec2(0.8, 0.08));
+ return vec3(smoothstep(0.04, -0.02, d));
+}
+```
+
+## 7. Hard Boolean Operations
+
+Equation:
+
+```text
+union: min(a, b)
+intersection: max(a, b)
+subtraction: max(a, -b)
+```
+
+GLSL:
+
+```glsl
+float opUnion(float a, float b) { return min(a, b); }
+float opIntersect(float a, float b) { return max(a, b); }
+float opSub(float a, float b) { return max(a, -b); }
+```
+
+Visual result:
+
+Hard manufactured seams, crisp cuts, sockets, holes, and intersections.
+
+Debug view:
+
+```glsl
+vec3 debugBoolean(float a, float b) {
+ float d = opSub(a, b);
+ return vec3(0.5 + 0.5*cos(90.0*d));
+}
+```
+
+## 8. Polynomial Smooth Minimum
+
+Equation:
+
+```text
+h = clamp(1/2 + (b-a)/(2k), 0, 1)
+smin(a,b,k) = mix(b,a,h) - k h(1-h)
+```
+
+GLSL:
+
+```glsl
+float smin(float a, float b, float k) {
+ float h = clamp(0.5 + 0.5*(b - a)/k, 0.0, 1.0);
+ return mix(b, a, h) - k*h*(1.0 - h);
+}
+```
+
+Visual result:
+
+Two implicit primitives merge into one continuous differentiable-looking surface. Use for organic unions, soft accumulations, and clay-like blends.
+
+Debug view:
+
+```glsl
+vec3 debugSmin(vec3 p) {
+ float a = sdSphere(p - vec3(-0.35, 0.0, 0.0), vec3(0.0), 0.55);
+ float b = sdSphere(p - vec3( 0.35, 0.0, 0.0), vec3(0.0), 0.55);
+ float d = smin(a, b, 0.35);
+ return vec3(0.5 + 0.5*cos(70.0*d));
+}
+```
+
+## 9. Smooth Subtraction
+
+Equation:
+
+```text
+h = clamp(1/2 - (b+a)/(2k), 0, 1)
+ssub(a,b,k) = mix(a, -b, h) + k h(1-h)
+```
+
+GLSL:
+
+```glsl
+float smoothSub(float a, float b, float k) {
+ float h = clamp(0.5 - 0.5*(b + a)/k, 0.0, 1.0);
+ return mix(a, -b, h) + k*h*(1.0 - h);
+}
+```
+
+Visual result:
+
+A soft subtractive depression, groove, socket, seam, indentation, or eroded cut.
+
+Debug view:
+
+```glsl
+vec3 debugSmoothSub(vec3 p) {
+ float carrier = sdEllipsoid(p, vec3(0.7, 0.95, 0.55));
+ float socket = sdSphere(p, vec3(0.25, 0.2, -0.45), 0.28);
+ float d = smoothSub(carrier, socket, 0.12);
+ return vec3(0.5 + 0.5*cos(85.0*d));
+}
+```
+
+## 10. Local Transform Before Evaluation
+
+Equation:
+
+```text
+q = R^-1 (p - c) / s
+d_world(p) = s d_local(q)
+```
+
+GLSL:
+
+```glsl
+mat2 rot(float a) {
+ float s = sin(a), c = cos(a);
+ return mat2(c, -s, s, c);
+}
+
+float posedEllipsoid(vec3 p, vec3 c, vec3 r, float yaw) {
+ vec3 q = p - c;
+ q.xz = rot(-yaw) * q.xz;
+ return sdEllipsoid(q, r);
+}
+```
+
+Visual result:
+
+The object moves, rotates, or poses without complicating the primitive formula. Use this for any local feature, modular cell, tilted lobe, leaning instance, or shell component.
+
+Debug view:
+
+```glsl
+vec3 debugLocalTransform(vec3 p) {
+ float d = posedEllipsoid(p, vec3(0.0), vec3(0.45, 0.8, 0.35), 0.45);
+ return vec3(smoothstep(0.05, -0.02, d));
+}
+```
+
+## 11. Mirror Symmetry With Later Breakage
+
+Equation:
+
+```text
+q_x = |p_x|
+```
+
+GLSL:
+
+```glsl
+vec3 mirrorX(vec3 p) {
+ p.x = abs(p.x);
+ return p;
+}
+```
+
+Visual result:
+
+Symmetric paired features or bilateral ornamentation. Add small ID-based offsets afterward to avoid a dead mirrored look.
+
+Debug view:
+
+```glsl
+vec3 debugMirror(vec3 p) {
+ vec3 q = mirrorX(p);
+ float d = sdSphere(q - vec3(0.32, 0.15, 0.0), vec3(0.0), 0.15);
+ return vec3(smoothstep(0.03, -0.01, d));
+}
+```
+
+## 12. Contour Debug for Distance Fields
+
+Equation:
+
+```text
+bands(d) = 1/2 + 1/2 cos(w d)
+surface(d) = smoothstep(e, 0, |d|)
+```
+
+GLSL:
+
+```glsl
+vec3 contourDebug(float d) {
+ float bands = 0.5 + 0.5*cos(80.0*d);
+ float surface = smoothstep(0.02, 0.0, abs(d));
+ return mix(vec3(bands), vec3(1.0, 0.35, 0.1), surface);
+}
+```
+
+Visual result:
+
+Evenly spaced lines around clean SDFs. Kinks, pinches, and uneven spacing reveal bad blending, wrong scale, or non-distance operations.
+
+Debug view:
+
+Use this directly as the material color while building geometry.
+
+## 13. Cylindrical Sector Coordinates
+
+Equation:
+
+```text
+a = atan(z, x)
+r = ||(x,z)||
+u = a / 2pi * N
+id = floor(u)
+local = fract(u) - 1/2
+```
+
+GLSL:
+
+```glsl
+vec3 cylindricalSector(vec3 p, float sectors, out float sectorId) {
+ float a = atan(p.z, p.x);
+ float r = length(p.xz);
+ float u = a / 6.2831853 * sectors;
+ sectorId = floor(u);
+ float localAngle = fract(u) - 0.5;
+ return vec3(localAngle, p.y, r);
+}
+```
+
+Visual result:
+
+The scene splits into repeated radial slices. Each slice has a stable ID for color or structural variation.
+
+Debug view:
+
+```glsl
+vec3 debugSector(vec3 p) {
+ float id;
+ vec3 q = cylindricalSector(p, 12.0, id);
+ return vec3(fract(id*0.17), fract(id*0.37), fract(id*0.61)) * smoothstep(0.48, 0.0, abs(q.x));
+}
+```
+
+## 14. Radial Row-Cell Local Space
+
+Equation:
+
+```text
+row = floor(y / H)
+u = a / 2pi * N + 0.5 mod(row, 2)
+sector = floor(u)
+local = (fract(u)-1/2, fract(y/H)-1/2, r-R)
+```
+
+GLSL:
+
+```glsl
+vec3 radialRowCellSpace(vec3 p, float sectors, float rowHeight, float radius, out vec2 id) {
+ float row = floor(p.y / rowHeight);
+ float stagger = 0.5 * mod(row, 2.0);
+ float a = atan(p.z, p.x);
+ float u = a / 6.2831853 * sectors + stagger;
+ float sector = floor(u);
+ id = vec2(sector, row);
+ float lu = fract(u) - 0.5;
+ float lv = fract(p.y / rowHeight) - 0.5;
+ float lr = length(p.xz) - radius;
+ return vec3(lu, lv, lr);
+}
+```
+
+Visual result:
+
+Staggered modular cells wrapping around a cylinder. If the equation is correct, alternate rows shift by half a cell while the underlying radial shell remains aligned.
+
+Debug view:
+
+```glsl
+vec3 debugBrickIds(vec3 p) {
+ vec2 id;
+ vec3 q = radialRowCellSpace(p, 16.0, 0.22, 1.0, id);
+ float mask = step(abs(q.x), 0.45) * step(abs(q.y), 0.42);
+ return mask * vec3(fract(id.x*0.13), fract(id.y*0.19), fract(dot(id, vec2(0.07, 0.11))));
+}
+```
+
+## 15. Modular Rectangular Cell SDF
+
+Equation:
+
+```text
+d_cell = sdBox((lu, lv, lr), (W, H, D))
+```
+
+GLSL:
+
+```glsl
+float sdRadialCell(vec3 p, out vec2 id) {
+ vec3 q = radialRowCellSpace(p, 16.0, 0.22, 1.0, id);
+ q.x *= 0.75; // angular width correction
+ return sdRoundBox(q, vec3(0.32, 0.085, 0.08), 0.018);
+}
+```
+
+Visual result:
+
+Individual rectangular modules on a cylindrical lattice. Without material variation, the structure should already read from silhouette and gaps.
+
+Debug view:
+
+```glsl
+vec3 debugBrickSdf(vec3 p) {
+ vec2 id;
+ float d = sdRadialCell(p, id);
+ return contourDebug(d);
+}
+```
+
+## 16. Continuous Interstitial Radial Shell
+
+Equation:
+
+```text
+d_shell = | ||p_xz|| - R | - thickness
+d_interstitial = max(d_shell, vertical/radial trim)
+```
+
+GLSL:
+
+```glsl
+float sdInterstitialShell(vec3 p, float radius, float thickness) {
+ float shell = abs(length(p.xz) - radius) - thickness;
+ float heightTrim = abs(p.y - 0.8) - 1.1;
+ return max(shell, heightTrim);
+}
+```
+
+Visual result:
+
+The interstitial shell reads as one continuous binding/support field behind and between modular cells, not as disconnected filler rectangles.
+
+Debug view:
+
+```glsl
+vec3 debugMortar(vec3 p) {
+ float d = sdInterstitialShell(p, 1.0, 0.025);
+ return vec3(0.35, 0.34, 0.31) * smoothstep(0.03, -0.01, d);
+}
+```
+
+## 17. Bilobed Organic Carrier
+
+Equation:
+
+```text
+d = smin( ellipsoid_lobe_a, ellipsoid_lobe_b, k )
+```
+
+GLSL:
+
+```glsl
+float sdBilobedCarrier(vec3 p) {
+ float upperLobe = sdEllipsoid(p - vec3(0.0, 0.18, 0.0), vec3(0.54, 0.68, 0.46));
+ float lowerLobe = sdEllipsoid(p - vec3(0.0, -0.28, 0.02), vec3(0.42, 0.36, 0.38));
+ return smin(upperLobe, lowerLobe, 0.22);
+}
+```
+
+Visual result:
+
+A two-lobe organic carrier: one dominant lobe and one secondary lobe blended into a continuous surface.
+
+Debug view:
+
+```glsl
+vec3 debugHeadBase(vec3 p) {
+ return contourDebug(sdBilobedCarrier(p));
+}
+```
+
+## 18. Paired Concavity Carve
+
+Equation:
+
+```text
+d = smoothSub(carrier, ellipsoid_concavity, k)
+```
+
+GLSL:
+
+```glsl
+float carvePairedConcavity(float carrierD, vec3 p, float side) {
+ vec3 q = p - vec3(0.22*side, 0.12, -0.36);
+ q.x *= 1.25;
+ float concavity = sdEllipsoid(q, vec3(0.18, 0.11, 0.12));
+ return smoothSub(carrierD, concavity, 0.08);
+}
+```
+
+Visual result:
+
+Soft paired concavities in a carrier surface. In lighting, each depression should read before any secondary inset element is added.
+
+Debug view:
+
+Render the carrier field as contour bands before and after applying the carve.
+
+## 19. Parametric Arc Aperture Curve
+
+Equation:
+
+```text
+r(x) = open (1 - x^2) (4x^3 - 9x^2 + 6x - 1)
+```
+
+GLSL:
+
+```glsl
+float apertureCurve(float x, float open) {
+ float base = max(0.0, 1.0 - x*x);
+ float expression = 4.0*x*x*x - 9.0*x*x + 6.0*x - 1.0;
+ return open * base * expression;
+}
+
+float apertureMask(vec2 uv, float open) {
+ float y = apertureCurve(uv.x, open);
+ return smoothstep(0.025, 0.0, abs(uv.y - y));
+}
+```
+
+Visual result:
+
+Curved aperture bands with controllable openness and asymmetry. This is better than a circular line when the feature needs expressive deformation.
+
+Debug view:
+
+```glsl
+vec3 debugEyelid(vec2 uv) {
+ return vec3(apertureMask(uv, 0.18));
+}
+```
+
+## 20. Soft Parametric Groove
+
+Equation:
+
+```text
+d_line = |y - f(x)| - width(x)
+mask = smoothstep(e, 0, d_line)
+```
+
+GLSL:
+
+```glsl
+float softGrooveCurve(vec2 uv) {
+ float center = -0.04 + 0.06*uv.x*uv.x;
+ float width = 0.018 * smoothstep(0.55, 0.05, abs(uv.x));
+ return abs(uv.y - center) - width;
+}
+
+float softGrooveMask(vec2 uv) {
+ float d = softGrooveCurve(uv);
+ return smoothstep(0.02, -0.005, d);
+}
+```
+
+Visual result:
+
+A soft curved groove that can be shaded darker inside and tinted around its border.
+
+Debug view:
+
+Show `softGrooveMask` as grayscale on the local coordinate plane.
+
+## 21. Anisotropic Strand Tube Perturbation
+
+Equation:
+
+```text
+q' = q + A1 cos(w1 y + phi_id) + A2 sin(w2 y + psi_id)
+```
+
+GLSL:
+
+```glsl
+vec3 strandPerturbationSpace(vec3 q, float id) {
+ float phase = 6.2831853 * hash12(vec2(id, 4.0));
+ q.x += 0.025*cos(23.0*q.y + phase);
+ q.z += 0.020*sin(23.0*q.y + phase);
+ q.xz += 0.008*vec2(cos(91.0*q.y), sin(87.0*q.y));
+ return q;
+}
+
+float sdPerturbedStrandSegment(vec3 p, vec3 a, vec3 b, float r, float id) {
+ vec3 q = strandPerturbationSpace(p, id);
+ return sdCapsule(q, a, b, r);
+}
+```
+
+Visual result:
+
+A strand-like tube that feels woven or fibrous rather than perfectly cylindrical. Use multiple nearby tubes with alternating phase.
+
+Debug view:
+
+Display strand IDs as color before adding the final anisotropic material.
+
+## 22. Ellipsoidal Shell Clipped by Half-Space
+
+Equation:
+
+```text
+d = max(sdEllipsoid(p, r), sdPlane(p, n, h))
+```
+
+GLSL:
+
+```glsl
+float sdPlane(vec3 p, vec3 n, float h) {
+ return dot(p, normalize(n)) + h;
+}
+
+float sdClippedEllipsoidShell(vec3 p) {
+ float shell = abs(sdEllipsoid(p, vec3(0.72, 0.86, 0.55))) - 0.045;
+ float halfSpaceCut = sdPlane(p, vec3(0.0, 0.0, -1.0), -0.42);
+ return max(shell, -halfSpaceCut);
+}
+```
+
+Visual result:
+
+A shell-like surface with a half-space opening or clipped front.
+
+Debug view:
+
+Use material IDs: one color for the carrier, one for the shell, one for the cut/inside.
+
+## 23. Fabric Micro-Displacement
+
+Equation:
+
+```text
+d' = d + A sin(wx x) sin(wy y)
+```
+
+GLSL:
+
+```glsl
+float fabricDisplace(float d, vec3 p) {
+ float weave = sin(91.0*p.x) * sin(87.0*p.y);
+ float broad = 0.5 + 0.5*sin(7.0*p.y + 2.0*sin(3.0*p.x));
+ return d + 0.0035*weave + 0.01*broad;
+}
+```
+
+Visual result:
+
+Fine fabric or knitted texture that perturbs highlights. Keep amplitude tiny or the cloth silhouette becomes noisy.
+
+Debug view:
+
+Show the displacement field as `0.5 + 20.0*(dPrime - d)`.
+
+## 24. Cone SDF for Trees and Props
+
+Equation:
+
+```text
+cone approximates distance to a linearly shrinking radius over height
+```
+
+GLSL:
+
+```glsl
+float sdConeApprox(vec3 p, float h, float r) {
+ float y = clamp(p.y, 0.0, h);
+ float radiusAtY = r * (1.0 - y / h);
+ vec2 q = vec2(length(p.xz) - radiusAtY, p.y - y);
+ return length(max(q, 0.0)) + min(max(q.x, q.y), 0.0);
+}
+```
+
+Visual result:
+
+Simple evergreen silhouettes, roofs, spikes, stylized mountains, and cone props.
+
+Debug view:
+
+Use contour bands on one cone, then repeat with per-instance IDs.
+
+## 25. Repeated Conical Field
+
+Equation:
+
+```text
+cell = floor(xz / s)
+local = fract(xz / s) - 1/2
+height = h0 + random(cell) hvar
+```
+
+GLSL:
+
+```glsl
+float sdRepeatedConeField(vec3 p, float spacing) {
+ vec2 cell = floor(p.xz / spacing);
+ vec2 local = fract(p.xz / spacing) - 0.5;
+ float rnd = hash12(cell);
+ vec3 q = vec3(local.x*spacing, p.y, local.y*spacing);
+ float h = mix(0.8, 1.6, rnd);
+ float r = mix(0.22, 0.38, hash12(cell + 5.1));
+ return sdConeApprox(q, h, r);
+}
+```
+
+Visual result:
+
+A field of repeated conical primitives. Variation should be visible in height and radius, but the set should still read as one coherent mass.
+
+Debug view:
+
+Render `hash12(cell)` as color to verify variation is stable in world space.
+
+## 26. SDF Scene Return With Material ID
+
+Equation:
+
+```text
+scene(p) = argmin_i d_i(p)
+```
+
+GLSL:
+
+```glsl
+struct Hit {
+ float d;
+ float mat;
+};
+
+Hit pickCloser(Hit a, Hit b) {
+ return (b.d < a.d) ? b : a;
+}
+
+Hit mapScene(vec3 p) {
+ Hit h = Hit(1e5, 0.0);
+ h = pickCloser(h, Hit(sdBilobedCarrier(p), 1.0));
+ h = pickCloser(h, Hit(sdClippedEllipsoidShell(p - vec3(0.0, 0.02, 0.0)), 2.0));
+ h = pickCloser(h, Hit(sdRepeatedConeField(p - vec3(0.0, -1.0, 4.0), 1.1), 3.0));
+ return h;
+}
+```
+
+Visual result:
+
+The closest surface wins and carries a material ID. This is the backbone for readable raymarched scenes.
+
+Debug view:
+
+```glsl
+vec3 idColor(float id) {
+ return vec3(fract(id*0.37), fract(id*0.61), fract(id*0.83));
+}
+```
diff --git a/skills/codex/shader-art-coding/references/formula-code-couples-terrain.md b/skills/codex/shader-art-coding/references/formula-code-couples-terrain.md
new file mode 100644
index 0000000..3f4b4af
--- /dev/null
+++ b/skills/codex/shader-art-coding/references/formula-code-couples-terrain.md
@@ -0,0 +1,781 @@
+# Formula-Code Couples: Heightfields, Density Fields, and Atmosphere
+
+Use this file when the task needs equation-to-code translation for heightfield synthesis, stratified material fields, instanced density fields, accumulation masks, atmosphere, coverage fields, and heightfield rendering.
+
+Each couple has:
+
+- Equation: the compact mathematical idea.
+- GLSL: an original Shadertoy-friendly implementation.
+- Visual result: what should appear when the formula is correct.
+- Debug view: the simplest way to inspect it.
+
+## 1. Smooth Cell Interpolation
+
+Equation:
+
+```text
+i = floor(p)
+f = fract(p)
+s(f) = f^2(3 - 2f) or f^3(6f^2 - 15f + 10)
+h = bilerp(h00, h10, h01, h11, s)
+```
+
+GLSL:
+
+```glsl
+float hash12(vec2 p) {
+ vec3 p3 = fract(vec3(p.xyx) * 0.1031);
+ p3 += dot(p3, p3.yzx + 33.33);
+ return fract((p3.x + p3.y) * p3.z);
+}
+
+float smoothCell(vec2 p) {
+ vec2 i = floor(p);
+ vec2 f = fract(p);
+ vec2 s = f*f*(3.0 - 2.0*f);
+ float h00 = hash12(i + vec2(0.0, 0.0));
+ float h10 = hash12(i + vec2(1.0, 0.0));
+ float h01 = hash12(i + vec2(0.0, 1.0));
+ float h11 = hash12(i + vec2(1.0, 1.0));
+ return mix(mix(h00, h10, s.x), mix(h01, h11, s.x), s.y);
+}
+```
+
+Visual result:
+
+A smooth quilt of hills. No hard cell borders, but the cell structure may still be visible at low frequency.
+
+Debug view:
+
+```glsl
+vec3 debugSmoothCell(vec2 p) {
+ return vec3(smoothCell(p));
+}
+```
+
+## 2. Quintic Interpolation for Better Normals
+
+Equation:
+
+```text
+s(f) = f^3( f(6f - 15) + 10 )
+```
+
+GLSL:
+
+```glsl
+vec2 quintic(vec2 f) {
+ return f*f*f*(f*(f*6.0 - 15.0) + 10.0);
+}
+
+float smoothCellQuintic(vec2 p) {
+ vec2 i = floor(p);
+ vec2 f = fract(p);
+ vec2 s = quintic(f);
+ float h00 = hash12(i + vec2(0.0, 0.0));
+ float h10 = hash12(i + vec2(1.0, 0.0));
+ float h01 = hash12(i + vec2(0.0, 1.0));
+ float h11 = hash12(i + vec2(1.0, 1.0));
+ return mix(mix(h00, h10, s.x), mix(h01, h11, s.x), s.y);
+}
+```
+
+Visual result:
+
+Smoother heightfield lighting near cell borders. Normals should not show obvious seams.
+
+Debug view:
+
+Show normals from finite differences; seams mean interpolation or sampling is wrong.
+
+## 3. Polynomial Patch Terrain
+
+Equation:
+
+```text
+f_ij(x,z) = a + bx + cz + d xz + e x^2 + f z^2 + ...
+```
+
+GLSL:
+
+```glsl
+float patchPoly(vec2 f, vec4 coeffA, vec4 coeffB) {
+ float x = f.x;
+ float z = f.y;
+ return coeffA.x
+ + coeffA.y*x
+ + coeffA.z*z
+ + coeffA.w*x*z
+ + coeffB.x*x*x
+ + coeffB.y*z*z
+ + coeffB.z*x*x*z
+ + coeffB.w*x*z*z;
+}
+```
+
+Visual result:
+
+A cell-local scalar surface that can make ridges, basins, and slopes with more control than simple value noise.
+
+Debug view:
+
+Show one patch in isolation as a height color before layering many cells.
+
+## 4. Rotated Octave Matrix
+
+Equation:
+
+```text
+F(p) = sum_n a_n N(M^n p)
+a_n = 2^-n
+```
+
+GLSL:
+
+```glsl
+float fbmTerrain(vec2 p) {
+ mat2 m = mat2(0.8, -0.6, 0.6, 0.8) * 2.03;
+ float h = 0.0;
+ float a = 0.55;
+ for (int i = 0; i < 7; i++) {
+ h += a * smoothCellQuintic(p);
+ p = m * p + 17.3;
+ a *= 0.5;
+ }
+ return h;
+}
+```
+
+Visual result:
+
+Fractal mountain detail with fewer grid-aligned artifacts. Large forms remain if a separate base shape is added.
+
+Debug view:
+
+```glsl
+vec3 debugOctaves(vec2 p) {
+ return vec3(fbmTerrain(p));
+}
+```
+
+## 5. Base Shape Plus Detail
+
+Equation:
+
+```text
+h(p) = H_base(p) + A_detail F(p)
+```
+
+GLSL:
+
+```glsl
+float terrainHeight(vec2 p) {
+ float ridge = 0.9*exp(-0.18*abs(p.x + 0.35*p.y));
+ float basin = -0.55*exp(-0.08*dot(p - vec2(1.5, -2.0), p - vec2(1.5, -2.0)));
+ float detail = fbmTerrain(p*0.45);
+ return ridge + basin + 0.38*detail;
+}
+```
+
+Visual result:
+
+Readable low-frequency height composition with fractal detail. The field should not become an even noisy blanket.
+
+Debug view:
+
+Show `ridge + basin` alone, then `detail` alone, then the combined height.
+
+## 6. Heightfield Normal
+
+Equation:
+
+```text
+n = normalize( (-dh/dx, eps, -dh/dz) )
+```
+
+GLSL:
+
+```glsl
+vec3 terrainNormal(vec2 p) {
+ float e = 0.02;
+ float h = terrainHeight(p);
+ float hx = terrainHeight(p + vec2(e, 0.0)) - h;
+ float hz = terrainHeight(p + vec2(0.0, e)) - h;
+ return normalize(vec3(-hx, e, -hz));
+}
+```
+
+Visual result:
+
+The heightfield responds to light as a continuous surface. Steep ridges and basins should be visible under diffuse light.
+
+Debug view:
+
+```glsl
+vec3 debugTerrainNormal(vec2 p) {
+ return 0.5 + 0.5*terrainNormal(p);
+}
+```
+
+## 7. Heightfield Ray March
+
+Equation:
+
+```text
+find t where ro_y + t rd_y = h(ro_xz + t rd_xz)
+```
+
+GLSL:
+
+```glsl
+float marchTerrain(vec3 ro, vec3 rd) {
+ float t = 0.0;
+ float lastDiff = 0.0;
+ for (int i = 0; i < 180; i++) {
+ vec3 p = ro + rd*t;
+ float diff = p.y - terrainHeight(p.xz);
+ if (diff < 0.0) {
+ float lo = t - max(0.02, 0.5*lastDiff);
+ float hi = t;
+ for (int j = 0; j < 5; j++) {
+ float mid = 0.5*(lo + hi);
+ vec3 mp = ro + rd*mid;
+ if (mp.y > terrainHeight(mp.xz)) lo = mid; else hi = mid;
+ }
+ return hi;
+ }
+ lastDiff = diff;
+ t += max(0.03, 0.35*diff);
+ if (t > 220.0) break;
+ }
+ return -1.0;
+}
+```
+
+Visual result:
+
+A heightfield surface rendered from a camera without polygon geometry.
+
+Debug view:
+
+Show hit distance as fog-like grayscale; missing/black holes mean step size is too large or the heightfield slope is too steep.
+
+## 8. Diffuse Terrain Lighting
+
+Equation:
+
+```text
+L_diff = max(dot(n, l), 0)
+```
+
+GLSL:
+
+```glsl
+vec3 terrainDiffuse(vec3 p, vec3 n, vec3 lightDir) {
+ float ndl = max(dot(n, lightDir), 0.0);
+ vec3 base = mix(vec3(0.22, 0.18, 0.14), vec3(0.52, 0.48, 0.38), smoothstep(0.0, 1.2, p.y));
+ return base * (0.18 + 1.35*ndl);
+}
+```
+
+Visual result:
+
+Surfaces facing the dominant light are bright; back-facing slopes fall into cool shadow.
+
+Debug view:
+
+Show `vec3(ndl)` before mixing material colors.
+
+## 9. Heightfield Self Shadow
+
+Equation:
+
+```text
+shadow = min_t smoothstep(0, k t, rayHeight(t) - terrainHeight(xz + t l_xz))
+```
+
+GLSL:
+
+```glsl
+float terrainShadow(vec2 xz, float h, vec3 lightDir) {
+ float sh = 1.0;
+ float t = 0.08;
+ for (int i = 0; i < 48; i++) {
+ vec2 q = xz + lightDir.xz*t;
+ float rayH = h + lightDir.y*t;
+ float clearance = rayH - terrainHeight(q);
+ sh = min(sh, smoothstep(0.0, 0.18*t, clearance));
+ t += 0.15 + 0.08*t;
+ }
+ return clamp(sh, 0.0, 1.0);
+}
+```
+
+Visual result:
+
+Elevated heightfield regions cast broad readable shadows over lower regions. The effect should create scale and depth.
+
+Debug view:
+
+Show `vec3(shadow)` only. Harsh flicker means too few steps or thresholds too tight.
+
+## 10. Slope Mask
+
+Equation:
+
+```text
+slope = 1 - n_y
+mask = smoothstep(a, b, slope)
+```
+
+GLSL:
+
+```glsl
+float slopeMask(vec3 n) {
+ float slope = 1.0 - n.y;
+ return smoothstep(0.18, 0.65, slope);
+}
+```
+
+Visual result:
+
+Steep slopes can select channel B; flatter surfaces can select channel A or channel C.
+
+Debug view:
+
+Show `slopeMask(n)` as grayscale before material mixing.
+
+## 11. Altitude Mask
+
+Equation:
+
+```text
+mask = smoothstep(low, high, h)
+```
+
+GLSL:
+
+```glsl
+float altitudeMask(float h) {
+ return smoothstep(0.65, 1.6, h);
+}
+```
+
+Visual result:
+
+A height-gated material, haze, or accumulation channel appears only above a chosen scalar threshold.
+
+Debug view:
+
+Show the mask alone and move the thresholds until it reads compositionally.
+
+## 12. Stratified Three-Channel Material Mix
+
+Equation:
+
+```text
+channelB = slope
+channelC = altitude * upward
+channelA = (1-channelB)(1-channelC)
+color = channelA Ca + channelB Cb + channelC Cc
+```
+
+GLSL:
+
+```glsl
+vec3 terrainMaterial(vec3 p, vec3 n) {
+ float slope = slopeMask(n);
+ float high = altitudeMask(p.y);
+ float channelC = high * smoothstep(0.45, 0.9, n.y);
+ float channelA = (1.0 - slope) * (1.0 - channelC);
+ vec3 channelACol = vec3(0.18, 0.34, 0.12);
+ vec3 channelBCol = vec3(0.38, 0.34, 0.30);
+ vec3 channelCCol = vec3(0.86, 0.90, 0.94);
+ vec3 col = channelACol*channelA + channelBCol*slope*(1.0 - channelC) + channelCCol*channelC;
+ return col / max(0.001, channelA + slope*(1.0 - channelC) + channelC);
+}
+```
+
+Visual result:
+
+Natural material zoning: one channel on gentle slopes, one on steep slopes, and one on high/upward-facing regions.
+
+Debug view:
+
+Show the three material masks as RGB channels.
+
+## 13. Atmospheric Fog
+
+Equation:
+
+```text
+f = 1 - exp(-density * distance)
+color = mix(surface, fogColor, f)
+```
+
+GLSL:
+
+```glsl
+vec3 applyFog(vec3 col, vec3 fogCol, float dist) {
+ float f = 1.0 - exp(-0.022*dist);
+ return mix(col, fogCol, clamp(f, 0.0, 1.0));
+}
+```
+
+Visual result:
+
+Distant surfaces fade into atmospheric color, giving depth and scale.
+
+Debug view:
+
+Show `vec3(f)` to verify the fog curve before coloring.
+
+## 14. Height Fog
+
+Equation:
+
+```text
+fog *= exp(-falloff * y)
+```
+
+GLSL:
+
+```glsl
+float heightFog(float dist, float y) {
+ float base = 1.0 - exp(-0.018*dist);
+ float low = exp(-0.65*max(y, 0.0));
+ return clamp(base * low, 0.0, 1.0);
+}
+```
+
+Visual result:
+
+Low-altitude regions hold more haze than exposed high regions.
+
+Debug view:
+
+Render haze as white over black; low-altitude basins should glow softly.
+
+## 15. Sky Gradient
+
+Equation:
+
+```text
+t = smoothstep(y0, y1, rd_y)
+sky = mix(horizon, zenith, t)
+```
+
+GLSL:
+
+```glsl
+vec3 skyColor(vec3 rd, vec3 sunDir) {
+ float t = smoothstep(-0.15, 0.65, rd.y);
+ vec3 horizon = vec3(0.78, 0.86, 0.94);
+ vec3 zenith = vec3(0.20, 0.45, 0.78);
+ float sun = pow(max(dot(rd, sunDir), 0.0), 450.0);
+ return mix(horizon, zenith, t) + sun*vec3(1.0, 0.75, 0.42);
+}
+```
+
+Visual result:
+
+A readable background radiance field with a warm directional accent and cooler zenith.
+
+Debug view:
+
+Render sky alone before terrain.
+
+## 16. Atmospheric Coverage Field
+
+Equation:
+
+```text
+coverage = smoothstep(c, c+w, fbm(p + warp(p)))
+```
+
+GLSL:
+
+```glsl
+float coverageMask(vec2 p, float coverage) {
+ vec2 warp = vec2(fbmTerrain(p*0.18 + 4.1), fbmTerrain(p*0.18 - 2.8));
+ float d = fbmTerrain(p + 0.55*warp);
+ return smoothstep(coverage, coverage + 0.18, d);
+}
+```
+
+Visual result:
+
+Soft coverage-field masses with natural breakup. Big masses should exist before high-frequency details.
+
+Debug view:
+
+Show the coverage mask as grayscale over the background field.
+
+## 17. Coverage Horizon Fade
+
+Equation:
+
+```text
+coverage *= smoothstep(horizonLow, horizonHigh, y)
+```
+
+GLSL:
+
+```glsl
+float coverageHorizonFade(vec2 uv) {
+ return smoothstep(-0.08, 0.22, uv.y);
+}
+```
+
+Visual result:
+
+Coverage-field contrast fades near the horizon so the background supports depth.
+
+Debug view:
+
+Show the fade gradient alone.
+
+## 18. Directional Coverage Lighting
+
+Equation:
+
+```text
+lit = coverage * (ambient + sunTint * phase)
+```
+
+GLSL:
+
+```glsl
+vec3 shadeCloud(float mask, vec2 p, vec2 sunDir) {
+ float edge = coverageMask(p + 0.05*sunDir, 0.52) - mask;
+ float rim = smoothstep(0.0, 0.18, edge);
+ return mask * mix(vec3(0.78, 0.82, 0.88), vec3(1.0, 0.86, 0.62), rim);
+}
+```
+
+Visual result:
+
+Coverage fields have warm highlights on the light-facing side and cooler shaded interiors.
+
+Debug view:
+
+Show `rim` as grayscale to ensure it is directional.
+
+## 19. Instance Placement Grid
+
+Equation:
+
+```text
+cell = floor(xz / spacing)
+local = fract(xz / spacing) - 1/2
+rand = hash(cell)
+```
+
+GLSL:
+
+```glsl
+vec2 instanceCell(vec2 xz, float spacing, out vec2 id) {
+ vec2 g = xz / spacing;
+ id = floor(g);
+ return fract(g) - 0.5;
+}
+```
+
+Visual result:
+
+Stable instance positions in world space. Instances do not swim as the camera moves.
+
+Debug view:
+
+Render cell IDs as color.
+
+## 20. Instance Suitability Field
+
+Equation:
+
+```text
+density = altitude * flatness * moisture * distanceFade
+```
+
+GLSL:
+
+```glsl
+float instanceSuitability(float height, float slope, float moisture, float dist) {
+ float altitude = smoothstep(0.05, 0.35, height) * smoothstep(1.0, 0.65, height);
+ float flatness = smoothstep(0.85, 0.35, slope);
+ float distanceFade = smoothstep(160.0, 20.0, dist);
+ return altitude * flatness * moisture * distanceFade;
+}
+```
+
+Visual result:
+
+Instances appear in controlled zones rather than covering every surface.
+
+Debug view:
+
+Show suitability as a heightfield overlay.
+
+## 21. Volumetric Clump Density
+
+Equation:
+
+```text
+density = crown(xz) * vertical(y) * breakup(xz)
+```
+
+GLSL:
+
+```glsl
+float clumpDensity(vec3 p, vec2 cellId) {
+ float crown = 1.0 - smoothstep(0.35, 0.95, length(p.xz));
+ float vertical = smoothstep(-0.3, 0.15, p.y) * smoothstep(1.1, 0.45, p.y);
+ float breakup = 0.65 + 0.35*fbmTerrain(p.xz*3.5 + cellId);
+ return crown * vertical * breakup;
+}
+```
+
+Visual result:
+
+Instanced details read as soft volumes or clumps rather than isolated dots.
+
+Debug view:
+
+Show density as white alpha over the heightfield.
+
+## 22. Upward-Facing Accumulation Mask
+
+Equation:
+
+```text
+accumulation = upwardNormal * altitude + noise
+```
+
+GLSL:
+
+```glsl
+float upwardAccumulation(vec3 n, float height, float noiseValue) {
+ float upward = smoothstep(0.35, 0.9, n.y);
+ float altitude = smoothstep(-0.2, 0.6, height);
+ return clamp(upward * altitude + 0.18*noiseValue, 0.0, 1.0);
+}
+```
+
+Visual result:
+
+The accumulation material collects on upward-facing and elevated surfaces, not uniformly on every face.
+
+Debug view:
+
+Show the accumulation mask as grayscale before mixing the bright material.
+
+## 23. Layered Sinusoidal Ridge
+
+Equation:
+
+```text
+d = |x - sum_i A_i sin(w_i y + phi_i)| - radius(y)
+```
+
+GLSL:
+
+```glsl
+float layeredRidge(vec2 p) {
+ float wave = 0.10*sin(11.0*p.y) + 0.05*sin(23.0*p.y + 1.7);
+ float radius = max(0.015, 0.08 - 0.03*p.y);
+ return abs(p.x - wave) - radius;
+}
+```
+
+Visual result:
+
+Stylized ridge field with organic waviness.
+
+Debug view:
+
+Render `smoothstep(0.02, -0.01, layeredRidge(p))`.
+
+## 24. Curvilinear Basin/Path Mask
+
+Equation:
+
+```text
+lineMask = exp(-k * distanceToCurve^2)
+```
+
+GLSL:
+
+```glsl
+float curvilinearPathMask(vec2 p) {
+ float center = 0.35*sin(0.35*p.y) + 0.18*sin(0.9*p.y + 1.2);
+ float d = abs(p.x - center);
+ return exp(-8.0*d*d);
+}
+```
+
+Visual result:
+
+A winding basin/path/shadow corridor that gives the heightfield compositional direction.
+
+Debug view:
+
+Show the curve mask as white over height.
+
+## 25. Distance-Based Detail Reduction
+
+Equation:
+
+```text
+detailAmount = smoothstep(far, near, distance)
+```
+
+GLSL:
+
+```glsl
+float detailFade(float dist) {
+ return smoothstep(180.0, 35.0, dist);
+}
+```
+
+Visual result:
+
+Near regions have crisp detail, distant regions become broad value shapes. This avoids noisy far fields.
+
+Debug view:
+
+Show `detailFade` as grayscale over hit distance.
+
+## 26. Complete Terrain Shade Skeleton
+
+Equation:
+
+```text
+color = fog( material(p,n) * light(n,l) * shadow(p,l), distance )
+```
+
+GLSL:
+
+```glsl
+vec3 shadeTerrain(vec3 ro, vec3 rd, vec3 sunDir) {
+ float t = marchTerrain(ro, rd);
+ vec3 sky = skyColor(rd, sunDir);
+ if (t < 0.0) return sky;
+
+ vec3 p = ro + rd*t;
+ vec3 n = terrainNormal(p.xz);
+ float ndl = max(dot(n, sunDir), 0.0);
+ float sh = terrainShadow(p.xz, p.y, sunDir);
+ vec3 mat = terrainMaterial(p, n);
+ vec3 col = mat * (0.18 + 1.35*ndl*sh);
+ float fog = heightFog(t, p.y);
+ return mix(col, sky, fog);
+}
+```
+
+Visual result:
+
+A coherent heightfield rendering pipeline: scalar shape, material zones, light, shadow, and atmosphere.
+
+Debug view:
+
+Replace the final return with individual terms: `mat`, `vec3(ndl)`, `vec3(sh)`, `vec3(fog)`.
diff --git a/skills/codex/shader-art-coding/references/formula-cookbook.md b/skills/codex/shader-art-coding/references/formula-cookbook.md
new file mode 100644
index 0000000..25d1fa9
--- /dev/null
+++ b/skills/codex/shader-art-coding/references/formula-cookbook.md
@@ -0,0 +1,501 @@
+# Formula Cookbook
+
+Use this when a prompt needs concrete mathematical construction strategy, not only generic shader structure.
+
+These recipes describe visually verified shader-building patterns: define a simple field, expose IDs and local coordinates, then use those controls for geometry, material, lighting, and variation. The examples are original abstractions, not copied source.
+
+## Visual Formula Audit
+
+When deriving or checking formulas from a video, screenshot, or sketch:
+
+1. Identify the visible stage: primitive, repetition, material, lighting, or polish.
+2. Name the coordinate space before naming the formula.
+3. Find the local ID: cell, sector, row, branch, feature, material, or layer.
+4. Separate silhouette math from material math.
+5. Display the controlling scalar as grayscale before using it in color.
+6. Ask what the formula is making controllable: position, thickness, softness, slope, frequency, density, or age.
+
+Good shader formulas usually create knobs. If a formula only makes a picture more complicated and exposes no art control, simplify it.
+
+## Cylindrical Modular Cell Lattice
+
+Use this for radial cell lattices, tiled columns, pipes, shingles, woven bands, modular facades, and radial ornaments.
+
+### Field Stack
+
+1. Convert horizontal position to polar form:
+ - `radius = length(p.xz)`
+ - `angle = atan(p.z, p.x)`
+2. Divide angle into sectors for cell columns.
+3. Divide height into rows.
+4. Stagger alternate rows by half a sector.
+5. Keep IDs:
+ - `sectorId` for left/right cell variation.
+ - `rowId` for vertical variation.
+ - `brickId` for color, displacement, damage, and missing pieces.
+6. Convert back to a local cell coordinate:
+ - angular local coordinate controls cell width.
+ - vertical local coordinate controls cell height.
+ - radial coordinate controls wall thickness.
+7. Model the interstitial material as its own continuous field, not just leftover space between cells.
+
+### Visual Checks
+
+- With only local cell coordinates visible, every cell should be a centered rectangle.
+- With IDs visible, adjacent bricks should not share identical colors too often.
+- The interstitial field should remain continuous around the cylinder when rows are staggered.
+- Displacement should be strongest inside cell faces, weaker near interstitial boundaries, and not destroy the silhouette unless erosion is intended.
+
+### Generic Formula Sketch
+
+```glsl
+vec3 radialCellSpace(vec3 p, float sectors, float rowHeight, out vec2 id) {
+ float a = atan(p.z, p.x);
+ float r = length(p.xz);
+ float row = floor(p.y / rowHeight);
+ float stagger = mod(row, 2.0) * 0.5;
+ float u = a / 6.2831853 * sectors + stagger;
+ float sector = floor(u);
+ id = vec2(sector, row);
+ float lu = fract(u) - 0.5;
+ float lv = fract(p.y / rowHeight) - 0.5;
+ return vec3(lu, lv, r);
+}
+```
+
+Use a box-like SDF in `(lu, lv, radialOffset)` for each cell face. Use a cylinder or radial shell field for an interstitial shell so the binding material feels continuous rather than fragmented.
+
+### Verified Build Order
+
+For cylindrical modular-cell systems, use this order:
+
+1. Start with an existing lit raymarch renderer and a single primitive.
+2. Replace the primitive with a box SDF and verify the box in isolation.
+3. Introduce polar angle only; render a single angularly controlled band.
+4. Add `sectorId = round(angle / sectorAngle)` and rotate the point back into the sector's local axis.
+5. Add `rowId = round(y / rowHeight)` and shift the local y coordinate by row height.
+6. Add row parity or hash-based stagger before material variation.
+7. Add modular-cell SDF.
+8. Add interstitial/tube SDF as a separate object/material.
+9. Use IDs for color variation and local face coordinates for roughness.
+10. Add displacement last; keep it local to cell faces.
+
+### Cell Material Flow
+
+Use IDs for coarse variation and local coordinates for fine variation:
+
+```glsl
+float cellRand = hash12(id);
+float faceGrain = fbm(local.xy*18.0 + 7.0*cellRand);
+float interstitialMask = smoothstep(0.02, 0.08, distanceFromInterstitial);
+vec3 cellColor = mix(vec3(0.45, 0.12, 0.07), vec3(0.9, 0.32, 0.18), cellRand);
+cellColor *= 0.82 + 0.28*faceGrain;
+vec3 color = mix(vec3(0.42, 0.39, 0.34), cellColor, interstitialMask);
+```
+
+Do not use the same noise for cell ID, cell grain, interstitial stain, and displacement. Those are different art controls.
+
+## Polynomial Heightfield Synthesis
+
+Use this for heightfields, rolling scalar surfaces, basin/ridge systems, and heightfield-like abstract surfaces.
+
+### Field Stack
+
+1. Start with a height function `h(xz)`, not a mesh.
+2. Use low-frequency shape first: ridge, basin, slope, plateau, horizon silhouette.
+3. Add multi-scale detail only after the large forms compose well.
+4. Estimate normals from finite differences of the exact height function.
+5. Derive material masks from interpretable fields:
+ - altitude,
+ - slope,
+ - curvature or ridge strength,
+ - moisture/noise,
+ - distance from camera.
+6. Add atmosphere before vegetation. Fog and sky color establish scale.
+7. Add density or material channels as a density field over heightfield, then light them as volumes or clumps.
+
+### Smooth Cell Terrain
+
+For tiled procedural heightfield, avoid visible cell seams by forcing continuity at cell boundaries. A useful pattern is: choose corner heights or coefficients per cell, interpolate with a cubic/quintic curve, then layer octaves. A single high-degree polynomial over the whole scene is too global; small patches give local control.
+
+```glsl
+float smoothCellHeight(vec2 p) {
+ vec2 i = floor(p);
+ vec2 f = fract(p);
+ vec2 u = f*f*f*(f*(f*6.0 - 15.0) + 10.0);
+ float a = hash12(i + vec2(0.0, 0.0));
+ 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));
+ return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);
+}
+```
+
+### Patch Thinking
+
+For a cell `(i, j)`, treat the local coordinate `(x, z)` as living in `[0,1]^2`. Build the height from values at the four corners plus smooth interpolation:
+
+```glsl
+float patchHeight(vec2 p) {
+ vec2 i = floor(p);
+ vec2 f = fract(p);
+ vec2 s = f*f*(3.0 - 2.0*f);
+ float h00 = hash12(i + vec2(0.0, 0.0));
+ float h10 = hash12(i + vec2(1.0, 0.0));
+ float h01 = hash12(i + vec2(0.0, 1.0));
+ float h11 = hash12(i + vec2(1.0, 1.0));
+ return mix(mix(h00, h10, s.x), mix(h01, h11, s.x), s.y);
+}
+```
+
+Use quintic interpolation when normal smoothness matters. Use derivative-aware or analytic derivatives when available; otherwise use finite differences.
+
+### Octave Matrix
+
+Rotate and scale each octave to avoid grid-aligned mountains:
+
+```glsl
+float heightfieldBase(vec2 p) {
+ mat2 m = mat2(0.8, -0.6, 0.6, 0.8) * 2.0;
+ float h = 0.0;
+ float a = 1.0;
+ for (int i = 0; i < 7; i++) {
+ h += a * patchHeight(p);
+ p = m * p + 13.7;
+ a *= 0.5;
+ }
+ return h;
+}
+```
+
+Keep a separate low-frequency base shape so the composition does not become an even carpet of fractal detail.
+
+### Terrain Normal
+
+```glsl
+vec3 heightfieldNormal(vec2 xz) {
+ float e = 0.02;
+ float h = heightfieldHeight(xz);
+ float hx = heightfieldHeight(xz + vec2(e, 0.0)) - h;
+ float hz = heightfieldHeight(xz + vec2(0.0, e)) - h;
+ return normalize(vec3(-hx, e, -hz));
+}
+```
+
+### Visual Checks
+
+- Show height as grayscale; large slopes should be legible without lighting.
+- Show normals as RGB; seams reveal discontinuity immediately.
+- Show slope masks before assigning accumulation/channel A/channel B material.
+- Show fog alone over depth; atmosphere should create scale before details.
+
+### Heightfield Self-Shadowing
+
+Terrain shadows can be approximated by marching along the light direction in the heightfield. The visual idea is to compare the heightfield height under the ray with the ray's expected height.
+
+```glsl
+float heightfieldShadow(vec2 xz, float h, vec3 ldir) {
+ float shadow = 1.0;
+ float t = 0.05;
+ for (int i = 0; i < 48; i++) {
+ vec2 q = xz + ldir.xz * t;
+ float rayH = h + ldir.y * t;
+ float heightfieldH = heightfieldHeight(q);
+ float clearance = rayH - heightfieldH;
+ shadow = min(shadow, smoothstep(0.0, 0.25*t, clearance));
+ t += 0.12 + 0.08*t;
+ }
+ return clamp(shadow, 0.0, 1.0);
+}
+```
+
+This is an art approximation: reduce steps for distant heightfield and soften aggressively to avoid crawling.
+
+## Bilateral Organic SDF Composition
+
+Use this for bilateral organic carriers, articulated forms, stylized ovoids, appendages, shell layers, and props.
+
+### Field Stack
+
+1. Block the primary carrier volume with ellipsoids and capsules.
+2. Pose by transforming the local space before evaluating each body part.
+3. Blend organic masses with smooth union.
+4. Carve concavities, aperture bands, curved grooves, shell seams, and small recesses with subtraction or smooth subtraction.
+5. Use material gradients to do some work that geometry should not do: localized warmth, subsurface tint, groove color, aperture shadow, woven-material tint.
+6. Add anisotropic strands as repeated curves, capsules, shells, or clumps, not as individually simulated strands unless the shot is close.
+7. Add environment only after dominant carrier proportions read.
+
+### Smooth-Min Sculpting
+
+Use smooth minimum to turn primitive intersections into anatomy. The polynomial smooth-min radius should be smaller than the feature being blended:
+
+```glsl
+float smin(float a, float b, float k) {
+ float h = clamp(0.5 + 0.5*(b - a)/k, 0.0, 1.0);
+ return mix(b, a, h) - k*h*(1.0 - h);
+}
+```
+
+Use contour-band debug to inspect whether the field remains smooth:
+
+```glsl
+vec3 contourDebug(float d) {
+ float bands = 0.5 + 0.5*cos(80.0*d);
+ float surface = smoothstep(0.02, 0.0, abs(d));
+ return mix(vec3(bands), vec3(1.0, 0.35, 0.1), surface);
+}
+```
+
+Contours that kink or bunch reveal bad blends, wrong scale, or accidental non-SDF operations.
+
+### Ellipsoid Approximation
+
+```glsl
+float sdEllipsoid(vec3 p, vec3 r) {
+ float k0 = length(p / r);
+ float k1 = length(p / (r*r));
+ return k0 * (k0 - 1.0) / k1;
+}
+```
+
+Use ellipsoids for ovoid lobes, convex protrusions, insets, appendages, stones, leaves, and soft props. Use capsules for necks, limbs, strand bundles, straps, stems, and rails.
+
+### Concavity and Aperture Pattern
+
+Create the inset sphere as a sphere/ellipsoid, then shape aperture bands as overlapping soft masks or SDF cuts. The concavity is usually a subtractive or darkened concavity, not merely a flat disk.
+
+Visual controls:
+
+- socket depth,
+- lid thickness,
+- iris radius,
+- highlight radius,
+- brow shadow,
+- asymmetry/pose.
+
+Eyeaperture bands can be controlled by a curve radius along local x:
+
+```glsl
+float lidCurve(float x, float open) {
+ float base = 1.0 - x*x;
+ float expression = x*x*(2.0*x - 3.0) + 1.0;
+ return open * base * expression;
+}
+```
+
+This style of formula is valuable because it exposes expression controls: openness, tilt, thickness, and asymmetry.
+
+### Subsurface and Soft Materials
+
+For subsurface-like or waxy materials, use:
+
+- warm diffuse base,
+- cool soft shadow,
+- warm localized curvature/chroma masks,
+- high roughness broad specular,
+- subtle noise in color, not noisy geometry.
+
+Use geometric fields to place color:
+
+```glsl
+float freckleField(vec2 uv) {
+ vec2 cell = floor(uv*25.0);
+ vec2 q = fract(uv*25.0) - 0.5;
+ float r = 0.08 + 0.12*hash12(cell);
+ float spot = exp(-24.0*dot(q, q) / r);
+ return spot * step(0.78, hash12(cell + 19.1));
+}
+
+float softBlush(vec3 n, vec3 viewDir, float cheekMask) {
+ float facing = pow(clamp(dot(n, -viewDir), 0.0, 1.0), 2.0);
+ return cheekMask * facing;
+}
+```
+
+Subsurface detail should be sparse and masked. Uniform procedural stochastic spots across every surface look synthetic.
+
+### Anisotropic Strand Clumps
+
+Use a curve or tube coordinate `q`, a strand ID, and sinusoidal offsets:
+
+```glsl
+vec3 braidOffset(vec3 q, float id) {
+ float phase = 6.28318*hash12(vec2(id, 4.0));
+ q.x += 0.025*cos(23.0*q.y + phase);
+ q.z += 0.020*sin(23.0*q.y + phase);
+ q.xz += 0.008*vec2(cos(91.0*q.y), sin(87.0*q.y));
+ return q;
+}
+```
+
+For visible strand bundles, repeat three or more lobes around the strand-bundle cross-section, then shade with alternating highlights using the strand ID and local tangent direction.
+
+### Visual Checks
+
+- In normal debug, facial planes should flow smoothly across blended forms.
+- In material-ID debug, insets, subsurface material, strands, shell layers, and props should be cleanly separable.
+- In grayscale, the focal carrier should read without relying on hue.
+
+## Vegetation as Volumetric Clumps
+
+Use this for instanced clump fields, low vegetation density fields, moss-like coverage, and stylized volumetric density.
+
+Do not start with individual leaves. Start with a density envelope:
+
+```glsl
+float foliageDensity(vec3 p, vec2 cellId) {
+ float crown = 1.0 - smoothstep(0.6, 1.0, length(p.xz));
+ float vertical = smoothstep(-0.4, 0.2, p.y) * smoothstep(1.2, 0.5, p.y);
+ float breakup = 0.65 + 0.35*fbm(p.xz*4.0 + cellId);
+ return crown * vertical * breakup;
+}
+```
+
+Then shade the clump with directional light, fake self-shadowing, and distance fade. Variation should come from cell IDs: height, hue, lean, crown radius, and density.
+
+For heightfield forests, place clumps using a grid over heightfield, but derive density from slope, altitude, light, and distance:
+
+```glsl
+float treeSuitability(float height, float slope, float moisture, float dist) {
+ float altitude = smoothstep(0.05, 0.35, height) * smoothstep(1.0, 0.65, height);
+ float flatness = smoothstep(0.85, 0.35, slope);
+ float distanceFade = smoothstep(140.0, 20.0, dist);
+ return altitude * flatness * moisture * distanceFade;
+}
+```
+
+Instance fields should align to the heightfield normal for close views and become texture/density fields in the distance.
+
+## Clouds and Atmospheric Volume
+
+Use this for skies, fog banks, mist, smoke, and volumetric-looking 2D effects.
+
+Atmospheric coverage recipe:
+
+1. Build a low-frequency coverage field.
+2. Warp coordinates gently with fbm.
+3. Use height or screen-y to shape coverage layer thickness.
+4. Light one side with the sun direction.
+5. Fade with distance/horizon.
+
+```glsl
+float cloudMask(vec2 p, float coverage) {
+ vec2 warp = vec2(fbm(p*0.45 + 4.1), fbm(p*0.45 - 2.8));
+ float d = fbm(p + 0.55*warp);
+ return smoothstep(coverage, coverage + 0.18, d);
+}
+```
+
+Visual checks:
+
+- Clouds should have large masses before wispy detail.
+- The sun-facing side should be warmer/brighter.
+- Coverage contrast should fall near the horizon if atmosphere is present.
+
+## Environment Props and Snowy Detail
+
+Use environment props to support the subject, not compete with it.
+
+Common formulas:
+
+- Cones for conical instance silhouettes.
+- Boxes/capsules for rails, planks, fences, bridges, and posts.
+- Sine-stacked offsets for layered branches, accumulation ridges, or stylized bark.
+- Height masks and upward normals for upward-facing accumulation.
+- Low-frequency fbm for uneven ground and wind-drifted accumulation.
+
+```glsl
+float snowAccumulation(vec3 n, float height, float noiseValue) {
+ float upward = smoothstep(0.35, 0.9, n.y);
+ float altitude = smoothstep(-0.2, 0.6, height);
+ return clamp(upward * altitude + 0.18*noiseValue, 0.0, 1.0);
+}
+
+float layeredBranch(vec2 p) {
+ float wave = 0.10*sin(11.0*p.y) + 0.05*sin(23.0*p.y + 1.7);
+ return abs(p.x - wave) - (0.08 - 0.03*p.y);
+}
+```
+
+For accumulation-material scenes, separate white material from bright lighting: the accumulation material has blue/cool shadow, warm highlights, rough sparkle, and soft occlusion in creases.
+
+## Temporal Polish
+
+Use tiny motion fields at the end:
+
+- camera breathing,
+- carrier/aperture drift,
+- cloth/fog movement,
+- branch sway,
+- coverage-field drift.
+
+```glsl
+float slowNoise(float t, float seed) {
+ return fbm(vec2(0.13*t, seed));
+}
+
+vec3 subtleCameraOffset(float t) {
+ return 0.01*vec3(
+ slowNoise(t, 1.0) - 0.5,
+ slowNoise(t, 2.0) - 0.5,
+ slowNoise(t, 3.0) - 0.5
+ );
+}
+```
+
+Motion should reveal the mathematical form without making the shader harder to inspect.
+
+## Material Breakup Without Noise Soup
+
+Use material breakup in named layers:
+
+- edge wear: function of SDF distance to bevel/edge,
+- stains: low-frequency world-space noise with gravity bias,
+- grain: tangent or object-local stretched noise,
+- cracks: thresholded cellular/noise ridges,
+- color variation: ID hash plus low-frequency noise,
+- roughness variation: independent from albedo.
+
+Noise should be masked by material logic:
+
+```glsl
+float cellInteriorMask = smoothstep(0.08, 0.14, distanceFromInterstitial);
+float grain = fbm(localFaceUv*18.0);
+albedo *= mix(1.0, 0.75 + 0.35*grain, cellInteriorMask);
+```
+
+This keeps detail inside the visual object it belongs to.
+
+## Composition Math
+
+Mathematical images still need composition math:
+
+- Put the focal mass near thirds or golden-ratio intersections, but break exact symmetry.
+- Use a broad value ramp from foreground to background.
+- Reduce high-frequency detail with distance.
+- Use directional light to draw attention toward the subject.
+- Use masks to reserve saturated color for the focal area.
+
+Composition overlays can be temporary debug views:
+
+```glsl
+float ruleLine(vec2 uv, float x) {
+ return smoothstep(0.006, 0.0, abs(uv.x - x));
+}
+vec3 compositionOverlay(vec2 uv, vec3 col) {
+ float g = 0.618;
+ float lines = max(ruleLine(uv, -g), ruleLine(uv, g));
+ lines = max(lines, max(ruleLine(uv.yx, -g), ruleLine(uv.yx, g)));
+ return mix(col, vec3(1.0, 0.85, 0.15), 0.45*lines);
+}
+```
+
+## Formula Selection Heuristics
+
+- Need perfect controllable silhouette: use SDF or analytic masks.
+- Need broad natural variation: use smooth noise/fbm.
+- Need repeated objects: use cell IDs and local coordinates.
+- Need organic blends: use smooth union/subtraction.
+- Need manufactured seams: use hard booleans, bevels, and separate material IDs.
+- Need scale: use fog, value compression, frequency reduction, and desaturation with distance.
+- Need bilateral organic appeal: use proportions, asymmetry, warm/cool material gradients, and clean inset/aperture geometry before micro-detail.
diff --git a/skills/codex/shader-art-coding/references/glsl-snippets.md b/skills/codex/shader-art-coding/references/glsl-snippets.md
new file mode 100644
index 0000000..1df377f
--- /dev/null
+++ b/skills/codex/shader-art-coding/references/glsl-snippets.md
@@ -0,0 +1,261 @@
+# GLSL Snippets
+
+These snippets are original Shadertoy-compatible building blocks. Adapt them to the user's scene.
+
+## Hash and Noise
+
+```glsl
+float hash12(vec2 p) {
+ vec3 p3 = fract(vec3(p.xyx) * 0.1031);
+ p3 += dot(p3, p3.yzx + 33.33);
+ return fract((p3.x + p3.y) * p3.z);
+}
+
+float noise(vec2 p) {
+ vec2 i = floor(p);
+ vec2 f = fract(p);
+ vec2 u = f*f*(3.0 - 2.0*f);
+ float a = hash12(i + vec2(0.0, 0.0));
+ 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));
+ return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);
+}
+
+float fbm(vec2 p) {
+ float f = 0.0;
+ float a = 0.5;
+ mat2 m = mat2(1.6, 1.2, -1.2, 1.6);
+ for (int i = 0; i < 5; i++) {
+ f += a * noise(p);
+ p = m * p + 11.7;
+ a *= 0.5;
+ }
+ return f;
+}
+```
+
+## 2D Masks
+
+```glsl
+float sdCircle(vec2 p, float r) {
+ return length(p) - r;
+}
+
+float sdRoundBox(vec2 p, vec2 b, float r) {
+ vec2 q = abs(p) - b + r;
+ return length(max(q, 0.0)) + min(max(q.x, q.y), 0.0) - r;
+}
+
+float fillMask(float d) {
+ return smoothstep(fwidth(d), -fwidth(d), d);
+}
+
+float strokeMask(float d, float width) {
+ float w = fwidth(d);
+ return smoothstep(width + w, width - w, abs(d));
+}
+```
+
+## Camera
+
+```glsl
+mat3 lookAt(vec3 ro, vec3 ta, float roll) {
+ vec3 ww = normalize(ta - ro);
+ vec3 uu = normalize(cross(ww, vec3(sin(roll), cos(roll), 0.0)));
+ vec3 vv = cross(uu, ww);
+ return mat3(uu, vv, ww);
+}
+
+vec3 cameraRay(vec2 uv, vec3 ro, vec3 ta, float lens) {
+ mat3 cam = lookAt(ro, ta, 0.0);
+ return normalize(cam * vec3(uv, lens));
+}
+```
+
+## SDF Utility Extras
+
+```glsl
+float smin(float a, float b, float k) {
+ float h = clamp(0.5 + 0.5*(b - a)/k, 0.0, 1.0);
+ return mix(b, a, h) - k*h*(1.0 - h);
+}
+
+float sdEllipsoid(vec3 p, vec3 r) {
+ float k0 = length(p / r);
+ float k1 = length(p / (r*r));
+ return k0 * (k0 - 1.0) / k1;
+}
+
+float sdTorus(vec3 p, vec2 t) {
+ vec2 q = vec2(length(p.xz) - t.x, p.y);
+ return length(q) - t.y;
+}
+
+float opSmoothSub(float a, float b, float k) {
+ float h = clamp(0.5 - 0.5*(b + a)/k, 0.0, 1.0);
+ return mix(a, -b, h) + k*h*(1.0 - h);
+}
+```
+
+## Debug Displays
+
+```glsl
+vec3 contourDebug(float d) {
+ float bands = 0.5 + 0.5*cos(80.0*d);
+ float surface = smoothstep(0.02, 0.0, abs(d));
+ return mix(vec3(bands), vec3(1.0, 0.35, 0.1), surface);
+}
+
+vec3 idColor(float id) {
+ return vec3(fract(id*0.37), fract(id*0.61), fract(id*0.83));
+}
+```
+
+## Heightfield Helpers
+
+```glsl
+float smoothCellHeight(vec2 p) {
+ vec2 i = floor(p);
+ vec2 f = fract(p);
+ vec2 u = f*f*f*(f*(f*6.0 - 15.0) + 10.0);
+ float a = hash12(i + vec2(0.0, 0.0));
+ 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));
+ return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);
+}
+
+vec3 heightNormal(vec2 p) {
+ float e = 0.02;
+ float h = terrainHeight(p);
+ return normalize(vec3(
+ h - terrainHeight(p + vec2(e, 0.0)),
+ e,
+ h - terrainHeight(p + vec2(0.0, e))
+ ));
+}
+```
+
+`heightNormal` expects the shader to define `terrainHeight(vec2)`.
+
+## Complete Minimal Raymarch Shader
+
+```glsl
+#define DEBUG_MODE 0
+
+struct Hit {
+ float d;
+ float mat;
+};
+
+mat3 lookAt(vec3 ro, vec3 ta, float roll) {
+ vec3 ww = normalize(ta - ro);
+ vec3 uu = normalize(cross(ww, vec3(sin(roll), cos(roll), 0.0)));
+ vec3 vv = cross(uu, ww);
+ return mat3(uu, vv, ww);
+}
+
+vec3 cameraRay(vec2 uv, vec3 ro, vec3 ta, float lens) {
+ mat3 cam = lookAt(ro, ta, 0.0);
+ return normalize(cam * vec3(uv, lens));
+}
+
+float hash12(vec2 p) {
+ vec3 p3 = fract(vec3(p.xyx) * 0.1031);
+ p3 += dot(p3, p3.yzx + 33.33);
+ return fract((p3.x + p3.y) * p3.z);
+}
+
+float sdSphere(vec3 p, float r) {
+ return length(p) - r;
+}
+
+float sdBox(vec3 p, vec3 b) {
+ vec3 q = abs(p) - b;
+ return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);
+}
+
+float opSmoothUnion(float a, float b, float k) {
+ float h = clamp(0.5 + 0.5*(b - a)/k, 0.0, 1.0);
+ return mix(b, a, h) - k*h*(1.0 - h);
+}
+
+Hit mapScene(vec3 p) {
+ Hit h = Hit(p.y + 0.75, 1.0);
+
+ vec3 q = p - vec3(0.0, 0.0, 3.0);
+ float body = sdSphere(q, 0.85);
+ float cut = sdBox(q - vec3(0.0, -0.25, 0.0), vec3(1.2, 0.2, 1.2));
+ body = max(body, -cut);
+
+ if (body < h.d) h = Hit(body, 2.0);
+ return h;
+}
+
+Hit raymarch(vec3 ro, vec3 rd) {
+ float t = 0.0;
+ float mat = 0.0;
+ for (int i = 0; i < 96; i++) {
+ vec3 p = ro + rd*t;
+ Hit h = mapScene(p);
+ if (h.d < 0.001*t + 0.0005) return Hit(t, h.mat);
+ if (t > 60.0) break;
+ t += h.d;
+ mat = h.mat;
+ }
+ return Hit(-1.0, mat);
+}
+
+vec3 calcNormal(vec3 p) {
+ vec2 e = vec2(0.001, -0.001);
+ return normalize(
+ e.xyy*mapScene(p + e.xyy).d +
+ e.yyx*mapScene(p + e.yyx).d +
+ e.yxy*mapScene(p + e.yxy).d +
+ e.xxx*mapScene(p + e.xxx).d
+ );
+}
+
+vec3 materialColor(float mat, vec3 p) {
+ if (mat < 1.5) return vec3(0.34, 0.30, 0.25);
+ float grain = hash12(floor(p.xz*12.0));
+ return mix(vec3(0.75, 0.42, 0.28), vec3(0.95, 0.72, 0.48), grain);
+}
+
+vec3 tonemap(vec3 x) {
+ x = max(x, 0.0);
+ return x / (1.0 + x);
+}
+
+void mainImage(out vec4 fragColor, in vec2 fragCoord) {
+ vec2 uv = (2.0*fragCoord - iResolution.xy) / iResolution.y;
+
+ float time = iTime;
+ vec3 ro = vec3(2.6*sin(0.2*time), 1.1, -1.2 + 2.6*cos(0.2*time));
+ vec3 ta = vec3(0.0, -0.05, 3.0);
+ vec3 rd = cameraRay(uv, ro, ta, 1.8);
+
+ vec3 sky = mix(vec3(0.62, 0.76, 0.95), vec3(0.08, 0.11, 0.16), smoothstep(-0.2, 0.8, uv.y));
+ vec3 col = sky;
+
+ Hit hit = raymarch(ro, rd);
+ if (hit.d > 0.0) {
+ vec3 p = ro + rd*hit.d;
+ vec3 n = calcNormal(p);
+ vec3 ldir = normalize(vec3(0.5, 0.8, -0.3));
+ float ndl = max(dot(n, ldir), 0.0);
+ float fres = pow(1.0 + dot(n, rd), 5.0);
+ vec3 albedo = materialColor(hit.mat, p);
+ col = albedo * (0.18 + 1.25*ndl) + 0.16*fres;
+ float fog = 1.0 - exp(-0.025*hit.d*hit.d);
+ col = mix(col, sky, clamp(fog, 0.0, 1.0));
+
+ if (DEBUG_MODE == 1) col = 0.5 + 0.5*n;
+ if (DEBUG_MODE == 2) col = vec3(fract(hit.mat*0.37), fract(hit.mat*0.61), fract(hit.mat*0.83));
+ }
+
+ col = pow(tonemap(col), vec3(1.0/2.2));
+ fragColor = vec4(col, 1.0);
+}
+```
diff --git a/skills/codex/shader-art-coding/references/math-patterns.md b/skills/codex/shader-art-coding/references/math-patterns.md
new file mode 100644
index 0000000..ae49040
--- /dev/null
+++ b/skills/codex/shader-art-coding/references/math-patterns.md
@@ -0,0 +1,160 @@
+# Math Patterns
+
+## Coordinates
+
+Use centered coordinates for Shadertoy:
+
+```glsl
+vec2 uv = (2.0*fragCoord - iResolution.xy) / iResolution.y;
+```
+
+Create local spaces by translating, rotating, scaling, mirroring, or repeating before evaluating a shape. Prefer local-space transforms over complicated global formulas.
+
+Common transforms:
+
+- Mirror symmetry: `p.x = abs(p.x);`
+- Polar angle: `float a = atan(p.y, p.x);`
+- Radius: `float r = length(p);`
+- Cell ID: `vec2 id = floor(p);`
+- Local cell coordinate: `vec2 q = fract(p) - 0.5;`
+- Rotate a local part instead of rotating the whole scene when posing features.
+
+```glsl
+mat2 rot(float a) {
+ float s = sin(a), c = cos(a);
+ return mat2(c, -s, s, c);
+}
+```
+
+## Shaping Functions
+
+Use shaping functions as art controls:
+
+- `smoothstep(a, b, x)` creates soft masks and antialias-like transitions.
+- `pow(x, k)` remaps contrast; `k > 1` tightens highlights, `k < 1` opens shadows.
+- `exp(-k*x)` creates haze, glow falloff, and atmospheric depth.
+- `sin` and `cos` are best as periodic controls, not random detail.
+- `mix(a, b, t)` should usually receive a named mask.
+
+Name masks after their visual role:
+
+```glsl
+float rimMask = smoothstep(0.15, 0.0, abs(d));
+float accumulationLine = smoothstep(0.35, 0.75, height + 0.2*noise);
+```
+
+## SDF Basics
+
+An SDF returns negative inside, zero on the surface, positive outside. Keep primitive helpers small and composable.
+
+Useful primitives:
+
+```glsl
+float sdSphere(vec3 p, float r) {
+ return length(p) - r;
+}
+
+float sdBox(vec3 p, vec3 b) {
+ vec3 q = abs(p) - b;
+ return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);
+}
+
+float sdCapsule(vec3 p, vec3 a, vec3 b, float r) {
+ vec3 pa = p - a, ba = b - a;
+ float h = clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0);
+ return length(pa - ba*h) - r;
+}
+```
+
+Composition:
+
+```glsl
+float opUnion(float a, float b) { return min(a, b); }
+float opSub(float a, float b) { return max(a, -b); }
+float opIntersect(float a, float b) { return max(a, b); }
+
+float opSmoothUnion(float a, float b, float k) {
+ float h = clamp(0.5 + 0.5*(b - a)/k, 0.0, 1.0);
+ return mix(b, a, h) - k*h*(1.0 - h);
+}
+```
+
+Use smooth union for organic blending and hard boolean operations for manufactured or carved forms.
+
+Smooth subtraction is useful for eyeaperture bands, sockets, grooves, dents, and soft cuts:
+
+```glsl
+float opSmoothSub(float a, float b, float k) {
+ float h = clamp(0.5 - 0.5*(b + a)/k, 0.0, 1.0);
+ return mix(a, -b, h) + k*h*(1.0 - h);
+}
+```
+
+## Repetition and IDs
+
+Separate repetition from variation:
+
+```glsl
+vec2 cell = floor(p.xz);
+vec2 local = fract(p.xz) - 0.5;
+float rnd = hash12(cell);
+```
+
+For circular repetition, use angle sectors and radius independently. Keep the sector ID for material variation.
+
+## Noise, FBM, and Domain Warping
+
+Use noise in tiers:
+
+- Low frequency: silhouette, heightfield height, coverage masses.
+- Mid frequency: material breakup, vegetation clumps, stone surface.
+- High frequency: grain, pores, scratches, sparkle.
+
+FBM pattern:
+
+```glsl
+float fbm(vec2 p) {
+ float a = 0.5;
+ float f = 0.0;
+ mat2 m = mat2(1.6, 1.2, -1.2, 1.6);
+ for (int i = 0; i < 5; i++) {
+ f += a * noise(p);
+ p = m * p;
+ a *= 0.5;
+ }
+ return f;
+}
+```
+
+Domain warping means using one field to move the coordinates of another:
+
+```glsl
+vec2 warp = vec2(fbm(p + 3.1), fbm(p - 2.7));
+float pattern = fbm(p + 0.35*warp);
+```
+
+Keep warp amplitude small until the base structure works.
+
+## Formula Debugging
+
+Every scalar field can become an image. Before using a scalar to drive color, geometry, or animation, show it:
+
+```glsl
+fragColor = vec4(vec3(fieldValue), 1.0);
+fragColor = vec4(vec3(smoothstep(a, b, fieldValue)), 1.0);
+fragColor = vec4(0.5 + 0.5*normal, 1.0);
+```
+
+If a field is too noisy in grayscale, it will be too noisy after coloring. If a mask has bad edges, material polish will not save it.
+
+## Palettes
+
+Use palettes as controlled ramps, not random RGB constants:
+
+```glsl
+vec3 palette(float t, vec3 a, vec3 b, vec3 c, vec3 d) {
+ return a + b*cos(6.28318*(c*t + d));
+}
+```
+
+For natural scenes, combine physically motivated value ramps with gentle hue shifts: warmer light, cooler shadow, lower saturation in distance.
diff --git a/skills/codex/shader-art-coding/references/rendering-patterns.md b/skills/codex/shader-art-coding/references/rendering-patterns.md
new file mode 100644
index 0000000..16351d9
--- /dev/null
+++ b/skills/codex/shader-art-coding/references/rendering-patterns.md
@@ -0,0 +1,168 @@
+# Rendering Patterns
+
+## Raymarching Structure
+
+Use a clear SDF scene function and a bounded marcher:
+
+```glsl
+struct Hit {
+ float d;
+ float mat;
+};
+
+Hit mapScene(vec3 p) {
+ Hit h = Hit(1e5, 0.0);
+ float ground = p.y + 1.0;
+ h = Hit(ground, 1.0);
+
+ float body = sdSphere(p - vec3(0.0, 0.0, 3.0), 1.0);
+ if (body < h.d) h = Hit(body, 2.0);
+ return h;
+}
+
+Hit raymarch(vec3 ro, vec3 rd) {
+ float t = 0.0;
+ float mat = 0.0;
+ for (int i = 0; i < 96; i++) {
+ vec3 p = ro + rd*t;
+ Hit h = mapScene(p);
+ if (h.d < 0.001*t) return Hit(t, h.mat);
+ if (t > 80.0) break;
+ t += h.d;
+ mat = h.mat;
+ }
+ return Hit(-1.0, mat);
+}
+```
+
+Scale epsilon with distance to reduce shimmer in far geometry.
+
+## Normals
+
+Use tetrahedral sampling for compact normals:
+
+```glsl
+vec3 calcNormal(vec3 p) {
+ vec2 e = vec2(0.001, -0.001);
+ return normalize(
+ e.xyy*mapScene(p + e.xyy).d +
+ e.yyx*mapScene(p + e.yyx).d +
+ e.yxy*mapScene(p + e.yxy).d +
+ e.xxx*mapScene(p + e.xxx).d
+ );
+}
+```
+
+If the surface has procedural displacement, sample the same displaced field for normals.
+
+## Lighting
+
+Start with one directional light, then add fill and ambient:
+
+```glsl
+vec3 shade(vec3 p, vec3 n, vec3 rd, float mat) {
+ vec3 ldir = normalize(vec3(0.6, 0.8, 0.4));
+ float ndl = max(dot(n, ldir), 0.0);
+ float fres = pow(1.0 + dot(n, rd), 5.0);
+ vec3 albedo = materialColor(mat, p);
+ vec3 col = albedo * (0.18 + 1.25*ndl);
+ col += 0.15*fres;
+ return col;
+}
+```
+
+Keep material identity visible under diffuse light before adding specular polish.
+
+## Ambient Occlusion and Soft Shadow
+
+Use small, bounded approximations:
+
+```glsl
+float calcAO(vec3 p, vec3 n) {
+ float occ = 0.0;
+ float sca = 1.0;
+ for (int i = 0; i < 5; i++) {
+ float h = 0.02 + 0.12*float(i)/4.0;
+ float d = mapScene(p + n*h).d;
+ occ += (h - d) * sca;
+ sca *= 0.75;
+ }
+ return clamp(1.0 - 2.0*occ, 0.0, 1.0);
+}
+
+float softShadow(vec3 ro, vec3 rd, float mint, float maxt, float k) {
+ float res = 1.0;
+ float t = mint;
+ for (int i = 0; i < 48; i++) {
+ float h = mapScene(ro + rd*t).d;
+ if (h < 0.001) return 0.0;
+ res = min(res, k*h/t);
+ t += clamp(h, 0.02, 0.5);
+ if (t > maxt) break;
+ }
+ return clamp(res, 0.0, 1.0);
+}
+```
+
+Use these as art controls, not as a substitute for good shape design.
+
+## Heightfields and Atmosphere
+
+For landscapes, separate:
+
+- Terrain height function.
+- Surface normal from height differences.
+- Material masks from altitude, slope, moisture/noise, and distance.
+- Sky color and sun direction.
+- Fog based on distance and height.
+
+Atmosphere should reinforce depth:
+
+```glsl
+vec3 applyFog(vec3 col, vec3 fogCol, float dist) {
+ float f = 1.0 - exp(-0.025*dist);
+ return mix(col, fogCol, clamp(f, 0.0, 1.0));
+}
+```
+
+## Antialiasing
+
+For analytic 2D masks, use derivatives when available:
+
+```glsl
+float aaStep(float edge, float x) {
+ float w = fwidth(x);
+ return smoothstep(edge - w, edge + w, x);
+}
+```
+
+For SDF edges, avoid fixed-width smoothing in screen space unless the scale is fixed. Derivative-aware or distance-scaled thresholds usually look better.
+
+## Color Management
+
+If lighting can exceed 1.0, tonemap and gamma-correct:
+
+```glsl
+vec3 tonemap(vec3 x) {
+ x = max(x, 0.0);
+ return x / (1.0 + x);
+}
+
+vec3 toSRGB(vec3 x) {
+ return pow(max(x, 0.0), vec3(1.0/2.2));
+}
+```
+
+## Practical Renderer Scaffolding
+
+For complex formula-heavy shaders, keep these renderer pieces stable while changing the scene:
+
+- Camera ray generation.
+- `mapScene` returning distance and material ID.
+- Normal calculation using the same map as rendering.
+- Ambient occlusion and soft shadow functions.
+- Background/sky.
+- Tonemap/gamma.
+- Optional cheap dithering after color grading.
+
+This lets formula experiments focus on one field at a time. Do not rewrite the renderer while testing a new SDF, terrain patch, or material mask unless the renderer is the problem.
diff --git a/skills/codex/shader-art-coding/references/shader-workflow.md b/skills/codex/shader-art-coding/references/shader-workflow.md
new file mode 100644
index 0000000..1eb07ea
--- /dev/null
+++ b/skills/codex/shader-art-coding/references/shader-workflow.md
@@ -0,0 +1,84 @@
+# Shader Workflow
+
+Use this workflow when creating or revising procedural shaders.
+
+## 1. Visual Contract
+
+Before coding, define the image in operational terms:
+
+- Subject: what the viewer should recognize first.
+- Camera: orthographic, perspective, low angle, portrait, macro, wide heightfield, flythrough.
+- Spatial model: 2D masks, heightfield, SDF scene, volumetric field, post effect.
+- Materials: matte, waxy, stone, subsurface, glass, metal, mist, density-field, painted ink.
+- Composition: silhouette, foreground/midground/background, focal contrast, empty space.
+- Motion: camera drift, object motion, environmental motion, loop duration.
+
+If the user only gives a vague style, choose a small concrete scene and state it.
+
+## 2. First Visible Pass
+
+Make the shader visible before making it clever:
+
+1. Normalize coordinates with aspect preservation.
+2. Draw a background gradient or sky.
+3. Add one primitive, mask, SDF, or height profile.
+4. Add a single color ramp or diffuse light.
+5. Confirm orientation and scale with debug colors.
+
+The first pass should answer: "Is this the right visual family?"
+
+## 3. Layering Order
+
+Build in layers that can be debugged independently:
+
+1. Domain and camera.
+2. Large forms.
+3. Repetition or variation IDs.
+4. Secondary forms and cuts.
+5. Material assignment.
+6. Lighting and shadows.
+7. Atmosphere and depth cues.
+8. Surface detail.
+9. Color grade and antialiasing.
+
+For 3D SDF scenes, keep geometry and material ID decisions close together. For 2D drawings, keep masks named by visual role rather than math trick.
+
+## 4. Debug Views
+
+Add cheap debug modes while developing:
+
+- Raw SDF distance as grayscale.
+- `abs(d)` contour bands for surface inspection.
+- Normal direction as `0.5 + 0.5*n`.
+- Material ID as flat colors.
+- Raymarch step count heatmap.
+- Height/noise octave contribution.
+- Masks for foreground, midground, atmosphere, and highlights.
+
+Debug modes should be easy to delete or gate behind a constant.
+
+## 5. Refinement Strategy
+
+Refine from global to local:
+
+- Proportions before details.
+- Silhouette before material texture.
+- Value structure before hue variation.
+- Lighting direction before shadow polish.
+- One noise layer before many octaves.
+- Performance after the visual target is clear.
+
+Avoid adding noise to hide weak structure. Noise should express a material or natural process.
+
+## 6. Review Checklist
+
+Before finalizing:
+
+- The code has a clear coordinate/camera section.
+- Constants have visual names or comments where useful.
+- Loops are bounded and have escape conditions.
+- Main objects read in silhouette.
+- Materials differ in value, roughness, or lighting response, not only hue.
+- The shader has antialiasing for sharp masks or edges.
+- The final color is tonemapped/gamma-aware when lighting exceeds 0-1.
+- The response explains the knobs a user can tune.
diff --git a/skills/codex/shader-art-coding/scripts/validate_skill_examples.py b/skills/codex/shader-art-coding/scripts/validate_skill_examples.py
new file mode 100644
index 0000000..76c0b70
--- /dev/null
+++ b/skills/codex/shader-art-coding/scripts/validate_skill_examples.py
@@ -0,0 +1,68 @@
+#!/usr/bin/env python3
+"""Validate GLSL snippets bundled with the shader-art-coding skill."""
+
+from __future__ import annotations
+
+import re
+import sys
+from pathlib import Path
+
+
+FENCE_RE = re.compile(r"```glsl\n(.*?)\n```", re.DOTALL)
+
+
+def balanced(source: str, open_ch: str, close_ch: str) -> bool:
+ depth = 0
+ for ch in source:
+ if ch == open_ch:
+ depth += 1
+ elif ch == close_ch:
+ depth -= 1
+ if depth < 0:
+ return False
+ return depth == 0
+
+
+def main() -> int:
+ skill_dir = Path(__file__).resolve().parents[1]
+ refs = skill_dir / "references"
+ failures: list[str] = []
+ snippet_count = 0
+ complete_count = 0
+
+ for path in sorted(refs.glob("*.md")):
+ text = path.read_text(encoding="utf-8")
+ for index, snippet in enumerate(FENCE_RE.findall(text), start=1):
+ snippet_count += 1
+ label = f"{path.name} snippet {index}"
+ if ("TO" + "DO") in snippet:
+ failures.append(f"{label}: contains placeholder text")
+ for a, b, name in [("{", "}", "braces"), ("(", ")", "parentheses"), ("[", "]", "brackets")]:
+ if not balanced(snippet, a, b):
+ failures.append(f"{label}: unbalanced {name}")
+ if "void mainImage" in snippet:
+ complete_count += 1
+ for required in ["fragColor", "fragCoord", "iResolution"]:
+ if required not in snippet:
+ failures.append(f"{label}: mainImage missing {required}")
+ for loop in re.findall(r"for\\s*\\((.*?)\\)", snippet):
+ if "int" not in loop or "<" not in loop:
+ failures.append(f"{label}: loop may not be statically bounded: {loop}")
+
+ if snippet_count == 0:
+ failures.append("no GLSL snippets found")
+ if complete_count == 0:
+ failures.append("no complete mainImage snippet found")
+
+ if failures:
+ print("Validation failed:")
+ for failure in failures:
+ print(f"- {failure}")
+ return 1
+
+ print(f"Validated {snippet_count} GLSL snippets; {complete_count} complete shader snippet(s).")
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())