GLSL Shader Playground
Write a GLSL fragment shader and watch it draw in your browser, with compiler messages on your own lines, mouse input and a PNG export.
Shortcuts: Ctrl+Enter run · / search (use ⌘ on Mac)
Free Online GLSL Shader Editor
Write a shader and watch it draw. Type a GLSL fragment shader on the left and the picture on the right updates as you type, with errors shown on your own lines. Drag the mouse over the picture to feed it your position, save a frame as a PNG, and download your files as one zip. Nothing you write is uploaded. Use it to learn how fragment shaders work, try an effect before putting it in a game or a page, or paste a single-pass Shadertoy shader and see it run.
How to use the shader editor
- Pick an example from Load an example… or edit image.frag. Write a function
mainImagethat setsfragColorfor each pixel. - Use
iResolutionfor the picture size,iTimefor seconds since the start, andiMousefor where you click and drag on the picture. - Read the compiler messages under the picture. Each one names your file and line; click one to jump to it.
- Use Pause, Restart and Save PNG under the picture.
- Put shared functions in
common.glsland pull them in with#include "common.glsl".
Good to know
This editor runs one shader, in the style of Shadertoy's image pass: no textures, sound or extra buffers. It needs a browser and device that support WebGL2. If a shader is too slow for your device, the page pauses it and says so. For web page effects without shaders, try the CSS Effects Generator.
Worked example
The first example turns the position of every pixel into a colour that changes over time:
// Shadertoy style: write mainImage, the page calls it for every pixel.
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = fragCoord / iResolution.xy;
vec3 col = 0.5 + 0.5 * cos(iTime + uv.xyx + vec3(0.0, 2.0, 4.0));
fragColor = vec4(col, 1.0);
}
Result: a smooth gradient that drifts through colours. If you remove the ; after vec2 uv = fragCoord / iResolution.xy, the message says what is wrong and on which line.
Common mistakes
- Writing
float x = 1;instead of1.0: GLSL does not convert whole numbers to decimals for you. - Dividing by
iResolutioninstead ofiResolution.xyoriResolution.y. - Forgetting to set
fragColor: the picture stays black. - Very long loops: a shader that runs too slowly makes the picture stutter and is paused.