Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 12.2 — Uniforms, Attributes and Varyings
3D Web · Example 2 of 3

A uniform you forgot to update

Left half: the update line is missing, so it never changes. Right half: updated every frame.

Data reaches a shader in three ways: uniforms (one value for the whole draw), attributes (one per vertex) and varyings (vertex outputs blended into fragment inputs). ShaderMaterial adds helpers, RawShaderMaterial adds nothing.

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

Add a uniform uTint (vec3) to the first example's ShaderMaterial and multiply the fragment colour by it.

02

Why can an attribute not be read in a fragment shader, and how do you get its value there?

Explain it without notes

01

Which door would you use to send (a) the time, (b) a colour per vertex, (c) the blended colour to the fragment shader?

02

Why does nothing happen when you write uniforms.uTimee = { value: 1.5 } with a typo?

A uniform you forgot to update
Press Run to see the page.
idle

Console

Nothing logged yet.

Expected console output

start (uTime 0):             128
set .value = 1.5:            255
typo uTimee = 1.5:           128 (no error, no change)
replace the uniform object:  255
uniforms.uTime = 1.5:        0