GPU shaders
Shader inputs
ShaderTexture calls a function that takes ctx: ShaderContext and returns
a Color for each texel. ctx.u and ctx.v are normalized coordinates
from the top-left. ctx.uv contains both. ctx.resolution gives the texture
size in pixels. ctx.aspect is the texture width divided by its height.
ctx.dpi gives the viewport DPI.
Bind extra parameters by name, as in plasma(phase = phase). Ebi checks
each argument against its parameter type. A bound sig parameter stays
live. Ebi samples it each frame and updates the texture on the GPU.
Omit size to render at the image frame's pixel dimensions. Set the image's
width and height in the layout. Pass size when you need a fixed-resolution
Texture for pixel operations.
Shader inputs support unitless Number, Bool, Color, and fixed-size
numeric lists. Shader bodies support arithmetic, comparisons, let,
if, return, constant list indices, Rgb, literal Color, RGB channel
reads, and direct calls to supported math functions and pure helpers. GPU
computations use 32-bit floats. Return normalized finite color channels.
Export WGSL
shader_wgsl(shader = ripple_shader) returns the generated compute source without
starting a GPU pass. A WebGPU host can bind an RGBA8 storage texture at group
0 binding 0 and dispatch in 8×8 workgroups. Binding 1 is a read-only buffer
of packed 32-bit floats. Start with the DPI, followed by the bound arguments
at the offsets named in the generated source. Boolean values use 0 or 1 and
colors use straight sRGBA channels.