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,7 @@
|
|
|
1
|
+
import type { MaterialDesc, Uniforms } from '../base/index.ts';
|
|
2
|
+
/** Instanced vegetation (`buildTreeBatches`): lit in the colour pass, casts shadows with its own depth program. */
|
|
3
|
+
export declare const VEGETATION_MATERIAL: MaterialDesc;
|
|
4
|
+
/** Palette rows of the season colours: autumn yellow, orange, rust, bare twigs; and the spring leaf. */
|
|
5
|
+
export declare function vegetationUniforms(seasonRows: readonly [number, number, number, number], springRow: number): Uniforms;
|
|
6
|
+
/** Sparse canopies (spring, autumn, winter) become transparent via alpha-to-coverage: the antialiasing samples act as a fine sieve. */
|
|
7
|
+
export declare function vegetationSieve(foliage: number): boolean;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Materials of the vegetation, as plain descriptions for the renderer.
|
|
2
|
+
import { TREE_ATTRIBS } from './trees.js';
|
|
3
|
+
import { DEPTH_TREE_FS, DEPTH_TREE_VS, TREE_FS, TREE_VS } from './tree-shader.js';
|
|
4
|
+
/** Instanced vegetation (`buildTreeBatches`): lit in the colour pass, casts shadows with its own depth program. */
|
|
5
|
+
export const VEGETATION_MATERIAL = {
|
|
6
|
+
name: 'vegetation',
|
|
7
|
+
attribs: TREE_ATTRIBS,
|
|
8
|
+
passes: { shadow: { vs: DEPTH_TREE_VS, fs: DEPTH_TREE_FS }, color: { vs: TREE_VS, fs: TREE_FS } },
|
|
9
|
+
};
|
|
10
|
+
/** Palette rows of the season colours: autumn yellow, orange, rust, bare twigs; and the spring leaf. */
|
|
11
|
+
export function vegetationUniforms(seasonRows, springRow) {
|
|
12
|
+
return { u_seasonRows: { ivec4: [seasonRows[0], seasonRows[1], seasonRows[2], seasonRows[3]] }, u_springRow: { int: springRow } };
|
|
13
|
+
}
|
|
14
|
+
/** Sparse canopies (spring, autumn, winter) become transparent via alpha-to-coverage: the antialiasing samples act as a fine sieve. */
|
|
15
|
+
export function vegetationSieve(foliage) {
|
|
16
|
+
return foliage < 0.999;
|
|
17
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import type { OutlineField } from '../gen-core/index.ts';
|
|
2
|
+
import type { Occupancy } from '../gen-core/index.ts';
|
|
3
|
+
/** Tree type by the place where it stands. */
|
|
4
|
+
export type TreeKind = 'forest' | 'park' | 'street' | 'house' | 'shrub';
|
|
5
|
+
/** Species, i.e. the canopy shape. */
|
|
6
|
+
export type TreeSpecies = 'round' | 'tall' | 'conifer' | 'birch' | 'shrub';
|
|
7
|
+
export declare const TREE_KINDS: readonly TreeKind[];
|
|
8
|
+
export declare const TREE_SPECIES: readonly TreeSpecies[];
|
|
9
|
+
/** Vegetation raster: height and canopy coverage per cell, rows from the north. */
|
|
10
|
+
export interface CanopyRaster {
|
|
11
|
+
/** Height in units of `heightScale` metres. */
|
|
12
|
+
height: Uint8Array;
|
|
13
|
+
/** Share of the cell under a canopy, 0–255. */
|
|
14
|
+
cover: Uint8Array;
|
|
15
|
+
cols: number;
|
|
16
|
+
rows: number;
|
|
17
|
+
/** Cell size in metres. */
|
|
18
|
+
step: number;
|
|
19
|
+
heightScale: number;
|
|
20
|
+
}
|
|
21
|
+
/** Street axis along which an avenue may stand. */
|
|
22
|
+
export interface StreetLine {
|
|
23
|
+
/** Polyline, flat array x, z. */
|
|
24
|
+
points: ArrayLike<number>;
|
|
25
|
+
/** Roadway width in metres. */
|
|
26
|
+
width: number;
|
|
27
|
+
id: number;
|
|
28
|
+
}
|
|
29
|
+
/** Placement rules in metres (setbacks, limits, spacing). The project supplies the numbers. */
|
|
30
|
+
export interface PlantingRules {
|
|
31
|
+
/** A trunk stands at least this far from a wall. */
|
|
32
|
+
trunkMinWallDistance: number;
|
|
33
|
+
/** Gap between a canopy and a wall: canopy radius is at most the distance to the wall minus this gap. */
|
|
34
|
+
crownWallGap: number;
|
|
35
|
+
/** A canopy smaller than this is not planted. */
|
|
36
|
+
crownMinRadius: number;
|
|
37
|
+
/** Lower vegetation is not drawn at all. */
|
|
38
|
+
minVegetationHeight: number;
|
|
39
|
+
/** Vegetation lower than this is a shrub. */
|
|
40
|
+
shrubMaxHeight: number;
|
|
41
|
+
maxHeight: number;
|
|
42
|
+
/** Radius of the neighbourhood in which the canopy top above a trunk is searched. */
|
|
43
|
+
heightSearchRadius: number;
|
|
44
|
+
/** A vegetation raster cell counts as growth from this coverage (0–1). */
|
|
45
|
+
minCellCover: number;
|
|
46
|
+
/** Strip along a road in which only street avenues stand. */
|
|
47
|
+
streetBand: number;
|
|
48
|
+
/** Dense growth may enter the strip along a road only from this distance from the roadway edge. */
|
|
49
|
+
streetBandForestFrom: number;
|
|
50
|
+
/** A tree closer to a wall than this is the "by house" type. */
|
|
51
|
+
nearHouseDistance: number;
|
|
52
|
+
/** Forest: at least this far from buildings and at least this share of vegetation in the neighbourhood. */
|
|
53
|
+
forestMinWallDistance: number;
|
|
54
|
+
forestNeighbourhoodRadius: number;
|
|
55
|
+
forestMinCover: number;
|
|
56
|
+
/** Neighbourhood used to shrink a canopy when the growth in the data is small. */
|
|
57
|
+
localCoverRadius: number;
|
|
58
|
+
/** A tree by a house is not taller than this. */
|
|
59
|
+
houseTreeMaxHeight: number;
|
|
60
|
+
/** Tree spacing in a row and trunk offset from the roadway edge. */
|
|
61
|
+
streetSpacing: number;
|
|
62
|
+
streetKerbOffset: number;
|
|
63
|
+
/** How much a trunk in a row may randomly shift along the street. */
|
|
64
|
+
streetJitter: number;
|
|
65
|
+
/** How far from the row position a canopy must be in the data. */
|
|
66
|
+
streetCanopySearch: number;
|
|
67
|
+
/** A row is planted only along streets at least this wide. */
|
|
68
|
+
streetMinRoadWidth: number;
|
|
69
|
+
forestCrown: CrownRule;
|
|
70
|
+
parkCrown: CrownRule;
|
|
71
|
+
streetCrown: CrownRule;
|
|
72
|
+
houseCrown: CrownRule;
|
|
73
|
+
shrubCrown: CrownRule;
|
|
74
|
+
/** Grid from which candidates are drawn. Each has a random position in its cell, so the grid is not visible. */
|
|
75
|
+
candidateCell: number;
|
|
76
|
+
/** Size of groups with the same hue and the same species. */
|
|
77
|
+
tintPatch: number;
|
|
78
|
+
speciesPatch: number;
|
|
79
|
+
/** Share of places where the species noise allows conifers and birches: noise threshold 0–1, higher = rarer. */
|
|
80
|
+
coniferThreshold: number;
|
|
81
|
+
birchThreshold: number;
|
|
82
|
+
/** The tree base is slightly below the terrain, so a trunk on a slope does not hang in the air. */
|
|
83
|
+
rootDepth: number;
|
|
84
|
+
/** How far an object's base may be above the terrain and still count as standing on the ground. */
|
|
85
|
+
groundTolerance: number;
|
|
86
|
+
/** Largest allowed sinking of the base of a tree and a car below the terrain. */
|
|
87
|
+
maxSink: number;
|
|
88
|
+
}
|
|
89
|
+
export interface PlantingInput {
|
|
90
|
+
rules: PlantingRules;
|
|
91
|
+
canopy: CanopyRaster;
|
|
92
|
+
walls: OutlineField;
|
|
93
|
+
occupancy: Occupancy;
|
|
94
|
+
/** Flags of the occupied area on which a trunk must not stand. */
|
|
95
|
+
noTrunkMask: number;
|
|
96
|
+
/** Flags that mean roadway. Its edge is searched by them. */
|
|
97
|
+
roadMask: number;
|
|
98
|
+
streets: StreetLine[];
|
|
99
|
+
heightAt: (x: number, z: number) => number;
|
|
100
|
+
seed: number;
|
|
101
|
+
/**
|
|
102
|
+
* Optional test whether a tree may stand at a point. Replaces the default test (`occupancy` against `noTrunkMask`
|
|
103
|
+
* at the point) everywhere a spot is tested.
|
|
104
|
+
*/
|
|
105
|
+
spotFree?: (x: number, z: number) => boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Optional: called when a candidate spot is not free. Returns another spot to use instead, or null to drop the
|
|
108
|
+
* candidate. The returned spot then goes through the usual wall tests. Without it the candidate is dropped.
|
|
109
|
+
*/
|
|
110
|
+
relocate?: (x: number, z: number, seed: number) => readonly [number, number] | null;
|
|
111
|
+
}
|
|
112
|
+
export interface PlantedTree {
|
|
113
|
+
x: number;
|
|
114
|
+
z: number;
|
|
115
|
+
/** Base height (slightly below the terrain). */
|
|
116
|
+
y: number;
|
|
117
|
+
/** Tree height above the base. */
|
|
118
|
+
height: number;
|
|
119
|
+
/** Canopy radius. */
|
|
120
|
+
radius: number;
|
|
121
|
+
kind: TreeKind;
|
|
122
|
+
species: TreeSpecies;
|
|
123
|
+
/** Rotation around the vertical axis. */
|
|
124
|
+
yaw: number;
|
|
125
|
+
/** Hue 0–1, changes smoothly across groups. */
|
|
126
|
+
tint: number;
|
|
127
|
+
/** At what fraction of the height the canopy starts. 0 = from the ground, the trunk is not visible. */
|
|
128
|
+
crownBase: number;
|
|
129
|
+
/** Flexibility in wind, 1 = ordinary broadleaf. */
|
|
130
|
+
flex: number;
|
|
131
|
+
/** Random number 0–1: sway phase and choice of shape variant. */
|
|
132
|
+
phase: number;
|
|
133
|
+
}
|
|
134
|
+
export interface PlantingStats {
|
|
135
|
+
candidates: number;
|
|
136
|
+
/** Why candidates failed. */
|
|
137
|
+
rejected: {
|
|
138
|
+
inWall: number;
|
|
139
|
+
nearWall: number;
|
|
140
|
+
occupied: number;
|
|
141
|
+
streetBand: number;
|
|
142
|
+
crownTooSmall: number;
|
|
143
|
+
spacing: number;
|
|
144
|
+
};
|
|
145
|
+
streetStations: number;
|
|
146
|
+
/** Trees placed at a spot returned by `relocate`. */
|
|
147
|
+
relocated: number;
|
|
148
|
+
}
|
|
149
|
+
export interface CrownRule {
|
|
150
|
+
perHeight: number;
|
|
151
|
+
base: number;
|
|
152
|
+
min: number;
|
|
153
|
+
max: number;
|
|
154
|
+
spacing: number;
|
|
155
|
+
}
|
|
156
|
+
/** Largest flexibility in wind among species. The check uses it to compute the worst canopy deflection. */
|
|
157
|
+
export declare const TREE_MAX_FLEX: number;
|
|
158
|
+
export declare function plantTrees(input: PlantingInput): {
|
|
159
|
+
trees: PlantedTree[];
|
|
160
|
+
stats: PlantingStats;
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* The same planting as `plantTrees`, as a generator that pauses between pieces of work (a row of the candidate grid,
|
|
164
|
+
* a street, a batch of candidates), so a caller can spread it over several tasks. The result does not depend on where
|
|
165
|
+
* it pauses.
|
|
166
|
+
*/
|
|
167
|
+
export declare function plantTreesSteps(input: PlantingInput): Generator<void, {
|
|
168
|
+
trees: PlantedTree[];
|
|
169
|
+
stats: PlantingStats;
|
|
170
|
+
}>;
|
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
// Tree placement rules. The input is a vegetation raster (where the canopy is and how tall), a field of distances
|
|
2
|
+
// to walls, the occupied area and street axes. The output is a list of trees with a type by location and a species.
|
|
3
|
+
//
|
|
4
|
+
// Order: first street avenues at regular spacing along the roadway, then the other trees.
|
|
5
|
+
// Those are drawn from a fine grid of candidates with a random position in the cell and accepted from the tallest:
|
|
6
|
+
// a candidate passes only when it is far enough from those already accepted. The spacing is thus irregular and no grid is visible.
|
|
7
|
+
// Everything is a pure function of the input and the seed, the rule numbers come in `PlantingInput.rules`.
|
|
8
|
+
import { SegmentField } from '../gen-core/index.js';
|
|
9
|
+
import { hashInts, rand } from '../gen-core/index.js';
|
|
10
|
+
import { valueNoise2 } from '../gen-core/index.js';
|
|
11
|
+
export const TREE_KINDS = ['forest', 'park', 'street', 'house', 'shrub'];
|
|
12
|
+
export const TREE_SPECIES = ['round', 'tall', 'conifer', 'birch', 'shrub'];
|
|
13
|
+
/** Shape by species: how narrow the canopy is relative to the type's rule, where it starts and how it yields to wind. */
|
|
14
|
+
const SPECIES_SHAPE = {
|
|
15
|
+
round: { radius: 1.0, crownBase: 0.3, crownBaseForest: 0.18, flex: 1.0 },
|
|
16
|
+
tall: { radius: 0.9, crownBase: 0.3, crownBaseForest: 0.2, flex: 0.9 },
|
|
17
|
+
conifer: { radius: 0.62, crownBase: 0.12, crownBaseForest: 0.08, flex: 0.45 },
|
|
18
|
+
birch: { radius: 0.7, crownBase: 0.42, crownBaseForest: 0.36, flex: 1.35 },
|
|
19
|
+
shrub: { radius: 1.0, crownBase: 0, crownBaseForest: 0, flex: 0.6 },
|
|
20
|
+
};
|
|
21
|
+
/** Largest flexibility in wind among species. The check uses it to compute the worst canopy deflection. */
|
|
22
|
+
export const TREE_MAX_FLEX = Math.max(...Object.values(SPECIES_SHAPE).map((v) => v.flex));
|
|
23
|
+
function clamp(v, lo, hi) {
|
|
24
|
+
return v < lo ? lo : v > hi ? hi : v;
|
|
25
|
+
}
|
|
26
|
+
export function plantTrees(input) {
|
|
27
|
+
const steps = plantTreesSteps(input);
|
|
28
|
+
for (;;) {
|
|
29
|
+
const r = steps.next();
|
|
30
|
+
if (r.done)
|
|
31
|
+
return r.value;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The same planting as `plantTrees`, as a generator that pauses between pieces of work (a row of the candidate grid,
|
|
36
|
+
* a street, a batch of candidates), so a caller can spread it over several tasks. The result does not depend on where
|
|
37
|
+
* it pauses.
|
|
38
|
+
*/
|
|
39
|
+
export function* plantTreesSteps(input) {
|
|
40
|
+
const { canopy, walls, occupancy, noTrunkMask, roadMask, seed } = input;
|
|
41
|
+
const R = input.rules;
|
|
42
|
+
const CROWN = { forest: R.forestCrown, park: R.parkCrown, street: R.streetCrown, house: R.houseCrown, shrub: R.shrubCrown };
|
|
43
|
+
// How far the generator queries the wall distance: beyond that the distance affects nothing (largest canopy with gap, forest boundary).
|
|
44
|
+
const WALL_REACH = Math.max(R.forestMinWallDistance, R.parkCrown.max + R.crownWallGap, R.forestCrown.max + R.crownWallGap) + 0.5;
|
|
45
|
+
const { cols, rows, step } = canopy;
|
|
46
|
+
const sizeX = cols * step;
|
|
47
|
+
const sizeZ = rows * step;
|
|
48
|
+
const stats = {
|
|
49
|
+
candidates: 0,
|
|
50
|
+
rejected: { inWall: 0, nearWall: 0, occupied: 0, streetBand: 0, crownTooSmall: 0, spacing: 0 },
|
|
51
|
+
streetStations: 0,
|
|
52
|
+
relocated: 0,
|
|
53
|
+
};
|
|
54
|
+
const trunkFree = input.spotFree ?? ((x, z) => (occupancy.at(x, z) & noTrunkMask) === 0);
|
|
55
|
+
const seedTint = hashInts(seed, 101);
|
|
56
|
+
const seedConifer = hashInts(seed, 102);
|
|
57
|
+
const seedBirch = hashInts(seed, 103);
|
|
58
|
+
const seedTall = hashInts(seed, 104);
|
|
59
|
+
// --- Vegetation raster queries ---------------------------------------------------------------
|
|
60
|
+
const coverMin = Math.round(R.minCellCover * 255);
|
|
61
|
+
const cellOf = (x, z) => clamp(Math.floor(z / step), 0, rows - 1) * cols + clamp(Math.floor(x / step), 0, cols - 1);
|
|
62
|
+
/** Summed-area table of cells with vegetation, for the share of vegetation in a neighbourhood. */
|
|
63
|
+
const integral = new Uint32Array((cols + 1) * (rows + 1));
|
|
64
|
+
for (let j = 0; j < rows; j++) {
|
|
65
|
+
let run = 0;
|
|
66
|
+
for (let i = 0; i < cols; i++) {
|
|
67
|
+
run += canopy.cover[j * cols + i] >= coverMin ? 1 : 0;
|
|
68
|
+
integral[(j + 1) * (cols + 1) + i + 1] = integral[j * (cols + 1) + i + 1] + run;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
yield;
|
|
72
|
+
const coverAround = (x, z, radius) => {
|
|
73
|
+
const i0 = clamp(Math.floor((x - radius) / step), 0, cols);
|
|
74
|
+
const i1 = clamp(Math.ceil((x + radius) / step), 0, cols);
|
|
75
|
+
const j0 = clamp(Math.floor((z - radius) / step), 0, rows);
|
|
76
|
+
const j1 = clamp(Math.ceil((z + radius) / step), 0, rows);
|
|
77
|
+
const n = (i1 - i0) * (j1 - j0);
|
|
78
|
+
if (n <= 0)
|
|
79
|
+
return 0;
|
|
80
|
+
const w = cols + 1;
|
|
81
|
+
return (integral[j1 * w + i1] - integral[j0 * w + i1] - integral[j1 * w + i0] + integral[j0 * w + i0]) / n;
|
|
82
|
+
};
|
|
83
|
+
/** Tallest canopy around a point, in metres. 0 when there is no vegetation around. */
|
|
84
|
+
const heightAround = (x, z, radius) => {
|
|
85
|
+
const i0 = clamp(Math.floor((x - radius) / step), 0, cols - 1);
|
|
86
|
+
const i1 = clamp(Math.floor((x + radius) / step), 0, cols - 1);
|
|
87
|
+
const j0 = clamp(Math.floor((z - radius) / step), 0, rows - 1);
|
|
88
|
+
const j1 = clamp(Math.floor((z + radius) / step), 0, rows - 1);
|
|
89
|
+
let best = 0;
|
|
90
|
+
for (let j = j0; j <= j1; j++) {
|
|
91
|
+
for (let i = i0; i <= i1; i++) {
|
|
92
|
+
const k = j * cols + i;
|
|
93
|
+
if (canopy.cover[k] >= coverMin && canopy.height[k] > best)
|
|
94
|
+
best = canopy.height[k];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return Math.min(R.maxHeight, best * canopy.heightScale);
|
|
98
|
+
};
|
|
99
|
+
// --- Street edges --------------------------------------------------------------------------------
|
|
100
|
+
const streetEdges = new SegmentField(sizeX, sizeZ);
|
|
101
|
+
for (const st of input.streets) {
|
|
102
|
+
if (st.width >= R.streetMinRoadWidth)
|
|
103
|
+
streetEdges.addPolyline(st.points, st.width / 2, st.id);
|
|
104
|
+
}
|
|
105
|
+
// --- Accepted trees and their spacing ----------------------------------------------------------
|
|
106
|
+
const trees = [];
|
|
107
|
+
const spacingOf = [];
|
|
108
|
+
const GRID_M = 4;
|
|
109
|
+
const gCols = Math.ceil(sizeX / GRID_M);
|
|
110
|
+
const gRows = Math.ceil(sizeZ / GRID_M);
|
|
111
|
+
const grid = new Array(gCols * gRows);
|
|
112
|
+
let maxSpacing = 0;
|
|
113
|
+
for (const kind of TREE_KINDS)
|
|
114
|
+
maxSpacing = Math.max(maxSpacing, CROWN[kind].max * CROWN[kind].spacing);
|
|
115
|
+
const fits = (x, z, spacing) => {
|
|
116
|
+
const reach = (spacing + maxSpacing) / 2;
|
|
117
|
+
const c0 = clamp(Math.floor((x - reach) / GRID_M), 0, gCols - 1);
|
|
118
|
+
const c1 = clamp(Math.floor((x + reach) / GRID_M), 0, gCols - 1);
|
|
119
|
+
const r0 = clamp(Math.floor((z - reach) / GRID_M), 0, gRows - 1);
|
|
120
|
+
const r1 = clamp(Math.floor((z + reach) / GRID_M), 0, gRows - 1);
|
|
121
|
+
for (let r = r0; r <= r1; r++) {
|
|
122
|
+
for (let c = c0; c <= c1; c++) {
|
|
123
|
+
const list = grid[r * gCols + c];
|
|
124
|
+
if (!list)
|
|
125
|
+
continue;
|
|
126
|
+
for (const t of list) {
|
|
127
|
+
const o = trees[t];
|
|
128
|
+
const need = (spacing + spacingOf[t]) / 2;
|
|
129
|
+
const dx = o.x - x;
|
|
130
|
+
const dz = o.z - z;
|
|
131
|
+
if (dx * dx + dz * dz < need * need)
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return true;
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Common ending for all types: trunk setback from the wall, occupied area, canopy size by the wall,
|
|
140
|
+
* spacing from neighbours. Returns true when the tree has grown.
|
|
141
|
+
*/
|
|
142
|
+
const place = (x0, z0, h, kind, species, treeSeed) => {
|
|
143
|
+
let x = x0;
|
|
144
|
+
let z = z0;
|
|
145
|
+
if (x < 0 || z < 0 || x >= sizeX || z >= sizeZ)
|
|
146
|
+
return false;
|
|
147
|
+
let dWall = walls.distance(x, z, WALL_REACH);
|
|
148
|
+
if (dWall < 0) {
|
|
149
|
+
stats.rejected.inWall++;
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
if (dWall < R.trunkMinWallDistance) {
|
|
153
|
+
stats.rejected.nearWall++;
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
if (!trunkFree(x, z)) {
|
|
157
|
+
const alt = input.relocate?.(x0, z0, treeSeed) ?? null;
|
|
158
|
+
const d = alt && alt[0] >= 0 && alt[1] >= 0 && alt[0] < sizeX && alt[1] < sizeZ ? walls.distance(alt[0], alt[1], WALL_REACH) : -1;
|
|
159
|
+
if (!alt || d < R.trunkMinWallDistance || !trunkFree(alt[0], alt[1])) {
|
|
160
|
+
stats.rejected.occupied++;
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
x = alt[0];
|
|
164
|
+
z = alt[1];
|
|
165
|
+
dWall = d;
|
|
166
|
+
stats.relocated++;
|
|
167
|
+
}
|
|
168
|
+
const rule = CROWN[kind];
|
|
169
|
+
const shape = SPECIES_SHAPE[species];
|
|
170
|
+
let radius = clamp(h * rule.perHeight + rule.base, rule.min, rule.max) * shape.radius * (0.85 + 0.3 * rand(treeSeed, 1));
|
|
171
|
+
// A small islet of vegetation in the data does not get a canopy like a tree in the middle of a forest.
|
|
172
|
+
if (kind !== 'street')
|
|
173
|
+
radius *= Math.sqrt(clamp(coverAround(x, z, R.localCoverRadius) * 1.4, 0.3, 1));
|
|
174
|
+
radius = Math.max(radius, R.crownMinRadius * 1.1);
|
|
175
|
+
// The canopy must not reach into the wall.
|
|
176
|
+
radius = Math.min(radius, dWall - R.crownWallGap);
|
|
177
|
+
if (radius < R.crownMinRadius) {
|
|
178
|
+
stats.rejected.crownTooSmall++;
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
const spacing = radius * rule.spacing;
|
|
182
|
+
if (!fits(x, z, spacing)) {
|
|
183
|
+
stats.rejected.spacing++;
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
const tintNoise = valueNoise2(x, z, R.tintPatch, seedTint);
|
|
187
|
+
const smooth = clamp((tintNoise - 0.25) / 0.5, 0, 1);
|
|
188
|
+
const index = trees.length;
|
|
189
|
+
trees.push({
|
|
190
|
+
x,
|
|
191
|
+
z,
|
|
192
|
+
y: input.heightAt(x, z) - R.rootDepth,
|
|
193
|
+
height: h,
|
|
194
|
+
radius,
|
|
195
|
+
kind,
|
|
196
|
+
species,
|
|
197
|
+
yaw: rand(treeSeed, 2) * Math.PI * 2,
|
|
198
|
+
tint: clamp(smooth * smooth * (3 - 2 * smooth) * 0.82 + 0.18 * rand(treeSeed, 3), 0, 1),
|
|
199
|
+
crownBase: clamp((kind === 'forest' ? shape.crownBaseForest : shape.crownBase) + (species === 'shrub' ? 0 : 0.08 * (rand(treeSeed, 4) - 0.5)), 0, 0.6),
|
|
200
|
+
flex: shape.flex,
|
|
201
|
+
phase: rand(treeSeed, 5),
|
|
202
|
+
});
|
|
203
|
+
spacingOf.push(spacing);
|
|
204
|
+
const g = clamp(Math.floor(z / GRID_M), 0, gRows - 1) * gCols + clamp(Math.floor(x / GRID_M), 0, gCols - 1);
|
|
205
|
+
(grid[g] ??= []).push(index);
|
|
206
|
+
return true;
|
|
207
|
+
};
|
|
208
|
+
// --- 1. Street avenues ------------------------------------------------------------------------
|
|
209
|
+
const isRoad = (x, z) => (occupancy.at(x, z) & roadMask) !== 0;
|
|
210
|
+
for (const st of input.streets) {
|
|
211
|
+
if (st.width < R.streetMinRoadWidth)
|
|
212
|
+
continue;
|
|
213
|
+
const p = st.points;
|
|
214
|
+
const n = p.length / 2;
|
|
215
|
+
// One street, one species: an avenue should be uniform.
|
|
216
|
+
const species = rand(seed, st.id, 11) < 0.55 ? 'tall' : 'round';
|
|
217
|
+
for (const side of [1, -1]) {
|
|
218
|
+
let next = rand(seed, st.id, side + 20) * R.streetSpacing;
|
|
219
|
+
let walked = 0;
|
|
220
|
+
let station = 0;
|
|
221
|
+
for (let k = 0; k + 1 < n; k++) {
|
|
222
|
+
const ax = p[k * 2];
|
|
223
|
+
const az = p[k * 2 + 1];
|
|
224
|
+
const dx = p[k * 2 + 2] - ax;
|
|
225
|
+
const dz = p[k * 2 + 3] - az;
|
|
226
|
+
const len = Math.hypot(dx, dz);
|
|
227
|
+
if (len < 1e-3)
|
|
228
|
+
continue;
|
|
229
|
+
const tx = dx / len;
|
|
230
|
+
const tz = dz / len;
|
|
231
|
+
const nx = -tz * side;
|
|
232
|
+
const nz = tx * side;
|
|
233
|
+
for (; next <= walked + len; next += R.streetSpacing) {
|
|
234
|
+
station++;
|
|
235
|
+
stats.streetStations++;
|
|
236
|
+
const treeSeed = hashInts(seed, st.id, side + 30, station);
|
|
237
|
+
const t = next - walked + (rand(treeSeed, 6) - 0.5) * 2 * R.streetJitter;
|
|
238
|
+
const cx = ax + tx * t;
|
|
239
|
+
const cz = az + tz * t;
|
|
240
|
+
// Actual roadway edge: from the axis outward while it is still under a road point.
|
|
241
|
+
let kerb = st.width / 2;
|
|
242
|
+
if (isRoad(cx, cz)) {
|
|
243
|
+
kerb = 0;
|
|
244
|
+
while (kerb < st.width / 2 + 3 && isRoad(cx + nx * (kerb + 0.5), cz + nz * (kerb + 0.5)))
|
|
245
|
+
kerb += 0.5;
|
|
246
|
+
kerb += 0.25;
|
|
247
|
+
}
|
|
248
|
+
// Place for the trunk: a bit beyond the edge. If there is a sidewalk or wall there, try a bit farther, still within the street strip.
|
|
249
|
+
for (let extra = 0; R.streetKerbOffset + extra <= R.streetBand; extra += 1) {
|
|
250
|
+
const off = kerb + R.streetKerbOffset + extra;
|
|
251
|
+
const x = cx + nx * off;
|
|
252
|
+
const z = cz + nz * off;
|
|
253
|
+
if (x < 0 || z < 0 || x >= sizeX || z >= sizeZ)
|
|
254
|
+
break;
|
|
255
|
+
if (!trunkFree(x, z))
|
|
256
|
+
continue;
|
|
257
|
+
const dWall = walls.distance(x, z, WALL_REACH);
|
|
258
|
+
if (dWall < R.trunkMinWallDistance + R.crownMinRadius)
|
|
259
|
+
continue;
|
|
260
|
+
// Another street is closer than this one (intersection): the row ends there.
|
|
261
|
+
if (streetEdges.distance(x, z, R.streetBand, st.id) < R.streetKerbOffset * 0.6)
|
|
262
|
+
break;
|
|
263
|
+
const h = heightAround(x, z, R.streetCanopySearch);
|
|
264
|
+
if (h < R.shrubMaxHeight)
|
|
265
|
+
break;
|
|
266
|
+
place(x, z, h, 'street', species, treeSeed);
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
walked += len;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
yield;
|
|
274
|
+
}
|
|
275
|
+
// --- 2. Candidates from the fine grid, from the tallest ---------------------------------------------------
|
|
276
|
+
const cell = R.candidateCell;
|
|
277
|
+
const cCols = Math.ceil(sizeX / cell);
|
|
278
|
+
const cRows = Math.ceil(sizeZ / cell);
|
|
279
|
+
const candX = [];
|
|
280
|
+
const candZ = [];
|
|
281
|
+
const candH = [];
|
|
282
|
+
const candPriority = [];
|
|
283
|
+
const candSeed = [];
|
|
284
|
+
for (let j = 0; j < cRows; j++) {
|
|
285
|
+
for (let i = 0; i < cCols; i++) {
|
|
286
|
+
const s = hashInts(seed, i, j);
|
|
287
|
+
const x = (i + rand(s, 1)) * cell;
|
|
288
|
+
const z = (j + rand(s, 2)) * cell;
|
|
289
|
+
if (x >= sizeX || z >= sizeZ)
|
|
290
|
+
continue;
|
|
291
|
+
if (canopy.cover[cellOf(x, z)] < coverMin)
|
|
292
|
+
continue;
|
|
293
|
+
const h = heightAround(x, z, R.heightSearchRadius);
|
|
294
|
+
if (h < R.minVegetationHeight)
|
|
295
|
+
continue;
|
|
296
|
+
candX.push(x);
|
|
297
|
+
candZ.push(z);
|
|
298
|
+
candH.push(h);
|
|
299
|
+
candPriority.push(h + 4 * rand(s, 3));
|
|
300
|
+
candSeed.push(s);
|
|
301
|
+
}
|
|
302
|
+
if ((j & 7) === 7)
|
|
303
|
+
yield;
|
|
304
|
+
}
|
|
305
|
+
stats.candidates = candX.length;
|
|
306
|
+
const order = Array.from(candX.keys()).sort((a, b) => candPriority[b] - candPriority[a] || a - b);
|
|
307
|
+
let done = 0;
|
|
308
|
+
for (const c of order) {
|
|
309
|
+
if ((++done & 1023) === 0)
|
|
310
|
+
yield;
|
|
311
|
+
const x = candX[c];
|
|
312
|
+
const z = candZ[c];
|
|
313
|
+
let h = candH[c];
|
|
314
|
+
const s = candSeed[c];
|
|
315
|
+
const dWall = walls.distance(x, z, WALL_REACH);
|
|
316
|
+
if (dWall < 0) {
|
|
317
|
+
stats.rejected.inWall++;
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
if (dWall < R.trunkMinWallDistance) {
|
|
321
|
+
stats.rejected.nearWall++;
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
const forestCover = coverAround(x, z, R.forestNeighbourhoodRadius);
|
|
325
|
+
const dStreet = streetEdges.distance(x, z, R.streetBand);
|
|
326
|
+
if (dStreet < R.streetBand && !(forestCover >= R.forestMinCover && dStreet >= R.streetBandForestFrom)) {
|
|
327
|
+
// The strip along a street belongs to the avenue.
|
|
328
|
+
stats.rejected.streetBand++;
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
let kind;
|
|
332
|
+
let species;
|
|
333
|
+
const u = rand(s, 7);
|
|
334
|
+
const v = rand(s, 8);
|
|
335
|
+
const conifer = valueNoise2(x, z, R.speciesPatch, seedConifer);
|
|
336
|
+
const birch = valueNoise2(x, z, R.speciesPatch * 0.7, seedBirch);
|
|
337
|
+
const tall = valueNoise2(x, z, R.speciesPatch * 0.8, seedTall);
|
|
338
|
+
if (h < R.shrubMaxHeight) {
|
|
339
|
+
kind = 'shrub';
|
|
340
|
+
species = 'shrub';
|
|
341
|
+
}
|
|
342
|
+
else if (dWall < R.nearHouseDistance) {
|
|
343
|
+
kind = 'house';
|
|
344
|
+
h = Math.min(h, R.houseTreeMaxHeight);
|
|
345
|
+
if (h < 4.2) {
|
|
346
|
+
species = 'shrub';
|
|
347
|
+
h = Math.min(h, R.shrubMaxHeight);
|
|
348
|
+
}
|
|
349
|
+
else
|
|
350
|
+
species = birch + 0.3 * (u - 0.5) > R.birchThreshold - 0.08 ? 'birch' : conifer + 0.3 * (u - 0.5) > R.coniferThreshold ? 'conifer' : 'round';
|
|
351
|
+
}
|
|
352
|
+
else if (dWall >= R.forestMinWallDistance && forestCover >= R.forestMinCover) {
|
|
353
|
+
kind = 'forest';
|
|
354
|
+
species = conifer + 0.25 * (u - 0.5) > R.coniferThreshold ? 'conifer' : tall + 0.5 * (v - 0.5) > 0.58 ? 'tall' : 'round';
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
kind = 'park';
|
|
358
|
+
species = birch + 0.3 * (u - 0.5) > R.birchThreshold ? 'birch' : conifer + 0.3 * (u - 0.5) > R.coniferThreshold ? 'conifer' : v < 0.75 ? 'round' : 'tall';
|
|
359
|
+
}
|
|
360
|
+
place(x, z, h, kind, species, s);
|
|
361
|
+
}
|
|
362
|
+
return { trees, stats };
|
|
363
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Shared transform of an instance vertex into the world, also used by the shadow pass. */
|
|
2
|
+
export declare const TREE_TRANSFORM = "\nin vec3 a_pos; // canopy and trunk at unit height 0\u20131, horizontally in canopy radii\nin vec3 a_normal;\nin vec4 a_shade; // x vertex shading 0\u20131, y kind: 0 canopy, 1 trunk, z wind flutter 0\u20131, w phase 0\u20131\nin vec4 i_base; // xyz tree base, w canopy radius\nin vec4 i_shape; // x height, y cos of rotation, z sin of rotation, w hue 0\u20131\nin vec4 i_extra; // x canopy start (share of height), y flexibility in wind, z phase 0\u20131, w reserve\nuniform float u_trunkReach; // how far the trunk reaches into the canopy (share of the canopy): a part in summer, almost to the top for a bare tree\n// Share of the tree height at which the vertex lies. The canopy occupies the span from its start upward, the trunk reaches a bit into it.\nfloat treeHeightFraction() {\n float cb = i_extra.x;\n return mix(cb + a_pos.y * (1.0 - cb), a_pos.y * (cb + u_trunkReach * (1.0 - cb)), a_shade.y);\n}\nvec3 treeLocal() {\n return vec3(a_pos.x * i_base.w, treeHeightFraction() * i_shape.x, a_pos.z * i_base.w);\n}\nvec3 treeRotate(vec3 v) {\n#ifdef WH_LOCAL_UP\n // Up is radial: the instance stands in the local frame of its base.\n return localFrame(i_base.xyz) * vec3(v.x * i_shape.y - v.z * i_shape.z, v.y, v.x * i_shape.z + v.z * i_shape.y);\n#else\n return vec3(v.x * i_shape.y - v.z * i_shape.z, v.y, v.x * i_shape.z + v.z * i_shape.y);\n#endif\n}\n// Position in tree space for noise: every tree has its pattern shifted by its hue.\nvec3 treeObj(vec3 local) {\n return local + vec3(i_shape.w * 37.0, 0.0, i_shape.w * 11.0);\n}\n";
|
|
3
|
+
/**
|
|
4
|
+
* Foliage by season: leafiness, autumn colour and freshness of one tree. Every tree has its own offset
|
|
5
|
+
* (leafs out, changes colour and sheds slightly at a different time). A bare canopy is a sparse lace of branches. Returns coverage by foliage and branches
|
|
6
|
+
* for alpha-to-coverage; outside winter it is 1 everywhere and nothing turns transparent.
|
|
7
|
+
*/
|
|
8
|
+
export declare const TREE_SEASON = "\nuniform int u_evergreen;\nconst float TWIG_COVER = 0.55;\nfloat treeHashA(float tint, float phase) { return fract(tint * 7.31 + phase * 3.73); }\nfloat treeHashB(float tint, float phase) { return fract(tint * 13.7 + phase * 5.11); }\nfloat treeDensity(float tint, float phase) {\n if (u_evergreen != 0) return 1.0;\n float h = treeHashA(tint, phase);\n return smoothstep(h * 0.4, h * 0.4 + 0.6, u_season.x);\n}\n// x foliage coverage, y total coverage (foliage or branches). visC and visF: how sharply the coarse (tufts around a metre)\n// and the fine canopy detail are visible. What is not visible turns into average coverage, which alpha-to-coverage spreads over the samples.\nvec2 crownCover(vec3 obj, float dens, float visC, float visF) {\n if (dens >= 0.999) return vec2(1.0);\n float coarse = vnoise3(obj * 0.9, 44u);\n float fine = vnoise3(obj * 2.6, 45u);\n float nz = smoothstep(0.2, 0.8, mix(coarse, 0.55 * coarse + 0.45 * fine, visF));\n float edge = mix(0.22, 0.05, visF);\n float leafA = mix(dens, 1.0 - smoothstep(dens - edge, dens + edge, nz), visC);\n // Branches up close as sharp clusters (no sieve), from afar average coverage.\n float tw = smoothstep(0.5, 0.56, vnoise3(obj * 3.4 + 7.0, 46u));\n float twigA = mix(TWIG_COVER * 0.6, tw * 0.95, visF);\n return vec2(leafA, max(leafA, twigA));\n}\n";
|
|
9
|
+
/**
|
|
10
|
+
* Wind in the canopies. A tree is anchored at the ground and bends more the higher the top is. Gusts travel across the landscape
|
|
11
|
+
* with the wind, every tree sways to them at its own rhythm and the canopy surface flutters slightly.
|
|
12
|
+
* The largest horizontal deflection is 1.03 × deflection × flexibility + 1.46 × flutter, the check of
|
|
13
|
+
* canopy setback from walls relies on it (see environment.ts).
|
|
14
|
+
*/
|
|
15
|
+
export declare const TREE_WIND = "\nvec3 treeWind(float heightFraction) {\n if (u_wind.z <= 0.0) return vec3(0.0);\n const float TAU = 6.2831853;\n vec2 dir = u_wind.xy;\n vec2 side = vec2(-dir.y, dir.x);\n float t = u_time.x;\n float own = i_extra.z * TAU;\n // Gust: a wave travelling with the wind. It is undulated across so its front is not ruler-straight.\n#ifdef WH_LOCAL_UP\n // Up is radial: gusts are placed by the position relative to the centre, and the bend lies in the local horizon.\n vec2 at = (i_base.xyz - u_upCenter.xyz).xz;\n#else\n vec2 at = i_base.xz;\n#endif\n float across = dot(at, side);\n float along = dot(at, dir) - u_gust.y * t;\n float gust = 0.5 + 0.5 * sin(along * u_gust.x + 1.4 * sin(across * 0.023) + across * u_gust.x * 0.31);\n float lean = 0.4 + 0.45 * gust + 0.15 * sin(t * 1.9 + own);\n float sway = 0.25 * sin(t * 1.3 + own * 1.7);\n vec2 bend = (dir * lean + side * sway) * (u_wind.z * i_extra.y * heightFraction * heightFraction);\n float ph = a_shade.w * TAU + own;\n vec3 flutter = vec3(sin(t * 5.3 + ph), 0.5 * sin(t * 4.1 + ph * 1.7), sin(t * 4.7 + ph * 2.3));\n#ifdef WH_LOCAL_UP\n return localFrame(i_base.xyz) * (vec3(bend.x, 0.0, bend.y) + flutter * (u_wind.w * a_shade.z * (0.6 + 0.4 * gust)));\n#else\n return vec3(bend.x, 0.0, bend.y) + flutter * (u_wind.w * a_shade.z * (0.6 + 0.4 * gust));\n#endif\n}\n";
|
|
16
|
+
export declare const TREE_VS = "#include <header>\n\nin vec3 a_pos; // canopy and trunk at unit height 0\u20131, horizontally in canopy radii\nin vec3 a_normal;\nin vec4 a_shade; // x vertex shading 0\u20131, y kind: 0 canopy, 1 trunk, z wind flutter 0\u20131, w phase 0\u20131\nin vec4 i_base; // xyz tree base, w canopy radius\nin vec4 i_shape; // x height, y cos of rotation, z sin of rotation, w hue 0\u20131\nin vec4 i_extra; // x canopy start (share of height), y flexibility in wind, z phase 0\u20131, w reserve\nuniform float u_trunkReach; // how far the trunk reaches into the canopy (share of the canopy): a part in summer, almost to the top for a bare tree\n// Share of the tree height at which the vertex lies. The canopy occupies the span from its start upward, the trunk reaches a bit into it.\nfloat treeHeightFraction() {\n float cb = i_extra.x;\n return mix(cb + a_pos.y * (1.0 - cb), a_pos.y * (cb + u_trunkReach * (1.0 - cb)), a_shade.y);\n}\nvec3 treeLocal() {\n return vec3(a_pos.x * i_base.w, treeHeightFraction() * i_shape.x, a_pos.z * i_base.w);\n}\nvec3 treeRotate(vec3 v) {\n#ifdef WH_LOCAL_UP\n // Up is radial: the instance stands in the local frame of its base.\n return localFrame(i_base.xyz) * vec3(v.x * i_shape.y - v.z * i_shape.z, v.y, v.x * i_shape.z + v.z * i_shape.y);\n#else\n return vec3(v.x * i_shape.y - v.z * i_shape.z, v.y, v.x * i_shape.z + v.z * i_shape.y);\n#endif\n}\n// Position in tree space for noise: every tree has its pattern shifted by its hue.\nvec3 treeObj(vec3 local) {\n return local + vec3(i_shape.w * 37.0, 0.0, i_shape.w * 11.0);\n}\n\nvec3 treeWind(float heightFraction) {\n if (u_wind.z <= 0.0) return vec3(0.0);\n const float TAU = 6.2831853;\n vec2 dir = u_wind.xy;\n vec2 side = vec2(-dir.y, dir.x);\n float t = u_time.x;\n float own = i_extra.z * TAU;\n // Gust: a wave travelling with the wind. It is undulated across so its front is not ruler-straight.\n#ifdef WH_LOCAL_UP\n // Up is radial: gusts are placed by the position relative to the centre, and the bend lies in the local horizon.\n vec2 at = (i_base.xyz - u_upCenter.xyz).xz;\n#else\n vec2 at = i_base.xz;\n#endif\n float across = dot(at, side);\n float along = dot(at, dir) - u_gust.y * t;\n float gust = 0.5 + 0.5 * sin(along * u_gust.x + 1.4 * sin(across * 0.023) + across * u_gust.x * 0.31);\n float lean = 0.4 + 0.45 * gust + 0.15 * sin(t * 1.9 + own);\n float sway = 0.25 * sin(t * 1.3 + own * 1.7);\n vec2 bend = (dir * lean + side * sway) * (u_wind.z * i_extra.y * heightFraction * heightFraction);\n float ph = a_shade.w * TAU + own;\n vec3 flutter = vec3(sin(t * 5.3 + ph), 0.5 * sin(t * 4.1 + ph * 1.7), sin(t * 4.7 + ph * 2.3));\n#ifdef WH_LOCAL_UP\n return localFrame(i_base.xyz) * (vec3(bend.x, 0.0, bend.y) + flutter * (u_wind.w * a_shade.z * (0.6 + 0.4 * gust)));\n#else\n return vec3(bend.x, 0.0, bend.y) + flutter * (u_wind.w * a_shade.z * (0.6 + 0.4 * gust));\n#endif\n}\n\nout vec3 v_world;\nout vec3 v_normal;\nout vec3 v_obj;\nout vec2 v_shade;\nflat out float v_tint;\nflat out float v_phase;\nvoid main() {\n vec3 local = treeLocal();\n // Light and shadows are computed from the rest position, wind moves only the outline. The shadow map is thus independent of time.\n v_world = i_base.xyz + treeRotate(local);\n // Normal under non-uniform scale: divided by the axis scale.\n v_normal = treeRotate(vec3(a_normal.x / i_base.w, a_normal.y / (i_shape.x * (1.0 - i_extra.x)), a_normal.z / i_base.w));\n v_obj = treeObj(local);\n v_shade = a_shade.xy;\n v_tint = i_shape.w;\n v_phase = i_extra.z;\n gl_Position = u_viewProj * vec4(v_world + treeWind(local.y / i_shape.x), 1.0);\n}";
|
|
17
|
+
export declare const TREE_FS = "#include <header>\n#include <noise>\n#include <lighting>\n#include <snow>\n\nuniform int u_evergreen;\nconst float TWIG_COVER = 0.55;\nfloat treeHashA(float tint, float phase) { return fract(tint * 7.31 + phase * 3.73); }\nfloat treeHashB(float tint, float phase) { return fract(tint * 13.7 + phase * 5.11); }\nfloat treeDensity(float tint, float phase) {\n if (u_evergreen != 0) return 1.0;\n float h = treeHashA(tint, phase);\n return smoothstep(h * 0.4, h * 0.4 + 0.6, u_season.x);\n}\n// x foliage coverage, y total coverage (foliage or branches). visC and visF: how sharply the coarse (tufts around a metre)\n// and the fine canopy detail are visible. What is not visible turns into average coverage, which alpha-to-coverage spreads over the samples.\nvec2 crownCover(vec3 obj, float dens, float visC, float visF) {\n if (dens >= 0.999) return vec2(1.0);\n float coarse = vnoise3(obj * 0.9, 44u);\n float fine = vnoise3(obj * 2.6, 45u);\n float nz = smoothstep(0.2, 0.8, mix(coarse, 0.55 * coarse + 0.45 * fine, visF));\n float edge = mix(0.22, 0.05, visF);\n float leafA = mix(dens, 1.0 - smoothstep(dens - edge, dens + edge, nz), visC);\n // Branches up close as sharp clusters (no sieve), from afar average coverage.\n float tw = smoothstep(0.5, 0.56, vnoise3(obj * 3.4 + 7.0, 46u));\n float twigA = mix(TWIG_COVER * 0.6, tw * 0.95, visF);\n return vec2(leafA, max(leafA, twigA));\n}\n\nuniform ivec4 u_rows; // palette rows: dark canopy, middle, light foliage, trunk\nuniform int u_rowAlt; // second hue of light foliage\nuniform ivec4 u_seasonRows; // palette rows: autumn yellow, orange, rust, bare branches\nuniform int u_springRow; // spring foliage\nin vec3 v_world;\nin vec3 v_normal;\nin vec3 v_obj;\nin vec2 v_shade;\nflat in float v_tint;\nflat in float v_phase;\nout vec4 o_color;\n\nvoid main() {\n vec3 n = normalize(v_normal);\n if (v_shade.y > 0.5) {\n float sunT = sunVisibility(v_world, n, 2.0);\n vec3 bark = u_palette[u_rows.w].rgb * (1.0 - 0.15 * u_weather.y);\n bark = mix(bark, u_snow.rgb, snowOn(v_world, n, 0.0));\n o_color = vec4(applyFog(toDisplay(bark * u_warmTint.rgb * lightOn(n, sunT, 0.6)), v_world), 1.0);\n return;\n }\n // Season: foliage density and autumn colour of this tree.\n float dens = treeDensity(v_tint, v_phase);\n vec2 cover = crownCover(v_obj, dens, detailVisible(1.1), detailVisible(0.35));\n if (cover.y < 0.03) discard;\n float leafShare = cover.x / cover.y;\n float aut = 0.0;\n vec3 autCol = vec3(0.0);\n if (u_evergreen == 0) {\n float hb = treeHashB(v_tint, v_phase);\n // Every tree changes colour at a different time, the latest ones stay half green even at the peak of autumn.\n aut = smoothstep(hb * 0.75, hb * 0.75 + 0.45, u_season.y);\n vec3 y = u_palette[u_seasonRows.x].rgb, o = u_palette[u_seasonRows.y].rgb, r = u_palette[u_seasonRows.z].rgb;\n autCol = hb < 0.45 ? mix(y, o, smoothstep(0.3, 0.45, hb)) : mix(o, r, smoothstep(0.6, 0.85, hb));\n }\n // Foliage tufts: noise in tree space. From afar it turns into the average.\n float clump = 0.6 * vnoise3(v_obj * 0.9, 41u) + 0.4 * vnoise3(v_obj * 2.6, 42u);\n clump = mix(0.5, clump, detailVisible(0.7));\n float fine = (vnoise3(v_obj * 9.0, 43u) - 0.5) * detailVisible(0.25);\n\n float sun = sunVisibility(v_world, n, 3.0);\n // Foliage lets light through, hence a softer transition than at a wall.\n float ndl = clamp((dot(n, u_sunDir.xyz) + 0.3) / 1.3, 0.0, 1.0);\n float lit = ndl * sun;\n float shade = v_shade.x * (0.7 + 0.6 * clump);\n\n vec3 deep = u_palette[u_rows.x].rgb;\n vec3 mid = u_palette[u_rows.y].rgb;\n vec3 leaf = mix(u_palette[u_rows.z].rgb, u_palette[u_rowAlt].rgb, v_tint * 0.6);\n if (u_evergreen == 0) {\n vec3 spring = u_palette[u_springRow].rgb;\n leaf = mix(leaf, spring, u_season.z * 0.45);\n mid = mix(mid, spring * 0.72, u_season.z * 0.25);\n deep = mix(deep, autCol * 0.38, aut * 0.55);\n mid = mix(mid, autCol * 0.66, aut);\n leaf = mix(leaf, autCol, aut);\n }\n // Canopy colour goes from almost black in the notches through dark green to lighter foliage only on lit bumps.\n vec3 col = mix(deep, mid, smoothstep(0.1, 0.8, shade));\n col = mix(col, leaf, smoothstep(0.22, 0.9, lit * (0.55 + clump)) * 0.85);\n col *= 1.0 + 0.5 * fine;\n col *= 0.96 + 0.24 * v_tint;\n // Bare branches: grey-brown lace, darker inside the canopy.\n vec3 twig = u_palette[u_seasonRows.w].rgb * (0.7 + 0.3 * clump) * mix(0.75, 1.05, v_shade.x);\n col = mix(twig, col, leafShare);\n col *= 1.0 - 0.12 * u_weather.y;\n // Snow on the upper side of the canopy. Needles and branches hold it, dense foliage less.\n float snow = snowOn(v_world, n, 0.08) * mix(0.9, 0.6, leafShare * float(u_evergreen == 0)) * smoothstep(0.35, 0.75, clump + 0.25);\n col = mix(col, u_snow.rgb * (0.92 + 0.12 * clump), snow);\n\n#ifdef WH_LOCAL_UP\n float nUp = dot(n, localUp(v_world));\n#else\n float nUp = n.y;\n#endif\n vec3 fill = (u_ambient.rgb + u_skyFill.rgb * (nUp * 0.5 + 0.5)) * mix(0.45, 1.0, v_shade.x);\n vec3 light = u_sunColor.rgb * lit * mix(0.6, 1.0, v_shade.x) + fill;\n o_color = vec4(applyFog(toDisplay(col * u_warmTint.rgb * light), v_world), cover.y);\n}";
|
|
18
|
+
export declare const DEPTH_TREE_VS = "#include <header>\nuniform mat4 u_lightRender;\n\nin vec3 a_pos; // canopy and trunk at unit height 0\u20131, horizontally in canopy radii\nin vec3 a_normal;\nin vec4 a_shade; // x vertex shading 0\u20131, y kind: 0 canopy, 1 trunk, z wind flutter 0\u20131, w phase 0\u20131\nin vec4 i_base; // xyz tree base, w canopy radius\nin vec4 i_shape; // x height, y cos of rotation, z sin of rotation, w hue 0\u20131\nin vec4 i_extra; // x canopy start (share of height), y flexibility in wind, z phase 0\u20131, w reserve\nuniform float u_trunkReach; // how far the trunk reaches into the canopy (share of the canopy): a part in summer, almost to the top for a bare tree\n// Share of the tree height at which the vertex lies. The canopy occupies the span from its start upward, the trunk reaches a bit into it.\nfloat treeHeightFraction() {\n float cb = i_extra.x;\n return mix(cb + a_pos.y * (1.0 - cb), a_pos.y * (cb + u_trunkReach * (1.0 - cb)), a_shade.y);\n}\nvec3 treeLocal() {\n return vec3(a_pos.x * i_base.w, treeHeightFraction() * i_shape.x, a_pos.z * i_base.w);\n}\nvec3 treeRotate(vec3 v) {\n#ifdef WH_LOCAL_UP\n // Up is radial: the instance stands in the local frame of its base.\n return localFrame(i_base.xyz) * vec3(v.x * i_shape.y - v.z * i_shape.z, v.y, v.x * i_shape.z + v.z * i_shape.y);\n#else\n return vec3(v.x * i_shape.y - v.z * i_shape.z, v.y, v.x * i_shape.z + v.z * i_shape.y);\n#endif\n}\n// Position in tree space for noise: every tree has its pattern shifted by its hue.\nvec3 treeObj(vec3 local) {\n return local + vec3(i_shape.w * 37.0, 0.0, i_shape.w * 11.0);\n}\n\nout vec3 v_obj;\nflat out vec3 v_tree; // hue, phase, trunk\nvoid main() {\n vec3 local = treeLocal();\n v_obj = treeObj(local);\n v_tree = vec3(i_shape.w, i_extra.z, a_shade.y);\n gl_Position = u_lightRender * vec4(i_base.xyz + treeRotate(local), 1.0);\n}";
|
|
19
|
+
/**
|
|
20
|
+
* Shadow of a sparse canopy: the fragment is discarded with a probability given by foliage and branch coverage. The threshold is a hash
|
|
21
|
+
* of the texel position, so the shadow is stable and soft shading turns it into a penumbra.
|
|
22
|
+
*/
|
|
23
|
+
export declare const DEPTH_TREE_FS = "#include <header>\n#include <noise>\n\nuniform int u_evergreen;\nconst float TWIG_COVER = 0.55;\nfloat treeHashA(float tint, float phase) { return fract(tint * 7.31 + phase * 3.73); }\nfloat treeHashB(float tint, float phase) { return fract(tint * 13.7 + phase * 5.11); }\nfloat treeDensity(float tint, float phase) {\n if (u_evergreen != 0) return 1.0;\n float h = treeHashA(tint, phase);\n return smoothstep(h * 0.4, h * 0.4 + 0.6, u_season.x);\n}\n// x foliage coverage, y total coverage (foliage or branches). visC and visF: how sharply the coarse (tufts around a metre)\n// and the fine canopy detail are visible. What is not visible turns into average coverage, which alpha-to-coverage spreads over the samples.\nvec2 crownCover(vec3 obj, float dens, float visC, float visF) {\n if (dens >= 0.999) return vec2(1.0);\n float coarse = vnoise3(obj * 0.9, 44u);\n float fine = vnoise3(obj * 2.6, 45u);\n float nz = smoothstep(0.2, 0.8, mix(coarse, 0.55 * coarse + 0.45 * fine, visF));\n float edge = mix(0.22, 0.05, visF);\n float leafA = mix(dens, 1.0 - smoothstep(dens - edge, dens + edge, nz), visC);\n // Branches up close as sharp clusters (no sieve), from afar average coverage.\n float tw = smoothstep(0.5, 0.56, vnoise3(obj * 3.4 + 7.0, 46u));\n float twigA = mix(TWIG_COVER * 0.6, tw * 0.95, visF);\n return vec2(leafA, max(leafA, twigA));\n}\n\nin vec3 v_obj;\nflat in vec3 v_tree;\nvoid main() {\n if (v_tree.z > 0.5) return;\n float dens = treeDensity(v_tree.x, v_tree.y);\n if (dens >= 0.999) return;\n float a = crownCover(v_obj, dens, 1.0, 1.0).y;\n if (a < hash2(ivec2(gl_FragCoord.xy), 17u)) discard;\n}";
|