/wgshadertoy

A WGSL playground inspired by Shadertoy.

Primary LanguageRustMIT LicenseMIT

WgShadertoy Logo

WgShadertoy

A WGSL playground inspired by Shadertoy.

preview

Wgs format

The application use a binary format wgs to save and load shaders and textures.

It helps to share your shaders amoung people.

You can find examples in wgshader-examples.

Uniforms

The runtime currently provided six parameters you can use in your shader as a uniform variable:

  • cursor: vec2
    • The mouse position in pixels.
  • mouse_down: u32
    • Whether the left button of the mouse is down.
    • 0: left button is up.
    • 1: left button is down.
  • mouse_press: vec2
    • The mouse position in pixels when the left button is pressed.
  • mouse_release: vec2
    • The mouse position in pixels when the left button is released.
  • resolution: vec2
    • The resolution of the canvas in pixels (width * height).
  • time: f32
    • The elapsed time since the shader first ran, in seconds.

You can use the above uniform like the following:

fn main_image(frag_color: vec4<f32>, frag_coord: vec2<f32>) -> vec4<f32> {
    let uv = frag_coord / u.resolution;
    let color = 0.5 + 0.5 * cos(u.time + uv.xyx + vec3(0.0, 2.0, 4.0));
    return vec4(color, 1.0);
}

Installation

Check the latest release, and download the package for your specific OS.

Currently, msi for Windows, dmg for MacOS and raw executable for Linux are provided. If you are willing to contribute more packages (such as deb, rpm...), feel free to open a PR.

For Arch Linux users, there is already a package named wgshadertoy in AUR, just install it:

yay -S wgsahdertoy

Limits

Todos

  • Web version
  • Advanced shader validation (detailed in fralonra#1)

Credits

  • wgpu for rendering.
  • egui for UI.
  • binrw for binary data read/write.
  • shadertoy for the wonderful vertex shader.