WESL is a strict superset of WGSL, adding import statements, conditional compilation, and other features.
- Add a
.weslfile alongside the other shader files.- The Lygia convention is to have one user-facing function per file. This keeps things organized while keeping user application bundle sizes small.
- It's fine to put multiple type variants of the same function in the same file.
For example, variants for a
fnwithf32and the samefnwithvec3farguments go in the same file.
- Add appropriate tests in
test/wesl.- Use
testCompute()for pure math functions - Use
testFragment()for derivative functions (fwidth,dpdx,dpdy) or texture sampling - Use
toMatchImage()for visual regression tests (filters, generative patterns, complex rendering)
- Use
- WESL file names can't start with a number, and can't be current WGSL or WESL keywords.
- The file/directory hierarchy translates to double colons in WESL:
See WESL imports for details.
import lygia::color::space::hsl2rgb::hsl2rgb;
- You can also reference other shader modules inline without import statements.
fn foo() -> f32 { let p = lygia::math::consts::PI; return p; }
- Conditional transpilation is supported via
@if,@else, and@elseifstatements. Conditions can be set at runtime or build time.[^1] See WESL Conditions for details.
WESL is documented at wesl-lang.dev. Community support for WESL is available on GitHub and on Discord.
- Function overloads or generics to reduce duplication across type variants
- Setting conditions from imported shaders.