ShaderToyVK v0.1

Download: https://horman.net/avisynth/

ShaderToyVK is a GPU compute/graphics pipeline interface using the Vulkan API. It generates RGB output from user-provided GLSL code, following the example of (but not affiliated to or endorsed by) shadertoy.com.

Many ShaderToy shaders (those without external inputs or buffer images) will work without modification.

Parameters

ParameterDescriptionDefault value
clip [optional]An input clip to provide clip parameters or audio
string "shader"GLSL code, or filename for GLSL code file, confirming to ShaderToy requirements
int "width"Output video width
int "height"Output video height
int "length"Output video length, in frames
int "fps_num"FPS numerator
int "fps_den"FPS denominator
string "pixel_type"Any Avisynth+ RGB colourspace name
bool "top_left"Origin at top left (instead of ShaderToy's/WebGL's bottom left)
false
bool "srgb"Convert linear output of shader to sRGB colourspace
false
string "pipeline"Vulkan pipeline type
compute
string "gpu"Select GPU by partial name match
bool "debug"Superimpose GPU list and enable Vulkan validation layers
false

clip [optional]

If an input clip is provided, output video properties (but deliberately not frame properties) will be taken from it, as well any audio. If it is not an RGB clip, an RGB colourspace will need to be specified in pixel_type.

If an input clip is not provided, the output clip will default to 640×480, 1000 frames, RGB32, at 60fps.

glsl (string)

This parameter either takes inline GLSL code, or the filename of a file containing GLSL code, which produces the output. At minimum, the code must have a function matching the following name and signature:

void mainImage(out vec4 rgba, vec2 fragCoord) {…}

The parameters may be renamed.

The function should write RGB (and, optionally, alpha) values to the rgba for the pixel centered at the coordinate specified by fragCoord.

The following global variables are provided:

VariableDescription
vec4 iMouseProvided for compatibility as many ShaderToy shaders use it. Emulates no mouse input.
vec3 iResolutionThree-dimensional resolution of output video (width × height × 1)
float iFrameRateVideo frame rate
float iTimeDeltaProvided for compatibility (equal to 1.0 / iFrameRate)
int iFrameCurrent frame number
float iTimeTime of current frame in seconds
Examples:
GLSLOutput
A simple colour field (with srgb = true for correct display):
ShaderToyVK(""" void mainImage(out vec4 o, vec2 fragCoord) { vec2 uv = fragCoord / iResolution.xy; o = vec4(1.0 - uv, uv.x * uv.y, 1.0); } """, srgb = true)
Dividing fragCoord by iResolution.xy normalises the coordinates to the range [0,1].
A rotating square, with built-in sRGB approximation, so srgb should be false.
ShaderToyVK(""" void mainImage(out vec4 o, vec2 fragCoord) { // center and normalise vec2 uv = (fragCoord - iResolution.xy * 0.5) / iResolution.y; // rotate float s = sin(iTime); float c = cos(iTime); uv *= mat2( vec2(s, c), vec2(c, -s) ); // square vec2 abs_uv = abs(uv); float len = max(abs_uv.x, abs_uv.y); float col = (0.25 - len) * iResolution.y; // convert distance to pixel-width edge // set output (sqrt acts as sRGB transfer function approximation) o = vec4(vec3(sqrt(col)), 1.0); } """)

width, height, length, fps_num, fps_den (int)

These parameters override the corresponding clip properties. You can set fps_num alone to specify an integer frameerate.

pixel_type (string)

The name of any Avisynth+ RGB colourspace.

RGB32 is the fastest 8-bit colourspace, and RGB64 the fastest >8-bit colourspace, as their internal formats match those of the corresponding GPU image.

top_left (bool)

WebGL defaults to a bottom-left origin (the bottom left pixel has coordinates [0.5, 0.5]).

Vulkan defaults to a top-left origin, so if your shader expects this, set this parameter to true.

srgb (bool)

All ShaderToy shaders make approxmations for (or just ignore) the non-linear sRGB transfer function for display.

If you want to output only raw linear RGB from your GLSL code, and have it converted for display (or if your output just looks too dark) set this parameter to true.

pipeline (string)

ShaderToyVK defaults to the Vulkan compute pipeline to create the output image, avoiding rasterisation.

To use the full graphics pipeline instead (vertex shader → rasterisation → fragment shader), set this parameter to graphics.

This may be useful in debugging, but should otherwise be left as default.

gpu (string)

Specifying this parameter will cause ShaderToyVK to select the first GPU whose system name contains the parameter value as a substring (case insensitive). E.g., gpu = "nvidia" will select the first NVIDIA GPU.

If unspecified, ShaderToyVK will choose the first discrete GPU it finds, falling back to the first integrated GPU if there are no discrete GPUs.

debug (bool)

This parameter enables Vulkan validation layers, which write to debug output, and overlays a list of available GPUs on the video, which is darkened to improve readability:


Note that GPUs may appear in a different order depending on which GPU the hosting program has been assigned to.

Caveats / troubleshooting

ShaderToy allows shaders to read external inputs and generate off-screen buffer images. ShaderToyVK doesn't support either of these, but most self-contained shaders that don't use these features should work without modification.

WebGL automatically initialises variables to zero. In Vulkan, this must be done explictly, and failing to do so may lead to unexpected behaviour. For example, the variable declaration float x; should be replaced with float x = 0;, unless it is initialised elsewhere before use.


© wonkey_monkey 2026