@null3d/engine 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/wasm/single/null3d.js +10 -8
- package/dist/wasm/single/null3d_bg.wasm +0 -0
- package/dist/wasm/threaded/null3d.js +10 -8
- package/dist/wasm/threaded/null3d_bg.wasm +0 -0
- package/docs/api/animation.md +96 -24
- package/docs/api/assets.md +99 -29
- package/docs/api/cameras.md +38 -7
- package/docs/api/controls.md +47 -23
- package/docs/api/debug.md +105 -35
- package/docs/api/engine.md +108 -32
- package/docs/api/feature-draws.md +21 -15
- package/docs/api/feature-effects.md +8 -8
- package/docs/api/feature-instances.md +68 -17
- package/docs/api/features.md +68 -37
- package/docs/api/geometry.md +83 -14
- package/docs/api/grass.md +55 -13
- package/docs/api/impostors.md +92 -50
- package/docs/api/input.md +22 -9
- package/docs/api/lights.md +67 -16
- package/docs/api/lines.md +38 -13
- package/docs/api/materials.md +187 -59
- package/docs/api/math.md +6 -6
- package/docs/api/objects.md +40 -15
- package/docs/api/page.md +58 -7
- package/docs/api/particles.md +36 -11
- package/docs/api/points.md +18 -8
- package/docs/api/post.md +57 -23
- package/docs/api/quality.md +36 -16
- package/docs/api/raycast.md +57 -24
- package/docs/api/reference/animation.md +1 -2
- package/docs/api/reference/assets.md +7 -4
- package/docs/api/reference/cameras.md +3 -2
- package/docs/api/reference/controls.md +59 -2
- package/docs/api/reference/debug.md +58 -6
- package/docs/api/reference/engine.md +40 -10
- package/docs/api/reference/feature-draws.md +3 -4
- package/docs/api/reference/feature-effects.md +2 -3
- package/docs/api/reference/feature-instances.md +5 -4
- package/docs/api/reference/features.md +7 -4
- package/docs/api/reference/geometry.md +132 -21
- package/docs/api/reference/grass.md +62 -2
- package/docs/api/reference/impostors.md +120 -16
- package/docs/api/reference/input.md +1 -2
- package/docs/api/reference/lights.md +4 -3
- package/docs/api/reference/lines.md +3 -4
- package/docs/api/reference/materials.md +7 -6
- package/docs/api/reference/math.md +13 -2
- package/docs/api/reference/objects.md +2 -3
- package/docs/api/reference/particles.md +31 -6
- package/docs/api/reference/points.md +2 -3
- package/docs/api/reference/post.md +4 -3
- package/docs/api/reference/quality.md +1 -2
- package/docs/api/reference/raycast.md +1 -2
- package/docs/api/reference/render.md +4 -3
- package/docs/api/reference/scene.md +24 -5
- package/docs/api/reference/sketch.md +11 -11
- package/docs/api/reference/sound.md +33 -2
- package/docs/api/reference/splats.md +42 -3
- package/docs/api/reference/sprites.md +2 -3
- package/docs/api/reference/tasks.md +16 -3
- package/docs/api/reference/terrain.md +26 -5
- package/docs/api/reference/textures.md +1 -2
- package/docs/api/reference/three-compat.md +18 -7
- package/docs/api/reference/time.md +1 -2
- package/docs/api/reference/ui.md +10 -7
- package/docs/api/reference/vertex-draws.md +2 -3
- package/docs/api/reference/water.md +78 -5
- package/docs/api/reference/wind.md +15 -2
- package/docs/api/render.md +67 -25
- package/docs/api/scene.md +129 -36
- package/docs/api/sketch.md +45 -19
- package/docs/api/sound.md +48 -12
- package/docs/api/splats.md +42 -15
- package/docs/api/sprites.md +8 -6
- package/docs/api/tasks.md +31 -22
- package/docs/api/terrain.md +44 -12
- package/docs/api/textures.md +61 -12
- package/docs/api/three-compat.md +15 -7
- package/docs/api/time.md +3 -5
- package/docs/api/ui.md +18 -10
- package/docs/api/vertex-draws.md +13 -12
- package/docs/api/water.md +111 -67
- package/docs/api/wind.md +61 -15
- package/docs/cli/null3d.md +90 -15
- package/docs/concepts/architecture.md +69 -23
- package/docs/concepts/assets.md +57 -16
- package/docs/concepts/backends.md +68 -24
- package/docs/concepts/color-management.md +42 -13
- package/docs/concepts/culling.md +68 -47
- package/docs/concepts/handles.md +14 -5
- package/docs/concepts/instances.md +72 -23
- package/docs/concepts/large-worlds.md +17 -7
- package/docs/concepts/lighting.md +117 -44
- package/docs/concepts/lod.md +128 -33
- package/docs/concepts/materials.md +43 -12
- package/docs/concepts/particle-buffer.md +48 -35
- package/docs/concepts/post-processing.md +77 -14
- package/docs/concepts/quality-preset-tables.md +3 -2
- package/docs/concepts/quality-presets.md +122 -39
- package/docs/concepts/render-graph.md +56 -21
- package/docs/concepts/render-layers.md +9 -5
- package/docs/concepts/shadows.md +96 -25
- package/docs/concepts/static-dynamic.md +22 -7
- package/docs/cookbook/index.md +163 -119
- package/docs/data/threejs-mapping.json +301 -340
- package/docs/errors/E1101.md +23 -5
- package/docs/errors/E1102.md +11 -3
- package/docs/errors/E1103.md +11 -3
- package/docs/errors/E1104.md +11 -3
- package/docs/errors/E1105.md +13 -5
- package/docs/errors/E1106.md +11 -3
- package/docs/errors/E1107.md +15 -5
- package/docs/errors/E1108.md +11 -3
- package/docs/errors/E1109.md +32 -6
- package/docs/errors/E1110.md +23 -5
- package/docs/errors/E1111.md +11 -3
- package/docs/errors/E1112.md +11 -3
- package/docs/errors/E1203.md +12 -4
- package/docs/errors/E1204.md +11 -3
- package/docs/errors/E1205.md +11 -3
- package/docs/errors/E1206.md +28 -6
- package/docs/errors/E1207.md +11 -3
- package/docs/errors/E1208.md +12 -3
- package/docs/errors/E1209.md +11 -3
- package/docs/errors/E1213.md +27 -5
- package/docs/errors/E1214.md +11 -3
- package/docs/errors/E1215.md +31 -6
- package/docs/errors/E1216.md +31 -6
- package/docs/errors/E1217.md +29 -6
- package/docs/errors/E1218.md +22 -6
- package/docs/errors/E1219.md +11 -3
- package/docs/errors/E1220.md +24 -5
- package/docs/errors/E1221.md +24 -5
- package/docs/errors/E1222.md +11 -3
- package/docs/errors/E1223.md +39 -6
- package/docs/errors/E1224.md +11 -3
- package/docs/errors/E1225.md +11 -3
- package/docs/errors/E1301.md +11 -3
- package/docs/errors/E1302.md +11 -3
- package/docs/errors/E1303.md +11 -3
- package/docs/errors/E1304.md +11 -3
- package/docs/errors/E1305.md +13 -3
- package/docs/errors/E1306.md +11 -3
- package/docs/errors/E1307.md +23 -6
- package/docs/errors/E1308.md +31 -0
- package/docs/errors/E1401.md +11 -3
- package/docs/errors/E1402.md +13 -5
- package/docs/errors/E1403.md +11 -3
- package/docs/errors/E1404.md +13 -3
- package/docs/errors/E1405.md +15 -4
- package/docs/errors/E1406.md +31 -5
- package/docs/errors/E1407.md +11 -3
- package/docs/errors/E1408.md +11 -3
- package/docs/errors/E1409.md +11 -3
- package/docs/errors/E1410.md +13 -5
- package/docs/errors/E1411.md +11 -3
- package/docs/errors/E1412.md +29 -6
- package/docs/errors/E1413.md +11 -3
- package/docs/errors/E1414.md +11 -3
- package/docs/errors/E1415.md +11 -3
- package/docs/errors/E1416.md +27 -6
- package/docs/errors/E1417.md +11 -3
- package/docs/errors/E1418.md +12 -3
- package/docs/errors/E1419.md +13 -5
- package/docs/errors/E1420.md +11 -3
- package/docs/errors/E1421.md +11 -3
- package/docs/errors/E1422.md +12 -3
- package/docs/errors/E1423.md +12 -3
- package/docs/errors/E1424.md +24 -5
- package/docs/errors/E1425.md +11 -3
- package/docs/errors/E1426.md +11 -3
- package/docs/errors/E1430.md +11 -3
- package/docs/errors/E1431.md +11 -3
- package/docs/errors/E1432.md +11 -3
- package/docs/errors/E1433.md +11 -3
- package/docs/errors/E1434.md +15 -6
- package/docs/errors/E1435.md +11 -3
- package/docs/errors/E1436.md +11 -3
- package/docs/errors/E1437.md +14 -6
- package/docs/errors/E1501.md +41 -6
- package/docs/errors/E1502.md +13 -3
- package/docs/errors/E1503.md +11 -3
- package/docs/errors/E1504.md +11 -3
- package/docs/errors/E1505.md +23 -5
- package/docs/errors/E1506.md +11 -3
- package/docs/errors/index.md +53 -29
- package/docs/getting-started/cdn.md +15 -9
- package/docs/getting-started/first-scene.md +20 -12
- package/docs/getting-started/hosting.md +113 -63
- package/docs/getting-started/install.md +39 -24
- package/docs/getting-started/network-use.md +31 -21
- package/docs/getting-started/project-structure.md +20 -8
- package/docs/getting-started/third-party-notices.md +6 -10
- package/docs/guides/accessibility.md +4 -4
- package/docs/guides/add-ons.md +83 -13
- package/docs/guides/agents.md +13 -14
- package/docs/guides/assets-pipeline.md +294 -72
- package/docs/guides/audio.md +17 -15
- package/docs/guides/baked-light-data.md +44 -23
- package/docs/guides/car-paint.md +37 -31
- package/docs/guides/content-pages.md +86 -29
- package/docs/guides/custom-passes.md +59 -17
- package/docs/guides/custom-shaders.md +54 -37
- package/docs/guides/debugging.md +31 -41
- package/docs/guides/deploying.md +10 -27
- package/docs/guides/deterministic-simulation.md +23 -16
- package/docs/guides/first-use-shaders.md +83 -45
- package/docs/guides/lens-kit.md +29 -26
- package/docs/guides/loading-screens.md +74 -30
- package/docs/guides/multiple-views.md +22 -11
- package/docs/guides/performance.md +188 -37
- package/docs/guides/phones.md +71 -19
- package/docs/guides/physics.md +6 -10
- package/docs/guides/screens.md +41 -29
- package/docs/guides/start-time.md +126 -85
- package/docs/guides/testing.md +137 -98
- package/docs/guides/ui-overlays.md +17 -12
- package/docs/guides/video-textures.md +14 -13
- package/docs/images/api/animation/character.webp +0 -0
- package/docs/images/api/animation/look-at-ring.webp +0 -0
- package/docs/images/api/animation/morph-tulips.webp +0 -0
- package/docs/images/api/animation/skeleton-lines.webp +0 -0
- package/docs/images/api/controls/gizmo-handles.webp +0 -0
- package/docs/images/api/controls/walk-and-fly.webp +0 -0
- package/docs/images/api/debug/debug-shapes.webp +0 -0
- package/docs/images/api/debug/levels-view.webp +0 -0
- package/docs/images/api/engine/transparent-canvas.webp +0 -0
- package/docs/images/api/feature-draws/feature-draw-clouds.webp +0 -0
- package/docs/images/api/feature-instances/compute-instances.webp +0 -0
- package/docs/images/api/feature-instances/instances-shadow.webp +0 -0
- package/docs/images/api/geometry/extra-shapes.webp +0 -0
- package/docs/images/api/geometry/generators.webp +0 -0
- package/docs/images/api/geometry/mesh-arrays.webp +0 -0
- package/docs/images/api/geometry/vertex-updates.webp +0 -0
- package/docs/images/api/grass/grass-grove.webp +0 -0
- package/docs/images/api/grass/grass-presets.webp +0 -0
- package/docs/images/api/grass/grass-shadow.webp +0 -0
- package/docs/images/api/impostors/impostor-handover.webp +0 -0
- package/docs/images/api/impostors/impostor-shadow.webp +0 -0
- package/docs/images/api/impostors/impostors-forest.webp +0 -0
- package/docs/images/api/lights/spot-cookies.webp +0 -0
- package/docs/images/api/lines/lines-lit.webp +0 -0
- package/docs/images/api/lines/lines-widths.webp +0 -0
- package/docs/images/api/materials/coat-and-sheen.webp +0 -0
- package/docs/images/api/materials/decals.webp +0 -0
- package/docs/images/api/materials/iridescence-and-anisotropy.webp +0 -0
- package/docs/images/api/materials/relief.webp +0 -0
- package/docs/images/api/materials/shader-inputs.webp +0 -0
- package/docs/images/api/materials/standard-grid.webp +0 -0
- package/docs/images/api/materials/subsurface.webp +0 -0
- package/docs/images/api/materials/translucency.webp +0 -0
- package/docs/images/api/objects/objects-turntable.webp +0 -0
- package/docs/images/api/particles/campfire.webp +0 -0
- package/docs/images/api/points/galaxy.webp +0 -0
- package/docs/images/api/reference/textures/texture-wrap.webp +0 -0
- package/docs/images/api/render/fullscreen-glow.webp +0 -0
- package/docs/images/api/render/reflection-mirror.webp +0 -0
- package/docs/images/api/render/security-camera.webp +0 -0
- package/docs/images/api/scene/aurora-sky-layer.webp +0 -0
- package/docs/images/api/sound/sound-demo.webp +0 -0
- package/docs/images/api/splats/splats-demo.webp +0 -0
- package/docs/images/api/sprites/sprites-lines.webp +0 -0
- package/docs/images/api/terrain/terrain-demo.webp +0 -0
- package/docs/images/api/textures/canvas-screen.webp +0 -0
- package/docs/images/api/textures/mipmaps.webp +0 -0
- package/docs/images/api/vertex-draws/rain.webp +0 -0
- package/docs/images/api/water/ocean.webp +0 -0
- package/docs/images/api/water/water-demo.webp +0 -0
- package/docs/images/api/water/water-rain.webp +0 -0
- package/docs/images/api/water/waterfall.webp +0 -0
- package/docs/images/concepts/assets/gltf-model.webp +0 -0
- package/docs/images/concepts/color-management/tone-mapped.webp +0 -0
- package/docs/images/concepts/culling/far-from-origin.webp +0 -0
- package/docs/images/concepts/instances/instances.webp +0 -0
- package/docs/images/concepts/instances/per-row-colors.webp +0 -0
- package/docs/images/concepts/large-worlds/large-world.webp +0 -0
- package/docs/images/concepts/lighting/area-lights.webp +0 -0
- package/docs/images/concepts/lighting/atmosphere.webp +0 -0
- package/docs/images/concepts/lighting/environment.webp +0 -0
- package/docs/images/concepts/lighting/light-shafts.webp +0 -0
- package/docs/images/concepts/lighting/reflection-probes.webp +0 -0
- package/docs/images/concepts/lod/forest.webp +0 -0
- package/docs/images/concepts/materials/weighted-transparency.webp +0 -0
- package/docs/images/concepts/post-processing/auto-exposure.webp +0 -0
- package/docs/images/concepts/post-processing/bounce-light.webp +0 -0
- package/docs/images/concepts/post-processing/depth-of-field.webp +0 -0
- package/docs/images/concepts/post-processing/post-effects-alley.webp +0 -0
- package/docs/images/concepts/post-processing/sharpen.webp +0 -0
- package/docs/images/concepts/post-processing/ssr-wet-street.webp +0 -0
- package/docs/images/concepts/render-layers/layers-cottages.webp +0 -0
- package/docs/images/concepts/shadows/hero-shadow.webp +0 -0
- package/docs/images/cookbook/index/picking.webp +0 -0
- package/docs/images/cookbook/index/time-of-day.webp +0 -0
- package/docs/images/errors/E1431/area-lights-no-tables.webp +0 -0
- package/docs/images/guides/custom-passes/reflection-water.webp +0 -0
- package/docs/images/guides/deterministic-simulation/replay-demo.webp +0 -0
- package/docs/images/guides/multiple-views/split-screen.webp +0 -0
- package/docs/images/guides/performance/overdraw-view.webp +0 -0
- package/docs/images/guides/testing/hold-mode-frame.webp +0 -0
- package/docs/images/index/showcase-island.webp +0 -0
- package/docs/images/porting/threejs-shaders/dissolve.webp +0 -0
- package/docs/images/shaders/builtins/builtins.webp +0 -0
- package/docs/images/shaders/surface-functions/custom-surface.webp +0 -0
- package/docs/images/shaders/surface-functions/vertex-offset.webp +0 -0
- package/docs/images/shots.json +2231 -0
- package/docs/index.md +14 -23
- package/docs/moves.json +1 -0
- package/docs/nav.json +300 -0
- package/docs/pages.md +230 -212
- package/docs/porting/react-three-fiber.md +2 -6
- package/docs/porting/threejs-loop-and-threads.md +1 -5
- package/docs/porting/threejs-mapping.md +1248 -234
- package/docs/porting/threejs-materials.md +10 -5
- package/docs/porting/threejs-overview.md +26 -6
- package/docs/porting/threejs-postprocessing.md +2 -6
- package/docs/porting/threejs-shaders.md +16 -14
- package/docs/porting/threejs-unsupported.md +6 -6
- package/docs/porting/verification.md +0 -4
- package/docs/shaders/builtins.md +15 -4
- package/docs/shaders/library.md +9 -6
- package/docs/shaders/surface-functions.md +51 -16
- package/docs/shaders/wgsl-rules.md +12 -5
- package/lib/debug/debug.d.ts +2 -2
- package/lib/debug/draw.d.ts +2 -2
- package/lib/debug/draw.js +8 -4
- package/lib/debug/overlay-look.d.ts +6 -0
- package/lib/debug/overlay-look.js +29 -7
- package/lib/debug/overlay.js +15 -11
- package/lib/debug/stats-options.d.ts +13 -0
- package/lib/debug/stats-panel.d.ts +21 -6
- package/lib/debug/stats-panel.js +80 -13
- package/lib/errors/codes.d.ts +17 -3
- package/lib/errors/codes.js +116 -105
- package/lib/errors/engine-error.js +1 -1
- package/lib/errors/fixes.d.ts +1 -0
- package/lib/errors/fixes.js +19 -18
- package/lib/generated/shader-permutations.d.ts +6 -0
- package/lib/generated/shader-permutations.js +6 -0
- package/lib/gpu/variants.d.ts +8 -2
- package/lib/gpu/variants.js +39 -7
- package/lib/gpu/webgl2/programs.js +1 -1
- package/lib/gpu/webgpu/pipelines.js +13 -13
- package/lib/index.d.ts +1 -1
- package/lib/page/capabilities.d.ts +1 -1
- package/lib/page/engine.d.ts +29 -7
- package/lib/page/engine.js +79 -7
- package/lib/page/label-loop.js +9 -4
- package/lib/page/stats-switch.js +2 -0
- package/lib/page/switches.d.ts +6 -4
- package/lib/page/switches.js +20 -4
- package/lib/scene/baked-light.d.ts +2 -2
- package/lib/scene/fake-call-values.js +2 -2
- package/lib/scene/frame-cameras.d.ts +16 -4
- package/lib/scene/frame-cameras.js +28 -10
- package/lib/scene/gltf.d.ts +1 -1
- package/lib/scene/level-rule.d.ts +6 -5
- package/lib/scene/level-rule.js +2 -2
- package/lib/scene/particles.d.ts +7 -3
- package/lib/scene/particles.js +3 -1
- package/lib/scene/post.d.ts +3 -2
- package/lib/scene/resources.d.ts +15 -9
- package/lib/scene/scene.d.ts +18 -2
- package/lib/scene/scene.js +47 -5
- package/lib/scene/time-of-day.d.ts +10 -5
- package/lib/scene/time-of-day.js +11 -7
- package/lib/shader-artifact.json +1 -1
- package/lib/shared/labels.d.ts +5 -2
- package/lib/shared/labels.js +5 -2
- package/lib/shared/permutation-words.d.ts +8 -0
- package/lib/shared/permutation-words.js +14 -0
- package/lib/shared/recording.d.ts +13 -5
- package/lib/shared/recording.js +31 -10
- package/lib/shared/sketch-data.d.ts +9 -0
- package/lib/shared/sketch-data.js +57 -0
- package/lib/shared/tier.d.ts +9 -0
- package/lib/shared/tier.js +4 -1
- package/lib/shared/version.d.ts +1 -1
- package/lib/shared/version.js +1 -1
- package/lib/sketch/define-sketch.d.ts +16 -7
- package/lib/sketch/define-sketch.js +2 -1
- package/lib/sketch/runner.d.ts +4 -0
- package/lib/sketch/runner.js +5 -0
- package/lib/sketch/ui.js +4 -2
- package/lib/stats.d.ts +1 -0
- package/lib/workers/protocol.d.ts +10 -0
- package/lib/workers/render-worker.js +4 -1
- package/lib/workers/sketch-worker.js +4 -1
- package/package.json +1 -1
package/docs/api/water.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: api/water
|
|
3
3
|
title: "Water (@null3d/water)"
|
|
4
|
-
status: experimental
|
|
5
|
-
since: "0.3"
|
|
6
4
|
summary: "createWater: a river and a lake from one shape, with waves that the current carries, ripples, caustics, foam, rain rings, a soft shore that reads the scene's depth or the shape's bed, a reflection whose cadence follows the preset, and createUnderwater for the view from below the surface. createWaterfall: a fall from a river's lip, with spray and mist. createOcean: an open sea of spectra transformed on the GPU."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Water (@null3d/water)
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+

|
|
10
|
+
|
|
11
|
+
The water demo.
|
|
12
12
|
|
|
13
13
|
```mermaid
|
|
14
14
|
flowchart LR
|
|
@@ -18,20 +18,13 @@ flowchart LR
|
|
|
18
18
|
mirror["A reflection pass"] --> material
|
|
19
19
|
bed["The scene's depth,<br/>or the shape's bed"] --> material
|
|
20
20
|
material --> screen["The water"]
|
|
21
|
-
spectrum["Wave spectra,<br/>a layer for each band"] --> chain["The transform:<br/>14 butterfly passes,<br/>then the heights in meters"]
|
|
22
|
-
chain --> sea["The sea's material:<br/>heights, slopes, foam"]
|
|
23
|
-
mirror --> sea
|
|
24
|
-
sea --> ocean["The sea"]
|
|
25
21
|
preset["The quality preset"] --> mirror
|
|
26
22
|
camera["A camera under the surface"] --> under["createUnderwater"]
|
|
27
|
-
lip["A river's lip,<br/>its current and a drop"] --> path["The path of<br/>falling water"]
|
|
28
|
-
path --> sheet["A column of water:<br/>streaks that ride the water"]
|
|
29
|
-
path --> spray["Spray, mist<br/>and a plume"]
|
|
30
|
-
sheet --> fall["The waterfall"]
|
|
31
|
-
spray --> fall
|
|
32
23
|
```
|
|
33
24
|
|
|
34
|
-
`@null3d/water` draws the water in a scene. A river follows a line, and a lake fills an outline, and both come from one description. The surface has long waves that the current carries downstream, and finer ripples in its normal. It draws caustics on the bed, foam around what breaks the surface, and a shore that fades where the bed rises to meet it.
|
|
25
|
+
`@null3d/water` draws the water in a scene. A river follows a line, and a lake fills an outline, and both come from one description. The surface has long waves that the current carries downstream, and finer ripples in its normal. It draws caustics on the bed, foam around what breaks the surface, and a shore that fades where the bed rises to meet it.
|
|
26
|
+
|
|
27
|
+
A reflection pass mirrors the banks and the sky, and redraws as often as the quality preset affords. The mirror softens where the waves lie finer than a pixel covers, since their tilt still scatters the light. A bank seen through ripples meets the surface on a soft edge, while water close to the camera stays glassy. The same surface draws from below, and `createUnderwater` gives the view from under the water its color, its bend and its caustics.
|
|
35
28
|
|
|
36
29
|
`createWaterfall` draws a fall from a river's lip, with spray at the lip, mist down the fall and a plume of mist at its foot.
|
|
37
30
|
|
|
@@ -43,6 +36,13 @@ The package is built on the engine's public API. Its surface and underwater shad
|
|
|
43
36
|
bun add @null3d/water @null3d/particles
|
|
44
37
|
```
|
|
45
38
|
|
|
39
|
+
The surface draws these:
|
|
40
|
+
|
|
41
|
+
- A river and a lake from one shape, with waves and ripples that the current carries.
|
|
42
|
+
- Caustics on the bed, and foam around what breaks the surface.
|
|
43
|
+
- A shore that fades, and a reflection whose cadence follows the preset.
|
|
44
|
+
- The view from below the surface, through `createUnderwater`.
|
|
45
|
+
|
|
46
46
|
```ts
|
|
47
47
|
// sketch.ts
|
|
48
48
|
import { defineSketch } from '@null3d/engine';
|
|
@@ -86,10 +86,16 @@ export default defineSketch(async (ctx) => {
|
|
|
86
86
|
Each body has a mesh of its own, so where a river runs into a lake the two meshes overlap. There
|
|
87
87
|
each point of the surface belongs to one body. A lake owns the water inside its shore, and a river
|
|
88
88
|
the water outside every lake. The other mesh skips the point, so the water never draws twice there.
|
|
89
|
+
|
|
90
|
+
<details>
|
|
91
|
+
<summary>Technical details: how the meeting blends</summary>
|
|
92
|
+
|
|
89
93
|
The river's waves give way to the lake's still water over about 3 m on each side of the meeting.
|
|
90
94
|
The surface lies flat within a few meters of it. Both meshes carry the river's current there, so
|
|
91
|
-
their waves agree on every pixel and leave no seam. A small map over each meeting
|
|
92
|
-
|
|
95
|
+
their waves agree on every pixel and leave no seam. A small map over each meeting holds these
|
|
96
|
+
values, which the add-on makes once, when it builds the meshes.
|
|
97
|
+
|
|
98
|
+
</details>
|
|
93
99
|
|
|
94
100
|
### A river
|
|
95
101
|
|
|
@@ -160,6 +166,7 @@ there: the map takes the water to run along +x.
|
|
|
160
166
|
A mark takes a `reach` of its own, in meters, in place of the map's. So one water can foam further
|
|
161
167
|
around some of its stones than around others. A mark without one keeps the map's reach. A reach
|
|
162
168
|
on the map or on a mark that is not a finite number above 0 stops the call.
|
|
169
|
+
|
|
163
170
|
The foam reaches `trail × (1 + r / reach)` meters toward +x from a mark, so a mark with a shorter
|
|
164
171
|
reach trails further in proportion to its radius.
|
|
165
172
|
|
|
@@ -185,7 +192,9 @@ return {
|
|
|
185
192
|
|
|
186
193
|
`waveAmplitude` scales the lift that the wind gives the surface, along with the long waves. A slow stream can therefore keep a nearly flat surface, with fine ripples. Its wind field still moves the plants and the leaves around it.
|
|
187
194
|
|
|
188
|
-
A field's lift rides on a long swell, which suits a lake or a river. A pool, a basin or a fountain is small beside that swell, so the lift reads there as one flat tilt of the whole surface. Give such a body a `windRipple` and the surface takes the air in short crests of its own, a few tenths of a meter apart, so its reflection moves with the gusts that sway the trees. It is 0 by default, which leaves every other surface as it was.
|
|
195
|
+
A field's lift rides on a long swell, which suits a lake or a river. A pool, a basin or a fountain is small beside that swell, so the lift reads there as one flat tilt of the whole surface. Give such a body a `windRipple` and the surface takes the air in short crests of its own, a few tenths of a meter apart, so its reflection moves with the gusts that sway the trees. It is 0 by default, which leaves every other surface as it was.
|
|
196
|
+
|
|
197
|
+
The crests cost one read of the field for each pixel, so a wide lake keeps the default and lets its swell answer the wind.
|
|
189
198
|
|
|
190
199
|
```ts
|
|
191
200
|
const pool = createWater(ctx, {
|
|
@@ -203,6 +212,10 @@ raindrop rings the surface where it lands. A ring grows and fades in about a sec
|
|
|
203
212
|
drift downstream with the current. They bend the surface's mirror and its highlights, as real rain
|
|
204
213
|
does. A light rain rings a few of the surface's cells, and a downpour rings all of them.
|
|
205
214
|
|
|
215
|
+

|
|
216
|
+
|
|
217
|
+
Rain on the surface.
|
|
218
|
+
|
|
206
219
|
```ts
|
|
207
220
|
const water = createWater(ctx, { shapes, rain: 0 });
|
|
208
221
|
|
|
@@ -210,7 +223,7 @@ const water = createWater(ctx, { shapes, rain: 0 });
|
|
|
210
223
|
water.setRain(1);
|
|
211
224
|
```
|
|
212
225
|
|
|
213
|
-
The rings follow the wet surface of the weather example add-on
|
|
226
|
+
The rings follow the wet surface of the weather example add-on in `examples/addons/weather`. Each cell of a grid about a meter
|
|
214
227
|
wide takes one drop at a time, with its place and its moment from the cell's hash. They give way where
|
|
215
228
|
one pixel covers more than a ring's line, so far water does not shimmer. Rain is off by default.
|
|
216
229
|
While it is off, the surface skips the rings' work.
|
|
@@ -221,9 +234,9 @@ While it is off, the surface skips the rings' work.
|
|
|
221
234
|
|
|
222
235
|
| Member | What it does |
|
|
223
236
|
| --- | --- |
|
|
224
|
-
| `update()` |
|
|
237
|
+
| `update()` | Call it once in each frame. It follows the camera, so the reflection draws in every frame while the view moves or turns. It applies the lowest quality tier's reflection cadence, and passes the wind field's gusts to the surface. Call it after the wind's `update()` |
|
|
225
238
|
| `level` | The height of the water's surface, in meters |
|
|
226
|
-
| `reflectionEvery` | The frames between two draws of the reflection
|
|
239
|
+
| `reflectionEvery` | The frames between two draws of the reflection, as the preset and the governor set it. A moving camera draws in every frame, whatever this says |
|
|
227
240
|
| `waveAmplitude` | The height of the long waves and of the wind's lift, as a factor of their base height |
|
|
228
241
|
| `surfaceHeight(x, z, t)` | The height of the surface at a point and a sketch time, in meters, from its long waves |
|
|
229
242
|
| `currentAt(x, z, out)` | The current at a point, as a velocity in meters a second, written into `out` |
|
|
@@ -241,13 +254,16 @@ current of the body that owns the point, and `surfaceHeight` follows the flat, m
|
|
|
241
254
|
The surface lets the bed's light through. The attenuation then takes a share of that light, for
|
|
242
255
|
each meter that it travels. The surface measures the travel as the depth of the bed under the
|
|
243
256
|
point. The water's own volume reaches from its surface down to that bed. So the tint of a shallow
|
|
244
|
-
creek follows its depth, and the caller sets how fast the tint gathers.
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
257
|
+
creek follows its depth, and the caller sets how fast the tint gathers.
|
|
258
|
+
|
|
259
|
+
`attenuationColor` is the color that the light takes after `attenuationDistance` meters. A clear
|
|
260
|
+
creek takes a pale color over a distance of several meters. Most of the bed's light then reaches
|
|
261
|
+
the eye at every point, and a little more of it over the shallows. A dark color over a distance
|
|
262
|
+
shorter than the bed is deep takes most of that light away.
|
|
263
|
+
|
|
264
|
+
The water then reads as an opaque slab
|
|
265
|
+
of its color, with no bed under it. The surface works out its own thickness and transmission, so
|
|
266
|
+
those two values do not apply here.
|
|
251
267
|
|
|
252
268
|
## The view from under the water
|
|
253
269
|
|
|
@@ -271,29 +287,37 @@ window overhead, and turns the light back past that window's edge.
|
|
|
271
287
|
|
|
272
288
|
## Waterfalls
|
|
273
289
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
the
|
|
290
|
+

|
|
291
|
+
|
|
292
|
+
A waterfall.
|
|
293
|
+
|
|
294
|
+
```mermaid
|
|
295
|
+
flowchart LR
|
|
296
|
+
lip["A river's lip,<br/>its current and a drop"] --> path["The path of<br/>falling water"]
|
|
297
|
+
path --> sheet["A column of water:<br/>streaks that ride the water"]
|
|
298
|
+
path --> spray["Spray, mist<br/>and a plume"]
|
|
299
|
+
sheet --> fall["The waterfall"]
|
|
300
|
+
spray --> fall
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
`createWaterfall(ctx, options)` makes a waterfall that falls from a river's lip. Over its first meters it draws in to about a quarter of the lip's width, so a notch as wide as the lip shows rock beside it. It hangs close to the rock under the brink, and fades where it nears a wall or a ledge behind it.
|
|
304
|
+
|
|
305
|
+
The sheet's material moves each streak with the water from the sketch's time alone, so the fall costs the CPU nothing in a frame. Spray froths at the lip, and a plume of mist rises at its foot.
|
|
306
|
+
|
|
307
|
+
<details>
|
|
308
|
+
<summary>Technical details: how the fall is shaped and lit</summary>
|
|
309
|
+
|
|
310
|
+
The water rolls over the lip as a smooth glassy tongue and arcs out. It then drops almost straight, as falling water does while the air slows it.
|
|
311
|
+
|
|
312
|
+
Below the tongue it turns white: a solid column of rough round ropes, with soft gray shade between them and clumps of froth that ride down with the water. Its outline tears into lobes and wisps, and its sides wander and break into separate ropes as it falls. Over its lower half it breaks up into clumps and dissolves into a broad mist, about four times its width, that draws over its foot, so it never lands and never ends in a line.
|
|
313
|
+
|
|
314
|
+
A streak rides down at the water's own speed, and it stretches as the water speeds up. The fall is one closed column with an oval section. It is thin under the brink and deepens out from the cliff over its first few meters as it falls, so the fall has a solid body from the side as well as from the front. Its outline thins and tears wherever the view grazes it, so no side shows a clean edge. Small drops fly off the column.
|
|
315
|
+
|
|
316
|
+
White water scatters the light that reaches it from all round. So the column takes the sky's light as a surface facing up does, and gives back a share of the air's light that `setLight` names, as the mist beside it does, so it reads as the lightest thing beside it. The scene's light lights the column.
|
|
317
|
+
|
|
318
|
+
</details>
|
|
319
|
+
|
|
320
|
+
The spray and the mist are systems of [`@null3d/particles`](particles.md), which the water package depends on.
|
|
297
321
|
|
|
298
322
|
```ts
|
|
299
323
|
// sketch.ts
|
|
@@ -367,6 +391,18 @@ a layer that the water's `layers` option leaves out, so the reflection pass skip
|
|
|
367
391
|
|
|
368
392
|
## The ocean
|
|
369
393
|
|
|
394
|
+

|
|
395
|
+
|
|
396
|
+
The water add-on fills the sea's heights with compute passes every frame.
|
|
397
|
+
|
|
398
|
+
```mermaid
|
|
399
|
+
flowchart LR
|
|
400
|
+
spectrum["Wave spectra,<br/>a layer for each band"] --> chain["The transform:<br/>14 butterfly passes,<br/>then the heights in meters"]
|
|
401
|
+
chain --> sea["The sea's material:<br/>heights, slopes, foam"]
|
|
402
|
+
reflection["A reflection pass"] --> sea
|
|
403
|
+
sea --> ocean["The sea"]
|
|
404
|
+
```
|
|
405
|
+
|
|
370
406
|
`createOcean(ctx, { camera })` makes an open sea. Its waves come from two or three bands of wave
|
|
371
407
|
spectra. A band is a square tile of the sea whose waves are a sum of plane waves. A spectrum gives
|
|
372
408
|
each wave an amplitude from the wind, and a seeded random number gives its phase.
|
|
@@ -424,7 +460,7 @@ holds longer waves, and a taller significant height lifts them further.
|
|
|
424
460
|
| Member | What it does |
|
|
425
461
|
| --- | --- |
|
|
426
462
|
| `update()` | Moves the mesh about the camera, and follows it for the reflection's cadence, which draws in every frame while the view moves. Call it once in each frame, after the camera moves |
|
|
427
|
-
| `reflectionEvery` | The frames between two draws of the reflection
|
|
463
|
+
| `reflectionEvery` | The frames between two draws of the reflection, as the preset and the governor set it. A moving camera draws in every frame, whatever this says |
|
|
428
464
|
| `heightAt(x, z)` | The height of the sea at a world place, in meters, at the sketch time. It runs the bands' transforms on this thread, and transforms again only when the sketch time moves, so several reads in a frame share one |
|
|
429
465
|
| `bands` | The bands, in the order that they sum |
|
|
430
466
|
| `level` | The height of the sea's surface |
|
|
@@ -440,27 +476,17 @@ near the eye and spends its vertices far away.
|
|
|
440
476
|
the call with E1217. The depth gives the water its depth behind each pixel, so a shore fades
|
|
441
477
|
against the bank. With `bed: 'shape'`, the mesh carries each vertex's bed depth in its vertex
|
|
442
478
|
colors and the surface reads that instead, for a bed that the scene states rather than draws.
|
|
443
|
-
- **The reflection.** The pass draws the scene a second time. It draws every other frame on Low and
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
shows a mirror of an older one, and the cadence returns when the view settles. While the lowest
|
|
447
|
-
quality tier applies, a still camera draws it in every 16th frame whatever the preset and the
|
|
448
|
-
governor give; leaving the tier gives the budget back. When frames
|
|
449
|
-
take too long, the frame-budget governor doubles the wait, up to every 16th frame. The stats
|
|
450
|
-
overlay shows the cadence as `reflectionEvery`. It shows the pass's GPU time and its share of a
|
|
451
|
-
frame as the water row's budget. It also shows the memory of the mesh arrays, the map of where bodies
|
|
452
|
-
meet, and the foam texture that the add-on made. The reflection target is the render graph's. `reflectionEvery` replaces the
|
|
453
|
-
preset's cadence. The pass costs no pipeline of its own, and its texture goes with `destroy`.
|
|
479
|
+
- **The reflection.** The pass draws the scene a second time. It draws every other frame on Low and Medium, and every frame on High and Ultra, and every frame while the camera moves or turns. A moving view never shows a mirror of an older one, and the cadence returns when the view settles.
|
|
480
|
+
- **The reflection's limits.** When frames take too long, the frame-budget governor doubles the wait, up to every 16th frame. While the lowest quality tier applies, a still camera draws the reflection every 16th frame whatever the preset and the governor give; leaving the tier gives the budget back.
|
|
481
|
+
- **The reflection's cost in the overlay.** The stats overlay shows the cadence as `reflectionEvery`, the pass's GPU time and its share of a frame as the water row's budget, and its memory. The pass costs no pipeline of its own, and its texture goes with `destroy`.
|
|
454
482
|
- **Levels of detail.** The river, lake and ocean meshes take `levels: false`, because the waves
|
|
455
483
|
move their vertices in the shader. The engine plans no levels for them.
|
|
456
484
|
- **Transmission.** The surface lets light through, so the engine copies the scene's colors in the
|
|
457
485
|
frame that the water draws. The water draws both faces.
|
|
458
486
|
- **Nothing before its first use.** A page that never creates water downloads none of the add-on.
|
|
459
487
|
- **A waterfall.** It draws one blended mesh, a closed column of just over 2,000 triangles at the
|
|
460
|
-
default detail.
|
|
461
|
-
|
|
462
|
-
wide that drops 10 m, each holds a few hundred large puffs at most; a taller or wider fall makes
|
|
463
|
-
more. The column reads the copy
|
|
488
|
+
default detail. For a fall 2.5 m wide that drops 10 m, each of its particle systems holds a few
|
|
489
|
+
hundred large puffs at most; a taller or wider fall makes more. The column reads the copy
|
|
464
490
|
of the scene's depth. The puffs blend over the pixels that they cover, so lower `spray` where a
|
|
465
491
|
phone's frame is short.
|
|
466
492
|
- **One way to make water.** Use this package rather than a hand-written custom material, so a
|
|
@@ -474,8 +500,19 @@ near the eye and spends its vertices far away.
|
|
|
474
500
|
to a layer, and the reflection draws at the reflection scale. The stats overlay names the
|
|
475
501
|
add-on's ocean row and its budget, and the frame's GPU time holds the transform's share.
|
|
476
502
|
|
|
477
|
-
|
|
478
|
-
|
|
503
|
+
<details>
|
|
504
|
+
<summary>Technical details: the reflection's memory</summary>
|
|
505
|
+
|
|
506
|
+
The overlay's memory figure holds the mesh arrays, the map of where bodies meet, and the foam texture that the add-on made. The reflection target is the render graph's.
|
|
507
|
+
|
|
508
|
+
</details>
|
|
509
|
+
|
|
510
|
+
<details>
|
|
511
|
+
<summary>Technical details: the fall's particle systems</summary>
|
|
512
|
+
|
|
513
|
+
The fall adds four particle systems: a froth at the lip, the drops thrown off the column, the mist that the fall dissolves into, and the plume at its foot.
|
|
514
|
+
|
|
515
|
+
</details>
|
|
479
516
|
|
|
480
517
|
## Related pages
|
|
481
518
|
|
|
@@ -484,3 +521,10 @@ description. The engine's doc comments make it.
|
|
|
484
521
|
- [Surface functions](../shaders/surface-functions.md#the-scenes-depth): the scene's depth in a
|
|
485
522
|
custom material.
|
|
486
523
|
- [Quality API](quality.md): the preset and the frame-budget governor.
|
|
524
|
+
- [Rivers and lakes](https://github.com/null3d-engine/null3d/tree/main/examples/water): a river winds down a valley into a lake, and the camera dives under it.
|
|
525
|
+
- [The ocean](https://github.com/null3d-engine/null3d/tree/main/examples/ocean): three bands of wave spectra, transformed by compute passes every frame.
|
|
526
|
+
- [Waterfalls](https://github.com/null3d-engine/null3d/tree/main/examples/showcase/creek): the fall is one part of the Creek showcase, which also runs a creek, a spring pool and an underwater view.
|
|
527
|
+
|
|
528
|
+
## API reference
|
|
529
|
+
|
|
530
|
+
[The API reference](reference/water.md) lists every export of this page with its type and description. The engine's doc comments make it.
|
package/docs/api/wind.md
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: api/wind
|
|
3
3
|
title: "Wind (@null3d/wind)"
|
|
4
|
-
status: experimental
|
|
5
|
-
since: "0.3"
|
|
6
4
|
summary: "createWind: one field of air that plants, flags, smoke and water read, from an analytic wind of place and time with traveling gusts and pushes, held in a grid that follows the camera."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Wind (@null3d/wind)
|
|
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
|
```mermaid
|
|
14
10
|
flowchart LR
|
|
15
11
|
base["setBase: speed<br/>and heading"] --> field["The field: a grid<br/>about the camera"]
|
|
@@ -21,7 +17,9 @@ flowchart LR
|
|
|
21
17
|
cpu["sample: the<br/>mirror on the CPU"] --> page
|
|
22
18
|
```
|
|
23
19
|
|
|
24
|
-
`@null3d/wind` makes the air in a scene. One field moves every plant, flag and smoke card that reads it, so a gust that crosses a field reaches all of them together. The air is solved: a grid that follows the camera carries it from frame to frame.
|
|
20
|
+
`@null3d/wind` makes the air in a scene. One field moves every plant, flag and smoke card that reads it, so a gust that crosses a field reaches all of them together. The air is solved: a grid that follows the camera carries it from frame to frame.
|
|
21
|
+
|
|
22
|
+
A gust therefore bends through the scene, and a body leaves a wake that outlives it. A steady wind slows near the ground, and swirls turn without piling up. A page can also shove the air at a point, as a body moving through it does.
|
|
25
23
|
|
|
26
24
|
```sh
|
|
27
25
|
bun add @null3d/wind
|
|
@@ -54,7 +52,14 @@ export default defineSketch((ctx) => {
|
|
|
54
52
|
});
|
|
55
53
|
```
|
|
56
54
|
|
|
57
|
-
Call `update` once in each frame. It places the box about the camera and sends the field's values to the GPU. The add-on's calls make no object of their own, so a sketch may make them in every frame. A
|
|
55
|
+
Call `update` once in each frame. It places the box about the camera and sends the field's values to the GPU. The add-on's calls make no object of their own, so a sketch may make them in every frame. A sketch that pushes in every frame keeps one two-number array for the place, rather than a new one each time.
|
|
56
|
+
|
|
57
|
+
<details>
|
|
58
|
+
<summary>Technical details: allocation in a frame</summary>
|
|
59
|
+
|
|
60
|
+
A `read` in each frame also takes the task's promise, which the engine makes. Until the browser has optimized the add-on's functions, a fraction that crosses one of its calls becomes an object, as in the engine's own steps.
|
|
61
|
+
|
|
62
|
+
</details>
|
|
58
63
|
|
|
59
64
|
## The calls
|
|
60
65
|
|
|
@@ -74,11 +79,21 @@ Call `update` once in each frame. It places the box about the camera and sends t
|
|
|
74
79
|
|
|
75
80
|
The ring holds the three newest pushes, and each fades over three seconds. A page that pushes often therefore keeps a wake behind the body it moves. The newest gust has a slot of its own, so a page's pushes never push its gust out. A gust's wave travels for as long as its reach holds it.
|
|
76
81
|
|
|
77
|
-
`read`
|
|
82
|
+
`read` works out the air on the engine's job workers, up to about five thousand places a call. The answer gives the air at the frame's own time and lands before the next frame's update.
|
|
83
|
+
|
|
84
|
+
<details>
|
|
85
|
+
<summary>Technical details: how read queues its asks</summary>
|
|
86
|
+
|
|
87
|
+
The field's walk over the pushes runs in the add-on's WebAssembly, on the engine's job workers. A call that arrives while an answer is still on its way sends one more ask when that answer comes. A third call that arrives before either answer replaces the queued one: the newest ask wins, the one it replaces is dropped, and its array keeps the numbers it held. A page that asks in every frame therefore queues about one ask a frame, and the add-on reports a dropped ask once.
|
|
88
|
+
|
|
89
|
+
</details>
|
|
78
90
|
|
|
79
91
|
## Reading the field in your own WGSL
|
|
80
92
|
|
|
81
|
-
A material reads the field with one texture. `field.texture` holds the air over `field.origin` and `field.size`. The shader build resolves only the engine's library. So your WGSL holds copies of the add-on's two blocks: the steady field, which every reader shares, and the sampling function. Copy both from `shaders/field.wgsl` in the package, or
|
|
93
|
+
A material reads the field with one texture. `field.texture` holds the air over `field.origin` and `field.size`. The shader build resolves only the engine's library. So your WGSL holds copies of the add-on's two blocks: the steady field, which every reader shares, and the sampling function. Copy both from `shaders/field.wgsl` in the package, or open the two blocks below.
|
|
94
|
+
|
|
95
|
+
<details>
|
|
96
|
+
<summary>Technical details: the steady field block to copy (wind-steady)</summary>
|
|
82
97
|
|
|
83
98
|
```wgsl
|
|
84
99
|
#import null3d::noise::{value3}
|
|
@@ -223,6 +238,11 @@ fn wind_steady(air: WindAir, p: vec3f) -> vec3f {
|
|
|
223
238
|
// </wind-steady>
|
|
224
239
|
```
|
|
225
240
|
|
|
241
|
+
</details>
|
|
242
|
+
|
|
243
|
+
<details>
|
|
244
|
+
<summary>Technical details: the sampling block to copy (wind-sample)</summary>
|
|
245
|
+
|
|
226
246
|
```wgsl
|
|
227
247
|
// <wind-sample>
|
|
228
248
|
/// The air's steady settings as a reader holds them: the base wind in the first vector, the gust in
|
|
@@ -269,7 +289,11 @@ fn wind_sample(world: vec3f, origin: vec2f, size: f32, layer: i32, air: WindAir)
|
|
|
269
289
|
// </wind-sample>
|
|
270
290
|
```
|
|
271
291
|
|
|
272
|
-
|
|
292
|
+
</details>
|
|
293
|
+
|
|
294
|
+
Inside the box, the sampling function gives the air with one texture read. Outside it, it works the air out from the steady field, at the height that the grid samples at. So the two meet at the box's edge, and a plant past the box moves with the air at its own place.
|
|
295
|
+
|
|
296
|
+
A page's pushes and a gust that the page sends turn the air inside the box, so a plant past the box does not see them. A device that keeps no grid works the air out everywhere.
|
|
273
297
|
|
|
274
298
|
```ts
|
|
275
299
|
const leaf = ctx.materials.shader({
|
|
@@ -323,7 +347,9 @@ The box follows the camera, so update the material's `origin` values in each fra
|
|
|
323
347
|
|
|
324
348
|
A vertex offset that reads the field orders the pass before every pass that draws the material. The shadows and the motion vectors therefore move with the plant.
|
|
325
349
|
|
|
326
|
-
Trees and plants sway through such a material. The forest demo
|
|
350
|
+
Trees and plants sway through such a material. The [forest demo](https://github.com/null3d-engine/null3d/tree/main/examples/forest) draws the bark of its trees made in code with one custom material, and their leaf cards with a standard material. The bark's vertex offset samples this field's block at each vertex, as the example above does. Its sway fades to nothing at the material's `swayDistance`. So a tree past it stands still, and its far shadow cascades keep their layers.
|
|
351
|
+
|
|
352
|
+
A tree loaded from a glTF file sways the same way: give its meshes such a material with `setMaterial`. The grass package, [`@null3d/grass`](grass.md), reads the field for its blades. Its `swayDistanceFor(preset)` gives each quality preset's sway distance.
|
|
327
353
|
|
|
328
354
|
Every reader takes the field as a plain texture and its box, so it needs no code from this add-on. A page's own material reads it, as the forest demo's does. The grass package's blades read it, and the water add-on's `wind` option lifts a water surface. They read the same sampling block, and each copy costs the reader one of its material's six texture slots. Tests hold the readers' blocks equal to this page's.
|
|
329
355
|
|
|
@@ -335,7 +361,7 @@ Each cycle pulls the air toward an analytic field of place and time. It injects
|
|
|
335
361
|
|
|
336
362
|
The air starts when a page makes the wind, so a field made late in a sketch runs no air from before it.
|
|
337
363
|
|
|
338
|
-
|
|
364
|
+
In [hold mode](../guides/testing.md#hold-mode), the engine steps the sketch's updates up to the held time. The first frame that draws runs the air that the hold owes, up to ten seconds of it. So a held picture carries the air that the hold built. Two held pages at two times within ten seconds of the wind's start therefore differ by the air that moved between them. A longer hold runs only ten seconds of air.
|
|
339
365
|
|
|
340
366
|
Beyond its box the field carries on. The box sets the detail, not the field's extent. So a plant past the box reads the air at its own place.
|
|
341
367
|
|
|
@@ -358,7 +384,10 @@ Low keeps no grid: every reader works the air out from the steady field. A page
|
|
|
358
384
|
|
|
359
385
|
The grid is one flat slice at the crown's height, with no layered or volume grid. High and Ultra use the flat 128 and 256 grids.
|
|
360
386
|
|
|
361
|
-
The field's own budget is 0.5, 1.2, 4.9 and 6.25 ms a frame from Low to Ultra.
|
|
387
|
+
The field's own budget is 0.5, 1.2, 4.9 and 6.25 ms a frame from Low to Ultra.
|
|
388
|
+
|
|
389
|
+
- The governor lowers the field's share by a quarter at each of its steps, down to a quarter of the budget. The field still moves at the lowest step: the step interval reaches at most 133 ms, and the pressure count stays above zero.
|
|
390
|
+
- The overlay row reads the field's cost in a frame, which grows when a slow display owes the field more than one cycle in that frame. This example is the Medium row, with an example GPU time: `wind gpu 0.62 ms windStepMs 33 · windPressureSteps 16 · windSpringTrees 8 · windGrid 64 · budget 1.2 of 1.2 ms · memory 0.1 MiB`.
|
|
362
391
|
|
|
363
392
|
A preset change that changes the grid makes the grid again at the new size. The air starts empty on the new grid. A reader takes `field.texture` again after that, because the texture is a new one.
|
|
364
393
|
|
|
@@ -369,7 +398,24 @@ A preset change that changes the grid makes the grid again at the new size. The
|
|
|
369
398
|
- A vertex inside the box costs one texture read. A vertex outside it costs the steady field's arithmetic instead: four reads of the engine's value noise, with a few trigonometric and exponential calls.
|
|
370
399
|
- A WebGL2 device whose float targets fail the engine's probe cannot hold the grid, so it keeps no pass. There `field.size` is zero and a reader's samples are the steady field worked out, so a plant still moves. The texture it declares holds a single black texel that it never reaches.
|
|
371
400
|
- With no grid, every reader works the steady field out: the base wind, the swirl, the preset's own traveling gust and the gust that a page sends. A reader takes that gust in the fourth vector of its settings, so the surface, the leaves or the blades it draws answer it. The sent gust travels from the place it was sent and fades over 8 s. A push reaches readers only through the grid, so a point with no grid, or beyond the box, reads no push.
|
|
372
|
-
- The add-on makes no object of its own in a frame, and its texture exists only while something reads it. `read` sends one request to a job worker and takes the task's promise.
|
|
401
|
+
- The add-on makes no object of its own in a frame, and its texture exists only while something reads it. `read` sends one request to a job worker and takes the task's promise. The engine's repository measures the bytes with `bun run bench:allocation --wind`.
|
|
402
|
+
|
|
403
|
+
<details>
|
|
404
|
+
<summary>Technical details: what the calls allocate</summary>
|
|
405
|
+
|
|
406
|
+
Where the page shares its memory, the worker writes the answer in place; otherwise the answer comes back as one buffer. The add-on's WebAssembly holds the walk over the pushes and the places, so a page's own motion costs the sketch's thread one message and one copy of the answer. Each fraction that the add-on works out reaches a call in an array that the add-on made once, so a call the browser does not inline boxes none of them.
|
|
407
|
+
|
|
408
|
+
</details>
|
|
409
|
+
|
|
410
|
+
## Related pages
|
|
411
|
+
|
|
412
|
+
- [Grass](grass.md): reads the field for its blades.
|
|
413
|
+
- [Water](water.md): its `wind` option lifts a water surface.
|
|
414
|
+
- [Materials](materials.md): a custom material's vertex offset reads the field.
|
|
415
|
+
- [Add-on feature descriptions](features.md): the feature that declares the field's work.
|
|
416
|
+
- [Quality API](quality.md): the presets that set the field's grid and steps.
|
|
417
|
+
- [Plants in the field](https://github.com/null3d-engine/null3d/tree/main/examples/vegetation-wind): a grove of oaks, birches and firs that sway in the field. The plant material lives in the shared helper `examples/lib/sway.ts`, which the sketch imports.
|
|
418
|
+
|
|
419
|
+
## API reference
|
|
373
420
|
|
|
374
|
-
[The API reference](reference/wind.md) lists every export of this page with its type and
|
|
375
|
-
description. The engine's doc comments make it.
|
|
421
|
+
[The API reference](reference/wind.md) lists every export of this page with its type and description. The engine's doc comments make it.
|