Loading...
Loading...
Comprehensive GLSL shader techniques for creating stunning visual effects — ray marching, SDF modeling, fluid simulation, particle systems, procedural generation, lighting, post-processing, and more.
npx skill4agent add minimax-ai/skills shader-dev/shader-dev <request>$ARGUMENTSshader-dev/
├── SKILL.md # Core skill (this file)
├── techniques/ # Implementation guides (read per routing table)
│ ├── ray-marching.md # Sphere tracing with SDF
│ ├── sdf-3d.md # 3D signed distance functions
│ ├── lighting-model.md # PBR, Phong, toon shading
│ ├── procedural-noise.md # Perlin, Simplex, FBM
│ └── ... # 34 more technique files
└── reference/ # Detailed guides (read as needed)
├── ray-marching.md # Math derivations & advanced patterns
├── sdf-3d.md # Extended SDF theory
├── lighting-model.md # Lighting math deep-dive
├── procedural-noise.md # Noise function theory
└── ... # 34 more reference filestechniques/reference/| User wants to create... | Primary technique | Combine with |
|---|---|---|
| 3D objects / scenes from math | ray-marching + sdf-3d | lighting-model, shadow-techniques |
| Complex 3D shapes (booleans, blends) | csg-boolean-operations | sdf-3d, ray-marching |
| Infinite repeating patterns in 3D | domain-repetition | sdf-3d, ray-marching |
| Organic / warped shapes | domain-warping | procedural-noise |
| Fluid / smoke / ink effects | fluid-simulation | multipass-buffer |
| Particle effects (fire, sparks, snow) | particle-system | procedural-noise, color-palette |
| Physically-based simulations | simulation-physics | multipass-buffer |
| Game of Life / reaction-diffusion | cellular-automata | multipass-buffer, color-palette |
| Ocean / water surface | water-ocean | atmospheric-scattering, lighting-model |
| Terrain / landscape | terrain-rendering | atmospheric-scattering, procedural-noise |
| Clouds / fog / volumetric fire | volumetric-rendering | procedural-noise, atmospheric-scattering |
| Sky / sunset / atmosphere | atmospheric-scattering | volumetric-rendering |
| Realistic lighting (PBR, Phong) | lighting-model | shadow-techniques, ambient-occlusion |
| Shadows (soft / hard) | shadow-techniques | lighting-model |
| Ambient occlusion | ambient-occlusion | lighting-model, normal-estimation |
| Path tracing / global illumination | path-tracing-gi | analytic-ray-tracing, multipass-buffer |
| Precise ray-geometry intersections | analytic-ray-tracing | lighting-model |
| Voxel worlds (Minecraft-style) | voxel-rendering | lighting-model, shadow-techniques |
| Noise / FBM textures | procedural-noise | domain-warping |
| Tiled 2D patterns | procedural-2d-pattern | polar-uv-manipulation |
| Voronoi / cell patterns | voronoi-cellular-noise | color-palette |
| Fractals (Mandelbrot, Julia, 3D) | fractal-rendering | color-palette, polar-uv-manipulation |
| Color grading / palettes | color-palette | — |
| Bloom / tone mapping / glitch | post-processing | multipass-buffer |
| Multi-pass ping-pong buffers | multipass-buffer | — |
| Texture / sampling techniques | texture-sampling | — |
| Camera / matrix transforms | matrix-transform | — |
| Surface normals | normal-estimation | — |
| Polar coords / kaleidoscope | polar-uv-manipulation | procedural-2d-pattern |
| 2D shapes / UI from SDF | sdf-2d | color-palette |
| Procedural audio / music | sound-synthesis | — |
| SDF tricks / optimization | sdf-tricks | sdf-3d, ray-marching |
| Anti-aliased rendering | anti-aliasing | sdf-2d, post-processing |
| Depth of field / motion blur / lens effects | camera-effects | post-processing, multipass-buffer |
| Advanced texture mapping / no-tile textures | texture-mapping-advanced | terrain-rendering, texture-sampling |
| WebGL2 shader errors / debugging | webgl-pitfalls | — |
fragCoordmain()canvas.getContext("webgl2")#version 300 esprecision highp float;out vec4 fragColor;attributeinvaryingoutvaryingingl_FragColorfragColortexture2D()texture()gl_FragCoord.xyfragCoordfragCoord// WRONG
vec2 uv = (2.0 * fragCoord - iResolution.xy) / iResolution.y;
// CORRECT
vec2 uv = (2.0 * gl_FragCoord.xy - iResolution.xy) / iResolution.y;void mainImage(out vec4 fragColor, in vec2 fragCoord)void main()void mainImage(out vec4 fragColor, in vec2 fragCoord) {
// shader code...
fragColor = vec4(col, 1.0);
}
void main() {
mainImage(fragColor, gl_FragCoord.xy);
}// WRONG — getAtmosphere() calls getSunDirection() before it's defined
vec3 getAtmosphere(vec3 dir) { return getSunDirection(); } // Error!
vec3 getSunDirection() { return normalize(vec3(1.0)); }
// CORRECT — define callee first
vec3 getSunDirection() { return normalize(vec3(1.0)); }
vec3 getAtmosphere(vec3 dir) { return getSunDirection(); } // Works#defineconst// WRONG
#define SUN_DIR normalize(vec3(0.8, 0.4, -0.6))
// CORRECT
const vec3 SUN_DIR = vec3(0.756, 0.378, -0.567); // Pre-computed normalized value<script>#version.trim()const fs = document.getElementById('fs').text.trim();gl.getUniformLocation()null#defineterrainM(vec2)terrainM(pos.xz + offset)terrainM(pos + offset)body { margin: 0; overflow: hidden; background: #000; }iTimeiResolutioniMouseiFrameletconst<script>// 1. State variables FIRST
let frameCount = 0;
let startTime = Date.now();
// 2. Canvas/GL init, shader compile, FBO creation
const canvas = document.getElementById('canvas');
const gl = canvas.getContext('webgl2');
// ...
// 3. Functions and event bindings LAST
function resize() { /* can now safely reference frameCount */ }
function render() { /* ... */ }
window.addEventListener('resize', resize);letconstReferenceErrorfloat fbm(vec3 p)fbm(uv)vec2patchcastsamplefilterinputoutputcommonpartitionactivevec3 x = 1.0vec3 x = vec3(1.0).zvec2ifelse| What to check | Code | What to look for |
|---|---|---|
| Surface normals | | Smooth gradients = correct normals; banding = epsilon too large |
| Ray march step count | | Red hotspots = performance bottleneck; uniform = wasted iterations |
| Depth / distance | | Verify correct hit distances |
| UV coordinates | | Check coordinate mapping |
| SDF distance field | | Visualize SDF bands and zero-crossing |
| Checker pattern (UV) | | Verify UV distortion, seams |
| Lighting only | | Isolate shadow/AO contributions |
| Material ID | | Verify material assignment |