---
id: "threejs-tsl-node-materials"
title: "Three.js Shading Language (TSL) Node Materials"
aliases: [TSL, Three.js TSL]
domain: "materials"
stage: "material"
realtime: "realtime"
platforms: [webgpu, webgl2, mobile-gpu]
year_introduced: 2024
inputs: [material-params, texture, normals]
outputs: [hdr-image, gbuffer]
style: "both"
dynamic: "dynamic"
cost: "cheap"
authority: "Authors, 2024"
url: "https://texelatlas.vercel.app/t/threejs-tsl-node-materials/"
sources_verified_at: "2026-12-02"
---
# Three.js Shading Language (TSL) Node Materials (Authors, 2024)

> A JavaScript-native composable shader node graph in Three.js that compiles identically to WGSL (WebGPU) and GLSL (WebGL2), replacing brittle `onBeforeCompile` string patching.

## 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 use 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.

## Cost

cheap — Zero runtime overhead over hand-written shaders once compiled; enables WebGPU compute passes.

## Failure modes

- 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

## Engine support

- threejs: builtin — `import { Fn, color, triplanarTexture, positionWorld } from "three/tsl" with WebGPURenderer` (evidence: https://github.com/mrdoob/three.js/wiki/Three.js-Shading-Language, checked 2026-12-02)

## Dataflow

- Inputs: material-params, texture, normals
- Outputs: hdr-image, gbuffer
- Platforms: webgpu, webgl2, mobile-gpu

## Presets

### TSL Node Material — composable triplanar procedural color + clearcoat Fresnel node graph (glsl-fragment; rendered 2026-12-02)

```json
{
  "P_SCALE": 6,
  "P_COAT": 0.85
}
```

```glsl
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.

## Lineage

- extends [Disney principled BRDF](https://texelatlas.vercel.app/t/disney-principled-brdf.md)

## Sources

1. [primary] Three.js Authors (2024) Three.js Shading Language (TSL) Specification. Three.js Documentation. https://github.com/mrdoob/three.js/wiki/Three.js-Shading-Language (verified via http on 2026-12-02)

## Cite this entry

Texel. "Three.js Shading Language (TSL) Node Materials." https://texelatlas.vercel.app/t/threejs-tsl-node-materials/ (accessed 2026-12-02).
