--- id: wiki-2026-0508-tsl-three-shader-language title: TSL (Three Shader Language) category: 10_Wiki/Topics status: verified canonical_id: self aliases: [Three.js Shading Language, TSL, Node Material] duplicate_of: none source_trust_level: A confidence_score: 0.9 verification_status: applied tags: [threejs, webgpu, shader, graphics] raw_sources: [] last_reinforced: 2026-05-10 github_commit: pending tech_stack: language: javascript framework: threejs-r170 --- # TSL (Three Shader Language) ## 매 한 줄 > **"매 GLSL/WGSL 의 abstract 의 JS-native shader DSL"**. 매 Three.js 의 node-based material system 의 evolution — 매 single source 의 WebGL2 + WebGPU 의 compile. 2026 의 r170+ 의 standard — 매 GLSL string 의 deprecated path. ## 매 핵심 ### 매 왜 TSL - **Backend agnostic**: 매 동일 code 의 WebGL2 (GLSL) + WebGPU (WGSL) 의 emit. - **JS-native**: 매 IDE autocomplete, type check, debug 의 enable. - **Composable**: 매 node graph 의 reuse — 매 material 의 lego. - **Compute shaders**: 매 GPGPU 의 first-class — particles, sims. ### 매 핵심 concepts - **Node**: 매 shader 의 unit (uniform, attribute, op). - **NodeMaterial**: 매 MeshBasicMaterial 의 TSL 의 version. - **Stage**: vertex / fragment / compute. - **Varying**: 매 vertex → fragment 의 interpolated. ### 매 응용 1. Custom PBR materials (procedural normal, AO). 2. Post-processing (bloom, SSAO via TSL). 3. GPGPU particles (10^6 particles compute shader). 4. Procedural textures (noise, voronoi). ## 💻 패턴 ### Basic — vertex displacement ```javascript import * as THREE from 'three'; import { positionLocal, sin, time, vec3, MeshStandardNodeMaterial } from 'three/tsl'; const mat = new MeshStandardNodeMaterial(); mat.positionNode = positionLocal.add( vec3(0, sin(positionLocal.x.add(time)).mul(0.5), 0) ); mat.colorNode = vec3(0.2, 0.6, 1.0); ``` ### Procedural fragment — checker ```javascript import { uv, floor, mod, vec3, mix, MeshBasicNodeMaterial } from 'three/tsl'; const scaled = uv().mul(8); const checker = mod(floor(scaled.x).add(floor(scaled.y)), 2); const mat = new MeshBasicNodeMaterial(); mat.colorNode = mix(vec3(0.1), vec3(0.9), checker); ``` ### Custom function (Fn) ```javascript import { Fn, vec3, dot, normalize } from 'three/tsl'; const lambert = Fn(([n, l]) => { return dot(normalize(n), normalize(l)).max(0); }); mat.colorNode = lambert(normalLocal, vec3(1, 1, 0)).mul(albedo); ``` ### Compute shader — particle update ```javascript import { Fn, instanceIndex, storage, time, vec3, sin } from 'three/tsl'; const positions = storage(buffer, 'vec3', count); const update = Fn(() => { const i = instanceIndex; positions.element(i).addAssign( vec3(sin(time.add(i)), 0.01, 0).mul(0.01) ); })().compute(count); renderer.computeAsync(update); ``` ### Uniform binding ```javascript import { uniform, MeshStandardNodeMaterial } from 'three/tsl'; const intensity = uniform(1.0); const mat = new MeshStandardNodeMaterial(); mat.emissiveNode = albedo.mul(intensity); // later intensity.value = 2.5; ``` ### Noise — simplex via TSL ```javascript import { mx_noise_float, positionLocal, vec3 } from 'three/tsl'; const n = mx_noise_float(positionLocal.mul(2)); mat.positionNode = positionLocal.add(normalLocal.mul(n.mul(0.1))); ``` ### WebGPU renderer setup ```javascript import { WebGPURenderer } from 'three/webgpu'; const renderer = new WebGPURenderer({ antialias: true }); await renderer.init(); document.body.appendChild(renderer.domElement); ``` ## 매 결정 기준 | 상황 | Approach | |---|---| | New Three.js project (2026+) | TSL + WebGPURenderer | | Legacy GLSL maintenance | Keep ShaderMaterial | | Cross-backend portability | TSL | | GPGPU / compute | TSL compute shaders | | Quick prototype | Built-in materials | **기본값**: 매 TSL + NodeMaterial — 매 r170+ 의 future-proof. ## 🔗 Graph - 부모: [[Three.js]] · [[WebGPU]] - 변형: [[GLSL]] · [[WGSL]] - 응용: [[PBR]] · [[Post-processing]] - Adjacent: [[Node Material]] · [[Compute_Shaders|Compute Shaders]] ## 🤖 LLM 활용 **언제**: shader generation, GLSL → TSL migration, procedural pattern synthesis. **언제 X**: bleeding-edge TSL APIs (training cutoff lag) — 매 docs 의 verify. ## ❌ 안티패턴 - **String-concat GLSL in 2026**: 매 deprecated path — 매 TSL 의 migrate. - **Heavy compute on main thread**: 매 compute shader 의 offload. - **Recompile on every frame**: 매 uniform.value 의 update — 매 node 의 rebuild 의 X. ## 🧪 검증 / 중복 - Verified (Three.js r170+ docs, threejs.org/examples TSL category). - 신뢰도 A. ## 🕓 Changelog | 날짜 | 변경 | |---|---| | 2026-05-08 | Phase 1 | | 2026-05-10 | Manual cleanup — TSL nodes, compute shaders, WebGPU |