9 releases

0.1.8 Oct 4, 2023
0.1.7 Oct 3, 2023
0.1.6 Feb 11, 2023
0.1.5 Nov 7, 2022
0.1.1 May 25, 2021

#101 in Graphics APIs

Download history 9/week @ 2023-10-29 2/week @ 2023-11-05 12/week @ 2023-11-12 11/week @ 2023-11-19 31/week @ 2023-11-26 12/week @ 2023-12-03 3/week @ 2023-12-10 13/week @ 2023-12-17 20/week @ 2023-12-24 2/week @ 2023-12-31 16/week @ 2024-01-07 6/week @ 2024-01-14 8/week @ 2024-01-21 18/week @ 2024-01-28 3/week @ 2024-02-04 47/week @ 2024-02-11

77 downloads per month

MIT license

407 lines



This is a simple playground for playing with WGSL fragment shaders. It is invoked by passing it a wgsl file. The program then looks for a framgent shader called fs_main in the wgsl file provided and renders it across the window. This is similar to what shadertoy does, except using WGSL instead of GLSL and on the desktop rather than in your browser.

wgsl-playground also watches the file for edits. Whenever you save the file, it rebuilds the pipeline with the updated shader and swaps it into the redraw process.

Under the hood, it uses wgpu for rendering and naga for validation.

Note that WGSL is still an evolving spec. This tool is for people who want to learn some WSGL in its current form.

A screenshot showing a grid of circles.

A number of examples shaders are in the examples directory. The screenshot above shows the uniforms.wgsl shader.


Install with cargo:

cargo install wgsl-playground

To run an existing .wgsl file, pass it on the command line:

wgsl-playground myfragshader.wgsl

To create a new shader file, pass the -c flag and the file name to create. This is useful because it provides the boilerplate to access uniforms and vertex data.


The shader receives the following vertex input:

  • The clip space (x, y) coordinate of this fragment as a vec2<f32> at location=0.
  • The device coordinate window-relative coordinate of this fragment as a vec4<f32> at builtin(position) (i.e. equivalent to gl_Position)

The following uniforms are also available:

  • The clip space (x, y) coordinate of the location of the mouse cursor as a vec2<f32>. Only updates if the mouse cursor is within the bounds of the window. Starts at (0.5, 0.5).
  • The (fractional) number of seconds since the program started as a f32. It does not reset when the shader is reloaded.


~800K SLoC