Skip to content

archibate/dotfiles-opencode / skills/shader-dev

shader-dev

Verified

Comprehensive GLSL shader techniques for creating stunning visual effects — ray marching, SDF modeling, fluid simulation, particle systems, procedural generation, lighting, post-processing, and more.

FileKindSize
SKILL.mdskill md16.5 KB
reference/ambient-occlusion.mdmarkdown14.5 KB
reference/analytic-ray-tracing.mdmarkdown24.1 KB
reference/anti-aliasing.mdmarkdown2.9 KB
reference/atmospheric-scattering.mdmarkdown27.5 KB
reference/camera-effects.mdmarkdown3.0 KB
reference/cellular-automata.mdmarkdown26.7 KB
reference/color-palette.mdmarkdown19.9 KB
reference/csg-boolean-operations.mdmarkdown17.5 KB
reference/domain-repetition.mdmarkdown17.7 KB
reference/domain-warping.mdmarkdown16.6 KB
reference/fluid-simulation.mdmarkdown18.5 KB
reference/fractal-rendering.mdmarkdown18.2 KB
reference/lighting-model.mdmarkdown29.4 KB
reference/matrix-transform.mdmarkdown18.5 KB
reference/multipass-buffer.mdmarkdown24.8 KB
reference/normal-estimation.mdmarkdown17.2 KB
reference/particle-system.mdmarkdown28.3 KB
reference/path-tracing-gi.mdmarkdown27.5 KB
reference/polar-uv-manipulation.mdmarkdown22.6 KB
reference/post-processing.mdmarkdown23.9 KB
reference/procedural-2d-pattern.mdmarkdown16.3 KB
reference/procedural-noise.mdmarkdown21.7 KB
reference/ray-marching.mdmarkdown15.5 KB
reference/sdf-2d.mdmarkdown27.5 KB
reference/sdf-3d.mdmarkdown26.8 KB
reference/sdf-tricks.mdmarkdown2.6 KB
reference/shadow-techniques.mdmarkdown21.0 KB
reference/simulation-physics.mdmarkdown27.6 KB
reference/sound-synthesis.mdmarkdown23.6 KB
reference/terrain-rendering.mdmarkdown32.2 KB
reference/texture-mapping-advanced.mdmarkdown3.3 KB
reference/texture-sampling.mdmarkdown25.6 KB
reference/volumetric-rendering.mdmarkdown28.1 KB
reference/voronoi-cellular-noise.mdmarkdown17.6 KB
reference/voxel-rendering.mdmarkdown29.2 KB
reference/water-ocean.mdmarkdown20.2 KB
reference/webgl-pitfalls.mdmarkdown1.9 KB
techniques/ambient-occlusion.mdmarkdown11.1 KB
techniques/analytic-ray-tracing.mdmarkdown18.8 KB
techniques/anti-aliasing.mdmarkdown4.5 KB
techniques/atmospheric-scattering.mdmarkdown18.2 KB
techniques/camera-effects.mdmarkdown3.4 KB
techniques/cellular-automata.mdmarkdown19.0 KB
techniques/color-palette.mdmarkdown12.8 KB
techniques/csg-boolean-operations.mdmarkdown15.0 KB
techniques/domain-repetition.mdmarkdown9.7 KB
techniques/domain-warping.mdmarkdown12.5 KB
techniques/fluid-simulation.mdmarkdown46.5 KB
techniques/fractal-rendering.mdmarkdown13.0 KB
techniques/lighting-model.mdmarkdown17.1 KB
techniques/matrix-transform.mdmarkdown12.4 KB
techniques/multipass-buffer.mdmarkdown33.5 KB
techniques/normal-estimation.mdmarkdown9.1 KB
techniques/particle-system.mdmarkdown44.6 KB
techniques/path-tracing-gi.mdmarkdown21.5 KB
techniques/polar-uv-manipulation.mdmarkdown13.2 KB
techniques/post-processing.mdmarkdown30.3 KB
techniques/procedural-2d-pattern.mdmarkdown10.7 KB
techniques/procedural-noise.mdmarkdown16.9 KB
techniques/ray-marching.mdmarkdown13.7 KB
techniques/sdf-2d.mdmarkdown21.2 KB
techniques/sdf-3d.mdmarkdown21.6 KB
techniques/sdf-tricks.mdmarkdown3.4 KB
techniques/shadow-techniques.mdmarkdown24.8 KB
techniques/simulation-physics.mdmarkdown56.2 KB
techniques/sound-synthesis.mdmarkdown17.2 KB
techniques/terrain-rendering.mdmarkdown14.3 KB
techniques/texture-mapping-advanced.mdmarkdown4.3 KB
techniques/texture-sampling.mdmarkdown13.0 KB
techniques/volumetric-rendering.mdmarkdown12.3 KB
techniques/voronoi-cellular-noise.mdmarkdown13.0 KB
techniques/voxel-rendering.mdmarkdown45.2 KB
techniques/water-ocean.mdmarkdown17.8 KB
techniques/webgl-pitfalls.mdmarkdown5.4 KB

techniques/texture-mapping-advanced.md

View on GitHub
# Advanced Texture Mapping Techniques

## Use Cases
- Texturing 3D surfaces without UV seams (triplanar/biplanar mapping)
- Eliminating visible tiling repetition on large surfaces
- Proper texture filtering in ray-marched scenes (mip-level selection)
- Combining procedural and sampled textures

## Techniques

### 1. Biplanar Mapping (Optimized Triplanar)

Uses only 2 texture fetches instead of 3, selecting the two most relevant projection axes:

```glsl
vec4 biplanar(sampler2D sam, vec3 p, vec3 n, float k) {
    vec3 dpdx = dFdx(p);
    vec3 dpdy = dFdy(p);
    n = abs(n);

    // Determine major, minor, median axes
    ivec3 ma = (n.x > n.y && n.x > n.z) ? ivec3(0,1,2) :
               (n.y > n.z)              ? ivec3(1,2,0) : ivec3(2,0,1);
    ivec3 mi = (n.x < n.y && n.x < n.z) ? ivec3(0,1,2) :
               (n.y < n.z)              ? ivec3(1,2,0) : ivec3(2,0,1);
    ivec3 me = ivec3(3) - mi - ma;

    // Two texture fetches (major and median projections)
    vec4 x = textureGrad(sam, vec2(p[ma.y], p[ma.z]),
                         vec2(dpdx[ma.y], dpdx[ma.z]),
                         vec2(dpdy[ma.y], dpdy[ma.z]));
    vec4 y = textureGrad(sam, vec2(p[me.y], p[me.z]),
                         vec2(dpdx[me.y], dpdx[me.z]),
                         vec2(dpdy[me.y], dpdy[me.z]));

    // Blend weights with local support
    vec2 w = vec2(n[ma.x], n[me.x]);
    w = clamp((w - 0.5773) / (1.0 - 0.5773), 0.0, 1.0);  // 0.5773 = 1/sqrt(3)
    w = pow(w, vec2(k / 8.0));

    return (x * w.x + y * w.y) / (w.x + w.y);
}
// Usage: vec4 col = biplanar(tex, worldPos * scale, worldNormal, 8.0);
```

**Why biplanar over triplanar**: Saves one texture fetch (bandwidth-bound advantage), with k=8 visually equivalent to triplanar. The `dFdx/dFdy` gradient propagation prevents mipmap seams at axis-switching boundaries.

### 2. Texture Repetition Avoidance

Three approaches to eliminate visible tiling patterns:

#### Method A: Per-Tile Random Offset (4 fetches)
```glsl
vec4 textureNoTile(sampler2D sam, vec2 uv) {
    vec2 iuv = floor(uv);
    vec2 fuv = fract(uv);

    // Generate 4 random offsets for the 4 surrounding tiles
    vec4 ofa = hash42(iuv + vec2(0, 0));
    vec4 ofb = hash42(iuv + vec2(1, 0));
    vec4 ofc = hash42(iuv + vec2(0, 1));
    vec4 ofd = hash42(iuv + vec2(1, 1));

    // Transform UVs per tile
    vec2 uva = uv + ofa.xy;
    vec2 uvb = uv + ofb.xy;
    vec2 uvc = uv + ofc.xy;
    vec2 uvd = uv + ofd.xy;

    // Blend near borders with smooth weights
    vec2 b = smoothstep(0.25, 0.75, fuv);
    return mix(mix(texture(sam, uva), texture(sam, uvb), b.x),
               mix(texture(sam, uvc), texture(sam, uvd), b.x), b.y);
}
```

#### Method B: Virtual Pattern (2 fetches, cheapest)
```glsl
vec4 textureNoTileCheap(sampler2D sam, vec2 uv) {
    float k = texture(iChannel1, 0.005 * uv).x;  // low-freq variation index
    float index = k * 8.0;
    float i = floor(index);
    float f = fract(index);

    // Two offset lookups based on index
    vec2 offa = sin(vec2(3.0, 7.0) * (i + 0.0));
    vec2 offb = sin(vec2(3.0, 7.0) * (i + 1.0));

    return mix(texture(sam, uv + offa), texture(sam, uv + offb), smoothstep(0.2, 0.8, f));
}
```

### 3. Ray Differential Texture Filtering

For ray-marched scenes, compute proper mip levels using ray differentials:
```glsl
// After finding hit point pos with normal nor:
// 1. Compute neighbor pixel ray directions
vec3 rdx = normalize(rd + dFdx(rd));  // x-neighbor ray
vec3 rdy = normalize(rd + dFdy(rd));  // y-neighbor ray

// 2. Intersect neighbors with tangent plane at hit point
float dt_dx = -dot(pos - ro, nor) / dot(rdx, nor);
float dt_dy = -dot(pos - ro, nor) / dot(rdy, nor);
vec3 posDx = ro + rdx * dt_dx;
vec3 posDy = ro + rdy * dt_dy;

// 3. World-space position derivatives = pixel footprint
vec3 dposdx = posDx - pos;
vec3 dposdy = posDy - pos;

// 4. Transform to texture derivatives and use textureGrad
// For simple planar mapping (e.g. ground plane):
vec2 duvdx = dposdx.xz * textureScale;
vec2 duvdy = dposdy.xz * textureScale;
vec4 color = textureGrad(tex, pos.xz * textureScale, duvdx, duvdy);
```

This provides correct mip-level selection for procedural and sampled textures on ray-marched surfaces, eliminating shimmer and aliasing at distance.

→ For deeper details, see [reference/texture-mapping-advanced.md](../reference/texture-mapping-advanced.md)
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 196kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 192kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 192kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 192kUpdated Claude CodeCodexVerifiedInstall