Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 13.3 — TSL Basics
3D Web · Example 3 of 3

Two JavaScript habits that bite

forceWebGL keeps the output the same everywhere. The last line is a statement of what the picture shows: the left half is blue, the right half orange.

TSL, the Three.js Shading Language, builds shader logic from JavaScript functions: Fn, uniform, time, uv, mix, sin. One program becomes WGSL on WebGPU and GLSL on WebGL 2. Its documentation is thin, so you learn to read the source.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 3 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write a Fn called stripes that takes a count and returns 0 or 1 across the uv.x, and use it for a plane's colorNode.

02

Print the vertex shader of a mesh with a positionNode and find the line that sets positionLocal.

Explain it without notes

01

Why can one TSL effect run on both WebGPU and WebGL 2?

02

A teammate writes material.colorNode = a + b with two nodes. What do they get and how do they fix it?

Two JavaScript habits that bite
Press Run to see the page.
idle

Console

Nothing logged yet.

Expected console output

JS  a + b:    [object Object][object Object]
TSL a.add(b): a node: a recipe, not a number
JS  if (node): branch taken, whatever the GPU will compute
drawn: blue on the left half, orange on the right