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,151 @@
|
|
|
1
|
+
// Terrain: colour from the baked ground texture, fine grain up close, shadows. The vertical cut along the perimeter is bare earth.
|
|
2
|
+
// The same shader in a second variant draws horizontal markings (crossings, lines): the marking mesh follows the terrain cells,
|
|
3
|
+
// so it sits exactly on the surface and gets the same light, shadow, snow, wetness and fog as the ground below it.
|
|
4
|
+
export const TERRAIN_VS = /* glsl */ `#include <header>
|
|
5
|
+
invariant gl_Position;
|
|
6
|
+
in vec3 a_pos;
|
|
7
|
+
in vec4 a_normal;
|
|
8
|
+
out vec3 v_world;
|
|
9
|
+
out vec3 v_normal;
|
|
10
|
+
flat out float v_kind;
|
|
11
|
+
void main() {
|
|
12
|
+
v_world = a_pos;
|
|
13
|
+
v_normal = a_normal.xyz;
|
|
14
|
+
v_kind = a_normal.w;
|
|
15
|
+
gl_Position = u_viewProj * vec4(a_pos, 1.0);
|
|
16
|
+
}`;
|
|
17
|
+
/** Marking vertices: position and normal as terrain, plus coordinates in the shape and its parameters. */
|
|
18
|
+
export const MARKING_VS = /* glsl */ `#include <header>
|
|
19
|
+
invariant gl_Position;
|
|
20
|
+
in vec3 a_pos;
|
|
21
|
+
in vec4 a_normal;
|
|
22
|
+
in vec2 a_uv;
|
|
23
|
+
in vec4 a_size;
|
|
24
|
+
in vec4 a_paint;
|
|
25
|
+
in vec2 a_pattern;
|
|
26
|
+
out vec3 v_world;
|
|
27
|
+
out vec3 v_normal;
|
|
28
|
+
out vec2 v_uv;
|
|
29
|
+
flat out vec4 v_size;
|
|
30
|
+
flat out vec4 v_paint;
|
|
31
|
+
flat out vec2 v_pattern;
|
|
32
|
+
void main() {
|
|
33
|
+
v_world = a_pos;
|
|
34
|
+
v_normal = a_normal.xyz;
|
|
35
|
+
v_uv = a_uv;
|
|
36
|
+
v_size = a_size;
|
|
37
|
+
v_paint = a_paint;
|
|
38
|
+
v_pattern = a_pattern;
|
|
39
|
+
gl_Position = u_viewProj * vec4(a_pos, 1.0);
|
|
40
|
+
}`;
|
|
41
|
+
const MARKING_COVER = /* glsl */ `
|
|
42
|
+
in vec2 v_uv; // x along the shape from its start (m), y across from the axis (m)
|
|
43
|
+
flat in vec4 v_size; // x length, y width, z stripe period, w share of colour in the period
|
|
44
|
+
flat in vec4 v_paint; // rgb colour, a wear 0–1
|
|
45
|
+
flat in vec2 v_pattern; // x pattern (0 solid, 1 stripes along the length, 2 outline), y outline line width
|
|
46
|
+
const float v_kind = 0.0;
|
|
47
|
+
|
|
48
|
+
// Integral of a rectangular wave (1 at the start of each period for the duration of duty).
|
|
49
|
+
float squareInt(float t, float duty) { return floor(t) * duty + min(fract(t), duty); }
|
|
50
|
+
// Stripes averaged over the pixel footprint: sharp up close, blending into the average from afar and not flickering.
|
|
51
|
+
float stripes(float t, float w, float duty) {
|
|
52
|
+
w = max(w, 1e-4);
|
|
53
|
+
return (squareInt(t + 0.5 * w, duty) - squareInt(t - 0.5 * w, duty)) / w;
|
|
54
|
+
}
|
|
55
|
+
// Exact overlap of the interval [-h, h] with a pixel footprint of width fw centred at x, divided by fw.
|
|
56
|
+
// For wide shapes this is the usual anti-aliased edge; a line thinner than a pixel fades to its true share
|
|
57
|
+
// instead of staying half-covered and flickering with the pixel centre.
|
|
58
|
+
float boxCover(float x, float h, float fw) { return clamp((min(h, x + 0.5 * fw) - max(-h, x - 0.5 * fw)) / fw, 0.0, 1.0); }
|
|
59
|
+
float markingCover(vec2 w) {
|
|
60
|
+
vec2 fw = max(fwidth(v_uv), vec2(1e-4));
|
|
61
|
+
float du = min(v_uv.x, v_size.x - v_uv.x);
|
|
62
|
+
float dv = 0.5 * v_size.y - abs(v_uv.y);
|
|
63
|
+
float cov = boxCover(v_uv.x - 0.5 * v_size.x, 0.5 * v_size.x, fw.x) * boxCover(v_uv.y, 0.5 * v_size.y, fw.y);
|
|
64
|
+
if (v_pattern.x > 0.5 && v_pattern.x < 1.5) cov *= stripes(v_uv.x / v_size.z, fw.x / v_size.z, v_size.w);
|
|
65
|
+
else if (v_pattern.x > 1.5) cov *= 1.0 - clamp((min(du, dv) - v_pattern.y) / max(fw.x, fw.y) + 0.5, 0.0, 1.0);
|
|
66
|
+
// Wear: the paint is rubbed off in places. The fine component vanishes before it would be smaller than a pixel.
|
|
67
|
+
float n = 0.6 * vnoise(w / 0.7, 61u) + 0.4 * mix(0.5, vnoise(w / 0.16, 62u), detailVisible(0.16));
|
|
68
|
+
cov *= 1.0 - 0.9 * v_paint.a * smoothstep(0.4, 0.75, n);
|
|
69
|
+
return cov;
|
|
70
|
+
}
|
|
71
|
+
`;
|
|
72
|
+
function terrainFs(marking) {
|
|
73
|
+
return /* glsl */ `#include <header>
|
|
74
|
+
#include <noise>
|
|
75
|
+
#include <lighting>
|
|
76
|
+
#include <snow>
|
|
77
|
+
${marking ? MARKING_COVER : ''}
|
|
78
|
+
uniform sampler2D u_ground;
|
|
79
|
+
// Surface kind from the ground bake: r vegetation, g paved area (0.6) and roadway (1), b under canopy, a water.
|
|
80
|
+
uniform sampler2D u_surface;
|
|
81
|
+
uniform vec2 u_invWorldSize;
|
|
82
|
+
uniform vec3 u_earth;
|
|
83
|
+
uniform float u_topY;
|
|
84
|
+
in vec3 v_world;
|
|
85
|
+
in vec3 v_normal;
|
|
86
|
+
${marking ? '' : 'flat in float v_kind;'}
|
|
87
|
+
out vec4 o_color;
|
|
88
|
+
|
|
89
|
+
void main() {
|
|
90
|
+
vec3 n = normalize(v_normal);
|
|
91
|
+
vec3 col;
|
|
92
|
+
float sun = 1.0;
|
|
93
|
+
float mark = 1.0;
|
|
94
|
+
float puddle = 0.0;
|
|
95
|
+
float wetK = 0.0;
|
|
96
|
+
if (v_kind > 0.5) {
|
|
97
|
+
// Cut: horizontal layers, darkening downward.
|
|
98
|
+
float along = dot(v_world.xz, vec2(-n.z, n.x));
|
|
99
|
+
float strata = vnoise(vec2(along * 0.03, v_world.y * 0.55), 5u);
|
|
100
|
+
float depth = clamp((u_topY - v_world.y) / 40.0, 0.0, 1.0);
|
|
101
|
+
col = u_earth * (0.72 + 0.3 * strata) * (1.0 - 0.45 * depth);
|
|
102
|
+
} else {
|
|
103
|
+
vec2 uv = v_world.xz * u_invWorldSize;
|
|
104
|
+
vec4 g = texture(u_ground, uv);
|
|
105
|
+
vec4 surf = texture(u_surface, uv);
|
|
106
|
+
col = g.rgb;
|
|
107
|
+
// Grain at two scales, anchored in the world. Each vanishes before it would be smaller than a pixel.
|
|
108
|
+
float fine = (vnoise(v_world.xz / 0.22, 21u) - 0.5) * detailVisible(0.22);
|
|
109
|
+
float mid = (vnoise(v_world.xz / 0.9, 22u) - 0.5) * detailVisible(0.9);
|
|
110
|
+
col *= 1.0 + g.a * (0.34 * fine + 0.2 * mid);
|
|
111
|
+
${marking
|
|
112
|
+
? ` // Marking: colour instead of ground, with weaker grain. Transparency carries the coverage of the shape.
|
|
113
|
+
mark = markingCover(v_world.xz);
|
|
114
|
+
if (mark < 0.004) discard;
|
|
115
|
+
col = v_paint.rgb * (1.0 + 0.5 * g.a * (0.34 * fine + 0.2 * mid));`
|
|
116
|
+
: ''}
|
|
117
|
+
|
|
118
|
+
// Season: grass outside the growing season fades to straw, is fresher in spring. Leaves lie under broadleaves.
|
|
119
|
+
float lum = dot(col, vec3(0.3, 0.5, 0.2));
|
|
120
|
+
col = mix(col, lum * vec3(1.24, 1.04, 0.7), surf.r * u_season.w * 0.72);
|
|
121
|
+
col = mix(col, col * vec3(1.04, 1.1, 0.88), surf.r * u_season.z * 0.8);
|
|
122
|
+
float litter = surf.b * (1.0 - u_season.x) * smoothstep(0.3, 0.6, vnoise(v_world.xz / 1.3, 23u) + 0.25);
|
|
123
|
+
col = mix(col, lum * vec3(1.4, 0.92, 0.58), litter * 0.6);
|
|
124
|
+
|
|
125
|
+
// Wetness: asphalt and paving darken, puddles stand in depressions. Grass darkens only a little.
|
|
126
|
+
float paved = smoothstep(0.3, 0.5, surf.g);
|
|
127
|
+
float road = smoothstep(0.75, 0.95, surf.g);
|
|
128
|
+
wetK = u_weather.y * paved;
|
|
129
|
+
col *= 1.0 - 0.4 * wetK - 0.1 * u_weather.y * surf.r;
|
|
130
|
+
float pn = 0.6 * vnoise(v_world.xz / 1.1, 91u) + 0.4 * vnoise(v_world.xz / 0.35, 92u);
|
|
131
|
+
puddle = wetK * smoothstep(0.72, 0.78, pn + 0.06 * u_weather.y) * (1.0 - surf.a) * mix(0.35, 1.0, detailVisible(0.35));
|
|
132
|
+
|
|
133
|
+
// Snow: it is cleared from roadways first, from pavements and yards a bit later, less falls under canopies,
|
|
134
|
+
// it does not lie on water. A cleared roadway is dark and wet.
|
|
135
|
+
float snow = snowOn(v_world, n, -0.32 * paved - 0.62 * road - 0.22 * surf.b) * (1.0 - surf.a);
|
|
136
|
+
float slush = u_weather.x * road * (1.0 - snow);
|
|
137
|
+
col *= 1.0 - 0.25 * slush;
|
|
138
|
+
wetK = max(wetK, 0.6 * slush);
|
|
139
|
+
col = mix(col, u_snow.rgb * (0.96 + 0.1 * fine), snow);
|
|
140
|
+
puddle *= 1.0 - snow;
|
|
141
|
+
sun = sunVisibility(v_world, n, 1.2);
|
|
142
|
+
}
|
|
143
|
+
vec3 c = toDisplay(col * u_warmTint.rgb * lightOn(n, sun, 1.0));
|
|
144
|
+
// Puddle reflects the sky, a wet surface gleams slightly.
|
|
145
|
+
c = mix(c, u_fogColor.rgb * 0.85, puddle * 0.32);
|
|
146
|
+
c += wetK * 0.035 * u_fogColor.rgb;
|
|
147
|
+
o_color = vec4(applyFog(c, v_world), ${marking ? 'mark' : '1.0'});
|
|
148
|
+
}`;
|
|
149
|
+
}
|
|
150
|
+
export const TERRAIN_FS = terrainFs(false);
|
|
151
|
+
export const MARKING_FS = terrainFs(true);
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import type { Vec3 } from '../base/math.ts';
|
|
2
|
+
import type { MeshBuilder } from './mesh-builder.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Which surface of a shape a vertex belongs to: the main surface, the cap at its start or end, or a cut plane (the two
|
|
5
|
+
* meridian planes that close a partial revolution; `j` 0 at `from`, 1 at `to`).
|
|
6
|
+
*/
|
|
7
|
+
export type ShapePart = 'side' | 'start' | 'end' | 'cut';
|
|
8
|
+
/**
|
|
9
|
+
* The geometric facts of one vertex, handed to the payload callback. One object is reused for every vertex of a
|
|
10
|
+
* call: read it inside the callback, do not keep it.
|
|
11
|
+
*/
|
|
12
|
+
export interface ShapeVertex {
|
|
13
|
+
/** Position in the shape's own frame (before the builder's transform). */
|
|
14
|
+
readonly p: Vec3;
|
|
15
|
+
/** Unit normal in the same frame. */
|
|
16
|
+
readonly n: Vec3;
|
|
17
|
+
part: ShapePart;
|
|
18
|
+
/**
|
|
19
|
+
* Grid indices. On a side: `i` across (around a revolution, along a section or an outline), `j` along (profile
|
|
20
|
+
* point, path point, 0/1 for the two ends of an extrusion). On a cap: `i` the outline corner, `j` 0.
|
|
21
|
+
*/
|
|
22
|
+
i: number;
|
|
23
|
+
j: number;
|
|
24
|
+
/**
|
|
25
|
+
* Shares 0–1 that match `i` and `j` (by arc length for profiles, sections, paths and outlines; by angle around a
|
|
26
|
+
* revolution). On a cap: `u` the share around the outline, `v` 1 on the rim and 0 at a fan centre.
|
|
27
|
+
*/
|
|
28
|
+
u: number;
|
|
29
|
+
v: number;
|
|
30
|
+
/** Number of the flat face within this call (−1 on smooth surfaces). */
|
|
31
|
+
face: number;
|
|
32
|
+
/** Corner within the flat face, from 0 in winding order (−1 on smooth surfaces and at a fan centre). */
|
|
33
|
+
corner: number;
|
|
34
|
+
/** True for the extra centre vertex of a fan. */
|
|
35
|
+
centre: boolean;
|
|
36
|
+
}
|
|
37
|
+
/** Normals of a grid: smooth everywhere, flat per cell (false), or flat across and smooth along ('along'). */
|
|
38
|
+
export type GridSmooth = boolean | 'along';
|
|
39
|
+
/** Gives the payload of one vertex from its geometric facts. */
|
|
40
|
+
export type ShapePayload<V> = (s: ShapeVertex) => V;
|
|
41
|
+
/** Moves a grid point (in the shape's frame) before normals are computed; `i`, `j` as in `ShapeVertex`. */
|
|
42
|
+
export type ShapeWarp = (p: Vec3, i: number, j: number) => void;
|
|
43
|
+
export interface PolygonOptions {
|
|
44
|
+
/** Triangulate as a fan from an extra centre vertex (the mean of the corners) instead of from the corners alone. */
|
|
45
|
+
fan?: boolean;
|
|
46
|
+
/** Which part the vertices report (default 'side'). */
|
|
47
|
+
part?: ShapePart;
|
|
48
|
+
/** Face number reported to the callback (default 0). */
|
|
49
|
+
face?: number;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* A flat simple polygon (corners counter-clockwise seen from the front) with one normal (Newell's). A convex polygon
|
|
53
|
+
* is a fan from its first corner; a concave one is ear-clipped (corners on a straight line may be left out of the
|
|
54
|
+
* triangles). Returns the index of the first vertex written.
|
|
55
|
+
*/
|
|
56
|
+
export declare function polygon<V>(b: MeshBuilder<V>, points: readonly ArrayLike<number>[], payload: ShapePayload<V>, o?: PolygonOptions): number;
|
|
57
|
+
export interface GridOptions {
|
|
58
|
+
/**
|
|
59
|
+
* Smooth normals from the grid (default), one flat face per cell (false), or 'along': hard edges between columns
|
|
60
|
+
* and smooth along each column strip (a section with sharp corners bent along a path).
|
|
61
|
+
*/
|
|
62
|
+
smooth?: GridSmooth;
|
|
63
|
+
/** The last column joins the first (a closed loop across). The seam vertices are written twice (u 0 and 1). */
|
|
64
|
+
wrapI?: boolean;
|
|
65
|
+
/** The last row joins the first (a closed loop along). */
|
|
66
|
+
wrapJ?: boolean;
|
|
67
|
+
/** Reverse the winding (the cross product d/di × d/dj then points inward). */
|
|
68
|
+
flip?: boolean;
|
|
69
|
+
/** Shares per column / row reported as `u` / `v` (default i / (cols − 1) and j / (rows − 1); with wrap / cols). */
|
|
70
|
+
u?: readonly number[];
|
|
71
|
+
v?: readonly number[];
|
|
72
|
+
/** Normal per grid point instead of the one from differences (smooth only). */
|
|
73
|
+
normalAt?: (i: number, j: number, out: Vec3) => Vec3;
|
|
74
|
+
/** Which part the vertices report. Default 'side'. */
|
|
75
|
+
part?: ShapePart;
|
|
76
|
+
/** First face number for flat cells. Default 0. Returns are the face numbers used. */
|
|
77
|
+
faceBase?: number;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* A grid of `cols` × `rows` points `at(i, j)` stitched into quads (i, j) (i+1, j) (i+1, j+1) (i, j+1), which face
|
|
81
|
+
* the side d/di × d/dj points to. Smooth normals come from central differences of neighbouring points (wrapping
|
|
82
|
+
* where the grid wraps). A cell whose two points on one edge coincide (an apex) becomes a triangle. With 'along'
|
|
83
|
+
* every column strip has its own vertices, normals across from the strip's edge and along from central differences
|
|
84
|
+
* (face and corner −1). Returns the number of flat faces written (0 unless flat).
|
|
85
|
+
*/
|
|
86
|
+
export declare function gridSurface<V>(b: MeshBuilder<V>, cols: number, rows: number, at: (i: number, j: number, out: Vec3) => Vec3, payload: ShapePayload<V>, o?: GridOptions): number;
|
|
87
|
+
export interface RevolveOptions {
|
|
88
|
+
/** Segments around. Default 24. */
|
|
89
|
+
segments?: number;
|
|
90
|
+
/**
|
|
91
|
+
* Angle range in radians, θ measured from +z toward +x (a point is (r sin θ, y, r cos θ)). Default the full turn.
|
|
92
|
+
* A partial range is open at its two meridians unless `sides`.
|
|
93
|
+
*/
|
|
94
|
+
from?: number;
|
|
95
|
+
to?: number;
|
|
96
|
+
/** Smooth normals (default), one flat face per cell (false), or flat around and smooth along the profile ('along'). */
|
|
97
|
+
smooth?: GridSmooth;
|
|
98
|
+
/** Close the profile's first / last point with a flat disc (when its radius is above zero). */
|
|
99
|
+
capStart?: boolean;
|
|
100
|
+
capEnd?: boolean;
|
|
101
|
+
/** Cap discs as fans from a centre vertex (default true) or from their first rim corner. */
|
|
102
|
+
capFan?: boolean;
|
|
103
|
+
/** For a partial range: close the two meridian planes (the profile and the axis), reported as part 'cut'. */
|
|
104
|
+
sides?: boolean;
|
|
105
|
+
/** Moves grid points (i around, j along the profile) before normals are taken. */
|
|
106
|
+
warp?: ShapeWarp;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* A surface of revolution about +y from a profile of [radius, y] points. Faces point to the right of the profile's
|
|
110
|
+
* direction in the r–y plane: a profile from bottom to top faces outward. A point of radius 0 is an apex (the cells
|
|
111
|
+
* next to it are triangles). Side vertices report `i` around (0…segments), `j` the profile point, `u` the angle
|
|
112
|
+
* share, `v` the arc-length share along the profile. Returns the vertex index of the first vertex written.
|
|
113
|
+
*/
|
|
114
|
+
export declare function revolve<V>(b: MeshBuilder<V>, profile: readonly (readonly [number, number])[], payload: ShapePayload<V>, o?: RevolveOptions): number;
|
|
115
|
+
/** A frame along a path: tangent `t`, and `u`, `v` across it (v = t × u). */
|
|
116
|
+
export interface PathFrame {
|
|
117
|
+
t: Vec3;
|
|
118
|
+
u: Vec3;
|
|
119
|
+
v: Vec3;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Rotation-minimising frames along a polyline (parallel transport): the first `u` is the direction across the
|
|
123
|
+
* tangent closest to perpendicular to `up` (u = up × t), then each next `u` is the previous one with its tangent part
|
|
124
|
+
* removed, so the frame does not twist. With `closed` the path's ends are neighbours for the tangents.
|
|
125
|
+
*/
|
|
126
|
+
export declare function pathFrames(path: readonly ArrayLike<number>[], up?: ArrayLike<number>, closed?: boolean): PathFrame[];
|
|
127
|
+
/**
|
|
128
|
+
* A smooth curve through `points` (centripetal Catmull–Rom): `steps` samples per segment, the given points kept. With
|
|
129
|
+
* `closed` the curve returns to its start (the first point is not repeated at the end).
|
|
130
|
+
*/
|
|
131
|
+
export declare function smoothPath(points: readonly ArrayLike<number>[], steps: number, closed?: boolean): Vec3[];
|
|
132
|
+
export interface SweepOptions {
|
|
133
|
+
/** The section is a closed loop (default true). */
|
|
134
|
+
closed?: boolean;
|
|
135
|
+
/** The path is a closed loop (a ring); its first point is not repeated at the end. */
|
|
136
|
+
loop?: boolean;
|
|
137
|
+
/** Close both ends with the section as a flat polygon (closed sections on open paths only). */
|
|
138
|
+
caps?: boolean;
|
|
139
|
+
/** Cap polygons as fans from a centre vertex instead of from their first corner. */
|
|
140
|
+
capFan?: boolean;
|
|
141
|
+
/** Scale of the section at a share 0–1 of the path length. */
|
|
142
|
+
scale?: (f: number) => number;
|
|
143
|
+
/** Turn of the section at a share 0–1 of the path length, radians (counter-clockwise in u–v). */
|
|
144
|
+
twist?: (f: number) => number;
|
|
145
|
+
/** Up hint of the first frame. Default +y. */
|
|
146
|
+
up?: ArrayLike<number>;
|
|
147
|
+
/** Smooth normals (default), one flat face per cell (false), or hard section corners smooth along the path ('along'). */
|
|
148
|
+
smooth?: GridSmooth;
|
|
149
|
+
/** Smooth the path first: this many samples per segment (centripetal Catmull–Rom through the points). */
|
|
150
|
+
subdivide?: number;
|
|
151
|
+
/** Moves grid points (i along the section, j along the path) before normals are taken. */
|
|
152
|
+
warp?: ShapeWarp;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Pulls a section ([x, y] in the frame u–v across the path) along a path of 3D points with rotation-minimising
|
|
156
|
+
* frames. A closed section given counter-clockwise in u–v faces outward; a clockwise one is turned around, so the
|
|
157
|
+
* faces always point away from the path. Side vertices report `i` the section point, `j` the path point, `u` the
|
|
158
|
+
* share along the section, `v` the share of the path length. Returns the index of the first vertex written.
|
|
159
|
+
*/
|
|
160
|
+
export declare function sweep<V>(b: MeshBuilder<V>, path: readonly ArrayLike<number>[], section: readonly (readonly [number, number])[], payload: ShapePayload<V>, o?: SweepOptions): number;
|
|
161
|
+
export interface ExtrudeOptions {
|
|
162
|
+
/** Close the start (z0, facing −z) / end (z1, facing +z). Default both. */
|
|
163
|
+
capStart?: boolean;
|
|
164
|
+
capEnd?: boolean;
|
|
165
|
+
/** Cap polygons as fans from a centre vertex instead of from their first corner (concave caps are ear-clipped). */
|
|
166
|
+
capFan?: boolean;
|
|
167
|
+
/** Smooth normals around the outline (a rounded outline) instead of one flat face per edge (default). */
|
|
168
|
+
smooth?: boolean;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* An outline ([x, y] points, counter-clockwise seen from +z; a clockwise one is turned around) pushed from z = z0 to
|
|
172
|
+
* z = z1. Each side face is a flat quad with corners (p, z0) (q, z0) (q, z1) (p, z1) for the edge p → q, reported as
|
|
173
|
+
* `corner` 0–3, with `i` the outline point, `j` 0 at z0 and 1 at z1, `u` the share along the outline and `v` 0 or 1.
|
|
174
|
+
* To extrude upward from a ground outline, push a rotation (+z onto +y) first. Returns the first vertex index.
|
|
175
|
+
*/
|
|
176
|
+
export declare function extrude<V>(b: MeshBuilder<V>, outline: readonly (readonly [number, number])[], z0: number, z1: number, payload: ShapePayload<V>, o?: ExtrudeOptions): number;
|
|
177
|
+
/**
|
|
178
|
+
* An axis-aligned box from `min` to `max`: an extrusion of the x–y rectangle along z, six flat faces (sides first,
|
|
179
|
+
* then +z, then −z). Returns the first vertex index.
|
|
180
|
+
*/
|
|
181
|
+
export declare function box<V>(b: MeshBuilder<V>, min: ArrayLike<number>, max: ArrayLike<number>, payload: ShapePayload<V>): number;
|
|
182
|
+
export interface CylinderOptions {
|
|
183
|
+
/** Segments around. Default 24. */
|
|
184
|
+
segments?: number;
|
|
185
|
+
/** Radius at y1 (default the same: a cylinder; otherwise a cone frustum, 0 an apex). */
|
|
186
|
+
radiusTop?: number;
|
|
187
|
+
/** Close the bottom / top disc. Default both. */
|
|
188
|
+
capStart?: boolean;
|
|
189
|
+
capEnd?: boolean;
|
|
190
|
+
/** Smooth sides (default) or flat. */
|
|
191
|
+
smooth?: boolean;
|
|
192
|
+
}
|
|
193
|
+
/** A cylinder (or cone frustum) about +y from y0 to y1: a revolution of a two-point profile. */
|
|
194
|
+
export declare function cylinder<V>(b: MeshBuilder<V>, radius: number, y0: number, y1: number, payload: ShapePayload<V>, o?: CylinderOptions): number;
|