@null3d/engine 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/wasm/single/null3d.js +10 -8
- package/dist/wasm/single/null3d_bg.wasm +0 -0
- package/dist/wasm/threaded/null3d.js +10 -8
- package/dist/wasm/threaded/null3d_bg.wasm +0 -0
- package/docs/api/animation.md +96 -24
- package/docs/api/assets.md +99 -29
- package/docs/api/cameras.md +38 -7
- package/docs/api/controls.md +47 -23
- package/docs/api/debug.md +105 -35
- package/docs/api/engine.md +108 -32
- package/docs/api/feature-draws.md +21 -15
- package/docs/api/feature-effects.md +8 -8
- package/docs/api/feature-instances.md +68 -17
- package/docs/api/features.md +68 -37
- package/docs/api/geometry.md +83 -14
- package/docs/api/grass.md +55 -13
- package/docs/api/impostors.md +92 -50
- package/docs/api/input.md +22 -9
- package/docs/api/lights.md +67 -16
- package/docs/api/lines.md +38 -13
- package/docs/api/materials.md +187 -59
- package/docs/api/math.md +6 -6
- package/docs/api/objects.md +40 -15
- package/docs/api/page.md +58 -7
- package/docs/api/particles.md +36 -11
- package/docs/api/points.md +18 -8
- package/docs/api/post.md +57 -23
- package/docs/api/quality.md +36 -16
- package/docs/api/raycast.md +57 -24
- package/docs/api/reference/animation.md +1 -2
- package/docs/api/reference/assets.md +7 -4
- package/docs/api/reference/cameras.md +3 -2
- package/docs/api/reference/controls.md +59 -2
- package/docs/api/reference/debug.md +58 -6
- package/docs/api/reference/engine.md +39 -10
- package/docs/api/reference/feature-draws.md +3 -4
- package/docs/api/reference/feature-effects.md +2 -3
- package/docs/api/reference/feature-instances.md +5 -4
- package/docs/api/reference/features.md +7 -4
- package/docs/api/reference/geometry.md +132 -21
- package/docs/api/reference/grass.md +62 -2
- package/docs/api/reference/impostors.md +120 -16
- package/docs/api/reference/input.md +1 -2
- package/docs/api/reference/lights.md +4 -3
- package/docs/api/reference/lines.md +3 -4
- package/docs/api/reference/materials.md +7 -6
- package/docs/api/reference/math.md +13 -2
- package/docs/api/reference/objects.md +2 -3
- package/docs/api/reference/particles.md +31 -6
- package/docs/api/reference/points.md +2 -3
- package/docs/api/reference/post.md +4 -3
- package/docs/api/reference/quality.md +1 -2
- package/docs/api/reference/raycast.md +1 -2
- package/docs/api/reference/render.md +4 -3
- package/docs/api/reference/scene.md +24 -5
- package/docs/api/reference/sketch.md +11 -11
- package/docs/api/reference/sound.md +33 -2
- package/docs/api/reference/splats.md +42 -3
- package/docs/api/reference/sprites.md +2 -3
- package/docs/api/reference/tasks.md +16 -3
- package/docs/api/reference/terrain.md +26 -5
- package/docs/api/reference/textures.md +1 -2
- package/docs/api/reference/three-compat.md +18 -7
- package/docs/api/reference/time.md +1 -2
- package/docs/api/reference/ui.md +10 -7
- package/docs/api/reference/vertex-draws.md +2 -3
- package/docs/api/reference/water.md +78 -5
- package/docs/api/reference/wind.md +15 -2
- package/docs/api/render.md +67 -25
- package/docs/api/scene.md +129 -36
- package/docs/api/sketch.md +45 -19
- package/docs/api/sound.md +48 -12
- package/docs/api/splats.md +42 -15
- package/docs/api/sprites.md +8 -6
- package/docs/api/tasks.md +31 -22
- package/docs/api/terrain.md +44 -12
- package/docs/api/textures.md +61 -12
- package/docs/api/three-compat.md +15 -7
- package/docs/api/time.md +3 -5
- package/docs/api/ui.md +18 -10
- package/docs/api/vertex-draws.md +13 -12
- package/docs/api/water.md +111 -67
- package/docs/api/wind.md +61 -15
- package/docs/cli/null3d.md +90 -15
- package/docs/concepts/architecture.md +69 -23
- package/docs/concepts/assets.md +57 -16
- package/docs/concepts/backends.md +65 -25
- package/docs/concepts/color-management.md +42 -13
- package/docs/concepts/culling.md +68 -47
- package/docs/concepts/handles.md +14 -5
- package/docs/concepts/instances.md +72 -23
- package/docs/concepts/large-worlds.md +17 -7
- package/docs/concepts/lighting.md +117 -44
- package/docs/concepts/lod.md +128 -33
- package/docs/concepts/materials.md +43 -12
- package/docs/concepts/particle-buffer.md +48 -35
- package/docs/concepts/post-processing.md +77 -14
- package/docs/concepts/quality-preset-tables.md +3 -2
- package/docs/concepts/quality-presets.md +122 -39
- package/docs/concepts/render-graph.md +56 -21
- package/docs/concepts/render-layers.md +9 -5
- package/docs/concepts/shadows.md +96 -25
- package/docs/concepts/static-dynamic.md +22 -7
- package/docs/cookbook/index.md +163 -119
- package/docs/data/threejs-mapping.json +301 -340
- package/docs/errors/E1101.md +23 -5
- package/docs/errors/E1102.md +11 -3
- package/docs/errors/E1103.md +11 -3
- package/docs/errors/E1104.md +11 -3
- package/docs/errors/E1105.md +13 -5
- package/docs/errors/E1106.md +11 -3
- package/docs/errors/E1107.md +15 -5
- package/docs/errors/E1108.md +11 -3
- package/docs/errors/E1109.md +32 -6
- package/docs/errors/E1110.md +23 -5
- package/docs/errors/E1111.md +11 -3
- package/docs/errors/E1112.md +11 -3
- package/docs/errors/E1203.md +12 -4
- package/docs/errors/E1204.md +11 -3
- package/docs/errors/E1205.md +11 -3
- package/docs/errors/E1206.md +28 -6
- package/docs/errors/E1207.md +11 -3
- package/docs/errors/E1208.md +12 -3
- package/docs/errors/E1209.md +11 -3
- package/docs/errors/E1213.md +27 -5
- package/docs/errors/E1214.md +11 -3
- package/docs/errors/E1215.md +31 -6
- package/docs/errors/E1216.md +31 -6
- package/docs/errors/E1217.md +29 -6
- package/docs/errors/E1218.md +22 -6
- package/docs/errors/E1219.md +11 -3
- package/docs/errors/E1220.md +24 -5
- package/docs/errors/E1221.md +24 -5
- package/docs/errors/E1222.md +11 -3
- package/docs/errors/E1223.md +39 -6
- package/docs/errors/E1224.md +11 -3
- package/docs/errors/E1225.md +11 -3
- package/docs/errors/E1301.md +11 -3
- package/docs/errors/E1302.md +11 -3
- package/docs/errors/E1303.md +11 -3
- package/docs/errors/E1304.md +11 -3
- package/docs/errors/E1305.md +13 -3
- package/docs/errors/E1306.md +11 -3
- package/docs/errors/E1307.md +23 -6
- package/docs/errors/E1401.md +11 -3
- package/docs/errors/E1402.md +13 -5
- package/docs/errors/E1403.md +11 -3
- package/docs/errors/E1404.md +13 -3
- package/docs/errors/E1405.md +15 -4
- package/docs/errors/E1406.md +31 -5
- package/docs/errors/E1407.md +11 -3
- package/docs/errors/E1408.md +11 -3
- package/docs/errors/E1409.md +11 -3
- package/docs/errors/E1410.md +13 -5
- package/docs/errors/E1411.md +11 -3
- package/docs/errors/E1412.md +29 -6
- package/docs/errors/E1413.md +11 -3
- package/docs/errors/E1414.md +11 -3
- package/docs/errors/E1415.md +11 -3
- package/docs/errors/E1416.md +27 -6
- package/docs/errors/E1417.md +11 -3
- package/docs/errors/E1418.md +12 -3
- package/docs/errors/E1419.md +13 -5
- package/docs/errors/E1420.md +11 -3
- package/docs/errors/E1421.md +11 -3
- package/docs/errors/E1422.md +12 -3
- package/docs/errors/E1423.md +12 -3
- package/docs/errors/E1424.md +24 -5
- package/docs/errors/E1425.md +11 -3
- package/docs/errors/E1426.md +11 -3
- package/docs/errors/E1430.md +11 -3
- package/docs/errors/E1431.md +11 -3
- package/docs/errors/E1432.md +11 -3
- package/docs/errors/E1433.md +11 -3
- package/docs/errors/E1434.md +15 -6
- package/docs/errors/E1435.md +11 -3
- package/docs/errors/E1436.md +11 -3
- package/docs/errors/E1437.md +14 -6
- package/docs/errors/E1501.md +41 -6
- package/docs/errors/E1502.md +13 -3
- package/docs/errors/E1503.md +11 -3
- package/docs/errors/E1504.md +11 -3
- package/docs/errors/E1505.md +23 -5
- package/docs/errors/E1506.md +11 -3
- package/docs/errors/index.md +52 -29
- package/docs/getting-started/cdn.md +15 -9
- package/docs/getting-started/first-scene.md +20 -12
- package/docs/getting-started/hosting.md +111 -63
- package/docs/getting-started/install.md +39 -24
- package/docs/getting-started/network-use.md +31 -21
- package/docs/getting-started/project-structure.md +20 -8
- package/docs/getting-started/third-party-notices.md +6 -10
- package/docs/guides/accessibility.md +4 -4
- package/docs/guides/add-ons.md +83 -13
- package/docs/guides/agents.md +2 -6
- package/docs/guides/assets-pipeline.md +248 -72
- package/docs/guides/audio.md +17 -15
- package/docs/guides/baked-light-data.md +44 -23
- package/docs/guides/car-paint.md +37 -31
- package/docs/guides/content-pages.md +53 -29
- package/docs/guides/custom-passes.md +59 -17
- package/docs/guides/custom-shaders.md +54 -37
- package/docs/guides/debugging.md +31 -41
- package/docs/guides/deploying.md +6 -27
- package/docs/guides/deterministic-simulation.md +23 -16
- package/docs/guides/first-use-shaders.md +83 -45
- package/docs/guides/lens-kit.md +29 -26
- package/docs/guides/loading-screens.md +70 -30
- package/docs/guides/multiple-views.md +22 -11
- package/docs/guides/performance.md +188 -37
- package/docs/guides/phones.md +71 -19
- package/docs/guides/physics.md +6 -10
- package/docs/guides/screens.md +41 -29
- package/docs/guides/start-time.md +120 -85
- package/docs/guides/testing.md +137 -98
- package/docs/guides/ui-overlays.md +17 -12
- package/docs/guides/video-textures.md +14 -13
- package/docs/images/api/animation/character.webp +0 -0
- package/docs/images/api/animation/look-at-ring.webp +0 -0
- package/docs/images/api/animation/morph-tulips.webp +0 -0
- package/docs/images/api/animation/skeleton-lines.webp +0 -0
- package/docs/images/api/controls/gizmo-handles.webp +0 -0
- package/docs/images/api/controls/walk-and-fly.webp +0 -0
- package/docs/images/api/debug/debug-shapes.webp +0 -0
- package/docs/images/api/debug/levels-view.webp +0 -0
- package/docs/images/api/engine/transparent-canvas.webp +0 -0
- package/docs/images/api/feature-draws/feature-draw-clouds.webp +0 -0
- package/docs/images/api/feature-instances/compute-instances.webp +0 -0
- package/docs/images/api/feature-instances/instances-shadow.webp +0 -0
- package/docs/images/api/geometry/extra-shapes.webp +0 -0
- package/docs/images/api/geometry/generators.webp +0 -0
- package/docs/images/api/geometry/mesh-arrays.webp +0 -0
- package/docs/images/api/geometry/vertex-updates.webp +0 -0
- package/docs/images/api/grass/grass-grove.webp +0 -0
- package/docs/images/api/grass/grass-presets.webp +0 -0
- package/docs/images/api/grass/grass-shadow.webp +0 -0
- package/docs/images/api/impostors/impostor-handover.webp +0 -0
- package/docs/images/api/impostors/impostor-shadow.webp +0 -0
- package/docs/images/api/impostors/impostors-forest.webp +0 -0
- package/docs/images/api/lights/spot-cookies.webp +0 -0
- package/docs/images/api/lines/lines-lit.webp +0 -0
- package/docs/images/api/lines/lines-widths.webp +0 -0
- package/docs/images/api/materials/coat-and-sheen.webp +0 -0
- package/docs/images/api/materials/decals.webp +0 -0
- package/docs/images/api/materials/iridescence-and-anisotropy.webp +0 -0
- package/docs/images/api/materials/relief.webp +0 -0
- package/docs/images/api/materials/shader-inputs.webp +0 -0
- package/docs/images/api/materials/standard-grid.webp +0 -0
- package/docs/images/api/materials/subsurface.webp +0 -0
- package/docs/images/api/materials/translucency.webp +0 -0
- package/docs/images/api/objects/objects-turntable.webp +0 -0
- package/docs/images/api/particles/campfire.webp +0 -0
- package/docs/images/api/points/galaxy.webp +0 -0
- package/docs/images/api/reference/textures/texture-wrap.webp +0 -0
- package/docs/images/api/render/fullscreen-glow.webp +0 -0
- package/docs/images/api/render/reflection-mirror.webp +0 -0
- package/docs/images/api/render/security-camera.webp +0 -0
- package/docs/images/api/scene/aurora-sky-layer.webp +0 -0
- package/docs/images/api/sound/sound-demo.webp +0 -0
- package/docs/images/api/splats/splats-demo.webp +0 -0
- package/docs/images/api/sprites/sprites-lines.webp +0 -0
- package/docs/images/api/terrain/terrain-demo.webp +0 -0
- package/docs/images/api/textures/canvas-screen.webp +0 -0
- package/docs/images/api/textures/mipmaps.webp +0 -0
- package/docs/images/api/vertex-draws/rain.webp +0 -0
- package/docs/images/api/water/ocean.webp +0 -0
- package/docs/images/api/water/water-demo.webp +0 -0
- package/docs/images/api/water/water-rain.webp +0 -0
- package/docs/images/api/water/waterfall.webp +0 -0
- package/docs/images/concepts/assets/gltf-model.webp +0 -0
- package/docs/images/concepts/color-management/tone-mapped.webp +0 -0
- package/docs/images/concepts/culling/far-from-origin.webp +0 -0
- package/docs/images/concepts/instances/instances.webp +0 -0
- package/docs/images/concepts/instances/per-row-colors.webp +0 -0
- package/docs/images/concepts/large-worlds/large-world.webp +0 -0
- package/docs/images/concepts/lighting/area-lights.webp +0 -0
- package/docs/images/concepts/lighting/atmosphere.webp +0 -0
- package/docs/images/concepts/lighting/environment.webp +0 -0
- package/docs/images/concepts/lighting/light-shafts.webp +0 -0
- package/docs/images/concepts/lighting/reflection-probes.webp +0 -0
- package/docs/images/concepts/lod/forest.webp +0 -0
- package/docs/images/concepts/materials/weighted-transparency.webp +0 -0
- package/docs/images/concepts/post-processing/auto-exposure.webp +0 -0
- package/docs/images/concepts/post-processing/bounce-light.webp +0 -0
- package/docs/images/concepts/post-processing/depth-of-field.webp +0 -0
- package/docs/images/concepts/post-processing/post-effects-alley.webp +0 -0
- package/docs/images/concepts/post-processing/sharpen.webp +0 -0
- package/docs/images/concepts/post-processing/ssr-wet-street.webp +0 -0
- package/docs/images/concepts/render-layers/layers-cottages.webp +0 -0
- package/docs/images/concepts/shadows/hero-shadow.webp +0 -0
- package/docs/images/cookbook/index/picking.webp +0 -0
- package/docs/images/cookbook/index/time-of-day.webp +0 -0
- package/docs/images/errors/E1431/area-lights-no-tables.webp +0 -0
- package/docs/images/guides/custom-passes/reflection-water.webp +0 -0
- package/docs/images/guides/deterministic-simulation/replay-demo.webp +0 -0
- package/docs/images/guides/multiple-views/split-screen.webp +0 -0
- package/docs/images/guides/performance/overdraw-view.webp +0 -0
- package/docs/images/guides/testing/hold-mode-frame.webp +0 -0
- package/docs/images/index/showcase-island.webp +0 -0
- package/docs/images/porting/threejs-shaders/dissolve.webp +0 -0
- package/docs/images/shaders/builtins/builtins.webp +0 -0
- package/docs/images/shaders/surface-functions/custom-surface.webp +0 -0
- package/docs/images/shaders/surface-functions/vertex-offset.webp +0 -0
- package/docs/images/shots.json +2231 -0
- package/docs/index.md +14 -23
- package/docs/moves.json +1 -0
- package/docs/nav.json +300 -0
- package/docs/pages.md +230 -212
- package/docs/porting/react-three-fiber.md +2 -6
- package/docs/porting/threejs-loop-and-threads.md +1 -5
- package/docs/porting/threejs-mapping.md +1248 -234
- package/docs/porting/threejs-materials.md +10 -5
- package/docs/porting/threejs-overview.md +26 -6
- package/docs/porting/threejs-postprocessing.md +2 -6
- package/docs/porting/threejs-shaders.md +16 -14
- package/docs/porting/threejs-unsupported.md +6 -6
- package/docs/porting/verification.md +0 -4
- package/docs/shaders/builtins.md +15 -4
- package/docs/shaders/library.md +9 -6
- package/docs/shaders/surface-functions.md +51 -16
- package/docs/shaders/wgsl-rules.md +12 -5
- package/lib/debug/debug.d.ts +2 -2
- package/lib/debug/draw.d.ts +2 -2
- package/lib/debug/draw.js +8 -4
- package/lib/debug/overlay-look.d.ts +6 -0
- package/lib/debug/overlay-look.js +29 -7
- package/lib/debug/overlay.js +15 -11
- package/lib/debug/stats-options.d.ts +13 -0
- package/lib/debug/stats-panel.d.ts +21 -6
- package/lib/debug/stats-panel.js +80 -13
- package/lib/errors/codes.d.ts +17 -3
- package/lib/errors/codes.js +111 -105
- package/lib/errors/fixes.js +18 -18
- package/lib/gpu/variants.d.ts +8 -2
- package/lib/gpu/variants.js +39 -7
- package/lib/gpu/webgl2/programs.js +1 -1
- package/lib/gpu/webgpu/pipelines.js +13 -13
- package/lib/index.d.ts +1 -1
- package/lib/page/capabilities.d.ts +1 -1
- package/lib/page/engine.d.ts +14 -5
- package/lib/page/engine.js +18 -2
- package/lib/page/label-loop.js +9 -4
- package/lib/page/stats-switch.js +2 -0
- package/lib/page/switches.d.ts +6 -4
- package/lib/page/switches.js +20 -4
- package/lib/scene/baked-light.d.ts +2 -2
- package/lib/scene/fake-call-values.js +2 -2
- package/lib/scene/frame-cameras.d.ts +16 -4
- package/lib/scene/frame-cameras.js +28 -10
- package/lib/scene/gltf.d.ts +1 -1
- package/lib/scene/level-rule.d.ts +6 -5
- package/lib/scene/level-rule.js +2 -2
- package/lib/scene/particles.d.ts +7 -3
- package/lib/scene/particles.js +3 -1
- package/lib/scene/post.d.ts +3 -2
- package/lib/scene/resources.d.ts +15 -9
- package/lib/scene/scene.d.ts +18 -2
- package/lib/scene/scene.js +47 -5
- package/lib/scene/time-of-day.d.ts +10 -5
- package/lib/scene/time-of-day.js +11 -7
- package/lib/shader-artifact.json +1 -1
- package/lib/shared/labels.d.ts +5 -2
- package/lib/shared/labels.js +5 -2
- package/lib/shared/permutation-words.d.ts +2 -0
- package/lib/shared/permutation-words.js +8 -0
- package/lib/shared/recording.d.ts +13 -5
- package/lib/shared/recording.js +31 -10
- package/lib/shared/sketch-data.d.ts +9 -0
- package/lib/shared/sketch-data.js +57 -0
- package/lib/shared/version.d.ts +1 -1
- package/lib/shared/version.js +1 -1
- package/lib/sketch/define-sketch.d.ts +16 -7
- package/lib/sketch/define-sketch.js +2 -1
- package/lib/sketch/runner.d.ts +4 -0
- package/lib/sketch/runner.js +5 -0
- package/lib/sketch/ui.js +4 -2
- package/lib/stats.d.ts +1 -0
- package/lib/workers/protocol.d.ts +10 -0
- package/lib/workers/render-worker.js +4 -1
- package/lib/workers/sketch-worker.js +4 -1
- package/package.json +1 -1
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: guides/baked-light-data
|
|
3
3
|
title: Baked light data
|
|
4
|
-
status: stable
|
|
5
|
-
since: "0.3"
|
|
6
4
|
summary: "One file format for probe grids and light maps baked outside the engine: the JSON members, base64 payloads, the loading calls, the engine's own bake, and the faults that the loader names."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Baked light data
|
|
10
8
|
|
|
11
|
-
>
|
|
9
|
+
> The format is stable: version 1 holds the members that this page lists.
|
|
12
10
|
|
|
13
11
|
```mermaid
|
|
14
12
|
flowchart LR
|
|
@@ -30,7 +28,7 @@ A file is JSON. Three members come first:
|
|
|
30
28
|
| `version` | The whole number `1`. A reader refuses any other version |
|
|
31
29
|
| `kind` | `probe-grid` or `light-map` |
|
|
32
30
|
|
|
33
|
-
The rest of the file depends on its kind. A reader ignores members that it does not know. A bake tool may write members that an earlier engine leaves out, and the file still reads. The `version` number changes only when a reader that predates the file would read it wrongly.
|
|
31
|
+
The rest of the file depends on its kind. A reader ignores members that it does not know. A bake tool may write members that an earlier engine leaves out, and the file still reads. The `version` number changes only when a reader that predates the file would read it wrongly.
|
|
34
32
|
|
|
35
33
|
The large values are base64. Decode them as bytes, not as text.
|
|
36
34
|
|
|
@@ -61,9 +59,18 @@ A probe grid file holds the values of `LightProbeGridData`. They are the grid's
|
|
|
61
59
|
| `validity` | Optional. Base64 of one 32-bit float for each probe, from 0 to 1 |
|
|
62
60
|
| `skyVisibility` | Optional. Base64 of one 32-bit float for each probe, from 0 to 1 |
|
|
63
61
|
|
|
64
|
-
The probes run x fastest, then y, then z. Each probe holds four RGB coefficients in the order that the shader reads them:
|
|
62
|
+
The probes run x fastest, then y, then z. Each probe holds four RGB coefficients in the order that the shader reads them:
|
|
65
63
|
|
|
66
|
-
|
|
64
|
+
- L0;
|
|
65
|
+
- L1 along y;
|
|
66
|
+
- L1 along z;
|
|
67
|
+
- L1 along x.
|
|
68
|
+
|
|
69
|
+
The 12 floats are three for L0 and three for each L1 axis. `bakeProbes` writes the same values. A bake that a tool makes therefore matches the engine's own bake for the same scene.
|
|
70
|
+
|
|
71
|
+
The coefficients hold the light that the surfaces around the probe bounce back. The validity is 1 where the probe stands in open space, or 0 where geometry encloses it, so its light never leaks through a wall.
|
|
72
|
+
|
|
73
|
+
The sky visibility is the share of the sky that the probe's rays reached. The engine weights it by how much a surface faces the sky above the horizon, and multiplies it by the environment's live light, so the hour needs no new bake.
|
|
67
74
|
|
|
68
75
|
A file without the two masks reads as one that baked the sky into its coefficients: every probe is valid, and no probe adds the live sky. A bake tool that writes version 1 without them therefore keeps the look that its coefficients alone give.
|
|
69
76
|
|
|
@@ -87,11 +94,11 @@ A file without the two masks reads as one that baked the sky into its coefficien
|
|
|
87
94
|
| `width`, `height` | The texels across and down: whole numbers of 1 or more |
|
|
88
95
|
| `encoding` | `rgb8`, three bytes per texel in sRGB, or `rgba16float`, eight bytes per texel as little-endian half floats in linear light |
|
|
89
96
|
| `radiance` | Base64 of the texels, rows along v from the first texel at u = 0, v = 0 |
|
|
90
|
-
| `direction` | Optional. Base64 of three signed bytes per texel, each axis of the
|
|
97
|
+
| `direction` | Optional. Base64 of three signed bytes per texel, from -127 to 127: each axis of the unit direction times 127, rounded. A reader divides each byte by 127 |
|
|
91
98
|
|
|
92
99
|
Use `rgba16float` for light above 1, such as a window or a lamp that the bake kept bright. It takes 8 bytes for each texel, against 3 for `rgb8`. A `direction` adds 3 bytes for each texel: a directional light map takes twice the memory of an `rgb8` radiance.
|
|
93
100
|
|
|
94
|
-
The direction is a unit vector in world space, and it points from the surface toward the light.
|
|
101
|
+
The direction is a unit vector in world space, and it points from the surface toward the light. The engine gives the direction a texture of its own, in the radiance's size and format, so the two share one texture array and one texture binding.
|
|
95
102
|
|
|
96
103
|
## Load a file
|
|
97
104
|
|
|
@@ -119,22 +126,16 @@ export default defineSketch(async ({ scene, assets, materials }) => {
|
|
|
119
126
|
|
|
120
127
|
`loadLightProbeGrid` gives the texture and the three placement values, so its result goes straight to `scene.setLightProbeGrid`. The grid replaces the environment's diffuse light, as a grid that `bakeProbes` made does.
|
|
121
128
|
|
|
122
|
-
`loadLightMap` gives a texture for a material's `lightMap`. A file with a `direction` also gives a `directionTexture`, which a material takes as `lightMapDirection`. The
|
|
129
|
+
`loadLightMap` gives a texture for a material's `lightMap`. A file with a `direction` also gives a `directionTexture`, which a material takes as `lightMapDirection`. The first load of either kind loads the reader, which is about 2 KB after Brotli. A page that reads no baked light file downloads none of it.
|
|
123
130
|
|
|
124
|
-
|
|
131
|
+
<details>
|
|
132
|
+
<summary>Technical details: the textures that the loader makes</summary>
|
|
125
133
|
|
|
126
|
-
|
|
134
|
+
The radiance texture is an `rgba8unorm` texture in sRGB, or an `rgba16float` texture in linear light. The file's three color bytes become three channels and an opaque fourth, because the engine has no three-channel texture format. The direction texture has the radiance's size and format, so a shader reads it through the light map's own binding. The weight costs one texture read and a few arithmetic operations for each pixel of a directional map, and a plain map pays a branch.
|
|
127
135
|
|
|
128
|
-
|
|
136
|
+
</details>
|
|
129
137
|
|
|
130
|
-
|
|
131
|
-
- The map reads the second texture coordinates. A mesh without a second set reads its first, as Needle's viewer does.
|
|
132
|
-
- The renderer's `lightmapScaleOffset` places the bake, and Needle's offset counts rows from the top, so the vertical offset flips in the engine.
|
|
133
|
-
- A skybox or reflection map that the extension registers is left out, and so is a pointer to a file that is not a texture of the model.
|
|
134
|
-
|
|
135
|
-
The loader makes a material for each node that places a light map of its own, so each bake lands where the file put it.
|
|
136
|
-
|
|
137
|
-
Both calls throw [E1434](../errors/E1434.md) for a file that the engine cannot read. The message names the fault. It may name a version that the engine does not read, or a payload that does not hold the count that the file gives. It may also name a file that a download cut short.
|
|
138
|
+
With `lightMapDirection`, the engine weights the light map at each pixel by how far the shaded normal turns toward the stored direction from the mesh's own normal. A normal map's relief then brightens where it faces the light of the bake and darkens where it turns away. A surface without a normal map keeps the light that the bake gave it.
|
|
138
139
|
|
|
139
140
|
## Save a grid that the engine baked
|
|
140
141
|
|
|
@@ -156,7 +157,7 @@ export default defineSketch(async ({ scene, assets }) => {
|
|
|
156
157
|
|
|
157
158
|
## What the loader checks
|
|
158
159
|
|
|
159
|
-
|
|
160
|
+
`loadLightProbeGrid` and `loadLightMap` throw [E1434](../errors/E1434.md) for a file whose contents do not agree with its own members. The message names the fault, which is one of these:
|
|
160
161
|
|
|
161
162
|
- a missing or wrong `format` member, or text that is not JSON;
|
|
162
163
|
- a `version` that this engine does not read;
|
|
@@ -171,6 +172,26 @@ A reader refuses a file whose contents do not agree with its own members. Each f
|
|
|
171
172
|
|
|
172
173
|
## Limits
|
|
173
174
|
|
|
174
|
-
- A grid takes at most 256 probes along x, 256 along y and 62 along z.
|
|
175
|
+
- A grid takes at most 256 probes along x, 256 along y and 62 along z.
|
|
175
176
|
- A light map's side is at most 4,096 texels, and one payload is at most 256 MiB, as every texture file is.
|
|
176
|
-
- The grid's texture takes 32 bytes of GPU memory for each probe,
|
|
177
|
+
- The grid's texture takes about 32 bytes of GPU memory for each probe, so a grid of 24 x 8 x 24 probes takes about 157 KiB. A light map's texture takes 4 bytes for each texel from `rgb8`, and 8 from `rgba16float`.
|
|
178
|
+
|
|
179
|
+
<details>
|
|
180
|
+
<summary>Technical details: how the grid's texture is laid out</summary>
|
|
181
|
+
|
|
182
|
+
The grid's texture is cut into four sub-volumes: three hold the coefficients, the first with the probe's own color and one direction's red, and the fourth holds the validity and the sky visibility. The z side carries a padding slice at either end of every sub-volume.
|
|
183
|
+
|
|
184
|
+
</details>
|
|
185
|
+
|
|
186
|
+
## Needle light maps
|
|
187
|
+
|
|
188
|
+
This path reads a glTF model's own light maps. It does not read a baked light file, and it throws no E1434 for one.
|
|
189
|
+
|
|
190
|
+
A model made for [Needle's viewer](https://engine.needle.tools/) carries its light maps in glTF's `NEEDLE_lightmaps` extension, and each node's `MeshRenderer` in `NEEDLE_components` names the map that it reads and the scale and offset that place the bake on its mesh. The loader gives each such node's material the map:
|
|
191
|
+
|
|
192
|
+
- The texture keeps the file's bytes, and the material decodes its RGBM texels: each color is multiplied by the texel's alpha times 8, then the sRGB transfer turns it linear. The texture is read in linear color for that reason.
|
|
193
|
+
- The map reads the second texture coordinates. A mesh without a second set reads its first, as Needle's viewer does.
|
|
194
|
+
- The renderer's `lightmapScaleOffset` places the bake, and Needle's offset counts rows from the top, so the vertical offset flips in the engine.
|
|
195
|
+
- A skybox or reflection map that the extension registers is left out, and so is a pointer to a file that is not a texture of the model.
|
|
196
|
+
|
|
197
|
+
The loader makes a material for each node that places a light map of its own, so each bake lands where the file put it.
|
package/docs/guides/car-paint.md
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: guides/car-paint
|
|
3
3
|
title: Car paint
|
|
4
|
-
|
|
5
|
-
since: "0.3"
|
|
6
|
-
summary: "A paint material over the clear coat, with glinting metal flakes that stop shimmering, panel seams that follow the pixel, and an optional carbon weave with direction-dependent shine."
|
|
4
|
+
summary: "An example add-on you copy: a paint material over the clear coat, with glinting metal flakes that stop shimmering, panel seams that follow the pixel, and an optional carbon weave with direction-dependent shine."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Car paint
|
|
10
8
|
|
|
11
|
-
> Roadmap step 0.3, first released in null3D 0.1.0. The API is experimental, so it can still change between versions.
|
|
12
|
-
|
|
13
9
|
The car paint draws a metallic base under a clear coat. Three parts change the look: metal flakes,
|
|
14
10
|
panel seams, and an optional carbon weave. Each part reads the mesh's texture coordinates, so the
|
|
15
11
|
paint fits any panel that has them.
|
|
@@ -25,25 +21,28 @@ flowchart LR
|
|
|
25
21
|
coat --> light
|
|
26
22
|
```
|
|
27
23
|
|
|
28
|
-
The paint is an example add-on in the repository, in the `examples/addons/car-paint` folder. It is
|
|
29
|
-
not an npm package. Copy the folder into your project and import its entry point.
|
|
24
|
+
The paint is an example add-on in the repository, in the `examples/addons/car-paint` folder. It is not an npm package. Copy the folder into your project and import its entry point. The null3D Vite plugin compiles the folder's WGSL file, as it does for your own shaders ([Add the Vite plugin](../getting-started/install.md#add-the-vite-plugin)). A page with no build step cannot use it.
|
|
30
25
|
|
|
31
26
|
## Use it
|
|
32
27
|
|
|
33
28
|
```ts
|
|
29
|
+
import { defineSketch } from '@null3d/engine';
|
|
34
30
|
import { createCarPaint } from './addons/car-paint';
|
|
35
31
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
32
|
+
export default defineSketch((ctx) => {
|
|
33
|
+
const paint = createCarPaint(ctx, {
|
|
34
|
+
color: '#9e0b16',
|
|
35
|
+
metalness: 0.72,
|
|
36
|
+
roughness: 0.34,
|
|
37
|
+
flakes: { cells: [120, 210], tilt: 0.25 },
|
|
38
|
+
seams: { spacing: [0.34, 0], width: 0.0022 },
|
|
39
|
+
clearcoat: 1,
|
|
40
|
+
clearcoatRoughness: 0.02,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// `body` is the car body's mesh, from your project's model or geometry.
|
|
44
|
+
ctx.scene.createMesh({ mesh: body, material: paint });
|
|
44
45
|
});
|
|
45
|
-
|
|
46
|
-
scene.createMesh({ mesh: body, material: paint });
|
|
47
46
|
```
|
|
48
47
|
|
|
49
48
|
## Options
|
|
@@ -57,7 +56,9 @@ scene.createMesh({ mesh: body, material: paint });
|
|
|
57
56
|
| `clearcoatRoughness` | The coat's perceptual roughness, from 0 to 1 | `0.02` |
|
|
58
57
|
| `flakes` | `{ cells, tilt, angle, max }`, or `false` | `{ cells: [120, 210], tilt: 0.25, angle: 0.25, max: 64 }` |
|
|
59
58
|
| `seams` | `{ spacing, width, shade }`, or `false` | `{ spacing: [0.34, 0], width: 0.0022, shade: 0.85 }` |
|
|
60
|
-
| `weave` | `{ cells, shine }`, or `false` | `false` |
|
|
59
|
+
| `weave` | `{ cells, shine }`, or `false` | `false`; a weave object starts from `{ cells: [90, 150], shine: 0.85 }` |
|
|
60
|
+
|
|
61
|
+
A part given as an object keeps the default for each field it leaves out.
|
|
61
62
|
|
|
62
63
|
- `flakes.cells` counts flake cells across each texture coordinate.
|
|
63
64
|
- `flakes.tilt` is how far the flakes' normals spread from the surface normal. It sets the width
|
|
@@ -70,19 +71,20 @@ scene.createMesh({ mesh: body, material: paint });
|
|
|
70
71
|
- `seams.spacing` gives the interval between seams along each texture coordinate. A value of 0
|
|
71
72
|
draws no seam along that coordinate.
|
|
72
73
|
- `seams.width` is the groove's half width in the texture coordinates.
|
|
74
|
+
- `seams.shade` is how dark the groove draws, from 0 for none to 1 for black.
|
|
73
75
|
- `weave.cells` counts weave cells across each texture coordinate.
|
|
74
76
|
- `weave.shine` is how strongly a tow's rounded cross-section shapes its highlight, from 0 to 1.
|
|
75
77
|
|
|
76
78
|
## How the parts draw
|
|
77
79
|
|
|
78
|
-
The **flakes** are the metal's microfacets, drawn with the glint model of Deliot and Belcour.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
80
|
+
The **flakes** are the metal's microfacets, drawn with the glint model of Deliot and Belcour. A pixel whose flakes miss the light draws no highlight, and one where a flake catches it draws a bright spot. A car far away draws as smooth metal, without shimmering as it moves. The spot stays where the light reflects, so the sparkle follows each light as the car turns. The clear coat keeps its own smooth normal, so the flakes never disturb the coat's reflection.
|
|
81
|
+
|
|
82
|
+
<details>
|
|
83
|
+
<summary>Technical details: the glint model</summary>
|
|
84
|
+
|
|
85
|
+
Each pixel covers a number of flake cells. The paint counts how many of the flakes in that footprint reflect a light into the eye, and uses that count in place of the smooth highlight. The count's average is the smooth lobe, so a car far away draws as smooth metal.
|
|
86
|
+
|
|
87
|
+
</details>
|
|
86
88
|
|
|
87
89
|
The model replaces the base highlight of the main directional light and of each point and spot
|
|
88
90
|
light. Area lights draw their own smooth highlight, with no glints.
|
|
@@ -97,11 +99,14 @@ their own way. The gaps between the tows draw darker and rougher.
|
|
|
97
99
|
|
|
98
100
|
## Cost
|
|
99
101
|
|
|
100
|
-
The
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
102
|
+
The flakes add a small cost for each light. The seams and the weave add a small cost for each pixel. A material without flakes, seams or a weave draws the same surface as a plain metallic paint.
|
|
103
|
+
|
|
104
|
+
<details>
|
|
105
|
+
<summary>Technical details: what each part costs</summary>
|
|
106
|
+
|
|
107
|
+
The paint pays for the clear coat's lobe. The flakes cost the footprint's derivatives and one hash for each pixel, and the lobe adds two hashes and a short sum of terms for each pixel and each light that reaches it. The seams cost a few derivatives for each pixel. The weave adds its own pattern, slope and roughness change.
|
|
108
|
+
|
|
109
|
+
</details>
|
|
105
110
|
|
|
106
111
|
## Limits
|
|
107
112
|
|
|
@@ -119,3 +124,4 @@ plain metallic paint.
|
|
|
119
124
|
glints use.
|
|
120
125
|
- [The Showroom to street demo](https://github.com/null3d-engine/null3d/tree/main/examples/showroom): a
|
|
121
126
|
car that uses the paint.
|
|
127
|
+
- [How the parts draw](https://github.com/null3d-engine/null3d/tree/main/examples/coat-and-sheen): a clear coat, rain rings and sheen in one rainy showroom.
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: guides/content-pages
|
|
3
3
|
title: 3D scenes on content pages
|
|
4
|
-
status: experimental
|
|
5
|
-
since: "0.1"
|
|
6
4
|
summary: "Product and marketing pages: the fallback page, a load deadline, pausing off screen, scroll-driven cameras, second visits and crashes."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# 3D scenes on content pages
|
|
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
|
On a product page or a marketing page, the visitor came for the page. The 3D scene supports it. So the page must work without the scene, show its content on time, and spend nothing on a scene that nobody can see.
|
|
14
10
|
|
|
15
11
|
A game or a full-screen app is different, because there the scene is the product. Each section says where its advice changes for such pages.
|
|
@@ -85,6 +81,8 @@ try {
|
|
|
85
81
|
|
|
86
82
|
For a game, the late state has no page content to show. There it changes the message, and opens the menus and settings that do not need the scene.
|
|
87
83
|
|
|
84
|
+
Later page blocks run after a successful start, inside that `try`.
|
|
85
|
+
|
|
88
86
|
## Mark a decorative canvas
|
|
89
87
|
|
|
90
88
|
A scene that only decorates gets `aria-hidden="true"`, so screen readers skip it. It takes no keyboard focus. Give it `pointer-events: none` when it does not react to the pointer, so clicks reach the page. [Accessibility](accessibility.md) covers a canvas the visitor operates.
|
|
@@ -124,51 +122,77 @@ When the page also has a pause button, or pauses for reduced motion, combine the
|
|
|
124
122
|
|
|
125
123
|
## Drive the camera from the scroll position
|
|
126
124
|
|
|
127
|
-
The page reads the scroll position, and the sketch moves the camera.
|
|
125
|
+
The page reads the scroll position, and the sketch moves the camera. Pass the first position as [start data](../api/page.md#start-data), so the first frame already shows it. A held frame of a page that opens partway down then shows it too. After the start, send the position only when it changes, at most once per animation frame:
|
|
128
126
|
|
|
129
127
|
```ts
|
|
130
128
|
// page.ts
|
|
129
|
+
const progress = () => {
|
|
130
|
+
const range = Math.max(1, document.documentElement.scrollHeight - window.innerHeight);
|
|
131
|
+
return Math.min(1, Math.max(0, window.scrollY / range));
|
|
132
|
+
};
|
|
133
|
+
const engine = await createEngine({
|
|
134
|
+
canvas,
|
|
135
|
+
sketch: new URL('./sketch.ts', import.meta.url),
|
|
136
|
+
sketchData: { scroll: progress() }, // the first frame's position
|
|
137
|
+
});
|
|
131
138
|
let queued = false;
|
|
132
139
|
const sendScroll = () => {
|
|
133
140
|
queued = false;
|
|
134
|
-
|
|
135
|
-
const progress = window.scrollY / range;
|
|
136
|
-
engine.postToSketch('scroll', Math.min(1, Math.max(0, progress)));
|
|
141
|
+
engine.postToSketch('scroll', progress());
|
|
137
142
|
};
|
|
138
143
|
window.addEventListener('scroll', () => {
|
|
139
144
|
if (!queued) requestAnimationFrame(sendScroll);
|
|
140
145
|
queued = true;
|
|
141
146
|
}, { passive: true });
|
|
142
|
-
sendScroll(); //
|
|
147
|
+
sendScroll(); // a position that the browser restored during the start
|
|
143
148
|
```
|
|
144
149
|
|
|
145
|
-
The sketch eases toward
|
|
150
|
+
The sketch starts at the start data's position, and eases toward each later one. Its easing factor depends on the frame's time step, so the motion looks the same at 60 and at 144 frames per second. The browser can restore the scroll position after the start, so the sketch jumps to the first position it receives. A page that opens scrolled down then never shows a camera flight. The page reveals the canvas once `engine.firstFrame` resolves:
|
|
146
151
|
|
|
147
152
|
```ts
|
|
148
153
|
// sketch.ts
|
|
149
|
-
|
|
150
|
-
let
|
|
151
|
-
let
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
154
|
+
export default defineSketch<{ scroll: number }>(({ data, page, preferences }) => {
|
|
155
|
+
let target = data?.scroll ?? 0;
|
|
156
|
+
let current = target;
|
|
157
|
+
let placed = false;
|
|
158
|
+
let toldPage = false;
|
|
159
|
+
page.onMessage((type, value) => {
|
|
160
|
+
if (type !== 'scroll') return;
|
|
161
|
+
target = value as number;
|
|
162
|
+
if (!placed) current = target;
|
|
157
163
|
placed = true;
|
|
158
|
-
|
|
159
|
-
|
|
164
|
+
});
|
|
165
|
+
return {
|
|
166
|
+
onUpdate(dt) {
|
|
167
|
+
// Closes 99.9% of the gap in one second, at any frame rate.
|
|
168
|
+
const k = preferences.reducedMotion ? 1 : 1 - Math.pow(0.001, dt);
|
|
169
|
+
current += (target - current) * k;
|
|
170
|
+
if (Math.abs(target - current) < 0.0001) current = target;
|
|
171
|
+
placeCamera(current);
|
|
172
|
+
if (!toldPage) {
|
|
173
|
+
toldPage = true;
|
|
174
|
+
page.post('placed');
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
};
|
|
160
178
|
});
|
|
161
|
-
return {
|
|
162
|
-
onUpdate(dt) {
|
|
163
|
-
// Closes 99.9% of the gap in one second, at any frame rate.
|
|
164
|
-
const k = preferences.reducedMotion ? 1 : 1 - Math.pow(0.001, dt);
|
|
165
|
-
current += (target - current) * k;
|
|
166
|
-
if (Math.abs(target - current) < 0.0001) current = target;
|
|
167
|
-
placeCamera(current);
|
|
168
|
-
},
|
|
169
|
-
};
|
|
170
179
|
```
|
|
171
180
|
|
|
181
|
+
The sketch posts `placed` once, after it first places the camera. The page then waits for both that message and the first frame:
|
|
182
|
+
|
|
183
|
+
```ts
|
|
184
|
+
// page.ts
|
|
185
|
+
const placed = new Promise<void>((resolve) =>
|
|
186
|
+
engine.onSketchMessage((type) => { if (type === 'placed') resolve(); }),
|
|
187
|
+
);
|
|
188
|
+
await Promise.all([engine.firstFrame, placed]);
|
|
189
|
+
root.classList.add('ready');
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
A page without scroll-driven cameras awaits only `engine.firstFrame`.
|
|
193
|
+
|
|
194
|
+
A canvas behind the page's text often wants its subject beside the text, not under it. Shift the lens rather than turn the camera: `camera.setLensShift(-0.25, 0)` puts the camera's target three quarters of the way across, and upright lines stay upright. A section can change the shift as the scroll moves, in the same `onUpdate` ([Cameras](../api/cameras.md#lens-shift)).
|
|
195
|
+
|
|
172
196
|
## Second visits and navigation
|
|
173
197
|
|
|
174
198
|
| Lifetime | What keeps it | How |
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: guides/custom-passes
|
|
3
3
|
title: Custom passes and render targets
|
|
4
|
-
status: experimental
|
|
5
|
-
since: "0.2"
|
|
6
4
|
summary: "Custom effects and tone curves in WGSL; declaring passes; reading and writing named textures; layer masks; reflections and a water recipe; full-screen passes, a soft outline glow and effects that read textures."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Custom passes and render targets
|
|
10
8
|
|
|
11
|
-
> Roadmap step 0.2, first released in null3D 0.1.0. The API is experimental, so it can still change between versions.
|
|
12
|
-
|
|
13
9
|
```mermaid
|
|
14
10
|
flowchart LR
|
|
15
11
|
scene["Scene passes:<br/>linear HDR color"] --> e1["Effect 1"]
|
|
@@ -22,7 +18,16 @@ flowchart LR
|
|
|
22
18
|
final --> canvas["Canvas"]
|
|
23
19
|
```
|
|
24
20
|
|
|
25
|
-
A custom
|
|
21
|
+
A custom pass adds work of your own to the frame. This page covers six kinds:
|
|
22
|
+
|
|
23
|
+
| Kind | Reads | Writes | Section |
|
|
24
|
+
| --- | --- | --- | --- |
|
|
25
|
+
| Custom effect | The scene's color, and its depth if it asks | A new color for the screen | [Custom effects](#custom-effects) |
|
|
26
|
+
| Custom tone curve | Linear color after bloom | The final display color | [Custom tone curves](#custom-tone-curves) |
|
|
27
|
+
| Scene pass | The scene, from a camera of its own | A texture that materials show | [Render to a texture](#render-to-a-texture) |
|
|
28
|
+
| Reflection pass | The scene, mirrored across a plane | A texture that materials read | [Reflections](#reflections) |
|
|
29
|
+
| Full-screen pass | An effect's WGSL, and an input image | A texture of its own | [Full-screen passes](#full-screen-passes) |
|
|
30
|
+
| Compute pass | A compute shader | A storage texture | [Compute passes](#compute-passes) |
|
|
26
31
|
|
|
27
32
|
## Custom effects
|
|
28
33
|
|
|
@@ -84,7 +89,7 @@ Effects import from the shader library as materials do, such as `#import null3d:
|
|
|
84
89
|
|
|
85
90
|
### Uniforms
|
|
86
91
|
|
|
87
|
-
Declare uniforms as `struct Uniforms`, and read them as `uniforms.name`.
|
|
92
|
+
Declare uniforms as `struct Uniforms`, and read them as `uniforms.name`. A custom material reads its own as `material.name`, but the other rules are the same:
|
|
88
93
|
|
|
89
94
|
- The types are `f32`, `i32`, `u32`, `vec2f`, `vec3f` and `vec4f`, in at most 32 numbers. Each `vec3f` and `vec4f` starts a group of four.
|
|
90
95
|
- A `vec3f` also takes a color string or a hex number, which the engine converts from sRGB to linear.
|
|
@@ -213,15 +218,21 @@ For caustics on the bed, find each pixel's point in the world as `eye + line.xyz
|
|
|
213
218
|
### Cost
|
|
214
219
|
|
|
215
220
|
- A full-screen pass reads and writes 8 bytes per pixel of the render size, in `rgba16float`. On a phone at full resolution each pass costs tens of megabytes of memory traffic per frame. One pass at full size costs about 0.05 ms of GPU time on a MacBook Pro, 0.1 ms on an iPad Pro with the A12X, and 0.25 to 0.31 ms on a Pixel 10.
|
|
216
|
-
- The engine joins effects
|
|
221
|
+
- The engine joins effects at every render scale. An effect that reads only its own pixel joins the pass of the effect before it: the pass runs both, one after the other, for each pixel. So you need not join such effects into one function yourself.
|
|
222
|
+
- The last pass of effects folds into the final pass only in frames at the whole canvas's scale, with bloom, depth of field and FXAA off. While the scale can drop below the whole canvas, nothing folds, even in a frame at scale 1 ([The post-processing chain](../concepts/post-processing.md#below-the-whole-canvass-render-scale)).
|
|
223
|
+
- Adding or removing an effect changes the frame's passes. A new effect's pipeline builds while the last image stays on screen, as a custom material's does. So a new effect shows a few frames after `addEffect`. To show it at a set moment, add it a little before.
|
|
224
|
+
|
|
225
|
+
<details>
|
|
226
|
+
<summary>Technical details: how the engine joins and folds effects</summary>
|
|
227
|
+
|
|
217
228
|
- An effect that calls `effectPixel` or `effectColor` reads other pixels of the color before it. So it starts a pass of its own. The effects after it can join it. Depth reads do not stop an effect from joining.
|
|
218
|
-
- The last pass of effects folds into the final pass when nothing reads the image between them. That needs bloom and FXAA off, and it needs the render scale to stay at the whole canvas: while the scale can drop below it, nothing folds, also in frames that draw at scale 1. One effect that reads only its own pixel then costs no pass of its own.
|
|
219
229
|
- A joined pass needs a shader that the engine makes from the effects' WGSL. It builds in the background after the effects' own shaders. Until it is built, each effect draws a pass of its own, so no frame waits for it.
|
|
220
230
|
- Some browsers cannot compile WebGL2 shaders in the background, such as Chrome on the Android phones tested. On WebGL2 they join only the effects that are there before the first frame. Effects added or reordered later draw a pass each there. A joined shader would hold up a frame while it compiles. Add your effects before the first frame to get the joined passes on those devices. Development builds tell you once in the console when this happens.
|
|
221
231
|
- Between joined effects the color keeps 32-bit precision instead of the 16 bits of a target. So the image can differ from separate passes in the last bits.
|
|
222
232
|
- The effects share two targets, whatever their number. They follow the render scale, so a new scale makes no new target.
|
|
223
233
|
- A depth read costs one texture read per call. The scene's render pass then keeps its depth in memory.
|
|
224
|
-
|
|
234
|
+
|
|
235
|
+
</details>
|
|
225
236
|
|
|
226
237
|
### Devices without HDR color
|
|
227
238
|
|
|
@@ -251,6 +262,8 @@ post.set({ toneMapping: 'aces' });
|
|
|
251
262
|
- A curve needs HDR color, as effects do. On a device with no HDR target, the built-in curve stays.
|
|
252
263
|
- The final pass builds again with the curve, so the first frame with a new curve waits for its pipeline.
|
|
253
264
|
|
|
265
|
+
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.
|
|
266
|
+
|
|
254
267
|
## Render to a texture
|
|
255
268
|
|
|
256
269
|
A scene pass draws the scene from a camera of your own into a texture. `textures.fromPass` gives the texture to any material or sprite.
|
|
@@ -303,21 +316,43 @@ A pass that need not change every frame draws every few frames. `setPassEvery` g
|
|
|
303
316
|
render.setPassEvery(map, 4);
|
|
304
317
|
```
|
|
305
318
|
|
|
306
|
-
|
|
319
|
+
`setPassEvery` compiles nothing, so a sketch may change the cadence as often as once a frame, for example when the quality preset or the frame budget moves. In a frame that the pass skips, a material that samples its texture shows the last image that it drew.
|
|
320
|
+
|
|
321
|
+
`render.setPassEnabled(pass, false)` turns a pass off, and its texture keeps its last image. Use the switch when a feature starts or stops, and the cadence to draw less often. Switching on a pass that has never drawn compiles the render graph. [Switching and removing passes](../api/render.md#switching-and-removing-passes) gives the full rule.
|
|
322
|
+
|
|
323
|
+
<details>
|
|
324
|
+
<summary>Technical details: cadence, the switch and the compiled plan</summary>
|
|
325
|
+
|
|
326
|
+
The engine compiles the render graph into a plan of GPU passes. A skipped frame neither culls nor clears the pass's target. A pass that has never drawn is out of the plan while it is off, so switching it on compiles the graph. Once a pass has drawn, its GPU passes stay in the plan while it is off: the switch only skips their recording and compiles nothing. [Render graph](../concepts/render-graph.md) explains the plan.
|
|
327
|
+
|
|
328
|
+
</details>
|
|
307
329
|
|
|
308
330
|
In [hold mode](testing.md#hold-mode) every pass draws in every frame, whatever its cadence. The engine draws only the hold's last frames, so a pass that skipped one of them would show an image that no drawn frame made: an empty mirror, for one.
|
|
309
331
|
|
|
310
332
|
### What a scene pass draws
|
|
311
333
|
|
|
312
|
-
A scene pass draws with the scene's materials, the sun and its shadows where the camera's shadow cascades reach. It draws
|
|
334
|
+
A scene pass draws with the scene's materials, the sun and its shadows where the camera's shadow cascades reach. It draws:
|
|
335
|
+
|
|
336
|
+
- the ambient and hemisphere lights, the environment's light and the fog;
|
|
337
|
+
- the point and spot lights that its camera sees;
|
|
338
|
+
- the scene's background behind them, the sky included.
|
|
339
|
+
|
|
340
|
+
With a `clearColor` the texture clears to that color and shows no background, which suits a minimap. A pass draws no ambient occlusion.
|
|
341
|
+
|
|
342
|
+
A point or spot light casts its shadow in a pass when the camera's view gives it a shadow. The engine gives shadows only to the lights that the camera sees. So a light that only the pass sees lights the pass without a shadow.
|
|
343
|
+
|
|
344
|
+
<details>
|
|
345
|
+
<summary>Technical details: lights and shadows in a scene pass</summary>
|
|
313
346
|
|
|
314
|
-
|
|
347
|
+
Reflection passes draw these lights the same way. A pass that sees a point or spot light keeps its own list of lights, as the camera's view does. The list takes under 1 MB of memory. A pass that sees none keeps no list.
|
|
348
|
+
|
|
349
|
+
</details>
|
|
315
350
|
|
|
316
351
|
The texture holds linear color after the exposure, so a material that shows it gives the camera the light that the pass saw. On devices that draw 8-bit color, each material tone maps its own color. In compatibility mode with MSAA, the texture holds that color turned back to linear, so the tone curve applies twice and the image looks a little lighter in the middle tones. On WebGL2 devices without float targets, the texture holds display color, which looks brighter and flatter.
|
|
317
352
|
|
|
318
353
|
## Reflections
|
|
319
354
|
|
|
320
|
-
A reflection pass draws the camera's view mirrored across a plane into a texture. Everything below the plane is clipped. A custom material reads the texture where its surface shows on the screen, so water and polished floors reflect what stands on them. [Render graph API](../api/render.md#reflection-passes) lists the options, and [Surface functions](../shaders/surface-functions.md#reflections) the WGSL side.
|
|
355
|
+
A reflection pass draws the camera's view mirrored across a plane into a texture. Everything below the plane is clipped. A custom material reads the texture where its surface shows on the screen, so water and polished floors reflect what stands on them. [Render graph API](../api/render.md#reflection-passes) lists the options, and [Surface functions](../shaders/surface-functions.md#reflections) the WGSL side. The [water demo](https://github.com/null3d-engine/null3d/tree/main/examples/water) uses the add-on's reflection for a river and a lake.
|
|
321
356
|
|
|
322
357
|
```ts
|
|
323
358
|
const pass = render.addPass({ kind: 'reflection', writes: 'water', plane: { point: [0, 0, 0] } });
|
|
@@ -333,7 +368,13 @@ const water = materials.shader({ wgsl: waterWgsl, textures: { mirror: textures.f
|
|
|
333
368
|
|
|
334
369
|
For water in a scene, use [`@null3d/water`](../api/water.md): it draws a river and a lake from one shape, with the waves, the foam, the soft shore and the reflection that this recipe builds by hand. This recipe shows the pieces that the add-on builds on, for a water surface of your own.
|
|
335
370
|
|
|
336
|
-
|
|
371
|
+

|
|
372
|
+
|
|
373
|
+
A reflection pass read by a water material.
|
|
374
|
+
|
|
375
|
+
This surface function makes a stream. It has ripples that move, a tint that deepens with the depth, foam at the banks, and the reflection of the banks and the sky.
|
|
376
|
+
|
|
377
|
+
It needs the height of the bed under each point of the water. A terrain made in code gives it with the same function that shapes the terrain. A loaded terrain gives it with a height map texture, which the function samples instead.
|
|
337
378
|
|
|
338
379
|
```ts
|
|
339
380
|
const waterWgsl = /* wgsl */ `
|
|
@@ -418,8 +459,7 @@ surface.setRotationEuler(-Math.PI / 2, 0, 0);
|
|
|
418
459
|
- `ripple` sets how far the waves tilt the normal. The tilt bends the reflection and the sun's highlights.
|
|
419
460
|
- The foam hides the reflection where it lies, through the reflection's share in `a`.
|
|
420
461
|
- The water is opaque, so the bed does not show through it. The shallow tint stands in for the bed's color.
|
|
421
|
-
- Without a height map of the bed, a blended sheet
|
|
422
|
-
|
|
462
|
+
- Without a height map of the bed, a blended sheet can read the scene's depth with `sceneInputs: ['sceneDepth']` and fade its alpha near the bank for a soft shore. [Materials](../api/materials.md#the-scene-behind-a-surface) shows the WGSL.
|
|
423
463
|
- Waves that move the surface's vertices need `setBounds`, as [Culling](../concepts/culling.md) explains. The reflection's plane stays flat, which suits small waves.
|
|
424
464
|
|
|
425
465
|
## Full-screen passes
|
|
@@ -504,7 +544,7 @@ post.addEffect({ wgsl: addGlow, textures: { glow: textures.fromPass(glow) } });
|
|
|
504
544
|
|
|
505
545
|
## Compute passes
|
|
506
546
|
|
|
507
|
-
A compute pass runs a compute shader over a texture of its own, on WebGPU. Use one when the work suits a GPU's parallel threads better than a pixel: a wave simulation that combines each pixel with its neighbors, a table that the shader fills in a loop, or a field that several materials read. [Render graph API](../api/render.md#compute-passes) lists its options and the bindings that its shader declares.
|
|
547
|
+
A compute pass runs a compute shader over a texture of its own, on WebGPU. Use one when the work suits a GPU's parallel threads better than a pixel: a wave simulation that combines each pixel with its neighbors, a table that the shader fills in a loop, or a field that several materials read. [Render graph API](../api/render.md#compute-passes) lists its options and the bindings that its shader declares. The [Ocean demo](https://github.com/null3d-engine/null3d/tree/main/examples/ocean) runs compute passes through the water add-on.
|
|
508
548
|
|
|
509
549
|
```ts
|
|
510
550
|
const ripples = /* wgsl */ `
|
|
@@ -581,6 +621,8 @@ const water = materials.unlit({ map: textures.fromPass(field) });
|
|
|
581
621
|
- [Post-processing API](../api/post.md): `post.addEffect`, `post.setEffectUniform`, `post.removeEffect` and `post.set`.
|
|
582
622
|
- [Render graph API](../api/render.md): `render.addPass`, `render.setPassUniform`, `render.setPassEnabled`, `render.removePass` and `render.dumpGraph`.
|
|
583
623
|
- [The security camera demo](https://github.com/null3d-engine/null3d/tree/main/examples/security-camera): a scene pass whose texture a monitor shows.
|
|
624
|
+
- [The post effects demo](https://github.com/null3d-engine/null3d/tree/main/examples/post-effects): its effect code lives in `examples/addons/lens-kit/`, which the demo imports.
|
|
625
|
+
- [The custom shader inputs demo](https://github.com/null3d-engine/null3d/tree/main/examples/shader-inputs): a custom material's shader, uniforms and textures.
|
|
584
626
|
- [The post-processing chain](../concepts/post-processing.md): where effects run, and the built-in effects.
|
|
585
627
|
- [Custom shaders](custom-shaders.md): the WGSL build, uniforms and the shader library.
|
|
586
628
|
- [Porting post-processing](../porting/threejs-postprocessing.md): three.js's `ShaderPass` and effect passes.
|