@null3d/engine 0.0.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/README.md +109 -0
- package/THIRD-PARTY-NOTICES.txt +0 -1
- package/dist/wasm/single/null3d.js +25 -10
- package/dist/wasm/single/null3d_bg.wasm +0 -0
- package/dist/wasm/threaded/null3d.js +25 -10
- package/dist/wasm/threaded/null3d_bg.wasm +0 -0
- package/docs/api/animation.md +114 -86
- package/docs/api/assets.md +135 -49
- package/docs/api/cameras.md +45 -12
- package/docs/api/controls.md +88 -62
- package/docs/api/debug.md +116 -41
- package/docs/api/engine.md +117 -35
- package/docs/api/feature-draws.md +23 -17
- package/docs/api/feature-effects.md +11 -11
- package/docs/api/feature-instances.md +70 -19
- package/docs/api/features.md +77 -47
- package/docs/api/geometry.md +132 -82
- package/docs/api/grass.md +55 -13
- package/docs/api/impostors.md +175 -22
- package/docs/api/input.md +24 -18
- package/docs/api/lights.md +78 -51
- package/docs/api/lines.md +41 -33
- package/docs/api/materials.md +248 -121
- package/docs/api/math.md +12 -13
- package/docs/api/objects.md +47 -22
- package/docs/api/page.md +58 -7
- package/docs/api/particles.md +33 -20
- package/docs/api/points.md +19 -31
- package/docs/api/post.md +75 -42
- package/docs/api/quality.md +42 -17
- package/docs/api/raycast.md +65 -51
- package/docs/api/reference/animation.md +10 -11
- package/docs/api/reference/assets.md +25 -22
- package/docs/api/reference/cameras.md +8 -4
- package/docs/api/reference/controls.md +134 -25
- package/docs/api/reference/debug.md +81 -14
- package/docs/api/reference/engine.md +58 -17
- 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 +287 -97
- package/docs/api/reference/grass.md +63 -3
- package/docs/api/reference/impostors.md +208 -13
- package/docs/api/reference/input.md +4 -5
- package/docs/api/reference/lights.md +13 -12
- package/docs/api/reference/lines.md +10 -11
- package/docs/api/reference/materials.md +54 -53
- package/docs/api/reference/math.md +35 -24
- package/docs/api/reference/objects.md +11 -12
- package/docs/api/reference/particles.md +31 -6
- package/docs/api/reference/points.md +6 -7
- package/docs/api/reference/post.md +21 -20
- package/docs/api/reference/quality.md +8 -5
- package/docs/api/reference/raycast.md +7 -8
- package/docs/api/reference/render.md +5 -4
- package/docs/api/reference/scene.md +52 -30
- package/docs/api/reference/sketch.md +15 -11
- package/docs/api/reference/sound.md +234 -0
- package/docs/api/reference/splats.md +42 -3
- package/docs/api/reference/sprites.md +7 -8
- package/docs/api/reference/tasks.md +16 -3
- package/docs/api/reference/terrain.md +27 -5
- package/docs/api/reference/textures.md +5 -6
- package/docs/api/reference/three-compat.md +18 -7
- package/docs/api/reference/time.md +1 -2
- package/docs/api/reference/ui.md +12 -9
- package/docs/api/reference/vertex-draws.md +5 -6
- package/docs/api/reference/water.md +153 -9
- package/docs/api/reference/wind.md +17 -4
- package/docs/api/render.md +73 -29
- package/docs/api/scene.md +164 -60
- package/docs/api/sketch.md +102 -15
- package/docs/api/sound.md +205 -0
- package/docs/api/splats.md +46 -12
- package/docs/api/sprites.md +10 -24
- package/docs/api/tasks.md +33 -24
- package/docs/api/terrain.md +42 -22
- package/docs/api/textures.md +68 -19
- package/docs/api/three-compat.md +15 -7
- package/docs/api/time.md +3 -5
- package/docs/api/ui.md +19 -23
- package/docs/api/vertex-draws.md +13 -12
- package/docs/api/water.md +262 -35
- package/docs/api/wind.md +63 -17
- package/docs/cli/null3d.md +177 -27
- package/docs/concepts/architecture.md +73 -27
- package/docs/concepts/assets.md +57 -33
- package/docs/concepts/backends.md +69 -27
- package/docs/concepts/color-management.md +54 -36
- package/docs/concepts/culling.md +68 -47
- package/docs/concepts/handles.md +14 -5
- package/docs/concepts/instances.md +74 -25
- package/docs/concepts/large-worlds.md +18 -8
- package/docs/concepts/lighting.md +155 -87
- package/docs/concepts/lod.md +126 -44
- package/docs/concepts/materials.md +58 -27
- package/docs/concepts/particle-buffer.md +48 -35
- package/docs/concepts/post-processing.md +84 -43
- package/docs/concepts/quality-preset-tables.md +56 -52
- package/docs/concepts/quality-presets.md +164 -52
- package/docs/concepts/render-graph.md +69 -29
- package/docs/concepts/render-layers.md +11 -21
- package/docs/concepts/shadows.md +105 -52
- package/docs/concepts/static-dynamic.md +22 -7
- package/docs/cookbook/index.md +164 -120
- package/docs/data/threejs-mapping.json +362 -367
- 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 +14 -6
- 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 +40 -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 +14 -6
- 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 +54 -30
- package/docs/getting-started/cdn.md +32 -10
- package/docs/getting-started/first-scene.md +21 -13
- package/docs/getting-started/hosting.md +152 -63
- package/docs/getting-started/install.md +44 -28
- package/docs/getting-started/network-use.md +33 -15
- package/docs/getting-started/project-structure.md +33 -12
- package/docs/getting-started/third-party-notices.md +12 -14
- package/docs/guides/accessibility.md +5 -5
- package/docs/guides/add-ons.md +86 -15
- package/docs/guides/agents.md +16 -9
- package/docs/guides/assets-pipeline.md +259 -82
- package/docs/guides/audio.md +115 -128
- package/docs/guides/baked-light-data.md +44 -23
- package/docs/guides/car-paint.md +38 -32
- package/docs/guides/content-pages.md +63 -35
- package/docs/guides/custom-passes.md +65 -22
- package/docs/guides/custom-shaders.md +59 -39
- package/docs/guides/debugging.md +74 -10
- package/docs/guides/deploying.md +85 -6
- package/docs/guides/deterministic-simulation.md +24 -17
- package/docs/guides/first-use-shaders.md +83 -45
- package/docs/guides/lens-kit.md +29 -26
- package/docs/guides/loading-screens.md +132 -47
- package/docs/guides/multiple-views.md +63 -13
- package/docs/guides/performance.md +192 -38
- package/docs/guides/phones.md +78 -15
- package/docs/guides/physics.md +7 -11
- package/docs/guides/screens.md +47 -33
- package/docs/guides/start-time.md +363 -0
- package/docs/guides/testing.md +152 -95
- package/docs/guides/ui-overlays.md +19 -14
- 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 +18 -23
- package/docs/moves.json +1 -0
- package/docs/nav.json +300 -0
- package/docs/pages.md +230 -209
- package/docs/porting/react-three-fiber.md +225 -6
- package/docs/porting/threejs-loop-and-threads.md +217 -7
- package/docs/porting/threejs-mapping.md +1249 -233
- package/docs/porting/threejs-materials.md +218 -6
- package/docs/porting/threejs-overview.md +240 -7
- package/docs/porting/threejs-postprocessing.md +4 -8
- package/docs/porting/threejs-shaders.md +301 -6
- package/docs/porting/threejs-unsupported.md +83 -7
- package/docs/porting/verification.md +178 -6
- package/docs/shaders/builtins.md +15 -4
- package/docs/shaders/library.md +72 -45
- package/docs/shaders/surface-functions.md +59 -23
- package/docs/shaders/wgsl-rules.md +12 -5
- package/lib/debug/channel.d.ts +103 -0
- package/lib/debug/channel.js +269 -0
- package/lib/debug/debug.d.ts +11 -9
- package/lib/debug/draw.d.ts +11 -2
- package/lib/debug/draw.js +57 -6
- package/lib/debug/inspector.d.ts +60 -0
- package/lib/debug/inspector.js +475 -0
- 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 +22 -7
- package/lib/debug/stats-panel.js +80 -13
- package/lib/debug/stats.d.ts +2 -3
- package/lib/errors/codes.d.ts +17 -3
- package/lib/errors/codes.js +117 -105
- package/lib/errors/engine-error.js +25 -10
- package/lib/errors/fixes.d.ts +1 -0
- package/lib/errors/fixes.js +20 -19
- package/lib/generated/core.d.ts +1 -1
- package/lib/generated/core.js +1 -1
- package/lib/gpu/early-builds.d.ts +68 -0
- package/lib/gpu/early-builds.js +158 -0
- package/lib/gpu/pipeline-name.d.ts +6 -0
- package/lib/gpu/pipeline-name.js +23 -0
- package/lib/gpu/variants.d.ts +8 -2
- package/lib/gpu/variants.js +39 -7
- package/lib/gpu/webgl2/backend.d.ts +63 -2
- package/lib/gpu/webgl2/backend.js +226 -8
- package/lib/gpu/webgl2/programs.d.ts +18 -0
- package/lib/gpu/webgl2/programs.js +5 -2
- package/lib/gpu/webgpu/backend.d.ts +89 -2
- package/lib/gpu/webgpu/backend.js +255 -8
- package/lib/gpu/webgpu/pipelines.d.ts +13 -0
- package/lib/gpu/webgpu/pipelines.js +28 -14
- package/lib/index.d.ts +7 -5
- package/lib/index.js +3 -2
- package/lib/math/color.d.ts +5 -5
- package/lib/math/color.js +5 -5
- package/lib/math/mat4.d.ts +6 -12
- package/lib/math/mat4.js +6 -12
- package/lib/math/namespaces/quat.d.ts +3 -3
- package/lib/math/namespaces/quat.js +3 -3
- package/lib/math/quat.d.ts +8 -12
- package/lib/math/quat.js +8 -12
- package/lib/math/random.d.ts +2 -3
- package/lib/math/random.js +2 -3
- package/lib/math/types.d.ts +4 -4
- package/lib/math/vec3.d.ts +3 -6
- package/lib/math/vec3.js +3 -6
- package/lib/page/capabilities.d.ts +8 -8
- package/lib/page/capabilities.js +39 -25
- package/lib/page/check-store.d.ts +14 -2
- package/lib/page/check-store.js +34 -11
- package/lib/page/engine.d.ts +117 -31
- package/lib/page/engine.js +438 -99
- package/lib/page/first-frame.d.ts +16 -0
- package/lib/page/first-frame.js +35 -0
- package/lib/page/frame-stats.d.ts +34 -1
- package/lib/page/frame-stats.js +15 -0
- package/lib/page/label-loop.d.ts +7 -3
- package/lib/page/label-loop.js +26 -14
- package/lib/page/labels.d.ts +3 -3
- package/lib/page/pipeline-store.d.ts +25 -0
- package/lib/page/pipeline-store.js +84 -0
- package/lib/page/start-marker.d.ts +4 -1
- package/lib/page/start-marker.js +5 -2
- package/lib/page/stats-switch.js +2 -0
- package/lib/page/switches.d.ts +38 -6
- package/lib/page/switches.js +29 -5
- package/lib/quality/check.d.ts +24 -3
- package/lib/quality/check.js +21 -7
- package/lib/quality/chooser.d.ts +6 -0
- package/lib/quality/chooser.js +8 -0
- package/lib/quality/governor.d.ts +98 -6
- package/lib/quality/governor.js +250 -20
- package/lib/quality/preset-docs.d.ts +16 -1
- package/lib/quality/preset-docs.js +3 -0
- package/lib/quality/presets.d.ts +84 -7
- package/lib/quality/presets.js +94 -2
- package/lib/render/draw.d.ts +3 -2
- package/lib/render/draw.js +15 -5
- package/lib/render/load-draw.d.ts +7 -5
- package/lib/render/load-draw.js +7 -5
- package/lib/render/loss.d.ts +28 -10
- package/lib/render/loss.js +50 -22
- package/lib/render/recovery.d.ts +20 -0
- package/lib/render/recovery.js +44 -4
- package/lib/render/renderer.d.ts +85 -9
- package/lib/render/renderer.js +181 -42
- package/lib/render/scene-renderer.d.ts +19 -1
- package/lib/render/scene-renderer.js +25 -1
- package/lib/render/webgl2-renderers.js +8 -5
- package/lib/render/webgpu-renderers.js +5 -4
- package/lib/scene/animation.d.ts +28 -32
- package/lib/scene/animation.js +12 -15
- package/lib/scene/assets.d.ts +61 -86
- package/lib/scene/assets.js +103 -236
- package/lib/scene/background.d.ts +14 -18
- package/lib/scene/background.js +5 -2
- package/lib/scene/baked-light.d.ts +2 -2
- package/lib/scene/color.d.ts +3 -3
- package/lib/scene/downloads.d.ts +2 -0
- package/lib/scene/downloads.js +371 -0
- package/lib/scene/environment.d.ts +7 -7
- package/lib/scene/environment.js +1 -1
- package/lib/scene/fake-call-values.js +3 -3
- package/lib/scene/fog.d.ts +11 -4
- package/lib/scene/fog.js +8 -2
- package/lib/scene/frame-cameras.d.ts +35 -4
- package/lib/scene/frame-cameras.js +86 -10
- package/lib/scene/gltf.d.ts +33 -3
- package/lib/scene/gltf.js +78 -49
- package/lib/scene/grading.d.ts +2 -2
- package/lib/scene/grading.js +3 -3
- package/lib/scene/ktx2.d.ts +9 -1
- package/lib/scene/ktx2.js +3 -2
- package/lib/scene/level-rule.d.ts +121 -0
- package/lib/scene/level-rule.js +130 -0
- package/lib/scene/lines.d.ts +13 -17
- package/lib/scene/lines.js +3 -3
- package/lib/scene/lut.d.ts +1 -2
- package/lib/scene/lut.js +1 -2
- package/lib/scene/particles.d.ts +7 -3
- package/lib/scene/particles.js +3 -1
- package/lib/scene/picks.d.ts +2 -2
- package/lib/scene/pointer-events.d.ts +4 -7
- package/lib/scene/post.d.ts +39 -43
- package/lib/scene/post.js +4 -1
- package/lib/scene/prefab.d.ts +7 -8
- package/lib/scene/prefab.js +7 -8
- package/lib/scene/property-animation.d.ts +1 -1
- package/lib/scene/property-animation.js +1 -1
- package/lib/scene/queries.d.ts +7 -13
- package/lib/scene/resources.d.ts +238 -261
- package/lib/scene/resources.js +179 -81
- package/lib/scene/scene.d.ts +167 -120
- package/lib/scene/scene.js +243 -103
- package/lib/scene/serial-loads.d.ts +29 -0
- package/lib/scene/serial-loads.js +68 -0
- package/lib/scene/shader-preloads.d.ts +34 -0
- package/lib/scene/shader-preloads.js +38 -0
- package/lib/scene/sprites.d.ts +14 -17
- package/lib/scene/sprites.js +5 -6
- package/lib/scene/textures.d.ts +11 -12
- package/lib/scene/textures.js +9 -10
- package/lib/scene/time-of-day.d.ts +11 -7
- package/lib/scene/time-of-day.js +11 -8
- package/lib/scene/vertex-draws.d.ts +5 -4
- package/lib/scene/vertex-draws.js +7 -5
- package/lib/shader-artifact.json +1 -0
- package/lib/shared/core.d.ts +5 -0
- package/lib/shared/core.js +1 -0
- package/lib/shared/import-once.d.ts +6 -0
- package/lib/shared/import-once.js +19 -0
- package/lib/shared/labels.d.ts +5 -2
- package/lib/shared/labels.js +5 -2
- package/lib/shared/metrics.d.ts +38 -0
- package/lib/shared/metrics.js +62 -1
- 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/run-task.js +7 -1
- package/lib/shared/sketch-data.d.ts +9 -0
- package/lib/shared/sketch-data.js +57 -0
- package/lib/shared/task-pending.d.ts +12 -0
- package/lib/shared/task-pending.js +61 -1
- package/lib/shared/tasks.js +79 -32
- package/lib/shared/version.d.ts +17 -1
- package/lib/shared/version.js +19 -1
- package/lib/shared/wasm.d.ts +12 -4
- package/lib/shared/wasm.js +50 -27
- package/lib/shared/worker-start.d.ts +7 -0
- package/lib/shared/worker-start.js +27 -0
- package/lib/sketch/define-sketch.d.ts +51 -7
- package/lib/sketch/define-sketch.js +2 -1
- package/lib/sketch/input.d.ts +2 -2
- package/lib/sketch/preset-check.d.ts +20 -6
- package/lib/sketch/preset-check.js +42 -17
- package/lib/sketch/quality.d.ts +69 -11
- package/lib/sketch/quality.js +54 -13
- package/lib/sketch/runner.d.ts +80 -9
- package/lib/sketch/runner.js +390 -52
- package/lib/sketch/ui.d.ts +5 -8
- package/lib/sketch/ui.js +4 -2
- package/lib/stats.d.ts +1 -0
- package/lib/workers/probe-worker.d.ts +5 -0
- package/lib/workers/probe-worker.js +13 -4
- package/lib/workers/protocol.d.ts +71 -13
- package/lib/workers/protocol.js +4 -0
- package/lib/workers/render-worker.js +29 -5
- package/lib/workers/sketch-worker.js +108 -16
- package/package.json +2 -2
package/docs/guides/audio.md
CHANGED
|
@@ -1,163 +1,150 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: guides/audio
|
|
3
|
-
title:
|
|
4
|
-
|
|
5
|
-
since: "0.1"
|
|
6
|
-
summary: "Why audio stays on the page; sending positions from the sketch."
|
|
3
|
+
title: Sound in a scene
|
|
4
|
+
summary: "Sound that follows the scene with @null3d/sound: beds whose level the scene sets, sources at places, groups of many sources, and events."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
|
-
#
|
|
10
|
-
|
|
11
|
-
> Roadmap step 0.1, first released in null3D 0.1.0. The API is experimental, so it can still change between versions.
|
|
7
|
+
# Sound in a scene
|
|
12
8
|
|
|
13
9
|
```mermaid
|
|
14
10
|
flowchart LR
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
scene["The sketch<br/>knows the scene"] -- "level, place, rate<br/>and tone of each sound" --> sound["@null3d/sound"]
|
|
12
|
+
sound --> bed["Beds:<br/>sea, wind, rain"]
|
|
13
|
+
sound --> spot["Sources at places:<br/>a waterfall"]
|
|
14
|
+
sound --> group["Groups:<br/>the cars of a street"]
|
|
15
|
+
sound --> shot["Events:<br/>thunder, a bounce"]
|
|
18
16
|
```
|
|
19
17
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
## Why audio stays on the page
|
|
23
|
-
|
|
24
|
-
A worker cannot create an `AudioContext`: the browser offers Web Audio on the page's main thread only. So the page plays the sound, and the sketch tells it where each sound is. The browser mixes the sound on a thread of its own, so the page's audio code has little to do. It moves the listener and the sounds to where the sketch put them.
|
|
18
|
+
A scene sounds right when its sounds follow what the camera sees. The sea grows louder as the camera nears the shore, and a passing car's engine moves from one ear to the other. The sketch knows all of that, so the sketch drives the sound. [Sound (@null3d/sound)](../api/sound.md) plays it on the page with the browser's audio, and this guide shows the four kinds of sound a scene needs.
|
|
25
19
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
| Fact | How it travels | Examples |
|
|
29
|
-
| --- | --- | --- |
|
|
30
|
-
| Positions that change in each frame | A shared array, which the sketch sends once | The camera, the engine of a moving car |
|
|
31
|
-
| Events | One message for each event | A footstep or an explosion |
|
|
20
|
+
## Set up the sound
|
|
32
21
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
This sketch flies a drone in a circle in front of the camera. In each frame it writes the camera's position and direction, and the drone's position, into an array that the page also reads. Once per lap, it asks the page for a chime at the drone.
|
|
22
|
+
The sketch makes the sounds with `createSound`, and the page connects with `connectSound`. Call `update` once a frame, in `onLateUpdate`.
|
|
36
23
|
|
|
37
24
|
```ts
|
|
38
25
|
// sketch.ts
|
|
39
|
-
import { defineSketch
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
scene.createDirectionalLight({ direction: [-1, -2, -1], intensity: 3 });
|
|
48
|
-
scene.createAmbientLight({ intensity: 0.4 });
|
|
49
|
-
const drone = scene.createMesh({
|
|
50
|
-
mesh: geometry.sphere({ radius: 0.3 }),
|
|
51
|
-
material: materials.standard({ color: '#e8554e' }),
|
|
52
|
-
dynamic: true,
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
// 12 numbers for the page: the listener's position, forward and up, then the drone's position.
|
|
56
|
-
const bytes = 12 * Float32Array.BYTES_PER_ELEMENT;
|
|
57
|
-
const positions = new Float32Array(
|
|
58
|
-
crossOriginIsolated ? new SharedArrayBuffer(bytes) : new ArrayBuffer(bytes),
|
|
59
|
-
);
|
|
60
|
-
const listener = positions.subarray(0, 3);
|
|
61
|
-
const forward = positions.subarray(3, 6);
|
|
62
|
-
const up = positions.subarray(6, 9);
|
|
63
|
-
const source = positions.subarray(9, 12);
|
|
64
|
-
page.post('audio', positions); // sent once, in the setup
|
|
65
|
-
|
|
66
|
-
const turn = quat.create();
|
|
67
|
-
let laps = 0;
|
|
26
|
+
import { defineSketch } from '@null3d/engine';
|
|
27
|
+
import { createSound } from '@null3d/sound';
|
|
28
|
+
|
|
29
|
+
export default defineSketch((ctx) => {
|
|
30
|
+
const camera = ctx.scene.createPerspectiveCamera({ position: [0, 2, 10], target: [0, 1, 0] });
|
|
31
|
+
ctx.scene.setActiveCamera(camera);
|
|
32
|
+
const sound = createSound(ctx, { listener: camera });
|
|
33
|
+
// ... the sounds below ...
|
|
68
34
|
return {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
drone.setPosition(Math.cos(angle) * 4, 1, Math.sin(angle) * 4);
|
|
72
|
-
drone.getPosition(source);
|
|
73
|
-
camera.getPosition(listener);
|
|
74
|
-
camera.getRotation(turn);
|
|
75
|
-
vec3.transformQuat(forward, AHEAD, turn);
|
|
76
|
-
vec3.transformQuat(up, UP, turn);
|
|
77
|
-
|
|
78
|
-
if (angle / (Math.PI * 2) >= laps + 1) {
|
|
79
|
-
laps++;
|
|
80
|
-
page.post('chime', [source[0], source[1], source[2]]); // one message for each event
|
|
81
|
-
}
|
|
35
|
+
onLateUpdate() {
|
|
36
|
+
sound.update();
|
|
82
37
|
},
|
|
83
38
|
};
|
|
84
39
|
});
|
|
85
40
|
```
|
|
86
41
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
42
|
+
```ts
|
|
43
|
+
// page.ts: the sound starts on the user's first click, tap or key.
|
|
44
|
+
import { connectSound } from '@null3d/sound/page';
|
|
45
|
+
const sound = connectSound(engine, { startOnInput: true });
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
A sound button suits a page that people browse. Call `sound.start()` from its click handler, and `sound.setMuted` to mute it after that.
|
|
91
49
|
|
|
92
|
-
##
|
|
50
|
+
## Beds whose level the scene sets
|
|
93
51
|
|
|
94
|
-
|
|
52
|
+
A bed is a sound that fills the space, such as the sea, wind or rain. Its level comes from a measure of the scene where the camera stands. That might be the distance to the shore, the trees around the camera, or the wind's speed. Make it with no `near` and no `far`, and set its level in each frame.
|
|
95
53
|
|
|
96
54
|
```ts
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
hum.connect(audio.destination);
|
|
109
|
-
const motor = new OscillatorNode(audio, { type: 'sawtooth', frequency: 110 });
|
|
110
|
-
motor.connect(new GainNode(audio, { gain: 0.1 })).connect(hum);
|
|
111
|
-
motor.start();
|
|
112
|
-
}, { once: true });
|
|
113
|
-
|
|
114
|
-
/** Plays a short tone at a point in the scene. */
|
|
115
|
-
function chime([x, y, z]: number[]) {
|
|
116
|
-
if (!audio) return;
|
|
117
|
-
const panner = new PannerNode(audio, { panningModel: 'HRTF', positionX: x, positionY: y, positionZ: z });
|
|
118
|
-
panner.connect(audio.destination);
|
|
119
|
-
const tone = new OscillatorNode(audio, { frequency: 880 });
|
|
120
|
-
tone.connect(panner);
|
|
121
|
-
tone.start();
|
|
122
|
-
tone.stop(audio.currentTime + 0.2);
|
|
123
|
-
}
|
|
55
|
+
const wind = sound.loop({ file: '/sounds/wind.mp3', positional: false });
|
|
56
|
+
const at = new Float64Array(3);
|
|
57
|
+
const air = new Float32Array(3);
|
|
58
|
+
// In onUpdate: louder and brighter as the wind blows harder and the camera climbs.
|
|
59
|
+
camera.getWorldPosition(at);
|
|
60
|
+
windField.sample(at[0], at[1], at[2], air);
|
|
61
|
+
const speed = Math.hypot(air[0], air[2]);
|
|
62
|
+
const height = Math.min(1, Math.max(0, (at[1] - groundHeight(at[0], at[2])) / 60));
|
|
63
|
+
wind.setLevel(Math.min(1, speed / 10) * (0.4 + 0.6 * height));
|
|
64
|
+
wind.setTone(0.4 + 0.6 * Math.min(1, speed / 12));
|
|
65
|
+
```
|
|
124
66
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
});
|
|
67
|
+
A bed that comes from one side can still have a place. The sea is louder toward the water. So place it out to sea from the camera, along the way the shore faces, and keep it positional. Its level still comes from the sketch.
|
|
68
|
+
|
|
69
|
+
## Sources at places
|
|
70
|
+
|
|
71
|
+
A source at a place falls off with distance by itself. Give it `near`, the distance within which it plays at its full level, and `far`, where it has faded out. A waterfall heard across a valley might take `near: 5` and `far: 400`. With `far`, the sound also loses its highs with distance, as real sounds do.
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
const fall = sound.loop({ file: '/sounds/waterfall.mp3', near: 5, far: 400 });
|
|
75
|
+
fall.setPosition(lip[0], lip[1] - drop, lip[2]);
|
|
76
|
+
```
|
|
133
77
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
78
|
+
Choose `far` as the distance at which a listener would stop hearing the thing, and `near` as the distance at which it is as loud as it gets. The ranges differ by kind:
|
|
79
|
+
|
|
80
|
+
| The source | `near` | `far` |
|
|
81
|
+
| --- | --- | --- |
|
|
82
|
+
| A stream, a fountain or water over stones | 3 | 50 |
|
|
83
|
+
| A bird or a voice nearby | 2 | 60 |
|
|
84
|
+
| A car or a van beside its road | 5 | 120 |
|
|
85
|
+
| A bus or a lorry | 8 | 200 |
|
|
86
|
+
| A crowd or a street of people | 5 | 150 |
|
|
87
|
+
| A waterfall, which is loud and carries | 5 | 400 |
|
|
88
|
+
| The breakers along a beach | 30 | 400 |
|
|
89
|
+
| The open sea heard from shore | 40 | 300 |
|
|
90
|
+
| Thunder, heard across a city | 100 | 4000 |
|
|
91
|
+
|
|
92
|
+
A source whose `far` reaches a kilometer is heard from the whole map, and a scene's opening view roars when nothing stands near it.
|
|
93
|
+
|
|
94
|
+
A long source, such as a stream, has a place that moves with the camera: the nearest point of its course. Work that point out in each frame and move the source there.
|
|
95
|
+
|
|
96
|
+
## Groups of many sources
|
|
97
|
+
|
|
98
|
+
A street of cars, a swarm of bees or the traffic of a city has more sources than a browser can mix. A group plays one file from each member, and gives a few voices to the loudest members where the listener stands. A voice that moves to another member fades out first.
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
const cars = sound.group({ file: '/sounds/car.mp3', count: 40, voices: 6, near: 4, far: 150 });
|
|
102
|
+
// In onUpdate: each car's place, and its engine's pitch from its speed.
|
|
103
|
+
for (let i = 0; i < 40; i++) {
|
|
104
|
+
cars.setPosition(i, x[i], y[i], z[i]);
|
|
105
|
+
cars.setRate(i, 0.8 + speed[i] / 30);
|
|
145
106
|
}
|
|
146
|
-
requestAnimationFrame(follow);
|
|
147
107
|
```
|
|
148
108
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
109
|
+
A sketch that keeps its places in one array of three numbers each copies them in one call: `cars.positions.set(places)`. A member whose level is 0, such as a parked car, takes no voice.
|
|
110
|
+
|
|
111
|
+
## Events
|
|
112
|
+
|
|
113
|
+
A shot plays its file once for each event, such as thunder, a door or a bounce. A physics library's contact events suit it ([Using a physics library](physics.md)).
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
const bounce = sound.shot({ file: '/sounds/bounce.mp3', voices: 4, near: 2, far: 60 });
|
|
117
|
+
// In the contact handler: a harder hit is louder.
|
|
118
|
+
bounce.play(x, y, z, Math.min(1, impact / 8));
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## A mix that works
|
|
122
|
+
|
|
123
|
+
- Normalize the files to one loudness, such as -20 LUFS, so a level of 1 means the same for each. If you cannot change the files, multiply each sound's level by a gain that brings it there.
|
|
124
|
+
- Keep beds below the sources that tell a story. The sea at 0.6 and a passing car at 1 lets the car stand out.
|
|
125
|
+
- Tie a sound to the motion that makes it. Rustling leaves follow the wind's speed and the trees near the camera, and an engine's rate follows its car's speed.
|
|
126
|
+
- Tie a bed's level to the scene. A level that follows the distance to the shore never jumps when the camera cuts.
|
|
127
|
+
- Give every source a reach that matches what makes it. Waves are heard near water, and an engine near its own car. A source whose `far` reaches a kilometer makes an opening view over open water roar. A scene's first frame is the test: where nothing makes a sound, the mix is silent.
|
|
128
|
+
- Never write a level as a step. Move it along a curve that passes through its neighbors, so a car that stops fades through silence rather than cutting off at a threshold. Let the frame's own time smooth what the scene writes.
|
|
129
|
+
- Count the voices of a group. They add as power, so three voices at full level sound about five decibels louder than one loop. Give a group's members a lower level than a loop's.
|
|
130
|
+
- Write massed ambience as one loop scaled by density, such as a wood's leaves from the canopy around the camera. One source for each of fifty trees adds up in a way no listener calls rustling. A density that levels off cannot pile up.
|
|
131
|
+
- Check the mix at fixed camera places, not by ear alone: the opening pose, the shore, a town square and the climb. The opening should be silent, and each place should lead with the sound its view shows. No level should move faster between frames than a listener would expect.
|
|
132
|
+
|
|
133
|
+
## How the sound reaches the speakers
|
|
134
|
+
|
|
135
|
+
The browser offers its audio on the page's main thread only, and the sketch runs in a worker. The add-on bridges the two with a table that the page shares. The sketch writes each sound's values there, and a mixer on the browser's audio thread reads them and drives each voice.
|
|
153
136
|
|
|
154
|
-
|
|
137
|
+
Where the page shares its memory with its workers, no message travels in a frame. The page's thread then does no work while the sounds play. When the engine pauses or the page is hidden, the sketch's frames stop, and the sound fades out with them.
|
|
155
138
|
|
|
156
|
-
|
|
139
|
+
The page can still play its own sounds with Web Audio, such as music or the clicks of its buttons. Such sounds belong to the page, so they need no add-on.
|
|
157
140
|
|
|
158
141
|
## Related pages
|
|
159
142
|
|
|
160
|
-
- [
|
|
143
|
+
- [Sound (@null3d/sound)](../api/sound.md): every call, the distances, the voices and the costs.
|
|
144
|
+
- [Sources at places](https://github.com/null3d-engine/null3d/tree/main/examples/sound): a thunderstorm on the moor, where each strike's thunder plays from where it struck.
|
|
145
|
+
- [Beds whose level the scene sets](https://github.com/null3d-engine/null3d/tree/main/examples/showcase/creek): the creek's loops follow the water and the wind.
|
|
146
|
+
- [Groups of many sources](https://github.com/null3d-engine/null3d/tree/main/examples/showcase/skyway): the hover cars, rain, thunder and city of a rainy night.
|
|
147
|
+
- [Cars and a bus as one group](https://github.com/null3d-engine/null3d/tree/main/examples/showcase/island): the island's traffic sounds from its lanes.
|
|
148
|
+
- [Messages between sketch and page](../api/page.md): messages for events that the page shows.
|
|
161
149
|
- [Using a physics library](physics.md): events from a physics world, such as a bounce.
|
|
162
|
-
- [
|
|
163
|
-
- [Hosting and cross-origin isolation](../getting-started/hosting.md): when a page gets shared memory.
|
|
150
|
+
- [Hosting and cross-origin isolation](../getting-started/hosting.md): when a page shares its memory.
|
|
@@ -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
|
|
|
@@ -117,5 +122,6 @@ plain metallic paint.
|
|
|
117
122
|
- [Surface functions](../shaders/surface-functions.md): the surface record that the paint returns.
|
|
118
123
|
- [A material's own lobe](../shaders/surface-functions.md#a-materials-own-lobe): the hook that the
|
|
119
124
|
glints use.
|
|
120
|
-
- [The Showroom demo](https://github.com/null3d-engine/null3d/tree/main/examples/
|
|
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.
|