@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
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: concepts/instances
|
|
3
3
|
title: Instances and batching
|
|
4
|
-
status: experimental
|
|
5
|
-
since: "0.1"
|
|
6
4
|
summary: "createInstances; typed-array views; markDirty; automatic batching; per-row colors and values."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Instances and batching
|
|
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
|
code["Sketch code writes rows<br/>into typed arrays"] --> rows[("Batch rows<br/>positions, rotations, scales")]
|
|
@@ -23,6 +19,10 @@ An instance batch draws one mesh with one material many times. Each copy is a ro
|
|
|
23
19
|
|
|
24
20
|
Use a batch for many copies that you move in loops, such as particles, bullets, crowds, trees and rocks. Use separate objects from `scene.createMesh` when each copy needs a name, a parent or its own setters.
|
|
25
21
|
|
|
22
|
+

|
|
23
|
+
|
|
24
|
+
One dynamic batch: the sketch writes every column's height in every frame.
|
|
25
|
+
|
|
26
26
|
## Create a batch
|
|
27
27
|
|
|
28
28
|
```ts
|
|
@@ -54,6 +54,10 @@ export default defineSketch(({ scene, geometry, materials }) => {
|
|
|
54
54
|
| `values` | `false` | `true` adds a `values` array: four numbers for each row, which a custom material reads |
|
|
55
55
|
| `layers` | `1`, layer 0 | The [layers](render-layers.md) of every row, as a 32-bit mask |
|
|
56
56
|
| `origin` | `[0, 0, 0]` | The point that every row's position is relative to, kept at full precision: [Batch origins](large-worlds.md#batch-origins) |
|
|
57
|
+
| `castShadows` | `false` | `true` makes every row cast shadows: [Shadows](shadows.md) |
|
|
58
|
+
| `receiveShadows` | `false` | `true` makes shadows fall on every row |
|
|
59
|
+
| `occluder` | `true` | `false` keeps rows from hiding what lies behind them in GPU occlusion culling on WebGPU: [Which objects hide others](culling.md#which-objects-hide-others) |
|
|
60
|
+
| `ranges` | `false` | `true` adds a `ranges` array: a start and an end distance for each row, so each row draws in a band of its own: [Distance bands](lod.md#distance-bands) |
|
|
57
61
|
|
|
58
62
|
`count` is the batch's capacity, which never changes. All rows draw at first. A new batch computes every row in its first frame, so rows that you write before that frame need no mark.
|
|
59
63
|
|
|
@@ -66,12 +70,13 @@ export default defineSketch(({ scene, geometry, materials }) => {
|
|
|
66
70
|
| `scales` | 3 | The scale on each axis | 1, 1, 1 |
|
|
67
71
|
| `colors` | 4 | A linear color (r, g, b, a), with `colors: true` only | 1, 1, 1, 1 |
|
|
68
72
|
| `values` | 4 | Four numbers of your own, with `values: true` only | 0, 0, 0, 0 |
|
|
73
|
+
| `ranges` | 2 | A start and an end distance, with `ranges: true` only | 0 and infinity |
|
|
69
74
|
|
|
70
75
|
Row `i` starts at index `i * 3` in an array of 3 floats per row, and at `i * 4` in an array of 4. Rows have no parent, so each position is in world space, relative to the batch's `origin`. Far from the world's origin, give the batch an origin near its rows, so their 32-bit positions stay small and precise.
|
|
71
76
|
|
|
72
77
|
The arrays are `Float32Array` views of engine memory. The engine's memory can grow when the scene grows: new meshes, batches, materials and lights, and textures made or updated from data. In the single-threaded build, growth empties every older view, and a write to an empty view does nothing. So read the arrays from the batch each time you use them, such as at the start of `onUpdate`. Do not keep them from the setup. A read allocates nothing while the memory keeps its size.
|
|
73
78
|
|
|
74
|
-
To turn rows, write quaternions. The engine
|
|
79
|
+
To turn rows, write unit quaternions, whose length is 1. The engine uses a quaternion within about one per cent of unit length exactly as written, so a rounded rotation such as `[0, 0.38, 0, 0.92]` does not move. The engine does not correct an error inside that band: it can stretch or shear the row by up to about four per cent. The engine scales a quaternion further from unit length to unit length, so a mistyped one turns its row without stretching it. The [math helpers](../api/math.md) make unit quaternions without allocating:
|
|
75
80
|
|
|
76
81
|
```ts
|
|
77
82
|
import { defineSketch, quat } from '@null3d/engine';
|
|
@@ -127,19 +132,14 @@ trees.rotations.set(q, 42 * 4);
|
|
|
127
132
|
trees.markDirty(42, 1); // recompute and upload row 42 only
|
|
128
133
|
```
|
|
129
134
|
|
|
130
|
-
A mark past the batch's capacity throws [E1108](../errors/E1108.md). Development builds
|
|
135
|
+
A mark past the batch's capacity throws [E1108](../errors/E1108.md). Development builds also find rows that changed without a mark and raise [E1110](../errors/E1110.md), which names the row. Sprite and point batches get the same check, and release builds leave it out. A dynamic batch needs no marks, because it recomputes every row in use in every frame. [Static and dynamic objects](static-dynamic.md) compares what each kind uploads. The [terrain demo](https://github.com/null3d-engine/null3d/tree/main/examples/terrain) writes its boulders into a static batch and marks them once. The [custom shader inputs demo](https://github.com/null3d-engine/null3d/tree/main/examples/shader-inputs) does the same for its crystal spiral.
|
|
131
136
|
|
|
132
|
-
|
|
137
|
+
<details>
|
|
138
|
+
<summary>Technical details: how the unmarked-write check works</summary>
|
|
139
|
+
|
|
140
|
+
Before each batch update the check notes the marked rows. It then compares up to 4,096 drawn rows a frame, over all static batches, with the values it read before. The next frame takes the next rows, so a write is found within a few frames at a bounded cost per frame.
|
|
133
141
|
|
|
134
|
-
|
|
135
|
-
add-on. Call `batch.createChunkRows()` to make a writer. The writer stores a chunk's arrays in the
|
|
136
|
-
engine's memory once, at load. Call `writer.reserve(count)` with the number of chunks. Then call
|
|
137
|
-
`writer.write(slot, chunk)` for each chunk as it arrives. In each frame that the chosen rows
|
|
138
|
-
change, call `writer.pack(counts)` with one chosen count for each slot. The writer writes the first
|
|
139
|
-
`counts[slot]` rows of each chunk into the batch, in slot order, and sets the batch's active count.
|
|
140
|
-
The pack runs in the engine's core, so the sketch copies no rows and runs no loop over them. The
|
|
141
|
-
batch must own its rows' transforms: a part of a model, or a sprite or line batch, takes no chunked
|
|
142
|
-
rows. The writer's code loads on first use. `writer.destroy()` frees its chunks.
|
|
142
|
+
</details>
|
|
143
143
|
|
|
144
144
|
## Pools: draw only the rows in use
|
|
145
145
|
|
|
@@ -171,17 +171,36 @@ function remove(row: number): void {
|
|
|
171
171
|
}
|
|
172
172
|
```
|
|
173
173
|
|
|
174
|
-
Keep each row's own data, such as a velocity, in your own typed arrays in the same row order, and move it the same way. An active count past the capacity throws [E1108](../errors/E1108.md).
|
|
174
|
+
Keep each row's own data, such as a velocity, in your own typed arrays in the same row order, and move it the same way. An active count past the capacity throws [E1108](../errors/E1108.md). The [instancing demo](https://github.com/null3d-engine/null3d/tree/main/examples/instances) sets its active count from the quality preset and fills the rows from the middle out.
|
|
175
175
|
|
|
176
176
|
`destroy()` removes a batch at once and frees its rows. After it, stop using the batch and every array that you read from it. Its calls throw [E1101](../errors/E1101.md), and so do its array getters, such as `positions`, in every build. An array that you read before the destroy can point at memory that the engine gives to another batch.
|
|
177
177
|
|
|
178
178
|
## Culling
|
|
179
179
|
|
|
180
|
-
Each row has its own bounding sphere
|
|
180
|
+
Each row has its own bounding sphere: its center is the row's position, and its radius is the mesh's radius times the row's largest scale. A vertex shader that moves rows far from their origins, as traffic along a lane does, needs `setBoundingRadius(r)`. Without it, the engine culls rows that are still on the screen. The call rebuilds the engine's draw tables, so make it at setup. [Culling](culling.md#how-each-path-culls) explains how each GPU path culls.
|
|
181
|
+
|
|
182
|
+
<details>
|
|
183
|
+
<summary>Technical details: how rows are culled</summary>
|
|
184
|
+
|
|
185
|
+
- Each view culls row by row.
|
|
186
|
+
- On WebGPU a compute pass culls, and on direct-draw devices the job workers cull.
|
|
187
|
+
- The rows of a blended material are culled one by one on the job workers, on both paths, and sorted back to front.
|
|
188
|
+
- On WebGL2 a static batch at rest is tested in groups of 64 nearby rows inside one grid cell. A group that is partly in view draws whole, and the GPU clips the rows outside.
|
|
189
|
+
- Both paths skip the rows of static batches in grid cells out of view.
|
|
190
|
+
- On WebGL2, a frame that marks a static batch, and the frame after it, test that batch row by row with no cell skipped.
|
|
191
|
+
|
|
192
|
+
</details>
|
|
181
193
|
|
|
182
194
|
## Automatic batching
|
|
183
195
|
|
|
184
|
-
The engine groups what it draws by mesh and material. Objects from `scene.createMesh` and batch rows that share a mesh and a material draw together. They share instanced or indirect draws. So 500 crates from `createMesh` with one mesh and one material draw as cheaply as a batch of 500 rows. Some groups split
|
|
196
|
+
The engine groups what it draws by mesh and material. Objects from `scene.createMesh` and batch rows that share a mesh and a material draw together. They share instanced or indirect draws. So 500 crates from `createMesh` with one mesh and one material draw as cheaply as a batch of 500 rows. Some groups split:
|
|
197
|
+
|
|
198
|
+
- On WebGPU, an object with bounds of its own from `setBounds` draws apart from the others.
|
|
199
|
+
- Objects that are never culled draw apart from the culled ones, in a group of their own for each mesh and material.
|
|
200
|
+
- Objects and rows that receive shadows draw with other pipelines than those that do not, so they draw apart from them.
|
|
201
|
+
- On WebGL2, the rows of a dynamic batch and of a static batch at rest draw apart from objects with the same mesh and material.
|
|
202
|
+
|
|
203
|
+
Blended objects and rows draw in the transparent pass, sorted back to front. The [factory comparison](https://github.com/null3d-engine/null3d/tree/main/examples/compare/factory) builds each robot arm from separate meshes, and tells how null3D draws parts that share a mesh and a material together.
|
|
185
204
|
|
|
186
205
|
The difference is the sketch's own work on the CPU:
|
|
187
206
|
|
|
@@ -191,7 +210,21 @@ The difference is the sketch's own work on the CPU:
|
|
|
191
210
|
| Hierarchy | Parents and children | None: each row is in world space |
|
|
192
211
|
| Identity | A name and a handle each | A row number |
|
|
193
212
|
|
|
194
|
-
Some calls change the scene's structure
|
|
213
|
+
Some calls change the scene's structure. The next frame then rebuilds the engine's draw tables, which costs more than a normal frame. These calls rebuild:
|
|
214
|
+
|
|
215
|
+
- creating or destroying a batch or an object of any kind, lights included
|
|
216
|
+
- `setMaterial`, `setMesh`, `setParent`, `setDynamic`, `setBounds`, `setFrustumCulled`, `setCastShadows` and `setReceiveShadows`, on an object or a batch
|
|
217
|
+
- `texture.destroy()`, and `texture.update()` with an image of another size
|
|
218
|
+
- turning shadows on or off
|
|
219
|
+
- in development builds, a new [debug view](../api/debug.md)
|
|
220
|
+
|
|
221
|
+
They rebuild even when the value does not change, apart from a batch's `setCastShadows` and `setReceiveShadows`. These never rebuild the tables:
|
|
222
|
+
|
|
223
|
+
- transform setters and row writes
|
|
224
|
+
- `setVisible`, `setLayers`, `setActiveCount` and `setRenderOrder`
|
|
225
|
+
- the other setters of lights and cameras, and `material.set`
|
|
226
|
+
|
|
227
|
+
So create batches in the setup, and pool rows during play instead of creating batches.
|
|
195
228
|
|
|
196
229
|
## Limits
|
|
197
230
|
|
|
@@ -201,12 +234,16 @@ Some calls change the scene's structure: creating or destroying a batch or an ob
|
|
|
201
234
|
- Each row takes about 210 bytes of engine memory, or about 300 with colors or values. When the engine cannot get more memory, `createInstances` throws [E1109](../errors/E1109.md). Rows with colors or values also take 32 bytes each of GPU memory.
|
|
202
235
|
- On WebGL2 the limit follows the largest texture the device allows. A device whose textures reach only 2,048 pixels, the least that WebGL2 allows, draws 1,048,576. That leaves 1,047,552 rows for batches beside a scene of up to 1,023 objects. [GPU tiers and backends](backends.md#the-portable-budget) gives the numbers.
|
|
203
236
|
- Development builds warn once in the console when a scene passes the number that every device of its GPU path draws. On WebGPU that is 2,097,152, the most that devices with WebGPU's default limits draw. On WebGL2 it is 1,048,576. The engine picks the GPU path for each device, so test a scene past 1,048,576 on both paths.
|
|
204
|
-
- A row costs the mesh's vertices in every pass that draws it. Many rows of a detailed mesh therefore cost more than their pixels suggest. A hull of 72 vertices drawn 30,000 times is 2,
|
|
237
|
+
- A row costs the mesh's vertices in every pass that draws it. Many rows of a detailed mesh therefore cost more than their pixels suggest. A hull of 72 vertices drawn 30,000 times is 2,160,000 vertex shader runs for one pass. A depth prepass draws the rows again, because the reflections and ambient occlusion turn one on. Share each vertex between the faces that meet at it where the shading allows a smooth surface. The same mesh with 24 vertices does a third of that work.
|
|
205
238
|
|
|
206
239
|
## Per-row colors
|
|
207
240
|
|
|
208
241
|
`colors: true` adds a `colors` array, with a linear RGBA color for each row, white at first. The color multiplies the material's base color and opacity, as a mesh's vertex colors do. So a white material shows each row's color, and a row's alpha below a masked material's cutoff hides the row. Convert an sRGB color, such as a hex string, with the color helpers in [Math helpers](../api/math.md).
|
|
209
242
|
|
|
243
|
+

|
|
244
|
+
|
|
245
|
+
Row colors multiply the material's color.
|
|
246
|
+
|
|
210
247
|
```ts
|
|
211
248
|
import { color, defineSketch } from '@null3d/engine';
|
|
212
249
|
|
|
@@ -230,7 +267,7 @@ A static batch draws a new color after `markDirty`, as it draws a new position.
|
|
|
230
267
|
|
|
231
268
|
## Per-row values
|
|
232
269
|
|
|
233
|
-
`values: true` adds a `values` array, with four numbers for each row, 0 at first. A [custom material](../guides/custom-shaders.md) reads its row's numbers as `object.values`, a `vec4f`, in its `vertexOffset` and `surface` functions. Use them for whatever changes from row to row: a phase of the wind, an age, a tint or a size. Objects from `scene.createMesh`, and batches without values, read zeros.
|
|
270
|
+
`values: true` adds a `values` array, with four numbers for each row, 0 at first. A [custom material](../guides/custom-shaders.md) reads its row's numbers as `object.values`, a `vec4f`, in its `vertexOffset` and `surface` functions. Use them for whatever changes from row to row: a phase of the wind, an age, a tint or a size. Objects from `scene.createMesh`, and batches without values, read zeros. The [instancing demo](https://github.com/null3d-engine/null3d/tree/main/examples/instances) draws its hover cars with the traffic lanes add-on, whose batches use values and whose shader moves each car.
|
|
234
271
|
|
|
235
272
|
```ts
|
|
236
273
|
import { defineSketch } from '@null3d/engine';
|
|
@@ -273,11 +310,23 @@ Rows with colors or values draw with shader builds of their own, which a page do
|
|
|
273
310
|
|
|
274
311
|
A custom material also reads each row's place in its batch as `input.instance`, from 0, in its `vertexOffset` and `surface` functions. It needs no `values` array: a hue, a phase or a size that follows from the row's place costs the sketch nothing. Every row reads its batch's id as `object.id`, which is `batch.shaderId` in the sketch. [Built-in shader inputs](../shaders/builtins.md#object) describes both.
|
|
275
312
|
|
|
313
|
+
## Rows that arrive in chunks
|
|
314
|
+
|
|
315
|
+
An add-on can give the engine rows that arrive in pieces, such as the chunks of a Gaussian splat cloud. A chunk row writer stores each chunk in the engine's memory once. In each frame it then packs the rows that you choose into the batch, in the engine's core. So the sketch copies no rows and runs no loop over them.
|
|
316
|
+
|
|
317
|
+
1. `const writer = await batch.createChunkRows()` makes the writer. Its code loads on first use.
|
|
318
|
+
2. `writer.reserve(count)` makes room for `count` chunks. Call it again when the cloud gets more chunks.
|
|
319
|
+
3. `writer.write(slot, chunk)` stores one chunk when it arrives. Do not call it in a frame.
|
|
320
|
+
4. `writer.pack(counts)`, in each frame where the chosen rows change, takes one count for each slot. It writes the first `counts[slot]` rows of each chunk into the batch, in slot order, sets the batch's active count and returns that count.
|
|
321
|
+
5. `writer.destroy()` frees the chunks.
|
|
322
|
+
|
|
323
|
+
The batch must own its rows' transforms. A part of a model, or a sprite or line batch, takes no chunked rows.
|
|
324
|
+
|
|
276
325
|
## Related pages
|
|
277
326
|
|
|
278
327
|
- [Static and dynamic objects](static-dynamic.md): what each kind recomputes and uploads.
|
|
279
328
|
- [Handles and objects](handles.md): separate objects, and per-object data in your own arrays.
|
|
280
|
-
- [Scene](../api/scene.md): `createInstances
|
|
329
|
+
- [Scene](../api/scene.md): `createInstances`. [The API reference of instance batches](../api/reference/scene.md#instancebatch) lists every member of `InstanceBatch` and every option of `createInstances`.
|
|
281
330
|
- [Math helpers](../api/math.md): vectors, quaternions and colors for rows.
|
|
282
331
|
- [Sprites](../api/sprites.md): batches of quads that face the camera, with the same rows, marks and limits.
|
|
283
332
|
- [Points](../api/points.md): batches of squares of one size that face the camera, made of sprite rows.
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: concepts/large-worlds
|
|
3
3
|
title: Large worlds and precision
|
|
4
|
-
status: experimental
|
|
5
|
-
since: "0.2"
|
|
6
4
|
summary: "Cell-relative positions and per-frame camera-to-cell offsets; reversed depth; largeWorld mode; batch origins; floating-origin geometry."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Large worlds and precision
|
|
10
8
|
|
|
11
|
-
> Roadmap step 0.2, 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
|
setters["Positions you set:<br/>JavaScript's 64-bit numbers"] -->|"largeWorld: true"| split["Whole cells and<br/>a small 32-bit rest"]
|
|
@@ -39,6 +35,10 @@ Lights, shadow cascades, raycasts, overlap queries, `screenToRay`, `worldToScree
|
|
|
39
35
|
|
|
40
36
|
Cells keep world matrices precise, but a position that you set is a 32-bit float by default. At the Earth's radius it moves in steps of 0.5 m before it reaches a cell. Start the engine with `largeWorld: true`, and the setters keep each position exact:
|
|
41
37
|
|
|
38
|
+

|
|
39
|
+
|
|
40
|
+
A road 6,378 km from the origin, in large-world mode.
|
|
41
|
+
|
|
42
42
|
```ts
|
|
43
43
|
// page.ts
|
|
44
44
|
const engine = await createEngine({ canvas, sketch, largeWorld: true });
|
|
@@ -94,9 +94,16 @@ Sprite, point and line batches take the same `origin` option. Batch origins work
|
|
|
94
94
|
|
|
95
95
|
A camera that moves far from the origin stays as smooth as one near it. Each frame, the engine computes the camera's offset to each cell in 64-bit numbers, so the offsets stay small and exact near the camera.
|
|
96
96
|
|
|
97
|
-
|
|
97
|
+
In large-world mode, a camera that flies past objects 1,000 km out or at the Earth's radius moves them on screen smoothly. It is as smooth as at the origin, on WebGPU, its compatibility mode and WebGL2. Without large-world mode, or when all 512 cells are in use ([Limits](#limits)), the same camera jitters. Positions then move in the coarse steps given at the top of this page.
|
|
98
|
+
|
|
99
|
+
<details>
|
|
100
|
+
<summary>Technical details: how the engine tests a moving camera</summary>
|
|
101
|
+
|
|
102
|
+
A test flies a camera sideways past six squares, 4 m to 35 m away, 12 cm per frame for 16 frames. It flies at the origin, 1,000 km out and at the Earth's radius, in large-world mode. Each square's image moves from frame to frame as it does at the origin, within 0.0001 pixels.
|
|
103
|
+
|
|
104
|
+
The same flight without large-world mode jitters. The camera's position moves in steps of about 6 cm at 1,000 km and 0.5 m at the Earth's radius. So the squares jump by up to 3.5 pixels at 1,000 km and 7.8 pixels at the Earth's radius.
|
|
98
105
|
|
|
99
|
-
|
|
106
|
+
</details>
|
|
100
107
|
|
|
101
108
|
## Floating-origin geometry
|
|
102
109
|
|
|
@@ -113,8 +120,10 @@ The engine does not use logarithmic depth, which writes depth from the fragment
|
|
|
113
120
|
## Limits
|
|
114
121
|
|
|
115
122
|
- At most 512 cells are in use at once, the origin's cell included. A cell is in use while an object or a row lies in it, and frees when the last one leaves. When all 512 are in use, an object or a row that enters a new cell goes into the origin's cell instead. There it has the precision of a 32-bit position. The engine then warns once in the console, as such content jitters far from the origin.
|
|
116
|
-
- Dense content fills the most objects and rows that a scene can draw before it fills the cells. A city of 20,000 objects per square kilometer reaches that most at about
|
|
123
|
+
- Dense content fills the most objects and rows that a scene can draw before it fills the cells. A city of 20,000 objects per square kilometer reaches that most at about 105 km² of flat ground. That needs a device with WebGPU's default limits, and it takes about 100 cells. On a device that allows the most, it reaches the limit at about 420 km², or about 400 cells. The property `engine.capabilities.maxInstances` gives the number for the device ([The portable budget](backends.md#the-portable-budget)).
|
|
124
|
+
- Content spread thin can reach it, such as one marker in each of 1,000 towns. Keep such content in fewer cells. Put far objects under a few parent objects, as children share their root's cell. Or create and destroy them as the camera moves.
|
|
117
125
|
- In large-world mode, positions reach about 2 × 10¹² m from the origin, the most whole cells that a 32-bit integer counts.
|
|
126
|
+
- `getWorldPosition` and `getWorldMatrix` return 64-bit positions, so pass a plain array or a `Float64Array`.
|
|
118
127
|
|
|
119
128
|
## Related pages
|
|
120
129
|
|
|
@@ -124,3 +133,4 @@ The engine does not use logarithmic depth, which writes depth from the fragment
|
|
|
124
133
|
- [Engine](../api/engine.md): the `largeWorld` option of `createEngine`.
|
|
125
134
|
- [GPU tiers and backends](backends.md#depth-on-each-tier): depth on each tier.
|
|
126
135
|
- [The large world demo](https://github.com/null3d-engine/null3d/tree/main/examples/large-world): a drive along a road on the Earth's surface, in large-world mode with batch origins.
|
|
136
|
+
- [No `largeWorld` flag](https://github.com/null3d-engine/null3d/tree/main/examples/far-from-origin): 2 cm keys and a brass wheel, 1,000 km from the origin, seen from 40 cm.
|