The Custom Shader allows advanced users to write their own GLSL fragment shader code, enabling complete creative freedom to design unique visuals that react to your music. This feature is for users who are comfortable with shader programming.
Getting Started
Select Custom from the shader gallery. You'll see a code editor where you can write your GLSL code.
How It Works
You write a complete GLSL fragment shader with a main() function. The template provides uniforms, coordinates, and helper functions - you just need to write main() and any custom functions you need.
void main() {
vec3 color = mix(iStartColor, iEndColor, vUv.x);
gl_FragColor = vec4(color, 1.0);
}
You can also define your own helper functions:
float circle(vec2 uv, vec2 center, float radius) {
return smoothstep(radius, radius - 0.01, length(uv - center));
}
void main() {
float c = circle(vUv, vec2(0.5), 0.3);
gl_FragColor = vec4(mix(iStartColor, iEndColor, c), 1.0);
}
Available Uniforms
Time & Audio
| Uniform | Type | Description |
|---|---|---|
iGlobalTime | float | Time in seconds since start |
iBpm | float | Beats per minute of the audio |
iLowFreq | float | Low frequency intensity (0-1) |
iMidFreq | float | Mid frequency intensity (0-1) |
iHighFreq | float | High frequency intensity (0-1) |
iSoundTexture | sampler2D | Full audio spectrum texture |
Custom Parameters
These parameters appear in the UI and can be bound to audio reactivity:
| Uniform | Type | Description |
|---|---|---|
iStartColor | vec3 | Start color (RGB, 0-1 range) |
iEndColor | vec3 | End color (RGB, 0-1 range) |
iIntensity | float | Intensity parameter (0-10) |
iPattern | float | Pattern parameter (0-10) |
Coordinates
| Name | Type | Description |
|---|---|---|
vUv | vec2 | UV coordinates (0-1 range) |
iResolution | vec2 | Resolution (1920x1080) |
PI | float | 3.141592654 |
TAU | float | 2 * PI |
Helper Functions
map(value, min1, max1, min2, max2)
Maps a value from one range to another.
float normalized = map(value, 0.0, 100.0, 0.0, 1.0);
getFrequency(x)
Gets the audio frequency at position x (0-1 range) from the sound texture.
float bass = getFrequency(0.1); // Low frequencies
float treble = getFrequency(0.9); // High frequencies
Examples
Simple Gradient
void main() {
vec3 color = mix(iStartColor, iEndColor, vUv.x);
gl_FragColor = vec4(color, 1.0);
}
Audio-Reactive Pulse
void main() {
float dist = length(vUv - 0.5);
float pulse = iLowFreq * iIntensity;
float c = smoothstep(0.3 + pulse * 0.2, 0.28 + pulse * 0.2, dist);
gl_FragColor = vec4(mix(iEndColor, iStartColor, c), 1.0);
}
Beat-Synced Animation
void main() {
float beat = sin(iGlobalTime * iBpm / 60.0 * TAU) * 0.5 + 0.5;
vec3 color = mix(iStartColor, iEndColor, beat);
color *= 1.0 + iLowFreq * iIntensity * 0.5;
gl_FragColor = vec4(color, 1.0);
}
Frequency Bars
void main() {
float barWidth = 0.05;
float barIndex = floor(vUv.x / barWidth);
float freq = getFrequency(barIndex / 20.0);
float barHeight = freq * iIntensity * 0.5;
float bar = step(1.0 - vUv.y, barHeight);
vec3 color = mix(iStartColor, iEndColor, vUv.x);
gl_FragColor = vec4(color * bar, 1.0);
}
Plasma Effect
void main() {
float t = iGlobalTime * 0.5;
float v = sin(vUv.x * 10.0 + t);
v += sin((vUv.y * 10.0 + t) * 0.5);
v += sin((vUv.x * 10.0 + vUv.y * 10.0 + t) * 0.5);
v = v * 0.5 + 0.5;
v += iLowFreq * iIntensity * 0.2;
gl_FragColor = vec4(mix(iStartColor, iEndColor, v), 1.0);
}
Tips
Performance
- Keep your shader code efficient. Avoid expensive operations in loops
- Use built-in GLSL functions like
mix,smoothstep,clamp - Test with different audio to ensure your visuals respond well
Audio Reactivity
iLowFreqresponds to bass - great for pulses and beatsiMidFreqresponds to vocals and instrumentsiHighFreqresponds to hi-hats and cymbals- Multiply audio values by
iIntensityto make reactivity adjustable
Common Issues
Shader won't compile
Check the error message below the editor - it shows the line number where the error occurred. Common issues:
- Missing semicolons
- Undeclared variables
- Type mismatches (e.g., using
floatwherevec3is expected)
Output is black
Make sure you're setting fragColor to a valid RGB value. Try starting with a simple gradient to verify your setup works.
Audio not reacting
Verify that you're using the audio uniforms (iLowFreq, iMidFreq, iHighFreq) in your calculations and that iIntensity is set above 0 in the UI.