TSL Quick Reference
Imports
Types
| TSL |
WGSL |
Example |
float(1.0) |
f32 |
Scalar float |
int(1) |
i32 |
Signed integer |
uint(1) |
u32 |
Unsigned integer |
bool(true) |
bool |
Boolean |
vec2(x, y) |
vec2<f32> |
2D vector |
vec3(x, y, z) |
vec3<f32> |
3D vector |
vec4(x, y, z, w) |
vec4<f32> |
4D vector |
color(0xff0000) |
vec3<f32> |
RGB color |
uniform(value) |
uniform |
Dynamic value |
Operators
| Operation |
TSL |
GLSL Equivalent |
| Add |
a.add(b) |
a + b |
| Subtract |
a.sub(b) |
a - b |
| Multiply |
a.mul(b) |
a * b |
| Divide |
a.div(b) |
a / b |
| Modulo |
a.mod(b) |
mod(a, b) |
| Negate |
a.negate() |
-a |
| Less Than |
a.lessThan(b) |
a < b |
| Greater Than |
a.greaterThan(b) |
a > b |
| Equal |
a.equal(b) |
a == b |
| And |
a.and(b) |
a && b |
| Or |
a.or(b) |
a || b |
| Assign |
a.assign(b) |
a = b |
| Add Assign |
a.addAssign(b) |
a += b |
Swizzling
Math Functions
| Function |
Description |
abs(x) |
Absolute value |
sign(x) |
Sign (-1, 0, 1) |
floor(x) |
Round down |
ceil(x) |
Round up |
fract(x) |
Fractional part |
min(a, b) |
Minimum |
max(a, b) |
Maximum |
clamp(x, lo, hi) |
Clamp to range |
mix(a, b, t) |
Linear interpolation |
step(edge, x) |
Step function |
smoothstep(a, b, x) |
Smooth step |
sin(x), cos(x) |
Trigonometry |
pow(x, y) |
Power |
sqrt(x) |
Square root |
length(v) |
Vector length |
distance(a, b) |
Distance |
dot(a, b) |
Dot product |
cross(a, b) |
Cross product |
normalize(v) |
Unit vector |
reflect(i, n) |
Reflection |
Geometry Nodes
| Node |
Description |
positionLocal |
Model space position |
positionWorld |
World space position |
positionView |
Camera space position |
normalLocal |
Model space normal |
normalWorld |
World space normal |
normalView |
Camera space normal |
uv() |
UV coordinates |
uv(1) |
Secondary UVs |
tangentLocal |
Tangent vector |
vertexColor() |
Vertex colors |
Camera Nodes
| Node |
Description |
cameraPosition |
Camera world position |
cameraNear |
Near plane |
cameraFar |
Far plane |
cameraViewMatrix |
View matrix |
cameraProjectionMatrix |
Projection matrix |
screenUV |
Screen UV (0-1) |
screenSize |
Screen dimensions |
Time
| Node |
Description |
time |
Seconds since start |
deltaTime |
Frame delta |
oscSine(t) |
Sine wave (0-1) |
oscSquare(t) |
Square wave |
oscTriangle(t) |
Triangle wave |
oscSawtooth(t) |
Sawtooth wave |
Material Properties
Control Flow
Custom Functions
Compute Shaders
Post-Processing
Common Patterns
Fresnel
Animated UV
Noise Hash
Dissolve
Color Gradient
Node Materials
| Material |
Use Case |
MeshBasicNodeMaterial |
Unlit |
MeshStandardNodeMaterial |
PBR |
MeshPhysicalNodeMaterial |
Advanced PBR |
MeshPhongNodeMaterial |
Phong shading |
MeshToonNodeMaterial |
Cel shading |
PointsNodeMaterial |
Point clouds |
LineBasicNodeMaterial |
Lines |
SpriteNodeMaterial |
Sprites |
Device Loss Handling
| Loss Reason |
Meaning |
'destroyed' |
Intentional via destroy() |
'unknown' |
Unexpected (driver crash, timeout, etc.) |
Recovery tips:
- Always get fresh adapter before new device
- Save/restore application state (not transient data)
- Use Chrome
about:gpucrash to test real GPU crashes
Compute Shader Built-ins
| Node |
Description |
instanceIndex |
Current instance/invocation index |
vertexIndex |
Current vertex index |
drawIndex |
Current draw call index |
globalId |
Global invocation position (uvec3) |
localId |
Local workgroup position (uvec3) |
workgroupId |
Workgroup index (uvec3) |
numWorkgroups |
Number of workgroups dispatched (uvec3) |
subgroupSize |
Size of the subgroup |
Version Notes
r178+:
PI2 is deprecated → use TWO_PI
transformedNormalView → use normalView
transformedNormalWorld → use normalWorld
r171+:
- Recommended minimum version for stable TSL
- Requires separate
three/webgpu import map entry
Resources