Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 12.6 — Debugging Shaders
3D Web · Example 2 of 3

Colour as a debugger, and precision

The precision lines are what this software GPU reports; a phone may say something else. The 16-bit values use Math.f16round.

You cannot print from a shader. You read three.js's compile log with its line numbers, show values as colours, know what precision a phone really has, and treat onBeforeCompile as a powerful but fragile tool.

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 5 hands-on exercises with automatic checks.

Practice questions

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

01

Show the UV of a mesh as colour in a MeshStandardMaterial.

02

Make insertAfter log the chunk name and the line where it inserted.

Explain it without notes

01

Why is the error on line 58 when your fragment shader has only 4 lines?

02

Why do two onBeforeCompile materials with different tints share one shader?

Colour as a debugger, and precision
Press Run to see the page.
idle

Console

Nothing logged yet.

Expected console output

normal  centre pixel: 130,130,255
uv      centre pixel: 65,129,0
depth   centre pixel: 245,245,245
this GPU, highp:  range 2^127, 23 fraction bits
this GPU, mediump: range 2^15, 10 fraction bits
a 16-bit float keeps 1000.5 of 1000.7 and 0.00010002 of 0.0001 and Infinity of 70000