Shaders are currently only available in Early Access. Runtime support is either in development or available as experimental builds.Have feedback? Join the Early Access community to share your thoughts and help shape the feature.
What’s a shader?A shader is a small program that runs on the GPU. GPUs are good at running the same program across many vertices or pixels in parallel, which makes shaders useful for graphics effects.A typical GPU pipeline uses two shader functions:
- Vertex shader - decides where vertices are drawn.
- Fragment shader - decides the color of each pixel covered by those vertices.
Creating a Shader Asset
Create a new script, select Shader as the type, and name itBasicShader.
The AI Agent can be a helpful way to create or iterate on shader code. Describe the effect you want, then review and test the generated WGSL in your file.
Basic WGSL Shader
This shader draws a single large triangle that covers the render target. This is a common technique called a fullscreen triangle. The fragment shader then colors each pixel with a gradient. No vertex or index buffers are needed because the triangle points are defined directly in the shader.
Rendering the Shader with a Script
How It Works
context:shader
context:shader("BasicShader") retrieves the compiled shader asset by name. The name must match the shader asset in your file.
GPUCanvas
context:gpuCanvas() creates the render target the shader draws into. The canvas exposes its rendered result as canvas.image.
GPUPipeline
GPUPipeline.new() combines the shader with render settings such as vertex layout and color target format.
drawCanvas
Use drawCanvas for GPU rendering. This is where you begin a render pass, set the pipeline, and issue draw calls.
draw
Use draw to draw the rendered canvas image into the Rive scene.
Shader Targets
When nothing is selected in the editor, the Inspector shows file-level Shader Targets options. Use these options to choose which shader languages Rive should generate from your WGSL shaders:- Metal (MSL)
- GLSL ES 300
- HLSL
- SPIR-V
