TypologySienna Chen
ToolsHeavyweight · 7 uses

TSL

Shaders written as JavaScript; one source runs on WebGPU and WebGL.

Three.js Shading Language: shaders written as plain JavaScript instead of GLSL strings. You chain functions like positionLocal, mix and mx_noise_float, and three.js compiles the graph to WGSL on WebGPU or GLSL on the WebGL 2 fallback. Because it plugs into the material system, an effect keeps the scene’s lights, shadows and skinning, and the same file can hold the compute pass that moves a million particles.

Uses · 7Pick one to run it on the left

  1. Prompt
    Build one TSL material and prove it runs on both backends. A sphere with MeshPhysicalNodeMaterial: colorNode = mix(colorA, colorB, smoothstep(0.42, 0.58, mx_noise_float(positionLocal.mul(3).add(time.mul(0.4))))), plus an emissiveNode that lights a thin band where the noise crosses 0.5. Render it in two canvases side by side, the second WebGPURenderer created with forceWebGL: true, and print which backend each one got under its canvas. Add a button that logs the generated WGSL and GLSL for the material so the two can be compared line by line. Imports only from three/webgpu and three/tsl; no ShaderMaterial anywhere.
  2. Prompt
    A dissolve on a skinned glTF character in TSL, with its AnimationMixer still playing. A uniform progress 0 → 1 is the threshold against mx_noise_float(positionLocal.mul(4)): maskNode removes fragments below it; emissiveNode lights a 0.04-wide band just above it in a hot ramp (white → yellow → deep orange) × 6 so bloom catches it. Embers: 20,000 particles in instancedArray buffers, spawned by a compute pass at points sampled on the mesh where the noise sits inside the burning band, rising on curl noise and fading over 1.2 s, drawn with SpriteNodeMaterial and additive blending. Bloom through the WebGPU post-processing pipeline. Because it is a node material, skinning, shadows and environment light keep working.
  3. Prompt
    Two tricks with node-material shadows in one scene. 1) A glass sphere (MeshPhysicalNodeMaterial, transmission 1) whose castShadowNode returns a color instead of black: Worley cells from mx_worley_noise_float on positionLocal mapped to three jewel tones, with dark lead lines where two cells meet, so the floor gets a stained-glass shadow (the three.js example webgpu_shadowmap_opacity shows the Fn signature). 2) A plain sphere whose castShadowPositionNode pushes its shadow-casting vertices into a five-point star in the plane facing the light, so it looks round but its shadow is a star. DirectionalLight with a 2048 shadow map on a ShadowMaterial floor; rotate both slowly so the lies move.
  4. Prompt
    WebGPURenderer + TSL: 1,000,000 particles in instancedArray buffers (position, velocity, target). One compute pass, Fn(() => { … })().compute(count) run with renderer.compute each frame, springs every particle toward its target (stiffness 6, damping 0.88) with a little curl noise on top; a second compute pass rewrites all targets when the shape changes. Shapes: a Fibonacci sphere, a torus knot, a three-armed galaxy, and the word TSL rasterized to a canvas and sampled. A click cycles the shape; each particle waits hash(instanceIndex) × 0.7 s, so it morphs as a wave. Draw with SpriteNodeMaterial (positionNode = positions.toAttribute(), additive blending, color by speed). Show fps and the backend; drop to 100,000 particles when forceWebGL is on.
  5. Prompt
    Comic-print shading on any glTF with TSL, after the three.js example webgpu_tsl_halftone: keep MeshStandardNodeMaterial lighting and set outputNode = halftones(output). Each halftone layer is an Fn that builds a screen-space grid (screenCoordinate.xy.div(screenSize.yy).mul(count)), turns it 45° with rotate(), takes .mod(1) for the cell, and draws a dot whose radius follows normalWorld.dot(direction) through smoothstep. Two layers: dark dots in the shadows (count 140) and light dots on the highlights (count 60), each mixed over the lit color. Expose count, radius and direction in lil-gui, and orbit the light slowly so the dots crawl across the form.
  6. Prompt
    A cutaway view in TSL, after the three.js example webgpu_tsl_angular_slicing: the outer hull of a glTF gearbox gets MeshPhysicalNodeMaterial with side: DoubleSide. maskNode hides fragments whose atan(positionLocal.y, positionLocal.x) falls inside an arc starting at a uniform sliceStart and spanning sliceArc. outputNode returns a flat accent color wherever frontFacing is false, so the inside of the shell reads as a solid cut surface. Animate sliceStart so the cut sweeps around, set maskShadowNode so the shadow matches the cut, and keep the inner gears on an ordinary material.
  7. Prompt
    A procedural planet in TSL with no image files. SphereGeometry(1, 128, 128) with MeshStandardNodeMaterial: height = mx_fractal_noise_float(positionLocal.mul(1.8), 6, 2.0, 0.5); land where height > 0.02, colored by height from sand to rock to snow; oceans with roughness 0.15 and land 0.9 through roughnessNode. Clouds on a slightly larger sphere whose opacityNode is the same noise at 3× frequency drifting with time, through smoothstep. City lights on land where the sun direction · normal is negative. An atmosphere shell with side BackSide and a fresnel alpha, after the three.js example webgpu_tsl_earth. A seed uniform makes a new world.
Breaks when
models slip back into ShaderMaterial and GLSL stringsthe API shifts between three.js releases; pin the versioncompute is limited on the WebGL fallback; test both backends
Also called
Three.js Shading Language, three/tsl, node materials, NodeMaterial, Fn()

More prompts

Starter that always runs
Vanilla three.js (a recent release, pinned) with an import map: import * as THREE from 'three/webgpu' and the node functions from 'three/tsl'. Create THREE.WebGPURenderer({ antialias: true }), await renderer.init() before the first frame, and drive it with renderer.setAnimationLoop. One mesh with MeshStandardNodeMaterial: colorNode mixes two uniform() colors by mx_noise_float(positionLocal.mul(3).add(time.mul(0.2))), and positionNode pushes vertices out along normalLocal by that noise × 0.08. A ?webgl URL flag passes forceWebGL: true so both backends can be checked. No ShaderMaterial, no GLSL strings, no onBeforeCompile.
Port a GLSL shader to TSL
Convert this GLSL fragment shader to TSL with identical output. [paste shader] Wrap reusable functions in Fn(), turn every uniform into uniform() with the same default, use .toVar() for mutable locals and .assign() for writes, If() and Loop() for control flow, float() and vec3() for explicit types. Assign the result to material.colorNode, or outputNode if it bypasses lighting. List any GLSL built-in without a direct TSL name and what you used instead. The three.js example webgpu_tsl_transpiler converts GLSL to TSL and is a good check.

Related

Resources · 7