depthview-mcp 0.1.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,200 @@
1
+ # Shaders in three.js
2
+
3
+ ## Three ways in, cheapest first
4
+
5
+ | Way | When | Live with Depthview |
6
+ | ------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------- |
7
+ | **Patch a built-in material** (`onBeforeCompile`) | The object should keep PBR lighting, shadows, fog and the environment, plus one custom thing: displacement, a fresnel rim, a dissolve, wind | `patch_shader` |
8
+ | **`ShaderMaterial`** | Fully custom look that needs no scene lighting: effects, backgrounds, particles, baked-light materials | `add_effect kind:"custom"`, `set_shader` |
9
+ | **`RawShaderMaterial`** | Same, with nothing declared for you (you write `#version 300 es`, precision, every uniform) | `set_shader` |
10
+
11
+ Also: `three-custom-shader-material` (CSM) wraps `onBeforeCompile` with named outputs
12
+ (`csm_Position`, `csm_DiffuseColor`...) and is the tidy way in R3F. drei `shaderMaterial()`
13
+ makes a ShaderMaterial class with uniform props.
14
+
15
+ ## What three.js declares for a ShaderMaterial
16
+
17
+ Vertex: `position`, `normal`, `uv` (attributes), `modelMatrix`, `modelViewMatrix`,
18
+ `projectionMatrix`, `viewMatrix`, `normalMatrix`, `cameraPosition`. Fragment: `viewMatrix`,
19
+ `cameraPosition`. No `#version` line, no `precision` line: three adds them. Write
20
+ `gl_FragColor`, `varying`, `attribute`, `texture2D`: three converts them for WebGL 2.
21
+
22
+ Minimal correct pair:
23
+
24
+ ```glsl
25
+ // vertex
26
+ varying vec2 vUv;
27
+ varying vec3 vWorldNormal;
28
+ varying vec3 vWorldPosition;
29
+ void main() {
30
+ vUv = uv;
31
+ vec4 world = modelMatrix * vec4(position, 1.0);
32
+ vWorldPosition = world.xyz;
33
+ vWorldNormal = normalize(mat3(modelMatrix) * normal); // uniform scale only
34
+ gl_Position = projectionMatrix * viewMatrix * world;
35
+ }
36
+ ```
37
+
38
+ ```glsl
39
+ // fragment
40
+ uniform vec3 uColor;
41
+ varying vec2 vUv;
42
+ varying vec3 vWorldNormal;
43
+ varying vec3 vWorldPosition;
44
+ void main() {
45
+ vec3 n = normalize(vWorldNormal);
46
+ vec3 v = normalize(cameraPosition - vWorldPosition);
47
+ float fresnel = pow(1.0 - max(dot(n, v), 0.0), 3.0);
48
+ gl_FragColor = vec4(uColor + fresnel, 1.0);
49
+ #include <tonemapping_fragment>
50
+ #include <colorspace_fragment>
51
+ }
52
+ ```
53
+
54
+ The last two lines are not optional: without them the object skips tone mapping and the sRGB
55
+ conversion and never matches the rest of the scene.
56
+
57
+ ## Patching a built-in material
58
+
59
+ The built-in shaders are made of `#include <chunk>` lines. Replace a chunk line with itself
60
+ plus your code. Useful anchors:
61
+
62
+ | Anchor | Stage | You can change |
63
+ | -------------------------------------------------------------- | -------- | -------------------------------------------------- |
64
+ | `#include <common>` | both | Declare uniforms, varyings and functions after it |
65
+ | `#include <begin_vertex>` | vertex | `transformed` (object-space position) |
66
+ | `#include <beginnormal_vertex>` | vertex | `objectNormal` (fix normals after displacing) |
67
+ | `#include <project_vertex>` | vertex | `mvPosition` is set here; `gl_Position` after it |
68
+ | `#include <color_fragment>` | fragment | `diffuseColor` (rgba base colour) after it |
69
+ | `#include <roughnessmap_fragment>` | fragment | `roughnessFactor` after it |
70
+ | `#include <metalnessmap_fragment>` | fragment | `metalnessFactor` after it |
71
+ | `#include <normal_fragment_maps>` | fragment | `normal` after it |
72
+ | `#include <emissivemap_fragment>` | fragment | `totalEmissiveRadiance` after it |
73
+ | `#include <opaque_fragment>` (r154+, `output_fragment` before) | fragment | `outgoingLight` before it; `gl_FragColor` after it |
74
+ | `#include <dithering_fragment>` | fragment | The very end: final colour tweaks |
75
+
76
+ ```js
77
+ const uniforms = { uTime: { value: 0 }, uAmount: { value: 0.1 } };
78
+ material.onBeforeCompile = (shader) => {
79
+ Object.assign(shader.uniforms, uniforms);
80
+ shader.vertexShader = shader.vertexShader
81
+ .replace('#include <common>', '#include <common>\nuniform float uTime;\nuniform float uAmount;')
82
+ .replace(
83
+ '#include <begin_vertex>',
84
+ '#include <begin_vertex>\n transformed += normal * sin(position.y * 6.0 + uTime * 3.0) * uAmount;',
85
+ );
86
+ };
87
+ material.customProgramCacheKey = () => 'wobble-1'; // or two patched materials share one program
88
+ ```
89
+
90
+ Traps: the shadow pass uses a different material, so a displaced mesh casts its undisplaced
91
+ shadow: give the mesh a `customDepthMaterial` (and `customDistanceMaterial` for point lights)
92
+ with the same displacement. Displacing vertices does not update normals: recompute them (two
93
+ neighbour samples and a cross product) or the lighting stays flat. Chunk names change between
94
+ releases: read the real shader with `get_shader` first, and pin the three.js version.
95
+
96
+ ## Building blocks
97
+
98
+ **Hash and noise.** No `sin`-hash on its own in production: it bands on some GPUs.
99
+
100
+ ```glsl
101
+ float hash(vec3 p) {
102
+ p = fract(p * 0.3183099 + 0.1);
103
+ p *= 17.0;
104
+ return fract(p.x * p.y * p.z * (p.x + p.y + p.z));
105
+ }
106
+ float noise(vec3 x) { // value noise, trilinear
107
+ vec3 i = floor(x), f = fract(x);
108
+ f = f * f * (3.0 - 2.0 * f);
109
+ return mix(mix(mix(hash(i), hash(i + vec3(1,0,0)), f.x),
110
+ mix(hash(i + vec3(0,1,0)), hash(i + vec3(1,1,0)), f.x), f.y),
111
+ mix(mix(hash(i + vec3(0,0,1)), hash(i + vec3(1,0,1)), f.x),
112
+ mix(hash(i + vec3(0,1,1)), hash(i + vec3(1,1,1)), f.x), f.y), f.z);
113
+ }
114
+ float fbm(vec3 p) { // 4 octaves
115
+ float a = 0.5, s = 0.0;
116
+ for (int i = 0; i < 4; i++) { s += a * noise(p); p = p * 2.02 + 13.1; a *= 0.5; }
117
+ return s / 0.9375;
118
+ }
119
+ ```
120
+
121
+ For nicer noise use simplex (`glsl-noise`, Ashima/Stefan Gustavson) or sample a **noise
122
+ texture**: one texture read is far cheaper than 4 octaves of arithmetic. In a ray march
123
+ always use a texture when you can.
124
+
125
+ **Fresnel rim**: `pow(1.0 - saturate(dot(n, v)), power)`. Power 2–5. Add it to emissive, or
126
+ use it to mix towards the environment colour.
127
+
128
+ **Dissolve**: `float n = fbm(vWorldPosition * scale); if (n < uProgress) discard;` then a
129
+ glowing edge: `emissive += edgeColor * smoothstep(uProgress + width, uProgress, n);`.
130
+ With `alphaToCoverage` the cut is anti-aliased.
131
+
132
+ **Reveal by height or distance**: compare `vWorldPosition.y` (or distance to a point) with a
133
+ uniform, add noise to the edge so it is not a ruler line.
134
+
135
+ **Triplanar mapping** (texture without UVs): sample three times along the world axes, blend
136
+ by `pow(abs(normal), vec3(4.0))` normalised.
137
+
138
+ **Scrolling and distortion**: offset UVs by time; distort by a second noise read
139
+ (`uv += (texture2D(uNoise, uv * 2.0 + t).rg - 0.5) * 0.05`). Water, heat haze, flags.
140
+
141
+ **Soft edges on a quad**: `smoothstep` on distance to the centre, never a hard `step`
142
+ (it aliases).
143
+
144
+ **Screen-space UV**: `gl_FragCoord.xy / uResolution` (uResolution = drawing-buffer size, not
145
+ CSS size).
146
+
147
+ **Dither against banding**, last line before output:
148
+ `color += (hash(vec3(gl_FragCoord.xy, uTime)) - 0.5) / 255.0;`
149
+
150
+ **SDF shapes**: `length(p) - r` (circle), `max(abs(p).x - w, abs(p).y - h)` (box); anti-alias
151
+ with `fwidth`: `smoothstep(-fwidth(d), fwidth(d), d)`. MSDF text (troika-three-text, or a
152
+ baked atlas like igloo's) uses the same idea.
153
+
154
+ **Matcap**: a lit sphere image looked up by view-space normal: full "lighting" for one texture
155
+ read. Good for stylised objects and for cheap phones.
156
+
157
+ **Baked light material**: `gl_FragColor = texture2D(uBaked, vUv)` plus a small live term
158
+ (fresnel, a moving highlight). The cheapest good-looking material there is.
159
+
160
+ ## Uniforms
161
+
162
+ - Share one `{ value }` object between materials that need the same time or mouse.
163
+ - Update in the render loop: `uniforms.uTime.value = clock.elapsedTime`. In R3F:
164
+ `useFrame((s) => { ref.current.uniforms.uTime.value = s.clock.elapsedTime })`. Never through
165
+ React state.
166
+ - Types: number → `float`; `Vector2/3/4` → `vec`; `Color` → `vec3`; `Matrix4` → `mat4`;
167
+ `Texture` → `sampler2D`; arrays of those → GLSL arrays.
168
+ - A uniform that is declared but unused is removed by the compiler: no error, no effect.
169
+
170
+ ## Performance rules for fragment shaders
171
+
172
+ - Cost = pixels covered × work per pixel × overdraw. A full-screen effect at pixel ratio 2 on
173
+ a 1440p screen runs 14 million times a frame.
174
+ - Texture reads are the unit of cost. Dependent reads (UV computed from another read) are
175
+ slower. Loops multiply everything.
176
+ - Move work to the vertex shader when it varies smoothly (lighting direction, fog amount).
177
+ - `highp` is the default in three; `mediump` on mobile saves little and breaks noise. Leave it.
178
+ - `discard` and `alphaTest` disable early depth rejection on some GPUs: avoid them on large
179
+ surfaces.
180
+ - Branches on uniforms are fine. Branches on per-pixel values run both sides on some GPUs.
181
+ - First use of a new shader compiles it and stalls a frame (tens to hundreds of ms on
182
+ Windows/ANGLE). Compile ahead: `renderer.compileAsync(scene, camera)`.
183
+
184
+ ## Debugging
185
+
186
+ - Black object: `get_errors` (compile log, with line numbers), then output intermediate
187
+ values as colour (`gl_FragColor = vec4(n * 0.5 + 0.5, 1.0)`).
188
+ - Works in one browser only: an implicit int/float conversion, a non-constant loop bound, or
189
+ `inverse()`/`transpose()` on WebGL 1.
190
+ - NaN shows as black or as flashing pixels that bloom spreads: `normalize(vec3(0))`,
191
+ `pow(negative, x)`, `sqrt(negative)`, `x / 0.0`. Guard with `max(x, 1e-4)`.
192
+ - Edit live with `set_shader` / `set_effect`: the compiler's errors come back with line
193
+ numbers and a failed shader is put back at once.
194
+
195
+ ## TSL
196
+
197
+ On `WebGPURenderer`, materials are node graphs written in TSL (`three/tsl`):
198
+ `material.colorNode = mix(colorA, colorB, fresnel)`, `material.positionNode = positionLocal.add(...)`.
199
+ It replaces GLSL strings and `onBeforeCompile`, and compiles to WGSL or GLSL. Use it for new
200
+ WebGPU projects; do not mix it into a WebGLRenderer project.
@@ -0,0 +1,288 @@
1
+ # Building a 3D site from nothing: the method
2
+
3
+ How to get from an empty folder to a page that reads as finished, with the tools in this
4
+ server. It is the order of work that was used to build the reference site in
5
+ `test-sites/noctua` (a perfume bottle, plain three.js, no model files), and every "do not"
6
+ in it is a mistake that was made and measured there.
7
+
8
+ The rule over all of it: **you cannot see your own code. Open the preview, look, fix, look
9
+ again.** A first draft always has faults that only show in the picture.
10
+
11
+ ## 0. Before any code: decide four things
12
+
13
+ 1. **The subject.** One object the page is about. Not "a 3D scene": a bottle, a watch, a
14
+ crystal, a machine part, a planet. If the user has a glTF model, that is it. If not, you
15
+ model it in code (the `modeling` guide), or `find_assets` for one.
16
+ 2. **Three materials that differ.** Clear against solid, polished against rough, metal
17
+ against stone. One material everywhere is what makes a scene look like a render test.
18
+ 3. **The palette.** One background colour (dark or light, never mid grey), one warm or cool
19
+ accent, the text colour. Write them as CSS variables and use the same values in the scene.
20
+ 4. **The journey.** Three to five stops, one per page section, each showing something the
21
+ last did not: the whole, a detail close up, the back or the light through it, the top, the
22
+ whole again with the call to action. One line of copy per stop.
23
+
24
+ Say these four to the user in a few lines and go. Do not ask them to choose unless they have
25
+ said they care.
26
+
27
+ ## 1. The files
28
+
29
+ ```
30
+ index.html canvas, a loading veil, the navigation, one <section> per stop
31
+ src/style.css type, layout, reveal transitions, the phone layout
32
+ src/main.js renderer, lights, post-processing, camera path, the frame loop, the reveal
33
+ src/studio.js the environment: what shiny things reflect
34
+ src/<subject>.js the subject, built from geometry
35
+ src/set.js floor, plinth, backdrop, contact shadow
36
+ src/dust.js atmosphere
37
+ src/finish.js the last pass: vignette, grain
38
+ ```
39
+
40
+ One module per thing, each returning `{ group, update(t) }`. Give every mesh, light and group
41
+ a `name`: the tools address objects by name, and so will you.
42
+
43
+ Use plain three.js with Vite unless the project is React already (then the `r3f` guide).
44
+ Check each import you are not sure of with `three_docs { name }` before writing it.
45
+
46
+ ## 2. The page first, with the canvas behind it
47
+
48
+ ```css
49
+ #scene {
50
+ position: fixed;
51
+ inset: 0;
52
+ width: 100%;
53
+ height: 100%;
54
+ display: block;
55
+ z-index: 0;
56
+ }
57
+ main {
58
+ position: relative;
59
+ z-index: 10;
60
+ }
61
+ .panel {
62
+ min-height: 120vh;
63
+ display: flex;
64
+ align-items: center;
65
+ padding: 0 var(--pad);
66
+ }
67
+ ```
68
+
69
+ - The canvas is fixed behind the page; the page scrolls natively over it. No scroll
70
+ library is needed for this, and native scroll is what every device does well.
71
+ - **Type carries half of the impression.** A display face for headlines (a high-contrast
72
+ serif, or a tight grotesque), a quiet face for text. Headline `clamp(60px, 9vw, 148px)` on
73
+ the hero, `clamp(40px, 5vw, 78px)` on sections, line height 0.9 to 1. Body 14 to 16 px at
74
+ 1.7. Labels 10 to 12 px, capitals, letter spacing 0.2em and up, in the accent colour.
75
+ Never a system font next to a crafted scene.
76
+ - Each section's copy sits in a column of about 480 px on **one side**; the scene puts the
77
+ subject on the other (step 6). Alternate sides between sections.
78
+ - Copy rises in when its section arrives (`IntersectionObserver`, a class, a 1 s transition
79
+ with a small stagger). The scene never waits for it.
80
+ - The subject will pass under the navigation at some stop. Give the navigation a scrim
81
+ (`linear-gradient(to bottom, <background at 0.8>, transparent)`), or it becomes unreadable
82
+ there.
83
+ - A phone has one column: copy at the bottom of each section over a dark foot
84
+ (a gradient), subject in the upper part (step 6).
85
+
86
+ ## 3. Renderer and environment
87
+
88
+ Renderer: the `threejs` guide has the set-up. Tone mapping `NeutralToneMapping` when the
89
+ subject's colour matters (ACES turns an amber liquid red), `AgXToneMapping` otherwise.
90
+
91
+ **The environment is the lighting.** Glass and metal show nothing but it. Build a studio:
92
+ a dark room with a few bright panels, rendered once with `PMREMGenerator.fromScene`.
93
+
94
+ ```js
95
+ const room = new THREE.Scene();
96
+ const panel = (color, power, w, h, pos) => {
97
+ const mat = new THREE.MeshBasicMaterial({ side: THREE.DoubleSide });
98
+ mat.color.set(color).multiplyScalar(power); // brighter than white: it is a light
99
+ const mesh = new THREE.Mesh(new THREE.PlaneGeometry(w, h), mat);
100
+ mesh.position.set(...pos);
101
+ mesh.lookAt(0, 0, 0);
102
+ room.add(mesh);
103
+ };
104
+ room.add(
105
+ new THREE.Mesh(
106
+ new THREE.SphereGeometry(30), // so nothing reflects pure black
107
+ new THREE.MeshBasicMaterial({ color: '#0d0b0a', side: THREE.BackSide }),
108
+ ),
109
+ );
110
+ panel('#fff4e4', 3.2, 9, 5, [0, 9, 1.5]); // large and soft, above: the broad highlight
111
+ panel('#ffffff', 5.5, 0.9, 9, [-7, 2.5, 3]); // a tall strip each side: the edge lines
112
+ panel('#ffe2bd', 4, 0.7, 9, [7.5, 2.5, 1]);
113
+ panel('#ff9a4d', 2.2, 6, 3, [2, 2.2, -9]); // warm, behind: the rim
114
+ panel('#cfd8ff', 0.5, 7, 4, [0, 1, 10]); // a faint cool fill in front
115
+ scene.environment = new THREE.PMREMGenerator(renderer).fromScene(room, 0.03).texture;
116
+ ```
117
+
118
+ - **Panel power 0.5 to 6.** At 10 and up every reflection is far above white and bloom turns
119
+ the subject into a glare. This was the first fault of the reference build.
120
+ - A strip gives a long clean line on a curved or bevelled edge; a large panel a soft
121
+ gradient across a face. Place them like a photographer places soft boxes, then look at the
122
+ highlights and move them.
123
+ - Or tune a studio live with `set_look world` (light boxes you can move) and `save_look`.
124
+
125
+ Direct lights on top, two at most:
126
+
127
+ - **Key**: a `SpotLight` from above and to one side, `penumbra 1`, shadows on. It makes a
128
+ **pool of light** on the floor that falls off into the dark: that falloff is what makes a
129
+ set look lit. A directional light lights the floor evenly to the horizon.
130
+ - **Rim**: a warm `SpotLight` from behind and the other side, no shadow. It draws the
131
+ outline against the dark background.
132
+ - Spot and point intensities are candela: 50 to 300 at 5 to 10 units, not 1.
133
+
134
+ ## 4. The set: no edges, no horizon
135
+
136
+ A floor that ends in a line against the background is the mark of a tutorial scene.
137
+
138
+ - **Fog in exactly the background colour**, starting before the floor would end:
139
+ `scene.background = BG; scene.fog = new THREE.Fog(BG, 11, 26)`. The floor is a disc several
140
+ times larger than the fog's far distance, dark, rough (0.8 and up), receiving shadows.
141
+ - **A glow behind the subject**: a large plane far back with a radial gradient in a
142
+ `ShaderMaterial` (`fog: false`), brightest behind the subject and **gone before it reaches
143
+ the floor line** (multiply by a `smoothstep` on height). It gives clear glass something to
144
+ show; without it the empty part of a glass object is a black hole. A glow that reaches the
145
+ floor is a wall with an edge: a horizon again. Put the plane **further away than the fog's
146
+ far distance from every camera position**, or the floor behind it is cut off in a line.
147
+ - **A plinth** or a surface under the subject, of a third material (stone, concrete, wood),
148
+ turned on a lathe with a soft edge.
149
+ - **A contact shadow**: one plane just above the surface with a soft radial dark texture
150
+ (`CanvasTexture` with a radial gradient, `transparent`, `depthWrite: false`). It grounds
151
+ the subject more surely than any shadow map and costs one quad.
152
+ - Surface variation without files: a tiling value-noise `CanvasTexture` as `bumpMap`
153
+ (strength 0.2 to 0.6). **Do not put it in `roughnessMap` with `roughness` under 1**: the
154
+ map multiplies, the surface turns shiny in patches and catches coloured blotches from the
155
+ environment. That was the third fault of the reference build.
156
+
157
+ ## 5. The subject
158
+
159
+ The `modeling` guide. The points that decide whether it reads as real:
160
+
161
+ - Every edge has a bevel. A razor edge catches no light; a bevel of 2 to 5% of the size
162
+ catches a line of it, and that line is most of what "premium" means.
163
+ - Silhouettes close to the camera need segments: 96 to 160 round a lathe.
164
+ - Detail is geometry or a map, never a flat colour: flutes cut into a cap, a label, a seam.
165
+ - Metals: `metalness 1`, `roughness 0.15 to 0.35`. Glass: `transmission 1`, `thickness`
166
+ a third of its size, `roughness` 0.03 to 0.06, `ior 1.5`, a little `dispersion` (under 0.2).
167
+ - A liquid in glass is an **opaque** body inside it (transmissive objects do not see each
168
+ other), nearly as large as the inside, darker towards its edges (absorption) with an
169
+ `onBeforeCompile` patch on `#include <color_fragment>`.
170
+ - Lettering on glass: a plane with an `alphaMap` drawn on a canvas, `transparent: true`.
171
+ As an opaque cut-out it would also appear refracted inside the glass, doubled.
172
+
173
+ ## 6. Framing and the scroll
174
+
175
+ One lens for the whole page: `fov` 24 to 32 for a product (a long lens flatters), 35 to 45
176
+ for a place. Change the lens only on a phone (step 8).
177
+
178
+ Each stop is a key: where the camera is, what it looks at, and **where on screen the subject
179
+ sits**.
180
+
181
+ ```js
182
+ const KEYS = [
183
+ { at: 0.0, pos: [0.9, 1.75, 8.6], look: [0, 1.7, 0], shift: 0.42 }, // whole, subject right
184
+ { at: 0.26, pos: [1.9, 3.15, 3.0], look: [0, 2.6, 0], shift: 0.4 }, // detail, close
185
+ { at: 0.52, pos: [-3.1, 1.2, 5.6], look: [0, 1.9, 0], shift: -0.42 }, // other side, subject left
186
+ { at: 0.78, pos: [3.6, 3.9, 6.4], look: [0, 1.9, 0], shift: 0.4 }, // from above
187
+ { at: 1.0, pos: [0, 1.6, 10.4], look: [0, 0.55, 0], shift: 0 }, // whole, centred, high in frame
188
+ ];
189
+ const posCurve = new THREE.CatmullRomCurve3(KEYS.map((k) => new THREE.Vector3(...k.pos)));
190
+ const lookCurve = new THREE.CatmullRomCurve3(KEYS.map((k) => new THREE.Vector3(...k.look)));
191
+ ```
192
+
193
+ - Between two keys ease the progress (`MathUtils.smootherstep`) so every key is a soft stop
194
+ and the move between is one push. Map scroll to the curve parameter per segment, then
195
+ `posCurve.getPoint(t)`, `lookCurve.getPoint(t)`, `camera.lookAt(look)`.
196
+ - **Put the subject on a side with `camera.setViewOffset`, not by aiming the camera away
197
+ from it.** Aiming away turns the subject and skews it; the view offset slides the whole
198
+ picture: `camera.setViewOffset(w, h, -shift * 0.25 * w, 0, w, h)` with `w`, `h` the
199
+ drawing-buffer size. Interpolate `shift` with the keys.
200
+ - **Scroll is a target, the scene follows**:
201
+ `scroll = MathUtils.damp(scroll, target, 4.5, dt)`, and the same for the pointer
202
+ (`lambda` 3, a few centimetres of camera travel, not degrees of swing).
203
+ - Something always moves a little: the subject turns slowly with the scroll and breathes a
204
+ few degrees by itself, dust drifts, a light pulses. A frame where nothing moves looks
205
+ frozen.
206
+ - `prefers-reduced-motion`: no damping, no idle motion; keep the fades.
207
+ - The subject must not be cut by the frame or sit under the navigation at a stop: move the
208
+ look-at point up or down until it is whole.
209
+ - Check the move: `audit_camera_motion` (it should say cinematic, with no jump or whip).
210
+ The developer can then drag each view in the extension (**Camera views**) and you read
211
+ them back with `get_camera_views`.
212
+
213
+ ## 7. The last pass, and atmosphere
214
+
215
+ Composer: `RenderPass` into a `HalfFloatType` target with `samples: 4`, bloom, `OutputPass`,
216
+ then one `ShaderPass` of your own for the finish (after `OutputPass`: it works on the final
217
+ colours).
218
+
219
+ - **Bloom**: strength 0.1 to 0.2, threshold 1.1. It should be missed when off, not seen when
220
+ on.
221
+ - **Vignette** 0.25 to 0.35. **Grain** 0.015 to 0.03, less in the highlights. **Fringe**
222
+ under 1.5 px at the corners and zero in the centre: `uv ± c * dot(c, c) * 0.004` with `c`
223
+ the offset from the centre. A fringe of ten pixels was the second fault of the reference
224
+ build.
225
+ - **Dust**: 100 to 200 soft points, additive, opacity 0.05 to 0.2, drifting slowly, larger
226
+ and fainter near the lens. Four hundred bright ones is a star field.
227
+ - `gl_PointSize` is in drawing-buffer pixels: scale it by
228
+ `bufferHeight / (2 * tan(fov / 2)) / -mvPosition.z` or the dust changes size with the
229
+ screen.
230
+
231
+ ## 8. The phone
232
+
233
+ `camera.aspect < 0.9`: widen the lens (`fov` 38 to 42) instead of pulling the camera back,
234
+ drop the sideways shift, and move the subject **up** with the vertical view offset
235
+ (`0.2 * h`) so the copy has the lower third. Then `review_site { phone: true }`: copy over
236
+ the subject shows up there first.
237
+
238
+ ## 9. The reveal
239
+
240
+ ```js
241
+ await renderer.compileAsync(scene, camera); // every shader, without blocking the page
242
+ composer.render(0); // one hidden frame: textures and shadow maps upload
243
+ await document.fonts.ready; // canvas labels and the page's type are there
244
+ renderer.setAnimationLoop(frame);
245
+ document.body.classList.add('ready'); // the veil fades over about 1.4 s
246
+ ```
247
+
248
+ A full-screen veil in the background colour covers all of that. Never show a half-built
249
+ frame, and never fake a timer: show a number that follows real steps.
250
+
251
+ ## 10. Review until it is clean
252
+
253
+ After **every** round of changes: `open_preview` (reload), `get_errors`, then
254
+ `review_site`. It returns a picture of every stop and the faults it measured: glare, flat
255
+ frame, horizon line, fringe, heavy grain, unreadable copy, a stock primitive as subject, no
256
+ copy, a default typeface, a scroll that changes nothing.
257
+
258
+ 1. Fix every high and medium issue in the source. Reload. Review again.
259
+ 2. When it is clean, look at each picture and answer its `lookFor` questions honestly. Name
260
+ the weakest stop and improve it. Two or three rounds are normal.
261
+ 3. `review_site { phone: true }`.
262
+ 4. `audit_visuals { scroll: [0, 25, 50, 75, 100] }`, `audit_camera_motion`,
263
+ `get_performance`. Draw calls for a product page: under 60.
264
+ 5. Show the user the pictures. Tell them what they can now set by hand in the extension:
265
+ the view of each section (Camera views) and the flow between them.
266
+
267
+ `get_realism` scoring 95 means the render settings are in order. It does not mean the page
268
+ looks good: the old starter scene (a cube on a cylinder, a grey floor to a hard horizon)
269
+ scored 97. `review_site` and your own eyes decide.
270
+
271
+ ## The faults of a first draft, in the order they were met
272
+
273
+ | Seen | Cause | Fix |
274
+ | -------------------------------------------- | ------------------------------------------------------------------ | ----------------------------------------------------------- |
275
+ | A white glare over the subject | Environment panels at 10× white and more, bloom on top | Panel power 0.5 to 6; bloom 0.15, threshold 1.1 |
276
+ | A white blob that stays after that | `anisotropy` on geometry without tangents: invalid pixels, bloomed | `computeTangents()` or no anisotropy |
277
+ | Red and yellow outlines towards the edges | A fringe scaled wrong (tens of pixels) | Under 1.5 px at the corners |
278
+ | The picture crawls with noise | Grain at 0.045 | 0.015 to 0.03 |
279
+ | Floor and stone covered in coloured blotches | `roughnessMap` multiplying a low `roughness` | `roughness` 0.8+, no roughness map; bump only |
280
+ | Radial streaks on the top of a turned disc | A lathe's UVs run round the axis | Project UVs from above for that mesh |
281
+ | The label appears twice | An opaque label is refracted by the glass as well as drawn | `transparent: true` so it is drawn after the glass |
282
+ | The label is nearly black | Foil at `metalness 1` reflecting a dark room | `metalness` 0.3 to 0.5, a lighter colour |
283
+ | Clear glass reads as a black hole | Nothing bright behind it | A glow behind the subject |
284
+ | The liquid is a red plastic block | ACES tone mapping; a body much smaller than the glass | Neutral tone mapping; fill the glass, darken its edges |
285
+ | A line across the frame | The backdrop plane meeting the floor | Fade the glow out above the floor line; fog |
286
+ | The subject under the navigation, cut off | The look-at point too low | Raise it; a scrim under the navigation |
287
+ | Dust reads as stars | 400 bright points | 160, opacity 0.05 to 0.17 |
288
+ | On a phone the copy lies over the subject | One column for both | Subject up with the view offset; a dark foot under the copy |