Cookbook
Copy-paste shader recipes for common effects, patterns, and techniques.
Turn the guide into code
Take the key idea from this page into the playground and validate it in a real shader instead of leaving it as theory.
Open PlaygroundPractical recipes you can drop into your shaders. Each one is self-contained with a live preview — tweak values, see results, copy the code.
Color & Tone
Grayscale
Convert a color to grayscale using perceptual luminance weights (human eyes are most sensitive to green):
Sepia Tone
Warm vintage look by mapping luminance to a tinted ramp:
Contrast Adjustment
Push colors away from or toward mid-gray:
Procedural Patterns
Checkerboard
Classic two-tone grid. Works on any UV-mapped surface:
Stripes
Diagonal bands with configurable frequency:
Dots
Circular dots on a grid:
Grid Lines
Thin lines forming a grid — useful for debug overlays and ground planes:
For anti-aliased grid lines, use fwidth to adapt thickness to screen-space derivatives. See fwidth.
Lighting Effects
Rim Lighting
Bright edge glow when the surface faces away from the camera. Common for character highlights and sci-fi effects:
Hemisphere Lighting
Simple ambient that varies between a sky color (up) and ground color (down). Much better than flat ambient:
Matcap (Material Capture)
Sample lighting from view-space normals. Gives complex lighting from a single calculation — no lights needed:
Animation
Pulsing Glow
Sinusoidal intensity oscillation:
Vertex Wobble
Displace vertices with a sine wave for organic/liquid motion:
Screen Effects (Post-Processing)
Vignette
Darken the edges of the screen for a cinematic look:
Film Grain
Add subtle noise for a filmic quality:
Pixelate
Snap UV coordinates to a grid for a retro pixel art look:
Surface Effects
Dissolve
Clip pixels based on noise, revealing or hiding geometry over time:
Fresnel / Edge Glow
Surfaces become more reflective at glancing angles. Useful for glass, water, force fields:
Triplanar Mapping
Project a pattern from three axes to avoid UV stretching on irregular geometry:
See Also
- Shader Concepts — Foundational GPU and shader knowledge
- PBR — Physically based rendering with interactive demos
- Intrinsics Overview — All built-in functions
- Playground — Try any recipe live