wgsl
Provides an "escape hatch" that allows developers to integrate and call raw WGSL (WebGPU Shading Language) code snippets directly within a TSL node graph.
Core Advantages
Its core advantage is providing unlimited flexibility and native performance. Developers can leverage the full power of WGSL to implement complex effects not built into TSL, achieve maximum performance optimizations, and easily reuse existing WGSL code libraries from the community.
Common Uses
Implementing custom lighting models (e.g., toon shading, anisotropic materials)
Writing high-performance procedural noise or fractal patterns
Executing general-purpose computations (GPGPU) in compute shaders
How to adjust
There are two main ways to adjust this node: 1. Directly modify the WGSL source code string passed to the constructor to fundamentally change its algorithm. 2. Keep the source code the same, but pass different TSL nodes as parameters to the `.call()` method to change the function's input data sources.
Code Examples
1// Define a TSL node containing WGSL code
2const mixColorsFn = wgsl(`
3 fn lerpColors( a: vec3<f32>, b: vec3<f32>, t: f32 ) -> vec3<f32> {
4 return mix(a, b, t);
5 }
6`);
7
8// Call the WGSL function using .call(), passing other TSL nodes as parameters
9const finalColor = mixColorsFn.call({
10 a: colorNodeA,
11 b: colorNodeB,
12 t: 0.5
13});