@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
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: guides/content-pages
|
|
3
3
|
title: 3D scenes on content pages
|
|
4
|
-
status: experimental
|
|
5
|
-
since: "0.1"
|
|
6
4
|
summary: "Product and marketing pages: the fallback page, a load deadline, pausing off screen, scroll-driven cameras, second visits and crashes."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# 3D scenes on content pages
|
|
10
8
|
|
|
11
|
-
> Roadmap step 0.1, first released in null3D 0.1.0. The API is experimental, so it can still change between versions.
|
|
12
|
-
|
|
13
9
|
On a product page or a marketing page, the visitor came for the page. The 3D scene supports it. So the page must work without the scene, show its content on time, and spend nothing on a scene that nobody can see.
|
|
14
10
|
|
|
15
11
|
A game or a full-screen app is different, because there the scene is the product. Each section says where its advice changes for such pages.
|
|
@@ -64,8 +60,8 @@ Decide how long a visitor waits for the scene, and count it from the moment the
|
|
|
64
60
|
- Keep the waiting state short. Largest Contentful Paint, the time until the largest content appears, should come within 2.5 seconds. Measure your own cold load on a slow connection before you pick a deadline.
|
|
65
61
|
- Never hide the page's text while the scene loads. Where a rule must hide content, put it inside `@media (scripting: enabled)`, so a page without JavaScript still shows everything.
|
|
66
62
|
- Show no loading indicator for the first half second or so. A fast load then never flashes one.
|
|
67
|
-
-
|
|
68
|
-
- Reveal the canvas only when `engine.firstFrame` resolves. Before that, it shows nothing.
|
|
63
|
+
- Within a phase, never let a progress value move back. Keep the largest value shown so far in that phase. When a new phase starts, name it beside its number ([Loading screens](loading-screens.md#show-progress-on-the-page)).
|
|
64
|
+
- Reveal the canvas only when `engine.firstFrame` resolves. Before that, it shows nothing. It rejects when drawing stops before the first frame, and the page then keeps its poster.
|
|
69
65
|
- Chromium browsers report `navigator.connection.saveData`. When it is true, go straight to the late state.
|
|
70
66
|
|
|
71
67
|
```ts
|
|
@@ -75,12 +71,18 @@ const root = document.documentElement;
|
|
|
75
71
|
setTimeout(() => {
|
|
76
72
|
if (!root.classList.contains('ready')) root.classList.add('late');
|
|
77
73
|
}, Math.max(0, DEADLINE_MS - performance.now()));
|
|
78
|
-
|
|
79
|
-
|
|
74
|
+
try {
|
|
75
|
+
await engine.firstFrame;
|
|
76
|
+
root.classList.add('ready'); // CSS fades the canvas in over the poster
|
|
77
|
+
} catch {
|
|
78
|
+
// Drawing stopped before the first frame: the onFailure handler above keeps the poster.
|
|
79
|
+
}
|
|
80
80
|
```
|
|
81
81
|
|
|
82
82
|
For a game, the late state has no page content to show. There it changes the message, and opens the menus and settings that do not need the scene.
|
|
83
83
|
|
|
84
|
+
Later page blocks run after a successful start, inside that `try`.
|
|
85
|
+
|
|
84
86
|
## Mark a decorative canvas
|
|
85
87
|
|
|
86
88
|
A scene that only decorates gets `aria-hidden="true"`, so screen readers skip it. It takes no keyboard focus. Give it `pointer-events: none` when it does not react to the pointer, so clicks reach the page. [Accessibility](accessibility.md) covers a canvas the visitor operates.
|
|
@@ -120,51 +122,77 @@ When the page also has a pause button, or pauses for reduced motion, combine the
|
|
|
120
122
|
|
|
121
123
|
## Drive the camera from the scroll position
|
|
122
124
|
|
|
123
|
-
The page reads the scroll position, and the sketch moves the camera.
|
|
125
|
+
The page reads the scroll position, and the sketch moves the camera. Pass the first position as [start data](../api/page.md#start-data), so the first frame already shows it. A held frame of a page that opens partway down then shows it too. After the start, send the position only when it changes, at most once per animation frame:
|
|
124
126
|
|
|
125
127
|
```ts
|
|
126
128
|
// page.ts
|
|
129
|
+
const progress = () => {
|
|
130
|
+
const range = Math.max(1, document.documentElement.scrollHeight - window.innerHeight);
|
|
131
|
+
return Math.min(1, Math.max(0, window.scrollY / range));
|
|
132
|
+
};
|
|
133
|
+
const engine = await createEngine({
|
|
134
|
+
canvas,
|
|
135
|
+
sketch: new URL('./sketch.ts', import.meta.url),
|
|
136
|
+
sketchData: { scroll: progress() }, // the first frame's position
|
|
137
|
+
});
|
|
127
138
|
let queued = false;
|
|
128
139
|
const sendScroll = () => {
|
|
129
140
|
queued = false;
|
|
130
|
-
|
|
131
|
-
const progress = window.scrollY / range;
|
|
132
|
-
engine.postToSketch('scroll', Math.min(1, Math.max(0, progress)));
|
|
141
|
+
engine.postToSketch('scroll', progress());
|
|
133
142
|
};
|
|
134
143
|
window.addEventListener('scroll', () => {
|
|
135
144
|
if (!queued) requestAnimationFrame(sendScroll);
|
|
136
145
|
queued = true;
|
|
137
146
|
}, { passive: true });
|
|
138
|
-
sendScroll(); //
|
|
147
|
+
sendScroll(); // a position that the browser restored during the start
|
|
139
148
|
```
|
|
140
149
|
|
|
141
|
-
The sketch eases toward
|
|
150
|
+
The sketch starts at the start data's position, and eases toward each later one. Its easing factor depends on the frame's time step, so the motion looks the same at 60 and at 144 frames per second. The browser can restore the scroll position after the start, so the sketch jumps to the first position it receives. A page that opens scrolled down then never shows a camera flight. The page reveals the canvas once `engine.firstFrame` resolves:
|
|
142
151
|
|
|
143
152
|
```ts
|
|
144
153
|
// sketch.ts
|
|
145
|
-
|
|
146
|
-
let
|
|
147
|
-
let
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
154
|
+
export default defineSketch<{ scroll: number }>(({ data, page, preferences }) => {
|
|
155
|
+
let target = data?.scroll ?? 0;
|
|
156
|
+
let current = target;
|
|
157
|
+
let placed = false;
|
|
158
|
+
let toldPage = false;
|
|
159
|
+
page.onMessage((type, value) => {
|
|
160
|
+
if (type !== 'scroll') return;
|
|
161
|
+
target = value as number;
|
|
162
|
+
if (!placed) current = target;
|
|
153
163
|
placed = true;
|
|
154
|
-
|
|
155
|
-
|
|
164
|
+
});
|
|
165
|
+
return {
|
|
166
|
+
onUpdate(dt) {
|
|
167
|
+
// Closes 99.9% of the gap in one second, at any frame rate.
|
|
168
|
+
const k = preferences.reducedMotion ? 1 : 1 - Math.pow(0.001, dt);
|
|
169
|
+
current += (target - current) * k;
|
|
170
|
+
if (Math.abs(target - current) < 0.0001) current = target;
|
|
171
|
+
placeCamera(current);
|
|
172
|
+
if (!toldPage) {
|
|
173
|
+
toldPage = true;
|
|
174
|
+
page.post('placed');
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
};
|
|
156
178
|
});
|
|
157
|
-
return {
|
|
158
|
-
onUpdate(dt) {
|
|
159
|
-
// Closes 99.9% of the gap in one second, at any frame rate.
|
|
160
|
-
const k = preferences.reducedMotion ? 1 : 1 - Math.pow(0.001, dt);
|
|
161
|
-
current += (target - current) * k;
|
|
162
|
-
if (Math.abs(target - current) < 0.0001) current = target;
|
|
163
|
-
placeCamera(current);
|
|
164
|
-
},
|
|
165
|
-
};
|
|
166
179
|
```
|
|
167
180
|
|
|
181
|
+
The sketch posts `placed` once, after it first places the camera. The page then waits for both that message and the first frame:
|
|
182
|
+
|
|
183
|
+
```ts
|
|
184
|
+
// page.ts
|
|
185
|
+
const placed = new Promise<void>((resolve) =>
|
|
186
|
+
engine.onSketchMessage((type) => { if (type === 'placed') resolve(); }),
|
|
187
|
+
);
|
|
188
|
+
await Promise.all([engine.firstFrame, placed]);
|
|
189
|
+
root.classList.add('ready');
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
A page without scroll-driven cameras awaits only `engine.firstFrame`.
|
|
193
|
+
|
|
194
|
+
A canvas behind the page's text often wants its subject beside the text, not under it. Shift the lens rather than turn the camera: `camera.setLensShift(-0.25, 0)` puts the camera's target three quarters of the way across, and upright lines stay upright. A section can change the shift as the scroll moves, in the same `onUpdate` ([Cameras](../api/cameras.md#lens-shift)).
|
|
195
|
+
|
|
168
196
|
## Second visits and navigation
|
|
169
197
|
|
|
170
198
|
| Lifetime | What keeps it | How |
|
|
@@ -174,7 +202,7 @@ return {
|
|
|
174
202
|
| Views of a single-page app | The running engine | `engine.detach()` and `engine.attach(element)`: [Architecture](../concepts/architecture.md) |
|
|
175
203
|
| Back and forward | The browser's back/forward cache | Listen for `pagehide`, never `unload`, and do not send `Cache-Control: no-store` on the page |
|
|
176
204
|
|
|
177
|
-
Browsers decide whether they can keep a page with a running engine in the back/forward cache. Build the page so that a full reload works too. [Caches between visits](../getting-started/hosting.md#caches-between-visits) shows every cache that a repeat visit uses.
|
|
205
|
+
Browsers decide whether they can keep a page with a running engine in the back/forward cache. Build the page so that a full reload works too. On phones and tablets the engine gives its GPU back while the page sits in that cache. It builds the scene's GPU objects again when the page shows ([When the GPU goes away](../concepts/backends.md#when-the-gpu-goes-away)). [Caches between visits](../getting-started/hosting.md#caches-between-visits) shows every cache that a repeat visit uses.
|
|
178
206
|
|
|
179
207
|
A sketch that generates data, such as a terrain or a scatter of objects, can keep it in the engine's cache of derived data. The call `assets.cache(name, version)` gives the sketch a namespace of it ([Caching](../api/assets.md#the-cache-of-derived-data)). Follow these rules:
|
|
180
208
|
|
|
@@ -218,7 +246,7 @@ else {
|
|
|
218
246
|
write(String(Date.now()));
|
|
219
247
|
addEventListener('pagehide', () => write(null));
|
|
220
248
|
// ... createEngine, then:
|
|
221
|
-
await engine.firstFrame;
|
|
249
|
+
await engine.firstFrame.catch(() => {}); // a start that failed cleanly is no crash
|
|
222
250
|
setTimeout(() => write(null), 5000);
|
|
223
251
|
}
|
|
224
252
|
```
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: guides/custom-passes
|
|
3
3
|
title: Custom passes and render targets
|
|
4
|
-
status: experimental
|
|
5
|
-
since: "0.2"
|
|
6
4
|
summary: "Custom effects and tone curves in WGSL; declaring passes; reading and writing named textures; layer masks; reflections and a water recipe; full-screen passes, a soft outline glow and effects that read textures."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Custom passes and render targets
|
|
10
8
|
|
|
11
|
-
> Roadmap step 0.2, first released in null3D 0.1.0. The API is experimental, so it can still change between versions.
|
|
12
|
-
|
|
13
9
|
```mermaid
|
|
14
10
|
flowchart LR
|
|
15
11
|
scene["Scene passes:<br/>linear HDR color"] --> e1["Effect 1"]
|
|
@@ -22,7 +18,16 @@ flowchart LR
|
|
|
22
18
|
final --> canvas["Canvas"]
|
|
23
19
|
```
|
|
24
20
|
|
|
25
|
-
A custom
|
|
21
|
+
A custom pass adds work of your own to the frame. This page covers six kinds:
|
|
22
|
+
|
|
23
|
+
| Kind | Reads | Writes | Section |
|
|
24
|
+
| --- | --- | --- | --- |
|
|
25
|
+
| Custom effect | The scene's color, and its depth if it asks | A new color for the screen | [Custom effects](#custom-effects) |
|
|
26
|
+
| Custom tone curve | Linear color after bloom | The final display color | [Custom tone curves](#custom-tone-curves) |
|
|
27
|
+
| Scene pass | The scene, from a camera of its own | A texture that materials show | [Render to a texture](#render-to-a-texture) |
|
|
28
|
+
| Reflection pass | The scene, mirrored across a plane | A texture that materials read | [Reflections](#reflections) |
|
|
29
|
+
| Full-screen pass | An effect's WGSL, and an input image | A texture of its own | [Full-screen passes](#full-screen-passes) |
|
|
30
|
+
| Compute pass | A compute shader | A storage texture | [Compute passes](#compute-passes) |
|
|
26
31
|
|
|
27
32
|
## Custom effects
|
|
28
33
|
|
|
@@ -71,8 +76,9 @@ The effect can also call these functions:
|
|
|
71
76
|
| --- | --- |
|
|
72
77
|
| `effectColor(uv: vec2f) -> vec4f` | The image's color at `uv`, read with a linear filter. Places outside the image read its edge. |
|
|
73
78
|
| `effectPixel(pixel: vec2i) -> vec4f` | The color of one pixel, counted from the top left. A pixel outside the image reads the nearest one inside. |
|
|
79
|
+
| `effectBloom(uv: vec2f) -> vec3f` | The glow at `uv` of the bloom chain's level that the effect's `bloomLevel` names, as linear HDR color. A level that the chain does not draw reads black ([Custom effects](../api/post.md#custom-effects)). |
|
|
74
80
|
| `effectDepth(uv: vec2f) -> f32` | The scene's depth at `uv`: 1 at the camera's near plane, 0 at its far plane, and 0 where nothing drew. |
|
|
75
|
-
| `effectViewPosition(uv: vec2f) -> vec3f` | The position of the surface at `uv` in view space. Its z is negative in front of the camera
|
|
81
|
+
| `effectViewPosition(uv: vec2f) -> vec3f` | The position of the surface at `uv` in view space. Its z is negative in front of the camera. |
|
|
76
82
|
| `effectDistance(uv: vec2f) -> f32` | How far in front of the camera the surface at `uv` lies, in world units. |
|
|
77
83
|
| `effectInputSize() -> vec2f` | The image's size in pixels. In an effect it equals `input.size`; a [full-screen pass](#full-screen-passes) of another size needs it. |
|
|
78
84
|
| `effectPassUv(uv: vec2f) -> vec2f` | The coordinates in a render pass's texture of the image's place `uv`. A pass texture holds its bottom row first, so `v` turns around. |
|
|
@@ -83,7 +89,7 @@ Effects import from the shader library as materials do, such as `#import null3d:
|
|
|
83
89
|
|
|
84
90
|
### Uniforms
|
|
85
91
|
|
|
86
|
-
Declare uniforms as `struct Uniforms`, and read them as `uniforms.name`.
|
|
92
|
+
Declare uniforms as `struct Uniforms`, and read them as `uniforms.name`. A custom material reads its own as `material.name`, but the other rules are the same:
|
|
87
93
|
|
|
88
94
|
- The types are `f32`, `i32`, `u32`, `vec2f`, `vec3f` and `vec4f`, in at most 32 numbers. Each `vec3f` and `vec4f` starts a group of four.
|
|
89
95
|
- A `vec3f` also takes a color string or a hex number, which the engine converts from sRGB to linear.
|
|
@@ -212,15 +218,21 @@ For caustics on the bed, find each pixel's point in the world as `eye + line.xyz
|
|
|
212
218
|
### Cost
|
|
213
219
|
|
|
214
220
|
- A full-screen pass reads and writes 8 bytes per pixel of the render size, in `rgba16float`. On a phone at full resolution each pass costs tens of megabytes of memory traffic per frame. One pass at full size costs about 0.05 ms of GPU time on a MacBook Pro, 0.1 ms on an iPad Pro with the A12X, and 0.25 to 0.31 ms on a Pixel 10.
|
|
215
|
-
- The engine joins effects
|
|
221
|
+
- The engine joins effects at every render scale. An effect that reads only its own pixel joins the pass of the effect before it: the pass runs both, one after the other, for each pixel. So you need not join such effects into one function yourself.
|
|
222
|
+
- The last pass of effects folds into the final pass only in frames at the whole canvas's scale, with bloom, depth of field and FXAA off. While the scale can drop below the whole canvas, nothing folds, even in a frame at scale 1 ([The post-processing chain](../concepts/post-processing.md#below-the-whole-canvass-render-scale)).
|
|
223
|
+
- Adding or removing an effect changes the frame's passes. A new effect's pipeline builds while the last image stays on screen, as a custom material's does. So a new effect shows a few frames after `addEffect`. To show it at a set moment, add it a little before.
|
|
224
|
+
|
|
225
|
+
<details>
|
|
226
|
+
<summary>Technical details: how the engine joins and folds effects</summary>
|
|
227
|
+
|
|
216
228
|
- An effect that calls `effectPixel` or `effectColor` reads other pixels of the color before it. So it starts a pass of its own. The effects after it can join it. Depth reads do not stop an effect from joining.
|
|
217
|
-
- The last pass of effects folds into the final pass when nothing reads the image between them. That needs bloom and FXAA off, and it needs the render scale to stay at the whole canvas: while the scale can drop below it, nothing folds, also in frames that draw at scale 1. One effect that reads only its own pixel then costs no pass of its own.
|
|
218
229
|
- A joined pass needs a shader that the engine makes from the effects' WGSL. It builds in the background after the effects' own shaders. Until it is built, each effect draws a pass of its own, so no frame waits for it.
|
|
219
230
|
- Some browsers cannot compile WebGL2 shaders in the background, such as Chrome on the Android phones tested. On WebGL2 they join only the effects that are there before the first frame. Effects added or reordered later draw a pass each there. A joined shader would hold up a frame while it compiles. Add your effects before the first frame to get the joined passes on those devices. Development builds tell you once in the console when this happens.
|
|
220
231
|
- Between joined effects the color keeps 32-bit precision instead of the 16 bits of a target. So the image can differ from separate passes in the last bits.
|
|
221
232
|
- The effects share two targets, whatever their number. They follow the render scale, so a new scale makes no new target.
|
|
222
233
|
- A depth read costs one texture read per call. The scene's render pass then keeps its depth in memory.
|
|
223
|
-
|
|
234
|
+
|
|
235
|
+
</details>
|
|
224
236
|
|
|
225
237
|
### Devices without HDR color
|
|
226
238
|
|
|
@@ -233,7 +245,7 @@ A debug view, such as `debug.view('normals')`, turns effects off while it draws.
|
|
|
233
245
|
A custom tone curve replaces the built-in curves (`'agx-punchy'`, the default, and `'agx'`, `'aces'`, `'neutral'` and `'none'`). Its WGSL declares one function, and `post.set` takes it as `toneMapping`:
|
|
234
246
|
|
|
235
247
|
```ts
|
|
236
|
-
// Reinhard's curve
|
|
248
|
+
// Reinhard's tone curve.
|
|
237
249
|
const reinhard = /* wgsl */ `
|
|
238
250
|
fn toneCurve(color: vec3f) -> vec3f {
|
|
239
251
|
return color / (vec3f(1.0) + color);
|
|
@@ -250,9 +262,11 @@ post.set({ toneMapping: 'aces' });
|
|
|
250
262
|
- A curve needs HDR color, as effects do. On a device with no HDR target, the built-in curve stays.
|
|
251
263
|
- The final pass builds again with the curve, so the first frame with a new curve waits for its pipeline.
|
|
252
264
|
|
|
265
|
+
The [Creek showcase](https://github.com/null3d-engine/null3d/tree/main/examples/showcase/creek) sets its own WGSL tone curve in the scene's look.
|
|
266
|
+
|
|
253
267
|
## Render to a texture
|
|
254
268
|
|
|
255
|
-
A scene pass draws the scene from a camera of your own into a texture
|
|
269
|
+
A scene pass draws the scene from a camera of your own into a texture. `textures.fromPass` gives the texture to any material or sprite.
|
|
256
270
|
|
|
257
271
|
```mermaid
|
|
258
272
|
flowchart LR
|
|
@@ -302,21 +316,43 @@ A pass that need not change every frame draws every few frames. `setPassEvery` g
|
|
|
302
316
|
render.setPassEvery(map, 4);
|
|
303
317
|
```
|
|
304
318
|
|
|
305
|
-
|
|
319
|
+
`setPassEvery` compiles nothing, so a sketch may change the cadence as often as once a frame, for example when the quality preset or the frame budget moves. In a frame that the pass skips, a material that samples its texture shows the last image that it drew.
|
|
320
|
+
|
|
321
|
+
`render.setPassEnabled(pass, false)` turns a pass off, and its texture keeps its last image. Use the switch when a feature starts or stops, and the cadence to draw less often. Switching on a pass that has never drawn compiles the render graph. [Switching and removing passes](../api/render.md#switching-and-removing-passes) gives the full rule.
|
|
322
|
+
|
|
323
|
+
<details>
|
|
324
|
+
<summary>Technical details: cadence, the switch and the compiled plan</summary>
|
|
325
|
+
|
|
326
|
+
The engine compiles the render graph into a plan of GPU passes. A skipped frame neither culls nor clears the pass's target. A pass that has never drawn is out of the plan while it is off, so switching it on compiles the graph. Once a pass has drawn, its GPU passes stay in the plan while it is off: the switch only skips their recording and compiles nothing. [Render graph](../concepts/render-graph.md) explains the plan.
|
|
327
|
+
|
|
328
|
+
</details>
|
|
306
329
|
|
|
307
330
|
In [hold mode](testing.md#hold-mode) every pass draws in every frame, whatever its cadence. The engine draws only the hold's last frames, so a pass that skipped one of them would show an image that no drawn frame made: an empty mirror, for one.
|
|
308
331
|
|
|
309
332
|
### What a scene pass draws
|
|
310
333
|
|
|
311
|
-
A scene pass draws with the scene's materials, the sun and its shadows where the camera's shadow cascades reach. It draws
|
|
334
|
+
A scene pass draws with the scene's materials, the sun and its shadows where the camera's shadow cascades reach. It draws:
|
|
335
|
+
|
|
336
|
+
- the ambient and hemisphere lights, the environment's light and the fog;
|
|
337
|
+
- the point and spot lights that its camera sees;
|
|
338
|
+
- the scene's background behind them, the sky included.
|
|
339
|
+
|
|
340
|
+
With a `clearColor` the texture clears to that color and shows no background, which suits a minimap. A pass draws no ambient occlusion.
|
|
341
|
+
|
|
342
|
+
A point or spot light casts its shadow in a pass when the camera's view gives it a shadow. The engine gives shadows only to the lights that the camera sees. So a light that only the pass sees lights the pass without a shadow.
|
|
343
|
+
|
|
344
|
+
<details>
|
|
345
|
+
<summary>Technical details: lights and shadows in a scene pass</summary>
|
|
312
346
|
|
|
313
|
-
|
|
347
|
+
Reflection passes draw these lights the same way. A pass that sees a point or spot light keeps its own list of lights, as the camera's view does. The list takes under 1 MB of memory. A pass that sees none keeps no list.
|
|
348
|
+
|
|
349
|
+
</details>
|
|
314
350
|
|
|
315
351
|
The texture holds linear color after the exposure, so a material that shows it gives the camera the light that the pass saw. On devices that draw 8-bit color, each material tone maps its own color. In compatibility mode with MSAA, the texture holds that color turned back to linear, so the tone curve applies twice and the image looks a little lighter in the middle tones. On WebGL2 devices without float targets, the texture holds display color, which looks brighter and flatter.
|
|
316
352
|
|
|
317
353
|
## Reflections
|
|
318
354
|
|
|
319
|
-
A reflection pass draws the camera's view mirrored across a plane into a texture
|
|
355
|
+
A reflection pass draws the camera's view mirrored across a plane into a texture. Everything below the plane is clipped. A custom material reads the texture where its surface shows on the screen, so water and polished floors reflect what stands on them. [Render graph API](../api/render.md#reflection-passes) lists the options, and [Surface functions](../shaders/surface-functions.md#reflections) the WGSL side. The [water demo](https://github.com/null3d-engine/null3d/tree/main/examples/water) uses the add-on's reflection for a river and a lake.
|
|
320
356
|
|
|
321
357
|
```ts
|
|
322
358
|
const pass = render.addPass({ kind: 'reflection', writes: 'water', plane: { point: [0, 0, 0] } });
|
|
@@ -326,13 +362,19 @@ const water = materials.shader({ wgsl: waterWgsl, textures: { mirror: textures.f
|
|
|
326
362
|
- The pass follows the active camera. The quality preset sets its size: half the render size each way on Medium and High.
|
|
327
363
|
- The surface function puts the pass's color in the surface's `reflection`. The engine's lighting then weighs it with the material's Fresnel, so water reflects little straight down and much at a low angle.
|
|
328
364
|
- `scale: 1` gives a sharp mirror. `every: 2` draws the reflection in every other frame, for a camera that moves slowly.
|
|
329
|
-
- A reflection draws the scene's background, the sun's light and shadows, and the point and spot lights that it sees. It draws no ambient occlusion
|
|
365
|
+
- A reflection draws the scene's background, the sun's light and shadows, and the point and spot lights that it sees. It draws no ambient occlusion.
|
|
330
366
|
|
|
331
367
|
### A water recipe
|
|
332
368
|
|
|
333
369
|
For water in a scene, use [`@null3d/water`](../api/water.md): it draws a river and a lake from one shape, with the waves, the foam, the soft shore and the reflection that this recipe builds by hand. This recipe shows the pieces that the add-on builds on, for a water surface of your own.
|
|
334
370
|
|
|
335
|
-
|
|
371
|
+

|
|
372
|
+
|
|
373
|
+
A reflection pass read by a water material.
|
|
374
|
+
|
|
375
|
+
This surface function makes a stream. It has ripples that move, a tint that deepens with the depth, foam at the banks, and the reflection of the banks and the sky.
|
|
376
|
+
|
|
377
|
+
It needs the height of the bed under each point of the water. A terrain made in code gives it with the same function that shapes the terrain. A loaded terrain gives it with a height map texture, which the function samples instead.
|
|
336
378
|
|
|
337
379
|
```ts
|
|
338
380
|
const waterWgsl = /* wgsl */ `
|
|
@@ -417,8 +459,7 @@ surface.setRotationEuler(-Math.PI / 2, 0, 0);
|
|
|
417
459
|
- `ripple` sets how far the waves tilt the normal. The tilt bends the reflection and the sun's highlights.
|
|
418
460
|
- The foam hides the reflection where it lies, through the reflection's share in `a`.
|
|
419
461
|
- The water is opaque, so the bed does not show through it. The shallow tint stands in for the bed's color.
|
|
420
|
-
- Without a height map of the bed, a blended sheet
|
|
421
|
-
|
|
462
|
+
- Without a height map of the bed, a blended sheet can read the scene's depth with `sceneInputs: ['sceneDepth']` and fade its alpha near the bank for a soft shore. [Materials](../api/materials.md#the-scene-behind-a-surface) shows the WGSL.
|
|
422
463
|
- Waves that move the surface's vertices need `setBounds`, as [Culling](../concepts/culling.md) explains. The reflection's plane stays flat, which suits small waves.
|
|
423
464
|
|
|
424
465
|
## Full-screen passes
|
|
@@ -466,7 +507,7 @@ A pass that names no input image is placed before the camera's passes. A chain o
|
|
|
466
507
|
|
|
467
508
|
### A soft outline glow
|
|
468
509
|
|
|
469
|
-
|
|
510
|
+
The built-in outline draws a crisp line ([Outlines](../api/post.md#outlines)). A full-screen pass and an effect add a soft glow around it. The `@null3d/three-compat` add-on builds this shape with `createOutlinePass`, which takes settings for the glow, a pulse and the blur ([its API page](../api/three-compat.md)). The recipe below shows what it does.
|
|
470
511
|
|
|
471
512
|
```ts
|
|
472
513
|
const glowFromMask = /* wgsl */ `
|
|
@@ -503,7 +544,7 @@ post.addEffect({ wgsl: addGlow, textures: { glow: textures.fromPass(glow) } });
|
|
|
503
544
|
|
|
504
545
|
## Compute passes
|
|
505
546
|
|
|
506
|
-
A compute pass runs a compute shader over a texture of its own, on WebGPU. Use one when the work suits a GPU's parallel threads better than a pixel: a wave simulation that combines each pixel with its neighbors, a table that the shader fills in a loop, or a field that several materials read. [Render graph API](../api/render.md#compute-passes) lists its options and the bindings that its shader declares.
|
|
547
|
+
A compute pass runs a compute shader over a texture of its own, on WebGPU. Use one when the work suits a GPU's parallel threads better than a pixel: a wave simulation that combines each pixel with its neighbors, a table that the shader fills in a loop, or a field that several materials read. [Render graph API](../api/render.md#compute-passes) lists its options and the bindings that its shader declares. The [Ocean demo](https://github.com/null3d-engine/null3d/tree/main/examples/ocean) runs compute passes through the water add-on.
|
|
507
548
|
|
|
508
549
|
```ts
|
|
509
550
|
const ripples = /* wgsl */ `
|
|
@@ -580,6 +621,8 @@ const water = materials.unlit({ map: textures.fromPass(field) });
|
|
|
580
621
|
- [Post-processing API](../api/post.md): `post.addEffect`, `post.setEffectUniform`, `post.removeEffect` and `post.set`.
|
|
581
622
|
- [Render graph API](../api/render.md): `render.addPass`, `render.setPassUniform`, `render.setPassEnabled`, `render.removePass` and `render.dumpGraph`.
|
|
582
623
|
- [The security camera demo](https://github.com/null3d-engine/null3d/tree/main/examples/security-camera): a scene pass whose texture a monitor shows.
|
|
624
|
+
- [The post effects demo](https://github.com/null3d-engine/null3d/tree/main/examples/post-effects): its effect code lives in `examples/addons/lens-kit/`, which the demo imports.
|
|
625
|
+
- [The custom shader inputs demo](https://github.com/null3d-engine/null3d/tree/main/examples/shader-inputs): a custom material's shader, uniforms and textures.
|
|
583
626
|
- [The post-processing chain](../concepts/post-processing.md): where effects run, and the built-in effects.
|
|
584
627
|
- [Custom shaders](custom-shaders.md): the WGSL build, uniforms and the shader library.
|
|
585
628
|
- [Porting post-processing](../porting/threejs-postprocessing.md): three.js's `ShaderPass` and effect passes.
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: guides/custom-shaders
|
|
3
3
|
title: Custom shaders
|
|
4
|
-
status: experimental
|
|
5
|
-
since: "0.1"
|
|
6
4
|
summary: "WGSL in sketch code; shader errors; surface functions; full shaders; uniforms, textures and typed materials; hot reload."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Custom shaders
|
|
10
8
|
|
|
11
|
-
> Roadmap step 0.1, first released in null3D 0.1.0. Step 0.2 adds typed uniforms, textures and hot reload. The API is experimental, so it can still change between versions. Custom materials with surface functions, vertex offsets, uniforms, textures and full shaders are built, and so is hot reload on the dev server.
|
|
12
|
-
|
|
13
9
|
```mermaid
|
|
14
10
|
flowchart LR
|
|
15
11
|
file["A .wgsl file<br/>that a module imports"] --> plugin["The null3D Vite plugin<br/>in vite and vite build"]
|
|
@@ -19,7 +15,7 @@ flowchart LR
|
|
|
19
15
|
plugin -. "a problem" .-> error["An error at the file,<br/>line and column"]
|
|
20
16
|
```
|
|
21
17
|
|
|
22
|
-
You write each null3D shader once, in WGSL. The null3D Vite plugin compiles the WGSL in your code while Vite serves or builds the project. Each shader becomes WGSL for WebGPU and GLSL ES 3.00 for WebGL2, so the page never downloads a shader translator.
|
|
18
|
+
You write each null3D shader once, in WGSL. The null3D Vite plugin compiles the WGSL in your code while Vite serves or builds the project. Each shader becomes WGSL for WebGPU and GLSL ES 3.00 for WebGL2, so the page never downloads a shader translator. The examples on this page tag WGSL with a `/* wgsl */` comment. [WGSL in sketch code](#wgsl-in-sketch-code) gives the two forms and the rules of the tag.
|
|
23
19
|
|
|
24
20
|
## Custom materials
|
|
25
21
|
|
|
@@ -40,7 +36,7 @@ fn surface(input: SurfaceInput) -> Surface {
|
|
|
40
36
|
const red = materials.shader({ wgsl: rings, color: '#e04040', roughness: 0.5 });
|
|
41
37
|
```
|
|
42
38
|
|
|
43
|
-
The WGSL can declare uniforms as `struct Uniforms`,
|
|
39
|
+
The WGSL can declare uniforms as `struct Uniforms` and read each field as `material.name`, and `set()` changes them at any time. It can declare textures as `var name: texture_2d<f32>;`, or texture arrays whose layers the shader picks as `var name: texture_2d_array<f32>;`, which the `textures` option gives. A vertex offset, `fn vertexOffset`, moves the mesh's vertices. A lobe, `fn lobe`, adds specular beside the base lobe for the main directional light and for each point and spot light. [Surface functions](../shaders/surface-functions.md) describes the surface input, the surface record, `defaultSurface`, uniforms, textures, vertex offsets and lobes. [Built-in shader inputs](../shaders/builtins.md) lists the values that every custom material reads, such as `frame.time`. The [custom shader inputs demo](https://github.com/null3d-engine/null3d/tree/main/examples/shader-inputs) makes 900 crystals from one custom material.
|
|
44
40
|
|
|
45
41
|
## Full shaders
|
|
46
42
|
|
|
@@ -87,13 +83,26 @@ const ghost = materials.shader({ wgsl: hologram, doubleSided: true });
|
|
|
87
83
|
The plugin takes WGSL as a full shader when its `@vertex` entry point takes an `InstanceIn`. The shader follows these rules:
|
|
88
84
|
|
|
89
85
|
- It has one `@vertex` and one `@fragment` entry point.
|
|
90
|
-
- The vertex entry point reads the mesh at the engine's locations
|
|
86
|
+
- The vertex entry point reads the mesh at the engine's locations, in the table below. A mesh draws only when it has every attribute that the shader reads.
|
|
91
87
|
- Pass the position through `mesh_position`, and texture coordinates through `mesh_uv` and `mesh_second_uv`, from `null3d::vertex`. They give the values that the mesh holds on every GPU path. WebGPU reads plain integer attributes as fractions, and these functions scale them back. Floats and normalized integers pass through unchanged.
|
|
92
88
|
- It finds its instance with `InstanceIn` and `find_instance` from `null3d::mesh`. On each GPU path, the engine gives each instance's transform in its own way, and these hide the difference.
|
|
93
89
|
- `null3d::mesh` also gives `clip_position(found, position)`, `relative_position(found, position)` and `world_normal(found, normal)`. Positions are relative to the camera, as in the engine's own shaders.
|
|
94
|
-
- The fragment entry point writes its linear color through `finish(color, clip.xy)` from `null3d::mesh`, which prepares it for the engine's output. `finish` multiplies the color by the exposure, as the engine does with an unlit material's color.
|
|
90
|
+
- The fragment entry point writes its linear color through `finish(color, clip.xy)` from `null3d::mesh`, which prepares it for the engine's output. `finish` multiplies the color by the exposure, as the engine does with an unlit material's color.
|
|
91
|
+
- For color that the engine already exposed, such as the sum of the frame's lights, write it through `finish_exposed` instead.
|
|
95
92
|
- `fill_builtins(origin)` from `null3d::builtins` fills `frame`, `camera` and `object` in a stage. Pass the object's origin relative to the camera, or zero when the shader does not read `object`.
|
|
96
|
-
- The
|
|
93
|
+
- The options for faces and depth apply, such as `doubleSided` and `depthBias`.
|
|
94
|
+
- The standard values, uniforms and textures do not reach a full shader. `vertexColors` and the `mask` alpha mode change nothing. The shader reads the colors and discards pixels itself. The build stops at a texture that a full shader declares.
|
|
95
|
+
|
|
96
|
+
| Location | Attribute | WGSL type |
|
|
97
|
+
| --- | --- | --- |
|
|
98
|
+
| 0 | Position | `vec3f` |
|
|
99
|
+
| 1 | Normal | `vec3f` |
|
|
100
|
+
| 2 | First texture coordinates | `vec2f` |
|
|
101
|
+
| 3 | Second texture coordinates | `vec2f` |
|
|
102
|
+
| 4 | Tangent | `vec4f` |
|
|
103
|
+
| 5 | Color | `vec4f` |
|
|
104
|
+
| 6 | Joints | `vec4u` |
|
|
105
|
+
| 7 | Weights | `vec4f` |
|
|
97
106
|
|
|
98
107
|
## WGSL in sketch code
|
|
99
108
|
|
|
@@ -111,17 +120,11 @@ The second form is a template literal after a `/* wgsl */` comment:
|
|
|
111
120
|
```ts
|
|
112
121
|
// sketch.ts
|
|
113
122
|
const glow = /* wgsl */ `
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
return vec4f(corner * 2.0 - 1.0, 0.0, 1.0);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
@fragment
|
|
123
|
-
fn fs_main() -> @location(0) vec4f {
|
|
124
|
-
return vec4f(null3d::color::linear_to_srgb(vec3f(0.5)), 1.0);
|
|
123
|
+
fn surface(input: SurfaceInput) -> Surface {
|
|
124
|
+
var s = defaultSurface(input);
|
|
125
|
+
let pulse = 0.5 + 0.5 * sin(input.uv.x * 12.0);
|
|
126
|
+
s.baseColor = mix(s.baseColor, vec3f(1.0, 0.6, 0.2), pulse);
|
|
127
|
+
return s;
|
|
125
128
|
}
|
|
126
129
|
`;
|
|
127
130
|
```
|
|
@@ -136,15 +139,20 @@ The plugin puts the compiled shader where the literal was. Your code therefore r
|
|
|
136
139
|
|
|
137
140
|
## What the plugin compiles
|
|
138
141
|
|
|
139
|
-
The plugin compiles
|
|
142
|
+
The plugin compiles these kinds of WGSL:
|
|
140
143
|
|
|
141
|
-
- WGSL without entry points that declares `fn surface`, `fn vertexOffset` or
|
|
144
|
+
- WGSL without entry points that declares `fn surface`, `fn vertexOffset`, `fn lobe`, `fn coverage` or `fn unlit` is a custom material's WGSL. The plugin builds it into the standard material's shader, once for each of that shader's variants.
|
|
145
|
+
- WGSL without entry points that declares `fn effect` or `fn toneCurve` is a [custom effect or tone curve](custom-passes.md#custom-effects). The plugin builds it into every variant of its template.
|
|
146
|
+
- WGSL without entry points that declares `fn skyLayer` is a [sky layer](../api/scene.md#sky-layers). The plugin builds it into the engine's sky-layer template.
|
|
142
147
|
- WGSL whose `@vertex` entry point takes an `InstanceIn` is a [full shader](#full-shaders) of a custom material. The plugin builds it for WebGPU, and for WebGL2 with and without multi-draw.
|
|
148
|
+
- WGSL whose `@vertex` entry point takes the vertex and instance indices and no mesh attribute is a draw shader. A [vertex draw](../api/vertex-draws.md) draws it from a vertex count.
|
|
143
149
|
- Other WGSL with entry points is a whole shader. It has one `@vertex` entry point and one or more `@fragment` entry points. Each `@fragment` entry point makes one render pipeline, named after it, with the `@vertex` entry point. A shader with only `@compute` entry points builds for WebGPU alone, because WebGL2 has no compute shaders.
|
|
144
150
|
|
|
145
151
|
WGSL that is neither stops the build with an error that says how to fix it.
|
|
146
152
|
|
|
147
|
-
|
|
153
|
+
A sketch uses a whole shader only as a compute pass's shader ([Compute passes](custom-passes.md#compute-passes)). WGSL with `@vertex` and `@fragment` entry points draws only as a full shader, with an `InstanceIn` vertex input, or as a draw shader, with the vertex and instance indices. Other render pipelines are for the engine's own passes, and no public call takes them.
|
|
154
|
+
|
|
155
|
+
The plugin compiles each shader once and caches the result, so a later build compiles only what changed. [Install null3D](../getting-started/install.md#shader-compiles-and-the-cache) says where the cache lives and how to ignore it.
|
|
148
156
|
|
|
149
157
|
A shader can import the engine's library modules, such as `#import null3d::math`. The plugin resolves each import. [Shader library and imports](../shaders/library.md) lists the modules.
|
|
150
158
|
|
|
@@ -160,28 +168,33 @@ Each shader builds twice. The WebGPU build is WGSL. The WebGL2 build holds one G
|
|
|
160
168
|
|
|
161
169
|
Both builds follow the [WGSL rules for portable shaders](../shaders/wgsl-rules.md). The rules page says what the build rejects, and what you must test on each path yourself.
|
|
162
170
|
|
|
163
|
-
|
|
171
|
+
You can use arrays in every form that WGSL allows; your WGSL does not change.
|
|
172
|
+
|
|
173
|
+
<details>
|
|
174
|
+
<summary>Technical details: how the WebGL2 build rewrites arrays</summary>
|
|
175
|
+
|
|
176
|
+
A function can return an array, and an array can take values that are not constants, such as `array<vec3f, 2>(a, b)`. Some Android GPUs reject these forms in GLSL, so the WebGL2 build rewrites them. A function that returns an array gives it through an extra `out` parameter, and an array built from values fills one element at a time. The WebGPU build keeps it as you wrote it.
|
|
177
|
+
|
|
178
|
+
</details>
|
|
164
179
|
|
|
165
|
-
|
|
180
|
+
### Where the builds go
|
|
166
181
|
|
|
167
|
-
|
|
168
|
-
- The material's value in your module holds only its uniforms, its textures, its vertex inputs and a function that imports a file.
|
|
169
|
-
- When the sketch first uses the material, it downloads its device's file. The first frame waits for that file and for the material's pipelines, as it waits for any pipeline. A device downloads another file only when it needs one: the builds that skin, for the material's first skinned mesh, or the builds without tone mapping, when bloom or depth of field turns on.
|
|
170
|
-
- In `vite build`, the files go into the assets folder with the build's other files. On the dev server, the plugin serves them from memory.
|
|
182
|
+
A custom material, effect or tone curve builds into small files of its own, not your module. The sketch downloads its device's file on first use. The first frame waits for a material's file, and a pass or an effect draws nothing until its file arrives while the rest of the frame draws. Deploy every file that the build writes, or the engine stops with [E1424](../errors/E1424.md).
|
|
171
183
|
|
|
172
|
-
For example, the battle comparison's sketch has 5 custom materials, and its module takes 5 KB.
|
|
184
|
+
For example, the [battle comparison's sketch](https://github.com/null3d-engine/null3d/tree/main/examples/compare/battle) has 5 custom materials, and its module takes 5 KB. A device downloads one file of about 20 KB after Brotli compression, and one more for its skinned meshes.
|
|
173
185
|
|
|
174
|
-
|
|
186
|
+
<details>
|
|
187
|
+
<summary>Technical details: the build files and their sizes</summary>
|
|
175
188
|
|
|
176
|
-
A custom
|
|
189
|
+
A custom material has many builds: one for each variant of the standard material, on each GPU path. The plugin puts them in files of their own, one for each GPU path, each kind of device, and the builds that skin meshes. These are 4 files for WebGPU and 8 for WebGL2, named `material-*.js`. The files of a module hold the builds of all its custom materials, from one `.wgsl` file or from the tagged literals of one script. The text that the builds share is in each file once.
|
|
177
190
|
|
|
178
|
-
|
|
179
|
-
- Its value in your module holds its uniforms, its textures and a function that imports a file.
|
|
180
|
-
- When the sketch first uses the effect or the curve, it downloads its device's file. A pass or an effect whose pipelines wait for it draws nothing until the file arrives, and the rest of the frame keeps drawing.
|
|
191
|
+
The material's value in your module holds only its uniforms, its textures, its vertex inputs and a function that imports a file. A device downloads another file only when it needs one: the builds that skin, for the material's first skinned mesh, or the builds without tone mapping, when bloom or depth of field turns on. In `vite build`, the files go into the assets folder with the build's other files. On the dev server, the plugin serves them from memory.
|
|
181
192
|
|
|
182
|
-
|
|
193
|
+
A custom effect and a custom tone curve build into every variant of their template, on each GPU path. An effect or a curve gets one file for each GPU path, named `effect-*.js` or `curve-*.js`, and its value holds its uniforms, its textures and a function that imports a file.
|
|
183
194
|
|
|
184
|
-
|
|
195
|
+
With every build in it, the battle comparison's module would take 1,504 KB, or 41 KB with Brotli compression. The device's file is 235 to 346 KB, or 18 to 21 KB with Brotli. The thread that draws keeps 3 to 4 MB of shader text. Every build of the device's GPU path would take 7 MB on WebGPU and 27 MB on WebGL2.
|
|
196
|
+
|
|
197
|
+
</details>
|
|
185
198
|
|
|
186
199
|
## Shader errors
|
|
187
200
|
|
|
@@ -210,10 +223,17 @@ These rules apply:
|
|
|
210
223
|
- A change to other code in the script file runs the module again, so Vite reloads the page as it does for any module.
|
|
211
224
|
- WGSL that does not compile shows in Vite's overlay and in the terminal. The page keeps drawing with the last shader that compiled. The overlay closes when your fix compiles.
|
|
212
225
|
- A change to the uniforms, the textures or the vertex attributes of a custom material reloads the page. So does a change between a surface function and a full shader, a vertex offset that you add or remove, and the scene inputs that the WGSL reads. The materials keep their values in a layout that these set, and a vertex offset gives a material the shaders of its shadows.
|
|
213
|
-
- A
|
|
226
|
+
- A compute pass's shader reloads the page.
|
|
214
227
|
- A change to the WGSL of a custom post effect or a custom tone curve reloads the page.
|
|
215
228
|
|
|
216
|
-
The plugin compiles WGSL on worker threads, so the dev server answers the page's other requests while a shader compiles.
|
|
229
|
+
The plugin compiles WGSL on worker threads, so the dev server answers the page's other requests while a shader compiles.
|
|
230
|
+
|
|
231
|
+
<details>
|
|
232
|
+
<summary>Technical details: how the plugin compiles on worker threads</summary>
|
|
233
|
+
|
|
234
|
+
It starts one thread for each core but one, at most 8, and each takes about 20 MB. It splits each custom material's variants among the threads.
|
|
235
|
+
|
|
236
|
+
</details>
|
|
217
237
|
|
|
218
238
|
## TypeScript
|
|
219
239
|
|