Skip to content

BumpyClock/agent-templates / skills/shader-art-coding

shader-art-coding

Verified

Writes, debugs, and art-directs procedural GLSL fragment shaders (Shadertoy mainImage, WebGL2 / GLSL ES 3.00): SDF raymarching, procedural buildings/cities, 2D distance-field graphics, noise / fBm / domain warping, terrain, ocean/coastal water optics, clouds and other volumes, PBR lighting, color and tonemapping. Ships a verified GLSL building-block library with a bundler and checker. Use when the user asks for a shader, Shadertoy, GLSL/.frag/.glsl code, a raymarcher, an SDF scene, a procedural texture or generative visual, or wants a shader fixed, optimized, ported or explained. Not for HLSL/Unity ShaderLab or non-graphics GPU compute.

FileKindSize
CREDITS.mdmarkdown6.3 KB
LICENSEother1.0 KB
SKILL.mdskill md7.1 KB
agents/openai.yamlconfig298 B
glsl/architecture.glslother1.8 KB
glsl/atmosphere.glslother4.6 KB
glsl/camera.glslother2.1 KB
glsl/color.glslother4.7 KB
glsl/common.glslother2.7 KB
glsl/debug.glslother1.4 KB
glsl/domain.glslother4.8 KB
glsl/hash.glslother4.1 KB
glsl/intersect.glslother1.7 KB
glsl/noise.glslother21.3 KB
glsl/operators.glslother5.3 KB
glsl/pattern.glslother3.1 KB
glsl/post.glslother2.6 KB
glsl/raymarch.glslother4.0 KB
glsl/sdf2d.glslother11.7 KB
glsl/sdf3d.glslother10.0 KB
glsl/shading.glslother4.6 KB
glsl/tonemap.glslother4.8 KB
glsl/volume.glslother3.4 KB
glsl/water.glslother3.1 KB
references/composition-and-debugging.mdmarkdown5.2 KB
references/formula-code-couples-materials.mdmarkdown15.5 KB
references/formula-code-couples-sdf.mdmarkdown20.5 KB
references/formula-code-couples-terrain.mdmarkdown17.1 KB
references/formula-cookbook.mdmarkdown19.0 KB
references/library-index.mdmarkdown56.2 KB
references/noise-use-cases.mdmarkdown17.1 KB
references/procedural-buildings.mdmarkdown7.5 KB
references/rendering-pipeline.mdmarkdown8.4 KB
references/sdf-library-guide.mdmarkdown10.4 KB
references/shader-workflow.mdmarkdown3.5 KB
references/subject-routing.mdmarkdown9.7 KB
references/terrain-production.mdmarkdown7.3 KB
references/water-quality.mdmarkdown10.6 KB
scripts/glsl_tools.pyscript29.4 KB
templates/alpine-valley.glslother3.9 KB
templates/coastal-water.glslother7.6 KB
templates/noise-progression.glslother2.3 KB
templates/noise-terrain-map.glslother2.2 KB
templates/ocean.glslother13.1 KB
templates/pattern-swatches.glslother3.6 KB
templates/procedural-city.glslother4.5 KB
templates/raymarch-sdf.glslother5.3 KB
templates/sdf-2d-poster.glslother3.7 KB
templates/terrain.glslother4.7 KB
templates/volumetric-clouds.glslother3.9 KB

references/formula-code-couples-materials.md

View on GitHub
# 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.

## Contents

- [1. Smoothstep Mask](#1-smoothstep-mask)
- [2. Derivative Antialiasing](#2-derivative-antialiasing)
- [3. Fill Mask From SDF](#3-fill-mask-from-sdf)
- [4. Stroke Mask From SDF](#4-stroke-mask-from-sdf)
- [5. Cosine Palette](#5-cosine-palette)
- [6. Warm Light, Cool Shadow](#6-warm-light-cool-shadow)
- [7. Fresnel Rim](#7-fresnel-rim)
- [8. Normal-View Localized Warmth Mask](#8-normal-view-localized-warmth-mask)
- [9. Sparse Stochastic Spot Field](#9-sparse-stochastic-spot-field)
- [10. Radial-Cell ID Albedo Variation](#10-radial-cell-id-albedo-variation)
- [11. Local Cell Grain](#11-local-cell-grain)
- [12. Interstitial Boundary Mask](#12-interstitial-boundary-mask)
- [13. Material Lambda Mix](#13-material-lambda-mix)
- [14. Multi-Material Weighted Sum](#14-multi-material-weighted-sum)
- [15. Edge Wear](#15-edge-wear)
- [16. Dirt or Stain Gravity Bias](#16-dirt-or-stain-gravity-bias)
- [17. Specular Lobe](#17-specular-lobe)
- [18. Radial Chromatic Ring Field](#18-radial-chromatic-ring-field)
- [19. Composition Thirds Overlay](#19-composition-thirds-overlay)
- [20. Golden Ratio Overlay](#20-golden-ratio-overlay)
- [21. Tonemap](#21-tonemap)
- [22. Linear to sRGB](#22-linear-to-srgb)
- [23. Dithering](#23-dithering)
- [24. Slow Procedural Motion](#24-slow-procedural-motion)
- [25. Looping Time Phase](#25-looping-time-phase)
- [26. Temporal Aperture Pulse Mask](#26-temporal-aperture-pulse-mask)
- [27. Background Blur Weight](#27-background-blur-weight)
- [28. Material Debug Router](#28-material-debug-router)

Names here describe geometry, not subjects, so the formulas stay reusable. `subject-routing.md` maps them to subjects (for example, "bilobed carrier" is a head or torso). Helpers such as `sdEllipsoid`, `smin`, `hash12` and `fbm` come from `glsl/` and are verified there.

## 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, 4);
    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), 4);
    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), 4));
    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
display = T(exposure * hdr)       T = AgX (default), Khronos Neutral (palette-faithful), ACES (filmic contrast)
```

GLSL: use `glsl/tonemap.glsl`. Every tonemapper there takes linear HDR and returns linear [0,1]. `x / (1 + x)`
looks grey (1.0 maps to 0.5) and shifts hue in highlights; avoid it for finished work.

```glsl
vec3 finishColor(vec3 hdr, float exposure) {
    return tonemapAgX(hdr * exposure);
}
```

Visual result:

Suns, glows and specular highlights roll off smoothly toward white instead of clipping to flat saturated blobs.

Debug view:

Render a horizontal HDR ramp `vec3(exp2(uv.x * 12.0 - 8.0))` through each tonemapper and compare the shoulders.

## 22. Linear to sRGB

Equation:

```text
srgb = 12.92 c                      for c <= 0.0031308
srgb = 1.055 c^(1/2.4) - 0.055      otherwise
```

GLSL: `linearToSrgb` (and the inverse `srgbToLinear`) from `glsl/color.glsl`. `pow(c, 1/2.2)` is visibly wrong near
black: linear 0.001 encodes to 0.013 with the exact curve but 0.043 with gamma 2.2, which lifts and fogs shadows.

```glsl
vec3 encodeOutput(vec3 linearColor) { return linearToSrgb(linearColor); }
```

Visual result:

Correct mid-tones and clean shadows. Apply exactly once, after tonemapping and after averaging AA samples.

Debug view:

A linear ramp `vec3(uv.x)` encoded once should look perceptually even; encoded twice it looks washed out.

## 23. Dithering

Equation:

```text
encoded += (u1 + u2 - 1) / 255        triangular PDF, +-1 LSB, added after encoding
```

GLSL: `ditherTPDF(fragCoord, iFrame)` from `glsl/post.glsl`.

```glsl
vec3 finalPixel(vec3 hdr, float exposure, vec2 fragCoord) {
    return linearToSrgb(tonemapAgX(hdr * exposure)) + ditherTPDF(fragCoord, iFrame);
}
```

Visual result:

Smooth skies, fog and vignettes with no banding and no visible noise.

Debug view:

Multiply the dither by 32 to see its pattern; it should be fine, even grain with no structure.

## 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), 4);
}

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.
receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementationStars: 319kUpdated Claude CodeCodexVerifiedInstall
requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirementsStars: 319kUpdated Claude CodeCodexVerifiedInstall
using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallbackStars: 319kUpdated Claude CodeCodexVerifiedInstall
verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions alwaysStars: 319kUpdated Claude CodeCodexVerifiedInstall