Slang Playground
Welcome to Slang Playground. Here you can write, compile and run Slang shaders locally within your browser. The Slang compiler runs locally in your browser and no data is sent to any server.
Compiling Shaders (the "Compile" button)
You can compile shaders to many targets supported by Slang here, including SPIR-V, HLSL, GLSL, Metal, and WGSL. Generating DXIL requires DXC, which doesn't run in the browser so it's not supported here.
Run Shaders (the "Run" button)
In addition to compiling shaders, this playground can also run simple shaders via WebGPU. The playground supports running two types of shaders:
- Image Compute Shader: This is a compute shader that returns a pixel value at a given image coordinate, similar to ShaderToys. An image compute shader must define a imageMain function, see the "Circle" demo for an example.
- Print Shader: This is a shader that prints text to the text output window. A print shader must define a printMain function, see the "Simple Print" demo for an example.
Shader Commands
WebGPU shaders in browser can use certain commands to specify how they will run.
//! @outputBuffer: ZEROS(512, 512)
RWTexture
s you will need to add a [format("r32f")]
attribute.
//! @myImage: URL("https://example.com/image.png")
//! @noiseBuffer: RAND(1000)
//! CALL(fn-name, SIZE_OF())
//! CALL(fn-name, 512, 512)
Playground functions
By importing the playground shader you gain access to a few helpful functions.
float4 getMousePosition()
xy
: mouse position (in pixels) during last button down.
abs(zw)
: mouse position during last button click.
sign(mouze.z)
: button is down
sign(mouze.w)
: button is clicked
float getTime()
void printf(String format, expand each T values) where T : IPrintf