WebGL Shader Playground
Write and preview GLSL fragment shaders live in your browser using WebGL.
Access built-in uniforms for animation (u_time),
canvas size (u_resolution),
and mouse position (u_mouse).
Includes 4 starter templates — gradient, wave, noise, and interactive circle.
Frequently Asked Questions
What is GLSL and WebGL?▼
WebGL is a JavaScript API that renders interactive 2D and 3D graphics in the browser using the GPU, with no plugins. GLSL (OpenGL Shading Language) is the C-like language used to write shaders — programs that run directly on the GPU for every pixel. Fragment shaders run for each pixel and output a color (gl_FragColor). They're used for procedural graphics, post-processing effects, generative art, and game rendering.
What uniforms are available in this playground?▼
Three uniforms are automatically provided: u_time (float) is the seconds elapsed since the page loaded — use it to animate values over time. u_resolution (vec2) is the canvas width and height in pixels — divide gl_FragCoord.xy by u_resolution to get normalized UV coordinates (0 to 1). u_mouse (vec2) is the mouse position in pixels with (0,0) at the bottom-left — move your mouse over the canvas to interact.
How do I get UV coordinates (0 to 1) in a fragment shader?▼
gl_FragCoord.xy gives the current pixel position in pixels. Divide by u_resolution to normalize: vec2 uv = gl_FragCoord.xy / u_resolution; — this gives (0,0) at bottom-left and (1,1) at top-right. To center the origin ((-0.5 to 0.5) or similar for non-square canvases): vec2 uv = (gl_FragCoord.xy - u_resolution * 0.5) / u_resolution.y; This is the pattern used by Shadertoy and most shader examples.
Why does my shader look different from Shadertoy?▼
Shadertoy uses a slightly different coordinate system: iResolution, iTime, and iMouse instead of u_resolution, u_time, and u_mouse. Shadertoy's origin (0,0) is at the bottom-left matching WebGL's default. To port a Shadertoy shader: replace iResolution with u_resolution, iTime with u_time, iMouse.xy with u_mouse. Shadertoy also uses mainImage(out vec4 fragColor, in vec2 fragCoord) — replace this with void main() { ... gl_FragColor = ...; }.
What is 'precision mediump float' for?▼
This sets the floating-point precision for the fragment shader. mediump (medium precision) is required on mobile GPUs and some embedded systems where highp (high precision) isn't always available. For most visual effects, mediump is sufficient. If you need very precise calculations (e.g. large coordinate values, deep zoom), use highp. Always declare precision at the top of your fragment shader — it's required by the GLSL ES spec.
How do I add a texture to a WebGL shader?▼
To use an image texture, upload it as a WebGL texture: const texture = gl.createTexture(); gl.bindTexture(gl.TEXTURE_2D, texture); gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image); gl.generateMipmap(gl.TEXTURE_2D); In your fragment shader, add: uniform sampler2D u_texture; then sample it with: vec4 color = texture2D(u_texture, uv); WebGL requires images to be served from the same origin (CORS) or loaded via a blob URL.
Related Products
on GumroadTypeScript Quick Reference Toolkit
5 practical reference files for TypeScript developers: cheatsheet, TS vs JS comparison, 20 utility types with real examples, tsconfig best practices template, and 15 common mistakes guide. Print it. Keep it on your desk.
Buy on Gumroad →DevToolkit Starter Kit
A ready-to-deploy developer tools website with 12 built-in tools. Astro + Preact + Tailwind. Deploy to Cloudflare Pages for free. Built-in SEO, dark mode, and ad-ready layout.
Buy on Gumroad →Developer Productivity Bundle
Stop rebuilding the same setup every project. 51 VSCode snippets, 40 Git aliases, 5 Docker Compose stacks, 5 GitHub Actions workflows, 5 README templates, and a dotfiles kit. Set up a professional dev environment in under an hour.
Buy on Gumroad →You Might Also Need
HTML5 Canvas API Playground
Interactive HTML5 Canvas animation playground. Choose animations, adjust parameters live, and copy generated JavaScript code for bouncing balls, sine waves, fireworks, and more.
Open free tool →
JS Prototype Chain Visualizer
Explore JavaScript prototype chains interactively. Visualize built-in types (Array, Map, Promise, Error) and custom classes with property lookup path diagrams.
Open free tool →
Particle System Config Generator
Design particle effects interactively — fire, snow, sparks, smoke, and magic rings. Configure emitter type, gravity, turbulence, blend mode, and export JavaScript particle system code.
Open free tool →
More Free Tools
Related Articles
Bun Shell Scripting Guide: Replace Bash Scripts with $.cmd() and Bun APIs
Learn how to replace complex bash scripts with Bun's built-in shell API. Covers $.cmd(), Bun.file(), spawn(), and practical real-world automation scripts.
TypeScript 5.5 New Features: Complete Guide for Developers 2026
Everything you need to know about TypeScript 5.5: inferred type predicates, isolated declarations, JSDoc @import tag, new Set methods, and performance improvements. With practical code examples.
Monorepo Tools Compared: Turborepo vs Nx vs Moon 2026
A comprehensive comparison of the top monorepo tools in 2026 — Turborepo, Nx, and Moon. Learn setup, remote caching, task orchestration, CI integration, and how to choose the right tool for your team.
How to Test Regular Expressions: Complete Beginner Guide
Learn how to test regular expressions step by step. This beginner guide covers regex syntax, how to use online testers, common patterns, and debugging techniques with practical examples.
JavaScript Minifier Online: Compress and Minify JS Files Free
Minify JavaScript online for free. Reduce JS file size by removing whitespace, comments, and shortening variable names. Learn when to minify, how it works, and best practices.
Enjoying this tool? Get more like it.
Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.
Unlock AI-Powered Dev Tools
- ⚡ AI Code Review, Doc Generator & SQL Builder
- ⚡ All premium templates & early access
- ⚡ Member discounts on Gumroad products
$9/mo after trial · Cancel anytime
Want the full toolkit?
Get DevPlaybook Pro
Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.
MIT licensed · Instant download · No subscription
See what's included → Browse all deals →