wallhammer-web 0.0.0-stage → 0.4.0
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 +88 -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,49 @@
|
|
|
1
|
+
// Ties an environment to a renderer: every frame computes the environment for the view, hands the light direction,
|
|
2
|
+
// background and shadow key to the renderer and fills the environment's part of the Frame block from its slots.
|
|
3
|
+
// Programs that read the environment include `header` and `lighting` (or only `shadow`, the sun visibility without the
|
|
4
|
+
// light model); a slot with GLSL is included by its name.
|
|
5
|
+
import { ATMOSPHERE_FALLBACK, CLOUD_FIELD_SLOT, LIGHTING, SHADOW_QUERY, SKY_FALLBACK, lightingGlsl, shadowGlsl } from '../env/index.js';
|
|
6
|
+
export class EnvironmentLink {
|
|
7
|
+
env;
|
|
8
|
+
block;
|
|
9
|
+
/** Environment of the last frame. */
|
|
10
|
+
frame = null;
|
|
11
|
+
background;
|
|
12
|
+
slotValues = new Map();
|
|
13
|
+
constructor(renderer, env, options) {
|
|
14
|
+
const block = options.block;
|
|
15
|
+
if (renderer.frameSlots.afterLight.length !== block.afterLight * 4 || renderer.frameSlots.afterView.length !== block.afterView * 4) {
|
|
16
|
+
throw new Error('The renderer was created with other frame slots than this block (frameSlots: block)');
|
|
17
|
+
}
|
|
18
|
+
this.env = env;
|
|
19
|
+
this.block = block;
|
|
20
|
+
this.background = options.background;
|
|
21
|
+
// A cloud cover by place (its slot) brings its functions with the lighting include.
|
|
22
|
+
const byPlace = block.slots.some((s) => s.name === CLOUD_FIELD_SLOT);
|
|
23
|
+
renderer.includes.set('lighting', byPlace ? lightingGlsl({ cloudField: true }) : LIGHTING);
|
|
24
|
+
renderer.includes.set('shadow', byPlace ? shadowGlsl({ cloudField: true }) : SHADOW_QUERY);
|
|
25
|
+
// `<sky>` always resolves: the sky slot's functions when it is registered, otherwise stand-ins without haze.
|
|
26
|
+
renderer.includes.set('sky', SKY_FALLBACK);
|
|
27
|
+
// The same for `<atmosphere>`: without the atmosphere slot `atmosphereApply` passes the colour unchanged.
|
|
28
|
+
renderer.includes.set('atmosphere', ATMOSPHERE_FALLBACK);
|
|
29
|
+
for (const s of block.slots)
|
|
30
|
+
if (s.glsl !== undefined)
|
|
31
|
+
renderer.includes.set(s.name, s.glsl);
|
|
32
|
+
renderer.beforeFrame.push((view) => this.update(renderer, view));
|
|
33
|
+
}
|
|
34
|
+
/** Values a slot computed for the last frame, or undefined before the first frame. */
|
|
35
|
+
value(slot) {
|
|
36
|
+
return this.slotValues.get(slot);
|
|
37
|
+
}
|
|
38
|
+
update(renderer, view) {
|
|
39
|
+
const E = this.env.frame(view);
|
|
40
|
+
this.frame = E;
|
|
41
|
+
const paper = this.background;
|
|
42
|
+
renderer.background = [paper[0] * E.backdrop[0], paper[1] * E.backdrop[1], paper[2] * E.backdrop[2]];
|
|
43
|
+
renderer.lightDirection = E.toSun;
|
|
44
|
+
const packed = this.block.pack(E, renderer.frameSlots);
|
|
45
|
+
this.slotValues = packed.values;
|
|
46
|
+
// Slots name what changes the shadow map besides the light (for example how much light passes through a partly transparent occluder).
|
|
47
|
+
renderer.shadowKeyExtra = packed.shadowKey;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { EnvironmentLink } from './environment-link.ts';
|
|
2
|
+
export type { EnvironmentLinkOptions } from './environment-link.ts';
|
|
3
|
+
export { PrecipitationLayer } from './precipitation.ts';
|
|
4
|
+
export { PRECIP_FS, PRECIP_VS } from './precipitation-glsl.ts';
|
|
5
|
+
export { CLOUD_SHELL_FS, CLOUD_SHELL_VS, CloudShellLayer } from './cloud-shell.ts';
|
|
6
|
+
export { SKY_FS, SKY_VS, SkyLayer } from './sky.ts';
|
|
7
|
+
export { ATMOSPHERE_FS, ATMOSPHERE_SKY_TABLE, ATMOSPHERE_TABLE_FS, AtmosphereLayer } from './atmosphere.ts';
|
|
8
|
+
export { Engine, HeadlessEngine, createEngine, createHeadlessEngine } from './engine.ts';
|
|
9
|
+
export type { EngineOptions, EngineView, HeadlessEngineOptions } from './engine.ts';
|
|
10
|
+
export { StreamedWorld, WorkerCellProvider, serveCellGenerator, viewTickets, viewerTickets } from './streaming.ts';
|
|
11
|
+
/** Kept here for older imports; it lives in base. */
|
|
12
|
+
export { boxInVolume } from '../base/view.ts';
|
|
13
|
+
export type { StreamArchetype, StreamedWorldOptions, StreamedWorldStats } from './streaming.ts';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Layer 6, runtime: the mediator (`createEngine`, `createHeadlessEngine`: init order, the frame, dispose), the wiring of
|
|
2
|
+
// environment → renderer and the screen-space precipitation.
|
|
3
|
+
export { EnvironmentLink } from './environment-link.js';
|
|
4
|
+
export { PrecipitationLayer } from './precipitation.js';
|
|
5
|
+
export { PRECIP_FS, PRECIP_VS } from './precipitation-glsl.js';
|
|
6
|
+
export { CLOUD_SHELL_FS, CLOUD_SHELL_VS, CloudShellLayer } from './cloud-shell.js';
|
|
7
|
+
export { SKY_FS, SKY_VS, SkyLayer } from './sky.js';
|
|
8
|
+
export { ATMOSPHERE_FS, ATMOSPHERE_SKY_TABLE, ATMOSPHERE_TABLE_FS, AtmosphereLayer } from './atmosphere.js';
|
|
9
|
+
export { Engine, HeadlessEngine, createEngine, createHeadlessEngine } from './engine.js';
|
|
10
|
+
export { StreamedWorld, WorkerCellProvider, serveCellGenerator, viewTickets, viewerTickets } from './streaming.js';
|
|
11
|
+
/** Kept here for older imports; it lives in base. */
|
|
12
|
+
export { boxInVolume } from '../base/view.js';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const PRECIP_VS = "#version 300 es\nvoid main() {\n vec2 p = vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2));\n gl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0);\n}";
|
|
2
|
+
export declare const PRECIP_FS = "#include <header>\n#include <noise>\nuniform float u_slant; // horizontal shift per pixel of fall (wind across the screen)\nuniform vec2 u_fall; // screen direction of the fall, (0, -1) when it runs straight down the screen\nuniform float u_pxScale; // physical pixels per CSS pixel\nout vec4 o_color;\n\n// One layer of rain streaks. Grid cells have at most one drop, the grid falls and is sheared by the wind.\nfloat rainLayer(vec2 p, vec2 cellSize, float speed, float len, uint seed, float density) {\n vec2 q = p;\n q.y += u_time.x * speed;\n q.x += q.y * u_slant;\n vec2 cell = floor(q / cellSize);\n ivec2 ic = ivec2(cell);\n if (hash2(ic, seed) > density) return 0.0;\n vec2 f = q - cell * cellSize;\n float x0 = (0.15 + 0.7 * hash2(ic, seed + 1u)) * cellSize.x;\n float y0 = hash2(ic, seed + 2u) * (cellSize.y - len);\n float a = 1.0 - smoothstep(0.3, 1.0, abs(f.x - x0) / u_pxScale);\n float along = (f.y - y0) / len;\n // The bottom end (earlier in time) is the strongest, the streak fades upward.\n return a * step(0.0, along) * step(along, 1.0) * (1.0 - 0.7 * along);\n}\n\nfloat snowLayer(vec2 p, float cell, float speed, float radius, uint seed, float density) {\n vec2 q = p;\n q.y += u_time.x * speed;\n q.x += u_time.x * speed * u_slant;\n vec2 c = floor(q / cell);\n ivec2 ic = ivec2(c);\n if (hash2(ic, seed) > density) return 0.0;\n float ph = hash2(ic, seed + 3u) * 6.2831853;\n vec2 center = vec2(0.2 + 0.6 * hash2(ic, seed + 1u), 0.2 + 0.6 * hash2(ic, seed + 2u)) * cell;\n center.x += sin(u_time.x * (0.9 + 0.6 * hash2(ic, seed + 4u)) + ph) * cell * 0.16;\n float d = length(q - c * cell - center);\n return 1.0 - smoothstep(radius * 0.45, radius, d);\n}\n\nvoid main() {\n float k = u_weather.w;\n // Rotate the screen so the fall runs along \u2212y.\n vec2 p = vec2(-u_fall.y * gl_FragCoord.x + u_fall.x * gl_FragCoord.y, -u_fall.x * gl_FragCoord.x - u_fall.y * gl_FragCoord.y);\n float s = u_pxScale;\n float a;\n vec3 col;\n if (u_fogColor.w < 0.5) {\n float d = 0.15 + 0.6 * k;\n a = 0.34 * rainLayer(p, vec2(7.0, 70.0) * s, 1500.0 * s, 26.0 * s, 101u, d)\n + 0.26 * rainLayer(p + 31.0, vec2(5.0, 52.0) * s, 1150.0 * s, 18.0 * s, 102u, d)\n + 0.18 * rainLayer(p + 57.0, vec2(4.0, 40.0) * s, 850.0 * s, 12.0 * s, 103u, d * 0.8);\n a *= 0.55 + 0.45 * k;\n col = min(u_fogColor.rgb * 1.25 + 0.08, vec3(1.0));\n } else {\n float d = 0.12 + 0.5 * k;\n a = 0.9 * snowLayer(p, 30.0 * s, 95.0 * s, 2.6 * s, 111u, d)\n + 0.75 * snowLayer(p + 13.0, 22.0 * s, 70.0 * s, 2.0 * s, 112u, d)\n + 0.55 * snowLayer(p + 29.0, 16.0 * s, 48.0 * s, 1.5 * s, 113u, d);\n col = mix(u_fogColor.rgb, vec3(0.93, 0.93, 0.91), 0.75);\n }\n a = clamp(a, 0.0, 0.9);\n o_color = vec4(col * a, a);\n}";
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Precipitation over the whole image: rain as slanted streaks, snow as flakes. Drawn with a single triangle across
|
|
2
|
+
// the screen after the scene and blended transparently. The pattern is a pure function of animation time and pixel position,
|
|
3
|
+
// so the same time gives the same image and stopped clocks stop the rain too.
|
|
4
|
+
export const PRECIP_VS = /* glsl */ `#version 300 es
|
|
5
|
+
void main() {
|
|
6
|
+
vec2 p = vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2));
|
|
7
|
+
gl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0);
|
|
8
|
+
}`;
|
|
9
|
+
export const PRECIP_FS = /* glsl */ `#include <header>
|
|
10
|
+
#include <noise>
|
|
11
|
+
uniform float u_slant; // horizontal shift per pixel of fall (wind across the screen)
|
|
12
|
+
uniform vec2 u_fall; // screen direction of the fall, (0, -1) when it runs straight down the screen
|
|
13
|
+
uniform float u_pxScale; // physical pixels per CSS pixel
|
|
14
|
+
out vec4 o_color;
|
|
15
|
+
|
|
16
|
+
// One layer of rain streaks. Grid cells have at most one drop, the grid falls and is sheared by the wind.
|
|
17
|
+
float rainLayer(vec2 p, vec2 cellSize, float speed, float len, uint seed, float density) {
|
|
18
|
+
vec2 q = p;
|
|
19
|
+
q.y += u_time.x * speed;
|
|
20
|
+
q.x += q.y * u_slant;
|
|
21
|
+
vec2 cell = floor(q / cellSize);
|
|
22
|
+
ivec2 ic = ivec2(cell);
|
|
23
|
+
if (hash2(ic, seed) > density) return 0.0;
|
|
24
|
+
vec2 f = q - cell * cellSize;
|
|
25
|
+
float x0 = (0.15 + 0.7 * hash2(ic, seed + 1u)) * cellSize.x;
|
|
26
|
+
float y0 = hash2(ic, seed + 2u) * (cellSize.y - len);
|
|
27
|
+
float a = 1.0 - smoothstep(0.3, 1.0, abs(f.x - x0) / u_pxScale);
|
|
28
|
+
float along = (f.y - y0) / len;
|
|
29
|
+
// The bottom end (earlier in time) is the strongest, the streak fades upward.
|
|
30
|
+
return a * step(0.0, along) * step(along, 1.0) * (1.0 - 0.7 * along);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
float snowLayer(vec2 p, float cell, float speed, float radius, uint seed, float density) {
|
|
34
|
+
vec2 q = p;
|
|
35
|
+
q.y += u_time.x * speed;
|
|
36
|
+
q.x += u_time.x * speed * u_slant;
|
|
37
|
+
vec2 c = floor(q / cell);
|
|
38
|
+
ivec2 ic = ivec2(c);
|
|
39
|
+
if (hash2(ic, seed) > density) return 0.0;
|
|
40
|
+
float ph = hash2(ic, seed + 3u) * 6.2831853;
|
|
41
|
+
vec2 center = vec2(0.2 + 0.6 * hash2(ic, seed + 1u), 0.2 + 0.6 * hash2(ic, seed + 2u)) * cell;
|
|
42
|
+
center.x += sin(u_time.x * (0.9 + 0.6 * hash2(ic, seed + 4u)) + ph) * cell * 0.16;
|
|
43
|
+
float d = length(q - c * cell - center);
|
|
44
|
+
return 1.0 - smoothstep(radius * 0.45, radius, d);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
void main() {
|
|
48
|
+
float k = u_weather.w;
|
|
49
|
+
// Rotate the screen so the fall runs along −y.
|
|
50
|
+
vec2 p = vec2(-u_fall.y * gl_FragCoord.x + u_fall.x * gl_FragCoord.y, -u_fall.x * gl_FragCoord.x - u_fall.y * gl_FragCoord.y);
|
|
51
|
+
float s = u_pxScale;
|
|
52
|
+
float a;
|
|
53
|
+
vec3 col;
|
|
54
|
+
if (u_fogColor.w < 0.5) {
|
|
55
|
+
float d = 0.15 + 0.6 * k;
|
|
56
|
+
a = 0.34 * rainLayer(p, vec2(7.0, 70.0) * s, 1500.0 * s, 26.0 * s, 101u, d)
|
|
57
|
+
+ 0.26 * rainLayer(p + 31.0, vec2(5.0, 52.0) * s, 1150.0 * s, 18.0 * s, 102u, d)
|
|
58
|
+
+ 0.18 * rainLayer(p + 57.0, vec2(4.0, 40.0) * s, 850.0 * s, 12.0 * s, 103u, d * 0.8);
|
|
59
|
+
a *= 0.55 + 0.45 * k;
|
|
60
|
+
col = min(u_fogColor.rgb * 1.25 + 0.08, vec3(1.0));
|
|
61
|
+
} else {
|
|
62
|
+
float d = 0.12 + 0.5 * k;
|
|
63
|
+
a = 0.9 * snowLayer(p, 30.0 * s, 95.0 * s, 2.6 * s, 111u, d)
|
|
64
|
+
+ 0.75 * snowLayer(p + 13.0, 22.0 * s, 70.0 * s, 2.0 * s, 112u, d)
|
|
65
|
+
+ 0.55 * snowLayer(p + 29.0, 16.0 * s, 48.0 * s, 1.5 * s, 113u, d);
|
|
66
|
+
col = mix(u_fogColor.rgb, vec3(0.93, 0.93, 0.91), 0.75);
|
|
67
|
+
}
|
|
68
|
+
a = clamp(a, 0.0, 0.9);
|
|
69
|
+
o_color = vec4(col * a, a);
|
|
70
|
+
}`;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { DrawContext, Layer, Renderer } from '../render/index.ts';
|
|
2
|
+
import type { EnvironmentLink } from './environment-link.ts';
|
|
3
|
+
export declare class PrecipitationLayer implements Layer {
|
|
4
|
+
/** Name in profiles (`Layer.name`). */
|
|
5
|
+
readonly name: string;
|
|
6
|
+
private readonly program;
|
|
7
|
+
private readonly link;
|
|
8
|
+
private readonly renderer;
|
|
9
|
+
constructor(renderer: Renderer, link: EnvironmentLink);
|
|
10
|
+
draw(ctx: DrawContext): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// Precipitation layer: rain or snowfall over the whole image in the overlay pass. Wind across the view tilts it.
|
|
2
|
+
// In an orthographic view the fall runs down the screen, sheared by the wind. In a perspective view the screen direction
|
|
3
|
+
// of the fall (with the wind) is projected at the view centre and the pattern is turned to it.
|
|
4
|
+
import { dot } from '../base/math.js';
|
|
5
|
+
import { PRECIP_FS, PRECIP_VS } from './precipitation-glsl.js';
|
|
6
|
+
/** Below this strength nothing is drawn. */
|
|
7
|
+
const MIN_PRECIPITATION = 0.005;
|
|
8
|
+
export class PrecipitationLayer {
|
|
9
|
+
/** Name in profiles (`Layer.name`). */
|
|
10
|
+
name = 'precipitation';
|
|
11
|
+
program;
|
|
12
|
+
link;
|
|
13
|
+
renderer;
|
|
14
|
+
constructor(renderer, link) {
|
|
15
|
+
this.program = renderer.device.program('precipitation', PRECIP_VS, renderer.resolve(PRECIP_FS));
|
|
16
|
+
this.link = link;
|
|
17
|
+
this.renderer = renderer;
|
|
18
|
+
}
|
|
19
|
+
draw(ctx) {
|
|
20
|
+
const E = this.link.frame;
|
|
21
|
+
if (ctx.pass !== 'overlay' || !E || E.precipitation <= MIN_PRECIPITATION)
|
|
22
|
+
return;
|
|
23
|
+
const view = ctx.view;
|
|
24
|
+
const right = view.axes().right;
|
|
25
|
+
const across = E.windX * right[0] + E.windZ * right[2];
|
|
26
|
+
const speed = this.link.env.wind.speedMs;
|
|
27
|
+
// Rain falls fast, wind tilts it less than light flakes.
|
|
28
|
+
const drift = Math.min(0.6, speed * (E.precipitationKind > 0.5 ? 0.09 : 0.035));
|
|
29
|
+
let slant = across * drift;
|
|
30
|
+
let fall = [0, -1];
|
|
31
|
+
if (view.pixelGrowth > 0) {
|
|
32
|
+
const center = this.renderer.upCenter();
|
|
33
|
+
fall = screenFall(view, center ? radialFall(view, center, E.windX, E.windZ, drift) : [E.windX * drift, -1, E.windZ * drift]);
|
|
34
|
+
slant = 0;
|
|
35
|
+
}
|
|
36
|
+
ctx.device.setState({ depthTest: false, blend: { src: 'one', dst: 'one-minus-src-alpha' } });
|
|
37
|
+
ctx.device.use(this.program);
|
|
38
|
+
this.program.float('u_slant', slant);
|
|
39
|
+
this.program.set('u_fall', { vec2: fall });
|
|
40
|
+
this.program.float('u_pxScale', ctx.view.dpr);
|
|
41
|
+
ctx.device.drawFullscreen();
|
|
42
|
+
ctx.count(1);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The motion of the fall under radial up: along the local down at the eye, tilted by the part of the wind that lies
|
|
47
|
+
* across that down.
|
|
48
|
+
*/
|
|
49
|
+
function radialFall(view, center, windX, windZ, drift) {
|
|
50
|
+
const eye = view.cornerRays()[0].origin;
|
|
51
|
+
const ux = eye[0] - center[0], uy = eye[1] - center[1], uz = eye[2] - center[2];
|
|
52
|
+
const len = Math.hypot(ux, uy, uz);
|
|
53
|
+
if (len <= 1e-6)
|
|
54
|
+
return [windX * drift, -1, windZ * drift];
|
|
55
|
+
const down = [-ux / len, -uy / len, -uz / len];
|
|
56
|
+
const along = windX * down[0] + windZ * down[2];
|
|
57
|
+
const wx = windX - down[0] * along, wy = -down[1] * along, wz = windZ - down[2] * along;
|
|
58
|
+
return [down[0] + wx * drift, down[1] + wy * drift, down[2] + wz * drift];
|
|
59
|
+
}
|
|
60
|
+
/** Screen direction (unit, y up) of a world motion seen at the centre of a perspective view. */
|
|
61
|
+
function screenFall(view, motion) {
|
|
62
|
+
const f = view.axes().forward;
|
|
63
|
+
const eye = view.cornerRays()[0].origin;
|
|
64
|
+
const t = view.refDepth - dot(f, eye);
|
|
65
|
+
const c = [eye[0] + f[0] * t, eye[1] + f[1] * t, eye[2] + f[2] * t];
|
|
66
|
+
const m = view.viewProj(c, 1);
|
|
67
|
+
const clip = (p) => {
|
|
68
|
+
const w = m[3] * p[0] + m[7] * p[1] + m[11] * p[2] + m[15];
|
|
69
|
+
return [(m[0] * p[0] + m[4] * p[1] + m[8] * p[2] + m[12]) / w, (m[1] * p[0] + m[5] * p[1] + m[9] * p[2] + m[13]) / w];
|
|
70
|
+
};
|
|
71
|
+
const a = clip(c);
|
|
72
|
+
const b = clip([c[0] + motion[0], c[1] + motion[1], c[2] + motion[2]]);
|
|
73
|
+
const dx = (b[0] - a[0]) * view.width;
|
|
74
|
+
const dy = (b[1] - a[1]) * view.height;
|
|
75
|
+
const len = Math.hypot(dx, dy);
|
|
76
|
+
// Looking straight down the fall has no screen direction; keep the default.
|
|
77
|
+
return len > 1e-6 ? [dx / len, dy / len] : [0, -1];
|
|
78
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { EnvSlot } from '../base/env-slot.ts';
|
|
2
|
+
import type { DrawContext, Layer, Renderer } from '../render/index.ts';
|
|
3
|
+
import type { SkyParams, SkyValues } from '../env/index.ts';
|
|
4
|
+
export declare const SKY_VS = "#version 300 es\nvoid main() {\n vec2 p = vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2));\n gl_Position = vec4(p * 2.0 - 1.0, 1.0, 1.0);\n}";
|
|
5
|
+
export declare const SKY_FS = "#include <header>\n#include <noise>\n#include <sky>\nuniform vec3 u_rayCenter; // view ray through the screen centre, scaled so that its depth along the view is 1\nuniform vec3 u_rayRight; // change of the ray from the centre to the right edge\nuniform vec3 u_rayUp; // change of the ray from the centre to the top edge\nuniform vec2 u_screen; // drawing surface in physical pixels\nout vec4 o_color;\nvoid main() {\n vec2 s = gl_FragCoord.xy / u_screen * 2.0 - 1.0;\n vec3 dir = normalize(u_rayCenter + u_rayRight * s.x + u_rayUp * s.y);\n o_color = vec4(skyView(dir), 1.0);\n}";
|
|
6
|
+
export declare class SkyLayer implements Layer {
|
|
7
|
+
readonly name = "sky";
|
|
8
|
+
readonly slot: EnvSlot<SkyParams, SkyValues>;
|
|
9
|
+
/**
|
|
10
|
+
* Draw only where nothing was drawn yet (see the top of this file). Default false: the sky covers the whole screen
|
|
11
|
+
* and must be the first layer. True: put the layer after the opaque layers and before the transparent ones.
|
|
12
|
+
*/
|
|
13
|
+
behindScene: boolean;
|
|
14
|
+
private readonly renderer;
|
|
15
|
+
private readonly program;
|
|
16
|
+
private behindProgram;
|
|
17
|
+
/** Scratch, so a frame allocates nothing here. */
|
|
18
|
+
private readonly axes;
|
|
19
|
+
private readonly rays;
|
|
20
|
+
private readonly eye;
|
|
21
|
+
/** The slot must be part of the renderer's Frame block (and its `EnvironmentLink`), so `<sky>` is the real one. */
|
|
22
|
+
constructor(renderer: Renderer, slot: EnvSlot<SkyParams, SkyValues>);
|
|
23
|
+
/**
|
|
24
|
+
* The program of the sky behind the scene, made at its first use: the triangle at the far end of the depth range
|
|
25
|
+
* of the renderer's depth mode. In the logarithmic mode the fragment shader is not wrapped (it would write a near
|
|
26
|
+
* depth); the pipeline's depth of the far end is used instead.
|
|
27
|
+
*/
|
|
28
|
+
private behind;
|
|
29
|
+
draw(ctx: DrawContext): void;
|
|
30
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// Sky layer: one triangle across the screen, drawn first in the colour pass, that computes the sky per pixel from the
|
|
2
|
+
// view ray (`skyView` from the include `<sky>`). Only perspective views see a sky; an orthographic view draws nothing
|
|
3
|
+
// here and keeps the plain background. Every frame it hands the view's eye to the sky slot, which carries it into the
|
|
4
|
+
// Frame block for the haze on distant geometry (`aerialPerspective`).
|
|
5
|
+
//
|
|
6
|
+
// Behind the scene (`behindScene`, default off): the same triangle is drawn later in the colour pass, at the far end
|
|
7
|
+
// of the depth range with the depth test on and without writing depth, so the sky is computed only for the pixels and
|
|
8
|
+
// samples nothing has covered yet instead of for the whole screen before the scene overdraws most of it. Every
|
|
9
|
+
// covered sample keeps its colour and every uncovered one gets the colour it got before, so the image is the same as
|
|
10
|
+
// long as the layers drawn before the sky are opaque (they write depth where they draw). Move the layer behind them
|
|
11
|
+
// with `Engine.moveSkyBefore`.
|
|
12
|
+
import { newCornerRays, newOrthoFrame } from '../base/view.js';
|
|
13
|
+
export const SKY_VS = /* glsl */ `#version 300 es
|
|
14
|
+
void main() {
|
|
15
|
+
vec2 p = vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2));
|
|
16
|
+
gl_Position = vec4(p * 2.0 - 1.0, 1.0, 1.0);
|
|
17
|
+
}`;
|
|
18
|
+
export const SKY_FS = /* glsl */ `#include <header>
|
|
19
|
+
#include <noise>
|
|
20
|
+
#include <sky>
|
|
21
|
+
uniform vec3 u_rayCenter; // view ray through the screen centre, scaled so that its depth along the view is 1
|
|
22
|
+
uniform vec3 u_rayRight; // change of the ray from the centre to the right edge
|
|
23
|
+
uniform vec3 u_rayUp; // change of the ray from the centre to the top edge
|
|
24
|
+
uniform vec2 u_screen; // drawing surface in physical pixels
|
|
25
|
+
out vec4 o_color;
|
|
26
|
+
void main() {
|
|
27
|
+
vec2 s = gl_FragCoord.xy / u_screen * 2.0 - 1.0;
|
|
28
|
+
vec3 dir = normalize(u_rayCenter + u_rayRight * s.x + u_rayUp * s.y);
|
|
29
|
+
o_color = vec4(skyView(dir), 1.0);
|
|
30
|
+
}`;
|
|
31
|
+
/** Draw state of the sky behind the scene: only where the depth is still the far end, depth kept as it is. */
|
|
32
|
+
const BEHIND_STATE = { depthTest: true, depthFunc: 'lequal', depthWrite: false, cullBack: false };
|
|
33
|
+
const FIRST_STATE = { depthTest: false, depthWrite: false, cullBack: false };
|
|
34
|
+
export class SkyLayer {
|
|
35
|
+
name = 'sky';
|
|
36
|
+
slot;
|
|
37
|
+
/**
|
|
38
|
+
* Draw only where nothing was drawn yet (see the top of this file). Default false: the sky covers the whole screen
|
|
39
|
+
* and must be the first layer. True: put the layer after the opaque layers and before the transparent ones.
|
|
40
|
+
*/
|
|
41
|
+
behindScene = false;
|
|
42
|
+
renderer;
|
|
43
|
+
program;
|
|
44
|
+
behindProgram = null;
|
|
45
|
+
/** Scratch, so a frame allocates nothing here. */
|
|
46
|
+
axes = newOrthoFrame();
|
|
47
|
+
rays = newCornerRays();
|
|
48
|
+
eye = [0, 0, 0];
|
|
49
|
+
/** The slot must be part of the renderer's Frame block (and its `EnvironmentLink`), so `<sky>` is the real one. */
|
|
50
|
+
constructor(renderer, slot) {
|
|
51
|
+
this.slot = slot;
|
|
52
|
+
this.renderer = renderer;
|
|
53
|
+
this.program = renderer.device.program('sky', SKY_VS, renderer.resolve(SKY_FS));
|
|
54
|
+
// Before the environment is packed, so the eye of this frame's view goes into this frame's block.
|
|
55
|
+
renderer.beforeFrame.unshift((view) => {
|
|
56
|
+
if (view.pixelGrowth <= 0) {
|
|
57
|
+
slot.params.eye = null;
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const o = view.cornerRays(this.rays)[0].origin;
|
|
61
|
+
const e = this.eye;
|
|
62
|
+
e[0] = o[0];
|
|
63
|
+
e[1] = o[1];
|
|
64
|
+
e[2] = o[2];
|
|
65
|
+
slot.params.eye = e;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The program of the sky behind the scene, made at its first use: the triangle at the far end of the depth range
|
|
70
|
+
* of the renderer's depth mode. In the logarithmic mode the fragment shader is not wrapped (it would write a near
|
|
71
|
+
* depth); the pipeline's depth of the far end is used instead.
|
|
72
|
+
*/
|
|
73
|
+
behind() {
|
|
74
|
+
if (this.behindProgram)
|
|
75
|
+
return this.behindProgram;
|
|
76
|
+
const r = this.renderer;
|
|
77
|
+
const far = r.depthMode === 'reversed' ? '0.0' : '1.0';
|
|
78
|
+
const vs = SKY_VS.replace('gl_Position = vec4(p * 2.0 - 1.0, 1.0, 1.0);', `gl_Position = vec4(p * 2.0 - 1.0, ${far}, 1.0);`);
|
|
79
|
+
this.behindProgram = r.device.program('sky behind', vs, r.resolve(SKY_FS, r.depthMode === 'logarithmic' ? 'other' : 'main'));
|
|
80
|
+
return this.behindProgram;
|
|
81
|
+
}
|
|
82
|
+
draw(ctx) {
|
|
83
|
+
const view = ctx.view;
|
|
84
|
+
if (ctx.pass !== 'color' || view.pixelGrowth <= 0)
|
|
85
|
+
return;
|
|
86
|
+
const f = view.axes(this.axes).forward;
|
|
87
|
+
// Corner rays: left-bottom, left-top, right-bottom, right-top. Scaled to depth 1 they interpolate linearly across the screen.
|
|
88
|
+
const rays = view.cornerRays(this.rays);
|
|
89
|
+
const lb = rays[0].dir;
|
|
90
|
+
const lt = rays[1].dir;
|
|
91
|
+
const rb = rays[2].dir;
|
|
92
|
+
const klb = 1 / (lb[0] * f[0] + lb[1] * f[1] + lb[2] * f[2]);
|
|
93
|
+
const klt = 1 / (lt[0] * f[0] + lt[1] * f[1] + lt[2] * f[2]);
|
|
94
|
+
const krb = 1 / (rb[0] * f[0] + rb[1] * f[1] + rb[2] * f[2]);
|
|
95
|
+
const lb0 = lb[0] * klb;
|
|
96
|
+
const lb1 = lb[1] * klb;
|
|
97
|
+
const lb2 = lb[2] * klb;
|
|
98
|
+
const rx = (rb[0] * krb - lb0) / 2;
|
|
99
|
+
const ry = (rb[1] * krb - lb1) / 2;
|
|
100
|
+
const rz = (rb[2] * krb - lb2) / 2;
|
|
101
|
+
const ux = (lt[0] * klt - lb0) / 2;
|
|
102
|
+
const uy = (lt[1] * klt - lb1) / 2;
|
|
103
|
+
const uz = (lt[2] * klt - lb2) / 2;
|
|
104
|
+
const program = this.behindScene ? this.behind() : this.program;
|
|
105
|
+
ctx.device.setState(this.behindScene ? BEHIND_STATE : FIRST_STATE);
|
|
106
|
+
ctx.device.use(program);
|
|
107
|
+
program.vec3('u_rayCenter', lb0 + rx + ux, lb1 + ry + uy, lb2 + rz + uz);
|
|
108
|
+
program.vec3('u_rayRight', rx, ry, rz);
|
|
109
|
+
program.vec3('u_rayUp', ux, uy, uz);
|
|
110
|
+
program.vec2('u_screen', view.width, view.height);
|
|
111
|
+
ctx.device.drawFullscreen();
|
|
112
|
+
ctx.count(1);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import type { MeshData } from '../base/data.ts';
|
|
2
|
+
import type { Uniforms } from '../base/material.ts';
|
|
3
|
+
import type { Vec3 } from '../base/math.ts';
|
|
4
|
+
import type { CullVolume, OriginAxes } from '../base/view.ts';
|
|
5
|
+
import type { CellContent, CellId, WorldPos } from '../gen-core/cell.ts';
|
|
6
|
+
import type { Mesh, Texture } from '../gpu/index.ts';
|
|
7
|
+
import type { DrawContext, Layer, Material, Renderer } from '../render/index.ts';
|
|
8
|
+
import type { CellProvider, CellResult, StreamingConfig, StreamingCounters, Ticket } from '../world/index.ts';
|
|
9
|
+
import { StreamingManager } from '../world/index.ts';
|
|
10
|
+
import type { CellEdits, CellGenerator, EditableCellGenerator } from '../world/index.ts';
|
|
11
|
+
import { WorkerPool } from '../platform/index.ts';
|
|
12
|
+
/** A shape drawn many times: one material and a level-of-detail chain, finest first. */
|
|
13
|
+
export interface StreamArchetype {
|
|
14
|
+
material: string;
|
|
15
|
+
/** Each mesh is used while the cell is at most `maxDistance` metres from the eye; beyond the last, nothing is drawn. */
|
|
16
|
+
lods: readonly {
|
|
17
|
+
mesh: MeshData;
|
|
18
|
+
maxDistance: number;
|
|
19
|
+
}[];
|
|
20
|
+
}
|
|
21
|
+
export interface StreamedWorldOptions {
|
|
22
|
+
renderer: Renderer;
|
|
23
|
+
config: StreamingConfig;
|
|
24
|
+
provider: CellProvider;
|
|
25
|
+
/**
|
|
26
|
+
* Materials by the names cell meshes and archetypes use. Programs read `u_cellOffset` (vec3, cell origin minus
|
|
27
|
+
* render origin) and may read `u_cellLevel` (float, the cell's quadtree level).
|
|
28
|
+
*/
|
|
29
|
+
materials: Readonly<Record<string, Material>>;
|
|
30
|
+
archetypes?: Readonly<Record<string, StreamArchetype>>;
|
|
31
|
+
/** Grid the render origin snaps to, in metres. Default 1,024 m. */
|
|
32
|
+
originGridM?: number;
|
|
33
|
+
/**
|
|
34
|
+
* Axes on which the render origin follows the focus. `'horizontal'` (default): x and z, its height stays 0, which
|
|
35
|
+
* is exact enough while the viewer stays within a few kilometres of height 0. `'all'`: the height too, so the
|
|
36
|
+
* numbers the GPU sees stay small at any height (and anywhere round a sphere). Heights handed to anything that
|
|
37
|
+
* works in render space (the view, fog, clouds) then need `origin[1]` subtracted.
|
|
38
|
+
*/
|
|
39
|
+
originAxes?: OriginAxes;
|
|
40
|
+
/** Upload time per frame in ms (at least one cell per frame is uploaded). Default 3. */
|
|
41
|
+
uploadMsPerFrame?: number;
|
|
42
|
+
/** Main-thread generation time per frame in ms, for blocking providers (at least one job per frame). Default 6. */
|
|
43
|
+
blockingMsPerFrame?: number;
|
|
44
|
+
/** Called when streaming work wants another frame (a job finished, or more is waiting). */
|
|
45
|
+
onActivity?: () => void;
|
|
46
|
+
/** Wall clock for the budgets only (ms). Default `performance.now`. */
|
|
47
|
+
now?: () => number;
|
|
48
|
+
/**
|
|
49
|
+
* Blend between levels of detail. When on, every program also gets `u_morphEye` (vec4: the viewer in render space
|
|
50
|
+
* and its altitude), `u_morphUp` (vec3) and, per cell, `u_cellMorph` (vec2: where the blend into the parent's shape
|
|
51
|
+
* starts and 1 / its length; 0, 0 for a cell with nothing to blend into). Materials read them through
|
|
52
|
+
* `CELL_MORPH_GLSL` of gen-mesh. Shadows are redrawn when the viewer has moved far enough to change the blend.
|
|
53
|
+
* Default off: none of these uniforms is set.
|
|
54
|
+
*/
|
|
55
|
+
morph?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Culling by the horizon of a sphere: a cell that the sphere's own bulge hides from the eye is left out of the
|
|
58
|
+
* view's draws (the shadow pass keeps it). `center` is the sphere's centre in world metres. `radiusM` is the radius
|
|
59
|
+
* of the sphere that hides; it must lie under everything that is drawn, so give the base radius plus the lowest
|
|
60
|
+
* height the content has (a larger one cuts holes at the horizon). Uses the eye of `setEye`.
|
|
61
|
+
* Default: unset, no cell is hidden this way.
|
|
62
|
+
*/
|
|
63
|
+
horizon?: {
|
|
64
|
+
center: WorldPos;
|
|
65
|
+
radiusM: number;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Textures per material name, by sampler name: bound to the units after the shadow map before the material's cells
|
|
69
|
+
* are drawn. The record stays reachable as `StreamedWorld.textures` and may be changed at any time.
|
|
70
|
+
*/
|
|
71
|
+
textures?: Record<string, Record<string, Texture | null>>;
|
|
72
|
+
/** Uniforms per material name, set after the shared `uniforms`. Reachable as `StreamedWorld.materialUniforms`. */
|
|
73
|
+
materialUniforms?: Record<string, Uniforms>;
|
|
74
|
+
/**
|
|
75
|
+
* Ceiling of GPU memory in bytes, measured on the device (`Device.memory().total`: everything the page holds, not
|
|
76
|
+
* only the cells). Over it, the manager takes cells off the GPU, least recently wanted first, and holds uploads
|
|
77
|
+
* back (`StreamingConfig.gpuBudgetBytes`, which this sets). Default off.
|
|
78
|
+
*/
|
|
79
|
+
gpuCeilingBytes?: number;
|
|
80
|
+
/** A cell was uploaded: its meshes on the GPU in the order of `content.meshes`. */
|
|
81
|
+
onResident?: (cell: CellId, meshes: readonly {
|
|
82
|
+
material: Material;
|
|
83
|
+
mesh: Mesh;
|
|
84
|
+
}[], content: CellContent) => void;
|
|
85
|
+
/** A cell left the GPU (its meshes are deleted). */
|
|
86
|
+
onReleased?: (cell: CellId) => void;
|
|
87
|
+
}
|
|
88
|
+
export interface StreamedWorldStats extends StreamingCounters {
|
|
89
|
+
/** Cells kept by the last view culling, and draw calls and triangles this layer issued in the last colour pass. */
|
|
90
|
+
cellsVisible: number;
|
|
91
|
+
drawCalls: number;
|
|
92
|
+
triangles: number;
|
|
93
|
+
instances: number;
|
|
94
|
+
/** Last frame: upload and main-thread generation time, and how many cells each handled. */
|
|
95
|
+
uploadMs: number;
|
|
96
|
+
uploads: number;
|
|
97
|
+
blockingMs: number;
|
|
98
|
+
blockingJobs: number;
|
|
99
|
+
/** Average generation time of one cell, measured where it ran (worker or main thread). */
|
|
100
|
+
generateMsAvg: number;
|
|
101
|
+
/** Average upload time of one cell. */
|
|
102
|
+
uploadMsAvg: number;
|
|
103
|
+
renderOrigin: WorldPos;
|
|
104
|
+
/** Cells refused because they were built for another world shape (their jobs count as failed). */
|
|
105
|
+
shapeMismatches: number;
|
|
106
|
+
/** Cells the last view culling left out because they lie behind the horizon (0 without the `horizon` option). */
|
|
107
|
+
horizonCulled: number;
|
|
108
|
+
}
|
|
109
|
+
export declare class StreamedWorld implements Layer {
|
|
110
|
+
/** Name in profiles (`Layer.name`). */
|
|
111
|
+
readonly name: string;
|
|
112
|
+
readonly manager: StreamingManager;
|
|
113
|
+
readonly renderer: Renderer;
|
|
114
|
+
readonly provider: CellProvider;
|
|
115
|
+
/** Render-space origin in world metres (double); x and z snap to the grid, y is 0 unless `originAxes` is `'all'`. */
|
|
116
|
+
origin: WorldPos;
|
|
117
|
+
/** Textures and uniforms per material name (see the options of the same names). */
|
|
118
|
+
textures: Record<string, Record<string, Texture | null>>;
|
|
119
|
+
materialUniforms: Record<string, Uniforms>;
|
|
120
|
+
private readonly gpuCeiling;
|
|
121
|
+
private readonly onResident;
|
|
122
|
+
private readonly onReleased;
|
|
123
|
+
/** Uniforms set for every material before its cells are drawn. */
|
|
124
|
+
uniforms: Uniforms;
|
|
125
|
+
private readonly materials;
|
|
126
|
+
private readonly archetypes;
|
|
127
|
+
private readonly grid;
|
|
128
|
+
private readonly originAxes;
|
|
129
|
+
private readonly uploadMs;
|
|
130
|
+
private readonly blockingMs;
|
|
131
|
+
private readonly onActivity;
|
|
132
|
+
private readonly now;
|
|
133
|
+
private tickets;
|
|
134
|
+
private readonly cpu;
|
|
135
|
+
private readonly gpu;
|
|
136
|
+
private readonly running;
|
|
137
|
+
private readonly blocking;
|
|
138
|
+
private readonly arrived;
|
|
139
|
+
private readonly failedJobs;
|
|
140
|
+
private pendingUploads;
|
|
141
|
+
private drawList;
|
|
142
|
+
private drawKey;
|
|
143
|
+
private viewList;
|
|
144
|
+
private shadowList;
|
|
145
|
+
private eye;
|
|
146
|
+
private eyeWorld;
|
|
147
|
+
private readonly horizon;
|
|
148
|
+
private horizonCulled;
|
|
149
|
+
private frame;
|
|
150
|
+
private totals;
|
|
151
|
+
private readonly undo;
|
|
152
|
+
private readonly morph;
|
|
153
|
+
/** Hash of the manager's world shape; a cell that states another one is refused. */
|
|
154
|
+
private readonly shape;
|
|
155
|
+
private shapeMismatches;
|
|
156
|
+
constructor(o: StreamedWorldOptions);
|
|
157
|
+
/**
|
|
158
|
+
* Forgets every GPU object of the cells without deleting it and has the manager list the cells for upload again
|
|
159
|
+
* (from the CPU data this layer keeps). For a fresh graphics context after a loss, on a device that did not keep
|
|
160
|
+
* the uploads; the cover fills in again within the upload budget of the next frames.
|
|
161
|
+
*/
|
|
162
|
+
reupload(): void;
|
|
163
|
+
/**
|
|
164
|
+
* Moves the render origin to the grid point at or below `p` (x and z; y too with `originAxes: 'all'`), and sets the
|
|
165
|
+
* renderer's world origin.
|
|
166
|
+
*/
|
|
167
|
+
setFocus(p: WorldPos): void;
|
|
168
|
+
/** World position (double) → render space (small numbers). */
|
|
169
|
+
toRender(p: WorldPos): Vec3;
|
|
170
|
+
/** Render space → world position (double). */
|
|
171
|
+
toWorld(p: readonly [number, number, number]): WorldPos;
|
|
172
|
+
/** The reasons to load for the coming frames. */
|
|
173
|
+
setTickets(tickets: readonly Ticket[]): void;
|
|
174
|
+
/** Eye position in world metres, for level-of-detail choice of instances. */
|
|
175
|
+
setEye(p: WorldPos): void;
|
|
176
|
+
/** True when every wanted cell is on the GPU and drawn, and no upload waits. */
|
|
177
|
+
get settled(): boolean;
|
|
178
|
+
/** True while jobs run or wait, or uploads wait. */
|
|
179
|
+
get busy(): boolean;
|
|
180
|
+
stats(): StreamedWorldStats;
|
|
181
|
+
/** Adds generation time measured elsewhere (a worker pool) to the average. */
|
|
182
|
+
recordGeneration(ms: number, jobs: number): void;
|
|
183
|
+
/** One streaming step. Runs at the start of every rendered frame (renderer.beforeFrame). */
|
|
184
|
+
step(): void;
|
|
185
|
+
/** Accepts a finished job (stale results are dropped by the manager). */
|
|
186
|
+
private accept;
|
|
187
|
+
/** Replaces the GPU data of a RESIDENT cell; it stays drawn, the frame that follows shows the new content. */
|
|
188
|
+
private swap;
|
|
189
|
+
/**
|
|
190
|
+
* The content of these cells is out of date (`StreamingManager.refresh`): cells on the GPU stay drawn and are
|
|
191
|
+
* swapped when their new content arrives, other loaded cells are built again when wanted. Returns how many tracked
|
|
192
|
+
* cells it touched.
|
|
193
|
+
*/
|
|
194
|
+
refresh(cells: Iterable<CellId>): number;
|
|
195
|
+
/** The viewer and the blend ranges for one draw, from the manager's last step. */
|
|
196
|
+
private morphFrame;
|
|
197
|
+
/**
|
|
198
|
+
* Changes when the viewer has moved far enough to change the blended shape visibly: its position and altitude in
|
|
199
|
+
* steps of 1/16 of the finest drawn cell's blend length. Part of the key that decides when shadows are redrawn.
|
|
200
|
+
*/
|
|
201
|
+
private morphKey;
|
|
202
|
+
private start;
|
|
203
|
+
private upload;
|
|
204
|
+
private release;
|
|
205
|
+
/** Render-space box of a drawn cell. */
|
|
206
|
+
private box;
|
|
207
|
+
private sceneBounds;
|
|
208
|
+
cull(volume: CullVolume, purpose: 'shadow' | 'view'): number;
|
|
209
|
+
draw(ctx: DrawContext): void;
|
|
210
|
+
/** Releases every GPU resource, aborts jobs and detaches from the renderer. */
|
|
211
|
+
dispose(): void;
|
|
212
|
+
}
|
|
213
|
+
/** Tickets for a viewer: one at the eye, and one at the predicted point ahead when it moves (design: `predict`). */
|
|
214
|
+
export declare function viewTickets(eye: WorldPos, altitude: number, forward: readonly [number, number], velocity?: readonly [number, number], lookAheadS?: number): Ticket[];
|
|
215
|
+
/**
|
|
216
|
+
* Tickets for a viewer on any world shape: as `viewTickets`, with the directions as world vectors and, for selection
|
|
217
|
+
* by screen-space error, the pixels one radian covers on the viewer's screen (`pixelsPerRadian` of world).
|
|
218
|
+
*/
|
|
219
|
+
export declare function viewerTickets(o: {
|
|
220
|
+
eye: WorldPos;
|
|
221
|
+
/** Height of the eye above the surface under it. */
|
|
222
|
+
altitude: number;
|
|
223
|
+
forward: readonly [number, number, number];
|
|
224
|
+
velocity?: readonly [number, number, number];
|
|
225
|
+
lookAheadS?: number;
|
|
226
|
+
pixelsPerRadian?: number;
|
|
227
|
+
}): Ticket[];
|
|
228
|
+
/** Generator provider running in a pool of module workers. The worker script calls `serveCellGenerator`. */
|
|
229
|
+
export declare class WorkerCellProvider implements CellProvider {
|
|
230
|
+
readonly name: string;
|
|
231
|
+
readonly blocking = false;
|
|
232
|
+
readonly pool: WorkerPool;
|
|
233
|
+
readonly seed: number;
|
|
234
|
+
private readonly edits;
|
|
235
|
+
/** With `edits`, the edits text of a cell travels with its job when it is not empty (read when the request starts). */
|
|
236
|
+
constructor(workerUrl: URL | string, seed: number, size?: number, edits?: CellEdits);
|
|
237
|
+
request(cell: CellId, signal: AbortSignal): Promise<CellResult>;
|
|
238
|
+
dispose(): void;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Inside a worker script: generates and encodes cells for `WorkerCellProvider`; the bytes are transferred. A job
|
|
242
|
+
* that carries edits text hands it to the generator as the third argument.
|
|
243
|
+
*/
|
|
244
|
+
export declare function serveCellGenerator(generate: CellGenerator): void;
|
|
245
|
+
export declare function serveCellGenerator(generate: EditableCellGenerator): void;
|