@null3d/engine 0.1.0 → 0.1.1
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.
- package/dist/wasm/single/null3d.js +10 -8
- package/dist/wasm/single/null3d_bg.wasm +0 -0
- package/dist/wasm/threaded/null3d.js +10 -8
- package/dist/wasm/threaded/null3d_bg.wasm +0 -0
- package/docs/api/animation.md +96 -24
- package/docs/api/assets.md +99 -29
- package/docs/api/cameras.md +38 -7
- package/docs/api/controls.md +47 -23
- package/docs/api/debug.md +105 -35
- package/docs/api/engine.md +108 -32
- package/docs/api/feature-draws.md +21 -15
- package/docs/api/feature-effects.md +8 -8
- package/docs/api/feature-instances.md +68 -17
- package/docs/api/features.md +68 -37
- package/docs/api/geometry.md +83 -14
- package/docs/api/grass.md +55 -13
- package/docs/api/impostors.md +92 -50
- package/docs/api/input.md +22 -9
- package/docs/api/lights.md +67 -16
- package/docs/api/lines.md +38 -13
- package/docs/api/materials.md +187 -59
- package/docs/api/math.md +6 -6
- package/docs/api/objects.md +40 -15
- package/docs/api/page.md +58 -7
- package/docs/api/particles.md +36 -11
- package/docs/api/points.md +18 -8
- package/docs/api/post.md +57 -23
- package/docs/api/quality.md +36 -16
- package/docs/api/raycast.md +57 -24
- package/docs/api/reference/animation.md +1 -2
- package/docs/api/reference/assets.md +7 -4
- package/docs/api/reference/cameras.md +3 -2
- package/docs/api/reference/controls.md +59 -2
- package/docs/api/reference/debug.md +58 -6
- package/docs/api/reference/engine.md +39 -10
- package/docs/api/reference/feature-draws.md +3 -4
- package/docs/api/reference/feature-effects.md +2 -3
- package/docs/api/reference/feature-instances.md +5 -4
- package/docs/api/reference/features.md +7 -4
- package/docs/api/reference/geometry.md +132 -21
- package/docs/api/reference/grass.md +62 -2
- package/docs/api/reference/impostors.md +120 -16
- package/docs/api/reference/input.md +1 -2
- package/docs/api/reference/lights.md +4 -3
- package/docs/api/reference/lines.md +3 -4
- package/docs/api/reference/materials.md +7 -6
- package/docs/api/reference/math.md +13 -2
- package/docs/api/reference/objects.md +2 -3
- package/docs/api/reference/particles.md +31 -6
- package/docs/api/reference/points.md +2 -3
- package/docs/api/reference/post.md +4 -3
- package/docs/api/reference/quality.md +1 -2
- package/docs/api/reference/raycast.md +1 -2
- package/docs/api/reference/render.md +4 -3
- package/docs/api/reference/scene.md +24 -5
- package/docs/api/reference/sketch.md +11 -11
- package/docs/api/reference/sound.md +33 -2
- package/docs/api/reference/splats.md +42 -3
- package/docs/api/reference/sprites.md +2 -3
- package/docs/api/reference/tasks.md +16 -3
- package/docs/api/reference/terrain.md +26 -5
- package/docs/api/reference/textures.md +1 -2
- package/docs/api/reference/three-compat.md +18 -7
- package/docs/api/reference/time.md +1 -2
- package/docs/api/reference/ui.md +10 -7
- package/docs/api/reference/vertex-draws.md +2 -3
- package/docs/api/reference/water.md +78 -5
- package/docs/api/reference/wind.md +15 -2
- package/docs/api/render.md +67 -25
- package/docs/api/scene.md +129 -36
- package/docs/api/sketch.md +45 -19
- package/docs/api/sound.md +48 -12
- package/docs/api/splats.md +42 -15
- package/docs/api/sprites.md +8 -6
- package/docs/api/tasks.md +31 -22
- package/docs/api/terrain.md +44 -12
- package/docs/api/textures.md +61 -12
- package/docs/api/three-compat.md +15 -7
- package/docs/api/time.md +3 -5
- package/docs/api/ui.md +18 -10
- package/docs/api/vertex-draws.md +13 -12
- package/docs/api/water.md +111 -67
- package/docs/api/wind.md +61 -15
- package/docs/cli/null3d.md +90 -15
- package/docs/concepts/architecture.md +69 -23
- package/docs/concepts/assets.md +57 -16
- package/docs/concepts/backends.md +65 -25
- package/docs/concepts/color-management.md +42 -13
- package/docs/concepts/culling.md +68 -47
- package/docs/concepts/handles.md +14 -5
- package/docs/concepts/instances.md +72 -23
- package/docs/concepts/large-worlds.md +17 -7
- package/docs/concepts/lighting.md +117 -44
- package/docs/concepts/lod.md +128 -33
- package/docs/concepts/materials.md +43 -12
- package/docs/concepts/particle-buffer.md +48 -35
- package/docs/concepts/post-processing.md +77 -14
- package/docs/concepts/quality-preset-tables.md +3 -2
- package/docs/concepts/quality-presets.md +122 -39
- package/docs/concepts/render-graph.md +56 -21
- package/docs/concepts/render-layers.md +9 -5
- package/docs/concepts/shadows.md +96 -25
- package/docs/concepts/static-dynamic.md +22 -7
- package/docs/cookbook/index.md +163 -119
- package/docs/data/threejs-mapping.json +301 -340
- package/docs/errors/E1101.md +23 -5
- package/docs/errors/E1102.md +11 -3
- package/docs/errors/E1103.md +11 -3
- package/docs/errors/E1104.md +11 -3
- package/docs/errors/E1105.md +13 -5
- package/docs/errors/E1106.md +11 -3
- package/docs/errors/E1107.md +15 -5
- package/docs/errors/E1108.md +11 -3
- package/docs/errors/E1109.md +32 -6
- package/docs/errors/E1110.md +23 -5
- package/docs/errors/E1111.md +11 -3
- package/docs/errors/E1112.md +11 -3
- package/docs/errors/E1203.md +12 -4
- package/docs/errors/E1204.md +11 -3
- package/docs/errors/E1205.md +11 -3
- package/docs/errors/E1206.md +28 -6
- package/docs/errors/E1207.md +11 -3
- package/docs/errors/E1208.md +12 -3
- package/docs/errors/E1209.md +11 -3
- package/docs/errors/E1213.md +27 -5
- package/docs/errors/E1214.md +11 -3
- package/docs/errors/E1215.md +31 -6
- package/docs/errors/E1216.md +31 -6
- package/docs/errors/E1217.md +29 -6
- package/docs/errors/E1218.md +22 -6
- package/docs/errors/E1219.md +11 -3
- package/docs/errors/E1220.md +24 -5
- package/docs/errors/E1221.md +24 -5
- package/docs/errors/E1222.md +11 -3
- package/docs/errors/E1223.md +39 -6
- package/docs/errors/E1224.md +11 -3
- package/docs/errors/E1225.md +11 -3
- package/docs/errors/E1301.md +11 -3
- package/docs/errors/E1302.md +11 -3
- package/docs/errors/E1303.md +11 -3
- package/docs/errors/E1304.md +11 -3
- package/docs/errors/E1305.md +13 -3
- package/docs/errors/E1306.md +11 -3
- package/docs/errors/E1307.md +23 -6
- package/docs/errors/E1401.md +11 -3
- package/docs/errors/E1402.md +13 -5
- package/docs/errors/E1403.md +11 -3
- package/docs/errors/E1404.md +13 -3
- package/docs/errors/E1405.md +15 -4
- package/docs/errors/E1406.md +31 -5
- package/docs/errors/E1407.md +11 -3
- package/docs/errors/E1408.md +11 -3
- package/docs/errors/E1409.md +11 -3
- package/docs/errors/E1410.md +13 -5
- package/docs/errors/E1411.md +11 -3
- package/docs/errors/E1412.md +29 -6
- package/docs/errors/E1413.md +11 -3
- package/docs/errors/E1414.md +11 -3
- package/docs/errors/E1415.md +11 -3
- package/docs/errors/E1416.md +27 -6
- package/docs/errors/E1417.md +11 -3
- package/docs/errors/E1418.md +12 -3
- package/docs/errors/E1419.md +13 -5
- package/docs/errors/E1420.md +11 -3
- package/docs/errors/E1421.md +11 -3
- package/docs/errors/E1422.md +12 -3
- package/docs/errors/E1423.md +12 -3
- package/docs/errors/E1424.md +24 -5
- package/docs/errors/E1425.md +11 -3
- package/docs/errors/E1426.md +11 -3
- package/docs/errors/E1430.md +11 -3
- package/docs/errors/E1431.md +11 -3
- package/docs/errors/E1432.md +11 -3
- package/docs/errors/E1433.md +11 -3
- package/docs/errors/E1434.md +15 -6
- package/docs/errors/E1435.md +11 -3
- package/docs/errors/E1436.md +11 -3
- package/docs/errors/E1437.md +14 -6
- package/docs/errors/E1501.md +41 -6
- package/docs/errors/E1502.md +13 -3
- package/docs/errors/E1503.md +11 -3
- package/docs/errors/E1504.md +11 -3
- package/docs/errors/E1505.md +23 -5
- package/docs/errors/E1506.md +11 -3
- package/docs/errors/index.md +52 -29
- package/docs/getting-started/cdn.md +15 -9
- package/docs/getting-started/first-scene.md +20 -12
- package/docs/getting-started/hosting.md +111 -63
- package/docs/getting-started/install.md +39 -24
- package/docs/getting-started/network-use.md +31 -21
- package/docs/getting-started/project-structure.md +20 -8
- package/docs/getting-started/third-party-notices.md +6 -10
- package/docs/guides/accessibility.md +4 -4
- package/docs/guides/add-ons.md +83 -13
- package/docs/guides/agents.md +2 -6
- package/docs/guides/assets-pipeline.md +248 -72
- package/docs/guides/audio.md +17 -15
- package/docs/guides/baked-light-data.md +44 -23
- package/docs/guides/car-paint.md +37 -31
- package/docs/guides/content-pages.md +53 -29
- package/docs/guides/custom-passes.md +59 -17
- package/docs/guides/custom-shaders.md +54 -37
- package/docs/guides/debugging.md +31 -41
- package/docs/guides/deploying.md +6 -27
- package/docs/guides/deterministic-simulation.md +23 -16
- package/docs/guides/first-use-shaders.md +83 -45
- package/docs/guides/lens-kit.md +29 -26
- package/docs/guides/loading-screens.md +70 -30
- package/docs/guides/multiple-views.md +22 -11
- package/docs/guides/performance.md +188 -37
- package/docs/guides/phones.md +71 -19
- package/docs/guides/physics.md +6 -10
- package/docs/guides/screens.md +41 -29
- package/docs/guides/start-time.md +120 -85
- package/docs/guides/testing.md +137 -98
- package/docs/guides/ui-overlays.md +17 -12
- package/docs/guides/video-textures.md +14 -13
- package/docs/images/api/animation/character.webp +0 -0
- package/docs/images/api/animation/look-at-ring.webp +0 -0
- package/docs/images/api/animation/morph-tulips.webp +0 -0
- package/docs/images/api/animation/skeleton-lines.webp +0 -0
- package/docs/images/api/controls/gizmo-handles.webp +0 -0
- package/docs/images/api/controls/walk-and-fly.webp +0 -0
- package/docs/images/api/debug/debug-shapes.webp +0 -0
- package/docs/images/api/debug/levels-view.webp +0 -0
- package/docs/images/api/engine/transparent-canvas.webp +0 -0
- package/docs/images/api/feature-draws/feature-draw-clouds.webp +0 -0
- package/docs/images/api/feature-instances/compute-instances.webp +0 -0
- package/docs/images/api/feature-instances/instances-shadow.webp +0 -0
- package/docs/images/api/geometry/extra-shapes.webp +0 -0
- package/docs/images/api/geometry/generators.webp +0 -0
- package/docs/images/api/geometry/mesh-arrays.webp +0 -0
- package/docs/images/api/geometry/vertex-updates.webp +0 -0
- package/docs/images/api/grass/grass-grove.webp +0 -0
- package/docs/images/api/grass/grass-presets.webp +0 -0
- package/docs/images/api/grass/grass-shadow.webp +0 -0
- package/docs/images/api/impostors/impostor-handover.webp +0 -0
- package/docs/images/api/impostors/impostor-shadow.webp +0 -0
- package/docs/images/api/impostors/impostors-forest.webp +0 -0
- package/docs/images/api/lights/spot-cookies.webp +0 -0
- package/docs/images/api/lines/lines-lit.webp +0 -0
- package/docs/images/api/lines/lines-widths.webp +0 -0
- package/docs/images/api/materials/coat-and-sheen.webp +0 -0
- package/docs/images/api/materials/decals.webp +0 -0
- package/docs/images/api/materials/iridescence-and-anisotropy.webp +0 -0
- package/docs/images/api/materials/relief.webp +0 -0
- package/docs/images/api/materials/shader-inputs.webp +0 -0
- package/docs/images/api/materials/standard-grid.webp +0 -0
- package/docs/images/api/materials/subsurface.webp +0 -0
- package/docs/images/api/materials/translucency.webp +0 -0
- package/docs/images/api/objects/objects-turntable.webp +0 -0
- package/docs/images/api/particles/campfire.webp +0 -0
- package/docs/images/api/points/galaxy.webp +0 -0
- package/docs/images/api/reference/textures/texture-wrap.webp +0 -0
- package/docs/images/api/render/fullscreen-glow.webp +0 -0
- package/docs/images/api/render/reflection-mirror.webp +0 -0
- package/docs/images/api/render/security-camera.webp +0 -0
- package/docs/images/api/scene/aurora-sky-layer.webp +0 -0
- package/docs/images/api/sound/sound-demo.webp +0 -0
- package/docs/images/api/splats/splats-demo.webp +0 -0
- package/docs/images/api/sprites/sprites-lines.webp +0 -0
- package/docs/images/api/terrain/terrain-demo.webp +0 -0
- package/docs/images/api/textures/canvas-screen.webp +0 -0
- package/docs/images/api/textures/mipmaps.webp +0 -0
- package/docs/images/api/vertex-draws/rain.webp +0 -0
- package/docs/images/api/water/ocean.webp +0 -0
- package/docs/images/api/water/water-demo.webp +0 -0
- package/docs/images/api/water/water-rain.webp +0 -0
- package/docs/images/api/water/waterfall.webp +0 -0
- package/docs/images/concepts/assets/gltf-model.webp +0 -0
- package/docs/images/concepts/color-management/tone-mapped.webp +0 -0
- package/docs/images/concepts/culling/far-from-origin.webp +0 -0
- package/docs/images/concepts/instances/instances.webp +0 -0
- package/docs/images/concepts/instances/per-row-colors.webp +0 -0
- package/docs/images/concepts/large-worlds/large-world.webp +0 -0
- package/docs/images/concepts/lighting/area-lights.webp +0 -0
- package/docs/images/concepts/lighting/atmosphere.webp +0 -0
- package/docs/images/concepts/lighting/environment.webp +0 -0
- package/docs/images/concepts/lighting/light-shafts.webp +0 -0
- package/docs/images/concepts/lighting/reflection-probes.webp +0 -0
- package/docs/images/concepts/lod/forest.webp +0 -0
- package/docs/images/concepts/materials/weighted-transparency.webp +0 -0
- package/docs/images/concepts/post-processing/auto-exposure.webp +0 -0
- package/docs/images/concepts/post-processing/bounce-light.webp +0 -0
- package/docs/images/concepts/post-processing/depth-of-field.webp +0 -0
- package/docs/images/concepts/post-processing/post-effects-alley.webp +0 -0
- package/docs/images/concepts/post-processing/sharpen.webp +0 -0
- package/docs/images/concepts/post-processing/ssr-wet-street.webp +0 -0
- package/docs/images/concepts/render-layers/layers-cottages.webp +0 -0
- package/docs/images/concepts/shadows/hero-shadow.webp +0 -0
- package/docs/images/cookbook/index/picking.webp +0 -0
- package/docs/images/cookbook/index/time-of-day.webp +0 -0
- package/docs/images/errors/E1431/area-lights-no-tables.webp +0 -0
- package/docs/images/guides/custom-passes/reflection-water.webp +0 -0
- package/docs/images/guides/deterministic-simulation/replay-demo.webp +0 -0
- package/docs/images/guides/multiple-views/split-screen.webp +0 -0
- package/docs/images/guides/performance/overdraw-view.webp +0 -0
- package/docs/images/guides/testing/hold-mode-frame.webp +0 -0
- package/docs/images/index/showcase-island.webp +0 -0
- package/docs/images/porting/threejs-shaders/dissolve.webp +0 -0
- package/docs/images/shaders/builtins/builtins.webp +0 -0
- package/docs/images/shaders/surface-functions/custom-surface.webp +0 -0
- package/docs/images/shaders/surface-functions/vertex-offset.webp +0 -0
- package/docs/images/shots.json +2231 -0
- package/docs/index.md +14 -23
- package/docs/moves.json +1 -0
- package/docs/nav.json +300 -0
- package/docs/pages.md +230 -212
- package/docs/porting/react-three-fiber.md +2 -6
- package/docs/porting/threejs-loop-and-threads.md +1 -5
- package/docs/porting/threejs-mapping.md +1248 -234
- package/docs/porting/threejs-materials.md +10 -5
- package/docs/porting/threejs-overview.md +26 -6
- package/docs/porting/threejs-postprocessing.md +2 -6
- package/docs/porting/threejs-shaders.md +16 -14
- package/docs/porting/threejs-unsupported.md +6 -6
- package/docs/porting/verification.md +0 -4
- package/docs/shaders/builtins.md +15 -4
- package/docs/shaders/library.md +9 -6
- package/docs/shaders/surface-functions.md +51 -16
- package/docs/shaders/wgsl-rules.md +12 -5
- package/lib/debug/debug.d.ts +2 -2
- package/lib/debug/draw.d.ts +2 -2
- package/lib/debug/draw.js +8 -4
- package/lib/debug/overlay-look.d.ts +6 -0
- package/lib/debug/overlay-look.js +29 -7
- package/lib/debug/overlay.js +15 -11
- package/lib/debug/stats-options.d.ts +13 -0
- package/lib/debug/stats-panel.d.ts +21 -6
- package/lib/debug/stats-panel.js +80 -13
- package/lib/errors/codes.d.ts +17 -3
- package/lib/errors/codes.js +111 -105
- package/lib/errors/fixes.js +18 -18
- package/lib/gpu/variants.d.ts +8 -2
- package/lib/gpu/variants.js +39 -7
- package/lib/gpu/webgl2/programs.js +1 -1
- package/lib/gpu/webgpu/pipelines.js +13 -13
- package/lib/index.d.ts +1 -1
- package/lib/page/capabilities.d.ts +1 -1
- package/lib/page/engine.d.ts +14 -5
- package/lib/page/engine.js +18 -2
- package/lib/page/label-loop.js +9 -4
- package/lib/page/stats-switch.js +2 -0
- package/lib/page/switches.d.ts +6 -4
- package/lib/page/switches.js +20 -4
- package/lib/scene/baked-light.d.ts +2 -2
- package/lib/scene/fake-call-values.js +2 -2
- package/lib/scene/frame-cameras.d.ts +16 -4
- package/lib/scene/frame-cameras.js +28 -10
- package/lib/scene/gltf.d.ts +1 -1
- package/lib/scene/level-rule.d.ts +6 -5
- package/lib/scene/level-rule.js +2 -2
- package/lib/scene/particles.d.ts +7 -3
- package/lib/scene/particles.js +3 -1
- package/lib/scene/post.d.ts +3 -2
- package/lib/scene/resources.d.ts +15 -9
- package/lib/scene/scene.d.ts +18 -2
- package/lib/scene/scene.js +47 -5
- package/lib/scene/time-of-day.d.ts +10 -5
- package/lib/scene/time-of-day.js +11 -7
- package/lib/shader-artifact.json +1 -1
- package/lib/shared/labels.d.ts +5 -2
- package/lib/shared/labels.js +5 -2
- package/lib/shared/permutation-words.d.ts +2 -0
- package/lib/shared/permutation-words.js +8 -0
- package/lib/shared/recording.d.ts +13 -5
- package/lib/shared/recording.js +31 -10
- package/lib/shared/sketch-data.d.ts +9 -0
- package/lib/shared/sketch-data.js +57 -0
- package/lib/shared/version.d.ts +1 -1
- package/lib/shared/version.js +1 -1
- package/lib/sketch/define-sketch.d.ts +16 -7
- package/lib/sketch/define-sketch.js +2 -1
- package/lib/sketch/runner.d.ts +4 -0
- package/lib/sketch/runner.js +5 -0
- package/lib/sketch/ui.js +4 -2
- package/lib/stats.d.ts +1 -0
- package/lib/workers/protocol.d.ts +10 -0
- package/lib/workers/render-worker.js +4 -1
- package/lib/workers/sketch-worker.js +4 -1
- package/package.json +1 -1
package/docs/guides/testing.md
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: guides/testing
|
|
3
3
|
title: Testing your sketch
|
|
4
|
-
status: experimental
|
|
5
|
-
since: "0.1"
|
|
6
4
|
summary: "Hold mode; image tests; reading results; frames that stay the same on every run; browser tests of a whole app."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Testing your sketch
|
|
10
8
|
|
|
11
|
-
> Roadmap step 0.1, first released in null3D 0.1.0. The API is experimental, so it can still change between versions.
|
|
12
|
-
|
|
13
9
|
```mermaid
|
|
14
10
|
flowchart LR
|
|
15
11
|
start["Page with ?hold=1.5"] --> setup["Sketch setup,<br/>random numbers seeded"]
|
|
@@ -23,32 +19,6 @@ flowchart LR
|
|
|
23
19
|
|
|
24
20
|
An image test draws your sketch at a set time and compares the frame with a reference image. A live engine draws whenever the browser gives it a frame. The time and the steps of a live frame therefore change from run to run. Hold mode fixes both, and the same code then draws the same frame on every run.
|
|
25
21
|
|
|
26
|
-
## Check every rendering mode
|
|
27
|
-
|
|
28
|
-
A scene that looks right and runs well in one setup can fail in another. Before you call a scene done, check frame rate, memory and looks in each of these:
|
|
29
|
-
|
|
30
|
-
| Switch | What it shows |
|
|
31
|
-
|---|---|
|
|
32
|
-
| `?gpu=webgpu&direct=off` | WebGPU with indirect draws |
|
|
33
|
-
| `?gpu=webgpu&direct=on` | WebGPU with direct draws, which holds more memory on some devices |
|
|
34
|
-
| `?gpu=compat` | WebGPU's compatibility mode, with fewer features |
|
|
35
|
-
| `?gpu=webgl2` | WebGL2, where the CPU culls and the draw calls cost more |
|
|
36
|
-
| `?preset=low` to `?preset=ultra` | Each quality preset. High on WebGL2 and compatibility runs at Medium. With no preset, the start-up check picks one |
|
|
37
|
-
|
|
38
|
-
Follow these rules when you measure:
|
|
39
|
-
|
|
40
|
-
- **Measure the whole camera path.** A part of it can read far better than the worst moment, so never quote a part as the whole.
|
|
41
|
-
- **Repeat each run.** One run misleads: two like runs can differ by a third. Fix the pixel ratio, and note what else the machine is doing.
|
|
42
|
-
- **Watch it move.** A held frame shows no popping, flicker or lag. Record a live camera and look at the frames.
|
|
43
|
-
- **Test on real devices.** Use phones and tablets of different form factors, and large and small screens. [Phones and tablets](phones.md#testing-on-real-devices) says how.
|
|
44
|
-
|
|
45
|
-
To read the numbers, open the stats overlay with `?stats=open`:
|
|
46
|
-
|
|
47
|
-
- **Frames per second:** read the average and the slowest second, and count the seconds under your target. An average hides a stall.
|
|
48
|
-
- **Frame work:** `Sketch`, `Drawing` and `GPU` say which side is slow. A bar past the mark is over the frame's budget.
|
|
49
|
-
- **Scale:** under 1.00, the frame-budget governor has lowered the render scale to keep the time, so the frame rate alone flatters the scene.
|
|
50
|
-
- **Memory:** read `GPU textures` and `GPU buffers` on each path, and the page's limit in [Phones and tablets](phones.md#memory).
|
|
51
|
-
|
|
52
22
|
## Hold mode
|
|
53
23
|
|
|
54
24
|
Start hold mode with the `?hold=<seconds>` switch in the page's address, or with the `hold` option of `createEngine`:
|
|
@@ -66,53 +36,35 @@ const { width, height, pixels } = await engine.captureFrame(); // RGBA8 rows, to
|
|
|
66
36
|
In hold mode, the engine does this:
|
|
67
37
|
|
|
68
38
|
1. It seeds the engine's random generator, [`math.random`](../api/math.md#random-numbers), in the sketch's thread, and makes `Math.random` draw from it too. This happens before the sketch module loads.
|
|
69
|
-
2. It runs the sketch's setup. The sketch's `assets` calls run one at a time,
|
|
39
|
+
2. It runs the sketch's setup. The sketch's `assets` calls run one at a time, in the order the sketch made them.
|
|
70
40
|
3. It steps the sketch from time 0 to the held time. The first frame is at time 0 and its `onUpdate` gets a step of 0. Each later frame adds a fixed step of 1/60 second, and the last one lands on the held time exactly. The sketch's own fixed steps fall due from the sketch time, so every hold runs the same ones. At the default rate, each frame after the first runs one.
|
|
71
|
-
4. It draws the last frame on the canvas
|
|
41
|
+
4. It draws the last frame on the canvas and reads its pixels back. The GPU passes of the other frames never run, and [`time.drawn`](../api/time.md#the-time-object) is false in them.
|
|
72
42
|
5. It publishes the frame, or the error that stopped it, as `window.__null3dHold`.
|
|
73
43
|
|
|
74
44
|
`createEngine` resolves once the frame is read back, and `engine.captureFrame()` returns that frame. `engine.mode.hold` gives the held time, and it is `null` for a live engine. After the held frame, the engine draws nothing more: it runs no frame loop, so `engine.measure()` finds no frames. The hold's result gives the held frame's own figures instead. The engine draws no frame before the held one, so the held frame creates every GPU object and uploads the whole scene.
|
|
75
45
|
|
|
76
|
-
A hold at 1.5 seconds runs 91 frames: frame 1 at time 0, then 90 steps. In the last `onUpdate`, `time.now` is 1.5 and `time.frame` is 91.
|
|
46
|
+
A hold at 1.5 seconds runs 91 frames: frame 1 at time 0, then 90 steps. In the last `onUpdate`, `time.now` is 1.5 and `time.frame` is 91.
|
|
77
47
|
|
|
78
|
-
|
|
48
|
+
Motion vectors need the frame before the last one, so with them the engine draws that frame too.
|
|
79
49
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
Hold mode works in every thread mode and on every GPU tier. The single-threaded build runs the sketch on the page's thread, so there the page's `math.random` is seeded too. The page's `Math.random` draws from it until the engine stops.
|
|
50
|
+
Some effects show their result one frame late: screen-space bounce light, mirrors and light probes. Tasks on the job workers can also answer after the last step. In these cases the engine draws one more frame at the held time. That frame runs none of the sketch's code, so the hold still reports the last step's frame number.
|
|
83
51
|
|
|
84
|
-
|
|
52
|
+
Hold mode waits for the sketch's tasks on the job workers, and for the levels of detail that meshes made in code plan. Each of its two waits for the tasks lasts up to 10 seconds, and then it warns and draws anyway. It waits up to five minutes for the plans, then stops with [E1408](../errors/E1408.md). Give a mesh `levels: false` when a test should draw it without levels.
|
|
85
53
|
|
|
86
|
-
|
|
54
|
+
<details>
|
|
55
|
+
<summary>Technical details: what hold mode waits for</summary>
|
|
87
56
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
| `width`, `height`, `pixels` | The frame's size, and its pixels as RGBA8 rows in a `Uint8Array`, top row first | Absent |
|
|
94
|
-
| `stats` | The frame's figures in the form that `engine.measure()` returns: CPU time by thread and phase, draw calls, uploads and pipelines | Absent |
|
|
95
|
-
| `code`, `error` | Absent | The error's code, or `null` for an error without one, and its message |
|
|
57
|
+
- Hold mode waits twice: once after the setup and before the first step, and once after the last step, before the extra frame. A task that never answers delays the hold twice.
|
|
58
|
+
- While plans are still running, the console says every 10 seconds which meshes still plan.
|
|
59
|
+
- The plans hand over their levels one at a time, in the order they started, whatever order the job workers answer in. So the steps find the same scene on every run, and the levels' meshes take the same places in engine memory.
|
|
60
|
+
- The extra frame draws the debug lines of the last `onUpdate` again, so the picture shows the same lines as the frame before it.
|
|
61
|
+
- The held frame creates every GPU object and uploads the whole scene.
|
|
96
62
|
|
|
97
|
-
|
|
63
|
+
</details>
|
|
98
64
|
|
|
99
|
-
|
|
100
|
-
// tests/boat.spec.ts
|
|
101
|
-
await page.goto('/?hold=1.5&gpu=webgl2');
|
|
102
|
-
await page.waitForFunction(() => (window as any).__null3dHold);
|
|
103
|
-
const result = await page.evaluate(() => {
|
|
104
|
-
const held = (window as any).__null3dHold;
|
|
105
|
-
if (!held.ok) return held;
|
|
106
|
-
let binary = '';
|
|
107
|
-
for (let i = 0; i < held.pixels.length; i += 0x8000)
|
|
108
|
-
binary += String.fromCharCode(...held.pixels.subarray(i, i + 0x8000));
|
|
109
|
-
return { ...held, pixels: btoa(binary) };
|
|
110
|
-
});
|
|
111
|
-
if (!result.ok) throw new Error(result.error);
|
|
112
|
-
const pixels = Buffer.from(result.pixels, 'base64'); // compare with the reference image
|
|
113
|
-
```
|
|
65
|
+
The switch wins over the option. A bare `?hold` holds at the time of the `hold` option, or at 0 without one. The time must be from 0 to 600 seconds, or the start fails with [E1407](../errors/E1407.md).
|
|
114
66
|
|
|
115
|
-
|
|
67
|
+
Hold mode works in every thread mode and on every GPU tier. The single-threaded build runs the sketch on the page's thread, so there the page's `math.random` is seeded too. The page's `Math.random` draws from it until the engine stops.
|
|
116
68
|
|
|
117
69
|
## A held frame from the command line
|
|
118
70
|
|
|
@@ -132,18 +84,6 @@ bunx @null3d/cli shot --script drive.script --out tour.png
|
|
|
132
84
|
|
|
133
85
|
[Timed scripts](../cli/null3d.md#timed-scripts) gives the steps and the addresses of objects and properties.
|
|
134
86
|
|
|
135
|
-
## Record a session that went wrong
|
|
136
|
-
|
|
137
|
-
A bug on a phone can replay on this computer. Open your page with `?record`: the engine records each frame's step and the input that the sketch read, from the page's first frame, and a **Save recording** button appears. Reproduce the bug, tap it, and copy the file to the computer. The recording keeps the sketch's random seed, so the sketch's setup builds the same scene on the replay.
|
|
138
|
-
|
|
139
|
-
Open the same page with `?replay=<file>`, or replay a file from anywhere with the command line:
|
|
140
|
-
|
|
141
|
-
```sh
|
|
142
|
-
bunx @null3d/cli shot --replay bug.n3dr --out bug.png
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
The replay runs the recording's frames in order, with their recorded steps and input, and draws the last one. It reads no live input. Its pixels differ from the phone's as any two GPUs' do, so a replay proves the frames and not the picture. A recording stops at 600 seconds of sketch time.
|
|
146
|
-
|
|
147
87
|
## Image tests from the command line
|
|
148
88
|
|
|
149
89
|
`bunx @null3d/cli test` runs your image tests with no test code. List them in `null3d.json` in your project's folder:
|
|
@@ -167,6 +107,24 @@ A test can give `script` instead of `hold`. It then draws each shot step of the
|
|
|
167
107
|
|
|
168
108
|
The first run of a new test fails, because the test has no reference yet. Open its image, and when it is right, keep it with `bunx @null3d/cli test --update-references`. [The `null3d` command](../cli/null3d.md#test) gives the settings of a test, where the files go, and what each line says.
|
|
169
109
|
|
|
110
|
+
## Frames that stay the same on every run
|
|
111
|
+
|
|
112
|
+

|
|
113
|
+
|
|
114
|
+
A held frame is the same on every run.
|
|
115
|
+
|
|
116
|
+
- Move things with `time.now`, the frame's step (`dt` or `time.dt`), or in `onFixedUpdate`. `Date.now()` and `performance.now()` change from run to run.
|
|
117
|
+
- Use `math.random` or `Math.random`: hold mode seeds both. Random numbers from another source, such as `crypto.getRandomValues`, are not seeded.
|
|
118
|
+
- Expect no input, unless the test gives a timed script. A plain hold reads none: every key and button stays up, and the pointer stays at the canvas's top-left corner. A script's key and pointer steps reach the sketch at their times.
|
|
119
|
+
- Finish loading in the setup. Await every asset there, because the hold starts when the setup's promise resolves. A sketch that adds large models after the first frame on a live page waits for them when `engine.held` is true ([A fast start](start-time.md#draw-the-first-frame-before-the-large-models)).
|
|
120
|
+
- Pass test settings in the sketch module's address, such as `new URL('./sketch.ts?view=harbor', import.meta.url)`, and read them in the sketch with `new URL(import.meta.url).searchParams`. The page's messages reach the sketch only after the hold, because `createEngine` resolves after it.
|
|
121
|
+
- Keep a reference image per GPU tier, and force the tier with `?gpu=webgpu`, `?gpu=compat` or `?gpu=webgl2`. The tiers can differ slightly at edges.
|
|
122
|
+
- Compare with a small tolerance. A software GPU in CI and a real GPU differ at object edges. `bunx @null3d/cli test` counts a pixel as different past 10% of the color range. It fails an image when more than 0.1% of its pixels differ ([References and results](../cli/null3d.md#references-and-results)).
|
|
123
|
+
|
|
124
|
+
Loads that run side by side are safe in a held frame or a replay. The engine then runs the sketch's `assets` calls one at a time ([Hold mode](#hold-mode)), and a model makes its textures in the file's order.
|
|
125
|
+
|
|
126
|
+
The [hold mode demo](https://github.com/null3d-engine/null3d/tree/main/examples/hold-mode) drops 400 balls from random places, and moves them by each frame's step. Every live run differs. With `?hold=3`, every run draws the same frame.
|
|
127
|
+
|
|
170
128
|
## When a hold fails
|
|
171
129
|
|
|
172
130
|
Hold mode stops at the first error and publishes it with `ok: false`:
|
|
@@ -178,26 +136,58 @@ Hold mode stops at the first error and publishes it with `ok: false`:
|
|
|
178
136
|
| The frame could not be drawn or read back | E1408, with the reason |
|
|
179
137
|
| The sketch's setup threw, or a thread did not start | The same error that a live start gives, such as [E1405](../errors/E1405.md) |
|
|
180
138
|
| The browser took the GPU away | [E1302](../errors/E1302.md). Hold mode draws on one device, so it does not start a new one. |
|
|
139
|
+
| A level-of-detail plan did not answer after five minutes | [E1408](../errors/E1408.md), naming the meshes that still plan |
|
|
181
140
|
|
|
182
141
|
A live engine logs an error in `onUpdate` and carries on. Hold mode stops instead, so a test fails at once. The console shows the sketch's error with its stack.
|
|
183
142
|
|
|
184
|
-
##
|
|
143
|
+
## Reading the result in a test
|
|
185
144
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
145
|
+
A test runner opens the page with `?hold` and waits for `window.__null3dHold`. The engine sets it the moment the hold ends, so a runner never waits out a timeout on a page that failed. The page needs no test code of its own.
|
|
146
|
+
|
|
147
|
+
| Field | Held frame | Failed hold |
|
|
148
|
+
| --- | --- | --- |
|
|
149
|
+
| `ok` | `true` | `false` |
|
|
150
|
+
| `time`, `frame` | The sketch time in seconds, and the frame's number | Absent |
|
|
151
|
+
| `tier` | The GPU path that drew the frame | Absent |
|
|
152
|
+
| `width`, `height`, `pixels` | The frame's size, and its pixels as RGBA8 rows in a `Uint8Array`, top row first | Absent |
|
|
153
|
+
| `stats` | The frame's figures in the form that `engine.measure()` returns: CPU time by thread and phase, draw calls, uploads and pipelines | Absent |
|
|
154
|
+
| `code`, `error` | Absent | The error's code, or `null` for an error without one, and its message |
|
|
193
155
|
|
|
194
|
-
|
|
156
|
+
With Playwright, a test reads the result like this:
|
|
195
157
|
|
|
196
|
-
|
|
158
|
+
```ts
|
|
159
|
+
// tests/boat.spec.ts
|
|
160
|
+
await page.goto('/?hold=1.5&gpu=webgl2');
|
|
161
|
+
await page.waitForFunction(() => (window as any).__null3dHold);
|
|
162
|
+
const result = await page.evaluate(() => {
|
|
163
|
+
const held = (window as any).__null3dHold;
|
|
164
|
+
if (!held.ok) return held;
|
|
165
|
+
let binary = '';
|
|
166
|
+
for (let i = 0; i < held.pixels.length; i += 0x8000)
|
|
167
|
+
binary += String.fromCharCode(...held.pixels.subarray(i, i + 0x8000));
|
|
168
|
+
return { ...held, pixels: btoa(binary) };
|
|
169
|
+
});
|
|
170
|
+
if (!result.ok) throw new Error(result.error);
|
|
171
|
+
const pixels = Buffer.from(result.pixels, 'base64'); // compare with the reference image
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
The engine reads the pixels back with its own GPU code and takes no screenshot of the canvas. Some browsers change what a page reads from a canvas, to stop fingerprinting.
|
|
175
|
+
|
|
176
|
+
## Record a session that went wrong
|
|
177
|
+
|
|
178
|
+
A bug on a phone can replay on this computer. Open your page with `?record`: the engine records each frame's step and the input that the sketch read, from the page's first frame, and a **Save recording** button appears. Reproduce the bug, tap it, and copy the file to the computer. The recording keeps the sketch's random seed and [start data](../api/page.md#start-data), so the setup builds the same scene on the replay.
|
|
179
|
+
|
|
180
|
+
Open the same page with `?replay=<file>`, or replay a file from anywhere with the command line:
|
|
181
|
+
|
|
182
|
+
```sh
|
|
183
|
+
bunx @null3d/cli shot --replay bug.n3dr --out bug.png
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
The replay runs the recording's frames in order, with their recorded steps and input, and draws the last one. It reads no live input. Its pixels differ from the phone's as any two GPUs' do, so a replay proves the frames and not the picture. A recording stops at 600 seconds of sketch time.
|
|
197
187
|
|
|
198
188
|
## Browser tests of a whole app
|
|
199
189
|
|
|
200
|
-
Image tests check pictures. A game or an app also needs a suite that opens its real page in a browser, drives it and checks what it did. The null3d-develop agent skill's `references/e2e-testing.md` gives the whole setup, with a worked Playwright config and spec. Its main rules:
|
|
190
|
+
Image tests check pictures. A game or an app also needs a suite that opens its real page in a browser, drives it and checks what it did. The null3d-develop agent skill's [`references/e2e-testing.md`](https://github.com/null3d-engine/null3d/blob/main/skills/null3d-develop/references/e2e-testing.md) gives the whole setup, with a worked Playwright config and spec. Its main rules:
|
|
201
191
|
|
|
202
192
|
- Run Playwright Test with its own pinned Chromium, installed with `bunx playwright install chromium`. Use one browser version on every machine, and never the installed Google Chrome.
|
|
203
193
|
- Start the real app with Playwright's `webServer`: the dev server, and the production build through `vite preview`. CI tests the production build.
|
|
@@ -209,29 +199,78 @@ Image tests check pictures. A game or an app also needs a suite that opens its r
|
|
|
209
199
|
- Give each copy of the project its own port, fail a test on any console error, and record a trace on the first retry.
|
|
210
200
|
- Keep real phones and tablets, and frame-rate timing, out of CI.
|
|
211
201
|
|
|
202
|
+
### Record the shader words that a test reaches
|
|
203
|
+
|
|
204
|
+
A suite that drives the game's states can also write the list of shader permutation words that a production build copies. Open the page with `withRecordingSwitch(address)` from `@null3d/cli/shaders`, drive it, then call `saveRecordedWords(page, 'shader-permutations.txt')`. It ends the page's recording and adds the words to the list. [Record from your browser tests](assets-pipeline.md#record-from-your-browser-tests) shows a spec.
|
|
205
|
+
|
|
206
|
+
## Check every rendering mode
|
|
207
|
+
|
|
208
|
+
A scene that looks right and runs well in one setup can fail in another. Before you call a scene done, check frame rate, memory and looks in each of these:
|
|
209
|
+
|
|
210
|
+
| Switch | What it shows |
|
|
211
|
+
|---|---|
|
|
212
|
+
| `?gpu=webgpu&direct=off` | WebGPU with indirect draws |
|
|
213
|
+
| `?gpu=webgpu&direct=on` | WebGPU with direct draws, which holds more memory on some devices |
|
|
214
|
+
| `?gpu=compat` | WebGPU's compatibility mode, with fewer features |
|
|
215
|
+
| `?gpu=webgl2` | WebGL2, where the CPU culls and the draw calls cost more |
|
|
216
|
+
| `?preset=low` to `?preset=ultra` | Each quality preset. High on WebGL2 and compatibility runs at Medium. With no preset, the start-up check picks one |
|
|
217
|
+
|
|
218
|
+
Follow these rules when you measure:
|
|
219
|
+
|
|
220
|
+
- **Measure the whole camera path.** A part of it can read far better than the worst moment, so never quote a part as the whole.
|
|
221
|
+
- **Repeat each run.** One run misleads: two like runs can differ by a third. Fix the pixel ratio, and note what else the machine is doing.
|
|
222
|
+
- **Watch it move.** A held frame shows no popping, flicker or lag. Record a live camera and look at the frames.
|
|
223
|
+
- **Test on real devices.** Use phones and tablets of different form factors, and large and small screens. [Phones and tablets](phones.md#testing-on-real-devices) says how.
|
|
224
|
+
|
|
225
|
+
To read the numbers, open the stats overlay with `?stats=open`:
|
|
226
|
+
|
|
227
|
+
- **Frames per second:** read the average and the slowest second, and count the seconds under your target. An average hides a stall.
|
|
228
|
+
- **Frame work:** `Sketch`, `Drawing` and `GPU` say which side is slow. A bar past the mark is over the frame's budget.
|
|
229
|
+
- **Scale:** under 1.00, the frame-budget governor has lowered the render scale to keep the time, so the frame rate alone flatters the scene.
|
|
230
|
+
- **Memory:** read `GPU textures` and `GPU buffers` on each path, and the page's limit in [Phones and tablets](phones.md#memory).
|
|
231
|
+
|
|
212
232
|
## Switches for tests
|
|
213
233
|
|
|
214
|
-
The engine reads these switches from the page's address in development builds
|
|
234
|
+
The engine reads these switches from the page's address in development builds: the dev server, the `null3d` command's runs and the CDN build's development entry, `lib-dev/index.js`. A production build and the CDN build's production entry, `lib/index.js`, ignore them.
|
|
235
|
+
|
|
236
|
+
To use them in a production build of test pages, turn on the Vite plugin's `urlSwitches` option: `null3d({ urlSwitches: true })`. For a benchmark page that loads the CDN build, `bun run build:cdn --url-switches` does the same ([Try null3D from a CDN](../getting-started/cdn.md#production-and-development-entries)).
|
|
237
|
+
|
|
238
|
+
### Common switches
|
|
215
239
|
|
|
216
240
|
| Switch | Effect |
|
|
217
241
|
| --- | --- |
|
|
218
242
|
| `?hold=1.5` | Hold mode at 1.5 seconds of sketch time; a bare `?hold` holds at the `hold` option's time, or at 0 |
|
|
219
243
|
| `?gpu=webgpu`, `?gpu=compat`, `?gpu=webgl2` | Force a GPU tier, where the device has it |
|
|
220
244
|
| `?direct=on`, `?direct=off` | On WebGPU, force the direct or the indirect draw path on any device, in place of the start-up probe's choice, to compare GPU time. The probe runs only on an Apple GPU in WebKit. `engine.capabilities.directDraws` says which path the engine took, and `engine.capabilities.drawPath` says why ([Performance guide](performance.md#how-the-engine-batches-builds-pipelines-and-times-frames)) |
|
|
245
|
+
| `?preset=low`, `?preset=medium`, `?preset=high`, `?preset=ultra` | Fix the quality preset, within the GPU path's highest; a crashed start still lowers it by one |
|
|
246
|
+
| `?target-fps=display`, `?target-fps=90` | Set the frame rate that the preset check and the governor defend, in place of the `targetFps` option: the display's full rate, or at most that many frames per second ([The target frame rate](../concepts/quality-presets.md#the-target-frame-rate)) |
|
|
247
|
+
| `?preset-check=during-play`, `?preset-check=before-play` | Set when the preset check measures, in place of the `presetCheck` option: in the first frames of play, or before play, with `createEngine` waiting for it ([The preset check](../concepts/quality-presets.md#the-preset-check)) |
|
|
248
|
+
| `?check=fresh` | Measure the quality preset again, as on a first visit, instead of taking the stored result of an earlier [preset check](../concepts/quality-presets.md#repeat-visits) |
|
|
249
|
+
| `?builds=fresh` | Start each pipeline build when the first frame asks for it, as on a first visit, instead of building the [stored list](loading-screens.md#repeat-visits) of an earlier start's first frame ahead of it |
|
|
250
|
+
| `?latency=pipelined`, `?latency=low` | Pick the latency mode |
|
|
251
|
+
| `?threads=off` | The single-threaded build |
|
|
252
|
+
| `?view=levels` | Draw a debug view, here the levels of detail, with no code change ([Debug views](../api/debug.md#the-view-from-the-address)). The switch takes any view name that `debug.view` takes |
|
|
253
|
+
|
|
254
|
+
### Act like another browser
|
|
255
|
+
|
|
256
|
+
| Switch | Effect |
|
|
257
|
+
| --- | --- |
|
|
221
258
|
| `?depth=reversed`, `?depth=reversed-gl`, `?depth=standard` | Force a WebGL2 depth mode. `reversed-gl` draws as browsers without the `EXT_clip_control` extension do, such as Firefox |
|
|
222
259
|
| `?uploads=copy` | On WebGL2, upload a copy of the data, as browsers that refuse to read shared memory need |
|
|
223
260
|
| `?multidraw=off` | On WebGL2, draw as a browser without the `WEBGL_multi_draw` extension does: the engine probes none and draws the whole levels of a cluster tree in place of its patches ([Levels of detail](../concepts/lod.md#cluster-levels)) |
|
|
224
261
|
| `?compile=wait` | On WebGL2, wait for each shader program's compile at its first draw, as browsers without the `KHR_parallel_shader_compile` extension do |
|
|
225
|
-
| `?check=fresh` | Measure the quality preset again, as on a first visit, instead of taking the stored result of an earlier [preset check](../concepts/quality-presets.md#repeat-visits) |
|
|
226
|
-
| `?builds=fresh` | Start each pipeline build when the first frame asks for it, as on a first visit, instead of building the [stored list](loading-screens.md#repeat-visits) of an earlier start's first frame ahead of it |
|
|
227
262
|
| `?compression=bc`, `?compression=astc,etc2`, `?compression=none` | Keep KTX2 textures to the compressed formats that the list names, of those the device has, as on a device with only those. `none` gives every KTX2 texture `rgba8unorm` |
|
|
228
|
-
| `?derived-cache=off` | Turn the [cache of derived data](../api/assets.md#the-cache-of-derived-data) off, so every load makes its data again, as on a first visit: KTX2 files transcode, and `assets.cache` keeps nothing |
|
|
229
|
-
| `?threads=off` | The single-threaded build |
|
|
230
263
|
| `?wake=message` | Make the worker threads wake each other with messages, as browsers without `Atomics.waitAsync` need, such as Firefox before 145 |
|
|
231
264
|
| `?render=main` | Draw on the page's main thread |
|
|
265
|
+
|
|
266
|
+
Other switches measure what one engine saving costs.
|
|
267
|
+
|
|
268
|
+
<details>
|
|
269
|
+
<summary>Technical details: switches that measure one engine saving</summary>
|
|
270
|
+
|
|
271
|
+
| Switch | Effect |
|
|
272
|
+
| --- | --- |
|
|
232
273
|
| `?display-check=off` | Where the page's main thread draws, stop the checks of the display. While the frames run slower than the display, two frame callbacks now and then draw nothing, and the time between them measures the display's refresh rate. The switch measures what they cost |
|
|
233
|
-
| `?sketch-thread=main` | Run the sketch on the page's main thread, over the `sketchThread` option |
|
|
234
|
-
| `?latency=pipelined`, `?latency=low` | Pick the latency mode |
|
|
235
274
|
| `?cells=off` | Cull every object, with no [grid cell](../concepts/culling.md) out of view skipped first, to measure what skipping cells saves |
|
|
236
275
|
| `?skinning=compute` | On WebGPU, skin every skinned mesh once per frame in the skinning pass, a compute pass, instead of in the vertex shader of each pass that draws it, to compare the two ([Animation](../api/animation.md#skinned-meshes)) |
|
|
237
276
|
| `?skinning=full`, `?skinning=skip`, `?skinning=narrow` | On WebGPU, skin in the skinning pass with fewer of its savings, to measure each one. `full` skins every character that a view draws in every frame, with normals and tangents as 32-bit floats. `skip` keeps only the skip of unchanged poses, and `narrow` keeps only the 8-bit normals and tangents |
|
|
@@ -239,7 +278,7 @@ The engine reads these switches from the page's address in development builds. T
|
|
|
239
278
|
| `?shadowdepth=32` | Store the directional light's shadow map in 32-bit float depth, instead of 16-bit depth, to compare the two ([Shadows](../concepts/shadows.md#bias)) |
|
|
240
279
|
| `?half=on`, `?half=off` | Do the scene shaders' color math at half precision, or at full precision. WebGPU needs the device feature `shader-f16`, and a device without it keeps full precision. `engine.capabilities.halfPrecision` says which one the engine took |
|
|
241
280
|
| `?still-camera=off` | Draw every frame of a view that holds still, without the [still-camera accumulation](../concepts/post-processing.md#still-camera-accumulation): the view neither blends nor rests. Hold mode draws without it too |
|
|
242
|
-
| `?
|
|
243
|
-
| `?
|
|
244
|
-
|
|
245
|
-
|
|
281
|
+
| `?derived-cache=off` | Turn the [cache of derived data](../api/assets.md#the-cache-of-derived-data) off, so every load makes its data again, as on a first visit: KTX2 files transcode, and `assets.cache` keeps nothing |
|
|
282
|
+
| `?sketch-thread=main` | Run the sketch on the page's main thread, over the `sketchThread` option |
|
|
283
|
+
|
|
284
|
+
</details>
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: guides/ui-overlays
|
|
3
|
-
title:
|
|
4
|
-
status: experimental
|
|
5
|
-
since: "0.2"
|
|
3
|
+
title: HTML UI around the scene
|
|
6
4
|
summary: "HTML UI on the page; labels that follow objects; GUI panels."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
|
-
# UI
|
|
10
|
-
|
|
11
|
-
> Roadmap step 0.2, first released in null3D 0.1.0. The API is experimental, so it can still change between versions.
|
|
7
|
+
# HTML UI around the scene
|
|
12
8
|
|
|
13
9
|
```mermaid
|
|
14
10
|
flowchart LR
|
|
@@ -47,7 +43,7 @@ document.querySelector('#pause')!.addEventListener('click', () => engine.postToS
|
|
|
47
43
|
|
|
48
44
|
## Labels that follow objects
|
|
49
45
|
|
|
50
|
-
A label is an element that sits over a scene object. The sketch tracks it with `ui.trackLabel`, and the page binds its element with `engine.labels.bind`. [
|
|
46
|
+
A label is an element that sits over a scene object. The sketch tracks it with `ui.trackLabel`, and the page binds its element with `engine.labels.bind`. [Labels that follow objects](../api/ui.md) describes both calls. The [picking demo](https://github.com/null3d-engine/null3d/tree/main/examples/picking) tracks a label on each piece as the plinth turns.
|
|
51
47
|
|
|
52
48
|
This example gives each unit a health bar. The bar follows its unit in every frame, and only the health value travels as a message, when it changes.
|
|
53
49
|
|
|
@@ -94,9 +90,14 @@ engine.onSketchMessage((type, data) => {
|
|
|
94
90
|
});
|
|
95
91
|
```
|
|
96
92
|
|
|
93
|
+
```css
|
|
94
|
+
/* page.css */
|
|
95
|
+
.hp { width: 60px; height: 6px; background: linear-gradient(to right, #4caf50 var(--hp), #333 0); }
|
|
96
|
+
```
|
|
97
|
+
|
|
97
98
|
Keep label elements light. The engine writes only their `transform` and `visibility`, which the browser applies without a new layout. Text or size changes inside a label do cost a layout, so change them only when the value changes.
|
|
98
99
|
|
|
99
|
-
|
|
100
|
+
With many labels, bind elements only for the ones the player can see, and untrack the rest. [Labels that follow objects](../api/ui.md#labels-that-follow-objects) gives the limits.
|
|
100
101
|
|
|
101
102
|
## Labels that are planes of the scene
|
|
102
103
|
|
|
@@ -111,7 +112,7 @@ ui.trackLabel(panel, 'card-3', { transform: 'world', offset: [0, 1.4, 0] });
|
|
|
111
112
|
ui.trackLabel(crown, 'title', { transform: 'billboard', rotation: 0.1 });
|
|
112
113
|
```
|
|
113
114
|
|
|
114
|
-
The page binds the element as for any label. The
|
|
115
|
+
The page binds the element as for any label. The parent must cover the canvas, because the engine turns the element with the camera's perspective.
|
|
115
116
|
|
|
116
117
|
```ts
|
|
117
118
|
// page.ts
|
|
@@ -121,11 +122,11 @@ layer.append(card);
|
|
|
121
122
|
engine.labels.bind('card-3', card);
|
|
122
123
|
```
|
|
123
124
|
|
|
124
|
-
|
|
125
|
+
Size the scene around the element's size in CSS pixels, and the browser keeps the text sharp at any distance. [Labels that follow objects](../api/ui.md#labels-that-follow-objects) gives the units. The [3D labels demo](https://github.com/null3d-engine/null3d/tree/main/examples/css3d-labels) sets a card to `world` and its title to `billboard`.
|
|
125
126
|
|
|
126
127
|
A plane follows either lens. An orthographic camera turns and scales the element as a perspective camera does. An element can hold any markup, such as an iframe or a form. Give it `pointer-events: auto` if it takes the pointer, because the layer around it passes the pointer through.
|
|
127
128
|
|
|
128
|
-
|
|
129
|
+
[Labels that follow objects](../api/ui.md#labels-that-follow-objects) gives the plane limit and the memory it takes.
|
|
129
130
|
|
|
130
131
|
### A page under the scene
|
|
131
132
|
|
|
@@ -148,6 +149,8 @@ const pagePlane = scene.createMesh({
|
|
|
148
149
|
ui.trackLabel(pagePlane, 'page', { transform: 'world' });
|
|
149
150
|
```
|
|
150
151
|
|
|
152
|
+
Give the page element the plane's size, 800 by 600 CSS pixels, so that the two rectangles match.
|
|
153
|
+
|
|
151
154
|
The plane writes its depth and nothing else. Objects behind the page then fail the depth test. Objects in front still draw over it, and a glass object in front still shows the page through itself. An opaque plane would hide the page instead. [Invisible surfaces that hide](../api/materials.md#invisible-surfaces-that-hide) covers the material.
|
|
152
155
|
|
|
153
156
|
The [depth-only demo](https://github.com/null3d-engine/null3d/tree/main/examples/depth-only) shows the pattern, with glass in front of an embedded page and a hall of glowing pylons behind it.
|
|
@@ -170,13 +173,15 @@ gui.add(settings, 'bloom').onChange((on: boolean) => engine.postToSketch('bloom'
|
|
|
170
173
|
// sketch.ts
|
|
171
174
|
page.onMessage((type, data) => {
|
|
172
175
|
if (type === 'exposure') post.set({ exposure: data as number });
|
|
176
|
+
if (type === 'bloom') post.set({ bloom: data ? {} : false });
|
|
173
177
|
});
|
|
174
178
|
```
|
|
175
179
|
|
|
176
180
|
## Related pages
|
|
177
181
|
|
|
178
|
-
- [
|
|
182
|
+
- [Labels that follow objects](../api/ui.md): `ui.trackLabel` and `engine.labels.bind`.
|
|
179
183
|
- [The 3D labels demo](https://github.com/null3d-engine/null3d/tree/main/examples/css3d-labels): cards that turn with a ring.
|
|
180
184
|
- [Messages between sketch and page](../api/page.md): `page.post`, `page.onMessage` and `engine.postToSketch`.
|
|
185
|
+
- [Messages in both directions](https://github.com/null3d-engine/null3d/tree/main/examples/weighted-transparency): a page button sends a blend to the sketch, and the sketch reports back.
|
|
181
186
|
- [Cameras](../api/cameras.md): `worldToScreen` places a single point on the canvas.
|
|
182
187
|
- [Accessibility](accessibility.md): meaning in HTML around the canvas.
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: guides/video-textures
|
|
3
3
|
title: Video textures
|
|
4
|
-
status: experimental
|
|
5
|
-
since: "0.3"
|
|
6
4
|
summary: "engine.registerVideo on the page and textures.fromVideo in the sketch; frame sizes and the upload budget; browser limits."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Video textures
|
|
10
8
|
|
|
11
|
-
> Roadmap step 0.3, first released in null3D 0.1.0. The API is experimental, so it can still change between versions.
|
|
12
|
-
|
|
13
9
|
```mermaid
|
|
14
10
|
flowchart LR
|
|
15
11
|
video["Page:<br/>a video element plays"] -->|"engine.registerVideo:<br/>one ImageBitmap a frame"| sketch["Sketch thread:<br/>textures.fromVideo shows the newest frame"]
|
|
@@ -35,9 +31,7 @@ video.src = '/clips/intro.mp4';
|
|
|
35
31
|
video.muted = true;
|
|
36
32
|
video.loop = true;
|
|
37
33
|
video.playsInline = true;
|
|
38
|
-
//
|
|
39
|
-
// frame in some browsers, so park it past the page's edge instead. Its sound comes from the page
|
|
40
|
-
// as any video's does.
|
|
34
|
+
// Park the element past the page's edge; see Browser limits.
|
|
41
35
|
video.style.position = 'absolute';
|
|
42
36
|
video.style.left = '-10000px';
|
|
43
37
|
video.style.width = '1px';
|
|
@@ -65,7 +59,9 @@ export default defineSketch(({ scene, geometry, materials, textures }) => {
|
|
|
65
59
|
});
|
|
66
60
|
```
|
|
67
61
|
|
|
68
|
-
The texture follows the video: pause, seek, loop and playback speed all show, because the page sends the frames that the video presents. The video has no pixels until its first frame arrives, and until then the material draws with its color alone. A video that is paused at the call still shows, because the sketch asks for the frame that it holds then.
|
|
62
|
+
The texture follows the video: pause, seek, loop and playback speed all show, because the page sends the frames that the video presents. The engine never plays, pauses or seeks the element. The video has no pixels until its first frame arrives, and until then the material draws with its color alone. A video that is paused at the call still shows, because the sketch asks for the frame that it holds then.
|
|
63
|
+
|
|
64
|
+
A page that shows a video in the scene and on the page at once runs one element and one timeline.
|
|
69
65
|
|
|
70
66
|
Stop the frames with `texture.destroy()` in the sketch, or with the function that `engine.registerVideo` returns on the page.
|
|
71
67
|
|
|
@@ -93,14 +89,19 @@ The video's own frame rate sets the cost. A 30 frames a second video uploads its
|
|
|
93
89
|
## Browser limits
|
|
94
90
|
|
|
95
91
|
- A browser plays the video formats that it supports, as for any video element. An H.264 MP4 file plays in the browsers that the engine runs on.
|
|
96
|
-
- A
|
|
92
|
+
- A video with sound plays only after the user acts, unless it is muted. A refused video sends no frames, and the material draws with its color alone, with no error. Start a muted video as the example does, or play it from a click.
|
|
97
93
|
- A video from another origin needs `video.crossOrigin = 'anonymous'` and the server's CORS headers. Without them, the browser refuses to copy the video's pixels into an image. No frames arrive, and the texture keeps the frame it had.
|
|
98
|
-
-
|
|
99
|
-
- The engine reads each frame through `createImageBitmap`, which every supported browser has. It does not need `VideoFrame`, which Safari and Firefox cannot make from a video element.
|
|
94
|
+
- Safari and Firefox cannot make a `VideoFrame` from a video element.
|
|
100
95
|
- Keep the element in the page's layout, out of sight. An element that `display: none` hides may give no frame in some browsers.
|
|
101
|
-
-
|
|
96
|
+
- Some browsers report no frames for a video that the page never shows.
|
|
102
97
|
- A phone plays a video at the rate that its heat allows, and the browser may lower that rate. A video that must keep time with the scene, such as a synchronized caption track, reads the video's time in the page.
|
|
103
|
-
|
|
98
|
+
|
|
99
|
+
<details>
|
|
100
|
+
<summary>Technical details: how the page reads each frame</summary>
|
|
101
|
+
|
|
102
|
+
The page makes each frame with `createImageBitmap`, which every supported browser has, so it does not need `VideoFrame`. It waits for the browser's report of each presented frame. When a browser gives no reports, the page checks the video's time on each display frame while the video plays, and stops that check while it is paused.
|
|
103
|
+
|
|
104
|
+
</details>
|
|
104
105
|
|
|
105
106
|
## Related pages
|
|
106
107
|
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|