@null3d/engine 0.1.0 → 0.1.2
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 +40 -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 +68 -24
- 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/E1308.md +31 -0
- 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 +53 -29
- package/docs/getting-started/cdn.md +15 -9
- package/docs/getting-started/first-scene.md +20 -12
- package/docs/getting-started/hosting.md +113 -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 +13 -14
- package/docs/guides/assets-pipeline.md +294 -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 +86 -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 +10 -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 +74 -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 +126 -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 +116 -105
- package/lib/errors/engine-error.js +1 -1
- package/lib/errors/fixes.d.ts +1 -0
- package/lib/errors/fixes.js +19 -18
- package/lib/generated/shader-permutations.d.ts +6 -0
- package/lib/generated/shader-permutations.js +6 -0
- 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 +29 -7
- package/lib/page/engine.js +79 -7
- 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 +8 -0
- package/lib/shared/permutation-words.js +14 -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/tier.d.ts +9 -0
- package/lib/shared/tier.js +4 -1
- 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/post.md
CHANGED
|
@@ -1,17 +1,28 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: api/post
|
|
3
3
|
title: Post-processing API
|
|
4
|
-
status: experimental
|
|
5
|
-
since: "0.1"
|
|
6
4
|
summary: "post.set for tone mapping, exposure and a camera's EV100, automatic exposure, bloom, ambient occlusion, screen-space reflections, depth of field, outlines, color grading tables and controls, the vignette and sharpening; custom effects with post.addEffect, custom tone curves, and still views."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Post-processing API
|
|
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
|
`ctx.post` holds the settings that the engine applies to the scene's color on its way to the canvas. They are the tone mapping, the exposure, automatic exposure, bloom, ambient occlusion, screen-space reflections, depth of field, outlines, a color grading table, the vignette, the sharpening and the sketch's own effects. [Color management](../concepts/color-management.md) explains how the first two fit into the frame. [The post-processing chain](../concepts/post-processing.md) explains how bloom, ambient occlusion, screen-space reflections, depth of field and sharpening do.
|
|
14
10
|
|
|
11
|
+
Every effect is off until `post.set` turns it on. The tone mapping (AgX punchy) and an exposure of 1 always apply.
|
|
12
|
+
|
|
13
|
+
| Effect | `post.set` key | [Quality setting that turns it off](../concepts/quality-presets.md) | [Without HDR color](../concepts/post-processing.md#effects-on-devices-without-hdr-color) |
|
|
14
|
+
| --- | --- | --- | --- |
|
|
15
|
+
| Automatic exposure | `autoExposure` | None (`exposureMeter` picks the meter) | Stays off |
|
|
16
|
+
| Bloom | `bloom` | None (`bloomSize` sets the detail) | Stays off |
|
|
17
|
+
| Ambient occlusion | `ao` | `aoScale` 0: Low, Medium | Stays off with no float targets |
|
|
18
|
+
| Screen-space reflections | `ssr` | `ssrScale` 0: Low | Stays off with no float targets |
|
|
19
|
+
| Depth of field | `dof` | `dofSamples` 0: Low | Stays off |
|
|
20
|
+
| Outlines | `outline` | None | Draws |
|
|
21
|
+
| Color grading | `lut`, `grading` | None | Draws |
|
|
22
|
+
| Vignette | `vignette` | None | Draws |
|
|
23
|
+
| Sharpening | `sharpen` | None (adds nothing below a render scale of 1) | Draws |
|
|
24
|
+
| Custom effects and tone curves | `post.addEffect`, `toneMapping` | None | Stay off |
|
|
25
|
+
|
|
15
26
|
## Tone mapping and exposure
|
|
16
27
|
|
|
17
28
|
```ts
|
|
@@ -38,7 +49,16 @@ export default defineSketch(({ post }) => {
|
|
|
38
49
|
|
|
39
50
|
## Lights in real units
|
|
40
51
|
|
|
41
|
-
Most scenes need no camera setting: their lights have small intensities, such as a sun of 3, and the exposure stays at 1. Lights in real units, such as a sun of 100,000 lux, need `ev100`: the exposure value of a camera at ISO 100. The units are on the [Lights](lights.md#color-intensity-and-units) page. Typical values are 15 for a sunny day, 12 for an overcast day and 7 for a lit room. Each step up is one stop darker.
|
|
52
|
+
Most scenes need no camera setting: their lights have small intensities, such as a sun of 3, and the exposure stays at 1. Lights in real units, such as a sun of 100,000 lux, need `ev100`: the exposure value of a camera at ISO 100. The units are on the [Lights](lights.md#color-intensity-and-units) page. Typical values are 15 for a sunny day, 12 for an overcast day and 7 for a lit room. Each step up is one stop darker.
|
|
53
|
+
|
|
54
|
+
The `exposure` setting then scales that, as exposure compensation does. Setting `ev100: false` turns the camera off again.
|
|
55
|
+
|
|
56
|
+
<details>
|
|
57
|
+
<summary>Technical details: the exposure formula</summary>
|
|
58
|
+
|
|
59
|
+
The engine scales the scene by 1 / (1.2 × 2^ev100), the formula of Filament, Bevy and Unity's HDRP. [Lighting and environment](../concepts/lighting.md) covers the units in full.
|
|
60
|
+
|
|
61
|
+
</details>
|
|
42
62
|
|
|
43
63
|
```ts
|
|
44
64
|
import { defineSketch } from '@null3d/engine';
|
|
@@ -51,11 +71,21 @@ export default defineSketch(({ scene, post }) => {
|
|
|
51
71
|
});
|
|
52
72
|
```
|
|
53
73
|
|
|
54
|
-
|
|
74
|
+
Background and unlit colors take the exposure too. At EV100 15 they draw black unless their own values are in real units.
|
|
75
|
+
|
|
76
|
+
<details>
|
|
77
|
+
<summary>Technical details: where the engine applies the exposure</summary>
|
|
55
78
|
|
|
56
|
-
|
|
79
|
+
The engine multiplies the exposure into each light, the environment's light, the background color and the fog color. The shaders multiply it into emissive light and unlit colors. The tone mapping then works on values near 1, even with a sun of 100,000 lux. Otherwise its highlights would pass the largest value of the 16-bit float scene color. The picture is the one that an exposure at the end gives.
|
|
57
80
|
|
|
58
|
-
|
|
81
|
+
</details>
|
|
82
|
+
|
|
83
|
+
## Changing settings during play
|
|
84
|
+
|
|
85
|
+
`post.set` allocates nothing, so a sketch can change settings every frame. Keep one settings object and change its field, so your own code allocates nothing either.
|
|
86
|
+
|
|
87
|
+
- A setting that a call leaves out keeps its value, also while its effect is off. `post.set({ effect: {} })` turns an effect on with the values it had.
|
|
88
|
+
- Turning an effect on or off can cost more. Each effect's section says how much.
|
|
59
89
|
|
|
60
90
|
```ts
|
|
61
91
|
export default defineSketch(({ post, time }) => {
|
|
@@ -106,11 +136,9 @@ export default defineSketch(({ scene, geometry, materials, post }) => {
|
|
|
106
136
|
- The scene draws at the camera's exposure, the `exposure` and `ev100` settings, and the eye adapts from there. A brightness of 0 stops is a scene that the camera's exposure shows as middle gray. With `ev100: 15`, `minEv: -8` lets the eye adapt down to a scene of about EV100 7.
|
|
107
137
|
- Within one stop of its target, the eye slows down, so it settles smoothly. Eyes adapt to the dark more slowly than to the light, so `speedDown` is lower by default.
|
|
108
138
|
- The first frame that meters takes its target at once, so a scene starts adapted. Hold mode draws one frame, so its image is the adapted image, the same in every run.
|
|
109
|
-
- The final pass multiplies the scene's color,
|
|
139
|
+
- The final pass multiplies the color it reads by the adapted exposure: the scene's color, with the result of any custom effects, and bloom's glow. It does this before FXAA, the vignette and the tone curve. Custom effects and depth of field read the color at the camera's exposure. This is also true when the engine joins an effect into the final pass. Bloom's `threshold` keeps its meaning in the scene's units.
|
|
110
140
|
- The quality setting `exposureMeter` picks the meter. `'histogram'` bins a grid of samples in compute shaders on WebGPU, on Medium and above. `'downsample'` averages 16 x 16 cells of the image, on Low and on WebGL2. Both take the same settings.
|
|
111
141
|
- It needs HDR color, as bloom does. In WebGPU's compatibility mode with MSAA, turning it on moves the engine to HDR color with FXAA. On a device with no HDR target it stays off, and development builds warn once.
|
|
112
|
-
- A setting that a call leaves out keeps its value, also while it is off. `post.set({ autoExposure: {} })` turns it on with the values it had.
|
|
113
|
-
- `post.set` allocates nothing, and a meter costs nothing while it is off. Its shaders download the first time it turns on.
|
|
114
142
|
|
|
115
143
|
## Bloom
|
|
116
144
|
|
|
@@ -325,15 +353,11 @@ export default defineSketch(async ({ assets, post }) => {
|
|
|
325
353
|
- The table grades each pixel after the tone mapping and the sRGB encoding. Tables made for sRGB display color, as most are, look as their authors made them.
|
|
326
354
|
- The final pass reads the table with a linear filter between its texel centers. It maps the colors of a `.cube` file's domain onto the table.
|
|
327
355
|
- The table grades the picture from the first frame after its texels reach the GPU, usually the next one.
|
|
328
|
-
- `lutIntensity` keeps its value while the table is off
|
|
356
|
+
- `lutIntensity` keeps its value while the table is off.
|
|
329
357
|
|
|
330
358
|
### Grading controls
|
|
331
359
|
|
|
332
|
-
The grading controls set a look from a few numbers, without a table file. A job worker bakes them
|
|
333
|
-
into a table of its own. The final pass applies that table to the display color that the tone curve
|
|
334
|
-
leaves, before a `lut`. A change stalls no frame. The picture shows the new grade once the
|
|
335
|
-
worker's bake reaches the GPU, usually within a few frames. The frame that lands a bake uploads the
|
|
336
|
-
table, 256 KB.
|
|
360
|
+
The grading controls set a look from a few numbers, without a table file. A [job worker](../concepts/architecture.md#the-kinds-of-thread) bakes them into a table of its own, so a change stalls no frame. The final pass applies that table to the display color that the tone curve leaves. The picture shows the new grade once the bake reaches the GPU, usually within a few frames.
|
|
337
361
|
|
|
338
362
|
```ts
|
|
339
363
|
post.set({
|
|
@@ -366,11 +390,20 @@ post.set({
|
|
|
366
390
|
- White balance corrects the light of the given temperature to the neutral white of daylight at 6500 kelvin. It keeps the picture's brightness.
|
|
367
391
|
- The table holds 32 texels along each side. The final pass takes the square root of the color before it reads the table. Its texels therefore lie closer together toward black, where a grade's curve is steepest.
|
|
368
392
|
- The table holds the grade alone, and the tone curve stays a calculation in the pass. A custom tone curve therefore still works with the controls.
|
|
393
|
+
|
|
394
|
+
The [Creek showcase](https://github.com/null3d-engine/null3d/tree/main/examples/showcase/creek) sets its own WGSL tone curve in the scene's look.
|
|
369
395
|
- The final pass applies the built-in grade first and a `lut` after it, so a look from a file can sit over a grade from the controls.
|
|
370
396
|
- The final pass draws on every GPU path, with HDR color or without it, so both paths grade alike.
|
|
371
|
-
- The bake runs in a job worker, so a value that changes in a frame loop does not stall the frames.
|
|
397
|
+
- The bake runs in a job worker, so a value that changes in a frame loop does not stall the frames. Where no worker can run tasks, the picture keeps its colors and development builds warn once.
|
|
372
398
|
- The values are designed for the null3D grading controls. To match a grade that a colorist made in another tool, load its `.cube` file instead.
|
|
373
399
|
|
|
400
|
+
<details>
|
|
401
|
+
<summary>Technical details: the grading table</summary>
|
|
402
|
+
|
|
403
|
+
Each table costs the final pass a few operations per pixel and one texture read. On a device that resolves its multisampled picture straight into the canvas, the table makes the final pass run, which reads the picture once more. The frame that lands a bake uploads the table, 256 KB.
|
|
404
|
+
|
|
405
|
+
</details>
|
|
406
|
+
|
|
374
407
|
## Vignette
|
|
375
408
|
|
|
376
409
|
The vignette darkens the picture toward its edges:
|
|
@@ -389,9 +422,8 @@ post.set({ vignette: { intensity: 0.8, size: 1.2 } });
|
|
|
389
422
|
|
|
390
423
|
- The vignette multiplies each pixel's light before the tone mapping. [The post-processing chain](../concepts/post-processing.md#color-grading-and-the-vignette) gives the rule and the engines it follows.
|
|
391
424
|
- At a distance `d` from the center, in canvas widths and heights times `size`, the light is multiplied by `1 - intensity × (1 - (1 - d²)^falloff)`, and never by less than 0.
|
|
392
|
-
- A setting that a call leaves out keeps its value, also while the vignette is off. `post.set({ vignette: {} })` turns it on with the values it had.
|
|
393
425
|
|
|
394
|
-
Grading and the vignette draw on every GPU path, with HDR color or without it. Without HDR color, the scene's shaders darken their light
|
|
426
|
+
Grading and the vignette draw on every GPU path, with HDR color or without it. Without HDR color, the vignette still draws: the scene's shaders darken their light before their tone mapping, and a plain background color darkens too.
|
|
395
427
|
|
|
396
428
|
The final pass dithers last, after the table and the vignette. It adds noise of up to one step of the 8-bit canvas, so smooth gradients show no bands. The noise is the same in every frame.
|
|
397
429
|
|
|
@@ -412,7 +444,7 @@ post.set({ sharpen: 0.5 });
|
|
|
412
444
|
- It draws at the whole canvas's render scale. A render scale below 1 sharpens its own upscale, so the value adds nothing there ([quality presets](../concepts/quality-presets.md#dynamic-resolution)).
|
|
413
445
|
- While it is on, the frame draws in two steps at the whole render scale. The first step tone maps the scene into an 8-bit target, and the second sharpens that display color. A sketch whose render scale can drop already keeps that target, so sharpening adds no memory there. One that holds the render scale at 1 keeps a target of the canvas's size while sharpening is on.
|
|
414
446
|
- While it is on, a still view keeps drawing instead of blending its frames and resting, because the sharpening draws in the moving frame's second step. [The post-processing chain](../concepts/post-processing.md#still-camera-accumulation) says what a still view does.
|
|
415
|
-
-
|
|
447
|
+
- `post.set({ sharpen: false })` turns it off, and 0 does the same.
|
|
416
448
|
|
|
417
449
|
## Custom effects
|
|
418
450
|
|
|
@@ -463,13 +495,13 @@ post.set({ toneMapping: reinhard });
|
|
|
463
495
|
|
|
464
496
|
## Still views
|
|
465
497
|
|
|
466
|
-
A view that holds still blends its frames into a sharper picture, then stops drawing until something changes. It needs no setting: `post.set` turns nothing on for it. Bloom, outlines
|
|
498
|
+
A view that holds still blends its frames into a sharper picture, then stops drawing until something changes. It needs no setting: `post.set` turns nothing on for it. Bloom, outlines, automatic exposure, screen-space reflections, sharpening and custom effects keep a view drawing every frame. [The post-processing chain](../concepts/post-processing.md#still-camera-accumulation) lists every feature that does. `createEngine({ still: false })` and the page switch `?still-camera=off` turn it off.
|
|
467
499
|
|
|
468
500
|
## Errors
|
|
469
501
|
|
|
470
502
|
| Code | Cause |
|
|
471
503
|
| --- | --- |
|
|
472
|
-
| [E1213](../errors/E1213.md) | A ninth effect
|
|
504
|
+
| [E1213](../errors/E1213.md) | A ninth effect, because at most 8 run at once. A setting that this version does not have, or a value that a setting does not take, such as a tone mapping that the engine does not know or a number outside its range. Each section's settings table gives the values that a setting takes. |
|
|
473
505
|
| [E1203](../errors/E1203.md) | A value that is not a finite number, such as NaN, or an effect's `order` that is not one. |
|
|
474
506
|
| [E1204](../errors/E1204.md) | An outline color that is not a hex string, a hex number or three linear components from 0 to 1. |
|
|
475
507
|
| [E1215](../errors/E1215.md) | An effect or a tone curve as WGSL that the null3D Vite plugin did not compile, or compiled WGSL of another kind. |
|
|
@@ -488,6 +520,8 @@ A view that holds still blends its frames into a sharper picture, then stops dra
|
|
|
488
520
|
- [Assets](assets.md): `assets.loadLut`, which loads color grading tables, and `assets.lutFromData`, which makes them from numbers.
|
|
489
521
|
- [The post effects demo](https://github.com/null3d-engine/null3d/tree/main/examples/post-effects): bloom, ambient occlusion, an outline, a vignette, sharpening and color grading tables in one scene. It makes its warm and cool tables from lift, gamma and gain in code.
|
|
490
522
|
- [The depth of field demo](https://github.com/null3d-engine/null3d/tree/main/examples/camera-lens): the focus racks across a chess board with `focusPoint`, while a dolly zoom changes the camera's focal length in every frame.
|
|
523
|
+
- [The automatic exposure demo](https://github.com/null3d-engine/null3d/tree/main/examples/auto-exposure): a walk from a sunny courtyard into a dark hall, where the eye opens and closes.
|
|
524
|
+
- [The screen-space reflections demo](https://github.com/null3d-engine/null3d/tree/main/examples/wet-street): puddles that mirror lit windows, neon signs and a passing taxi.
|
|
491
525
|
|
|
492
526
|
## API reference
|
|
493
527
|
|
package/docs/api/quality.md
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: api/quality
|
|
3
3
|
title: Quality API
|
|
4
|
-
status: experimental
|
|
5
|
-
since: "0.1"
|
|
6
4
|
summary: "quality.preset, quality.set, quality.setPreset, the preset check, the frame-budget governor, budgets for a sketch's own systems, quality events."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Quality API
|
|
10
8
|
|
|
11
|
-
>
|
|
9
|
+
> `quality.set` takes every setting that changes during play, as [Changing settings during play](#changing-settings-during-play) says. The others stay fixed while the engine runs.
|
|
12
10
|
|
|
13
|
-
`ctx.quality` gives a sketch the quality preset that the engine runs and its settings. The sketch can change the settings that change during play, switch to another preset, and hear when either changes. [Quality presets](../concepts/quality-presets.md) explains how the engine chooses and checks the preset, and lists each preset's values.
|
|
11
|
+
`ctx.quality` gives a sketch the quality preset that the engine runs and its settings. The sketch can change the settings that change during play, switch to another preset, and hear when either changes ([Quality events](#quality-events)). [Quality presets](../concepts/quality-presets.md) explains how the engine chooses and checks the preset, and lists each preset's values.
|
|
14
12
|
|
|
15
13
|
```ts
|
|
16
14
|
import { defineSketch } from '@null3d/engine';
|
|
@@ -46,12 +44,12 @@ console.log(engine.mode.presetCheck); // { from: 'high', targetFps: 60, rounds:
|
|
|
46
44
|
| `presetCheck: 'during-play'` or `'before-play'` | When the preset check measures: in the first frames of play, the default, or before play, with `createEngine` waiting for it: [The preset check](../concepts/quality-presets.md#the-preset-check). |
|
|
47
45
|
| `targetFps: 'display'` or a whole number | The frame rate that the preset check and the governor defend. Without it, the display's refresh rate, at most 60. `'display'` defends the display's full rate, and a number caps the target at that rate: [The target frame rate](../concepts/quality-presets.md#the-target-frame-rate). |
|
|
48
46
|
| `maxPixelRatio` | Replaces the preset's pixel ratio cap. |
|
|
49
|
-
| `antialias: 'msaa'`, `'fxaa'` or `'none'` | Replaces the preset's anti-aliasing mode. |
|
|
50
|
-
| `shadowCascades`, `shadowMapSize`, `shadowTiles`, `shadowTileSize`, `heroTileSize`, `pointLightShadows`, `momentTransparency`, `gpuOcclusion`, `morphTargets` | Replace the preset's values of these settings, which stay fixed while the engine runs. |
|
|
47
|
+
| `antialias: 'msaa'`, `'fxaa'` or `'none'` | Replaces the preset's anti-aliasing mode: [GPU tiers and backends](../concepts/backends.md#color-and-anti-aliasing-on-each-tier). |
|
|
48
|
+
| `shadowCascades`, `shadowMapSize`, `shadowTiles`, `shadowTileSize`, `heroTileSize`, `pointLightShadows`, `momentTransparency`, `gpuOcclusion`, `morphTargets` | Replace the preset's values of these settings, which stay fixed while the engine runs. [Quality presets](../concepts/quality-presets.md#moment-transparency) explains `momentTransparency` and its `?moments=` switch. |
|
|
51
49
|
| `depthPrepass`, `cloudSteps`, `softwareOcclusion`, `textureMemoryMiB` | Replace the preset's values of these settings. A sketch can change them during play. |
|
|
52
50
|
| `memory: { maximumMiB }` | Replaces the preset's memory maximum: [Page API](engine.md#memory). |
|
|
53
|
-
| `?preset=low` to `?preset=ultra` | Fixes the preset for tests. It wins over the option, and the
|
|
54
|
-
| `?tier=lowest` | Starts in the lowest quality tier
|
|
51
|
+
| `?preset=low` to `?preset=ultra` | Fixes the preset for tests. It wins over the option, skips the preset check and starts outside the lowest tier. A crashed start still lowers the preset by one. |
|
|
52
|
+
| `?tier=lowest` | Starts in the [lowest quality tier](../concepts/quality-presets.md#the-lowest-quality-tier), for tests and weak devices. |
|
|
55
53
|
| `?tier=off` | Keeps the governor out of the lowest quality tier, so a test reads the presets' own settings and looks on a slow machine. |
|
|
56
54
|
| `?target-fps=display` or `?target-fps=90` | Sets the target frame rate. It wins over the `targetFps` option. |
|
|
57
55
|
| `?preset-check=during-play` or `?preset-check=before-play` | Sets when the preset check measures. It wins over the `presetCheck` option. |
|
|
@@ -62,17 +60,24 @@ console.log(engine.mode.presetCheck); // { from: 'high', targetFps: 60, rounds:
|
|
|
62
60
|
|
|
63
61
|
Most settings change during play. The preset tables' "Changes" column names the ones that stay fixed from the start, which the page's `createEngine` options set.
|
|
64
62
|
|
|
65
|
-
|
|
63
|
+
## Changing settings during play
|
|
66
64
|
|
|
67
|
-
`
|
|
65
|
+
`quality.set(settings)` changes the settings it gets and keeps the others. It takes the settings that change during play, applies them from the next frame on, and returns a promise that resolves at once. Another setting, or a value outside the setting's range, throws [E1213](../errors/E1213.md) and changes nothing. E1213 is also thrown for a `minRenderScale` above `maxRenderScale`, for a `createEngine` option with a value that its setting does not take, and for a preset name that `createEngine` does not know. [Quality presets](../concepts/quality-presets.md#moment-transparency) describes the moment transparency layer and the surfaces that it draws.
|
|
68
66
|
|
|
69
|
-
|
|
67
|
+
<details>
|
|
68
|
+
<summary>Technical details: other calls that throw, and the render scale's range</summary>
|
|
70
69
|
|
|
71
|
-
|
|
70
|
+
To move both ends of the render scale's range past each other, give both in one call. In the [lowest quality tier](../concepts/quality-presets.md#the-lowest-quality-tier), a `minRenderScale` above the tier's cap on the scale raises the cap to it instead. Only a `maxRenderScale` that the sketch set itself throws.
|
|
71
|
+
|
|
72
|
+
</details>
|
|
72
73
|
|
|
73
74
|
## Switching presets
|
|
74
75
|
|
|
75
|
-
`quality.setPreset(preset)` switches to another preset at a point that the sketch picks, such as a menu or a loading screen. Every setting that changes during play takes the new preset's value, apart from those that the page's options give. The values that `set` gave end with the switch too. The settings fixed at the start, such as `antialias`, keep their values.
|
|
76
|
+
`quality.setPreset(preset)` switches to another preset at a point that the sketch picks, such as a menu or a loading screen. Every setting that changes during play takes the new preset's value, apart from those that the page's options give. The values that `set` gave end with the switch too. The settings fixed at the start, such as `antialias`, keep their values.
|
|
77
|
+
|
|
78
|
+
The preset check is different: when it lowers the preset after the setup, the settings that the setup changed with `set` keep their values.
|
|
79
|
+
|
|
80
|
+
The GPU path caps the preset: `setPreset('ultra')` on WebGL2 runs Medium. `quality.highest` names that cap, so a menu shows the presets above it as unavailable.
|
|
76
81
|
|
|
77
82
|
```ts
|
|
78
83
|
export default defineSketch(({ quality, page }) => {
|
|
@@ -99,7 +104,16 @@ console.log(quality.renderScale); // 0.75
|
|
|
99
104
|
|
|
100
105
|
## The frame-budget governor
|
|
101
106
|
|
|
102
|
-
When frames take too long, the engine lowers
|
|
107
|
+
When frames take too long, the engine lowers the sketch's budgets and the render scale first, then detail, shadow and effect settings, one step at a time. It raises them again once frames have time to spare. When frames still miss at the lowest render scale, it enters the [lowest quality tier](../concepts/quality-presets.md#the-lowest-quality-tier). [Quality presets](../concepts/quality-presets.md#the-frame-budget-governor) lists every step in order.
|
|
108
|
+
|
|
109
|
+
`quality.settings` keeps the values that the preset and the sketch gave. `quality.governor` reports what the engine draws with now. [`QualityGovernor`](reference/quality.md#qualitygovernor) lists each of its members with the step that changes it.
|
|
110
|
+
|
|
111
|
+
<details>
|
|
112
|
+
<summary>Technical details: the order of the steps</summary>
|
|
113
|
+
|
|
114
|
+
After the budgets and the render scale, the governor lowers the levels of detail, the live shadow settings, bloom's size, ambient occlusion's scale and the scale of screen-space reflections. It then lowers the steps of contact shadows, the far characters' update interval and the slices of volumetric fog.
|
|
115
|
+
|
|
116
|
+
</details>
|
|
103
117
|
|
|
104
118
|
The `quality.onChange` handlers run after each of these steps. So a sketch can lighten its own work with the engine's:
|
|
105
119
|
|
|
@@ -174,7 +188,7 @@ Each budget step adds a step before a step of the render scale. So with budgets,
|
|
|
174
188
|
|
|
175
189
|
## Texture memory
|
|
176
190
|
|
|
177
|
-
The `quality.textureMemory` object reports the GPU memory of textures against
|
|
191
|
+
The `quality.textureMemory` object reports the GPU memory of textures against the `textureMemoryMiB` budget, and how many mip levels the engine dropped to stay under it. [`TextureMemory`](reference/quality.md#texturememory) lists its fields, and each texture's own `droppedLevels` gives its count. [Quality presets](../concepts/quality-presets.md#texture-memory) explains which levels drop and how they come back.
|
|
178
192
|
|
|
179
193
|
```ts
|
|
180
194
|
quality.onChange(({ textureMemory }) => {
|
|
@@ -187,7 +201,13 @@ Some textures never drop levels: those that the sketch made from images or data,
|
|
|
187
201
|
|
|
188
202
|
## Quality events
|
|
189
203
|
|
|
190
|
-
`quality.onChange(handler)`
|
|
204
|
+
`quality.onChange(handler)` returns a function that removes the handler. The engine calls the handler:
|
|
205
|
+
|
|
206
|
+
- At the start of the first frame after `quality.set` or `quality.setPreset` changes the settings or the preset. After a preset change, that frame waits for its pipelines, so objects that the handler makes for the new preset appear with it.
|
|
207
|
+
- After each step of [the frame-budget governor](#the-frame-budget-governor), apart from a step of the render scale.
|
|
208
|
+
- After the [texture memory](#texture-memory) budget drops mip levels or asks for them again.
|
|
209
|
+
|
|
210
|
+
A step of the [budgets](#budgets-for-the-sketchs-own-systems) calls their `onScale` functions, not these handlers. Keep handlers cheap: they run when quality changes, not every frame.
|
|
191
211
|
|
|
192
212
|
## Related pages
|
|
193
213
|
|
package/docs/api/raycast.md
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: api/raycast
|
|
3
3
|
title: Raycasting and spatial queries
|
|
4
|
-
status: experimental
|
|
5
|
-
since: "0.2"
|
|
6
4
|
summary: "raycast, raycastAny, raycastAll, raycastBatch, overlap queries, pointer events on objects."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Raycasting and spatial queries
|
|
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. Queries test a skinned character in its bind pose, not in its animated pose. Pixel-exact picking draws each character as it is posed.
|
|
12
|
-
|
|
13
9
|
```mermaid
|
|
14
10
|
flowchart LR
|
|
15
11
|
query["A ray, a sphere<br/>or a box"] --> scene["The scene's trees:<br/>static and dynamic objects"]
|
|
@@ -20,7 +16,7 @@ flowchart LR
|
|
|
20
16
|
|
|
21
17
|
A raycast finds where a ray meets the scene's objects. An overlap query finds the objects inside a sphere or a box. Every query tests the triangles of objects and instance rows. Raycasts also hit [sprites, points and lines](#sprites-points-and-lines) where they draw. The engine keeps a tree over the scene's objects and a tree over each mesh's triangles. So a query tests only the few triangles near it.
|
|
22
18
|
|
|
23
|
-
Queries run in the sketch, on the scene. They write their results into objects and arrays that you create once, so a query in every frame allocates nothing.
|
|
19
|
+
Queries run in the sketch, on the scene. They write their results into objects and arrays that you create once, so a query in every frame allocates nothing. The engine's allocation benchmark checks it in every frame. The [picking demo](https://github.com/null3d-engine/null3d/tree/main/examples/picking) casts rays from the pointer, and its `object.on` events report the hit point.
|
|
24
20
|
|
|
25
21
|
```ts
|
|
26
22
|
import { defineSketch, type RaycastHit, vec3 } from '@null3d/engine';
|
|
@@ -103,7 +99,9 @@ in-world screen turns a click into a pixel of its image.
|
|
|
103
99
|
|
|
104
100
|
## Rays from the pointer
|
|
105
101
|
|
|
106
|
-
For clicks and hover on objects, `object.on('click', handler)` casts the ray itself. [Pointer events on objects](input.md#pointer-events-on-objects) describes it.
|
|
102
|
+
For clicks and hover on objects, `object.on('click', handler)` casts the ray itself. [Pointer events on objects](input.md#pointer-events-on-objects) describes it.
|
|
103
|
+
|
|
104
|
+
For a ray of your own, such as one that tests only some layers, `camera.screenToRay(x, y, ray)` writes the ray through a point on the canvas. Pass `input.pointer.x` and `input.pointer.y`, and the ray comes from the frame that was on screen at the pointer's event. Over a view from `scene.createView`, cast the ray with `view.screenToRay` instead, and `scene.viewAt(x, y)` finds that view ([Multiple views](../guides/multiple-views.md#picking-in-a-view)).
|
|
107
105
|
|
|
108
106
|
```ts
|
|
109
107
|
const ray = { origin: vec3.create(), direction: vec3.create() }; // made once
|
|
@@ -116,7 +114,9 @@ if (input.wasPressed('Mouse0')) {
|
|
|
116
114
|
|
|
117
115
|
## Batches of rays
|
|
118
116
|
|
|
119
|
-
The call `scene.raycastBatch(rays, options, out)` casts many rays at once, on the job workers. Its `rays` array holds six numbers per ray: its origin, then its direction. Its `out` object holds typed arrays with one entry per ray, or three numbers per ray for points and normals.
|
|
117
|
+
The call `scene.raycastBatch(rays, options, out)` casts many rays at once, on the job workers. Its `rays` array holds six numbers per ray: its origin, then its direction. Its `out` object holds typed arrays with one entry per ray, or three numbers per ray for points and normals.
|
|
118
|
+
|
|
119
|
+
Only `distances` is required, and the call fills each other array that you give. It returns how many rays hit something.
|
|
120
120
|
|
|
121
121
|
```ts
|
|
122
122
|
const COUNT = 1000;
|
|
@@ -146,26 +146,48 @@ scene.pick(240, 180).then((hit) => {
|
|
|
146
146
|
});
|
|
147
147
|
```
|
|
148
148
|
|
|
149
|
-
|
|
149
|
+
The pick draws each object's id into a small image around the point, then reads the id back. So a pick is exact to the pixel only when every source in the scene can draw into that image.
|
|
150
150
|
|
|
151
|
-
|
|
151
|
+
One sprite, point or line in the scene, one material that blends, uses `transmission` or uses `alphaMode: 'hash'`, or one custom material that masks or has no vertex offset, makes every pick a raycast. That raycast tests triangles: it ignores masks, tests skinned characters in their bind pose, and uses the camera of the frame that last ran. In [hold mode](../guides/testing.md), which runs no frame loop, a pick is a raycast too.
|
|
152
152
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
The point is tested at the pixel that the camera draws, not at a projected triangle. A surface thinner than a pixel picks where its pixels are. An engine material with `alphaMode: 'mask'` picks by its mask. So a ray through a cut-out hole finds what lies behind the hole. The frame that records the pick draws it, so the camera of that frame answers. A camera that moves meanwhile can differ from the frame that the click saw.
|
|
156
|
-
|
|
157
|
-
A pick finds these sources:
|
|
153
|
+
### What a pick finds
|
|
158
154
|
|
|
159
155
|
- Meshes of the engine's materials, on the camera's layers, where they draw opaque.
|
|
160
156
|
- Custom materials with a vertex offset, whose pick builds move each vertex as the surface draws.
|
|
161
157
|
- Each row of an instance batch, named by `object` and `instance`.
|
|
162
158
|
- Skinned and morphed characters, as their last frame's pose places them.
|
|
163
159
|
|
|
164
|
-
|
|
160
|
+
### Texture coordinates
|
|
161
|
+
|
|
162
|
+
A hit carries `uv` and `hasUv`, as a raycast's hit does. `uv` holds where on the surface the pixel landed, in the mesh's first texture coordinates. It blends them across the hit triangle's three corners. `hasUv` says whether the surface has such coordinates. Read `hasUv` first: `uv` holds nothing to read when it is false.
|
|
163
|
+
|
|
164
|
+
The coordinates stay the mesh's own. A repeated texture reports values past 1, and a material's `uvTransform` does not move them.
|
|
165
|
+
|
|
166
|
+
<details>
|
|
167
|
+
<summary>Technical details: how a pick finds its texture coordinates</summary>
|
|
168
|
+
|
|
169
|
+
A ray through the same point finds them, from the camera of the frame that recorded the pick. So a pick and a raycast on one point give one answer. A ray that names another object than the pixel did leaves `hasUv` false. The pick then keeps the object that the pixel showed.
|
|
165
170
|
|
|
166
|
-
|
|
171
|
+
</details>
|
|
167
172
|
|
|
168
|
-
|
|
173
|
+
The point is tested at the pixel that the camera draws, not at a projected triangle. A surface thinner than a pixel picks where its pixels are. An engine material with `alphaMode: 'mask'` picks by its mask. So a ray through a cut-out hole finds what lies behind the hole. The frame that records the pick draws it, so the camera of that frame answers. A camera that moves meanwhile can differ from the frame that the click saw.
|
|
174
|
+
|
|
175
|
+
A skinned or morphed character draws a different shape than the mesh that the ray tests. So does a custom material that moves its vertices in its shader. Their coordinates can therefore differ from the pose that the frame drew.
|
|
176
|
+
|
|
177
|
+
### Timing and cost
|
|
178
|
+
|
|
179
|
+
A pick costs one more draw of the camera's opaque objects, one read of four bytes, and one raycast for the texture coordinates. A pick answers in a frame after the one that records it.
|
|
180
|
+
|
|
181
|
+
<details>
|
|
182
|
+
<summary>Technical details: what a pick costs</summary>
|
|
183
|
+
|
|
184
|
+
Picks wait in a queue of their own, because a frame records one read.
|
|
185
|
+
|
|
186
|
+
</details>
|
|
187
|
+
|
|
188
|
+
### When a pick answers null or fails
|
|
189
|
+
|
|
190
|
+
A pick before the first frame answers `null`. A hidden object, an object off the camera's layers, and a pixel that no object covers answer `null` too.
|
|
169
191
|
|
|
170
192
|
A pick that waits for its read when the browser takes the GPU away is rejected with [E1436](../errors/E1436.md). The engine starts a new device, but the frame that recorded the pick drew on the lost one, so the read never lands. Ask for the pick again: the new device answers a new pick. A pick still queued behind it goes to the new device in its turn.
|
|
171
193
|
|
|
@@ -203,7 +225,9 @@ A ray hits [sprites](sprites.md), [points](points.md) and [lines](lines.md) wher
|
|
|
203
225
|
|
|
204
226
|
A hit's `instance` is the row: the sprite, the point, or the segment. Segment `i` of a strip or a loop joins points `i` and `i + 1`, and the last segment of a loop joins the last point to the first. Segment `i` of a batch of segments joins points `2i` and `2i + 1`. A hit's `triangle` is -1.
|
|
205
227
|
|
|
206
|
-
Sprites face the camera, and sizes in pixels depend on it. So these raycasts need a camera. `scene.raycast` and the other raycasts use the active camera. A pointer event's ray uses the camera of the frame on screen at the event.
|
|
228
|
+
Sprites face the camera, and sizes in pixels depend on it. So these raycasts need a camera. `scene.raycast` and the other raycasts use the active camera. A pointer event's ray uses the camera of the frame on screen at the event.
|
|
229
|
+
|
|
230
|
+
Without an active camera, rays miss sprites, points without `pointThreshold` and lines sized in pixels. A row sized in pixels is hit only between the camera's near and far planes, where the camera draws it.
|
|
207
231
|
|
|
208
232
|
The hit on a sprite or a point's square is the point where the ray crosses it, and its normal faces the camera. A hit near a line, or near a point within a threshold, is the ray's closest point to it. Its distance is that point's distance along the ray, and its normal points back along the ray. A ray hits a dashed line in its gaps too, and a sprite or a point where its map is clear.
|
|
209
233
|
|
|
@@ -251,18 +275,27 @@ A direction can have any length above 0, from 10^-300 to 10^300. The engine make
|
|
|
251
275
|
|
|
252
276
|
## How queries find objects
|
|
253
277
|
|
|
254
|
-
The
|
|
278
|
+
- The first query after a mesh is created builds that mesh's tree. A large mesh can make that first query slow.
|
|
279
|
+
- Static objects are cheap to move. Creating or destroying objects rebuilds the static tree at the next query.
|
|
280
|
+
- Dynamic objects, dynamic batches, sprites, points and lines are rebuilt in each frame that runs a query. A large dynamic batch of particles adds to each such frame. A frame without queries builds nothing.
|
|
281
|
+
- A raycast on layers that hold pixel-sized sprites, points or lines costs more. Keep them on their own layers to keep other raycasts fast.
|
|
282
|
+
- A ray costs about the same in a large scene as in a small one.
|
|
283
|
+
- Objects thousands of kilometers from the origin get the same precision as objects near it.
|
|
284
|
+
|
|
285
|
+
<details>
|
|
286
|
+
<summary>Technical details: the query trees</summary>
|
|
287
|
+
|
|
288
|
+
The engine keeps two levels of trees, in its WebAssembly core. One tree per mesh, over its triangles. Two trees sit over the scene's objects and instance rows. The tree over static objects is built once, and again only after objects are created or destroyed. When a static object moves, the engine adjusts the boxes of its tree instead.
|
|
255
289
|
|
|
256
|
-
|
|
257
|
-
- Two trees over the scene's objects and instance rows. The tree over static objects is built once, and again only after objects are created or destroyed. When a static object moves, the engine adjusts the boxes of its tree instead. The tree over dynamic objects is built again in each frame that runs a query, from all their positions at once. It holds the rows of dynamic batches too, also sprites, points and lines, on every layer. So a large dynamic batch of particles adds to each frame that runs a query. A frame without queries builds nothing.
|
|
290
|
+
The tree over dynamic objects is built again in each frame that runs a query, from all their positions at once. It holds the rows of dynamic batches too, also sprites, points and lines, on every layer.
|
|
258
291
|
|
|
259
292
|
Each node of a tree has four children, so one SIMD instruction tests a ray against four boxes. A query walks the scene's trees to the objects whose boxes it meets. Then it moves the ray into each object's own space and walks that object's mesh tree. Each object's box comes from its mesh's box, so it holds every triangle.
|
|
260
293
|
|
|
261
|
-
|
|
294
|
+
A three.js `Raycaster` tests each object's bounding sphere in turn, so its rays cost more as the scene grows. The trees hold sprites, points and line segments too. A row sized in pixels takes more room in the world the farther it lies from the camera. A threshold reaches past what a row draws. So when the query's layers hold such rows, the raycast grows each box of the trees as it walks them. A raycast on layers without them costs no more.
|
|
262
295
|
|
|
263
|
-
The trees
|
|
296
|
+
The trees give the same hits as testing every triangle of every object in turn. The engine stores positions relative to grid cells, and each query moves its origin into each cell's frame in 64-bit numbers.
|
|
264
297
|
|
|
265
|
-
|
|
298
|
+
</details>
|
|
266
299
|
|
|
267
300
|
## API reference
|
|
268
301
|
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: api/reference/assets
|
|
3
3
|
title: "Assets: API reference"
|
|
4
|
-
|
|
5
|
-
since: "0.1"
|
|
4
|
+
generated: true
|
|
6
5
|
summary: "Every export of the Assets API, from the engine's doc comments."
|
|
7
6
|
---
|
|
8
7
|
|
|
@@ -176,7 +175,7 @@ A light map from `assets.loadLightMap`: its radiance texture, ready for a materi
|
|
|
176
175
|
| `readonly width: number` | The texels across. |
|
|
177
176
|
| `readonly height: number` | The texels down. |
|
|
178
177
|
| `readonly texture: Texture` | The radiance, as a texture that a material takes as `lightMap`. |
|
|
179
|
-
| `readonly direction: Int8Array \| undefined` | Three signed bytes per texel, from -127 to 127
|
|
178
|
+
| `readonly direction: Int8Array \| undefined` | Three signed bytes per texel, from -127 to 127: each axis of the direction times 127. It runs from the same first texel as the radiance, and it is undefined for a light map without a direction. |
|
|
180
179
|
| `readonly directionTexture: Texture \| undefined` | The direction at each texel, in linear color: its red, green and blue map the direction's x, y and z from -1 to 1. It has the radiance's size, format and color space, so the engine reads it through the light map's own texture binding; give it to a material beside the radiance as `lightMapDirection`. It is undefined for a light map without a direction. |
|
|
181
180
|
|
|
182
181
|
## `LightMapEncoding`
|
|
@@ -332,4 +331,8 @@ Called as a download's bytes arrive and when one finishes or fails. It gets the
|
|
|
332
331
|
function registerGltfExtension(handler: GltfExtensionHandler): () => void
|
|
333
332
|
```
|
|
334
333
|
|
|
335
|
-
Registers a handler for the glTF extensions that an add-on reads, for every sketch of this thread. An add-on calls it once as its module loads, so a page that imports the add-on loads the add-on's files with no other call. Returns a function that unregisters the handler.
|
|
334
|
+
Registers a handler for the glTF extensions that an add-on reads, for every sketch of this thread. An add-on calls it once as its module loads, so a page that imports the add-on loads the add-on's files with no other call. Returns a function that unregisters the handler.
|
|
335
|
+
|
|
336
|
+
A later handler for an extension replaces the earlier one, which a development reload of the add-on's module needs. Two add-ons that read one extension therefore give it to the one that loaded last. A sketch that reads one extension in one scene alone uses `assets.registerGltfExtension` instead.
|
|
337
|
+
|
|
338
|
+
Throws E1213 for a handler without a list of extension names or a `load` function.
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: api/reference/cameras
|
|
3
3
|
title: "Cameras: API reference"
|
|
4
|
-
|
|
5
|
-
since: "0.1"
|
|
4
|
+
generated: true
|
|
6
5
|
summary: "Every export of the Cameras API, from the engine's doc comments."
|
|
7
6
|
---
|
|
8
7
|
|
|
@@ -23,6 +22,8 @@ An object that the scene can be drawn from. `scene.setActiveCamera` picks the ca
|
|
|
23
22
|
| `readonly far: number` | The distance to the far clipping plane. |
|
|
24
23
|
| `setLayers(mask: number): void` | Sets the layers the camera draws, as a 32-bit mask: it draws the objects whose masks share a layer with it. The default, 1, draws layer 0, where every object starts. |
|
|
25
24
|
| `setNearFar(near: number, far: number): void` | Sets the distances to the near and far clipping planes. |
|
|
25
|
+
| `readonly lensShift: readonly [number, number]` | The lens shift: how far the view sits right of and above the camera's axis, as fractions of the view's width and height. The array is the camera's own and changes with `setLensShift`, so copy it to keep a value. |
|
|
26
|
+
| `setLensShift(x: number, y: number): void` | Moves the view off the camera's axis, as a shift lens on a real camera does: right by `x` times the view's width, and up by `y` times its height. The perspective stays as it is, so the image is a crop of a wider view from the same place. A shift of 0.25 across puts the camera's axis, and a `target` it looks at, a quarter of the width left of the middle. Culling, shadows, picking, `screenToRay`, `worldToScreen`, views and labels all follow the shifted view. The default is no shift. It allocates nothing. |
|
|
26
27
|
| `screenToRay(x: number, y: number, out: Ray): void` | Writes the ray from the camera through a point on the canvas into `out`: `x` and `y` are CSS pixels from the canvas's top-left corner, as `input.pointer` gives them. A perspective ray starts at the camera, and an orthographic ray on the near plane. The direction has length 1. When the point is the position of the pointer or a finger from `input`, the ray uses the camera of the frame that was on screen at that event, if the engine still keeps it. It keeps the last four views, and frames in a row with the same view count as one. So a click during a fast pan picks what the user saw. Any other point uses the camera of the frame that last ran, with its lens as it is now. Objects stay where they are now, so a moving object can be up to a frame of its motion away from where the user saw it. |
|
|
27
28
|
| `worldToScreen(point: Vec3Like, out: Vec3Like): void` | Writes where a point in the world lies on the canvas into `out`: x and y in CSS pixels from the canvas's top-left corner, then the point's depth, its distance in front of the camera along the view. A depth below 0 puts the point behind the camera, where x and y have no meaning. It uses the camera of the frame that last ran, with its lens as it is now, so in `onLateUpdate` it places points where the frame draws them. |
|
|
28
29
|
|