Three.js Shading Language (TSL) Node Materials
A JavaScript-native composable shader node graph in Three.js that compiles identically to WGSL (WebGPU) and GLSL (WebGL2), replacing brittle `onBeforeCompile` string patching.
Also known as TSL, Three.js TSL
In the family Materials, BRDFs & texturing, shading-languages
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | Built in | import { Fn, color, triplanarTexture, positionWorld } from "three/tsl" with WebGPURenderer docs |
| Babylon.js 9.x | None found | Specific to Three.js WebGPU/WebGL2 node material architecture. |
| Godot 4.7 | None found | Specific to Three.js WebGPU/WebGL2 node material architecture. |
| Unity 6.0 | None found | Specific to Three.js WebGPU/WebGL2 node material architecture. |
| Unreal 5.7 | None found | Specific to Three.js WebGPU/WebGL2 node material architecture. |
| Blender 5.0 | None found | Specific to Three.js WebGPU/WebGL2 node material architecture. |
| WebGPU W3C | None found | Specific to Three.js WebGPU/WebGL2 node material architecture. |
| Metal | None found | Specific to Three.js WebGPU/WebGL2 node material architecture. |
How it works
Instead of injecting raw GLSL substrings into internal ShaderChunk hooks—which break across engine releases—TSL expresses shading math, triplanar sampling, custom lighting, post-processing passes, and GPU compute kernels as typed JavaScript node expressions (Fn, uniform, texture, triplanarTexture, positionWorld, normalView). Three.js's node builder analyzes the graph, deduplicates varyings and bindings, and emits optimized WGSL for WebGPURenderer with automatic GLSL fallback when running on WebGL2.
When to choose it
Use for any custom material, procedural surface, custom post-processing node, or GPU compute shader in modern Three.js (r170+) instead of onBeforeCompile string patching.
Field marks
- Requires importing from `three/webgpu` and `three/tsl` rather than legacy `WebGLRenderer`-only bundles
- API names evolved rapidly across r165–r187; pin your Three.js version
- Shader compilation still incurs first-frame pipeline creation cost unless pre-warmed
Presets
TSL Node Material — composable triplanar procedural color + clearcoat Fresnel node graph
{
"P_SCALE": 6,
"P_COAT": 0.85
}Show GLSL (36 lines)
const float P_SCALE = 6.0; // P Triplanar Scale [2.0, 14.0, 0.5]
const float P_COAT = 0.85; // P Clearcoat Weight [0.0, 1.0, 0.05]
float hash21(vec2 p) { p = fract(p * vec2(123.34, 456.21)); p += dot(p, p + 45.32); return fract(p.x * p.y); }
float noise(vec2 p) {
vec2 i = floor(p), f = fract(p); f = f * f * (3.0 - 2.0 * f);
return mix(mix(hash21(i), hash21(i + vec2(1, 0)), f.x), mix(hash21(i + vec2(0, 1)), hash21(i + vec2(1, 1)), f.x), f.y);
}
float triplanar(vec3 p, vec3 n) {
vec3 w = pow(abs(n), vec3(4.0)); w /= (w.x + w.y + w.z + 1e-5);
return noise(p.yz * P_SCALE) * w.x + noise(p.xz * P_SCALE) * w.y + noise(p.xy * P_SCALE) * w.z;
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
vec3 ro = vec3(0.0, 0.0, 2.4), rd = normalize(vec3(uv, -1.55));
float b = dot(ro, rd), c = dot(ro, ro) - 0.76 * 0.76;
float disc = b * b - c;
vec3 col = mix(vec3(0.04, 0.06, 0.11), vec3(0.11, 0.15, 0.24), uv.y + 0.5);
if (disc > 0.0) {
vec3 p = ro + rd * (-b - sqrt(disc));
float a = iTime * 0.45;
mat2 R = mat2(cos(a), -sin(a), sin(a), cos(a));
vec3 rp = p; rp.xz = R * rp.xz;
vec3 n = normalize(p), rn = normalize(rp);
float pat = triplanar(rp, rn);
vec3 alb = mix(vec3(0.16, 0.26, 0.42), vec3(0.86, 0.54, 0.26), smoothstep(0.28, 0.72, pat));
vec3 lDir = normalize(vec3(0.6, 0.75, 0.5));
float diff = max(dot(n, lDir), 0.0);
float coatSpec = pow(max(dot(n, normalize(lDir - rd)), 0.0), 96.0) * P_COAT;
float fres = pow(1.0 - max(dot(n, -rd), 0.0), 4.0) * P_COAT;
col = alb * (0.24 + 0.85 * diff) + vec3(1.15, 1.05, 0.95) * coatSpec + vec3(0.35, 0.62, 0.98) * fres * 0.55;
}
col = (col * (2.51 * col + 0.03)) / (col * (2.43 * col + 0.59) + 0.14);
fragColor = vec4(pow(clamp(col, 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}Attribution: MIT — written for this index.
Measured GPU weight
Not yet timed in the standardized NVIDIA T4 sweep. Run the browser profiler above, or time all live specimens at 1080p in Google Colab (NVIDIA T4).
Lineage
Sources
- primaryThree.js Authors (2024). Three.js Shading Language (TSL) Specification. Three.js Documentation.Verified via live page · 2026-12-02