@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/api/features.md
CHANGED
|
@@ -1,29 +1,36 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: api/features
|
|
3
3
|
title: Add-on feature descriptions
|
|
4
|
-
status: experimental
|
|
5
|
-
since: "0.3"
|
|
6
4
|
summary: "One description for an add-on's render work: the frame point, the reads and writes, the callbacks, the outputs with neutral defaults, the lighting slots, the order band and the view mask."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Add-on feature descriptions
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
A description with `kind: 'draw'` can become a draw with [`scene.addFeatureDraw`](feature-draws.md). A description with `kind: 'fullscreen'` can become a pass over the scene's color with [`post.addFeatureEffect`](feature-effects.md). A description with `kind: 'compute'` can become a compute pass with [`render.addPass`](render.md#compute-passes). A registration checks the shape, and the adapters place the work that each kind declares.
|
|
12
10
|
|
|
13
11
|
```mermaid
|
|
14
12
|
flowchart LR
|
|
15
13
|
description["defineFeature<br/>frame point, reads, writes"] --> registry["FeatureRegistry<br/>one owner for each name"]
|
|
16
14
|
registry --> outputs[("published outputs<br/>a neutral value for readers")]
|
|
17
15
|
registry --> slots["lighting slots<br/>one provider each"]
|
|
18
|
-
registry -->
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
effect --> chain["The chain of custom effects"]
|
|
16
|
+
registry --> adapters["the five adapters<br/>draw, instance, effect,<br/>compute, sky layer"]
|
|
17
|
+
adapters --> frame["The frame's draw list"]
|
|
18
|
+
adapters --> chain["The chain of custom effects"]
|
|
22
19
|
registry --> host["FeatureHost<br/>preset values, budget, figures"]
|
|
23
20
|
host --> overlay["The stats overlay<br/>one row for each feature"]
|
|
24
21
|
```
|
|
25
22
|
|
|
26
|
-
A feature description is one object that describes an add-on's part of a frame. It names the point where the feature records and the scene resources that it reads and writes. It also names the textures that it publishes, the lighting slot that it provides, and the callbacks that keep it in step with the engine.
|
|
23
|
+
A feature description is one object that describes an add-on's part of a frame. It names the point where the feature records and the scene resources that it reads and writes. It also names the textures that it publishes, the lighting slot that it provides, and the callbacks that keep it in step with the engine.
|
|
24
|
+
|
|
25
|
+
Every add-on hook that records frame work uses this one shape. An add-on learns one API, and the engine documents and versions one shape.
|
|
26
|
+
|
|
27
|
+
| Kind | Frame point | Call | Page |
|
|
28
|
+
| --- | --- | --- | --- |
|
|
29
|
+
| Draw | The description's frame point | `scene.addFeatureDraw` | [Add-on draws](feature-draws.md) |
|
|
30
|
+
| Instance draw | `'opaque'` | `scene.addComputeInstances` | [Instanced draws](feature-instances.md) |
|
|
31
|
+
| Full-screen effect | `'resolve'` | `post.addFeatureEffect` | [Add-on effects](feature-effects.md) |
|
|
32
|
+
| Compute pass | The description's frame point | `render.addPass({ kind: 'compute' })` | [Compute passes](render.md#compute-passes) |
|
|
33
|
+
| Sky layer | `'background'` | `scene.setSkyLayer` | [Sky layers](scene.md#sky-layers) |
|
|
27
34
|
|
|
28
35
|
## Writing a description
|
|
29
36
|
|
|
@@ -74,19 +81,19 @@ A description is data, apart from its callbacks. The engine can send the declara
|
|
|
74
81
|
| `order` | The feature's place inside its band. A lower number runs first. | The band's first place |
|
|
75
82
|
| `reads` | The scene resources that the feature reads. | None |
|
|
76
83
|
| `writes` | The scene resources that the feature writes. | None |
|
|
77
|
-
| `outputs` | The textures that the feature publishes
|
|
78
|
-
| `provides` | The lighting slots that the feature
|
|
84
|
+
| `outputs` | The textures that the feature publishes, by name, each with a neutral default. A compute pass publishes its one output as a texture that materials, effects and passes read through `textures.fromPass`. | None |
|
|
85
|
+
| `provides` | The lighting slots that the feature claims. The registry keeps one owner for each slot, and no part of the engine reads the owner. | None |
|
|
79
86
|
| `debugViews` | The debug views that the feature adds, each with a name and a `set` callback. See [Debug drawing and stats](debug.md#views-from-add-ons). | None |
|
|
80
87
|
| `views` | The views that the feature records in, as its view mask. | `['main']` |
|
|
81
|
-
| `ready` | Called when the engine needs to know whether the feature draws. `false` means no cost
|
|
88
|
+
| `ready` | Called when the engine needs to know whether the feature draws. `false` means no cost for the adapters that ask it, the full-screen and instance adapters. | Always ready |
|
|
82
89
|
| `settings` | The feature's own settings, by name, each with a value on every preset and the values it takes. | None |
|
|
83
90
|
| `budget` | The feature's time budget in each frame, on every preset. | None |
|
|
84
91
|
| `gpu` | The render passes that carry the feature's frame work, whose GPU time the overlay shows as its own. | None |
|
|
85
92
|
| `memory` | Returns the GPU bytes that the feature's own objects hold. | None |
|
|
86
|
-
| `quality` |
|
|
87
|
-
| `resize` |
|
|
88
|
-
| `reset` |
|
|
89
|
-
| `destroy` |
|
|
93
|
+
| `quality` | A callback that maps the engine's preset and settings onto the feature's own. See [Callbacks](#callbacks). | None |
|
|
94
|
+
| `resize` | A callback that makes targets of a new size. See [Callbacks](#callbacks). | None |
|
|
95
|
+
| `reset` | A callback that drops history that the reason makes stale. See [Callbacks](#callbacks). | None |
|
|
96
|
+
| `destroy` | A callback that frees the feature's own objects. See [Callbacks](#callbacks). | None |
|
|
90
97
|
|
|
91
98
|
A feature with no `frame` records no frame work. It gives no `kind`, `reads`, `writes` or `views`. It can still publish outputs, provide a lighting slot, add debug views and receive the callbacks.
|
|
92
99
|
|
|
@@ -128,9 +135,9 @@ A feature without an `order` takes the first place of its band, which is 0 for `
|
|
|
128
135
|
|
|
129
136
|
The render graph runs a feature after the passes that write the resources that it reads. It runs the readers of the resources that the feature writes after the feature. The graph keeps its order from these declarations.
|
|
130
137
|
|
|
131
|
-
The first four are the scene inputs
|
|
138
|
+
The first four are the scene inputs (`SceneInput`). `FeatureResource` adds `'history'` and `'shadowAtlas'` to them. Of the scene inputs, a custom material declares only `'sceneDepth'` ([Materials](materials.md#the-scene-behind-a-surface)). The engine binds a feature's reads when it places the feature in the frame.
|
|
132
139
|
|
|
133
|
-
|
|
140
|
+
No pass makes a normals target, and the motion pass runs only while a reader wants the motion vectors.
|
|
134
141
|
|
|
135
142
|
## Published outputs
|
|
136
143
|
|
|
@@ -175,7 +182,13 @@ export const NAMESPACE = declareAddonNamespace({
|
|
|
175
182
|
});
|
|
176
183
|
```
|
|
177
184
|
|
|
178
|
-
|
|
185
|
+
The name and the package follow these rules:
|
|
186
|
+
|
|
187
|
+
- A name takes 1 to 32 lowercase letters, digits or underscore characters, and it starts with a letter.
|
|
188
|
+
- The package takes 1 to 128 characters with no spaces.
|
|
189
|
+
- The engine reserves `null3d` for both the name and the shader library.
|
|
190
|
+
- The engine's own error codes lie below 2000. An add-on's range therefore lies from 2000 to 9999, and two add-ons' ranges do not overlap.
|
|
191
|
+
- A quality key must not be a key of the engine's [quality table](../concepts/quality-presets.md#the-settings-of-each-preset) or another add-on's.
|
|
179
192
|
|
|
180
193
|
`FeatureHost` takes the namespace. A feature that the host registers exports its name, its outputs and its lighting slots to the whole thread. A second add-on that registers one of them is refused. The host's budgets carry the add-on's name too, so two add-ons keep their own budgets. A host refuses a namespace that the thread's registry does not hold.
|
|
181
194
|
|
|
@@ -254,7 +267,14 @@ features.add(
|
|
|
254
267
|
);
|
|
255
268
|
```
|
|
256
269
|
|
|
257
|
-
A feature whose work records inside a pass of the engine's own, such as a draw among the transparent objects, names no scope, and its row reads `gpu not measured`.
|
|
270
|
+
A feature whose work records inside a pass of the engine's own, such as a draw among the transparent objects, names no scope, and its row reads `gpu not measured`. On WebGL2 the engine times the whole frame alone, so no feature has a figure there.
|
|
271
|
+
|
|
272
|
+
<details>
|
|
273
|
+
<summary>Technical details: how the engine samples GPU time</summary>
|
|
274
|
+
|
|
275
|
+
The engine times one frame in eleven and at most seven passes in it. The passes after them share one figure, named `later passes`, which no scope names. A feature therefore never reads another step's time. A pass that draws in some frames only keeps the figure of the window that last timed it, so its row does not blank between them.
|
|
276
|
+
|
|
277
|
+
</details>
|
|
258
278
|
|
|
259
279
|
The overlay also lists the GPU time of each step of the frame that the GPU timed, under `GPU steps` in the same tab. A step is one of the engine's own passes, by its name, or a sketch's pass, by the feature that declares it.
|
|
260
280
|
|
|
@@ -264,32 +284,27 @@ A feature's `memory` callback runs when the engine reads the figures, which happ
|
|
|
264
284
|
|
|
265
285
|
## Callbacks
|
|
266
286
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
- `
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
| Callback | Who calls it |
|
|
276
|
-
| --- | --- |
|
|
277
|
-
| `quality` | `FeatureHost`, when the preset or its settings change |
|
|
278
|
-
| `ready` | The full-screen adapter, when it places a feature and on each quality change, and `effect.refresh()` when the add-on calls it. The instance adapter asks it once each frame. The draw, compute and sky-layer adapters do not ask it. |
|
|
279
|
-
| `resize`, `reset` | Nothing in the engine. An add-on that keeps targets or history keeps its own size and reset state. |
|
|
280
|
-
| `destroy` | The full-screen adapter's handle, when the add-on destroys it. Otherwise the owner of the feature calls it. |
|
|
287
|
+
| Callback | What it gets | Who calls it, and when |
|
|
288
|
+
| --- | --- | --- |
|
|
289
|
+
| `ready` | Nothing | The full-screen adapter, when it places a feature and on each quality change, and `effect.refresh()` when the add-on calls it. The instance adapter asks it once each frame. The draw, compute and sky-layer adapters do not ask it. `false` means no cost for the adapters that ask it. |
|
|
290
|
+
| `quality` | The preset, the engine's settings, and the feature's resolved settings and budget share | `FeatureHost`, when the preset or its settings change. It runs once when the feature is added too. |
|
|
291
|
+
| `resize` | The render size in device pixels | Nothing in the engine. An add-on that keeps targets keeps its own size. |
|
|
292
|
+
| `reset` | `'resize'`, `'camera'` or `'exposure'` | Nothing in the engine. An add-on that keeps history keeps its own reset state. |
|
|
293
|
+
| `destroy` | Nothing | The full-screen adapter's handle, when the add-on destroys it. Otherwise the owner of the feature calls it. |
|
|
281
294
|
|
|
282
295
|
## Adapters
|
|
283
296
|
|
|
284
297
|
Adapters turn a checked description into work in the frame. Five exist:
|
|
285
298
|
|
|
286
299
|
- **Draws:** [`scene.addFeatureDraw(description, options)`](feature-draws.md) draws the add-on's WGSL over its own vertices, with its uniforms, at the description's frame point. The band and order place a blended draw among the transparent pass's objects. The adapter places the main view alone.
|
|
287
|
-
- **Instance draws:** [`scene.addComputeInstances(description, options)`](feature-instances.md) draws a capacity of instances from the add-on's own buffer. The count comes from the GPU on WebGPU, and from the
|
|
300
|
+
- **Instance draws:** [`scene.addComputeInstances(description, options)`](feature-instances.md) draws a capacity of instances from the add-on's own buffer. The count comes from the GPU on WebGPU, and from the sketch on WebGL2. The adapter places the main view alone, at the opaque point.
|
|
288
301
|
- **Full-screen effects:** [`post.addFeatureEffect(description, options)`](feature-effects.md) runs the add-on's WGSL over the whole image, at the `'resolve'` point. The pass reads the scene's color, and its depth when the description declares it, and writes the color. The adapter draws it only while the feature is ready, and asks `ready` again when the quality changes.
|
|
289
302
|
- **Compute passes:** [`render.addPass({ kind: 'compute', description, ... })`](render.md#compute-passes) runs the add-on's compute shader over a storage texture, which materials, effects and passes sample in the same frame. The adapter places the main view alone, binds no scene resource, and publishes the description's one output. A WebGL2 page runs the pass's fragment form, or the call throws.
|
|
290
303
|
- **Sky layers:** [`scene.setSkyLayer(description, options)`](scene.md#sky-layers) draws the add-on's WGSL over the background, at the `'background'` point as a `'draw'`, with the `'sky'` slot and the three views. The engine places it itself, because the background draws it before the opaque objects. Its function reads the core sky's values.
|
|
291
304
|
|
|
292
|
-
|
|
305
|
+
## Limits
|
|
306
|
+
|
|
307
|
+
The descriptions serve the five adapters alone. Some kinds of add-on have no hook:
|
|
293
308
|
|
|
294
309
|
| Kind of add-on | What the engine does |
|
|
295
310
|
| --- | --- |
|
|
@@ -300,7 +315,18 @@ The descriptions serve these five adapters alone. Some kinds of add-on have no h
|
|
|
300
315
|
|
|
301
316
|
## Checks
|
|
302
317
|
|
|
303
|
-
`defineFeature` returns a frozen description with the defaults filled. It throws E1223
|
|
318
|
+
`defineFeature` returns a frozen description with the defaults filled. It throws [E1223](../errors/E1223.md) for:
|
|
319
|
+
|
|
320
|
+
- An option that a description does not take.
|
|
321
|
+
- A frame point or kind that does not go together.
|
|
322
|
+
- An order outside its band.
|
|
323
|
+
- A name that is too long.
|
|
324
|
+
- An output with no neutral default.
|
|
325
|
+
- A resource, view or slot that does not exist.
|
|
326
|
+
- A setting whose preset value is not one of its values.
|
|
327
|
+
- A setting with a governor but no budget.
|
|
328
|
+
- A budget whose four times are not above 0.
|
|
329
|
+
- A GPU scope pass that `render.addPass` did not return.
|
|
304
330
|
|
|
305
331
|
`FeatureRegistry.add` refuses a feature name that another feature has. It also refuses an output name that another feature publishes, a lighting slot that another feature provides, and a debug view name that another feature adds. `remove` gives those names back. A debug view name that names one of the engine's own views is refused too.
|
|
306
332
|
|
|
@@ -308,7 +334,7 @@ The descriptions serve these five adapters alone. Some kinds of add-on have no h
|
|
|
308
334
|
|
|
309
335
|
| Code | Cause |
|
|
310
336
|
| --- | --- |
|
|
311
|
-
| E1223 | A description that `defineFeature` or `FeatureRegistry.add` cannot take
|
|
337
|
+
| E1223 | A description that `defineFeature` or `FeatureRegistry.add` cannot take. [Checks](#checks) lists each case. |
|
|
312
338
|
|
|
313
339
|
## Related pages
|
|
314
340
|
|
|
@@ -317,6 +343,11 @@ The descriptions serve these five adapters alone. Some kinds of add-on have no h
|
|
|
317
343
|
- [Quality API](quality.md): the preset and settings that a feature's `quality` callback receives, and the budgets' scale.
|
|
318
344
|
- [Debug drawing and stats](debug.md#stats-overlay-and-frame-figures): the overlay's figures, the add-on rows among them.
|
|
319
345
|
- [Post-processing API](post.md): the engine's effects, which run at the resolve and post points.
|
|
346
|
+
- [The aurora feature](https://github.com/null3d-engine/null3d/tree/main/examples/aurora): its add-on file, `examples/addons/aurora/index.ts`, declares a sky layer at the background frame point.
|
|
347
|
+
- [Reflection cadence](https://github.com/null3d-engine/null3d/tree/main/examples/water): the water add-on sets a cadence on its reflection pass.
|
|
348
|
+
- [The splats feature](https://github.com/null3d-engine/null3d/tree/main/examples/splats): the add-on's `feature.ts` and `system.ts` make the feature and draw it.
|
|
349
|
+
- [Published outputs](https://github.com/null3d-engine/null3d/tree/main/examples/ocean): the ocean's compute passes publish outputs that its material reads with `textures.fromPass`.
|
|
350
|
+
- [Lighting slots](https://github.com/null3d-engine/null3d/tree/main/examples/aurora): the aurora add-on provides the sky slot.
|
|
320
351
|
|
|
321
352
|
## API reference
|
|
322
353
|
|
package/docs/api/geometry.md
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: api/geometry
|
|
3
3
|
title: Geometry
|
|
4
|
-
status: experimental
|
|
5
|
-
since: "0.1"
|
|
6
4
|
summary: "Generators of common shapes; extra shapes in @null3d/geometry; meshes from arrays; morph targets; vertices that change; levels of detail that meshes plan on the job workers; vertex formats; large meshes."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Geometry
|
|
10
8
|
|
|
11
|
-
>
|
|
9
|
+
> No call skins a mesh that you build, so its joints and weights do not move its vertices.
|
|
12
10
|
|
|
13
11
|
```mermaid
|
|
14
12
|
flowchart LR
|
|
@@ -27,6 +25,10 @@ A mesh is the shape that objects draw. `ctx.geometry` makes meshes, and any numb
|
|
|
27
25
|
|
|
28
26
|
Each generator takes named options. An option that you leave out takes its default.
|
|
29
27
|
|
|
28
|
+

|
|
29
|
+
|
|
30
|
+
The geometry generators.
|
|
31
|
+
|
|
30
32
|
```ts
|
|
31
33
|
// sketch.ts
|
|
32
34
|
const crate = geometry.box({ width: 1, height: 0.5, depth: 1 });
|
|
@@ -55,6 +57,10 @@ The generators give each vertex a position, a normal and texture coordinates. Th
|
|
|
55
57
|
|
|
56
58
|
The `@null3d/geometry` package holds more shapes, and the curves and outlines that build them. Install it beside the engine:
|
|
57
59
|
|
|
60
|
+

|
|
61
|
+
|
|
62
|
+
Extra shapes from @null3d/geometry.
|
|
63
|
+
|
|
58
64
|
```sh
|
|
59
65
|
bun add @null3d/geometry
|
|
60
66
|
```
|
|
@@ -109,7 +115,7 @@ scene.createMesh({ mesh: quad, material: materials.unlit({ color: '#ffffff' }) }
|
|
|
109
115
|
| `tangents` | 4: the direction in which u grows, then 1 or -1 for the direction of v |
|
|
110
116
|
| `joints` | 4 joint indices, for skinned meshes |
|
|
111
117
|
| `weights` | 4: how much each joint moves the vertex, which add up to 1 |
|
|
112
|
-
| `targets` | 4
|
|
118
|
+
| `targets` | 4 numbers that a custom material's vertex offset reads, such as the position that the vertex takes at the next coarser level and that level's error |
|
|
113
119
|
|
|
114
120
|
The arrays follow these rules:
|
|
115
121
|
|
|
@@ -117,6 +123,7 @@ The arrays follow these rules:
|
|
|
117
123
|
- `indices` takes a `Uint16Array`, a `Uint32Array` or an array of numbers, with three indices per triangle. Without indices, each three vertices in a row make one triangle.
|
|
118
124
|
- `joints` and `weights` come together. A mesh keeps them for [skinning](animation.md#skinned-meshes). A mesh that you build draws in the pose that its positions give.
|
|
119
125
|
- `targets` takes floats only, and a mesh takes it or `morphTargets`, never both: the two share one vertex record.
|
|
126
|
+
- `targets` is for a shape whose material moves its vertices between levels of detail, as the [terrain](terrain.md#how-it-works) does. The material's vertex offset reads the four numbers as `input.vertexRecord` ([Vertex offsets](../shaders/surface-functions.md#vertex-offsets)). Leave it out unless your vertex offset reads it.
|
|
120
127
|
- A triangle's front face has its vertices in counter-clockwise order.
|
|
121
128
|
- Each array's length must fit the vertex count, and its type must be one that its attribute takes. Each index must name a vertex, and each value must be a finite number. Otherwise the call throws [E1206](../errors/E1206.md).
|
|
122
129
|
- The engine copies the arrays. You can change or drop them after the call.
|
|
@@ -154,11 +161,17 @@ Integer positions keep their own units. Give the object the scale and the positi
|
|
|
154
161
|
|
|
155
162
|
`computeNormals: true` computes the normals from the triangles. Each vertex gets the average of the normals of its triangles, weighted by their areas. Vertices that triangles share get smooth normals. For hard edges, give each face its own vertices. The [meshes from arrays demo](https://github.com/null3d-engine/null3d/tree/main/examples/mesh-arrays) shows both: a smooth height field, an island with a color at each vertex, and a crystal with hard edges.
|
|
156
163
|
|
|
164
|
+

|
|
165
|
+
|
|
166
|
+
Meshes from arrays.
|
|
167
|
+
|
|
157
168
|
`computeTangents: true` computes tangents from the positions, the normals and `uvs`, with Eric Lengyel's method. It needs `uvs`, and it works with or without indices. The job workers share the work, so a large mesh takes less time. Both options compute from integer positions, normals and texture coordinates too, as shaders read them, and give 32-bit floats.
|
|
158
169
|
|
|
159
170
|
## Morph targets
|
|
160
171
|
|
|
161
|
-
A morph target is another shape of a mesh, such as a smile on a face. The `morphTargets` option gives a mesh its targets, as glTF stores them. Each target is an array of three numbers per vertex: how far the target moves the vertex at weight 1. The list `positions` moves the vertices, `normals` turns their normals, and `tangents` turns their tangents.
|
|
172
|
+
A morph target is another shape of a mesh, such as a smile on a face. The `morphTargets` option gives a mesh its targets, as glTF stores them. Each target is an array of three numbers per vertex: how far the target moves the vertex at weight 1. The list `positions` moves the vertices, `normals` turns their normals, and `tangents` turns their tangents.
|
|
173
|
+
|
|
174
|
+
The list `colors` changes the mesh's vertex colors, with as many numbers per vertex as `colors` has, three or four. Every list holds the same number of targets, from 1 to 256. The list `names` names the targets.
|
|
162
175
|
|
|
163
176
|
```ts
|
|
164
177
|
const count = positions.length / 3;
|
|
@@ -175,12 +188,27 @@ const head = scene.createMesh({ mesh: face, material });
|
|
|
175
188
|
head.setMorphWeight('Smile', 0.8);
|
|
176
189
|
```
|
|
177
190
|
|
|
178
|
-
Each object of the mesh has weights of its own, which start at 0. `setMorphWeight` sets them, and clips from glTF files animate them ([Morph targets](animation.md#morph-targets)). The [morph targets demo](https://github.com/null3d-engine/null3d/tree/main/examples/morph-flowers) makes tulips with one target, which opens the petals, turns their normals and changes their color. Each tulip has a weight of its own.
|
|
191
|
+
Each object of the mesh has weights of its own, which start at 0. `setMorphWeight` sets them, and clips from glTF files animate them ([Morph targets](animation.md#morph-targets)). The [morph targets demo](https://github.com/null3d-engine/null3d/tree/main/examples/morph-flowers) makes tulips with one target, which opens the petals, turns their normals and changes their color. Each tulip has a weight of its own.
|
|
192
|
+
|
|
193
|
+
The targets of a mesh have size limits. Past them, `fromArrays` throws [E1206](../errors/E1206.md).
|
|
194
|
+
|
|
195
|
+
<details>
|
|
196
|
+
<summary>Technical details: how morph targets are stored</summary>
|
|
197
|
+
|
|
198
|
+
The engine stores, for each vertex, only the targets that move it. So a face whose targets each move a small part of it takes far less memory than a copy of every vertex for every target. A vertex can take up to 255 targets.
|
|
199
|
+
|
|
200
|
+
The targets of every mesh together can take up to 4,194,304 deltas, 32 MiB of GPU memory. Each of a vertex's positions, normals, tangents and colors counts once. The GPU keeps each delta in a 16-bit float, which is exact to 1/2048 of the delta's size, and each weight in a 32-bit float. A morphed color stays between 0 and 1, as the glTF specification asks.
|
|
201
|
+
|
|
202
|
+
</details>
|
|
179
203
|
|
|
180
204
|
## Vertices that change
|
|
181
205
|
|
|
182
206
|
`mesh.updateVertices(name, values, start, count)` writes new values into one attribute of a mesh. Keep the arrays that you made the mesh with, change them, and pass them again:
|
|
183
207
|
|
|
208
|
+

|
|
209
|
+
|
|
210
|
+
updateVertices every frame.
|
|
211
|
+
|
|
184
212
|
```ts
|
|
185
213
|
// sketch.ts: a sheet whose middle rows rise and fall
|
|
186
214
|
const sheet = geometry.fromArrays({ positions, normals, indices });
|
|
@@ -201,11 +229,13 @@ The call follows these rules:
|
|
|
201
229
|
- `start` and `count` pick the vertices that change. By default every vertex changes. The next frame uploads only the bytes of those vertices.
|
|
202
230
|
- Values that do not fit the mesh throw [E1206](../errors/E1206.md), and so does a mesh with joints or morph targets.
|
|
203
231
|
- The first call takes away the levels of detail that the mesh planned, which measured the old shape, and the mesh plans no levels on its own again. Give a mesh whose vertices change in every frame `levels: false`, so it plans none.
|
|
204
|
-
- The call allocates nothing, so a call in every frame makes no garbage.
|
|
232
|
+
- The call allocates nothing, so a call in every frame makes no garbage. The engine's allocation benchmark checks it in every frame.
|
|
205
233
|
|
|
206
234
|
Change the normals with the positions when the shape changes, because the engine does not compute them again. The [vertex updates demo](https://github.com/null3d-engine/null3d/tree/main/examples/vertex-updates) moves rings over a pool of water this way.
|
|
207
235
|
|
|
208
|
-
The mesh keeps the bounding sphere of the vertices that it was made with. Culling tests that sphere. When the new vertices reach outside it, give each object that draws the mesh bounds that hold every shape, with [`setBounds`](objects.md#mesh-calls). Raycasts and overlap queries always test the new vertices.
|
|
236
|
+
The mesh keeps the bounding sphere of the vertices that it was made with. Culling tests that sphere. When the new vertices reach outside it, give each object that draws the mesh bounds that hold every shape, with [`setBounds`](objects.md#mesh-calls). Raycasts and overlap queries always test the new vertices.
|
|
237
|
+
|
|
238
|
+
The first query after an update builds the mesh's tree again. So a scene that updates a large mesh and raycasts in each frame pays for a build in each frame. Shadows of point and spot lights draw again when a mesh that casts them changes.
|
|
209
239
|
|
|
210
240
|
The first update of a mesh rebuilds the draw tables once, as `setMesh` does, so make it at setup or behind a loading screen. Later updates cost only the copy and the upload. On WebGL2, a mesh whose positions changed no longer hides the objects behind it from software occlusion culling. For many objects that move as wholes, use [instance batches](../concepts/instances.md) instead: they move each object with one matrix, not each vertex.
|
|
211
241
|
|
|
@@ -225,7 +255,9 @@ Meshes of one vertex format share GPU buffers, so the engine draws them with few
|
|
|
225
255
|
|
|
226
256
|
## Levels of detail
|
|
227
257
|
|
|
228
|
-
A mesh made in code plans its own levels of detail the first time the scene draws it, when it holds 4,096 triangles or more, or when its copies hold 65,536 triangles together and it holds at least 256, as a batch of pebbles does. Meshes from `geometry.fromArrays` and from the generators both plan. The plan runs on the job workers, never in a frame.
|
|
258
|
+
A mesh made in code plans its own levels of detail the first time the scene draws it, when it holds 4,096 triangles or more, or when its copies hold 65,536 triangles together and it holds at least 256, as a batch of pebbles does. Meshes from `geometry.fromArrays` and from the generators both plan. The plan runs on the job workers, never in a frame.
|
|
259
|
+
|
|
260
|
+
It uses the planner of the asset tool's `--lod`, with the same simplifier, so a mesh made in code gets the levels that the same mesh in a file gets. The mesh draws its full shape until the levels arrive, a few frames later. Then every object and instance batch that draws it picks its level:
|
|
229
261
|
|
|
230
262
|
```ts
|
|
231
263
|
// 32,768 triangles: the first draw plans about six levels, down to a few hundred triangles.
|
|
@@ -235,9 +267,33 @@ scene.createInstances(ground, 400, { material: grass });
|
|
|
235
267
|
const levels = await ground.buildLevels();
|
|
236
268
|
```
|
|
237
269
|
|
|
238
|
-
Each level about halves the triangles of the level above and keeps the largest distance between its surface and the mesh's as its error. So it switches in at once, with no fade, while that distance covers less than the `lodThreshold` setting's pixels. The governor can raise that threshold past about one and a half pixels, where the switch shows, and the level then fades. A preset's own threshold never makes it fade.
|
|
270
|
+
Each level about halves the triangles of the level above and keeps the largest distance between its surface and the mesh's as its error. So it switches in at once, with no fade, while that distance covers less than the `lodThreshold` setting's pixels. The governor can raise that threshold past about one and a half pixels, where the switch shows, and the level then fades. A preset's own threshold never makes it fade.
|
|
271
|
+
|
|
272
|
+
A level costs only its indices. The plan runs on the job workers, and the frames go on meanwhile.
|
|
239
273
|
|
|
240
|
-
|
|
274
|
+
<details>
|
|
275
|
+
<summary>Technical details: how the planner works</summary>
|
|
276
|
+
|
|
277
|
+
The levels name the mesh's own vertices: the mesh keeps its vertices and triangles in their order, and a level costs its indices alone. A mesh of more than 65,535 vertices, which the engine splits into parts, shares its vertices part by part. Only the few triangles that cross from one part to another copy their vertices.
|
|
278
|
+
|
|
279
|
+
A plan of 130,000 triangles takes about half a second of one job worker, and a plan of a million about six seconds. A large mesh spreads its work over frames, so no frame waits for it.
|
|
280
|
+
|
|
281
|
+
The engine reads one part of the mesh in each frame for the plan. It makes one level in each frame when the plan is done. It gives the scene the whole set once, so its draw tables rebuild once. The planner, about 23 KB after Brotli, downloads with the first mesh that plans.
|
|
282
|
+
|
|
283
|
+
</details>
|
|
284
|
+
|
|
285
|
+
The plan also sorts large levels into pieces, so each copy skips the pieces that lie outside the view or face away from the camera. [Pieces of a large level](../concepts/lod.md#pieces-of-a-large-level) gives the rules.
|
|
286
|
+
|
|
287
|
+
<details>
|
|
288
|
+
<summary>Technical details: how the planner builds and splits levels</summary>
|
|
289
|
+
|
|
290
|
+
The plan sorts the mesh and each level of 32,768 triangles or more into 8 to 16 pieces. A mesh that one object draws gets pieces of its own too, over a sorted copy of its indices that arrives in the frame after the last level, so the mesh keeps its triangles in their order. Copies of a large mesh draw their full mesh only near the camera, so only their levels get pieces.
|
|
291
|
+
|
|
292
|
+
A list that faces mostly one way, such as a ground, splits by space. A smaller list of 1,024 triangles or more that many copies draw gets facing pieces where its triangles face a few ways. A building's walls are such a list: they get one piece for each way, and one for the rest.
|
|
293
|
+
|
|
294
|
+
A mesh whose levels are set by hand plans such pieces of its own list too. They draw only once the scene's copies of the mesh hold 65,536 triangles together.
|
|
295
|
+
|
|
296
|
+
</details>
|
|
241
297
|
|
|
242
298
|
The `levels` option of `fromArrays` and of every generator controls the plan:
|
|
243
299
|
|
|
@@ -274,9 +330,15 @@ rock.setLevels([
|
|
|
274
330
|
]);
|
|
275
331
|
```
|
|
276
332
|
|
|
277
|
-
An `error` level draws while it covers fewer pixels than the `lodThreshold` quality setting. A `distance` level draws while the camera lies farther than that distance. A `coverage` level draws while the bounds cover less than that share of the render's height. A level given by a distance, by a coverage or by a hand-set error fades over a short band.
|
|
333
|
+
An `error` level draws while it covers fewer pixels than the `lodThreshold` quality setting. A `distance` level draws while the camera lies farther than that distance. A `coverage` level draws while the bounds cover less than that share of the render's height. A level given by a distance, by a coverage or by a hand-set error fades over a short band.
|
|
334
|
+
|
|
335
|
+
A level with a measured error switches at once, and fades once the governor raises the threshold above about one and a half pixels. A glTF file marks a measured error with the screen coverage that the asset tool writes beside it. An error alone is hand-set, and it fades. `setLevels(levels, { fade: false })` switches every level at once while the threshold stays small.
|
|
336
|
+
|
|
337
|
+
Each level must have the mesh's vertex attributes, as it draws with the same pipelines. A level may name a `material` of its own, so a far level shades more cheaply. A level without one draws with the material of the level before it. The base level draws with the object's or the instance batch's material.
|
|
278
338
|
|
|
279
|
-
|
|
339
|
+
An empty list takes the levels away, and destroying a level's mesh takes every level away. `mesh.levels` lists them as you gave them. A mesh whose bound covers fewer pixels than the threshold draws nothing: its last level holds no geometry. Wrong levels throw [E1221](../errors/E1221.md).
|
|
340
|
+
|
|
341
|
+
[Levels of detail](../concepts/lod.md) explains the three measures, the hide distance, the fading bands and the shadows. It also explains how glTF files from the asset tool bring their levels. The [forest demo](https://github.com/null3d-engine/null3d/tree/main/examples/forest) calls `setLevels` on each tree mesh, with measured errors.
|
|
280
342
|
|
|
281
343
|
A far object that draws as a card follows its own rules. A card that lights unlike its mesh reads as
|
|
282
344
|
another tree. [Impostors](impostors.md#make-a-card-read-as-its-mesh) says which mesh to bake, the
|
|
@@ -300,7 +362,14 @@ While an object or an instance batch still uses the mesh, `destroy` throws [E111
|
|
|
300
362
|
|
|
301
363
|
## Large meshes
|
|
302
364
|
|
|
303
|
-
A mesh can have any number of vertices.
|
|
365
|
+
A mesh can have any number of vertices. A mesh of more than 65,535 vertices splits into parts that draw one after another. For the fewest draw calls, keep meshes under 65,535 vertices. A mesh that draws a cluster tree is the exception. Its patches draw in one draw across all its parts, as [cluster levels](../concepts/lod.md#cluster-levels) describes.
|
|
366
|
+
|
|
367
|
+
<details>
|
|
368
|
+
<summary>Technical details: why large meshes split</summary>
|
|
369
|
+
|
|
370
|
+
The engine uses 16-bit indices, and WebGL2 always reads the largest one, 65,535, as the end of a primitive, so one draw reaches 65,535 vertices. Each part holds a copy of the vertices that it shares with the part before it.
|
|
371
|
+
|
|
372
|
+
</details>
|
|
304
373
|
|
|
305
374
|
## API reference
|
|
306
375
|
|
package/docs/api/grass.md
CHANGED
|
@@ -1,22 +1,18 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: api/grass
|
|
3
3
|
title: "Grass (@null3d/grass)"
|
|
4
|
-
|
|
5
|
-
since: "0.3"
|
|
6
|
-
summary: "createGrass: tufts of bent blades over a ground, placed by integer hashes, built in a compute pass on WebGPU with near shadows, swaying in the wind add-on's field, with a share for each quality preset."
|
|
4
|
+
summary: "createGrass: tufts of bent blades over a ground, placed by integer hashes, built in a compute pass on WebGPU with the sun's shadows, swaying in the wind add-on's field, with a share for each quality preset."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Grass (@null3d/grass)
|
|
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
|
ground["The ground's height,<br/>a mask, a seed"] --> place["Tufts placed<br/>by integer hash"]
|
|
16
12
|
place --> gpu["WebGPU: a compute pass<br/>writes the blade list"]
|
|
17
13
|
place --> batch["WebGL2: one instance<br/>batch for each shape"]
|
|
18
14
|
camera["The camera"] --> gpu
|
|
19
|
-
gpu --> draw["The blades, with<br/>
|
|
15
|
+
gpu --> draw["The blades, with<br/>the sun's shadows"]
|
|
20
16
|
batch --> draw
|
|
21
17
|
wind["The wind add-on's field"] --> draw
|
|
22
18
|
preset["The quality preset"] --> place
|
|
@@ -24,6 +20,10 @@ flowchart LR
|
|
|
24
20
|
|
|
25
21
|
`@null3d/grass` draws tufts of bent blades over a square of ground. One seed places the same tufts on every device, and the blades bend in the air of the wind add-on's field. On WebGPU a compute pass builds the blade list each frame, culls it to the view and thins the far tufts. WebGL2 draws the same rows as an instance batch. The grass casts and receives the sun's shadows on both paths.
|
|
26
22
|
|
|
23
|
+

|
|
24
|
+
|
|
25
|
+
The plants in wind demo. On feature-instances: the grass add-on places and counts its blades with a compute pass on WebGPU.
|
|
26
|
+
|
|
27
27
|
The package is built on the engine's public API. Its two shaders ship compiled, so your build does not compile them. It reads the field of `@null3d/wind`, which it lists as a peer dependency.
|
|
28
28
|
|
|
29
29
|
```sh
|
|
@@ -37,12 +37,19 @@ import { createGrass, swayDistanceFor } from '@null3d/grass';
|
|
|
37
37
|
import { createWind } from '@null3d/wind';
|
|
38
38
|
|
|
39
39
|
export default defineSketch(async (ctx) => {
|
|
40
|
-
const { scene, quality } = ctx;
|
|
40
|
+
const { scene, quality, geometry, materials } = ctx;
|
|
41
41
|
const camera = scene.createPerspectiveCamera({ position: [0, 2, 12], target: [0, 0, 0] });
|
|
42
42
|
scene.setActiveCamera(camera);
|
|
43
43
|
scene.createDirectionalLight({ direction: [-0.4, -1, -0.3], intensity: 3, castShadows: true });
|
|
44
44
|
|
|
45
|
-
const height = (
|
|
45
|
+
const height = () => 0;
|
|
46
|
+
scene.setBackground('#8fb3cf');
|
|
47
|
+
scene.createMesh({
|
|
48
|
+
mesh: geometry.plane({ width: 40, height: 40 }),
|
|
49
|
+
material: materials.standard({ color: '#4f6b2a' }),
|
|
50
|
+
rotation: [-Math.SQRT1_2, 0, 0, Math.SQRT1_2],
|
|
51
|
+
receiveShadows: true,
|
|
52
|
+
});
|
|
46
53
|
const wind = createWind(ctx, { camera, box: 128 });
|
|
47
54
|
wind.setBase(3, 0.4);
|
|
48
55
|
const grass = await createGrass(ctx, {
|
|
@@ -54,6 +61,10 @@ export default defineSketch(async (ctx) => {
|
|
|
54
61
|
camera,
|
|
55
62
|
swayDistance: swayDistanceFor(quality.preset),
|
|
56
63
|
});
|
|
64
|
+
quality.onChange(() => {
|
|
65
|
+
grass.fit(quality.preset);
|
|
66
|
+
grass.setSwayDistance(swayDistanceFor(quality.preset));
|
|
67
|
+
});
|
|
57
68
|
|
|
58
69
|
return {
|
|
59
70
|
onUpdate() {
|
|
@@ -66,13 +77,30 @@ export default defineSketch(async (ctx) => {
|
|
|
66
77
|
|
|
67
78
|
## Grass on the ground
|
|
68
79
|
|
|
69
|
-
`await createGrass(ctx,
|
|
80
|
+
`await createGrass(ctx, options)` draws tufts of bent blades over a square of ground. Await the call in the sketch's setup, because WebGPU makes its draw then. The [`GrassOptions` table](reference/grass.md#grassoptions) lists every option with its default.
|
|
81
|
+
|
|
82
|
+

|
|
83
|
+
|
|
84
|
+
Grass counts follow the preset.
|
|
85
|
+
|
|
86
|
+
The tufts stand on `height(x, z)` and skip ground steeper than `maxSlope`. They also skip ground that `mask` refuses, such as water or a footprint, and ground that `where` refuses, such as a road. A tuft grows only where both allow it.
|
|
87
|
+
|
|
88
|
+
`count` is the tufts at the High preset. Low, Medium and Ultra draw 0.35, 0.6 and 1.25 of it. `createGrass` fits the engine's starting preset, and `grass.fit(preset)` takes a new one.
|
|
89
|
+
|
|
90
|
+
<details>
|
|
91
|
+
<summary>Technical details: how the tufts are placed</summary>
|
|
92
|
+
|
|
93
|
+
Each tuft's turn and size come from integer hashes, so one seed places the same grass on every device. Each tuft's tint comes from a hash of its root's place, in the shader.
|
|
94
|
+
|
|
95
|
+
</details>
|
|
70
96
|
|
|
71
97
|
The blades bend in the wind add-on's field. Give `createGrass` its `wind` field, and call `grass.setWindLayer(field)` in each frame with the field's newest state. A page that gives no field grows grass that stands still.
|
|
72
98
|
|
|
73
99
|
## The blade shape
|
|
74
100
|
|
|
75
|
-
Without a shape, each blade narrows to a point from its root. The `blade` option gives every blade one shape. Its `widthAt(t)` is the blade's width in meters at a share `t` of its length, from 0 at the root to 1 at the tip. Its `fold` is the degrees that each half rises from the keel.
|
|
101
|
+
Without a shape, each blade narrows to a point from its root. The `blade` option gives every blade one shape. Its `widthAt(t)` is the blade's width in meters at a share `t` of its length, from 0 at the root to 1 at the tip. Its `fold` is the degrees that each half rises from the keel.
|
|
102
|
+
|
|
103
|
+
A blade with a fold draws a vertex at its keel, so its two halves light apart. Give a plant's own blade with the plant's own `color`, so the cover reads as the same grass where the plant stands.
|
|
76
104
|
|
|
77
105
|
```ts
|
|
78
106
|
const grass = await createGrass(ctx, {
|
|
@@ -89,15 +117,25 @@ const grass = await createGrass(ctx, {
|
|
|
89
117
|
|
|
90
118
|
On WebGPU and compatibility mode a compute pass builds the blade list. It writes each tuft's row and the count into a draw that the frame culls no further. The engine copies the count into the main view and every drawn shadow view.
|
|
91
119
|
|
|
92
|
-
Give the pass the drawing `camera`, and it culls the tiles outside the view and thins the far tufts. A far tuft draws the share that its root's hash picks. Its blades widen by the inverse of that share, so the hill's cover stays the same.
|
|
120
|
+
Give the pass the drawing `camera`, and it culls the tiles outside the view and thins the far tufts. A far tuft draws the share that its root's hash picks. Its blades widen by the inverse of that share, so the hill's cover stays the same.
|
|
121
|
+
|
|
122
|
+
The draw shader then culls each view to its own box, from that view's matrix. The camera's view draws its frustum. A light's view draws its cascade, whose box reaches toward the light over the casters. So a shadow view does not draw the whole kept list.
|
|
93
123
|
|
|
94
124
|
WebGL2 fills one instance batch for each tuft shape on the CPU. Its vertex shader applies the same share and the same per-view cull, so both paths draw the same hill. The rows are built for Ultra's share once. A preset change then changes only how many rows draw, not the memory. A page that drives the rows itself gives `compute: false`, which keeps the instance batch on both paths.
|
|
95
125
|
|
|
96
126
|
The tuft meshes plan no levels of detail: the wind bends their blades in the shader, and the tufts thin with distance by themselves.
|
|
97
127
|
|
|
98
|
-
##
|
|
128
|
+
## Shadows and the sway distance
|
|
129
|
+
|
|
130
|
+
The grass casts and receives the sun's shadows on both paths. Far shadow cascades draw only every few frames, unless a moving caster touches them. Swaying blades count as moving, so by default the far cascades draw in every frame ([Shadows](../concepts/shadows.md#update-rates)).
|
|
131
|
+
|
|
132
|
+

|
|
133
|
+
|
|
134
|
+
Near grass shadows.
|
|
135
|
+
|
|
136
|
+
Give the grass a `swayDistance` to stop the blades past that distance. Then a far cascade that only the grass reaches keeps its turns. The default, 0, sways at every distance. Call `grass.setSwayDistance(distance)` when the preset changes.
|
|
99
137
|
|
|
100
|
-
|
|
138
|
+
`swayDistanceFor(preset)` gives each preset's distance from `PLANT_SWAY_DISTANCE`: 8, 16, 24 and 32 meters from Low to Ultra. Give a swaying plant's material the same distance, so plants and grass stop at one line. The ground's own color and the blades' root colors should meet at the hill's foot.
|
|
101
139
|
|
|
102
140
|
## The placement hash
|
|
103
141
|
|
|
@@ -111,4 +149,8 @@ The grass casts and receives the sun's shadows on both paths. Give it a `swayDis
|
|
|
111
149
|
|
|
112
150
|
- [Wind](wind.md): the field of air that the blades bend in.
|
|
113
151
|
- [Add-on instance draws](feature-instances.md): the draw whose count the blade list writes.
|
|
152
|
+
- [Shadows](../concepts/shadows.md#update-rates): how the far cascades keep their layers.
|
|
114
153
|
- [Quality API](quality.md): the preset and the frame-budget governor.
|
|
154
|
+
- [Grass in the wind](https://github.com/null3d-engine/null3d/tree/main/examples/vegetation-wind): a grove whose grass and plants sway in the wind field.
|
|
155
|
+
- [Grass in a scene](https://github.com/null3d-engine/null3d/tree/main/examples/contact-shadows): tufts of grass that cast contact shadows in a stone garden.
|
|
156
|
+
- [Grass at scale](https://github.com/null3d-engine/null3d/tree/main/examples/showcase/island): the island sets `compute: false`, so its grass draws as an instance batch on both paths.
|