Skip to main content

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.

✓ Real-time WebGL preview ✓ u_time + u_mouse + u_resolution ✓ 4 starter templates ✓ GLSL error highlighting

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.

Share this tool: X / Twitter LinkedIn
✓ 60,000+ developers use DevPlaybook ★★★★★ 4.8 / 5 on Gumroad ✓ MIT licensed · Instant download ✓ No login required

Related Products

on Gumroad

You Might Also Need

More Free Tools

Enjoying this tool? Get more like it.

Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.

DevPlaybook Pro 7 days free

Unlock AI-Powered Dev Tools

  • ⚡ AI Code Review, Doc Generator & SQL Builder
  • ⚡ All premium templates & early access
  • ⚡ Member discounts on Gumroad products
Start Free Trial →

$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.

$79
$241 separately Save $162 (67% off)
Get DevPlaybook Pro — $79 →

MIT licensed · Instant download · No subscription

See what's included → Browse all deals →