wallhammer-web 0.0.0-stage → 0.4.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/LICENSE +21 -0
- package/README.md +92 -2
- package/dist/base/data.d.ts +67 -0
- package/dist/base/data.js +10 -0
- package/dist/base/destructible.d.ts +167 -0
- package/dist/base/destructible.js +47 -0
- package/dist/base/env-slot.d.ts +101 -0
- package/dist/base/env-slot.js +8 -0
- package/dist/base/frames.d.ts +138 -0
- package/dist/base/frames.js +459 -0
- package/dist/base/index.d.ts +21 -0
- package/dist/base/index.js +11 -0
- package/dist/base/mat34.d.ts +46 -0
- package/dist/base/mat34.js +173 -0
- package/dist/base/material.d.ts +87 -0
- package/dist/base/material.js +6 -0
- package/dist/base/math.d.ts +27 -0
- package/dist/base/math.js +60 -0
- package/dist/base/progress.d.ts +38 -0
- package/dist/base/progress.js +81 -0
- package/dist/base/rig.d.ts +177 -0
- package/dist/base/rig.js +97 -0
- package/dist/base/trig.d.ts +29 -0
- package/dist/base/trig.js +169 -0
- package/dist/base/up.d.ts +26 -0
- package/dist/base/up.js +40 -0
- package/dist/base/view.d.ts +128 -0
- package/dist/base/view.js +136 -0
- package/dist/camera/camera.d.ts +99 -0
- package/dist/camera/camera.js +228 -0
- package/dist/camera/follow.d.ts +120 -0
- package/dist/camera/follow.js +320 -0
- package/dist/camera/free.d.ts +153 -0
- package/dist/camera/free.js +359 -0
- package/dist/camera/index.d.ts +10 -0
- package/dist/camera/index.js +6 -0
- package/dist/camera/orbit.d.ts +93 -0
- package/dist/camera/orbit.js +261 -0
- package/dist/camera/path.d.ts +48 -0
- package/dist/camera/path.js +179 -0
- package/dist/core/ballistic.d.ts +66 -0
- package/dist/core/ballistic.js +104 -0
- package/dist/core/bodies.d.ts +77 -0
- package/dist/core/bodies.js +125 -0
- package/dist/core/clock.d.ts +37 -0
- package/dist/core/clock.js +87 -0
- package/dist/core/cover-fade.d.ts +14 -0
- package/dist/core/cover-fade.js +38 -0
- package/dist/core/index.d.ts +13 -0
- package/dist/core/index.js +8 -0
- package/dist/core/kepler.d.ts +74 -0
- package/dist/core/kepler.js +108 -0
- package/dist/core/level-fade.d.ts +66 -0
- package/dist/core/level-fade.js +123 -0
- package/dist/core/palette.d.ts +15 -0
- package/dist/core/palette.js +47 -0
- package/dist/env/atmosphere.d.ts +129 -0
- package/dist/env/atmosphere.js +707 -0
- package/dist/env/cloud-field.d.ts +44 -0
- package/dist/env/cloud-field.js +111 -0
- package/dist/env/environment.d.ts +217 -0
- package/dist/env/environment.js +441 -0
- package/dist/env/frame-block.d.ts +29 -0
- package/dist/env/frame-block.js +152 -0
- package/dist/env/glsl.d.ts +35 -0
- package/dist/env/glsl.js +246 -0
- package/dist/env/index.d.ts +13 -0
- package/dist/env/index.js +9 -0
- package/dist/env/sky.d.ts +48 -0
- package/dist/env/sky.js +227 -0
- package/dist/env/sun.d.ts +31 -0
- package/dist/env/sun.js +42 -0
- package/dist/gen-arch/build.d.ts +17 -0
- package/dist/gen-arch/build.js +414 -0
- package/dist/gen-arch/damage/damaged.d.ts +44 -0
- package/dist/gen-arch/damage/damaged.js +1119 -0
- package/dist/gen-arch/damage/fall-material.d.ts +10 -0
- package/dist/gen-arch/damage/fall-material.js +47 -0
- package/dist/gen-arch/damage/fall.d.ts +78 -0
- package/dist/gen-arch/damage/fall.js +797 -0
- package/dist/gen-arch/damage/rubble.d.ts +22 -0
- package/dist/gen-arch/damage/rubble.js +188 -0
- package/dist/gen-arch/index.d.ts +25 -0
- package/dist/gen-arch/index.js +16 -0
- package/dist/gen-arch/interior/interior-plan.d.ts +114 -0
- package/dist/gen-arch/interior/interior-plan.js +615 -0
- package/dist/gen-arch/interior/interior.d.ts +97 -0
- package/dist/gen-arch/interior/interior.js +966 -0
- package/dist/gen-arch/structure/building-shader.d.ts +25 -0
- package/dist/gen-arch/structure/building-shader.js +946 -0
- package/dist/gen-arch/structure/buildings.d.ts +248 -0
- package/dist/gen-arch/structure/buildings.js +294 -0
- package/dist/gen-arch/structure/dims.d.ts +77 -0
- package/dist/gen-arch/structure/dims.js +39 -0
- package/dist/gen-arch/structure/distant.d.ts +62 -0
- package/dist/gen-arch/structure/distant.js +316 -0
- package/dist/gen-arch/structure/env-slots.d.ts +18 -0
- package/dist/gen-arch/structure/env-slots.js +47 -0
- package/dist/gen-arch/structure/facade.d.ts +193 -0
- package/dist/gen-arch/structure/facade.js +159 -0
- package/dist/gen-arch/structure/parts.d.ts +31 -0
- package/dist/gen-arch/structure/parts.js +69 -0
- package/dist/gen-arch/structure/roof.d.ts +76 -0
- package/dist/gen-arch/structure/roof.js +568 -0
- package/dist/gen-arch/structure/structure-material.d.ts +23 -0
- package/dist/gen-arch/structure/structure-material.js +55 -0
- package/dist/gen-arch/structure/writer.d.ts +94 -0
- package/dist/gen-arch/structure/writer.js +195 -0
- package/dist/gen-core/cell.d.ts +138 -0
- package/dist/gen-core/cell.js +150 -0
- package/dist/gen-core/cube-sphere.d.ts +57 -0
- package/dist/gen-core/cube-sphere.js +159 -0
- package/dist/gen-core/field.d.ts +55 -0
- package/dist/gen-core/field.js +154 -0
- package/dist/gen-core/geometry.d.ts +31 -0
- package/dist/gen-core/geometry.js +231 -0
- package/dist/gen-core/hash.d.ts +18 -0
- package/dist/gen-core/hash.js +58 -0
- package/dist/gen-core/height-field.d.ts +33 -0
- package/dist/gen-core/height-field.js +137 -0
- package/dist/gen-core/index.d.ts +22 -0
- package/dist/gen-core/index.js +17 -0
- package/dist/gen-core/instance-cells.d.ts +37 -0
- package/dist/gen-core/instance-cells.js +72 -0
- package/dist/gen-core/near-scatter.d.ts +56 -0
- package/dist/gen-core/near-scatter.js +120 -0
- package/dist/gen-core/noise.d.ts +23 -0
- package/dist/gen-core/noise.js +72 -0
- package/dist/gen-core/occupancy.d.ts +21 -0
- package/dist/gen-core/occupancy.js +104 -0
- package/dist/gen-core/sphere-patch.d.ts +138 -0
- package/dist/gen-core/sphere-patch.js +544 -0
- package/dist/gen-core/strip-surface.d.ts +34 -0
- package/dist/gen-core/strip-surface.js +246 -0
- package/dist/gen-core/strip.d.ts +102 -0
- package/dist/gen-core/strip.js +817 -0
- package/dist/gen-ground/env-slots.d.ts +48 -0
- package/dist/gen-ground/env-slots.js +78 -0
- package/dist/gen-ground/ground.d.ts +78 -0
- package/dist/gen-ground/ground.js +208 -0
- package/dist/gen-ground/index.d.ts +9 -0
- package/dist/gen-ground/index.js +7 -0
- package/dist/gen-ground/markings.d.ts +46 -0
- package/dist/gen-ground/markings.js +124 -0
- package/dist/gen-ground/materials.d.ts +18 -0
- package/dist/gen-ground/materials.js +22 -0
- package/dist/gen-ground/terrain-shader.d.ts +5 -0
- package/dist/gen-ground/terrain-shader.js +151 -0
- package/dist/gen-mesh/bare-shapes.d.ts +194 -0
- package/dist/gen-mesh/bare-shapes.js +596 -0
- package/dist/gen-mesh/bisect-surface.d.ts +47 -0
- package/dist/gen-mesh/bisect-surface.js +261 -0
- package/dist/gen-mesh/box.d.ts +18 -0
- package/dist/gen-mesh/box.js +2 -0
- package/dist/gen-mesh/cell-morph-mesh.d.ts +52 -0
- package/dist/gen-mesh/cell-morph-mesh.js +258 -0
- package/dist/gen-mesh/cell-surface-mesh.d.ts +32 -0
- package/dist/gen-mesh/cell-surface-mesh.js +140 -0
- package/dist/gen-mesh/chunk-mesh.d.ts +25 -0
- package/dist/gen-mesh/chunk-mesh.js +112 -0
- package/dist/gen-mesh/drape-mesh.d.ts +36 -0
- package/dist/gen-mesh/drape-mesh.js +98 -0
- package/dist/gen-mesh/height-field-mesh.d.ts +14 -0
- package/dist/gen-mesh/height-field-mesh.js +98 -0
- package/dist/gen-mesh/index.d.ts +26 -0
- package/dist/gen-mesh/index.js +15 -0
- package/dist/gen-mesh/line-mesh.d.ts +25 -0
- package/dist/gen-mesh/line-mesh.js +62 -0
- package/dist/gen-mesh/mesh-builder.d.ts +115 -0
- package/dist/gen-mesh/mesh-builder.js +315 -0
- package/dist/gen-mesh/packed-mesh.d.ts +53 -0
- package/dist/gen-mesh/packed-mesh.js +205 -0
- package/dist/gen-mesh/prism-mesh.d.ts +33 -0
- package/dist/gen-mesh/prism-mesh.js +176 -0
- package/dist/gen-mesh/rig-mesh.d.ts +9 -0
- package/dist/gen-mesh/rig-mesh.js +135 -0
- package/dist/gen-mesh/strip-mesh.d.ts +45 -0
- package/dist/gen-mesh/strip-mesh.js +258 -0
- package/dist/gen-plan/drain.d.ts +58 -0
- package/dist/gen-plan/drain.js +270 -0
- package/dist/gen-plan/grid.d.ts +37 -0
- package/dist/gen-plan/grid.js +182 -0
- package/dist/gen-plan/horizon.d.ts +50 -0
- package/dist/gen-plan/horizon.js +185 -0
- package/dist/gen-plan/index.d.ts +15 -0
- package/dist/gen-plan/index.js +13 -0
- package/dist/gen-plan/line-tiles.d.ts +35 -0
- package/dist/gen-plan/line-tiles.js +190 -0
- package/dist/gen-plan/lines.d.ts +31 -0
- package/dist/gen-plan/lines.js +183 -0
- package/dist/gen-plan/plots.d.ts +40 -0
- package/dist/gen-plan/plots.js +282 -0
- package/dist/gen-plan/route.d.ts +55 -0
- package/dist/gen-plan/route.js +297 -0
- package/dist/gen-plan/sites.d.ts +32 -0
- package/dist/gen-plan/sites.js +209 -0
- package/dist/gen-tex/code-stamp.d.ts +31 -0
- package/dist/gen-tex/code-stamp.js +137 -0
- package/dist/gen-tex/index.d.ts +7 -0
- package/dist/gen-tex/index.js +5 -0
- package/dist/gen-tex/light-horizon.d.ts +47 -0
- package/dist/gen-tex/light-horizon.js +180 -0
- package/dist/gen-tex/textures.d.ts +8 -0
- package/dist/gen-tex/textures.js +49 -0
- package/dist/gen-tex/value-textures.d.ts +46 -0
- package/dist/gen-tex/value-textures.js +102 -0
- package/dist/gen-vegetation/env-slots.d.ts +20 -0
- package/dist/gen-vegetation/env-slots.js +29 -0
- package/dist/gen-vegetation/index.d.ts +8 -0
- package/dist/gen-vegetation/index.js +7 -0
- package/dist/gen-vegetation/materials.d.ts +7 -0
- package/dist/gen-vegetation/materials.js +17 -0
- package/dist/gen-vegetation/planting.d.ts +170 -0
- package/dist/gen-vegetation/planting.js +363 -0
- package/dist/gen-vegetation/tree-shader.d.ts +23 -0
- package/dist/gen-vegetation/tree-shader.js +229 -0
- package/dist/gen-vegetation/trees.d.ts +59 -0
- package/dist/gen-vegetation/trees.js +329 -0
- package/dist/gpu/device.d.ts +286 -0
- package/dist/gpu/device.js +1157 -0
- package/dist/gpu/gl.d.ts +134 -0
- package/dist/gpu/gl.js +276 -0
- package/dist/gpu/index.d.ts +4 -0
- package/dist/gpu/index.js +3 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +13 -0
- package/dist/motion/graph.d.ts +244 -0
- package/dist/motion/graph.js +739 -0
- package/dist/motion/index.d.ts +8 -0
- package/dist/motion/index.js +8 -0
- package/dist/motion/pose-ops.d.ts +30 -0
- package/dist/motion/pose-ops.js +232 -0
- package/dist/motion/reach.d.ts +45 -0
- package/dist/motion/reach.js +264 -0
- package/dist/motion/skeleton.d.ts +49 -0
- package/dist/motion/skeleton.js +99 -0
- package/dist/platform/byte-store.d.ts +21 -0
- package/dist/platform/byte-store.js +137 -0
- package/dist/platform/canvas.d.ts +29 -0
- package/dist/platform/canvas.js +76 -0
- package/dist/platform/context-loss.d.ts +8 -0
- package/dist/platform/context-loss.js +17 -0
- package/dist/platform/free-input.d.ts +51 -0
- package/dist/platform/free-input.js +100 -0
- package/dist/platform/index.d.ts +18 -0
- package/dist/platform/index.js +10 -0
- package/dist/platform/input.d.ts +48 -0
- package/dist/platform/input.js +117 -0
- package/dist/platform/keys.d.ts +12 -0
- package/dist/platform/keys.js +29 -0
- package/dist/platform/loop.d.ts +41 -0
- package/dist/platform/loop.js +84 -0
- package/dist/platform/walk-input.d.ts +74 -0
- package/dist/platform/walk-input.js +226 -0
- package/dist/platform/worker.d.ts +51 -0
- package/dist/platform/worker.js +170 -0
- package/dist/render/bone-instances.d.ts +24 -0
- package/dist/render/bone-instances.js +74 -0
- package/dist/render/cells.d.ts +70 -0
- package/dist/render/cells.js +144 -0
- package/dist/render/glsl.d.ts +66 -0
- package/dist/render/glsl.js +173 -0
- package/dist/render/index.d.ts +26 -0
- package/dist/render/index.js +16 -0
- package/dist/render/instance-sets.d.ts +97 -0
- package/dist/render/instance-sets.js +241 -0
- package/dist/render/near-instances.d.ts +75 -0
- package/dist/render/near-instances.js +219 -0
- package/dist/render/particles.d.ts +63 -0
- package/dist/render/particles.js +215 -0
- package/dist/render/pieces.d.ts +57 -0
- package/dist/render/pieces.js +151 -0
- package/dist/render/point-lights.d.ts +97 -0
- package/dist/render/point-lights.js +243 -0
- package/dist/render/renderer.d.ts +447 -0
- package/dist/render/renderer.js +1100 -0
- package/dist/render/rig.d.ts +74 -0
- package/dist/render/rig.js +576 -0
- package/dist/render/shadow-areas.d.ts +49 -0
- package/dist/render/shadow-areas.js +125 -0
- package/dist/render/shadow-glsl.d.ts +12 -0
- package/dist/render/shadow-glsl.js +146 -0
- package/dist/render/transient.d.ts +61 -0
- package/dist/render/transient.js +213 -0
- package/dist/render/value-glsl.d.ts +17 -0
- package/dist/render/value-glsl.js +208 -0
- package/dist/render/value-layers.d.ts +180 -0
- package/dist/render/value-layers.js +333 -0
- package/dist/runtime/atmosphere.d.ts +37 -0
- package/dist/runtime/atmosphere.js +304 -0
- package/dist/runtime/cloud-shell.d.ts +29 -0
- package/dist/runtime/cloud-shell.js +158 -0
- package/dist/runtime/engine.d.ts +155 -0
- package/dist/runtime/engine.js +305 -0
- package/dist/runtime/environment-link.d.ts +22 -0
- package/dist/runtime/environment-link.js +49 -0
- package/dist/runtime/index.d.ts +13 -0
- package/dist/runtime/index.js +12 -0
- package/dist/runtime/precipitation-glsl.d.ts +2 -0
- package/dist/runtime/precipitation-glsl.js +70 -0
- package/dist/runtime/precipitation.d.ts +11 -0
- package/dist/runtime/precipitation.js +78 -0
- package/dist/runtime/sky.d.ts +30 -0
- package/dist/runtime/sky.js +114 -0
- package/dist/runtime/streaming.d.ts +245 -0
- package/dist/runtime/streaming.js +602 -0
- package/dist/sim/agenda.d.ts +167 -0
- package/dist/sim/agenda.js +425 -0
- package/dist/sim/bytes.d.ts +34 -0
- package/dist/sim/bytes.js +125 -0
- package/dist/sim/destruction/apply.d.ts +59 -0
- package/dist/sim/destruction/apply.js +243 -0
- package/dist/sim/destruction/cell-states.d.ts +54 -0
- package/dist/sim/destruction/cell-states.js +198 -0
- package/dist/sim/destruction/index.d.ts +11 -0
- package/dist/sim/destruction/index.js +10 -0
- package/dist/sim/destruction/int-geometry.d.ts +17 -0
- package/dist/sim/destruction/int-geometry.js +131 -0
- package/dist/sim/destruction/pick.d.ts +13 -0
- package/dist/sim/destruction/pick.js +59 -0
- package/dist/sim/destruction/rubble.d.ts +8 -0
- package/dist/sim/destruction/rubble.js +159 -0
- package/dist/sim/destruction/state.d.ts +15 -0
- package/dist/sim/destruction/state.js +83 -0
- package/dist/sim/destruction/structure.d.ts +30 -0
- package/dist/sim/destruction/structure.js +139 -0
- package/dist/sim/events.d.ts +37 -0
- package/dist/sim/events.js +106 -0
- package/dist/sim/fixed.d.ts +21 -0
- package/dist/sim/fixed.js +64 -0
- package/dist/sim/flow-probe.d.ts +58 -0
- package/dist/sim/flow-probe.js +158 -0
- package/dist/sim/flow.d.ts +257 -0
- package/dist/sim/flow.js +967 -0
- package/dist/sim/index.d.ts +28 -0
- package/dist/sim/index.js +20 -0
- package/dist/sim/interlock.d.ts +47 -0
- package/dist/sim/interlock.js +252 -0
- package/dist/sim/movers.d.ts +228 -0
- package/dist/sim/movers.js +1083 -0
- package/dist/sim/nav.d.ts +72 -0
- package/dist/sim/nav.js +292 -0
- package/dist/sim/paths.d.ts +80 -0
- package/dist/sim/paths.js +197 -0
- package/dist/sim/regions.d.ts +87 -0
- package/dist/sim/regions.js +517 -0
- package/dist/sim/simulation.d.ts +114 -0
- package/dist/sim/simulation.js +291 -0
- package/dist/sim/states.d.ts +23 -0
- package/dist/sim/states.js +54 -0
- package/dist/sim/table.d.ts +49 -0
- package/dist/sim/table.js +126 -0
- package/dist/sim/zones.d.ts +11 -0
- package/dist/sim/zones.js +196 -0
- package/dist/tools/collision-lines.d.ts +12 -0
- package/dist/tools/collision-lines.js +50 -0
- package/dist/tools/data-view-glsl.d.ts +3 -0
- package/dist/tools/data-view-glsl.js +63 -0
- package/dist/tools/data-view-layers.d.ts +20 -0
- package/dist/tools/data-view-layers.js +60 -0
- package/dist/tools/debug-view.d.ts +30 -0
- package/dist/tools/debug-view.js +4 -0
- package/dist/tools/index.d.ts +10 -0
- package/dist/tools/index.js +7 -0
- package/dist/tools/mesh-checks.d.ts +67 -0
- package/dist/tools/mesh-checks.js +188 -0
- package/dist/tools/profile.d.ts +85 -0
- package/dist/tools/profile.js +173 -0
- package/dist/world/cell-cache.d.ts +32 -0
- package/dist/world/cell-cache.js +60 -0
- package/dist/world/cell-format.d.ts +25 -0
- package/dist/world/cell-format.js +232 -0
- package/dist/world/collide.d.ts +192 -0
- package/dist/world/collide.js +822 -0
- package/dist/world/index.d.ts +16 -0
- package/dist/world/index.js +12 -0
- package/dist/world/mesh-solids.d.ts +48 -0
- package/dist/world/mesh-solids.js +169 -0
- package/dist/world/pick.d.ts +34 -0
- package/dist/world/pick.js +177 -0
- package/dist/world/providers.d.ts +66 -0
- package/dist/world/providers.js +83 -0
- package/dist/world/sphere.d.ts +69 -0
- package/dist/world/sphere.js +271 -0
- package/dist/world/streaming.d.ts +288 -0
- package/dist/world/streaming.js +801 -0
- package/dist/world/walker.d.ts +145 -0
- package/dist/world/walker.js +502 -0
- package/docs/architecture.md +111 -0
- package/docs/cameras.md +302 -0
- package/docs/concepts.md +123 -0
- package/docs/destruction.md +127 -0
- package/docs/frames.md +199 -0
- package/docs/generators.md +575 -0
- package/docs/getting-started.md +123 -0
- package/docs/headless.md +50 -0
- package/docs/motion.md +160 -0
- package/docs/planet.md +152 -0
- package/docs/recipes.md +521 -0
- package/docs/reference.md +364 -0
- package/docs/rendering.md +823 -0
- package/docs/rigs.md +203 -0
- package/docs/simulation.md +235 -0
- package/docs/streaming.md +590 -0
- package/docs/system.md +166 -0
- package/docs/tools.md +175 -0
- package/docs/walking.md +262 -0
- package/package.json +131 -3
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// Level of detail picked from one scalar (for example screen pixels per metre), with a dead band around every
|
|
2
|
+
// threshold and a timed transition between neighbouring levels, and the screen-door fade that draws the transition:
|
|
3
|
+
// during it both levels are drawn, each fragment by exactly one of them, so nothing pops and nothing needs blending.
|
|
4
|
+
// Pure logic and GLSL text: no clock inside (the caller passes the elapsed time), no GPU.
|
|
5
|
+
/**
|
|
6
|
+
* Chooses a level from a value and moves a continuous position towards it. Position 1.3 means: 30 % of the way from
|
|
7
|
+
* level 1 to level 2. What is drawn at a position comes from `fade` (the `u_fade` value of a layer) and `shown`.
|
|
8
|
+
*/
|
|
9
|
+
export class LevelFade {
|
|
10
|
+
/** Number of levels. */
|
|
11
|
+
count;
|
|
12
|
+
/** Highest level that may be shown now. Lower it while a coarser level is not ready; the position follows. */
|
|
13
|
+
limit;
|
|
14
|
+
below;
|
|
15
|
+
hysteresis;
|
|
16
|
+
seconds;
|
|
17
|
+
target = 0;
|
|
18
|
+
pos = 0;
|
|
19
|
+
started = false;
|
|
20
|
+
constructor(o) {
|
|
21
|
+
for (let k = 1; k < o.below.length; k++) {
|
|
22
|
+
if (!(o.below[k] < o.below[k - 1]))
|
|
23
|
+
throw new Error('LevelFade: thresholds must descend');
|
|
24
|
+
}
|
|
25
|
+
this.below = [...o.below];
|
|
26
|
+
this.count = o.below.length + 1;
|
|
27
|
+
this.limit = o.below.length;
|
|
28
|
+
this.hysteresis = o.hysteresis ?? 0.15;
|
|
29
|
+
this.seconds = o.seconds ?? 0.35;
|
|
30
|
+
}
|
|
31
|
+
/** The level the value asks for (ignores `limit` and the transition). */
|
|
32
|
+
get level() {
|
|
33
|
+
return this.target;
|
|
34
|
+
}
|
|
35
|
+
/** Where the transition is: a whole number when at rest, between two levels while moving. */
|
|
36
|
+
get position() {
|
|
37
|
+
return this.pos;
|
|
38
|
+
}
|
|
39
|
+
/** Whether a transition is under way. */
|
|
40
|
+
get moving() {
|
|
41
|
+
return this.started && this.pos !== Math.min(this.target, this.limit);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Takes the current value and the time since the last call. The first call places the position on its level without
|
|
45
|
+
* a transition. Returns whether the position still has to move, that is, whether another frame is needed.
|
|
46
|
+
*/
|
|
47
|
+
update(value, dtSeconds) {
|
|
48
|
+
let t = this.target;
|
|
49
|
+
while (t < this.below.length && value < this.below[t] * (1 - this.hysteresis))
|
|
50
|
+
t++;
|
|
51
|
+
while (t > 0 && value > this.below[t - 1] * (1 + this.hysteresis))
|
|
52
|
+
t--;
|
|
53
|
+
this.target = t;
|
|
54
|
+
const goal = Math.min(t, this.limit);
|
|
55
|
+
if (!this.started) {
|
|
56
|
+
this.started = true;
|
|
57
|
+
this.pos = goal;
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
if (this.pos === goal)
|
|
61
|
+
return false;
|
|
62
|
+
const step = this.seconds > 0 ? Math.max(0, dtSeconds) / this.seconds : Infinity;
|
|
63
|
+
this.pos = this.pos < goal ? Math.min(goal, this.pos + step) : Math.max(goal, this.pos - step);
|
|
64
|
+
return this.pos !== goal;
|
|
65
|
+
}
|
|
66
|
+
/** Ends the transition at once (after a jump of the view, for example). */
|
|
67
|
+
snap() {
|
|
68
|
+
this.pos = Math.min(this.target, this.limit);
|
|
69
|
+
this.started = true;
|
|
70
|
+
}
|
|
71
|
+
/** Whether anything drawn on the levels `first`…`last` is visible at the current position. */
|
|
72
|
+
shown(first, last = first) {
|
|
73
|
+
return this.pos > first - 1 && this.pos < last + 1;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* `u_fade` of something drawn on the levels `first`…`last`: x the share of fragments left out (0 inside the span,
|
|
77
|
+
* growing to 1 one level away), y the side of the pattern (0 when leaving towards coarser levels, 1 towards finer
|
|
78
|
+
* ones). Two neighbouring spans get complementary patterns, so together they cover every fragment exactly once.
|
|
79
|
+
*/
|
|
80
|
+
fade(first, last = first) {
|
|
81
|
+
if (this.pos > last)
|
|
82
|
+
return [Math.min(1, this.pos - last), 0];
|
|
83
|
+
if (this.pos < first)
|
|
84
|
+
return [Math.min(1, first - this.pos), 1];
|
|
85
|
+
return [0, 0];
|
|
86
|
+
}
|
|
87
|
+
/** The same as a uniform set: `{ u_fade }`. */
|
|
88
|
+
uniforms(first, last = first) {
|
|
89
|
+
return { u_fade: { vec2: this.fade(first, last) } };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* GLSL of the screen-door fade (fragment shader): `uniform vec2 u_fade` (x share of fragments left out 0–1, y > 0.5
|
|
94
|
+
* the complementary side of the pattern) and `bool fadeHidden(vec2 frag)`, called with `gl_FragCoord.xy`. A uniform
|
|
95
|
+
* that is never set is zero: everything is drawn. The threshold is interleaved gradient noise of the fragment
|
|
96
|
+
* position, so the pattern is even at every share and the same in every program.
|
|
97
|
+
*/
|
|
98
|
+
export const FADE_GLSL = /* glsl */ `uniform vec2 u_fade;
|
|
99
|
+
bool fadeHidden(vec2 frag) {
|
|
100
|
+
float t = fract(52.9829189 * fract(dot(floor(frag), vec2(0.06711056, 0.00583715))));
|
|
101
|
+
return (u_fade.y > 0.5 ? 1.0 - t : t) < u_fade.x;
|
|
102
|
+
}
|
|
103
|
+
`;
|
|
104
|
+
const MAIN = 'void main() {';
|
|
105
|
+
/** A fragment shader with the screen-door fade added in front of everything else in `main`. */
|
|
106
|
+
export function fadeFragment(fs) {
|
|
107
|
+
const at = fs.indexOf(MAIN);
|
|
108
|
+
if (at < 0 || fs.indexOf(MAIN, at + MAIN.length) >= 0)
|
|
109
|
+
throw new Error('fadeFragment: the shader must have exactly one "void main() {"');
|
|
110
|
+
return `${fs.slice(0, at)}${FADE_GLSL}${MAIN}\n if (fadeHidden(gl_FragCoord.xy)) discard;${fs.slice(at + MAIN.length)}`;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* The material with the screen-door fade in every pass that has its own program (`u_fade`, see `FADE_GLSL`). A pass
|
|
114
|
+
* drawn by the plain depth program (`'depth'`) stays as it is. The original description is not touched.
|
|
115
|
+
*/
|
|
116
|
+
export function withFade(desc) {
|
|
117
|
+
const passes = {};
|
|
118
|
+
for (const name of Object.keys(desc.passes)) {
|
|
119
|
+
const src = desc.passes[name];
|
|
120
|
+
passes[name] = src === 'depth' ? src : { vs: src.vs, fs: fadeFragment(src.fs) };
|
|
121
|
+
}
|
|
122
|
+
return { ...desc, name: `${desc.name}+fade`, passes };
|
|
123
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { RGB } from '../base/math.ts';
|
|
2
|
+
/** Largest number of rows the shaders expect (size of the Palette uniform block). */
|
|
3
|
+
export declare const PALETTE_CAPACITY = 96;
|
|
4
|
+
export interface Palette<K extends string> {
|
|
5
|
+
/** Row names in row order. */
|
|
6
|
+
readonly keys: readonly K[];
|
|
7
|
+
/** Row index of a colour: the number that goes into vertices and shader uniforms. */
|
|
8
|
+
index(key: K): number;
|
|
9
|
+
/** Colour of a row as three numbers 0–1 in display space (sRGB). */
|
|
10
|
+
color(key: K): RGB;
|
|
11
|
+
/** The table for the Palette uniform block: `PALETTE_CAPACITY` vec4 rows, unused rows are zero. */
|
|
12
|
+
data(): Float32Array;
|
|
13
|
+
}
|
|
14
|
+
/** Builds a palette from named `#rrggbb` rows. */
|
|
15
|
+
export declare function definePalette<const R extends Record<string, string>>(rows: R): Palette<Extract<keyof R, string>>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Palette mechanism: a project names its colours, the engine turns them into a colour table for the shaders and
|
|
2
|
+
// hands back typed keys and row indices. The engine itself holds no colours.
|
|
3
|
+
//
|
|
4
|
+
// const palette = definePalette({ ground: '#4d4335', sky: '#6795b1' });
|
|
5
|
+
// palette.index('sky') // 1, the row a shader reads as u_palette[1]
|
|
6
|
+
// palette.color('sky') // [r, g, b] in 0–1, display space (sRGB)
|
|
7
|
+
//
|
|
8
|
+
// Rows keep the order in which the object lists them, so the table is the same byte for byte on every run.
|
|
9
|
+
/** Largest number of rows the shaders expect (size of the Palette uniform block). */
|
|
10
|
+
export const PALETTE_CAPACITY = 96;
|
|
11
|
+
function hexToRgb(hex) {
|
|
12
|
+
if (!/^#[0-9a-fA-F]{6}$/.test(hex))
|
|
13
|
+
throw new Error(`Not a #rrggbb colour: ${hex}`);
|
|
14
|
+
const v = Number.parseInt(hex.slice(1), 16);
|
|
15
|
+
return [((v >> 16) & 255) / 255, ((v >> 8) & 255) / 255, (v & 255) / 255];
|
|
16
|
+
}
|
|
17
|
+
/** Builds a palette from named `#rrggbb` rows. */
|
|
18
|
+
export function definePalette(rows) {
|
|
19
|
+
const keys = Object.keys(rows);
|
|
20
|
+
if (keys.length > PALETTE_CAPACITY)
|
|
21
|
+
throw new Error(`The palette has ${keys.length} rows, the shaders hold ${PALETTE_CAPACITY}`);
|
|
22
|
+
const colors = keys.map((k) => hexToRgb(rows[k]));
|
|
23
|
+
const indexOf = new Map(keys.map((k, i) => [k, i]));
|
|
24
|
+
return {
|
|
25
|
+
keys,
|
|
26
|
+
index(key) {
|
|
27
|
+
const i = indexOf.get(key);
|
|
28
|
+
if (i === undefined)
|
|
29
|
+
throw new Error(`Unknown palette row: ${key}`);
|
|
30
|
+
return i;
|
|
31
|
+
},
|
|
32
|
+
color(key) {
|
|
33
|
+
const c = colors[this.index(key)];
|
|
34
|
+
return [c[0], c[1], c[2]];
|
|
35
|
+
},
|
|
36
|
+
data() {
|
|
37
|
+
const out = new Float32Array(PALETTE_CAPACITY * 4);
|
|
38
|
+
colors.forEach((c, i) => {
|
|
39
|
+
out[i * 4] = c[0];
|
|
40
|
+
out[i * 4 + 1] = c[1];
|
|
41
|
+
out[i * 4 + 2] = c[2];
|
|
42
|
+
out[i * 4 + 3] = 1;
|
|
43
|
+
});
|
|
44
|
+
return out;
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import type { RGB, Vec3 } from '../base/math.ts';
|
|
2
|
+
import type { TextureData } from '../base/data.ts';
|
|
3
|
+
import type { EnvSlot, FrameEnvironment } from '../base/env-slot.ts';
|
|
4
|
+
/** What the air is made of. Fixed when the slot is created: the tables are computed from it. */
|
|
5
|
+
export interface AtmosphereMedium {
|
|
6
|
+
/** Radius of the ground sphere in metres. With the renderer's `radialUp` give the same radius. */
|
|
7
|
+
radiusM: number;
|
|
8
|
+
/** Thickness of the shell of air above the ground sphere in metres. */
|
|
9
|
+
heightM: number;
|
|
10
|
+
/** Scattering by molecules per metre at the ground, and the height over which their density falls to 1/e. */
|
|
11
|
+
rayleigh: RGB;
|
|
12
|
+
rayleighScaleM: number;
|
|
13
|
+
/** Scattering and absorption by particles per metre at the ground, their scale height, and the forward share g (0–1). */
|
|
14
|
+
mieScattering: number;
|
|
15
|
+
mieAbsorption: number;
|
|
16
|
+
mieScaleM: number;
|
|
17
|
+
mieG: number;
|
|
18
|
+
/** An absorbing layer (ozone): absorption per metre in its middle, the height of the middle and its half-width. */
|
|
19
|
+
absorption: RGB;
|
|
20
|
+
absorptionCenterM: number;
|
|
21
|
+
absorptionHalfWidthM: number;
|
|
22
|
+
/** Share of light the ground sends back into the air, for the light scattered more than once. */
|
|
23
|
+
groundAlbedo: number;
|
|
24
|
+
}
|
|
25
|
+
export interface AtmosphereParams extends AtmosphereMedium {
|
|
26
|
+
/**
|
|
27
|
+
* Brightness of the scattered light on screen: its colour is `1 − exp(−radiance × exposure)`, where the radiance is
|
|
28
|
+
* measured with the sun above the air as 1.
|
|
29
|
+
*/
|
|
30
|
+
exposure: number;
|
|
31
|
+
/** The sun above the air as light on surfaces, a multiple of the surface colour (`atmosphereLight`). */
|
|
32
|
+
sunLight: RGB;
|
|
33
|
+
/** Gain of the sky's light on surfaces. 1 is the physical share; more lifts the shadows. */
|
|
34
|
+
skyLightGain: number;
|
|
35
|
+
/** Light on surfaces that remains where the sun does not reach. */
|
|
36
|
+
nightLight: RGB;
|
|
37
|
+
/** Radius of the sun's disc in radians. */
|
|
38
|
+
sunDiscRad: number;
|
|
39
|
+
/** Visibility of the stars behind dark air, 0–1. */
|
|
40
|
+
stars: number;
|
|
41
|
+
/** Where up is +y: height of the ground in render space. */
|
|
42
|
+
groundY: number;
|
|
43
|
+
/** Steps along a view ray of the sky and along the way to a surface point (at most 48). Fixed at creation. */
|
|
44
|
+
skySteps: number;
|
|
45
|
+
airSteps: number;
|
|
46
|
+
/**
|
|
47
|
+
* Reference quality: the integral along the view ray is taken for every pixel, of the sky and of every material,
|
|
48
|
+
* instead of read from the sky table and carried from the vertices. Many times slower; for comparing the two.
|
|
49
|
+
*/
|
|
50
|
+
reference: boolean;
|
|
51
|
+
/** Eye of the current view in render space, or null for a view without one. The atmosphere layer sets it every frame. */
|
|
52
|
+
eye: Vec3 | null;
|
|
53
|
+
/** Height of that eye above the ground sphere in metres. The atmosphere layer sets it every frame. */
|
|
54
|
+
eyeHeightM: number;
|
|
55
|
+
}
|
|
56
|
+
/** Air of the Earth (coefficients as in Hillaire 2020). */
|
|
57
|
+
export declare const DEFAULT_ATMOSPHERE_MEDIUM: AtmosphereMedium;
|
|
58
|
+
export declare const DEFAULT_ATMOSPHERE: Omit<AtmosphereParams, 'eye' | 'eyeHeightM'>;
|
|
59
|
+
/**
|
|
60
|
+
* The default air fitted to a sphere of another size: every height is scaled to a shell `heightM` thick and every
|
|
61
|
+
* density the other way, so the light that comes straight down is the same as through the default air.
|
|
62
|
+
*/
|
|
63
|
+
export declare function atmosphereFor(radiusM: number, heightM: number): AtmosphereMedium;
|
|
64
|
+
/** Texture unit the atmosphere layer keeps the tables on during the colour pass (sampler `u_atmTables`). */
|
|
65
|
+
export declare const ATMOSPHERE_TABLE_UNIT = 14;
|
|
66
|
+
/** Where each table lies in the texture, in texels: x, y, width, height. */
|
|
67
|
+
export declare const ATMOSPHERE_TABLE_LAYOUT: {
|
|
68
|
+
readonly width: 160;
|
|
69
|
+
readonly height: 32;
|
|
70
|
+
readonly transmittance: readonly [0, 0, 128, 32];
|
|
71
|
+
readonly multiScatter: readonly [128, 0, 32, 16];
|
|
72
|
+
readonly skyLight: readonly [128, 16, 32, 16];
|
|
73
|
+
};
|
|
74
|
+
export interface AtmosphereTables {
|
|
75
|
+
/** RGBA8, linear filter. Every table stores the square root of its value over its scale. */
|
|
76
|
+
texture: TextureData;
|
|
77
|
+
/** Largest value of the table of light scattered more than once, and of the table of sky light. */
|
|
78
|
+
multiScatterScale: number;
|
|
79
|
+
skyLightScale: number;
|
|
80
|
+
}
|
|
81
|
+
/** Pure: the three tables of a medium, packed into one texture. Takes tens of milliseconds. */
|
|
82
|
+
export declare function atmosphereTables(m: AtmosphereMedium): AtmosphereTables;
|
|
83
|
+
/** What the atmosphere slot computes for one frame. */
|
|
84
|
+
export interface AtmosphereValues {
|
|
85
|
+
/** True unit direction to the sun. */
|
|
86
|
+
sunDir: Vec3;
|
|
87
|
+
/** 0 for a view without an eye: no air is drawn in it. */
|
|
88
|
+
exposure: number;
|
|
89
|
+
eye: Vec3;
|
|
90
|
+
eyeHeightM: number;
|
|
91
|
+
radiusM: number;
|
|
92
|
+
topM: number;
|
|
93
|
+
groundY: number;
|
|
94
|
+
sunDiscRad: number;
|
|
95
|
+
rayleigh: RGB;
|
|
96
|
+
invRayleighScale: number;
|
|
97
|
+
mieScattering: number;
|
|
98
|
+
mieExtinction: number;
|
|
99
|
+
invMieScale: number;
|
|
100
|
+
mieG: number;
|
|
101
|
+
absorption: RGB;
|
|
102
|
+
absorptionCenterM: number;
|
|
103
|
+
invAbsorptionHalfWidth: number;
|
|
104
|
+
multiScatterScale: number;
|
|
105
|
+
skyLightScale: number;
|
|
106
|
+
stars: number;
|
|
107
|
+
sunLight: RGB;
|
|
108
|
+
skyLightGain: number;
|
|
109
|
+
nightLight: RGB;
|
|
110
|
+
/** 1 for the reference quality (`AtmosphereParams.reference`), else 0. */
|
|
111
|
+
reference: number;
|
|
112
|
+
}
|
|
113
|
+
/** An atmosphere slot: the slot and the tables computed for its medium. */
|
|
114
|
+
export interface AtmosphereSlot extends EnvSlot<AtmosphereParams, AtmosphereValues> {
|
|
115
|
+
/** The medium the tables were made for (a copy; later changes of the params' medium have no effect). */
|
|
116
|
+
readonly medium: AtmosphereMedium;
|
|
117
|
+
readonly tables: AtmosphereTables;
|
|
118
|
+
}
|
|
119
|
+
/** Pure: the slot's values from the generic environment, the params, and the medium with its tables. */
|
|
120
|
+
export declare function computeAtmosphere(E: FrameEnvironment, p: AtmosphereParams, m: AtmosphereMedium, tables: Pick<AtmosphereTables, 'multiScatterScale' | 'skyLightScale'>): AtmosphereValues;
|
|
121
|
+
/** GLSL of the slot for the given step counts. Needs `<header>` before it. */
|
|
122
|
+
export declare function atmosphereGlsl(skySteps: number, airSteps: number): string;
|
|
123
|
+
/** The functions a material may call without asking: no air, the colour passes unchanged. Registered as `<atmosphere>` when there is no atmosphere slot. */
|
|
124
|
+
export declare const ATMOSPHERE_FALLBACK = "\nvec3 atmosphereApply(vec3 display, vec3 worldPos) { return display; }\nvec3 atmosphereAir(vec3 worldPos, out vec3 through) { through = vec3(1.0); return vec3(0.0); }\nvec3 atmosphereApply(vec3 display, vec3 worldPos, vec3 air, vec3 through) { return display; }\n";
|
|
125
|
+
/**
|
|
126
|
+
* The atmosphere slot. Pass it in the engine's slots together with an `AtmosphereLayer` of runtime, or use
|
|
127
|
+
* `createEngine({ atmosphere })`, which does both. The medium part of the params is read once, here.
|
|
128
|
+
*/
|
|
129
|
+
export declare function atmosphereSlot(params?: Partial<AtmosphereParams>): AtmosphereSlot;
|