shadertoy

June 12, 2025 ยท View on GitHub

CI PyPI version

shadertoy

Shadertoy implementation based on wgpu-py.

Introduction

This library provides an easy to use python utility to run shader programs from the website Shadertoy.com. It provides the compatibility to let users copy code from the website directly and run it with the various GUIs that are supported in rendercanvas. Including Jupyter notebooks.
Shadertoys translated to wgsl are also supported using the uniforms i_resolution, i_time, etc.

This project is not affiliated with shadertoy.com.

Installation

pip install wgpu-shadertoy

To use the Shadertoy.com API, please setup an environment variable with the key SHADERTOY_KEY. See How To for instructions.

Usage

The main Shadertoy class takes shader code as a string.

from wgpu_shadertoy import Shadertoy

shader_code = """
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,2,4));
    fragColor = vec4(col,1.0);
}
"""

shader = Shadertoy(shader_code, resolution=(800, 450))

if __name__ == "__main__":
    shader.show()

Texture inputs are supported by using the ShadertoyChannelTexture class. Up to 4 channels are supported.

from wgpu_shadertoy import Shadertoy, ShadertoyChannelTexture
from PIL import Image

shader_code = """
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    vec2 uv = fragCoord/iResolution.xy;
    vec4 c0 = texture(iChannel0, 2.0*uv + iTime * 0.2);
    fragColor = c0;
}
"""

img = Image.open("./examples/screenshots/shadertoy_star.png")
channel0 = ShadertoyChannelTexture(img, wrap="repeat")
shader = Shadertoy(shader_code, resolution=(800, 450), inputs=[channel0])

To easily load shaders from the website make use of the .from_id or .from_json classmethods. This will also download supported input media.

shader = Shadertoy.from_id("NslGRN")

When passing offscreen=True the .snapshot() method allows you to render individual frames with chosen uniforms. Be aware that based on your device and backend, the preferred format might be BRGA, so the channels need to be swapped to get an RGBA image.

shader = Shadertoy(shader_code, resolution=(800, 450), offscreen=True)
frame0_data = shader.snapshot()
frame600_data = shader.snapshot(time_float=10.0, frame=600)
frame0_img = Image.fromarray(np.asarray(frame0_data))
frame0_img.save("frame0.png")

For more examples see examples.

CLI Usage

A basic command line interface is provided as wgpu-shadertoy. To display a shader from the website, simply provide its ID or url.

> wgpu-shadertoy tsXBzS --resolution 1024 640

Uniforms

The Shadertoy uniform format is directly supported for GLSL. However for WGSL the syntax is a bit different.

Shadertoy.comGLSLWGSL
vec4 iMouseiMousei_mouse
vec4 iDateiDatei_date
vec3 iResolutioniResolutioni_resolution
float iTimeiTimei_time
vec3 iChannelResolution[4]iChannelResolutioni_channel_resolution
float iTimeDeltaiTimeDeltai_time_delta
int iFrameiFramei_frame
float iFrameRateiFrameRatei_frame_rate
sampler2D iChannel0..3iChannel0..3i_channel0..3
sampler3D iChannel0..3not yet supportednot yet supported
samplerCube iChannel0..3not yet supportednot yet supported
float iChannelTime[4]not yet supportednot yet supported
float iSampleRatenot yet supportednot yet supported

Status

This project is still in development. Some functionality from the Shadertoy website is missing and new features are being added. See the issues to follow the development or contribute yourself! For progress see the changelog.

License

This code is distributed under the 2-clause BSD license.

Code of Conduct

Our code of conduct can be found here: Code of Conduct