ShaderPad: A Zero-Friction GLSL Playground That Ships as an Embeddable React Component
Shader experimentation has been stuck behind project setup overhead and playgrounds that either break on edge cases or lock features behind logins. ShaderPad removes both barriers and packages the editor as a reusable component, which means documentation authors can embed runnable, editable shaders directly into tutorials without sending readers to a separate site.
Writing GLSL typically means scaffolding an HTML file, importing Three.js, and running a local dev server just to test a few lines of transformation logic. ShaderPad replaces that loop with a browser-based editor that pairs a Monaco-backed code pane with a live Three.js preview, built-in geometries, and common uniforms like u_time and u_mouse ready to use.
The tool uses RawShaderMaterial deliberately—no hidden Three.js injections—so the source you write is exactly what runs on the GPU, and error line numbers map 1:1 to your code. A share feature compresses the entire shader source into the URL hash via LZString and Base64, making links self-contained and backend-free.
Beyond the standalone site, the Playground is extracted as the `@lucascv/shaderpad-playground` npm package. It slots into any React-based MDX document (Docusaurus, Astro, Nextra) so that technical writing can include live, editable shaders instead of static code blocks or external links. A djb2-hash-based localStorage keying scheme prevents stale drafts from surviving example updates.
Choosing RawShaderMaterial over ShaderMaterial is a pedagogical decision, not a performance one: it trades convenience for transparency so learners see exactly what runs on the GPU.
Encoding an entire shader into a URL hash via LZString + Base64 is a pragmatic hack that eliminates backend dependency for sharing, but it implicitly enforces brevity since browsers cap URL length around 8–32 KB.
The djb2-hash localStorage keying pattern solves a real content-sync problem that most embedded playgrounds ignore: when the author updates an example, the reader's stale draft silently vanishes instead of causing confusion.
Publishing the editor as an npm package rather than just a hosted site treats the playground as infrastructure, not a destination—this shifts the tool's value from 'another ShaderToy clone' to a documentation primitive.
Astro's island architecture is a genuinely good fit for this class of tool: the heavy WebGL and Monaco editor runtime stays quarantined in a client-only island while the surrounding documentation remains static HTML under 3 kB gzipped.