@null3d/engine 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +109 -0
- package/THIRD-PARTY-NOTICES.txt +0 -1
- package/dist/wasm/single/null3d.js +19 -6
- package/dist/wasm/single/null3d_bg.wasm +0 -0
- package/dist/wasm/threaded/null3d.js +19 -6
- package/dist/wasm/threaded/null3d_bg.wasm +0 -0
- package/docs/api/animation.md +23 -67
- package/docs/api/assets.md +42 -26
- package/docs/api/cameras.md +8 -6
- package/docs/api/controls.md +46 -44
- package/docs/api/debug.md +13 -8
- package/docs/api/engine.md +17 -11
- package/docs/api/feature-draws.md +3 -3
- package/docs/api/feature-effects.md +3 -3
- package/docs/api/feature-instances.md +2 -2
- package/docs/api/features.md +14 -15
- package/docs/api/geometry.md +56 -75
- package/docs/api/grass.md +1 -1
- package/docs/api/impostors.md +120 -9
- package/docs/api/input.md +4 -11
- package/docs/api/lights.md +14 -38
- package/docs/api/lines.md +8 -25
- package/docs/api/materials.md +69 -70
- package/docs/api/math.md +6 -7
- package/docs/api/objects.md +13 -13
- package/docs/api/particles.md +2 -14
- package/docs/api/points.md +3 -25
- package/docs/api/post.md +22 -23
- package/docs/api/quality.md +11 -6
- package/docs/api/raycast.md +13 -32
- package/docs/api/reference/animation.md +9 -9
- package/docs/api/reference/assets.md +18 -18
- package/docs/api/reference/cameras.md +5 -2
- package/docs/api/reference/controls.md +75 -23
- package/docs/api/reference/debug.md +23 -8
- package/docs/api/reference/engine.md +22 -10
- package/docs/api/reference/geometry.md +161 -82
- package/docs/api/reference/grass.md +1 -1
- package/docs/api/reference/impostors.md +92 -1
- package/docs/api/reference/input.md +3 -3
- package/docs/api/reference/lights.md +9 -9
- package/docs/api/reference/lines.md +7 -7
- package/docs/api/reference/materials.md +48 -48
- package/docs/api/reference/math.md +22 -22
- package/docs/api/reference/objects.md +9 -9
- package/docs/api/reference/points.md +4 -4
- package/docs/api/reference/post.md +18 -18
- package/docs/api/reference/quality.md +7 -3
- package/docs/api/reference/raycast.md +6 -6
- package/docs/api/reference/render.md +2 -2
- package/docs/api/reference/scene.md +29 -26
- package/docs/api/reference/sketch.md +4 -0
- package/docs/api/reference/sound.md +203 -0
- package/docs/api/reference/sprites.md +5 -5
- package/docs/api/reference/terrain.md +2 -1
- package/docs/api/reference/textures.md +4 -4
- package/docs/api/reference/ui.md +3 -3
- package/docs/api/reference/vertex-draws.md +3 -3
- package/docs/api/reference/water.md +77 -6
- package/docs/api/reference/wind.md +2 -2
- package/docs/api/render.md +12 -10
- package/docs/api/scene.md +40 -29
- package/docs/api/sketch.md +64 -3
- package/docs/api/sound.md +169 -0
- package/docs/api/splats.md +7 -0
- package/docs/api/sprites.md +4 -20
- package/docs/api/tasks.md +2 -2
- package/docs/api/terrain.md +2 -14
- package/docs/api/textures.md +9 -9
- package/docs/api/ui.md +3 -15
- package/docs/api/water.md +198 -15
- package/docs/api/wind.md +5 -5
- package/docs/cli/null3d.md +93 -18
- package/docs/concepts/architecture.md +10 -10
- package/docs/concepts/assets.md +2 -19
- package/docs/concepts/backends.md +7 -5
- package/docs/concepts/color-management.md +15 -26
- package/docs/concepts/culling.md +1 -1
- package/docs/concepts/instances.md +5 -5
- package/docs/concepts/large-worlds.md +1 -1
- package/docs/concepts/lighting.md +50 -55
- package/docs/concepts/lod.md +2 -15
- package/docs/concepts/materials.md +16 -16
- package/docs/concepts/post-processing.md +7 -29
- package/docs/concepts/quality-preset-tables.md +53 -50
- package/docs/concepts/quality-presets.md +56 -27
- package/docs/concepts/render-graph.md +19 -14
- package/docs/concepts/render-layers.md +3 -17
- package/docs/concepts/shadows.md +10 -28
- package/docs/concepts/static-dynamic.md +2 -2
- package/docs/cookbook/index.md +1 -1
- package/docs/data/threejs-mapping.json +136 -102
- package/docs/errors/E1214.md +3 -3
- package/docs/errors/E1307.md +23 -0
- package/docs/errors/E1420.md +3 -3
- package/docs/errors/index.md +3 -2
- package/docs/getting-started/cdn.md +17 -1
- package/docs/getting-started/first-scene.md +1 -1
- package/docs/getting-started/hosting.md +50 -9
- package/docs/getting-started/install.md +8 -7
- package/docs/getting-started/network-use.md +10 -2
- package/docs/getting-started/project-structure.md +15 -6
- package/docs/getting-started/third-party-notices.md +8 -6
- package/docs/guides/accessibility.md +1 -1
- package/docs/guides/add-ons.md +3 -2
- package/docs/guides/agents.md +16 -5
- package/docs/guides/assets-pipeline.md +13 -12
- package/docs/guides/audio.md +109 -124
- package/docs/guides/car-paint.md +1 -1
- package/docs/guides/content-pages.md +10 -6
- package/docs/guides/custom-passes.md +9 -8
- package/docs/guides/custom-shaders.md +6 -3
- package/docs/guides/debugging.md +78 -4
- package/docs/guides/deploying.md +105 -5
- package/docs/guides/deterministic-simulation.md +1 -1
- package/docs/guides/first-use-shaders.md +4 -4
- package/docs/guides/loading-screens.md +78 -33
- package/docs/guides/multiple-views.md +41 -2
- package/docs/guides/performance.md +6 -3
- package/docs/guides/phones.md +12 -1
- package/docs/guides/physics.md +1 -1
- package/docs/guides/screens.md +7 -5
- package/docs/guides/start-time.md +328 -0
- package/docs/guides/testing.md +23 -5
- package/docs/guides/ui-overlays.md +3 -3
- package/docs/index.md +12 -8
- package/docs/pages.md +26 -23
- package/docs/porting/react-three-fiber.md +228 -5
- package/docs/porting/threejs-loop-and-threads.md +220 -6
- package/docs/porting/threejs-mapping.md +86 -84
- package/docs/porting/threejs-materials.md +212 -5
- package/docs/porting/threejs-overview.md +218 -5
- package/docs/porting/threejs-postprocessing.md +2 -2
- package/docs/porting/threejs-shaders.md +298 -5
- package/docs/porting/threejs-unsupported.md +82 -6
- package/docs/porting/verification.md +181 -5
- package/docs/shaders/builtins.md +1 -1
- package/docs/shaders/library.md +63 -39
- package/docs/shaders/surface-functions.md +11 -10
- package/docs/shaders/wgsl-rules.md +1 -1
- package/lib/debug/channel.d.ts +103 -0
- package/lib/debug/channel.js +269 -0
- package/lib/debug/debug.d.ts +9 -7
- package/lib/debug/draw.d.ts +9 -0
- package/lib/debug/draw.js +49 -2
- package/lib/debug/inspector.d.ts +60 -0
- package/lib/debug/inspector.js +475 -0
- package/lib/debug/stats-panel.d.ts +1 -1
- package/lib/debug/stats.d.ts +2 -3
- package/lib/errors/codes.js +8 -2
- package/lib/errors/engine-error.js +25 -10
- package/lib/errors/fixes.d.ts +1 -0
- package/lib/errors/fixes.js +3 -2
- package/lib/generated/core.d.ts +1 -1
- package/lib/generated/core.js +1 -1
- package/lib/gpu/early-builds.d.ts +68 -0
- package/lib/gpu/early-builds.js +158 -0
- package/lib/gpu/pipeline-name.d.ts +6 -0
- package/lib/gpu/pipeline-name.js +23 -0
- package/lib/gpu/webgl2/backend.d.ts +63 -2
- package/lib/gpu/webgl2/backend.js +226 -8
- package/lib/gpu/webgl2/programs.d.ts +18 -0
- package/lib/gpu/webgl2/programs.js +4 -1
- package/lib/gpu/webgpu/backend.d.ts +89 -2
- package/lib/gpu/webgpu/backend.js +255 -8
- package/lib/gpu/webgpu/pipelines.d.ts +13 -0
- package/lib/gpu/webgpu/pipelines.js +15 -1
- package/lib/index.d.ts +6 -4
- package/lib/index.js +3 -2
- package/lib/math/color.d.ts +5 -5
- package/lib/math/color.js +5 -5
- package/lib/math/mat4.d.ts +6 -12
- package/lib/math/mat4.js +6 -12
- package/lib/math/namespaces/quat.d.ts +3 -3
- package/lib/math/namespaces/quat.js +3 -3
- package/lib/math/quat.d.ts +8 -12
- package/lib/math/quat.js +8 -12
- package/lib/math/random.d.ts +2 -3
- package/lib/math/random.js +2 -3
- package/lib/math/types.d.ts +4 -4
- package/lib/math/vec3.d.ts +3 -6
- package/lib/math/vec3.js +3 -6
- package/lib/page/capabilities.d.ts +7 -7
- package/lib/page/capabilities.js +39 -25
- package/lib/page/check-store.d.ts +14 -2
- package/lib/page/check-store.js +34 -11
- package/lib/page/engine.d.ts +103 -26
- package/lib/page/engine.js +420 -97
- package/lib/page/first-frame.d.ts +16 -0
- package/lib/page/first-frame.js +35 -0
- package/lib/page/frame-stats.d.ts +34 -1
- package/lib/page/frame-stats.js +15 -0
- package/lib/page/label-loop.d.ts +7 -3
- package/lib/page/label-loop.js +17 -10
- package/lib/page/labels.d.ts +3 -3
- package/lib/page/pipeline-store.d.ts +25 -0
- package/lib/page/pipeline-store.js +84 -0
- package/lib/page/start-marker.d.ts +4 -1
- package/lib/page/start-marker.js +5 -2
- package/lib/page/switches.d.ts +32 -2
- package/lib/page/switches.js +9 -1
- package/lib/quality/check.d.ts +24 -3
- package/lib/quality/check.js +21 -7
- package/lib/quality/chooser.d.ts +6 -0
- package/lib/quality/chooser.js +8 -0
- package/lib/quality/governor.d.ts +98 -6
- package/lib/quality/governor.js +250 -20
- package/lib/quality/preset-docs.d.ts +16 -1
- package/lib/quality/preset-docs.js +3 -0
- package/lib/quality/presets.d.ts +84 -7
- package/lib/quality/presets.js +94 -2
- package/lib/render/draw.d.ts +3 -2
- package/lib/render/draw.js +15 -5
- package/lib/render/load-draw.d.ts +7 -5
- package/lib/render/load-draw.js +7 -5
- package/lib/render/loss.d.ts +28 -10
- package/lib/render/loss.js +50 -22
- package/lib/render/recovery.d.ts +20 -0
- package/lib/render/recovery.js +44 -4
- package/lib/render/renderer.d.ts +85 -9
- package/lib/render/renderer.js +181 -42
- package/lib/render/scene-renderer.d.ts +19 -1
- package/lib/render/scene-renderer.js +25 -1
- package/lib/render/webgl2-renderers.js +8 -5
- package/lib/render/webgpu-renderers.js +5 -4
- package/lib/scene/animation.d.ts +28 -32
- package/lib/scene/animation.js +12 -15
- package/lib/scene/assets.d.ts +61 -86
- package/lib/scene/assets.js +103 -236
- package/lib/scene/background.d.ts +14 -18
- package/lib/scene/background.js +5 -2
- package/lib/scene/color.d.ts +3 -3
- package/lib/scene/downloads.d.ts +2 -0
- package/lib/scene/downloads.js +371 -0
- package/lib/scene/environment.d.ts +7 -7
- package/lib/scene/environment.js +1 -1
- package/lib/scene/fake-call-values.js +1 -1
- package/lib/scene/fog.d.ts +11 -4
- package/lib/scene/fog.js +8 -2
- package/lib/scene/frame-cameras.d.ts +19 -0
- package/lib/scene/frame-cameras.js +58 -0
- package/lib/scene/gltf.d.ts +32 -2
- package/lib/scene/gltf.js +78 -49
- package/lib/scene/grading.d.ts +2 -2
- package/lib/scene/grading.js +3 -3
- package/lib/scene/ktx2.d.ts +9 -1
- package/lib/scene/ktx2.js +3 -2
- package/lib/scene/level-rule.d.ts +120 -0
- package/lib/scene/level-rule.js +130 -0
- package/lib/scene/lines.d.ts +13 -17
- package/lib/scene/lines.js +3 -3
- package/lib/scene/lut.d.ts +1 -2
- package/lib/scene/lut.js +1 -2
- package/lib/scene/picks.d.ts +2 -2
- package/lib/scene/pointer-events.d.ts +4 -7
- package/lib/scene/post.d.ts +38 -43
- package/lib/scene/post.js +4 -1
- package/lib/scene/prefab.d.ts +7 -8
- package/lib/scene/prefab.js +7 -8
- package/lib/scene/property-animation.d.ts +1 -1
- package/lib/scene/property-animation.js +1 -1
- package/lib/scene/queries.d.ts +7 -13
- package/lib/scene/resources.d.ts +225 -254
- package/lib/scene/resources.js +179 -81
- package/lib/scene/scene.d.ts +149 -118
- package/lib/scene/scene.js +196 -98
- package/lib/scene/serial-loads.d.ts +29 -0
- package/lib/scene/serial-loads.js +68 -0
- package/lib/scene/shader-preloads.d.ts +34 -0
- package/lib/scene/shader-preloads.js +38 -0
- package/lib/scene/sprites.d.ts +14 -17
- package/lib/scene/sprites.js +5 -6
- package/lib/scene/textures.d.ts +11 -12
- package/lib/scene/textures.js +9 -10
- package/lib/scene/time-of-day.d.ts +3 -4
- package/lib/scene/time-of-day.js +2 -3
- package/lib/scene/vertex-draws.d.ts +5 -4
- package/lib/scene/vertex-draws.js +7 -5
- package/lib/shader-artifact.json +1 -0
- package/lib/shared/core.d.ts +5 -0
- package/lib/shared/core.js +1 -0
- package/lib/shared/import-once.d.ts +6 -0
- package/lib/shared/import-once.js +19 -0
- package/lib/shared/metrics.d.ts +38 -0
- package/lib/shared/metrics.js +62 -1
- package/lib/shared/run-task.js +7 -1
- package/lib/shared/task-pending.d.ts +12 -0
- package/lib/shared/task-pending.js +61 -1
- package/lib/shared/tasks.js +79 -32
- package/lib/shared/version.d.ts +17 -1
- package/lib/shared/version.js +19 -1
- package/lib/shared/wasm.d.ts +12 -4
- package/lib/shared/wasm.js +50 -27
- package/lib/shared/worker-start.d.ts +7 -0
- package/lib/shared/worker-start.js +27 -0
- package/lib/sketch/define-sketch.d.ts +35 -0
- package/lib/sketch/input.d.ts +2 -2
- package/lib/sketch/preset-check.d.ts +20 -6
- package/lib/sketch/preset-check.js +42 -17
- package/lib/sketch/quality.d.ts +69 -11
- package/lib/sketch/quality.js +54 -13
- package/lib/sketch/runner.d.ts +76 -9
- package/lib/sketch/runner.js +385 -52
- package/lib/sketch/ui.d.ts +5 -8
- package/lib/workers/probe-worker.d.ts +5 -0
- package/lib/workers/probe-worker.js +13 -4
- package/lib/workers/protocol.d.ts +61 -13
- package/lib/workers/protocol.js +4 -0
- package/lib/workers/render-worker.js +25 -4
- package/lib/workers/sketch-worker.js +104 -15
- package/package.json +2 -2
|
@@ -8,7 +8,7 @@ summary: "Main thread, sketch worker, render worker, job workers; where the sket
|
|
|
8
8
|
|
|
9
9
|
# Architecture: threads and the frame
|
|
10
10
|
|
|
11
|
-
> Roadmap step 0.1, first released in null3D 0.1.0.
|
|
11
|
+
> Roadmap step 0.1, first released in null3D 0.1.0. The API is experimental, so it can still change between versions.
|
|
12
12
|
|
|
13
13
|
```mermaid
|
|
14
14
|
flowchart LR
|
|
@@ -40,11 +40,11 @@ In null3D, a 3D scene is called a sketch: a module that builds the scene and upd
|
|
|
40
40
|
| Sketch worker | Your sketch code and the engine core. Reading or writing scene data is a plain memory access here. | 1 |
|
|
41
41
|
| Render worker | The GPU device and the canvas. It uploads changed data and replays draw lists into WebGPU or WebGL2 calls. It runs no sketch code. | 1 |
|
|
42
42
|
| Job workers | Parallel loops over scene data in Rust: the animation of clips, transforms and bounds, instance batches, and the sort of see-through objects. On WebGL2 they also cull, hide what occluders hide, and list the lights of each cluster. Between frames, they compute the normals and tangents of new meshes, build the trees that raycasts use, cast batches of rays, and run decoders such as the KTX2 transcoder. | None at the start. They start as the work grows, up to the logical cores minus 2, and at least 1 |
|
|
43
|
-
| Helper workers | Short-lived workers that start on first use. A glTF worker reads model files and decodes their images and meshopt data. A panorama worker reads HDR and EXR files. A task worker runs decoders where no job worker can take them. They run no frame work. | One of each kind, on first use |
|
|
43
|
+
| Helper workers | Short-lived workers that start on first use. A glTF worker reads model files and decodes their images and meshopt data. A panorama worker reads HDR and EXR files. A task worker runs decoders where no job worker can take them. A probe worker runs once at startup. It tests whether a worker can draw with WebGL2 and WebGPU, and on an Apple GPU in WebKit it measures the two draw paths. They run no frame work. | One of each kind, on first use or at startup |
|
|
44
44
|
|
|
45
45
|
### When the job workers start
|
|
46
46
|
|
|
47
|
-
A job worker is a whole browser thread, and each costs about 3.5 MiB of memory even when it waits. So the engine starts none at first. The sketch thread times the parallel loops that it hands out. Over each 30 frames, it takes the mean time of those loops per frame. At 0.2 ms or more, it asks for 2 job workers. After each later such window, it asks for twice as many, up to the most. The first decoders, such as the KTX2 transcoder, ask for 2 too. They ask for more while every job worker has a task.
|
|
47
|
+
A job worker is a whole browser thread, and each costs about 3.5 MiB of memory even when it waits. So the engine starts none at first. The sketch thread times the parallel loops that it hands out. Over each window of 30 frames, or 2 seconds once it holds 2 frames, it takes the mean time of those loops per frame. At 0.2 ms or more, it asks for 2 job workers. After each later such window, it asks for twice as many, up to the most. The first decoders, such as the KTX2 transcoder, ask for 2 too, while their own code downloads. The first decode then runs on the first job worker that is ready, and later ones on the second. They ask for more while every job worker has a task. The page downloads the job workers' script while the core downloads. So a setup that loads a model starts its job workers from the browser's cache. Work that only job workers run between frames asks for 2 as well when none has started, such as the resampling of a model's clips. Until a job worker is ready, the sketch thread runs its share of each loop. Job workers that started stay until the engine stops. After a window with too little parallel work, the sketch thread stops timing its loops for 4.5 seconds of sketch time. Each reading of the browser's clock allocates. A slow frame rate makes that wait no longer. Once it has asked for the most, it stops for good. A small scene never starts one. On an 18-core Mac, a scene with 100,000 moving boxes started 4 to 16 job workers on WebGPU, more when the Mac was busy. On WebGL2, where the job workers also cull, it started all 16 within 1 second. `engine.mode.jobWorkers` gives the most job workers that the engine may start. The stats overlay counts the ones that run.
|
|
48
48
|
|
|
49
49
|
## Why the work is split this way
|
|
50
50
|
|
|
@@ -86,7 +86,7 @@ The engine times each step of the sketch worker's frame, the replay on the drawi
|
|
|
86
86
|
|
|
87
87
|
## The passes of a frame
|
|
88
88
|
|
|
89
|
-
A frame's draw list holds a series of passes, and the [render graph](render-graph.md) puts them in order. A pass is one job for the GPU, such as drawing the scene from the camera. The engine declares its own passes, and a sketch adds [scene passes](../api/render.md) that draw the scene from other cameras into textures. A frame runs
|
|
89
|
+
A frame's draw list holds a series of passes, and the [render graph](render-graph.md) puts them in order. A pass is one job for the GPU, such as drawing the scene from the camera. The engine declares its own passes, and a sketch adds [scene passes](../api/render.md) that draw the scene from other cameras into textures. A frame runs its main passes in this order. The passes of the other effects, such as decals, the transparency layers, volumetric fog and depth of field, run between them ([The post-processing chain](post-processing.md)).
|
|
90
90
|
|
|
91
91
|
1. Light clustering, on WebGPU: a compute pass fits the depth slices to the range the light depth pass measured in the frame before. It then lists the point and spot lights of each cluster of the camera's view ([Lighting and environment](lighting.md#clustered-forward-shading)).
|
|
92
92
|
2. Culling, on WebGPU: a compute pass for each view tests the objects and instance rows against the view, on the GPU. In a scene over several grid cells, it skips the still objects of the cells out of view ([Culling](culling.md)). On a device that draws directly, the job workers cull on the CPU, as on WebGL2.
|
|
@@ -98,16 +98,16 @@ A frame's draw list holds a series of passes, and the [render graph](render-grap
|
|
|
98
98
|
8. The opaque pass draws the objects in view into the scene color and depth, with 4 samples per pixel in the MSAA mode. With GPU occlusion culling on WebGPU, an occluders' pass first draws the depth of the large objects that showed in the camera's last frame. A compute pass builds a depth pyramid from that depth and culls every object in view against it. The depth prepass and the opaque pass then draw the objects that show ([Culling](culling.md#gpu-occlusion-culling-on-webgpu)). After the opaque objects, the same render pass draws a texture, environment, cube map or sky background into the pixels that no object covers.
|
|
99
99
|
9. In development builds, a frame with [debug drawing](../api/debug.md) draws the lines after the opaque pass, in the same render pass.
|
|
100
100
|
10. While some object blends, the transparent pass draws the blended objects back to front, in the same render pass.
|
|
101
|
-
11.
|
|
102
|
-
12.
|
|
103
|
-
13.
|
|
104
|
-
14. The final pass draws the scene color into the canvas. On the HDR path it blends in bloom, and applies the vignette, the exposure and the tone mapping. Then it draws the outlines, applies the color grading table, encodes sRGB and dithers. It also smooths edges in the FXAA mode. Below the whole canvas's render scale, that work splits in two, while the render scale can drop. The first step draws the FXAA, the tone curve and the sRGB encode at the render size. The second step scales the image up to the canvas and draws the rest ([The post-processing chain](post-processing.md#below-the-whole-canvass-render-scale)). On the 8-bit path the scene's shaders tone map their own output. There, with MSAA and a lowest render scale of 1, the scene's render pass averages its samples straight into the canvas. The frame then has no final pass, unless
|
|
101
|
+
11. Outlines, while some object is outlined: a pass draws the outlined objects into a mask.
|
|
102
|
+
12. Custom effects, on the HDR path: the sketch's own WGSL effects, joined into as few passes as their reads allow ([Custom passes](../guides/custom-passes.md)).
|
|
103
|
+
13. Bloom, on the HDR path: passes down and up a chain of mip levels. When a custom effect reads a level of the chain, bloom runs before the effects, from the scene color.
|
|
104
|
+
14. The final pass draws the scene color into the canvas. On the HDR path it blends in bloom, and applies the vignette, the exposure and the tone mapping. Then it draws the outlines, applies the color grading table, encodes sRGB and dithers. It also smooths edges in the FXAA mode. Below the whole canvas's render scale, that work splits in two, while the render scale can drop. The first step draws the FXAA, the tone curve and the sRGB encode at the render size. The second step scales the image up to the canvas and draws the rest ([The post-processing chain](post-processing.md#below-the-whole-canvass-render-scale)). On the 8-bit path the scene's shaders tone map their own output. There, with MSAA and a lowest render scale of 1, the scene's render pass averages its samples straight into the canvas. The frame then has no final pass, unless an effect needs it, such as color grading, sharpening, outlines or transmission ([Color management](color-management.md#the-8-bit-path)). There the scene's shaders apply the vignette before their tone mapping ([GPU tiers and backends](backends.md#color-and-anti-aliasing-on-each-tier)).
|
|
105
105
|
|
|
106
106
|
On WebGL2 the job workers cull, test the occluders and list the lights of each cluster before the frame records. The vertex shaders of the shadow and scene passes skin and morph the meshes. So the frame has no compute passes there. A new environment from a file, or the built-in room, adds GPU work to the next frame once. The GPU filters its map for each roughness before the frame draws ([Lighting and environment](lighting.md#environment-maps)). The graph works out the order only when the passes change, so a frame whose passes stay the same pays nothing for it.
|
|
107
107
|
|
|
108
108
|
## Precision far from the origin
|
|
109
109
|
|
|
110
|
-
Positions are 32-bit floats
|
|
110
|
+
Positions are 32-bit floats. Far from the origin such a value moves in coarse steps: about 8 mm at 100 km. The engine therefore keeps each world matrix relative to the center of a grid cell, 1,024 m wide. A root object takes the cell that holds its position, and its children take their root's cell. An instance row takes the cell that holds its own position.
|
|
111
111
|
|
|
112
112
|
Each frame, the engine computes the offset from the camera to each cell in use, in 64-bit floats. The GPU adds those offsets, so it draws positions relative to the camera, which stay precise near it. Static matrices stay on the GPU while the camera moves. [Culling](culling.md) describes the cells and their limits.
|
|
113
113
|
|
|
@@ -140,7 +140,7 @@ The engine puts the sketch, the drawing and the parallel work on threads by the
|
|
|
140
140
|
|
|
141
141
|
A worker can draw only where the browser gives it a WebGPU or WebGL2 context for a canvas that the page hands over. The engine tests this at startup. Where a worker cannot draw, the page draws, and the sketch stays on its thread, in pipelined mode. Low latency with the sketch in its worker needs that worker to draw, so there the engine runs in pipelined mode instead. A development build logs a warning, and `engine.mode.latency` is `pipelined`. Read `engine.mode` for the build, the latency mode, the thread that runs the sketch, the thread that draws and the number of job workers.
|
|
142
142
|
|
|
143
|
-
`createEngine({ sketchThread: 'main' })` runs your sketch code and the engine core on the page's main thread, in the threaded build. Your sketch can then reach the DOM. Use it for apps that work mostly with the DOM, for
|
|
143
|
+
`createEngine({ sketchThread: 'main' })` runs your sketch code and the engine core on the page's main thread, in the threaded build. Your sketch can then reach the DOM. Use it for apps that work mostly with the DOM, for ported code that still uses the DOM, and for debugging. The API stays the same. Your sketch's frames share the main thread with the page. Layout work and page scripts can delay a frame, and a slow frame delays the page's input. With the `?render=main` switch, the page draws too, as in low-latency mode, and `engine.mode.latency` is `low`. The page runs the sketch of one engine at a time. A second engine that asks for the main thread before the first has stopped fails with [E1415](../errors/E1415.md).
|
|
144
144
|
|
|
145
145
|
Worker threads need shared memory, and browsers allow shared memory only on cross-origin isolated pages. On any other page, the engine loads its single-threaded build, which runs the same code on one thread. [Hosting and cross-origin isolation](../getting-started/hosting.md) shows how to send the two headers that turn isolation on. The page switches `?threads=off`, `?render=main` and `?sketch-thread=main` force the other modes on one device, for tests ([Testing your sketch](../guides/testing.md)).
|
|
146
146
|
|
package/docs/concepts/assets.md
CHANGED
|
@@ -40,7 +40,7 @@ For hundreds or thousands of copies, `scene.createInstances(prefab, count)` draw
|
|
|
40
40
|
|
|
41
41
|
Before you publish a model, run it through `bunx @null3d/cli assets optimize`. The command stores its meshes as integers compressed with meshopt, and its textures as KTX2 files. The model then downloads less and takes less GPU memory. [The asset pipeline](../guides/assets-pipeline.md) covers it.
|
|
42
42
|
|
|
43
|
-
The loader reads `.glb` files, and `.gltf` files with the files they name. It reads these extensions: `KHR_mesh_quantization`, `KHR_meshopt_compression`, `EXT_meshopt_compression`, `KHR_draco_mesh_compression`, `KHR_texture_basisu`, `EXT_texture_webp`, `EXT_texture_avif`, `KHR_texture_transform`, `KHR_materials_unlit`, `KHR_materials_emissive_strength`, `KHR_materials_specular`, `KHR_materials_ior`, `KHR_materials_transmission`, `KHR_materials_volume`, `KHR_materials_dispersion`, `KHR_materials_diffuse_transmission`, `KHR_materials_volume_scatter`, `KHR_materials_clearcoat`, `KHR_materials_sheen`, `KHR_materials_iridescence`, `KHR_materials_anisotropy`, `KHR_lights_punctual`, `KHR_animation_pointer`, `KHR_node_visibility`, `EXT_mesh_gpu_instancing`, `NEEDLE_lightmaps` and `NEEDLE_components`. A file that requires another extension fails with E1417. The loader leaves out other extensions that a file only uses, and the model draws without them.
|
|
43
|
+
The loader reads `.glb` files, and `.gltf` files with the files they name. It reads these extensions: `KHR_mesh_quantization`, `KHR_meshopt_compression`, `EXT_meshopt_compression`, `KHR_draco_mesh_compression`, `KHR_texture_basisu`, `EXT_texture_webp`, `EXT_texture_avif`, `KHR_texture_transform`, `KHR_materials_unlit`, `KHR_materials_emissive_strength`, `KHR_materials_specular`, `KHR_materials_ior`, `KHR_materials_transmission`, `KHR_materials_volume`, `KHR_materials_dispersion`, `KHR_materials_diffuse_transmission`, `KHR_materials_volume_scatter`, `KHR_materials_clearcoat`, `KHR_materials_sheen`, `KHR_materials_iridescence`, `KHR_materials_anisotropy`, `KHR_lights_punctual`, `KHR_animation_pointer`, `KHR_node_visibility`, `EXT_mesh_gpu_instancing`, `MSFT_lod`, `NEEDLE_lightmaps` and `NEEDLE_components`. It also reads the asset tool's own `NULL3D_mesh_bvh`, `NULL3D_occluder`, `NULL3D_clusters` and `NULL3D_pieces`. A file that requires another extension fails with E1417. The loader leaves out other extensions that a file only uses, and the model draws without them.
|
|
44
44
|
|
|
45
45
|
An add-on can read an extension that the engine leaves out. It registers a handler with `assets.registerGltfExtension`, and the loader draws the primitives that carry the extension through that handler. Without the handler, a file that requires such an extension fails with E1417, and the message names the package to import. [Assets](../api/assets.md#extensions-that-add-ons-read) gives the handler's shape.
|
|
46
46
|
|
|
@@ -56,7 +56,7 @@ scene.instantiate(city);
|
|
|
56
56
|
|
|
57
57
|
The loader reads both names of the extension: `KHR_meshopt_compression`, and the older `EXT_meshopt_compression`. A file can carry a fallback buffer with the uncompressed data, for loaders without a decoder. The engine never downloads that buffer, because it always decodes. A file whose compressed data breaks the extension's rules, or does not decode, fails with E1416.
|
|
58
58
|
|
|
59
|
-
The loader also reads Draco compression, `KHR_draco_mesh_compression`, which many older models
|
|
59
|
+
The loader also reads Draco compression, `KHR_draco_mesh_compression`, which many older models use. It decodes each mesh in its worker with Draco's own decoder for glTF files. That decoder is about 60 KB after Brotli. It downloads with the first file that holds Draco data, so a page without such files does not download it. The engine compiles it once per page.
|
|
60
60
|
|
|
61
61
|
The loader stores the decoded normals and tangents as 8-bit integers, and texture coordinates between 0 and 1 as 16-bit integers. These are the types that the asset tool writes. They take half the GPU memory of the floats that other loaders keep, or less. Positions stay floats. In development builds, the loader warns about each Draco file and names the command that converts it.
|
|
62
62
|
|
|
@@ -126,20 +126,3 @@ Each frame sends at most the preset's texture upload budget to the GPU: 2 MiB on
|
|
|
126
126
|
Each texture reports its GPU memory in `bytes`, and `textures.memoryBytes` counts every texture. The quality preset's texture memory budget holds textures under `textureMemoryMiB`. Past it, the engine drops the largest mip levels of textures from files. It loads them again from the file once room returns, as [Quality presets](quality-presets.md#texture-memory) explains. `geometry.memoryBytes` gives the GPU memory of all meshes.
|
|
127
127
|
|
|
128
128
|
`prefab.destroy()` frees a model with its meshes, materials, textures, skeleton and clips, and `mesh.destroy()` frees one mesh. The next models and meshes take the memory that they gave back. [Freeing a model](../api/assets.md#freeing-a-model) gives the order of the calls.
|
|
129
|
-
|
|
130
|
-
## From three.js
|
|
131
|
-
|
|
132
|
-
| three.js | null3D |
|
|
133
|
-
| --- | --- |
|
|
134
|
-
| `TextureLoader`, and `KTX2Loader` with its transcoder path | `assets.loadTexture(url)` for both. The engine ships the transcoder |
|
|
135
|
-
| A `BufferAttribute` of an `Int16Array` with `normalized: true` | `{ array: new Int16Array(values), normalized: true }` in `geometry.fromArrays` |
|
|
136
|
-
| `new GLTFLoader().loadAsync(url)`, then `scene.add(gltf.scene)` | `const prefab = await assets.loadGltf(url)`, then `scene.instantiate(prefab)` |
|
|
137
|
-
| `gltf.scene.clone()` or `SkeletonUtils.clone` for each copy | `scene.instantiate(prefab)` for each copy, which shares the GPU data |
|
|
138
|
-
| `dispose()` on each geometry, material and texture of a glTF scene | `prefab.destroy()`, after destroying its copies |
|
|
139
|
-
| `GLTFLoader` with `KTX2Loader` and its transcoder path | `assets.loadGltf(url)`. The engine ships the transcoder |
|
|
140
|
-
| `GLTFLoader` with a model whose textures use `EXT_texture_webp` or `EXT_texture_avif` | `assets.loadGltf(url)`. The browser decodes both formats |
|
|
141
|
-
| `KTX2Loader` with a UASTC HDR file | `assets.loadTexture(url)`, which gives BC6H or `rgb9e5ufloat` |
|
|
142
|
-
| `GLTFLoader` with `setMeshoptDecoder(MeshoptDecoder)` | `assets.loadGltf(url)`. The engine ships the decoder, and downloads it with the first compressed file |
|
|
143
|
-
| `GLTFLoader` with `setDRACOLoader(dracoLoader)` and `setDecoderPath` | `assets.loadGltf(url)`. The engine ships Draco's decoder, and downloads it with the first Draco file. Convert the files with `bunx @null3d/cli assets optimize` to load faster |
|
|
144
|
-
| `GLTFLoader` with a quantized mesh | `assets.loadGltf(url)`. A glTF node's transform becomes the object's transform, so the integers stay on the GPU |
|
|
145
|
-
| An `InstancedMesh` for each mesh of a model, kept in step by hand | `scene.createInstances(prefab, count)`: one set of rows for all the model's meshes |
|
|
@@ -18,7 +18,7 @@ flowchart TD
|
|
|
18
18
|
adapter -- "no" --> gl["WebGL2"]
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
null3D draws with WebGPU where the browser offers it, and with WebGL2 everywhere else. The same sketch code runs on both, with no backend checks in it. The engine picks the tier once, at startup, from feature tests. It tests the thread that will draw: where a worker draws, the engine picks the best tier that the worker can use. Where no worker can draw, the page draws in pipelined mode, even when the page asks for low latency ([Architecture](architecture.md#where-the-sketch-runs)). After two starts in a row that crashed the tab on WebGPU, the engine starts on WebGL2. A page that names a GPU path keeps it ([Quality presets](quality-presets.md#starts-that-crashed-the-tab)).
|
|
21
|
+
null3D draws with WebGPU where the browser offers it, and with WebGL2 everywhere else. The same sketch code runs on both, with no backend checks in it. So one sketch works in every current browser on computers, tablets and phones. The engine picks the tier once, at startup, from feature tests. It tests the thread that will draw: where a worker draws, the engine picks the best tier that the worker can use. Where no worker can draw, the page draws in pipelined mode, even when the page asks for low latency ([Architecture](architecture.md#where-the-sketch-runs)). After two starts in a row that crashed the tab on WebGPU, the engine starts on WebGL2. A page that names a GPU path keeps it ([Quality presets](quality-presets.md#starts-that-crashed-the-tab)).
|
|
22
22
|
|
|
23
23
|
## The three tiers
|
|
24
24
|
|
|
@@ -72,10 +72,10 @@ The scene's color target differs from tier to tier:
|
|
|
72
72
|
| Tier | Scene color | How it reaches the canvas |
|
|
73
73
|
| --- | --- | --- |
|
|
74
74
|
| WebGPU core | `rg11b10ufloat` where the device can draw into it and the canvas is opaque; `rgba16float` elsewhere | The final pass applies the exposure and the tone mapping, encodes sRGB and dithers, into the canvas. With MSAA, the render pass first averages the samples into a texture. |
|
|
75
|
-
| WebGPU compatibility mode | With MSAA, 8 bits per channel. With FXAA or none, as on core WebGPU. | With MSAA, each shader tone maps and encodes its own result. The render pass averages the samples into the canvas, or into a texture that the final pass copies while the render scale can drop below 1. With FXAA or none, as on core WebGPU. |
|
|
75
|
+
| WebGPU compatibility mode | With MSAA, 8 bits per channel. With FXAA or none, as on core WebGPU. | With MSAA, each shader tone maps and encodes its own result. The render pass averages the samples into the canvas, or into a texture that the final pass copies while the render scale can drop below 1 or an effect needs the final pass. With FXAA or none, as on core WebGPU. |
|
|
76
76
|
| WebGL2 | `RGBA16F` where the float target test passes; 8 bits per channel elsewhere. With `?scene-format=rg11b10`, `R11F_G11F_B10F` where the canvas is opaque and that format passes the test too | As on core WebGPU with the float target. Without it, each shader tone maps its own result. MSAA then averages the samples as in compatibility mode. With FXAA or none, the final pass reads the color as it is, and FXAA smooths its edges. |
|
|
77
77
|
|
|
78
|
-
On every tier, the final pass also scales the image up to the canvas when the [render scale](quality-presets.md#dynamic-resolution) is below 1. It
|
|
78
|
+
On every tier, the final pass also scales the image up to the canvas when the [render scale](quality-presets.md#dynamic-resolution) is below 1. It then runs in two steps. The first applies FXAA, the tone curve and the sRGB encode at the render size. The second scales the image up to the canvas with GSR 1, an upscaler that keeps edges sharp ([The post-processing chain](post-processing.md#below-the-whole-canvass-render-scale)). WebGL2 and compatibility mode run Low or Medium, whose lowest render scale is below 1, so there the final pass usually runs.
|
|
79
79
|
|
|
80
80
|
High dynamic range (HDR) color keeps light brighter than white until the tone mapping. It needs a float target that the GPU can draw into, with 4 samples for MSAA. Compatibility mode allows no MSAA on 16-bit float targets, so there MSAA takes the 8-bit path, and FXAA and none keep HDR color. Some WebGL2 devices draw into no float target at all. On WebGL2, `engine.report.webgl2.floatRenderTargets` gives the result of the engine's test for `RGBA16F`, `RGBA32F` and `R11F_G11F_B10F`. The target must be complete and keep values above 1. For MSAA it must also take 4 samples.
|
|
81
81
|
|
|
@@ -127,7 +127,7 @@ The WebGPU path stays inside WebGPU's default limits, and inside compatibility m
|
|
|
127
127
|
|
|
128
128
|
| Limit | Budget |
|
|
129
129
|
| --- | --- |
|
|
130
|
-
| Bind groups | 4 (the engine uses
|
|
130
|
+
| Bind groups | 4 (the engine uses all 4) |
|
|
131
131
|
| Compute threads per workgroup | 128 |
|
|
132
132
|
| Uniform binding size | 16 KB |
|
|
133
133
|
| Color attachments | 4 |
|
|
@@ -167,7 +167,7 @@ On WebGL2, the engine compiles shader programs in the background where the brows
|
|
|
167
167
|
|
|
168
168
|
The switch `?half=on` makes the scene shaders do their color math at half precision, where the device can. It is off by default, and serves measurements. The switch `?hdr=off` makes the engine draw the 8-bit color path on a device that draws HDR color, so one device can test both. The switch `?scene-format=` picks the HDR scene color's format where the device can draw it. The value `rg11b10` takes the packed small float format of 4 bytes a pixel, and `rgba16f` takes 16-bit floats of 8 bytes. The small format keeps 6 bits of mantissa in red and green and 5 in blue, against 10 in a 16-bit float. On WebGL2 it serves measurements of its cost and of banding in dark gradients. Without the switch, WebGL2 keeps `RGBA16F`: on the phones measured, the small format drew no faster. The switch `?prepass=on` or `?prepass=off` turns the depth prepass on or off, and `?occlusion=on` or `?occlusion=off` turns GPU occlusion culling on or off.
|
|
169
169
|
|
|
170
|
-
The switch `?depth=` forces a WebGL2 depth mode: `reversed`, `reversed-gl` or `standard`,
|
|
170
|
+
The switch `?depth=` forces a WebGL2 depth mode: `reversed`, `reversed-gl` or `standard`, where the near plane stores 0 and the far plane 1. A browser without `EXT_clip_control` cannot draw `reversed`, so it draws its own mode instead. Shadow maps hold the same depth values as on WebGPU in `reversed` and `reversed-gl`. In `standard` they would hold them the other way around, so WebGL2 draws no shadows in that mode.
|
|
171
171
|
|
|
172
172
|
KTX2 textures take the compressed format of the first family that the device has: ASTC, BC7 or ETC2 by the file's data ([Textures](../api/textures.md#ktx2-files)). The switch `?compression=` keeps them to the families that it lists, such as `?compression=bc`, or to none with `?compression=none`. One device can then test the format of each kind of device.
|
|
173
173
|
|
|
@@ -175,6 +175,8 @@ KTX2 textures take the compressed format of the first family that the device has
|
|
|
175
175
|
|
|
176
176
|
A WebGPU device can be lost, for example after a driver reset, and so can a WebGL2 context. The thread that draws then makes a new device, or waits for the context to come back. It draws the whole scene again from data the engine kept. A texture from a file loads its file again. On a phone or a tablet the engine also keeps a copy of each texture's texels after their upload, so those maps come back too. The `keepTextureCopies` option of `createEngine` turns that on or off on any device ([Page API](../api/engine.md#options)). Keeping the copies costs about one more copy of each image in memory. Where no copy is kept, such a texture draws without its map until the sketch gives it texels again ([Textures](../api/textures.md#when-the-browser-takes-the-gpu-away)). The sketch worker keeps running, so your sketch's state survives. If the GPU is lost more than twice within one minute, or no new device starts, the engine stops drawing and reports E1302.
|
|
177
177
|
|
|
178
|
+
The engine also gives the GPU away itself while the browser keeps the page in its back-forward cache, where it keeps texture copies. A cached page would otherwise hold all its GPU memory, and on a phone with little memory the next page could lack it. When the page shows again, the thread that draws makes a new device and draws the scene again, as after a loss. This counts as no loss.
|
|
179
|
+
|
|
178
180
|
## Minimum browsers
|
|
179
181
|
|
|
180
182
|
| Browser | Minimum version |
|
|
@@ -3,7 +3,7 @@ id: concepts/color-management
|
|
|
3
3
|
title: Color management
|
|
4
4
|
status: experimental
|
|
5
5
|
since: "0.1"
|
|
6
|
-
summary: "Linear working space; sRGB hex colors and linear arrays; texture color spaces; HDR color; exposure and tone mapping; transparent canvases
|
|
6
|
+
summary: "Linear working space; sRGB hex colors and linear arrays; texture color spaces; HDR color; exposure and tone mapping; transparent canvases."
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
# Color management
|
|
@@ -20,7 +20,7 @@ flowchart LR
|
|
|
20
20
|
scene --> final["Final pass: tone mapping,<br/>sRGB encoding, dithering"] --> canvas[("Canvas")]
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
null3D works in linear color
|
|
23
|
+
null3D works in linear color. A color that you give as a hex string or a number is sRGB, the way CSS writes colors. The engine converts it to linear once, when the call receives it. A color that you give as three numbers is linear already.
|
|
24
24
|
|
|
25
25
|
Lighting adds and scales light in linear color, so a lit surface can be brighter than white. The scene therefore draws into a high dynamic range (HDR) target. Each light and each color of the scene comes in scaled by the exposure. At the end of each frame, a tone mapping curve maps it into the display's range. The final pass then encodes it as sRGB for the canvas.
|
|
26
26
|
|
|
@@ -40,7 +40,7 @@ const same = materials.standard({ color: [0.07, 0.26, 1] }); // the same color,
|
|
|
40
40
|
scene.createDirectionalLight({ color: '#fff4e0', intensity: 3 });
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
Three numbers are linear
|
|
43
|
+
Three numbers are linear. The color helpers give linear numbers too: `color.fromSrgb` converts sRGB components, and `color.fromHsl` reads a hue, a saturation and a lightness as linear RGB ([Math helpers](../api/math.md#colors)). A light's intensity multiplies its linear color. A color in any other form throws [E1204](../errors/E1204.md).
|
|
44
44
|
|
|
45
45
|
## Texture color spaces
|
|
46
46
|
|
|
@@ -64,7 +64,7 @@ The final pass reads each pixel of the scene color. In the FXAA anti-aliasing mo
|
|
|
64
64
|
|
|
65
65
|
### The 8-bit path
|
|
66
66
|
|
|
67
|
-
Some devices cannot draw a float target in the anti-aliasing mode. These are WebGPU in compatibility mode with MSAA, and WebGL2 devices whose float targets fail the engine's test. There, each shader applies the tone mapping itself, and writes into an 8-bit target. With MSAA that target
|
|
67
|
+
Some devices cannot draw a float target in the anti-aliasing mode. These are WebGPU in compatibility mode with MSAA, and WebGL2 devices whose float targets fail the engine's test. There, each shader applies the tone mapping itself, and writes into an 8-bit target. With MSAA that target can resolve straight into the canvas, with no final pass. That holds while the render scale cannot drop below 1 and no effect needs the final pass. Such effects are color grading, sharpening, outlines, transmission, screen-space reflections and the bounce light. So are soft particles, a material that reads the scene's depth, the moment transparency layer, and a full-screen pass that reads the scene color. The scene's shaders apply the vignette themselves there. Low and Medium let the render scale drop below 1, so there the final pass usually runs. With FXAA or no anti-aliasing, the final pass reads the target and keeps its colors.
|
|
68
68
|
|
|
69
69
|
Effects that need HDR color, such as bloom, move compatibility mode to HDR color with FXAA when a sketch turns them on. On a WebGL2 device with no float target they stay off. [The post-processing chain](post-processing.md#effects-on-devices-without-hdr-color) explains both.
|
|
70
70
|
|
|
@@ -72,7 +72,7 @@ Effects that need HDR color, such as bloom, move compatibility mode to HDR color
|
|
|
72
72
|
|
|
73
73
|
### Materials that keep their display color
|
|
74
74
|
|
|
75
|
-
A material with `toneMapped: false` keeps its color as the display shows it
|
|
75
|
+
A material with `toneMapped: false` keeps its color as the display shows it. Use it for a panel, a sign or another object whose colors are set for the screen, such as a heads-up display in the world.
|
|
76
76
|
|
|
77
77
|
The 8-bit path honours it in each material's own shader, which tone maps there: the shader encodes the color without the curve. The HDR path tone maps the whole image once, in its final pass. While a material keeps its display color, that pass also reads a mask of the surfaces whose material does so, and it skips the curve for those pixels. A blended surface keeps the curve on the HDR path, because a blended pixel mixes two surfaces and the mask cannot say which one owns it. Draw such a surface on the 8-bit path with `createEngine({ hdr: false })` if it needs the exact color. [The post-processing chain](post-processing.md) explains what else that path changes.
|
|
78
78
|
|
|
@@ -91,25 +91,25 @@ export default defineSketch(({ post }) => {
|
|
|
91
91
|
});
|
|
92
92
|
```
|
|
93
93
|
|
|
94
|
-
| `toneMapping` |
|
|
95
|
-
| --- | --- |
|
|
96
|
-
| `'agx-punchy'` (the default) |
|
|
97
|
-
| `'agx'` |
|
|
98
|
-
| `'aces'` |
|
|
99
|
-
| `'neutral'` |
|
|
100
|
-
| `'none'` |
|
|
94
|
+
| `toneMapping` | Look |
|
|
95
|
+
| --- | --- |
|
|
96
|
+
| `'agx-punchy'` (the default) | AgX with Filament's punchy look: more contrast and more color, with AgX's hues. |
|
|
97
|
+
| `'agx'` | Softer contrast. Bright colors fade toward white and keep their hue. |
|
|
98
|
+
| `'aces'` | Strong contrast, and the color is scaled by 1 / 0.6 first. Bright saturated colors change hue on their way to white: red turns orange, then yellow, and blue turns purple. |
|
|
99
|
+
| `'neutral'` | Base colors keep their values until they near white. Khronos made it for product images. |
|
|
100
|
+
| `'none'` | The exposed color, clipped at white. A bright color loses detail once a channel reaches white. |
|
|
101
101
|
|
|
102
102
|
Punchy AgX suits most scenes: bright lights and colors keep their hue, and the picture keeps its contrast. Plain AgX looks flatter. For a product view, where a material's color must show as its maker gave it, use `'neutral'`, as model-viewer does.
|
|
103
103
|
|
|
104
|
-
The exposure multiplies the scene's color before the tone mapping. An exposure of 2 is one stop brighter, and 0.5 is one stop darker. The engine applies it to each light and each color as they enter the scene. That gives the same picture as scaling the finished color, and keeps scenes in real units inside the range of the HDR target. [Lighting and environment](lighting.md#units-and-exposure) explains it.
|
|
104
|
+
The exposure multiplies the scene's color before the tone mapping. An exposure of 2 is one stop brighter, and 0.5 is one stop darker. The engine applies it to each light and each color as they enter the scene. That gives the same picture as scaling the finished color, and keeps scenes in real units inside the range of the HDR target. [Lighting and environment](lighting.md#units-and-exposure) explains it.
|
|
105
105
|
|
|
106
106
|
Automatic exposure adapts the picture to the scene's brightness over time, as an eye does. The scene still draws at the exposure that `exposure` and `ev100` set. A meter on the GPU then reads each frame, and the final pass multiplies the HDR color by the adapted exposure before the tone mapping. [The post-processing chain](post-processing.md#automatic-exposure) explains the meter.
|
|
107
107
|
|
|
108
108
|
## The background
|
|
109
109
|
|
|
110
|
-
The background color is part of the scene. Exposure and tone mapping change it as they change the objects
|
|
110
|
+
The background color is part of the scene. Exposure and tone mapping change it as they change the objects. The curves, for example, make dark colors a little darker. To show an exact page color behind the scene, use `toneMapping: 'none'` at an exposure of 1. You can also use a transparent canvas over a CSS background.
|
|
111
111
|
|
|
112
|
-
A [background texture](../api/scene.md#the-camera-and-the-background) draws into the scene color too, so exposure and tone mapping change it in the same way.
|
|
112
|
+
A [background texture](../api/scene.md#the-camera-and-the-background) draws into the scene color too, so exposure and tone mapping change it in the same way. To show the texture's own colors, use `toneMapping: 'none'` at an exposure of 1.
|
|
113
113
|
|
|
114
114
|
## Transparent canvases
|
|
115
115
|
|
|
@@ -123,17 +123,6 @@ const engine = await createEngine({
|
|
|
123
123
|
});
|
|
124
124
|
```
|
|
125
125
|
|
|
126
|
-
## Parity with three.js
|
|
127
|
-
|
|
128
|
-
- Hex colors, linear lighting and sRGB output work as in three.js r152 and later, where color management is on by default.
|
|
129
|
-
- Three numbers are linear, as `Color.setRGB` reads them.
|
|
130
|
-
- A color map with `texture.colorSpace = SRGBColorSpace` is a texture with an sRGB format in null3D.
|
|
131
|
-
- A data map with `NoColorSpace` or `LinearSRGBColorSpace` is a texture with a linear format.
|
|
132
|
-
- The tone mapping curves use three.js's formulas. The defaults differ: three.js uses no tone mapping, and null3D uses punchy AgX, which three.js lacks. A port of a scene with `AgXToneMapping` sets `toneMapping: 'agx'`. A port of a scene without tone mapping sets `toneMapping: 'none'`.
|
|
133
|
-
- three.js's `NoToneMapping` ignores the exposure. null3D's `'none'` applies it, as `LinearToneMapping` does, and an exposure of 1 gives the same image.
|
|
134
|
-
- three.js's WebGLRenderer draws a `scene.background` color without tone mapping. null3D tone maps the background, as three.js's WebGPURenderer does.
|
|
135
|
-
- null3D always dithers its output, and three.js only dithers materials that ask for it. The difference is at most one step of an 8-bit color.
|
|
136
|
-
|
|
137
126
|
## Related pages
|
|
138
127
|
|
|
139
128
|
- [Post-processing API](../api/post.md): `post.set` and each setting.
|
package/docs/concepts/culling.md
CHANGED
|
@@ -8,7 +8,7 @@ summary: "Frustum culling on the GPU on WebGPU, or on the job workers there when
|
|
|
8
8
|
|
|
9
9
|
# Culling
|
|
10
10
|
|
|
11
|
-
> Roadmap step 0.1, first released in null3D 0.1.0.
|
|
11
|
+
> Roadmap step 0.1, first released in null3D 0.1.0. The API is experimental, so it can still change between versions.
|
|
12
12
|
|
|
13
13
|
```mermaid
|
|
14
14
|
flowchart LR
|
|
@@ -8,7 +8,7 @@ summary: "createInstances; typed-array views; markDirty; automatic batching; per
|
|
|
8
8
|
|
|
9
9
|
# Instances and batching
|
|
10
10
|
|
|
11
|
-
> Roadmap step 0.1, first released in null3D 0.1.0.
|
|
11
|
+
> Roadmap step 0.1, first released in null3D 0.1.0. The API is experimental, so it can still change between versions.
|
|
12
12
|
|
|
13
13
|
```mermaid
|
|
14
14
|
flowchart LR
|
|
@@ -127,7 +127,7 @@ trees.rotations.set(q, 42 * 4);
|
|
|
127
127
|
trees.markDirty(42, 1); // recompute and upload row 42 only
|
|
128
128
|
```
|
|
129
129
|
|
|
130
|
-
A mark past the batch's capacity throws [E1108](../errors/E1108.md). Development builds check the rule. Before each batch update, they note the marked rows, and compare up to
|
|
130
|
+
A mark past the batch's capacity throws [E1108](../errors/E1108.md). Development builds check the rule. Before each batch update, they note the marked rows, and compare up to 4,096 drawn rows a frame, over all static batches, with the values they read before. The next frame takes the next rows, so the check finds a write within a few frames, and costs a bounded time per frame. A row that changed without a mark raises [E1110](../errors/E1110.md), which names the row. Sprite and point batches get the same check. Release builds leave it out. A dynamic batch needs no marks, because it recomputes every row in use in every frame. [Static and dynamic objects](static-dynamic.md) compares what each kind uploads.
|
|
131
131
|
|
|
132
132
|
## Rows that arrive in chunks
|
|
133
133
|
|
|
@@ -177,7 +177,7 @@ Keep each row's own data, such as a velocity, in your own typed arrays in the sa
|
|
|
177
177
|
|
|
178
178
|
## Culling
|
|
179
179
|
|
|
180
|
-
Each row has its own bounding sphere. The sphere's center is the row's position, and its radius is the mesh's radius times the row's largest scale. `setBoundingRadius(r)` gives one batch's rows a radius of their own
|
|
180
|
+
Each row has its own bounding sphere. The sphere's center is the row's position, and its radius is the mesh's radius times the row's largest scale. `setBoundingRadius(r)` gives one batch's rows a radius of their own. Use it for a vertex shader that moves rows far from their origins, as traffic along a lane does. Without it, the engine culls rows that are still on the screen. A call builds the engine's draw tables again, so make it at setup. The engine culls row by row in each view, and skips the rows outside the view. On WebGPU a compute pass on the GPU culls. On a device that draws directly, the job workers cull on the CPU there too. The rows of a batch whose material blends are the exception. On both paths, the job workers cull them one by one and sort them back to front. On WebGL2 the job workers cull. They test a static batch at rest in groups of 64 nearby rows, each group inside one grid cell. A group that is partly in view draws whole, and the GPU clips the rows outside. In a scene over several grid cells, both paths skip the rows of static batches in the cells out of view ([Culling](culling.md)). On WebGL2, a frame where you mark a static batch's rows tests the batch row by row, with no cell skipped. So does the frame after it.
|
|
181
181
|
|
|
182
182
|
## Automatic batching
|
|
183
183
|
|
|
@@ -196,7 +196,7 @@ Some calls change the scene's structure: creating or destroying a batch or an ob
|
|
|
196
196
|
## Limits
|
|
197
197
|
|
|
198
198
|
- Every row of a batch casts and receives shadows alike: give `castShadows` and `receiveShadows` to `createInstances`, or call `batch.setCastShadows(true)` and `batch.setReceiveShadows(true)`. Both are false by default. [Shadows](shadows.md) explains them. Sprite, point and line batches take no shadows.
|
|
199
|
-
- An engine holds up to
|
|
199
|
+
- An engine holds up to 512 instance batches, sprite, point and line batches included. One more throws [E1102](../errors/E1102.md).
|
|
200
200
|
- Every row counts toward the device's limit of objects and instance rows, whether it draws or not. `engine.capabilities.maxInstances` gives the limit. The places in the scene's object tables count toward it too, used or not. They start at 1,024 and double as the scene grows. So the batches of a scene hold at most the limit less those places. A `createInstances` call that would pass it throws [E1501](../errors/E1501.md).
|
|
201
201
|
- Each row takes about 210 bytes of engine memory, or about 300 with colors or values. When the engine cannot get more memory, `createInstances` throws [E1109](../errors/E1109.md). Rows with colors or values also take 32 bytes each of GPU memory.
|
|
202
202
|
- On WebGL2 the limit follows the largest texture the device allows. A device whose textures reach only 2,048 pixels, the least that WebGL2 allows, draws 1,048,576. That leaves 1,047,552 rows for batches beside a scene of up to 1,023 objects. [GPU tiers and backends](backends.md#the-portable-budget) gives the numbers.
|
|
@@ -271,7 +271,7 @@ Rows with colors or values draw with shader builds of their own, which a page do
|
|
|
271
271
|
|
|
272
272
|
### A row's place and its batch's id
|
|
273
273
|
|
|
274
|
-
A custom material also reads each row's place in its batch as `input.instance`, from 0, in its `vertexOffset` and `surface` functions
|
|
274
|
+
A custom material also reads each row's place in its batch as `input.instance`, from 0, in its `vertexOffset` and `surface` functions. It needs no `values` array: a hue, a phase or a size that follows from the row's place costs the sketch nothing. Every row reads its batch's id as `object.id`, which is `batch.shaderId` in the sketch. [Built-in shader inputs](../shaders/builtins.md#object) describes both.
|
|
275
275
|
|
|
276
276
|
## Related pages
|
|
277
277
|
|
|
@@ -108,7 +108,7 @@ Shaders work the same way. The surface input's `relativePosition` is relative to
|
|
|
108
108
|
|
|
109
109
|
The engine draws reversed depth in a 32-bit float buffer on every GPU path. The far plane stores 0, where floating-point numbers are most precise. So far surfaces stay apart over long view distances, which large scenes need. On WebGL2 without the `EXT_clip_control` extension, reversed depth keeps WebGL2's range from -1 to 1, which is less precise. [Depth on each tier](backends.md#depth-on-each-tier) gives the distances, and `engine.capabilities.depth` says which depth the device draws.
|
|
110
110
|
|
|
111
|
-
|
|
111
|
+
The engine does not use logarithmic depth, which writes depth from the fragment shader and so turns off the GPU's early depth test.
|
|
112
112
|
|
|
113
113
|
## Limits
|
|
114
114
|
|