Custom Shadertoy Viewer - Shader Files
This directory contains GLSL shader files for the custom Shadertoy viewer implementation.
Background
Shadertoy recently added CAPTCHA protection, which broke the iframe embeds used throughout the blog. This custom viewer provides a local alternative using Three.js and lil-gui.
File Structure
Each shader is stored as a .glsl file with the Shadertoy shader ID as the filename:
Real Shaders (from shaders_public.json)
DssczX.glsl✓ Two-Body Field visualization - REAL CODEdd2cWy.glsl✓ Rhombus Gradient Field - REAL CODEcs2cW3.glsl✓ Apollonian Circles / Conic Sections - REAL CODEmtKfWz.glsl✓ Rotational Derivative Visualization - REAL CODE
Placeholder Shaders (need original code)
clV3Rz.glsl⚠ UGF Field Notation - Plane Intersection - PLACEHOLDERdtVGRd.glsl⚠ Boolean Operations Comparison - PLACEHOLDER4f2XzW.glsl⚠ Rectangle SDF with Derivatives - PLACEHOLDERMdXSWn.glsl⚠ Fractal Tufted Furniture - PLACEHOLDER
Shader Format
Each shader file should contain a mainImage function compatible with Shadertoy’s format:
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
// Your shader code here
// Available uniforms:
// - iTime (float)
// - iResolution (vec3)
// - iMouse (vec4)
// - iFrame (int)
// - iTimeDelta (float)
// - iFrameRate (float)
// - iParam1, iParam2, iParam3, iParam4 (float) - for GUI controls
}
How to Add/Replace Shader Code
Option 1: Manual Copy from Shadertoy
- Visit the Shadertoy page (e.g., https://www.shadertoy.com/view/DssczX)
- Click “View Shader” or inspect the page source
- Copy the
mainImagefunction and any helper functions - Paste into the corresponding
.glslfile - Test locally
Option 2: Using Shadertoy API (requires API key)
If you have a Shadertoy API key:
curl "https://www.shadertoy.com/api/v1/shaders/DssczX?key=YOUR_KEY" | jq -r '.Shader.renderpass[0].code' > DssczX.glsl
Current Status
Real Shaders - All Complete! ✅ (Dec 24, 2024)
All eight blog shaders have been updated with real code:
From original JSON dump:
DssczX.glsl- Two-Body Field (dropdown: 5 visualization modes)dd2cWy.glsl- Rhombus Gradient Field (slider: angle)cs2cW3.glsl- Apollonian Circles (slider: wiggle + dropdown: circles/lines)mtKfWz.glsl- Rotational Derivative (slider: wobble + dropdown: 3 shapes)
From updated JSON dump:
clV3Rz.glsl- UGF Intersection (slider: offset + toggle: SDF mode + slider: angle)dtVGRd.glsl- UGF and Traditional Blends (slider: offset + dropdown: 7 blend modes + slider: angle)4f2XzW.glsl- Derivatives of Rectangle (slider: wobble + dropdown: 4 derivative modes)
From user:
MdXSWn.glsl- Mandelbulb Fractal by evilryu (pure animation, no controls)
All shaders feature:
- ✓ Full Common code with Implicit struct and UGF operations
- ✓ Adapted Image code using
iParam1-4uniforms instead of Buffer A sliders - ✓ Shadertoy-accurate mouse behavior (iMouse.xy=position, iMouse.zw=click with sign for button state)
- ✓ Auto-sizing, transparent GUI panel in lower left
- ✓ Proper high-DPI/4K support with devicePixelRatio
- ✓ Appropriate controls (dropdowns for modes, sliders for continuous values, toggles for booleans)
Adding New Shaders
To add a new shader to a blog post:
- Create a new
.glslfile in this directory with the shader ID as the filename - Add the shader code with the
mainImagefunction - In your blog post, use: `
`
- Optionally customize GUI controls in
/assets/js/shadertoy-viewer.jsby adding a case inaddShaderSpecificControls()
Technical Details
- Renderer: Three.js r160
- GUI: lil-gui v0.19
- Viewer:
/assets/js/shadertoy-viewer.js - Include:
/_includes/extensions/shadertoy.html
Shader-Specific GUI Controls
The viewer automatically provides appropriate controls based on the shader ID. To customize:
Edit /assets/js/shadertoy-viewer.js and modify the addShaderSpecificControls() method to add controls for your shader.
Troubleshooting
If a shader doesn’t appear:
- Check browser console for errors
- Verify the
.glslfile exists and is valid GLSL - Ensure the shader ID matches the filename
- Check that Three.js and lil-gui loaded successfully
License
Original Shadertoy shaders are © their respective authors. The custom viewer implementation is part of this blog’s codebase.