@null3d/engine 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/wasm/single/null3d.js +10 -8
- package/dist/wasm/single/null3d_bg.wasm +0 -0
- package/dist/wasm/threaded/null3d.js +10 -8
- package/dist/wasm/threaded/null3d_bg.wasm +0 -0
- package/docs/api/animation.md +96 -24
- package/docs/api/assets.md +99 -29
- package/docs/api/cameras.md +38 -7
- package/docs/api/controls.md +47 -23
- package/docs/api/debug.md +105 -35
- package/docs/api/engine.md +108 -32
- package/docs/api/feature-draws.md +21 -15
- package/docs/api/feature-effects.md +8 -8
- package/docs/api/feature-instances.md +68 -17
- package/docs/api/features.md +68 -37
- package/docs/api/geometry.md +83 -14
- package/docs/api/grass.md +55 -13
- package/docs/api/impostors.md +92 -50
- package/docs/api/input.md +22 -9
- package/docs/api/lights.md +67 -16
- package/docs/api/lines.md +38 -13
- package/docs/api/materials.md +187 -59
- package/docs/api/math.md +6 -6
- package/docs/api/objects.md +40 -15
- package/docs/api/page.md +58 -7
- package/docs/api/particles.md +36 -11
- package/docs/api/points.md +18 -8
- package/docs/api/post.md +57 -23
- package/docs/api/quality.md +36 -16
- package/docs/api/raycast.md +57 -24
- package/docs/api/reference/animation.md +1 -2
- package/docs/api/reference/assets.md +7 -4
- package/docs/api/reference/cameras.md +3 -2
- package/docs/api/reference/controls.md +59 -2
- package/docs/api/reference/debug.md +58 -6
- package/docs/api/reference/engine.md +40 -10
- package/docs/api/reference/feature-draws.md +3 -4
- package/docs/api/reference/feature-effects.md +2 -3
- package/docs/api/reference/feature-instances.md +5 -4
- package/docs/api/reference/features.md +7 -4
- package/docs/api/reference/geometry.md +132 -21
- package/docs/api/reference/grass.md +62 -2
- package/docs/api/reference/impostors.md +120 -16
- package/docs/api/reference/input.md +1 -2
- package/docs/api/reference/lights.md +4 -3
- package/docs/api/reference/lines.md +3 -4
- package/docs/api/reference/materials.md +7 -6
- package/docs/api/reference/math.md +13 -2
- package/docs/api/reference/objects.md +2 -3
- package/docs/api/reference/particles.md +31 -6
- package/docs/api/reference/points.md +2 -3
- package/docs/api/reference/post.md +4 -3
- package/docs/api/reference/quality.md +1 -2
- package/docs/api/reference/raycast.md +1 -2
- package/docs/api/reference/render.md +4 -3
- package/docs/api/reference/scene.md +24 -5
- package/docs/api/reference/sketch.md +11 -11
- package/docs/api/reference/sound.md +33 -2
- package/docs/api/reference/splats.md +42 -3
- package/docs/api/reference/sprites.md +2 -3
- package/docs/api/reference/tasks.md +16 -3
- package/docs/api/reference/terrain.md +26 -5
- package/docs/api/reference/textures.md +1 -2
- package/docs/api/reference/three-compat.md +18 -7
- package/docs/api/reference/time.md +1 -2
- package/docs/api/reference/ui.md +10 -7
- package/docs/api/reference/vertex-draws.md +2 -3
- package/docs/api/reference/water.md +78 -5
- package/docs/api/reference/wind.md +15 -2
- package/docs/api/render.md +67 -25
- package/docs/api/scene.md +129 -36
- package/docs/api/sketch.md +45 -19
- package/docs/api/sound.md +48 -12
- package/docs/api/splats.md +42 -15
- package/docs/api/sprites.md +8 -6
- package/docs/api/tasks.md +31 -22
- package/docs/api/terrain.md +44 -12
- package/docs/api/textures.md +61 -12
- package/docs/api/three-compat.md +15 -7
- package/docs/api/time.md +3 -5
- package/docs/api/ui.md +18 -10
- package/docs/api/vertex-draws.md +13 -12
- package/docs/api/water.md +111 -67
- package/docs/api/wind.md +61 -15
- package/docs/cli/null3d.md +90 -15
- package/docs/concepts/architecture.md +69 -23
- package/docs/concepts/assets.md +57 -16
- package/docs/concepts/backends.md +68 -24
- package/docs/concepts/color-management.md +42 -13
- package/docs/concepts/culling.md +68 -47
- package/docs/concepts/handles.md +14 -5
- package/docs/concepts/instances.md +72 -23
- package/docs/concepts/large-worlds.md +17 -7
- package/docs/concepts/lighting.md +117 -44
- package/docs/concepts/lod.md +128 -33
- package/docs/concepts/materials.md +43 -12
- package/docs/concepts/particle-buffer.md +48 -35
- package/docs/concepts/post-processing.md +77 -14
- package/docs/concepts/quality-preset-tables.md +3 -2
- package/docs/concepts/quality-presets.md +122 -39
- package/docs/concepts/render-graph.md +56 -21
- package/docs/concepts/render-layers.md +9 -5
- package/docs/concepts/shadows.md +96 -25
- package/docs/concepts/static-dynamic.md +22 -7
- package/docs/cookbook/index.md +163 -119
- package/docs/data/threejs-mapping.json +301 -340
- package/docs/errors/E1101.md +23 -5
- package/docs/errors/E1102.md +11 -3
- package/docs/errors/E1103.md +11 -3
- package/docs/errors/E1104.md +11 -3
- package/docs/errors/E1105.md +13 -5
- package/docs/errors/E1106.md +11 -3
- package/docs/errors/E1107.md +15 -5
- package/docs/errors/E1108.md +11 -3
- package/docs/errors/E1109.md +32 -6
- package/docs/errors/E1110.md +23 -5
- package/docs/errors/E1111.md +11 -3
- package/docs/errors/E1112.md +11 -3
- package/docs/errors/E1203.md +12 -4
- package/docs/errors/E1204.md +11 -3
- package/docs/errors/E1205.md +11 -3
- package/docs/errors/E1206.md +28 -6
- package/docs/errors/E1207.md +11 -3
- package/docs/errors/E1208.md +12 -3
- package/docs/errors/E1209.md +11 -3
- package/docs/errors/E1213.md +27 -5
- package/docs/errors/E1214.md +11 -3
- package/docs/errors/E1215.md +31 -6
- package/docs/errors/E1216.md +31 -6
- package/docs/errors/E1217.md +29 -6
- package/docs/errors/E1218.md +22 -6
- package/docs/errors/E1219.md +11 -3
- package/docs/errors/E1220.md +24 -5
- package/docs/errors/E1221.md +24 -5
- package/docs/errors/E1222.md +11 -3
- package/docs/errors/E1223.md +39 -6
- package/docs/errors/E1224.md +11 -3
- package/docs/errors/E1225.md +11 -3
- package/docs/errors/E1301.md +11 -3
- package/docs/errors/E1302.md +11 -3
- package/docs/errors/E1303.md +11 -3
- package/docs/errors/E1304.md +11 -3
- package/docs/errors/E1305.md +13 -3
- package/docs/errors/E1306.md +11 -3
- package/docs/errors/E1307.md +23 -6
- package/docs/errors/E1308.md +31 -0
- package/docs/errors/E1401.md +11 -3
- package/docs/errors/E1402.md +13 -5
- package/docs/errors/E1403.md +11 -3
- package/docs/errors/E1404.md +13 -3
- package/docs/errors/E1405.md +15 -4
- package/docs/errors/E1406.md +31 -5
- package/docs/errors/E1407.md +11 -3
- package/docs/errors/E1408.md +11 -3
- package/docs/errors/E1409.md +11 -3
- package/docs/errors/E1410.md +13 -5
- package/docs/errors/E1411.md +11 -3
- package/docs/errors/E1412.md +29 -6
- package/docs/errors/E1413.md +11 -3
- package/docs/errors/E1414.md +11 -3
- package/docs/errors/E1415.md +11 -3
- package/docs/errors/E1416.md +27 -6
- package/docs/errors/E1417.md +11 -3
- package/docs/errors/E1418.md +12 -3
- package/docs/errors/E1419.md +13 -5
- package/docs/errors/E1420.md +11 -3
- package/docs/errors/E1421.md +11 -3
- package/docs/errors/E1422.md +12 -3
- package/docs/errors/E1423.md +12 -3
- package/docs/errors/E1424.md +24 -5
- package/docs/errors/E1425.md +11 -3
- package/docs/errors/E1426.md +11 -3
- package/docs/errors/E1430.md +11 -3
- package/docs/errors/E1431.md +11 -3
- package/docs/errors/E1432.md +11 -3
- package/docs/errors/E1433.md +11 -3
- package/docs/errors/E1434.md +15 -6
- package/docs/errors/E1435.md +11 -3
- package/docs/errors/E1436.md +11 -3
- package/docs/errors/E1437.md +14 -6
- package/docs/errors/E1501.md +41 -6
- package/docs/errors/E1502.md +13 -3
- package/docs/errors/E1503.md +11 -3
- package/docs/errors/E1504.md +11 -3
- package/docs/errors/E1505.md +23 -5
- package/docs/errors/E1506.md +11 -3
- package/docs/errors/index.md +53 -29
- package/docs/getting-started/cdn.md +15 -9
- package/docs/getting-started/first-scene.md +20 -12
- package/docs/getting-started/hosting.md +113 -63
- package/docs/getting-started/install.md +39 -24
- package/docs/getting-started/network-use.md +31 -21
- package/docs/getting-started/project-structure.md +20 -8
- package/docs/getting-started/third-party-notices.md +6 -10
- package/docs/guides/accessibility.md +4 -4
- package/docs/guides/add-ons.md +83 -13
- package/docs/guides/agents.md +13 -14
- package/docs/guides/assets-pipeline.md +294 -72
- package/docs/guides/audio.md +17 -15
- package/docs/guides/baked-light-data.md +44 -23
- package/docs/guides/car-paint.md +37 -31
- package/docs/guides/content-pages.md +86 -29
- package/docs/guides/custom-passes.md +59 -17
- package/docs/guides/custom-shaders.md +54 -37
- package/docs/guides/debugging.md +31 -41
- package/docs/guides/deploying.md +10 -27
- package/docs/guides/deterministic-simulation.md +23 -16
- package/docs/guides/first-use-shaders.md +83 -45
- package/docs/guides/lens-kit.md +29 -26
- package/docs/guides/loading-screens.md +74 -30
- package/docs/guides/multiple-views.md +22 -11
- package/docs/guides/performance.md +188 -37
- package/docs/guides/phones.md +71 -19
- package/docs/guides/physics.md +6 -10
- package/docs/guides/screens.md +41 -29
- package/docs/guides/start-time.md +126 -85
- package/docs/guides/testing.md +137 -98
- package/docs/guides/ui-overlays.md +17 -12
- package/docs/guides/video-textures.md +14 -13
- package/docs/images/api/animation/character.webp +0 -0
- package/docs/images/api/animation/look-at-ring.webp +0 -0
- package/docs/images/api/animation/morph-tulips.webp +0 -0
- package/docs/images/api/animation/skeleton-lines.webp +0 -0
- package/docs/images/api/controls/gizmo-handles.webp +0 -0
- package/docs/images/api/controls/walk-and-fly.webp +0 -0
- package/docs/images/api/debug/debug-shapes.webp +0 -0
- package/docs/images/api/debug/levels-view.webp +0 -0
- package/docs/images/api/engine/transparent-canvas.webp +0 -0
- package/docs/images/api/feature-draws/feature-draw-clouds.webp +0 -0
- package/docs/images/api/feature-instances/compute-instances.webp +0 -0
- package/docs/images/api/feature-instances/instances-shadow.webp +0 -0
- package/docs/images/api/geometry/extra-shapes.webp +0 -0
- package/docs/images/api/geometry/generators.webp +0 -0
- package/docs/images/api/geometry/mesh-arrays.webp +0 -0
- package/docs/images/api/geometry/vertex-updates.webp +0 -0
- package/docs/images/api/grass/grass-grove.webp +0 -0
- package/docs/images/api/grass/grass-presets.webp +0 -0
- package/docs/images/api/grass/grass-shadow.webp +0 -0
- package/docs/images/api/impostors/impostor-handover.webp +0 -0
- package/docs/images/api/impostors/impostor-shadow.webp +0 -0
- package/docs/images/api/impostors/impostors-forest.webp +0 -0
- package/docs/images/api/lights/spot-cookies.webp +0 -0
- package/docs/images/api/lines/lines-lit.webp +0 -0
- package/docs/images/api/lines/lines-widths.webp +0 -0
- package/docs/images/api/materials/coat-and-sheen.webp +0 -0
- package/docs/images/api/materials/decals.webp +0 -0
- package/docs/images/api/materials/iridescence-and-anisotropy.webp +0 -0
- package/docs/images/api/materials/relief.webp +0 -0
- package/docs/images/api/materials/shader-inputs.webp +0 -0
- package/docs/images/api/materials/standard-grid.webp +0 -0
- package/docs/images/api/materials/subsurface.webp +0 -0
- package/docs/images/api/materials/translucency.webp +0 -0
- package/docs/images/api/objects/objects-turntable.webp +0 -0
- package/docs/images/api/particles/campfire.webp +0 -0
- package/docs/images/api/points/galaxy.webp +0 -0
- package/docs/images/api/reference/textures/texture-wrap.webp +0 -0
- package/docs/images/api/render/fullscreen-glow.webp +0 -0
- package/docs/images/api/render/reflection-mirror.webp +0 -0
- package/docs/images/api/render/security-camera.webp +0 -0
- package/docs/images/api/scene/aurora-sky-layer.webp +0 -0
- package/docs/images/api/sound/sound-demo.webp +0 -0
- package/docs/images/api/splats/splats-demo.webp +0 -0
- package/docs/images/api/sprites/sprites-lines.webp +0 -0
- package/docs/images/api/terrain/terrain-demo.webp +0 -0
- package/docs/images/api/textures/canvas-screen.webp +0 -0
- package/docs/images/api/textures/mipmaps.webp +0 -0
- package/docs/images/api/vertex-draws/rain.webp +0 -0
- package/docs/images/api/water/ocean.webp +0 -0
- package/docs/images/api/water/water-demo.webp +0 -0
- package/docs/images/api/water/water-rain.webp +0 -0
- package/docs/images/api/water/waterfall.webp +0 -0
- package/docs/images/concepts/assets/gltf-model.webp +0 -0
- package/docs/images/concepts/color-management/tone-mapped.webp +0 -0
- package/docs/images/concepts/culling/far-from-origin.webp +0 -0
- package/docs/images/concepts/instances/instances.webp +0 -0
- package/docs/images/concepts/instances/per-row-colors.webp +0 -0
- package/docs/images/concepts/large-worlds/large-world.webp +0 -0
- package/docs/images/concepts/lighting/area-lights.webp +0 -0
- package/docs/images/concepts/lighting/atmosphere.webp +0 -0
- package/docs/images/concepts/lighting/environment.webp +0 -0
- package/docs/images/concepts/lighting/light-shafts.webp +0 -0
- package/docs/images/concepts/lighting/reflection-probes.webp +0 -0
- package/docs/images/concepts/lod/forest.webp +0 -0
- package/docs/images/concepts/materials/weighted-transparency.webp +0 -0
- package/docs/images/concepts/post-processing/auto-exposure.webp +0 -0
- package/docs/images/concepts/post-processing/bounce-light.webp +0 -0
- package/docs/images/concepts/post-processing/depth-of-field.webp +0 -0
- package/docs/images/concepts/post-processing/post-effects-alley.webp +0 -0
- package/docs/images/concepts/post-processing/sharpen.webp +0 -0
- package/docs/images/concepts/post-processing/ssr-wet-street.webp +0 -0
- package/docs/images/concepts/render-layers/layers-cottages.webp +0 -0
- package/docs/images/concepts/shadows/hero-shadow.webp +0 -0
- package/docs/images/cookbook/index/picking.webp +0 -0
- package/docs/images/cookbook/index/time-of-day.webp +0 -0
- package/docs/images/errors/E1431/area-lights-no-tables.webp +0 -0
- package/docs/images/guides/custom-passes/reflection-water.webp +0 -0
- package/docs/images/guides/deterministic-simulation/replay-demo.webp +0 -0
- package/docs/images/guides/multiple-views/split-screen.webp +0 -0
- package/docs/images/guides/performance/overdraw-view.webp +0 -0
- package/docs/images/guides/testing/hold-mode-frame.webp +0 -0
- package/docs/images/index/showcase-island.webp +0 -0
- package/docs/images/porting/threejs-shaders/dissolve.webp +0 -0
- package/docs/images/shaders/builtins/builtins.webp +0 -0
- package/docs/images/shaders/surface-functions/custom-surface.webp +0 -0
- package/docs/images/shaders/surface-functions/vertex-offset.webp +0 -0
- package/docs/images/shots.json +2231 -0
- package/docs/index.md +14 -23
- package/docs/moves.json +1 -0
- package/docs/nav.json +300 -0
- package/docs/pages.md +230 -212
- package/docs/porting/react-three-fiber.md +2 -6
- package/docs/porting/threejs-loop-and-threads.md +1 -5
- package/docs/porting/threejs-mapping.md +1248 -234
- package/docs/porting/threejs-materials.md +10 -5
- package/docs/porting/threejs-overview.md +26 -6
- package/docs/porting/threejs-postprocessing.md +2 -6
- package/docs/porting/threejs-shaders.md +16 -14
- package/docs/porting/threejs-unsupported.md +6 -6
- package/docs/porting/verification.md +0 -4
- package/docs/shaders/builtins.md +15 -4
- package/docs/shaders/library.md +9 -6
- package/docs/shaders/surface-functions.md +51 -16
- package/docs/shaders/wgsl-rules.md +12 -5
- package/lib/debug/debug.d.ts +2 -2
- package/lib/debug/draw.d.ts +2 -2
- package/lib/debug/draw.js +8 -4
- package/lib/debug/overlay-look.d.ts +6 -0
- package/lib/debug/overlay-look.js +29 -7
- package/lib/debug/overlay.js +15 -11
- package/lib/debug/stats-options.d.ts +13 -0
- package/lib/debug/stats-panel.d.ts +21 -6
- package/lib/debug/stats-panel.js +80 -13
- package/lib/errors/codes.d.ts +17 -3
- package/lib/errors/codes.js +116 -105
- package/lib/errors/engine-error.js +1 -1
- package/lib/errors/fixes.d.ts +1 -0
- package/lib/errors/fixes.js +19 -18
- package/lib/generated/shader-permutations.d.ts +6 -0
- package/lib/generated/shader-permutations.js +6 -0
- package/lib/gpu/variants.d.ts +8 -2
- package/lib/gpu/variants.js +39 -7
- package/lib/gpu/webgl2/programs.js +1 -1
- package/lib/gpu/webgpu/pipelines.js +13 -13
- package/lib/index.d.ts +1 -1
- package/lib/page/capabilities.d.ts +1 -1
- package/lib/page/engine.d.ts +29 -7
- package/lib/page/engine.js +79 -7
- package/lib/page/label-loop.js +9 -4
- package/lib/page/stats-switch.js +2 -0
- package/lib/page/switches.d.ts +6 -4
- package/lib/page/switches.js +20 -4
- package/lib/scene/baked-light.d.ts +2 -2
- package/lib/scene/fake-call-values.js +2 -2
- package/lib/scene/frame-cameras.d.ts +16 -4
- package/lib/scene/frame-cameras.js +28 -10
- package/lib/scene/gltf.d.ts +1 -1
- package/lib/scene/level-rule.d.ts +6 -5
- package/lib/scene/level-rule.js +2 -2
- package/lib/scene/particles.d.ts +7 -3
- package/lib/scene/particles.js +3 -1
- package/lib/scene/post.d.ts +3 -2
- package/lib/scene/resources.d.ts +15 -9
- package/lib/scene/scene.d.ts +18 -2
- package/lib/scene/scene.js +47 -5
- package/lib/scene/time-of-day.d.ts +10 -5
- package/lib/scene/time-of-day.js +11 -7
- package/lib/shader-artifact.json +1 -1
- package/lib/shared/labels.d.ts +5 -2
- package/lib/shared/labels.js +5 -2
- package/lib/shared/permutation-words.d.ts +8 -0
- package/lib/shared/permutation-words.js +14 -0
- package/lib/shared/recording.d.ts +13 -5
- package/lib/shared/recording.js +31 -10
- package/lib/shared/sketch-data.d.ts +9 -0
- package/lib/shared/sketch-data.js +57 -0
- package/lib/shared/tier.d.ts +9 -0
- package/lib/shared/tier.js +4 -1
- package/lib/shared/version.d.ts +1 -1
- package/lib/shared/version.js +1 -1
- package/lib/sketch/define-sketch.d.ts +16 -7
- package/lib/sketch/define-sketch.js +2 -1
- package/lib/sketch/runner.d.ts +4 -0
- package/lib/sketch/runner.js +5 -0
- package/lib/sketch/ui.js +4 -2
- package/lib/stats.d.ts +1 -0
- package/lib/workers/protocol.d.ts +10 -0
- package/lib/workers/render-worker.js +4 -1
- package/lib/workers/sketch-worker.js +4 -1
- package/package.json +1 -1
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: concepts/lighting
|
|
3
3
|
title: Lighting and environment
|
|
4
|
-
status: experimental
|
|
5
|
-
since: "0.1"
|
|
6
4
|
summary: "Light types, units and exposure; clustered lighting; fog; environment maps and spherical harmonics; light probe grids; sky and environment backgrounds; the sky's light and time of day."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Lighting and environment
|
|
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. Surfaces show up to four directional lights. The quality presets cap area lights, and they do not cap point and spot lights.
|
|
12
|
-
|
|
13
9
|
```mermaid
|
|
14
10
|
flowchart LR
|
|
15
11
|
sketch["Sketch code<br/>createPointLight, setIntensity"] --> object["Light object<br/>position, rotation, parent"]
|
|
@@ -30,16 +26,20 @@ Every light is a scene object with a row in the engine's light table. The object
|
|
|
30
26
|
Setters change the engine's memory at once. They write their numbers into a block of the engine's memory, and they call the core with whole numbers only. So a setter allocates nothing, a color included. Call a per-frame setter from a small function of its own, so the browser inlines it. Each frame, after the engine updates transforms, it reads every light:
|
|
31
27
|
|
|
32
28
|
1. It skips a light that is hidden by itself or a parent, or whose layer mask shares no bit with the camera's.
|
|
33
|
-
2. Standard materials reflect
|
|
29
|
+
2. Standard materials reflect up to four of the remaining directional lights, as [Kinds of light and their units](#kinds-of-light-and-their-units) explains, plus the sum of the ambient and hemisphere lights and the scene's environment.
|
|
34
30
|
3. It tests the sphere of each point, spot and area light's range against the camera's view, and lists the lights whose spheres reach into it.
|
|
35
31
|
4. Each listed light goes into the clusters of the view that its sphere reaches. On WebGPU the GPU does this work, and on WebGL2 the job workers do it, as [Clustered forward shading](#clustered-forward-shading) explains.
|
|
36
32
|
|
|
37
|
-
A scene pass ([Custom passes](../guides/custom-passes.md))
|
|
33
|
+
A scene pass ([Custom passes](../guides/custom-passes.md)) runs steps 3 and 4 again for its own camera and layers, with its own light grid ([Lights in scene passes](#lights-in-scene-passes)).
|
|
38
34
|
|
|
39
35
|
## Kinds of light and their units
|
|
40
36
|
|
|
41
37
|
Each kind of light takes its intensity in a physical unit:
|
|
42
38
|
|
|
39
|
+

|
|
40
|
+
|
|
41
|
+
Rectangle and tube lights.
|
|
42
|
+
|
|
43
43
|
| Light | What it models | Intensity | `intensityUnit` |
|
|
44
44
|
| --- | --- | --- | --- |
|
|
45
45
|
| Directional | The sun or the moon: parallel light from one direction | Lux: the light that reaches a surface facing it | `'lux'` |
|
|
@@ -73,7 +73,7 @@ export default defineSketch(({ scene }) => {
|
|
|
73
73
|
});
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
-
Up to four directional lights light a frame. The first one created that
|
|
76
|
+
Up to four directional lights light a frame. The first one created that is not hidden and shares a layer with the camera casts the shadows, when it has `castShadows`. The next three light surfaces as fill and rim lights, and cast none. A fifth directional light gives no light. Each fill light adds one direct light term to every lit pixel, and no shadow reads.
|
|
77
77
|
|
|
78
78
|
## Units and exposure
|
|
79
79
|
|
|
@@ -91,7 +91,9 @@ flowchart LR
|
|
|
91
91
|
|
|
92
92
|
Most scenes give small intensities, such as 3 for a bright sun, with an exposure of 1. A scene can also give its lights real values. A real sun gives about 100,000 lux, an 800-lumen bulb lights a room, and a camera's exposure brings that light to the screen. In null3D, `intensityUnit` gives a light its real unit, and `post.set({ ev100 })` sets the camera's exposure value at ISO 100, as in Filament and Bevy. The exposure is 1 / (1.2 × 2^ev100): about 1 / 39,000 at 15, a sunny day.
|
|
93
93
|
|
|
94
|
-
The engine multiplies the exposure into each light at its source, as Filament does, not into the finished picture. On the CPU it scales each light, the background color and the fog color. In the shaders it scales emissive light, light maps, unlit colors and background textures.
|
|
94
|
+
The engine multiplies the exposure into each light at its source, as Filament does, not into the finished picture. On the CPU it scales each light, the background color and the fog color. In the shaders it scales emissive light, light maps, unlit colors and background textures.
|
|
95
|
+
|
|
96
|
+
Everything before the tone mapping is linear, so the picture is the same as with the exposure at the end. But the scene's colors stay near 1, so a 16-bit float holds them. With the exposure at the end, a sun of 100,000 lux gives a smooth metal a highlight above 65,504. That is the largest 16-bit float, so the highlight loses its color.
|
|
95
97
|
|
|
96
98
|
```ts
|
|
97
99
|
import { defineSketch } from '@null3d/engine';
|
|
@@ -111,7 +113,9 @@ Colors that you set in the scene's units take the exposure too: a background col
|
|
|
111
113
|
|
|
112
114
|
A scene can hold hundreds of point, spot and area lights, but a surface only needs the few whose ranges reach it. The engine therefore cuts the camera's view into clusters. The screen splits into 16 tiles across and 9 up, and the depth splits into 24 slices. Slices grow with distance. Near the camera, where each meter covers more of the screen, slices are thin.
|
|
113
115
|
|
|
114
|
-
On WebGPU at Medium and above, the slices fit the depth that the surfaces in view span. A small compute pass after the opaque pass samples the depth sparsely and keeps the nearest and farthest surface. The next frame fits its slices to that range, so a slice covers a shorter part of the view and lists fewer lights.
|
|
116
|
+
On WebGPU at Medium and above, the slices fit the depth that the surfaces in view span. A small compute pass after the opaque pass samples the depth sparsely and keeps the nearest and farthest surface. The next frame fits its slices to that range, so a slice covers a shorter part of the view and lists fewer lights.
|
|
117
|
+
|
|
118
|
+
The first slice still starts at the near plane. The last still ends where the farthest light ends. A surface outside the measured range therefore keeps every light that reaches it. Low keeps the CPU's slicing, from the near plane to the farthest light's end. WebGL2 keeps that slicing at every preset.
|
|
115
119
|
|
|
116
120
|
Each frame the engine lists, for each cluster, the lights whose range spheres reach it. Each pixel of a standard material then finds its cluster and loops over that cluster's lights alone. The test is conservative: a cluster may list a light that ends just before it, but never misses a light that reaches it. Each light fades smoothly to nothing at its range, so a listed light that does not reach a pixel adds nothing.
|
|
117
121
|
|
|
@@ -139,7 +143,7 @@ The engine shades each surface in the pass that draws it. A deferred renderer wo
|
|
|
139
143
|
- Forward shading works with MSAA directly, where deferred shading needs extra passes.
|
|
140
144
|
- Transparent surfaces use the same lighting code as opaque ones.
|
|
141
145
|
|
|
142
|
-
Both GPU paths light a scene the same way. WebGPU reads the lists from storage buffers, and WebGL2 from small data textures. The camera lists up to 1,024 lights in a frame, the ones nearest to it. Each cluster lists up to 128. Of those, the quality preset's `areaLights` caps the rectangle and tube lights, which cost more per pixel. [Performance guide](../guides/performance.md#point-and-spot-lights) gives the cost of lights.
|
|
146
|
+
Both GPU paths light a scene the same way. WebGPU reads the lists from storage buffers, and WebGL2 from small data textures. The camera lists up to 1,024 lights in a frame, the ones nearest to it. Each cluster lists up to 128. Of those, the quality preset's `areaLights` caps the rectangle and tube lights, which cost more per pixel. [Performance guide](../guides/performance.md#point-and-spot-lights) gives the cost of lights. The [300 drones, each with its own point light](https://github.com/null3d-engine/null3d/tree/main/examples/math) fly over a landing pad at dusk.
|
|
143
147
|
|
|
144
148
|
## Lights as objects
|
|
145
149
|
|
|
@@ -149,9 +153,20 @@ Point and spot lights that move in most frames should be dynamic, with `dynamic:
|
|
|
149
153
|
|
|
150
154
|
A glTF file's lights (`KHR_lights_punctual`) become directional, point and spot lights in each copy of the model, in the same units. A light on a node that a clip moves is left out ([Animation](../api/animation.md#models-from-gltf-files)).
|
|
151
155
|
|
|
156
|
+
The engine keeps each light's position relative to a grid cell, a cube about 1 km wide, so lights far from the origin stay precise ([Large worlds and precision](large-worlds.md)).
|
|
157
|
+
|
|
158
|
+
<details>
|
|
159
|
+
<summary>Technical details: how lights keep precision far away</summary>
|
|
160
|
+
|
|
161
|
+
Each frame the engine finds every point and spot light's position relative to the camera, with the offset between their cells in 64-bit floats. A lamp 1,000 km from the origin is then as precise, next to the camera, as a lamp at the origin.
|
|
162
|
+
|
|
163
|
+
</details>
|
|
164
|
+
|
|
152
165
|
## Ambient and hemisphere lights
|
|
153
166
|
|
|
154
|
-
An ambient light gives every surface the same light. A hemisphere light blends from its ground color to its sky color as a surface's normal turns toward its +Y axis. That blend is half the sum of the two colors, plus a term that grows with the cosine between the normal and the sky's direction.
|
|
167
|
+
An ambient light gives every surface the same light. A hemisphere light blends from its ground color to its sky color as a surface's normal turns toward its +Y axis. That blend is half the sum of the two colors, plus a term that grows with the cosine between the normal and the sky's direction.
|
|
168
|
+
|
|
169
|
+
Each frame, the engine sums every ambient and hemisphere light on the CPU. The sum is one color from every direction and one color along each world axis. Each pixel of a standard material adds them up with three multiply-adds, whatever the number of lights.
|
|
155
170
|
|
|
156
171
|
Both lights are diffuse only: they light a surface's color and give no highlights. An environment's light adds to theirs. The environment's `intensity` and a material's `envIntensity` scale only the environment's own light. The occlusion map and ambient occlusion darken the light of all of them.
|
|
157
172
|
|
|
@@ -159,13 +174,9 @@ Both lights are diffuse only: they light a surface's color and give no highlight
|
|
|
159
174
|
|
|
160
175
|
A light that stands for the sky must follow the hour. An ambient or hemisphere light with a fixed color and intensity is a day light. Under a night sky it lights sand, wall and road as brightly as at noon. The scene then reads as a dark sky over a lit town.
|
|
161
176
|
|
|
162
|
-
Scale the light with the hour, shifting its colors cool at night. The
|
|
163
|
-
|
|
164
|
-
Exposure is one value for the whole scene. An exposure high enough for a bright day lifts a moonlit scene by the same factor, so choose it at the hour the scene shows longest. A demo stage offers the share of a town's lamps as `stage.lamps`, from 0 by day to 1 at night, which drives such a light.
|
|
177
|
+
Scale the light with the hour, shifting its colors cool at night. The [Island showcase](https://github.com/null3d-engine/null3d/tree/main/examples/showcase/island) holds its hemisphere light at 0.8 with warm sky and ground colors by day. By night it takes it to a cool 0.06, driven by the share of a town's lamps that are lit. The moon's directional light and the lamps then carry the night, and a faint ambient keeps the dark from going black.
|
|
165
178
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
The engine keeps each object's position relative to a grid cell, a cube of space about 1 km wide. Scenes far from the origin then stay precise. Lights take part too. Each frame the engine finds every point and spot light's position relative to the camera, with the offset between their cells in 64-bit floats. A lamp 1,000 km from the origin is then as precise, next to the camera, as a lamp at the origin.
|
|
179
|
+
Exposure is one value for the whole scene. An exposure high enough for a bright day lifts a moonlit scene by the same factor, so choose it at the hour the scene shows longest. Drive the light from a value of your own that follows the sun's height, from 0 by day to 1 at night. The showcase uses the share of the town's lamps that are lit as that value.
|
|
169
180
|
|
|
170
181
|
## Fog
|
|
171
182
|
|
|
@@ -173,14 +184,22 @@ Fog fades objects toward one color with their distance from the camera, as air d
|
|
|
173
184
|
|
|
174
185
|
A curve sets how the fog thickens. The default, exponential fog, follows light through an even haze: each unit of distance hides the same share of what is left. Exponential squared fog thickens with the square of the distance. Linear fog is clear up to `near` and hides objects from `far`, with a smooth change between them.
|
|
175
186
|
|
|
176
|
-
Real mist lies low and thins with height. With a `heightFalloff`, the fog's density falls by a factor of e every 1 / `heightFalloff` units up. The engine sums that density along each line of sight with an exact formula, as Filament does. A view down into the mist then sees thick fog, and a view across its top sees thin fog.
|
|
187
|
+
Real mist lies low and thins with height. With a `heightFalloff`, the fog's density falls by a factor of e every 1 / `heightFalloff` units up. The engine sums that density along each line of sight with an exact formula, as Filament does. A view down into the mist then sees thick fog, and a view across its top sees thin fog.
|
|
188
|
+
|
|
189
|
+
With a `sunGlow`, the fog toward the main directional light takes some of that light's color, as haze around a low sun does. The glow follows the light and its intensity. Shadows do not block it.
|
|
190
|
+
|
|
191
|
+
The engine mixes the fog into each pixel's color as it shades the pixel, after lighting and before the tone mapping. Fog therefore needs no pass and no texture. It costs about 15 arithmetic operations and one or two exponentials per pixel, and nothing in a scene without fog. The mix happens in linear color.
|
|
177
192
|
|
|
178
|
-
The
|
|
193
|
+
The sky and the background can take the same fog as a surface at the camera's far plane. They do so at the share that the fog's `background` option sets, above 0; the default is 0. The haze over the land can then continue over the sky it meets. A material created with `fog: false` keeps its color at every distance.
|
|
179
194
|
|
|
180
195
|
### Volumetric fog
|
|
181
196
|
|
|
182
197
|
With the fog's `volumetric` option, the lights light the fog itself, through their shadows. A low sun shines through the gaps between trees in rays, and the trees' shadows cut dark lanes through the haze. A street lamp or a car's headlight casts a glowing cone, with the shadows of what stands in it. [Scene](../api/scene.md#volumetric-fog) lists the options.
|
|
183
198
|
|
|
199
|
+

|
|
200
|
+
|
|
201
|
+
Volumetric fog takes the sun's light.
|
|
202
|
+
|
|
184
203
|
```mermaid
|
|
185
204
|
flowchart LR
|
|
186
205
|
light["Light step<br/>each cell of the grid:<br/>fog density, sun through its cascades,<br/>lamps of its cluster through their tiles"] --> sum["Sum steps<br/>each cell adds up<br/>the cells in front of it,<br/>block by block"]
|
|
@@ -202,12 +221,16 @@ The fog of the section above stays as it is: it dims each surface and mixes in t
|
|
|
202
221
|
|
|
203
222
|
The quality setting `fogSlices` sets the grid: 32 slices with 64 cells on the canvas's short side on Medium, 64 slices with 96 on High, and 96 slices with 128 on Ultra. On Low it is 0, and the fog keeps its sun glow, at no cost. The frame-budget governor's last step halves the slices that each frame draws. While the fog is not volumetric, nothing of it runs or downloads.
|
|
204
223
|
|
|
205
|
-
Surfaces that blend or let light through, such as water and glass, draw before the apply step. They take the lit fog of the whole line of sight to the opaque surface behind them.
|
|
224
|
+
Surfaces that blend or let light through, such as water and glass, draw before the apply step. They take the lit fog of the whole line of sight to the opaque surface behind them. The [light shafts demo](https://github.com/null3d-engine/null3d/tree/main/examples/light-shafts) shows volumetric fog at dusk, with sun rays between the trunks and a glowing cone from each lantern.
|
|
206
225
|
|
|
207
226
|
## Environment maps
|
|
208
227
|
|
|
209
228
|
An environment map holds the light that reaches a point from every direction, such as a sky, a street or a room. Metal and glossy surfaces reflect it, and every surface takes some of it as diffuse light. Metals need it most, since they have almost no diffuse color and show only what they reflect.
|
|
210
229
|
|
|
230
|
+

|
|
231
|
+
|
|
232
|
+
Light from an environment alone. The demo filters the HDR file at load, which gives the same map as the assets env command.
|
|
233
|
+
|
|
211
234
|
```ts
|
|
212
235
|
import { defineSketch } from '@null3d/engine';
|
|
213
236
|
|
|
@@ -251,7 +274,9 @@ The standard material takes the environment's light in these ways:
|
|
|
251
274
|
|
|
252
275
|
A small table picks the level that each roughness reads.
|
|
253
276
|
|
|
254
|
-
`scene.setEnvironment(environment, { intensity, rotation })` sets the scene's environment, and `scene.setEnvironment(null)` removes it. `intensity` scales the light. `rotation` turns the environment by Euler angles in radians, in the order X, Y, Z. The call allocates nothing, so a sketch can turn the environment in every frame.
|
|
277
|
+
`scene.setEnvironment(environment, { intensity, rotation })` sets the scene's environment, and `scene.setEnvironment(null)` removes it. `intensity` scales the light. `rotation` turns the environment by Euler angles in radians, in the order X, Y, Z. The call allocates nothing, so a sketch can turn the environment in every frame.
|
|
278
|
+
|
|
279
|
+
A material's `envIntensity` scales the environment's light on that material alone, and multiplies the scene's `intensity`. A scene has one environment. For the light of one place in the scene, use a [reflection probe](#reflection-probes).
|
|
255
280
|
|
|
256
281
|
| Call | Gives |
|
|
257
282
|
| --- | --- |
|
|
@@ -263,18 +288,28 @@ A small table picks the level that each roughness reads.
|
|
|
263
288
|
|
|
264
289
|
### Cost
|
|
265
290
|
|
|
291
|
+
- Load an HDR file, or ask for the built-in room or the sky's environment, while the scene loads. Each one makes its whole map in one frame, so a call during play makes one long frame. A KTX2 file from the asset tool uploads over several frames and makes no long frame.
|
|
292
|
+
- A map of the default size takes 2 MB of GPU memory. The scene draws without an environment until its map is on the GPU.
|
|
293
|
+
- The environment is a value of each frame, not a build of the shaders. So setting one builds no pipeline.
|
|
294
|
+
- On WebGL2 a custom material can use only the texture units that the lighting leaves; the engine refuses one with too many with [E1209](../errors/E1209.md). WebGPU has no such limit.
|
|
295
|
+
|
|
296
|
+
<details>
|
|
297
|
+
<summary>Technical details: download sizes, memory and timings</summary>
|
|
298
|
+
|
|
266
299
|
- A page downloads the file reader, under 1 KB after Brotli, with its first environment file.
|
|
267
|
-
- An HDR file loads the HDR reader and its worker, about 6.5 KB after Brotli, and the code and shaders that make the room. They load while the file downloads. The worker reads a 2K file in about 100 ms on a MacBook Pro, outside the sketch's frames. The GPU then filters the map in the next frame, before that frame draws, in about the room's time.
|
|
300
|
+
- An HDR file loads the HDR reader and its worker, about 6.5 KB after Brotli, and the code and shaders that make the room. They load while the file downloads. The worker reads a 2K file in about 100 ms on a MacBook Pro, outside the sketch's frames. The GPU then filters the map in the next frame, before that frame draws, in about the room's time.
|
|
268
301
|
- An HDR map keeps its panorama on the thread that draws, up to 8 MB for an image of 2,048 x 1,024 texels or more. A new GPU device makes the map again from it. `environment.destroy()` frees both.
|
|
269
|
-
- The built-in room downloads no file. Its first use loads the code and the shaders that make it, about 12 KB after Brotli. The shaders compile in the background while the scene loads, and `builtinEnvironment` resolves once they are ready. The GPU then makes the whole map in the next frame, before that frame draws.
|
|
270
|
-
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
302
|
+
- The built-in room downloads no file. Its first use loads the code and the shaders that make it, about 12 KB after Brotli. The shaders compile in the background while the scene loads, and `builtinEnvironment` resolves once they are ready. The GPU then makes the whole map in the next frame, before that frame draws. That frame takes longer by the map's GPU time, which the table below gives.
|
|
303
|
+
- The sky's environment loads the same code and shaders as the room. The GPU makes its whole map in the next frame, in about 14 ms on a MacBook Pro. After a change of the sky that shows, it makes the map again in 20 stages, one a frame.
|
|
304
|
+
|
|
305
|
+
A sun that turns less than half a degree leaves the map as it is. A color value that drifts by less than 2% does the same. Slowly drifting clouds wait too, and their changes add up. One last refresh captures the sky exactly once it stops changing.
|
|
306
|
+
|
|
307
|
+
Each stage takes about 1 ms of GPU time on a MacBook Pro. The scene draws with the old map until the last stage, so no frame waits for a whole map. A sun that turns in every frame pays a stage only while it crosses those steps.
|
|
308
|
+
- The sky's environment keeps about 9 MB more for its steps. A file's map uploads in the frames after the load, within the frame's upload budget.
|
|
274
309
|
- With an environment, each pixel of a standard material reads the cube map once and adds up the nine coefficients.
|
|
275
|
-
- On WebGL2
|
|
310
|
+
- On WebGL2 the standard material uses at most 13 of the texture units that the device reports. The cube map, the area lights' tables and the reflection probes' maps share one array, and the copy of the opaque colors that screen-space reflections read is included, so three stay free on a device with 16. A material's maps share six units, and a material with more leaves out its specular intensity map first, then its specular color map, then its light map.
|
|
276
311
|
|
|
277
|
-
|
|
312
|
+
These times come from Chrome. The phones loaded a page with no shader cache. On WebGPU the map's time is the GPU's own. On WebGL2 it runs from the call until the GPU has finished.
|
|
278
313
|
|
|
279
314
|
| Device | Shaders, in the background | The whole map, in one frame |
|
|
280
315
|
| --- | --- | --- |
|
|
@@ -283,9 +318,15 @@ The tests of the room's generator measured these times in Chrome. The phones ran
|
|
|
283
318
|
| Galaxy S25, Pixel 9, Pixel 10 and Pixel 11, WebGPU | 93 to 129 ms | 48 to 100 ms |
|
|
284
319
|
| The same phones, WebGL2 | 100 to 226 ms | 58 to 107 ms |
|
|
285
320
|
|
|
321
|
+
</details>
|
|
322
|
+
|
|
286
323
|
## Reflection probes
|
|
287
324
|
|
|
288
|
-
An environment map holds light from infinitely far away. In a room, a polished floor then reflects the sky, not the walls. A reflection probe holds the light around one point of the scene, and lights the surfaces inside its box in place of the environment:
|
|
325
|
+
An environment map holds light from infinitely far away. In a room, a polished floor then reflects the sky, not the walls. A reflection probe holds the light around one point of the scene, and lights the surfaces inside its box in place of the environment. The [reflection probes demo](https://github.com/null3d-engine/null3d/tree/main/examples/reflection-probes) puts a probe in each of two rooms, and B toggles box projection:
|
|
326
|
+
|
|
327
|
+

|
|
328
|
+
|
|
329
|
+
Two rooms, one probe each. The demo's B key turns box projection on and off.
|
|
289
330
|
|
|
290
331
|
```mermaid
|
|
291
332
|
flowchart LR
|
|
@@ -319,20 +360,36 @@ Mirror reflections win over probes: a [reflection pass](../api/render.md#reflect
|
|
|
319
360
|
### Cost of probes
|
|
320
361
|
|
|
321
362
|
- A captured probe costs only its surfaces' shading: each pixel inside a box reads two levels of the probe's map, and one more for the diffuse light. A scene without probes pays one test per pixel.
|
|
322
|
-
- A capture draws the scene six times, at half the map's size, and its filter draws about 50 small passes in the same frame, before the camera's view draws. A probe that refreshes always pays this in turns with the other such probes.
|
|
323
|
-
- Each probe's map takes 0.7 MB of GPU memory at 256 x 256, the size from Medium up, and 0.2 MB at 128 x 128 on Low. The six views and the filter's chain take about 1.5 MB more while the scene has a probe. The quality setting `probeSize` sets the size.
|
|
324
363
|
- Probes need half-float render targets. WebGPU always has them. WebGL2 devices without them keep the environment's light, and development builds warn once.
|
|
325
364
|
- On the 8-bit path, which compatibility mode with antialiasing takes, the captures hold display color, so reflections in probes look a little grayer.
|
|
326
365
|
|
|
366
|
+
<details>
|
|
367
|
+
<summary>Technical details: what a probe's capture costs</summary>
|
|
368
|
+
|
|
369
|
+
A capture draws the scene six times, at half the map's size. Its filter draws about 50 small passes in the same frame, before the camera's view draws. A probe that refreshes always pays this in turns with the other such probes.
|
|
370
|
+
|
|
371
|
+
Each probe's map takes 0.7 MB of GPU memory at 256 x 256, the size from Medium up. At 128 x 128 on Low it takes 0.2 MB. The six views and the filter's chain take about 1.5 MB more while the scene has a probe. The quality setting `probeSize` sets the size.
|
|
372
|
+
|
|
373
|
+
</details>
|
|
374
|
+
|
|
327
375
|
## Light probe grid
|
|
328
376
|
|
|
329
377
|
An environment map lights every surface the same way. A light probe grid varies the light by place. Its probes hold the light that arrives at each point, so light bounced from a red wall or blocked by a corner reaches the surfaces near it. `scene.setLightProbeGrid` sets one. [Scene](../api/scene.md#the-light-probe-grid) gives its options, and the calls that make a grid.
|
|
330
378
|
|
|
331
|
-
Each probe holds L1 spherical harmonics of the light that arrives there
|
|
379
|
+
Each probe holds L1 spherical harmonics of the light that arrives there, and two masks. Standard materials read the grid per pixel. The grid's light takes the place of the environment's diffuse light, and the environment keeps its reflections. `environmentWeight` sets the share of the diffuse light that the grid takes over.
|
|
380
|
+
|
|
381
|
+
<details>
|
|
382
|
+
<summary>Technical details: what a probe holds</summary>
|
|
383
|
+
|
|
384
|
+
The coefficients are four RGB values. The first mask is the probe's validity: 1 where the probe stands in open space, and 0 where geometry encloses it, so the light of a probe inside a wall never leaks through the wall. The second is its sky visibility: the share of the sky that its rays reached.
|
|
385
|
+
|
|
386
|
+
</details>
|
|
332
387
|
|
|
333
388
|
A scene with a grid draws no [screen-space bounce light](post-processing.md#screen-space-bounce-light). The grid already holds one bounce, with the occlusion the screen cannot supply, and the two would count the same light twice.
|
|
334
389
|
|
|
335
|
-
`bakeProbes` bakes a grid in the browser. Each probe casts directions with `scene.raycastBatch`, which tests both faces of every triangle here. A direction that reaches the sky counts toward the probe's sky visibility. A direction that meets a surface's back means geometry encloses the probe
|
|
390
|
+
`bakeProbes` bakes a grid in the browser. Each probe casts directions with `scene.raycastBatch`, which tests both faces of every triangle here. A direction that reaches the sky counts toward the probe's sky visibility. A direction that meets a surface's back means geometry encloses the probe. The bake gives it no validity, and fills it from the probes around it. A direction that hits a surface's front takes that surface's color once, as a matte bounce.
|
|
391
|
+
|
|
392
|
+
The bake counts no lamps, so the grid holds one colored bounce, the occlusion of the sky and which probes lie inside geometry. `step` bakes a few probes a frame, so a loading screen can show progress. `finish` bakes the rest at once.
|
|
336
393
|
|
|
337
394
|
The sky itself never bakes. The shader weights each probe's sky visibility by how much the surface faces the sky above the horizon, multiplies that by the environment's live light, and adds it to the baked bounce. A time of day that moves the sky, or an environment that turns or changes its intensity, then lights the grid again with no new bake. Only the bounce keeps the environment that the bake read.
|
|
338
395
|
|
|
@@ -351,12 +408,18 @@ Such a mesh keeps the environment's diffuse light, and takes no light from the g
|
|
|
351
408
|
|
|
352
409
|
### Limits and cost
|
|
353
410
|
|
|
354
|
-
- The grid's texture is a 3D texture of half floats, at most 256 texels along each side on every device. `LightProbeGridData.toTexture()` makes it.
|
|
355
|
-
- A grid holds at most 256 probes along x, 256 along y and 62 along z. The z side is smaller because the texture is cut into four sub-volumes, three of coefficients and one of the masks, and each sub-volume has a padding slice at either end.
|
|
356
|
-
- `counts` takes whole numbers of 2 or more, and `spacing` must be above 0. Development builds throw E1108 for a grid too large for the texture, and the error names the limit. Use a larger spacing, or a smaller box.
|
|
357
|
-
- The grid takes 32 bytes of GPU memory for each probe, the 12 half floats of its coefficients and the 2 half floats of its masks, plus the padding slices along z. A grid of 24 x 8 x 24 probes (4,608 probes, one per metre over a 24 m hall) takes about 157 KiB.
|
|
358
411
|
- Each lit pixel of a standard material reads the grid four times.
|
|
359
412
|
- The grid's shaders load on first use, so a page that sets no grid downloads none of it. To load them before the first frame, list `'probe_grid'` in `createEngine`'s `preload` option: [Loading screens](../guides/loading-screens.md#loading-everything-up-front).
|
|
413
|
+
- A grid holds at most 256 probes along x, 256 along y and 62 along z.
|
|
414
|
+
- `counts` takes whole numbers of 2 or more, and `spacing` must be above 0. Development builds throw [E1108](../errors/E1108.md) for a grid too large for the texture, and the error names the limit. Use a larger spacing, or a smaller box.
|
|
415
|
+
|
|
416
|
+
<details>
|
|
417
|
+
<summary>Technical details: the grid's memory and texture</summary>
|
|
418
|
+
|
|
419
|
+
- The grid's texture is a 3D texture of half floats, at most 256 texels along each side on every device. `LightProbeGridData.toTexture()` makes it. The z side is smaller because the texture is cut into four sub-volumes, three of coefficients and one of the masks, and each sub-volume has a padding slice at either end.
|
|
420
|
+
- The grid takes 32 bytes of GPU memory for each probe, the 12 half floats of its coefficients and the 2 half floats of its masks, plus the padding slices along z. A grid of 24 x 8 x 24 probes (4,608 probes, one per meter over a 24 m hall) takes about 157 KiB.
|
|
421
|
+
|
|
422
|
+
</details>
|
|
360
423
|
|
|
361
424
|
## Sky and backgrounds
|
|
362
425
|
|
|
@@ -374,7 +437,9 @@ export default defineSketch(async ({ scene, assets }) => {
|
|
|
374
437
|
});
|
|
375
438
|
```
|
|
376
439
|
|
|
377
|
-
The engine draws a background after the opaque objects, at the far plane, with the depth test. So it shades only the pixels that no object covers, and transparent objects draw over it. While an opaque material has `depthWrite: false` or `depthTest: false`, the background draws before the objects instead, without the depth test. That material then still shows over the background.
|
|
440
|
+
The engine draws a background after the opaque objects, at the far plane, with the depth test. So it shades only the pixels that no object covers, and transparent objects draw over it. While an opaque material has `depthWrite: false` or `depthTest: false`, the background draws before the objects instead, without the depth test. That material then still shows over the background.
|
|
441
|
+
|
|
442
|
+
A texture fills the view as one triangle. An environment, a cube map and the sky draw as a box around the camera. So each pixel takes its color from its own direction. Their light goes into the scene's color like an object's, so exposure and tone mapping change them too.
|
|
378
443
|
|
|
379
444
|
- An environment's background reads the environment's cube map at the level of the blur's roughness. The levels hold the blur already, so a blurred background costs no more than a sharp one. Only environments blur: for a background that blurs, load an environment with `assets.loadEnvironment`.
|
|
380
445
|
- A cube map shows its six images as seen from inside the cube, mirrored across x.
|
|
@@ -478,6 +543,10 @@ Give the sheets the fog's color, and change it with `material.set({ air })` when
|
|
|
478
543
|
|
|
479
544
|
The physical sky models the earth's air: a layer 100 km deep over a planet of the earth's size. Its molecules scatter blue light more than red (Rayleigh scattering), its haze scatters every color and mostly forward (Mie scattering), and its ozone absorbs some orange. The engine follows Hillaire's method of 2020, which Unreal Engine and Bevy use. Three small tables hold what each pixel would otherwise work out along its ray:
|
|
480
545
|
|
|
546
|
+

|
|
547
|
+
|
|
548
|
+
The physical sky.
|
|
549
|
+
|
|
481
550
|
```mermaid
|
|
482
551
|
flowchart LR
|
|
483
552
|
air["The air's settings"] --> T["Transmittance table<br/>256 x 64"]
|
|
@@ -501,7 +570,7 @@ The aerial perspective needs no table. Over a scene's distances, the air's densi
|
|
|
501
570
|
|
|
502
571
|
At night the moon is a second light of the air: it lights the sky as the sun does, a little bluer at the scene's exposure. The moon's disc shows its phase, lit from the sun's side. The stars add their light to the sky's, so they show only where the sky is dark enough, and the air dims them toward the horizon.
|
|
503
572
|
|
|
504
|
-
The sky's environment shows the physical sky too. When a refresh starts, the engine draws the sky with its clouds into a panorama, and the map's steps read it. So every face of the map shows the same sky while the sun moves. The diffuse light comes from a CPU copy of the same model.
|
|
573
|
+
The sky's environment shows the physical sky too. When a refresh starts, the engine draws the sky with its clouds into a panorama, and the map's steps read it. So every face of the map shows the same sky while the sun moves. The diffuse light comes from a CPU copy of the same model. The [atmosphere demo](https://github.com/null3d-engine/null3d/tree/main/examples/atmosphere) shows a day over a valley of ridges, with the moon and stars at night.
|
|
505
574
|
|
|
506
575
|
### Background cost
|
|
507
576
|
|
|
@@ -515,7 +584,9 @@ The sky's environment shows the physical sky too. When a refresh starts, the eng
|
|
|
515
584
|
|
|
516
585
|
## Time of day
|
|
517
586
|
|
|
518
|
-
`timeOfDay` works out the settings that change together through a day, from one value: an hour from 0 to 24, or a preset. They are the sky's sun and air, the main light, the fog's color and glow, an ambient light, the sky's intensity and the exposure. Each comes from the same sky model as the sky background.
|
|
587
|
+
`timeOfDay` works out the settings that change together through a day, from one value: an hour from 0 to 24, or a preset. They are the sky's sun and air, the main light, the fog's color and glow, an ambient light, the sky's intensity and the exposure. Each comes from the same sky model as the sky background.
|
|
588
|
+
|
|
589
|
+
With the analytic sky, the fog takes the color of the sky's horizon by day and fades to the sky's average color at dusk. With the physical sky, the fog takes the sky's mean light by day and through dusk. That is the light that the exposure follows, so the fog stays as dim as the sky around it. A fog of the horizon's color would carry the sky's brightest band over the whole scene.
|
|
519
590
|
|
|
520
591
|
```ts
|
|
521
592
|
import { defineSketch, timeOfDay } from '@null3d/engine';
|
|
@@ -547,7 +618,7 @@ The result holds plain values. Apply them to your own objects, as above:
|
|
|
547
618
|
| `sky` | `scene.setBackground({ sky })`. Add the clouds and their `time` of your own: `{ ...day.sky, cloudCoverage: 0.3 }` |
|
|
548
619
|
| `skyIntensity` | The sky background's and the sky environment's `intensity` |
|
|
549
620
|
| `light` | The main directional light: `direction`, a linear `color` and `intensity`. By day it is the sun. After sunset it is the moon, a cool light that rises from the horizon as night falls |
|
|
550
|
-
| `fog` | `scene.setFog`: the
|
|
621
|
+
| `fog` | `scene.setFog`: the sky's horizon color by day and its average at dusk, and the `sunGlow`. Choose the curve and the density for your scene |
|
|
551
622
|
| `ambient` | An ambient light's `color` and `intensity`, for a scene without the sky's environment. A scene lit by the sky's environment needs none |
|
|
552
623
|
| `exposure` | `post.set({ exposure })`: 1 by day, up to 3.5 at night |
|
|
553
624
|
|
|
@@ -558,7 +629,7 @@ With `{ model: 'physical' }`, the values match the physical sky instead, from a
|
|
|
558
629
|
| `atmosphere` | `scene.setBackground({ atmosphere })`: the real sun, its light above the air, and at night the moon and the stars. Add your scene's clouds and haze: `{ ...day.atmosphere, aerialPerspective: 2 }` |
|
|
559
630
|
| `skyIntensity` | 1: the physical sky dims by itself after sunset |
|
|
560
631
|
| `light` | The sun through the air, which reddens as it sets. Its light goes out as its disc sets, and the glowing sky lights the scene through the ambient light and the sky's environment. The light turns to the moon's place while it gives none, then the moon's light rises as night falls: no light sweeps across the scene. The moon stands opposite the sun, so it is highest at midnight. Its light and its sky are brightest then, and fade as it sinks toward dawn |
|
|
561
|
-
| `fog` | The
|
|
632
|
+
| `fog` | The sky's mean light, with no glow: the aerial perspective already glows toward the sun. At night it takes the moon sky's horizon light |
|
|
562
633
|
| `exposure` | Follows the sky's mean light, as an eye adapts: about 0.55 by day, up to 4 through dusk, and 1.1 once night has fallen. It holds at 1.1 until dawn, so the night is brightest under the midnight moon |
|
|
563
634
|
|
|
564
635
|
The helper gives values and leaves them to the sketch. A scene keeps its own light, fog curve and density, and post settings, which a call that applied them would overwrite.
|
|
@@ -571,7 +642,7 @@ The helper gives values and leaves them to the sketch. A scene keeps its own lig
|
|
|
571
642
|
|
|
572
643
|
## Lights in scene passes
|
|
573
644
|
|
|
574
|
-
A [scene pass](../api/render.md) draws the scene from another camera into a texture. It lights its objects with the sun, the ambient and hemisphere lights, the environment and the fog. It draws the sun's shadows where the camera's cascades reach, and the point, spot and area lights that its camera sees. It draws the scene's background behind them, the sky included, unless the pass has a `clearColor`, which its texture then clears to.
|
|
645
|
+
A [scene pass](../api/render.md) draws the scene from another camera into a texture. It lights its objects with the sun, the ambient and hemisphere lights, the environment and the fog. It draws the sun's shadows where the camera's cascades reach, and the point, spot and area lights that its camera sees. Its point and spot lights cast shadows where the camera's view gives them shadows. It draws the scene's background behind them, the sky included, unless the pass has a `clearColor`, which its texture then clears to.
|
|
575
646
|
|
|
576
647
|
## Related pages
|
|
577
648
|
|
|
@@ -585,3 +656,5 @@ A [scene pass](../api/render.md) draws the scene from another camera into a text
|
|
|
585
656
|
- [Assets](../api/assets.md#environments): the calls that load environments and cube maps.
|
|
586
657
|
- [The environment light demo](https://github.com/null3d-engine/null3d/tree/main/examples/environment): rough and smooth spheres in an HDR file's light, an EXR file's light and the built-in room.
|
|
587
658
|
- [The time of day demo](https://github.com/null3d-engine/null3d/tree/main/examples/time-of-day): a day passes over a lighthouse in 40 seconds. The sketch calls `timeOfDay` each time the hour moves on by three minutes, and the sky's light follows the sun.
|
|
659
|
+
- [The area lights demo](https://github.com/null3d-engine/null3d/tree/main/examples/area-lights): rectangle windows and tube-light neon, whose whole shapes show in the wet street.
|
|
660
|
+
- [The night town comparison](https://github.com/null3d-engine/null3d/tree/main/examples/compare/night-town): a city block in both engines, where each click adds 12 lights and a slider raises the count.
|