shadertoy
This skill should be used when working with Shadertoy shaders, GLSL fragment shaders, or creating procedural graphics for the web. Use when writing .glsl files, implementing visual effects, creating generative art, or working with WebGL shader code. This skill provides GLSL ES syntax reference, common shader patterns, and Shadertoy-specific conventions.
What this skill does
# Shadertoy Shader Development
## Overview
Shadertoy is a platform for creating and sharing GLSL fragment shaders that run in the browser using WebGL. This skill provides comprehensive guidance for writing shaders including GLSL ES syntax, common patterns, mathematical techniques, and best practices specific to real-time procedural graphics.
## When to Use This Skill
Activate this skill when:
- Writing or editing `.glsl` shader files
- Creating procedural graphics, generative art, or visual effects
- Working with Shadertoy.com projects or WebGL fragment shaders
- Implementing ray marching, distance fields, or procedural textures
- Debugging shader code or optimizing shader performance
- Need GLSL ES syntax reference or Shadertoy input variables
## Core Concepts
### Shader Entry Point
Every Shadertoy shader implements the `mainImage` function:
```glsl
void mainImage(out vec4 fragColor, in vec2 fragCoord)
{
// fragCoord: pixel coordinates (0 to iResolution.xy)
// fragColor: output color (RGBA, typically alpha = 1.0)
vec2 uv = fragCoord / iResolution.xy;
fragColor = vec4(uv, 0.0, 1.0);
}
```
### Shadertoy Built-in Inputs
Always available in shaders:
| Type | Name | Description |
|------|------|-------------|
| `vec3` | `iResolution` | Viewport resolution (x, y, aspect ratio) |
| `float` | `iTime` | Current time in seconds (primary animation driver) |
| `float` | `iTimeDelta` | Time to render one frame |
| `int` | `iFrame` | Current frame number |
| `vec4` | `iMouse` | Mouse: xy = current position, zw = click position |
| `sampler2D` | `iChannel0`-`iChannel3` | Input textures/buffers |
| `vec3` | `iChannelResolution[4]` | Resolution of each input channel |
| `vec4` | `iDate` | Year, month, day, time in seconds (.xyzw) |
### Coordinate System Setup
Standard patterns for normalizing coordinates:
```glsl
// Aspect-corrected UV centered at origin (-1 to 1, aspect-preserved)
vec2 uv = (fragCoord.xy - 0.5 * iResolution.xy) / min(iResolution.y, iResolution.x);
// Alternative compact form:
vec2 uv = (fragCoord * 2.0 - iResolution.xy) / min(iResolution.x, iResolution.y);
// Simple normalized (0 to 1)
vec2 uv = fragCoord / iResolution.xy;
```
## Common Shader Patterns
### 1. Procedural Color Palettes
Use Inigo Quilez's cosine palette for smooth color gradients:
```glsl
vec3 palette(float t, vec3 a, vec3 b, vec3 c, vec3 d) {
return a + b * cos(6.28318 * (c * t + d));
}
// Example usage:
vec3 col = palette(
t,
vec3(0.5, 0.5, 0.5), // base
vec3(0.5, 0.5, 0.5), // amplitude
vec3(1.0, 1.0, 0.5), // frequency
vec3(0.8, 0.90, 0.30) // phase
);
```
### 2. Hash Functions (Pseudo-Random)
Simple 2D hash for noise and randomness:
```glsl
float hash21(vec2 p) {
p = fract(p * vec2(234.34, 435.345));
p += dot(p, p + 34.23);
return fract(p.x * p.y);
}
```
### 3. Ray Marching
Standard pattern for 3D rendering via sphere tracing:
```glsl
// Distance field function
float map(vec3 p) {
return length(p) - 1.0; // Sphere at origin, radius 1
}
// Normal calculation
vec3 calcNormal(vec3 p) {
vec2 e = vec2(0.001, 0.0);
return normalize(vec3(
map(p + e.xyy) - map(p - e.xyy),
map(p + e.yxy) - map(p - e.yxy),
map(p + e.yyx) - map(p - e.yyx)
));
}
// Ray marching loop
vec3 render(vec3 ro, vec3 rd) {
float t = 0.0;
for (int i = 0; i < 100; i++) {
vec3 p = ro + rd * t;
float d = map(p);
if (d < 0.001) {
// Hit - calculate lighting
vec3 n = calcNormal(p);
return n * 0.5 + 0.5; // Normal visualization
}
if (t > 10.0) break;
t += d * 0.5; // Step (0.5 factor for safety)
}
return vec3(0.0); // Miss
}
```
### 4. Rotations
2D rotation:
```glsl
mat2 rot2d(float a) {
float c = cos(a), s = sin(a);
return mat2(c, -s, s, c);
}
// Usage: p.xy *= rot2d(iTime);
```
3D axis-angle rotation (modifies in-place):
```glsl
void rot(inout vec3 p, vec3 axis, float angle) {
axis = normalize(axis);
float s = sin(angle), c = cos(angle), oc = 1.0 - c;
mat3 m = mat3(
oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s,
oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s,
oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c
);
p = m * p;
}
```
### 5. Domain Repetition and Folding
Create fractal-like structures:
```glsl
vec3 foldRotate(vec3 p, float timeOffset) {
for (int i = 0; i < 5; i++) {
p = abs(p); // Mirror fold
rot(p, vec3(0.707, 0.707, 0.0), 0.785);
p -= 0.5; // Translate
}
return p;
}
```
### 6. Post-Processing
Vignette:
```glsl
float vignette(vec2 uv) {
uv *= 1.0 - uv.yx;
return pow(uv.x * uv.y * 15.0, 0.25);
}
```
Film grain/dithering (reduces banding):
```glsl
float dither = hash21(fragCoord + iTime) * 0.001;
finalCol += dither;
```
Gamma correction:
```glsl
finalCol = pow(finalCol, vec3(0.45)); // ~1/2.2
```
## Multi-Pass Rendering
For complex effects requiring temporal feedback or multiple rendering stages:
### Buffer A (Computation):
```glsl
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = fragCoord / iResolution.xy;
// Generate or compute values
fragColor = vec4(computedColor, 1.0);
}
```
### Buffer B (Feedback/Blending):
```glsl
#define BUFFER_A iChannel0
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = fragCoord / iResolution.xy;
vec4 current = texture(BUFFER_A, uv);
vec4 previous = texture(iChannel1, uv); // Self-reference
fragColor = mix(previous, current, 0.1); // Temporal blend
}
```
### Main (Final Output):
```glsl
#define BUFFER_B iChannel1
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = fragCoord / iResolution.xy;
fragColor = texture(BUFFER_B, uv);
}
```
## Critical GLSL ES Rules
**ALWAYS follow these rules to avoid compilation errors:**
1. **NO `f` suffix**: Use `1.0` NOT `1.0f`
2. **NO `saturate()`**: Use `clamp(x, 0.0, 1.0)` instead
3. **Protect pow/sqrt**: Wrap arguments: `pow(max(x, 0.0), p)`, `sqrt(abs(x))`
4. **Avoid division by zero**: Check denominators or add epsilon
5. **Initialize variables**: Don't assume default values
6. **Avoid name conflicts**: Don't name functions like variables
7. **NO interactive commands**: Avoid `find`, `grep` - use Glob/Grep tools instead
## Workflow Guide
### Creating a New Shader
1. **Set up coordinate system** - Choose appropriate UV normalization
2. **Define core effect** - Implement main visual algorithm
3. **Add animation** - Use `iTime` for temporal variation
4. **Apply color palette** - Use cosine palette or custom scheme
5. **Add post-processing** - Vignette, dither, gamma correction
6. **Optimize** - Reduce iterations, use early exits, minimize branches
### Common Tasks
**Visualizing complex numbers:**
- Use the complex math functions in `references/common-patterns.md`
- Plot with `cx_log()`, `cx_pow()`, or polynomial evaluation
- Map complex results to color via palette
**Ray marching 3D scenes:**
- Define distance field in `map()` function
- Set up camera (ray origin `ro`, ray direction `rd`)
- March using standard loop pattern
- Calculate normals with tetrahedron method
- Apply lighting and material properties
**Creating noise/organic effects:**
- Use `hash21()` for random values
- Implement `fbm()` (fractional Brownian motion) for natural variation
- Combine with `sin()`/`cos()` for structured patterns
- Apply domain warping for organic distortion
**Multi-layer composition:**
- Render multiple passes with different parameters
- Blend layers using `mix()` or custom blend modes
- Add interference patterns by comparing layer differences
- Use `smoothstep()` for soft transitions
### Debugging Strategies
**Visualize intermediate values:**
```glsl
fragRelated in Writing & Docs
jax-development
IncludedUse this skill when the user is writing, debugging, profiling, refactoring, reviewing, benchmarking, parallelising, exporting, or explaining JAX code, or when they mention JAX, jax.numpy, jit, grad, value_and_grad, vmap, scan, lax, random keys, pytrees, jax.Array, sharding, Mesh, PartitionSpec, NamedSharding, pmap, shard_map, Pallas, XLA, StableHLO, checkify, profiler, or the JAX repo. It helps turn NumPy or PyTorch-style code into pure functional JAX, fix tracer/control-flow/shape/PRNG bugs, remove recompiles and host-device syncs, choose transforms and sharding strategies, inspect jaxpr/lowering/IR, and benchmark compiled code correctly.
nature-article-writer
IncludedDrafts, rewrites, diagnostically critiques, and style-calibrates primary research manuscripts for Nature and Nature Portfolio journals. Use when the user wants a Nature-style title, summary paragraph or abstract, introduction, results, discussion, methods, figure legends, presubmission enquiry, cover letter, reviewer response, or when a scientific draft sounds generic, jargon-heavy, structurally weak, or AI-ish and needs precise, broad-reader-friendly prose without inventing data, analyses, or references. Best for primary research articles and letters rather than reviews or press releases unless explicitly adapting one.
deckrd
IncludedDocument-driven framework that derives requirements, specifications, implementation plans, and executable tasks from goals through structured AI dialogue. Use when user says "write requirements", "create spec", "plan implementation", "derive tasks", "structure this feature", "break down into tasks", or "document this module". Also use for reverse engineering existing code into docs (/deckrd rev). Do NOT use for direct code writing — use /deckrd-coder after tasks are generated. Do NOT use when the user only wants to run or fix existing code without planning.
clinical-decision-support
IncludedGenerate professional clinical decision support (CDS) documents for pharmaceutical and clinical research settings, including patient cohort analyses (biomarker-stratified with outcomes) and treatment recommendation reports (evidence-based guidelines with decision algorithms). Supports GRADE evidence grading, statistical analysis (hazard ratios, survival curves, waterfall plots), biomarker integration, and regulatory compliance. Outputs publication-ready LaTeX/PDF format optimized for drug development, clinical research, and evidence synthesis.
handling-sf-data
IncludedSalesforce data operations with 130-point scoring. Use this skill to create, update, delete, bulk import/export, generate test data, and clean up org records using sf CLI and anonymous Apex. TRIGGER when: user creates test data, performs bulk import/export, uses sf data CLI commands, needs data factory patterns for Apex tests, or needs to seed/clean records in a Salesforce org. DO NOT TRIGGER when: SOQL query writing only (use querying-soql), Apex test execution (use running-apex-tests), or metadata deployment (use deploying-metadata).
accelint-ac-to-playwright
IncludedConvert and validate acceptance criteria for Playwright test automation. Use when user asks to (1) review/evaluate/check if AC are ready for automation, (2) assess if AC can be converted as-is, (3) validate AC quality for Playwright, (4) turn AC into tests, (5) generate tests from acceptance criteria, (6) convert .md bullets or .feature Gherkin files to Playwright specs, (7) create test automation from requirements. Handles both bullet-style markdown and Gherkin syntax with JSON test plan generation and validation.