wallhammer-web 0.0.0-stage → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +88 -2
- package/dist/base/data.d.ts +67 -0
- package/dist/base/data.js +10 -0
- package/dist/base/destructible.d.ts +167 -0
- package/dist/base/destructible.js +47 -0
- package/dist/base/env-slot.d.ts +101 -0
- package/dist/base/env-slot.js +8 -0
- package/dist/base/frames.d.ts +138 -0
- package/dist/base/frames.js +459 -0
- package/dist/base/index.d.ts +21 -0
- package/dist/base/index.js +11 -0
- package/dist/base/mat34.d.ts +46 -0
- package/dist/base/mat34.js +173 -0
- package/dist/base/material.d.ts +87 -0
- package/dist/base/material.js +6 -0
- package/dist/base/math.d.ts +27 -0
- package/dist/base/math.js +60 -0
- package/dist/base/progress.d.ts +38 -0
- package/dist/base/progress.js +81 -0
- package/dist/base/rig.d.ts +177 -0
- package/dist/base/rig.js +97 -0
- package/dist/base/trig.d.ts +29 -0
- package/dist/base/trig.js +169 -0
- package/dist/base/up.d.ts +26 -0
- package/dist/base/up.js +40 -0
- package/dist/base/view.d.ts +128 -0
- package/dist/base/view.js +136 -0
- package/dist/camera/camera.d.ts +99 -0
- package/dist/camera/camera.js +228 -0
- package/dist/camera/follow.d.ts +120 -0
- package/dist/camera/follow.js +320 -0
- package/dist/camera/free.d.ts +153 -0
- package/dist/camera/free.js +359 -0
- package/dist/camera/index.d.ts +10 -0
- package/dist/camera/index.js +6 -0
- package/dist/camera/orbit.d.ts +93 -0
- package/dist/camera/orbit.js +261 -0
- package/dist/camera/path.d.ts +48 -0
- package/dist/camera/path.js +179 -0
- package/dist/core/ballistic.d.ts +66 -0
- package/dist/core/ballistic.js +104 -0
- package/dist/core/bodies.d.ts +77 -0
- package/dist/core/bodies.js +125 -0
- package/dist/core/clock.d.ts +37 -0
- package/dist/core/clock.js +87 -0
- package/dist/core/cover-fade.d.ts +14 -0
- package/dist/core/cover-fade.js +38 -0
- package/dist/core/index.d.ts +13 -0
- package/dist/core/index.js +8 -0
- package/dist/core/kepler.d.ts +74 -0
- package/dist/core/kepler.js +108 -0
- package/dist/core/level-fade.d.ts +66 -0
- package/dist/core/level-fade.js +123 -0
- package/dist/core/palette.d.ts +15 -0
- package/dist/core/palette.js +47 -0
- package/dist/env/atmosphere.d.ts +129 -0
- package/dist/env/atmosphere.js +707 -0
- package/dist/env/cloud-field.d.ts +44 -0
- package/dist/env/cloud-field.js +111 -0
- package/dist/env/environment.d.ts +217 -0
- package/dist/env/environment.js +441 -0
- package/dist/env/frame-block.d.ts +29 -0
- package/dist/env/frame-block.js +152 -0
- package/dist/env/glsl.d.ts +35 -0
- package/dist/env/glsl.js +246 -0
- package/dist/env/index.d.ts +13 -0
- package/dist/env/index.js +9 -0
- package/dist/env/sky.d.ts +48 -0
- package/dist/env/sky.js +227 -0
- package/dist/env/sun.d.ts +31 -0
- package/dist/env/sun.js +42 -0
- package/dist/gen-arch/build.d.ts +17 -0
- package/dist/gen-arch/build.js +414 -0
- package/dist/gen-arch/damage/damaged.d.ts +44 -0
- package/dist/gen-arch/damage/damaged.js +1119 -0
- package/dist/gen-arch/damage/fall-material.d.ts +10 -0
- package/dist/gen-arch/damage/fall-material.js +47 -0
- package/dist/gen-arch/damage/fall.d.ts +78 -0
- package/dist/gen-arch/damage/fall.js +797 -0
- package/dist/gen-arch/damage/rubble.d.ts +22 -0
- package/dist/gen-arch/damage/rubble.js +188 -0
- package/dist/gen-arch/index.d.ts +25 -0
- package/dist/gen-arch/index.js +16 -0
- package/dist/gen-arch/interior/interior-plan.d.ts +114 -0
- package/dist/gen-arch/interior/interior-plan.js +615 -0
- package/dist/gen-arch/interior/interior.d.ts +97 -0
- package/dist/gen-arch/interior/interior.js +966 -0
- package/dist/gen-arch/structure/building-shader.d.ts +25 -0
- package/dist/gen-arch/structure/building-shader.js +946 -0
- package/dist/gen-arch/structure/buildings.d.ts +248 -0
- package/dist/gen-arch/structure/buildings.js +294 -0
- package/dist/gen-arch/structure/dims.d.ts +77 -0
- package/dist/gen-arch/structure/dims.js +39 -0
- package/dist/gen-arch/structure/distant.d.ts +62 -0
- package/dist/gen-arch/structure/distant.js +316 -0
- package/dist/gen-arch/structure/env-slots.d.ts +18 -0
- package/dist/gen-arch/structure/env-slots.js +47 -0
- package/dist/gen-arch/structure/facade.d.ts +193 -0
- package/dist/gen-arch/structure/facade.js +159 -0
- package/dist/gen-arch/structure/parts.d.ts +31 -0
- package/dist/gen-arch/structure/parts.js +69 -0
- package/dist/gen-arch/structure/roof.d.ts +76 -0
- package/dist/gen-arch/structure/roof.js +568 -0
- package/dist/gen-arch/structure/structure-material.d.ts +23 -0
- package/dist/gen-arch/structure/structure-material.js +55 -0
- package/dist/gen-arch/structure/writer.d.ts +94 -0
- package/dist/gen-arch/structure/writer.js +195 -0
- package/dist/gen-core/cell.d.ts +138 -0
- package/dist/gen-core/cell.js +150 -0
- package/dist/gen-core/cube-sphere.d.ts +57 -0
- package/dist/gen-core/cube-sphere.js +159 -0
- package/dist/gen-core/field.d.ts +55 -0
- package/dist/gen-core/field.js +154 -0
- package/dist/gen-core/geometry.d.ts +31 -0
- package/dist/gen-core/geometry.js +231 -0
- package/dist/gen-core/hash.d.ts +18 -0
- package/dist/gen-core/hash.js +58 -0
- package/dist/gen-core/height-field.d.ts +33 -0
- package/dist/gen-core/height-field.js +137 -0
- package/dist/gen-core/index.d.ts +22 -0
- package/dist/gen-core/index.js +17 -0
- package/dist/gen-core/instance-cells.d.ts +37 -0
- package/dist/gen-core/instance-cells.js +72 -0
- package/dist/gen-core/near-scatter.d.ts +56 -0
- package/dist/gen-core/near-scatter.js +120 -0
- package/dist/gen-core/noise.d.ts +23 -0
- package/dist/gen-core/noise.js +72 -0
- package/dist/gen-core/occupancy.d.ts +21 -0
- package/dist/gen-core/occupancy.js +104 -0
- package/dist/gen-core/sphere-patch.d.ts +138 -0
- package/dist/gen-core/sphere-patch.js +544 -0
- package/dist/gen-core/strip-surface.d.ts +34 -0
- package/dist/gen-core/strip-surface.js +246 -0
- package/dist/gen-core/strip.d.ts +102 -0
- package/dist/gen-core/strip.js +817 -0
- package/dist/gen-ground/env-slots.d.ts +48 -0
- package/dist/gen-ground/env-slots.js +78 -0
- package/dist/gen-ground/ground.d.ts +78 -0
- package/dist/gen-ground/ground.js +208 -0
- package/dist/gen-ground/index.d.ts +9 -0
- package/dist/gen-ground/index.js +7 -0
- package/dist/gen-ground/markings.d.ts +46 -0
- package/dist/gen-ground/markings.js +124 -0
- package/dist/gen-ground/materials.d.ts +18 -0
- package/dist/gen-ground/materials.js +22 -0
- package/dist/gen-ground/terrain-shader.d.ts +5 -0
- package/dist/gen-ground/terrain-shader.js +151 -0
- package/dist/gen-mesh/bare-shapes.d.ts +194 -0
- package/dist/gen-mesh/bare-shapes.js +596 -0
- package/dist/gen-mesh/bisect-surface.d.ts +47 -0
- package/dist/gen-mesh/bisect-surface.js +261 -0
- package/dist/gen-mesh/box.d.ts +18 -0
- package/dist/gen-mesh/box.js +2 -0
- package/dist/gen-mesh/cell-morph-mesh.d.ts +52 -0
- package/dist/gen-mesh/cell-morph-mesh.js +258 -0
- package/dist/gen-mesh/cell-surface-mesh.d.ts +32 -0
- package/dist/gen-mesh/cell-surface-mesh.js +140 -0
- package/dist/gen-mesh/chunk-mesh.d.ts +25 -0
- package/dist/gen-mesh/chunk-mesh.js +112 -0
- package/dist/gen-mesh/drape-mesh.d.ts +36 -0
- package/dist/gen-mesh/drape-mesh.js +98 -0
- package/dist/gen-mesh/height-field-mesh.d.ts +14 -0
- package/dist/gen-mesh/height-field-mesh.js +98 -0
- package/dist/gen-mesh/index.d.ts +26 -0
- package/dist/gen-mesh/index.js +15 -0
- package/dist/gen-mesh/line-mesh.d.ts +25 -0
- package/dist/gen-mesh/line-mesh.js +62 -0
- package/dist/gen-mesh/mesh-builder.d.ts +115 -0
- package/dist/gen-mesh/mesh-builder.js +315 -0
- package/dist/gen-mesh/packed-mesh.d.ts +53 -0
- package/dist/gen-mesh/packed-mesh.js +205 -0
- package/dist/gen-mesh/prism-mesh.d.ts +33 -0
- package/dist/gen-mesh/prism-mesh.js +176 -0
- package/dist/gen-mesh/rig-mesh.d.ts +9 -0
- package/dist/gen-mesh/rig-mesh.js +135 -0
- package/dist/gen-mesh/strip-mesh.d.ts +45 -0
- package/dist/gen-mesh/strip-mesh.js +258 -0
- package/dist/gen-plan/drain.d.ts +58 -0
- package/dist/gen-plan/drain.js +270 -0
- package/dist/gen-plan/grid.d.ts +37 -0
- package/dist/gen-plan/grid.js +182 -0
- package/dist/gen-plan/horizon.d.ts +50 -0
- package/dist/gen-plan/horizon.js +185 -0
- package/dist/gen-plan/index.d.ts +15 -0
- package/dist/gen-plan/index.js +13 -0
- package/dist/gen-plan/line-tiles.d.ts +35 -0
- package/dist/gen-plan/line-tiles.js +190 -0
- package/dist/gen-plan/lines.d.ts +31 -0
- package/dist/gen-plan/lines.js +183 -0
- package/dist/gen-plan/plots.d.ts +40 -0
- package/dist/gen-plan/plots.js +282 -0
- package/dist/gen-plan/route.d.ts +55 -0
- package/dist/gen-plan/route.js +297 -0
- package/dist/gen-plan/sites.d.ts +32 -0
- package/dist/gen-plan/sites.js +209 -0
- package/dist/gen-tex/code-stamp.d.ts +31 -0
- package/dist/gen-tex/code-stamp.js +137 -0
- package/dist/gen-tex/index.d.ts +7 -0
- package/dist/gen-tex/index.js +5 -0
- package/dist/gen-tex/light-horizon.d.ts +47 -0
- package/dist/gen-tex/light-horizon.js +180 -0
- package/dist/gen-tex/textures.d.ts +8 -0
- package/dist/gen-tex/textures.js +49 -0
- package/dist/gen-tex/value-textures.d.ts +46 -0
- package/dist/gen-tex/value-textures.js +102 -0
- package/dist/gen-vegetation/env-slots.d.ts +20 -0
- package/dist/gen-vegetation/env-slots.js +29 -0
- package/dist/gen-vegetation/index.d.ts +8 -0
- package/dist/gen-vegetation/index.js +7 -0
- package/dist/gen-vegetation/materials.d.ts +7 -0
- package/dist/gen-vegetation/materials.js +17 -0
- package/dist/gen-vegetation/planting.d.ts +170 -0
- package/dist/gen-vegetation/planting.js +363 -0
- package/dist/gen-vegetation/tree-shader.d.ts +23 -0
- package/dist/gen-vegetation/tree-shader.js +229 -0
- package/dist/gen-vegetation/trees.d.ts +59 -0
- package/dist/gen-vegetation/trees.js +329 -0
- package/dist/gpu/device.d.ts +286 -0
- package/dist/gpu/device.js +1157 -0
- package/dist/gpu/gl.d.ts +134 -0
- package/dist/gpu/gl.js +276 -0
- package/dist/gpu/index.d.ts +4 -0
- package/dist/gpu/index.js +3 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +13 -0
- package/dist/motion/graph.d.ts +244 -0
- package/dist/motion/graph.js +739 -0
- package/dist/motion/index.d.ts +8 -0
- package/dist/motion/index.js +8 -0
- package/dist/motion/pose-ops.d.ts +30 -0
- package/dist/motion/pose-ops.js +232 -0
- package/dist/motion/reach.d.ts +45 -0
- package/dist/motion/reach.js +264 -0
- package/dist/motion/skeleton.d.ts +49 -0
- package/dist/motion/skeleton.js +99 -0
- package/dist/platform/byte-store.d.ts +21 -0
- package/dist/platform/byte-store.js +137 -0
- package/dist/platform/canvas.d.ts +29 -0
- package/dist/platform/canvas.js +76 -0
- package/dist/platform/context-loss.d.ts +8 -0
- package/dist/platform/context-loss.js +17 -0
- package/dist/platform/free-input.d.ts +51 -0
- package/dist/platform/free-input.js +100 -0
- package/dist/platform/index.d.ts +18 -0
- package/dist/platform/index.js +10 -0
- package/dist/platform/input.d.ts +48 -0
- package/dist/platform/input.js +117 -0
- package/dist/platform/keys.d.ts +12 -0
- package/dist/platform/keys.js +29 -0
- package/dist/platform/loop.d.ts +41 -0
- package/dist/platform/loop.js +84 -0
- package/dist/platform/walk-input.d.ts +74 -0
- package/dist/platform/walk-input.js +226 -0
- package/dist/platform/worker.d.ts +51 -0
- package/dist/platform/worker.js +170 -0
- package/dist/render/bone-instances.d.ts +24 -0
- package/dist/render/bone-instances.js +74 -0
- package/dist/render/cells.d.ts +70 -0
- package/dist/render/cells.js +144 -0
- package/dist/render/glsl.d.ts +66 -0
- package/dist/render/glsl.js +173 -0
- package/dist/render/index.d.ts +26 -0
- package/dist/render/index.js +16 -0
- package/dist/render/instance-sets.d.ts +97 -0
- package/dist/render/instance-sets.js +241 -0
- package/dist/render/near-instances.d.ts +75 -0
- package/dist/render/near-instances.js +219 -0
- package/dist/render/particles.d.ts +63 -0
- package/dist/render/particles.js +215 -0
- package/dist/render/pieces.d.ts +57 -0
- package/dist/render/pieces.js +151 -0
- package/dist/render/point-lights.d.ts +97 -0
- package/dist/render/point-lights.js +243 -0
- package/dist/render/renderer.d.ts +447 -0
- package/dist/render/renderer.js +1100 -0
- package/dist/render/rig.d.ts +74 -0
- package/dist/render/rig.js +576 -0
- package/dist/render/shadow-areas.d.ts +49 -0
- package/dist/render/shadow-areas.js +125 -0
- package/dist/render/shadow-glsl.d.ts +12 -0
- package/dist/render/shadow-glsl.js +146 -0
- package/dist/render/transient.d.ts +61 -0
- package/dist/render/transient.js +213 -0
- package/dist/render/value-glsl.d.ts +17 -0
- package/dist/render/value-glsl.js +208 -0
- package/dist/render/value-layers.d.ts +180 -0
- package/dist/render/value-layers.js +333 -0
- package/dist/runtime/atmosphere.d.ts +37 -0
- package/dist/runtime/atmosphere.js +304 -0
- package/dist/runtime/cloud-shell.d.ts +29 -0
- package/dist/runtime/cloud-shell.js +158 -0
- package/dist/runtime/engine.d.ts +155 -0
- package/dist/runtime/engine.js +305 -0
- package/dist/runtime/environment-link.d.ts +22 -0
- package/dist/runtime/environment-link.js +49 -0
- package/dist/runtime/index.d.ts +13 -0
- package/dist/runtime/index.js +12 -0
- package/dist/runtime/precipitation-glsl.d.ts +2 -0
- package/dist/runtime/precipitation-glsl.js +70 -0
- package/dist/runtime/precipitation.d.ts +11 -0
- package/dist/runtime/precipitation.js +78 -0
- package/dist/runtime/sky.d.ts +30 -0
- package/dist/runtime/sky.js +114 -0
- package/dist/runtime/streaming.d.ts +245 -0
- package/dist/runtime/streaming.js +602 -0
- package/dist/sim/agenda.d.ts +167 -0
- package/dist/sim/agenda.js +425 -0
- package/dist/sim/bytes.d.ts +34 -0
- package/dist/sim/bytes.js +125 -0
- package/dist/sim/destruction/apply.d.ts +59 -0
- package/dist/sim/destruction/apply.js +243 -0
- package/dist/sim/destruction/cell-states.d.ts +54 -0
- package/dist/sim/destruction/cell-states.js +198 -0
- package/dist/sim/destruction/index.d.ts +11 -0
- package/dist/sim/destruction/index.js +10 -0
- package/dist/sim/destruction/int-geometry.d.ts +17 -0
- package/dist/sim/destruction/int-geometry.js +131 -0
- package/dist/sim/destruction/pick.d.ts +13 -0
- package/dist/sim/destruction/pick.js +59 -0
- package/dist/sim/destruction/rubble.d.ts +8 -0
- package/dist/sim/destruction/rubble.js +159 -0
- package/dist/sim/destruction/state.d.ts +15 -0
- package/dist/sim/destruction/state.js +83 -0
- package/dist/sim/destruction/structure.d.ts +30 -0
- package/dist/sim/destruction/structure.js +139 -0
- package/dist/sim/events.d.ts +37 -0
- package/dist/sim/events.js +106 -0
- package/dist/sim/fixed.d.ts +21 -0
- package/dist/sim/fixed.js +64 -0
- package/dist/sim/flow-probe.d.ts +58 -0
- package/dist/sim/flow-probe.js +158 -0
- package/dist/sim/flow.d.ts +257 -0
- package/dist/sim/flow.js +967 -0
- package/dist/sim/index.d.ts +28 -0
- package/dist/sim/index.js +20 -0
- package/dist/sim/interlock.d.ts +47 -0
- package/dist/sim/interlock.js +252 -0
- package/dist/sim/movers.d.ts +228 -0
- package/dist/sim/movers.js +1083 -0
- package/dist/sim/nav.d.ts +72 -0
- package/dist/sim/nav.js +292 -0
- package/dist/sim/paths.d.ts +80 -0
- package/dist/sim/paths.js +197 -0
- package/dist/sim/regions.d.ts +87 -0
- package/dist/sim/regions.js +517 -0
- package/dist/sim/simulation.d.ts +114 -0
- package/dist/sim/simulation.js +291 -0
- package/dist/sim/states.d.ts +23 -0
- package/dist/sim/states.js +54 -0
- package/dist/sim/table.d.ts +49 -0
- package/dist/sim/table.js +126 -0
- package/dist/sim/zones.d.ts +11 -0
- package/dist/sim/zones.js +196 -0
- package/dist/tools/collision-lines.d.ts +12 -0
- package/dist/tools/collision-lines.js +50 -0
- package/dist/tools/data-view-glsl.d.ts +3 -0
- package/dist/tools/data-view-glsl.js +63 -0
- package/dist/tools/data-view-layers.d.ts +20 -0
- package/dist/tools/data-view-layers.js +60 -0
- package/dist/tools/debug-view.d.ts +30 -0
- package/dist/tools/debug-view.js +4 -0
- package/dist/tools/index.d.ts +10 -0
- package/dist/tools/index.js +7 -0
- package/dist/tools/mesh-checks.d.ts +67 -0
- package/dist/tools/mesh-checks.js +188 -0
- package/dist/tools/profile.d.ts +85 -0
- package/dist/tools/profile.js +173 -0
- package/dist/world/cell-cache.d.ts +32 -0
- package/dist/world/cell-cache.js +60 -0
- package/dist/world/cell-format.d.ts +25 -0
- package/dist/world/cell-format.js +232 -0
- package/dist/world/collide.d.ts +192 -0
- package/dist/world/collide.js +822 -0
- package/dist/world/index.d.ts +16 -0
- package/dist/world/index.js +12 -0
- package/dist/world/mesh-solids.d.ts +48 -0
- package/dist/world/mesh-solids.js +169 -0
- package/dist/world/pick.d.ts +34 -0
- package/dist/world/pick.js +177 -0
- package/dist/world/providers.d.ts +66 -0
- package/dist/world/providers.js +83 -0
- package/dist/world/sphere.d.ts +69 -0
- package/dist/world/sphere.js +271 -0
- package/dist/world/streaming.d.ts +288 -0
- package/dist/world/streaming.js +801 -0
- package/dist/world/walker.d.ts +145 -0
- package/dist/world/walker.js +502 -0
- package/docs/architecture.md +111 -0
- package/docs/cameras.md +302 -0
- package/docs/concepts.md +123 -0
- package/docs/destruction.md +127 -0
- package/docs/frames.md +199 -0
- package/docs/generators.md +575 -0
- package/docs/getting-started.md +123 -0
- package/docs/headless.md +50 -0
- package/docs/motion.md +160 -0
- package/docs/planet.md +152 -0
- package/docs/recipes.md +521 -0
- package/docs/reference.md +364 -0
- package/docs/rendering.md +823 -0
- package/docs/rigs.md +203 -0
- package/docs/simulation.md +235 -0
- package/docs/streaming.md +590 -0
- package/docs/system.md +166 -0
- package/docs/tools.md +175 -0
- package/docs/walking.md +262 -0
- package/package.json +131 -3
|
@@ -0,0 +1,946 @@
|
|
|
1
|
+
// Buildings: façades with window rows per storey, plinth, cornice, roof covering. The shader draws all of it
|
|
2
|
+
// from the position on the wall that the generator wrote into the vertices. Patterns are analytically
|
|
3
|
+
// antialiased: once a window is smaller than a pixel the wall turns into its average colour and nothing shimmers.
|
|
4
|
+
//
|
|
5
|
+
// Two façade paths: the simple one (window style only) and the recipe path (facade.ts), selected per wall by
|
|
6
|
+
// the recipe bit. The recipe path adds a ground floor, entrances, window formats, frames, mullions, sills,
|
|
7
|
+
// curtains and blinds, stairwell strips, loggia recesses and prefab panel joints.
|
|
8
|
+
import { FACADE_DIM, FACADE_FLAG } from './facade.js';
|
|
9
|
+
import { ARCH_WINDOW_BIT, WIN_TALL } from './writer.js';
|
|
10
|
+
import { INTERIOR_DIM } from './dims.js';
|
|
11
|
+
export const BUILDING_VS = /* glsl */ `#include <header>
|
|
12
|
+
in vec3 a_pos;
|
|
13
|
+
in vec4 a_normal;
|
|
14
|
+
in vec4 a_surf;
|
|
15
|
+
in vec4 a_bld;
|
|
16
|
+
in uvec4 a_mat;
|
|
17
|
+
in vec4 a_fac;
|
|
18
|
+
in uvec4 a_win;
|
|
19
|
+
in uvec4 a_bits;
|
|
20
|
+
in uvec4 a_col;
|
|
21
|
+
out vec3 v_world;
|
|
22
|
+
// Rest position and normal: patterns are anchored to them, so they stay on a piece that moves (fallVs).
|
|
23
|
+
out vec3 v_pat;
|
|
24
|
+
flat out vec3 v_patN;
|
|
25
|
+
flat out vec3 v_normal;
|
|
26
|
+
flat out int v_kind;
|
|
27
|
+
flat out int v_damage;
|
|
28
|
+
out vec4 v_surf;
|
|
29
|
+
flat out vec4 v_bld;
|
|
30
|
+
flat out uvec4 v_mat;
|
|
31
|
+
flat out vec4 v_fac;
|
|
32
|
+
flat out uvec4 v_win;
|
|
33
|
+
flat out uvec4 v_bits;
|
|
34
|
+
flat out uvec4 v_col;
|
|
35
|
+
void main() {
|
|
36
|
+
vec3 pos = a_pos;
|
|
37
|
+
// Rubble that is still arriving grows up from its base (writer.ts, growIn).
|
|
38
|
+
if (a_fac.y < 0.0) {
|
|
39
|
+
float g = clamp((u_time.x - a_fac.x) / -a_fac.y, 0.0, 1.0);
|
|
40
|
+
pos.y = mix(a_fac.z, a_pos.y, g * g * (3.0 - 2.0 * g));
|
|
41
|
+
}
|
|
42
|
+
v_world = pos;
|
|
43
|
+
v_pat = pos;
|
|
44
|
+
v_patN = normalize(a_normal.xyz);
|
|
45
|
+
v_normal = normalize(a_normal.xyz);
|
|
46
|
+
// Low three bits: kind of surface; above them the damage level (writer.ts, DAMAGE_STEP).
|
|
47
|
+
int kindWord = int(a_normal.w);
|
|
48
|
+
v_kind = kindWord & 7;
|
|
49
|
+
v_damage = kindWord >> 3;
|
|
50
|
+
v_surf = a_surf;
|
|
51
|
+
v_bld = a_bld;
|
|
52
|
+
v_mat = a_mat;
|
|
53
|
+
v_fac = a_fac;
|
|
54
|
+
v_win = a_win;
|
|
55
|
+
v_bits = a_bits;
|
|
56
|
+
v_col = a_col;
|
|
57
|
+
gl_Position = u_viewProj * vec4(pos, 1.0);
|
|
58
|
+
}`;
|
|
59
|
+
/** Replaces `from` by `to` in `text`, and fails loudly when `from` is not there (the text changed shape). */
|
|
60
|
+
function must(text, from, to, what) {
|
|
61
|
+
const out = text.replace(from, to);
|
|
62
|
+
if (out === text)
|
|
63
|
+
throw new Error(`structure shader: ${what} changed shape`);
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* A vertex stage of the structure shaders turned into its framed form: positions and normals go through `u_frame`
|
|
68
|
+
* into render space, while `v_pat` and `v_patN` (patterns, damage) stay in the frame of the mesh.
|
|
69
|
+
*/
|
|
70
|
+
export function frameVs(vs) {
|
|
71
|
+
let out = must(vs, 'out vec3 v_world;\n', 'uniform mat4 u_frame; // frame of the mesh → render space\nout vec3 v_world;\n', 'frame uniform');
|
|
72
|
+
out = must(out, ' v_world = pos;\n', ' v_world = (u_frame * vec4(pos, 1.0)).xyz;\n', 'v_world');
|
|
73
|
+
out = must(out, /v_normal = normalize\((.+?)\);/, 'v_normal = normalize(mat3(u_frame) * ($1));', 'v_normal');
|
|
74
|
+
return must(out, 'gl_Position = u_viewProj * vec4(pos, 1.0);', 'gl_Position = u_viewProj * vec4(v_world, 1.0);', 'gl_Position');
|
|
75
|
+
}
|
|
76
|
+
/** Vertex stage of the structures; `BUILDING_VS` is `buildingVs()`. */
|
|
77
|
+
export function buildingVs(o = {}) {
|
|
78
|
+
return o.framed ? frameVs(BUILDING_VS) : BUILDING_VS;
|
|
79
|
+
}
|
|
80
|
+
const f = (v) => v.toFixed(3);
|
|
81
|
+
/**
|
|
82
|
+
* Fragment shader of the structures; `dims` sizes are baked in as constants. `damage` adds the damage shading of the
|
|
83
|
+
* vertex damage channel; it is a separate program, so intact structures pay nothing for it. `o` picks the framed and
|
|
84
|
+
* the finishes variant (see `StructureShaderOptions`); without it the text is that of the plain material.
|
|
85
|
+
*/
|
|
86
|
+
export function buildingFs(dims, damage = false, o = {}) {
|
|
87
|
+
const text = plainFs(dims, damage, o.finishes === true);
|
|
88
|
+
return o.framed ? frameFs(text, damage) : text;
|
|
89
|
+
}
|
|
90
|
+
/** The fragment stage turned into its framed form: every "up" is the y axis of the frame in render space. */
|
|
91
|
+
function frameFs(fs, damage) {
|
|
92
|
+
let out = must(fs, 'uniform ivec4 u_rows; // palette rows: glass, glass with sky reflection, plinth, unused\n', 'uniform ivec4 u_rows; // palette rows: glass, glass with sky reflection, plinth, unused\nuniform mat4 u_frame; // frame of the mesh → render space\n// Up of the frame of the mesh, in render space.\nvec3 frameUp() { return normalize(u_frame[1].xyz); }\n', 'frame uniform');
|
|
93
|
+
out = must(out, 'float s = v_surf.z / max(sqrt(1.0 - n.y * n.y), 0.2);', 'float ny = dot(n, frameUp());\n float s = v_surf.z / max(sqrt(1.0 - ny * ny), 0.2);', 'roof slope');
|
|
94
|
+
out = must(out, 'if (n.y < 0.5) ao =', 'if (dot(n, frameUp()) < 0.5) ao =', 'side faces');
|
|
95
|
+
if (damage) {
|
|
96
|
+
out = must(out, ' float up = clamp(u_sunDir.y * 4.0, 0.0, 1.0);\n vec2 s = u_sunDir.xz / max(length(u_sunDir.xz), 1e-3);', ' // The sun in the frame of the mesh, where the room directions are.\n vec3 sl = transpose(mat3(u_frame)) * u_sunDir.xyz;\n float up = clamp(sl.y * 4.0, 0.0, 1.0);\n vec2 s = sl.xz / max(length(sl.xz), 1e-3);', 'room fill');
|
|
97
|
+
}
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
/** Finishes of walls and covers of roofs (`materialCode`), only in the `finishes` variant. */
|
|
101
|
+
const FINISH_GLSL = (dims) => /* glsl */ `// Wall finish by the material byte (bits 2–3): 1 timber frame over the render, 2 coursed stone, 3 upright boards.
|
|
102
|
+
// gfH, fh: heights of the ground floor and of the storeys above; top: the eave above the floor base.
|
|
103
|
+
vec3 finishWall(vec3 col, uint seed, float u, float len, float yRel, float above, float gfH, float fh, float top) {
|
|
104
|
+
int finish = int((v_mat.z >> 2u) & 3u);
|
|
105
|
+
if (finish == 0) return col;
|
|
106
|
+
float fwU = fwidth(u), fwY = fwidth(yRel);
|
|
107
|
+
if (finish == 1) {
|
|
108
|
+
// Posts about every 1.2 m, rails at the storey lines, a diagonal brace in some fields; above the plinth only.
|
|
109
|
+
float plinth = max(float(v_win.w) * 0.02, ${f(dims.plinthHeight)});
|
|
110
|
+
float n = max(1.0, floor(len / 1.2 + 0.5));
|
|
111
|
+
float pw = len / n;
|
|
112
|
+
float cu = u / pw;
|
|
113
|
+
float post = pulseFaded(cu + 0.09 / pw, fwU / pw, 0.0, 0.18 / pw);
|
|
114
|
+
bool low = yRel < gfH;
|
|
115
|
+
float flH = low ? gfH : fh;
|
|
116
|
+
float sl = low ? yRel / gfH : 1.0 + (yRel - gfH) / fh;
|
|
117
|
+
float rail = pulseFaded(sl + 0.08 / flH, fwY / flH, 0.0, 0.16 / flH);
|
|
118
|
+
// The gable above the eave has rails every storey height as well, and its own fields.
|
|
119
|
+
float h = hash2(ivec2(int(floor(cu)), int(floor(sl))), seed + 61u);
|
|
120
|
+
float brace = 0.0;
|
|
121
|
+
if (h < 0.4) {
|
|
122
|
+
float fx = fract(cu), fy = fract(sl);
|
|
123
|
+
float d = h < 0.2 ? fx - fy : fx + fy - 1.0;
|
|
124
|
+
float dm = abs(d) * min(pw, flH) * 0.7071;
|
|
125
|
+
float fw = max(fwU, fwY);
|
|
126
|
+
brace = (1.0 - smoothstep(0.08 - fw, 0.08 + fw, dm)) * detailVisible(0.16);
|
|
127
|
+
}
|
|
128
|
+
float m = max(max(post, rail), brace) * boxCover(above, fwY, plinth, 1.0e4);
|
|
129
|
+
vec3 timber = u_palette[v_mat.w].rgb * (0.85 + 0.12 * hash1(seed + 63u));
|
|
130
|
+
return mix(col, timber, m * 0.95);
|
|
131
|
+
}
|
|
132
|
+
if (finish == 2) {
|
|
133
|
+
// Courses of 0.3 m, stones about 0.55 m long with staggered joints, a tone per stone.
|
|
134
|
+
float cv = yRel / 0.3;
|
|
135
|
+
float row = floor(cv);
|
|
136
|
+
float along = u / 0.55 + 0.5 * row;
|
|
137
|
+
float tone = hash2(ivec2(int(floor(along)), int(row)), seed + 62u);
|
|
138
|
+
col *= 1.0 + 0.24 * (tone - 0.5) * detailVisible(0.3);
|
|
139
|
+
float jh = pulseFaded(cv, fwY / 0.3, 0.0, 0.1);
|
|
140
|
+
float jv = pulseFaded(along, fwU / 0.55, 0.0, 0.055);
|
|
141
|
+
return col * (1.0 - 0.32 * max(jh, jv));
|
|
142
|
+
}
|
|
143
|
+
// Upright boards of 0.18 m with dark joints, a tone per board.
|
|
144
|
+
float cu = u / 0.18;
|
|
145
|
+
float tone = hash2(ivec2(int(floor(cu)), 3), seed + 64u);
|
|
146
|
+
col *= 1.0 + 0.18 * (tone - 0.5) * detailVisible(0.18);
|
|
147
|
+
col *= 0.94 + 0.08 * vnoise(vec2(u * 0.5, yRel * 4.0), seed + 65u) * detailVisible(0.1);
|
|
148
|
+
return col * (1.0 - 0.38 * pulseFaded(cu, fwU / 0.18, 0.0, 0.12));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Cover of a pitched roof by the material byte (bits 4–5): 1 thatch, 2 slate, 3 shingle. s: metres up the slope from
|
|
152
|
+
// the eave; across: metres along the eave (in the frame of the mesh).
|
|
153
|
+
vec3 coverRoof(vec3 base, uint seed, float s, float across) {
|
|
154
|
+
int cover = int((v_mat.z >> 4u) & 3u);
|
|
155
|
+
float ws = fwidth(s), wa = fwidth(across);
|
|
156
|
+
if (cover == 1) {
|
|
157
|
+
// Soft courses of 0.5 m, strong streaks down the fall line, a darker ragged eave.
|
|
158
|
+
base *= 1.0 - 0.12 * pulseFaded(s / 0.5, ws / 0.5, 0.0, 0.35);
|
|
159
|
+
float streak = vnoise(vec2(across * 7.0, s * 0.35), seed + 66u);
|
|
160
|
+
base *= 1.0 + 0.4 * (streak - 0.5) * detailVisible(0.12);
|
|
161
|
+
base *= 0.93 + 0.14 * vnoise(vec2(across, s) * 0.6, seed + 67u);
|
|
162
|
+
float edge = 0.3 + 0.22 * vnoise(vec2(across * 2.5, 0.5), seed + 68u);
|
|
163
|
+
return base * mix(0.62, 1.0, smoothstep(edge - 0.06 - ws, edge + 0.06 + ws, s));
|
|
164
|
+
}
|
|
165
|
+
float c = cover == 2 ? 0.25 : 0.18;
|
|
166
|
+
float pl = cover == 2 ? 0.4 : 0.22;
|
|
167
|
+
float row = floor(s / c);
|
|
168
|
+
float along = across / pl + 0.5 * row;
|
|
169
|
+
float tone = hash2(ivec2(int(floor(along)), int(row)), seed + 69u);
|
|
170
|
+
float vis = detailVisible(c);
|
|
171
|
+
base *= 1.0 + (cover == 2 ? 0.14 : 0.3) * (tone - 0.5) * vis;
|
|
172
|
+
float jh = pulseFaded(s / c, ws / c, 0.0, 0.14);
|
|
173
|
+
float jv = pulseFaded(along, wa / pl, 0.0, 0.05);
|
|
174
|
+
return base * (1.0 - 0.3 * max(jh, jv));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
`;
|
|
178
|
+
/** Shutter leaves beside a window of the recipe path, only in the `finishes` variant (inside `recipeWall`). */
|
|
179
|
+
const SHUTTER_GLSL = /* glsl */ ` if ((v_mat.z & 64u) != 0u && !balconyColumn) {
|
|
180
|
+
// A leaf on each side, 0.45 × the window width, with horizontal slats.
|
|
181
|
+
float sw = 0.45 * (x1 - x0), gap = 0.03 / colW;
|
|
182
|
+
float leaves = (cellBox(fu, fwu, x0 - gap - sw, x0 - gap) + cellBox(fu, fwu, x1 + gap, x1 + gap + sw)) * cellBox(fv, fwv, y0, y1) * inFloors;
|
|
183
|
+
vec3 sc = u_palette[v_col.w].rgb * (0.9 + 0.14 * pulseFaded(fv * flH / 0.12, fwv * flH / 0.12, 0.0, 0.5) * fine);
|
|
184
|
+
col = mix(col, sc, leaves);
|
|
185
|
+
}
|
|
186
|
+
`;
|
|
187
|
+
/** The fragment text without a frame; `finishes` adds the wall finishes, roof covers and shutters. */
|
|
188
|
+
function plainFs(dims, damage, finishes) {
|
|
189
|
+
const text = plainFsText(dims, damage, finishes);
|
|
190
|
+
return finishes ? text.split('int style = int(v_mat.z);').join('int style = int(v_mat.z & 3u);') : text;
|
|
191
|
+
}
|
|
192
|
+
const plainFsText = (dims, damage, finishes) => /* glsl */ `#include <header>
|
|
193
|
+
#include <noise>
|
|
194
|
+
#include <lighting>
|
|
195
|
+
#include <snow>
|
|
196
|
+
uniform ivec4 u_rows; // palette rows: glass, glass with sky reflection, plinth, unused
|
|
197
|
+
in vec3 v_world;
|
|
198
|
+
in vec3 v_pat;
|
|
199
|
+
flat in vec3 v_patN;
|
|
200
|
+
flat in vec3 v_normal;
|
|
201
|
+
flat in int v_kind;
|
|
202
|
+
flat in int v_damage;
|
|
203
|
+
in vec4 v_surf;
|
|
204
|
+
flat in vec4 v_bld;
|
|
205
|
+
flat in uvec4 v_mat;
|
|
206
|
+
flat in vec4 v_fac;
|
|
207
|
+
flat in uvec4 v_win;
|
|
208
|
+
flat in uvec4 v_bits;
|
|
209
|
+
flat in uvec4 v_col;
|
|
210
|
+
out vec4 o_color;
|
|
211
|
+
|
|
212
|
+
// Share of the interval [x − w/2, x + w/2] that lies inside [a, b].
|
|
213
|
+
float boxCover(float x, float w, float a, float b) {
|
|
214
|
+
w = max(w, 1e-5);
|
|
215
|
+
return clamp((min(x + 0.5 * w, b) - max(x - 0.5 * w, a)) / w, 0.0, 1.0);
|
|
216
|
+
}
|
|
217
|
+
// The same for a pattern repeating in every unit cell: a pulse from a to b.
|
|
218
|
+
float pulseIntegral(float x, float a, float b) {
|
|
219
|
+
return floor(x) * (b - a) + clamp(fract(x), a, b) - a;
|
|
220
|
+
}
|
|
221
|
+
float pulseCover(float x, float w, float a, float b) {
|
|
222
|
+
w = max(w, 1e-5);
|
|
223
|
+
return clamp((pulseIntegral(x + 0.5 * w, a, b) - pulseIntegral(x - 0.5 * w, a, b)) / w, 0.0, 1.0);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// A repeated pattern for drawing: antialiased over the pixel footprint and faded out as well. Box filtering
|
|
227
|
+
// alone is not enough: a pattern with a period of one to two pixels still beats with the screen grid and makes
|
|
228
|
+
// stripes. So below about three pixels per period it fades into its mean, and below two it is only the mean.
|
|
229
|
+
float pulseFaded(float x, float w, float a, float b) {
|
|
230
|
+
return mix(pulseCover(x, w, a, b), b - a, smoothstep(0.3, 0.5, w));
|
|
231
|
+
}
|
|
232
|
+
// The same for one rectangle inside a cell whose coordinate f runs 0–1 (w = cell coordinate per pixel).
|
|
233
|
+
float cellBox(float f, float w, float a, float b) {
|
|
234
|
+
return mix(boxCover(f, w, a, b), max(b - a, 0.0), smoothstep(0.3, 0.5, w));
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
${finishes ? FINISH_GLSL(dims) : ''}// Light of lit windows at the current wall point: lamp colour, zero where nothing is lit.
|
|
238
|
+
vec3 g_windowGlow = vec3(0.0);
|
|
239
|
+
|
|
240
|
+
vec3 wallColor(uint seed) {
|
|
241
|
+
float u = v_surf.x, len = v_surf.y, yRel = v_surf.z, above = v_surf.w;
|
|
242
|
+
float floorH = v_bld.x, floors = v_bld.y, bay = v_bld.w;
|
|
243
|
+
int style = int(v_mat.z);
|
|
244
|
+
vec3 trim = u_palette[v_mat.w].rgb;
|
|
245
|
+
|
|
246
|
+
// Building tint and slow plaster blotches.
|
|
247
|
+
vec3 wall = u_palette[v_mat.x].rgb * (0.88 + 0.22 * hash1(seed + 1u));
|
|
248
|
+
wall *= mix(vec3(1.0), vec3(1.05, 1.0, 0.9), hash1(seed + 2u));
|
|
249
|
+
wall *= 0.95 + 0.1 * vnoise(vec2(u, yRel) * 0.4, seed);
|
|
250
|
+
vec3 col = ${finishes ? 'finishWall(wall, seed, u, len, yRel, above, floorH, floorH, floors * floorH)' : 'wall'};
|
|
251
|
+
|
|
252
|
+
float fwU = fwidth(u), fwY = fwidth(yRel);
|
|
253
|
+
float top = floors * floorH;
|
|
254
|
+
|
|
255
|
+
if (style != 0 && len > bay * 0.7) {
|
|
256
|
+
float n = max(1.0, floor(len / bay + 0.5));
|
|
257
|
+
float bayW = len / n;
|
|
258
|
+
float cu = u / bayW, cv = yRel / floorH;
|
|
259
|
+
float fu = fwU / bayW, fv = fwY / floorH;
|
|
260
|
+
// Window width, height and sill as a share of the cell.
|
|
261
|
+
float ww, wh, sill;
|
|
262
|
+
if (style == 2) { ww = 0.8; wh = 0.48; sill = 0.3; }
|
|
263
|
+
else if (style == 3) { ww = 0.36; wh = 0.3; sill = 0.42; }
|
|
264
|
+
else { ww = clamp(1.5 / bayW, 0.38, 0.66); wh = clamp(1.65 / floorH, 0.3, 0.62); sill = 0.9 / floorH; }
|
|
265
|
+
float inFloors = boxCover(yRel, fwY, 0.0, top);
|
|
266
|
+
float gx = pulseFaded(cu, fu, 0.5 - 0.5 * ww, 0.5 + 0.5 * ww);
|
|
267
|
+
float gy = pulseFaded(cv, fv, sill, sill + wh);
|
|
268
|
+
float glass = gx * gy * inFloors;
|
|
269
|
+
float fr = 0.09 / bayW, frV = 0.09 / floorH;
|
|
270
|
+
float frame = pulseFaded(cu, fu, 0.5 - 0.5 * ww - fr, 0.5 + 0.5 * ww + fr)
|
|
271
|
+
* pulseFaded(cv, fv, sill - 1.6 * frV, sill + wh + frV) * inFloors;
|
|
272
|
+
// Every window has its own glass tone. From afar, where windows merge, it turns into the mean.
|
|
273
|
+
float r = hash2(ivec2(floor(cu), floor(cv)), seed + uint(len * 31.0));
|
|
274
|
+
float vis = detailVisible(bayW * 0.6);
|
|
275
|
+
float bright = mix(0.3, r * r, vis);
|
|
276
|
+
// Sky reflection in the upper part of the window.
|
|
277
|
+
float inWin = clamp((fract(cv) - sill) / wh, 0.0, 1.0);
|
|
278
|
+
vec3 glassCol = mix(u_palette[u_rows.x].rgb, u_palette[u_rows.y].rgb, bright * (0.55 + 0.45 * mix(0.5, inWin, vis)));
|
|
279
|
+
col = mix(col, trim, frame * 0.8);
|
|
280
|
+
col = mix(col, glassCol, glass);
|
|
281
|
+
if (u_time.z > 0.0) {
|
|
282
|
+
// Windows are lit in the evening. Each window decides by its own hash against the share of lit windows,
|
|
283
|
+
// so they turn on and off one by one. Every house has its habit: lights almost everywhere or almost
|
|
284
|
+
// nowhere, fewer in halls and works (strip and sparse windows) than in flats.
|
|
285
|
+
float habit = 0.35 + 1.3 * hash1(seed + 9u);
|
|
286
|
+
float share = clamp(u_time.w * habit * (style == 1 ? 1.0 : 0.55), 0.0, 0.95);
|
|
287
|
+
float h = hash2(ivec2(floor(cu), floor(cv)), seed + 77u + uint(len * 31.0));
|
|
288
|
+
float on = 1.0 - smoothstep(share - 0.012, share + 0.012, h);
|
|
289
|
+
// From afar, where windows merge, the wall glows with the mean.
|
|
290
|
+
on = mix(share, on, vis);
|
|
291
|
+
// Warm bulbs, now and then a cooler fluorescent tube. Brightness differs a little per window.
|
|
292
|
+
vec3 lamp = mix(vec3(1.0, 0.74, 0.38), vec3(0.86, 0.9, 0.82), step(0.82, r));
|
|
293
|
+
g_windowGlow = lamp * (glass * on * (0.75 + 0.5 * mix(0.5, fract(h * 53.0), vis)));
|
|
294
|
+
}
|
|
295
|
+
// Thin line at every storey's ceiling.
|
|
296
|
+
col *= 1.0 - 0.1 * pulseFaded(cv, fv, 0.0, 0.04) * inFloors;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// Cornice under the roof and plinth at the ground.
|
|
300
|
+
col = mix(col, trim, 0.55 * boxCover(yRel, fwY, top - 0.18, top + 0.7));
|
|
301
|
+
col = mix(col, u_palette[u_rows.z].rgb, 0.85 * boxCover(above, fwY, -1000.0, ${f(dims.plinthHeight)}));
|
|
302
|
+
return col;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// --- Recipe path ------------------------------------------------------------------------------------------
|
|
306
|
+
|
|
307
|
+
// Share of windows lit tonight in this house, and whether a given window is lit (0–1, mean from afar).
|
|
308
|
+
float litShare(uint seed, float factor) {
|
|
309
|
+
float habit = 0.35 + 1.3 * hash1(seed + 9u);
|
|
310
|
+
return clamp(u_time.w * habit * factor, 0.0, 0.95);
|
|
311
|
+
}
|
|
312
|
+
float litWindow(float share, float h, float vis) {
|
|
313
|
+
float on = 1.0 - smoothstep(share - 0.012, share + 0.012, h);
|
|
314
|
+
return mix(share, on, vis);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// Window cell of the recipe façade at a wall point: column and storey, the window rectangle in the cell and which
|
|
318
|
+
// columns hold doors, stairwell strips and balconies. Shared by the outer face and the inner face (wallInside).
|
|
319
|
+
struct RCell {
|
|
320
|
+
float colW, cu, column, fu, fwu, fl, flH, fv, fwv, vis, doorH, top, inFloors, ww, y0, y1;
|
|
321
|
+
int c4;
|
|
322
|
+
bool groundFloor, hasDoor, doorColumn, stairColumn, balconyColumn, windows;
|
|
323
|
+
};
|
|
324
|
+
RCell recipeCell(float u, float len, float yRel, float fwU, float fwY) {
|
|
325
|
+
float fh = v_bld.x, floors = v_bld.y, bay = v_bld.w;
|
|
326
|
+
float gfH = v_fac.w;
|
|
327
|
+
uint flags = v_bits.x;
|
|
328
|
+
// Bit 7 of bits.y: arched window, its height stored on the tall scale.
|
|
329
|
+
bool archWin = (v_bits.y & ${ARCH_WINDOW_BIT}u) != 0u;
|
|
330
|
+
float winW = float(v_win.x) * 0.02, winH = float(v_win.y) * 0.02 * (archWin ? ${f(WIN_TALL)} : 1.0), sill = float(v_win.z) * 0.02;
|
|
331
|
+
int gfKind = int((v_bits.y >> 2u) & 3u);
|
|
332
|
+
int doorKind = int((v_bits.y >> 4u) & 7u);
|
|
333
|
+
uint balMask = v_bits.w & 15u, narrowMask = v_bits.w >> 4u;
|
|
334
|
+
bool blindWall = (flags & ${FACADE_FLAG.blind}u) != 0u;
|
|
335
|
+
bool stairStrip = (flags & ${FACADE_FLAG.stairStrip}u) != 0u;
|
|
336
|
+
bool balconies = (flags & ${FACADE_FLAG.balconies}u) != 0u;
|
|
337
|
+
float top = gfH + (floors - 1.0) * fh;
|
|
338
|
+
float inFloors = boxCover(yRel, fwY, 0.0, top);
|
|
339
|
+
|
|
340
|
+
// Window columns along the wall, storeys up the wall (the ground floor has its own height).
|
|
341
|
+
float n = max(1.0, floor(len / bay + 0.5));
|
|
342
|
+
float colW = len / n;
|
|
343
|
+
float cu = u / colW;
|
|
344
|
+
float column = floor(cu);
|
|
345
|
+
float fu = fract(cu);
|
|
346
|
+
float fwu = fwU / colW;
|
|
347
|
+
bool groundFloor = yRel < gfH;
|
|
348
|
+
float fl = groundFloor ? 0.0 : 1.0 + floor((yRel - gfH) / fh);
|
|
349
|
+
float flH = groundFloor ? gfH : fh;
|
|
350
|
+
float fv = groundFloor ? yRel / gfH : fract((yRel - gfH) / fh);
|
|
351
|
+
float fwv = fwY / flH;
|
|
352
|
+
int c4 = int(mod(column, 4.0));
|
|
353
|
+
float vis = detailVisible(colW * 0.6);
|
|
354
|
+
|
|
355
|
+
bool hasDoor = doorKind > 0;
|
|
356
|
+
float doorCol = floor(v_fac.x / colW);
|
|
357
|
+
bool doorColumn = hasDoor && column == doorCol;
|
|
358
|
+
float doorH = doorKind == 4 ? v_fac.y * ${f(FACADE_DIM.archHeightPerWidth)} : doorKind == 2 ? ${f(FACADE_DIM.garageDoorHeight)} : doorKind == 3 ? ${f(FACADE_DIM.portalHeight)} : ${f(FACADE_DIM.doorHeight)};
|
|
359
|
+
bool stairColumn = doorColumn && stairStrip && doorKind != 2;
|
|
360
|
+
bool balconyColumn = balconies && !groundFloor && ((balMask >> uint(c4)) & 1u) != 0u && !stairColumn;
|
|
361
|
+
|
|
362
|
+
// Window rectangle in the cell (x across the column, y up the storey), by storey and column format.
|
|
363
|
+
float ww = winW * (((narrowMask >> uint(c4)) & 1u) != 0u ? 0.55 : 1.0) / colW;
|
|
364
|
+
float y0 = sill / flH, y1 = (sill + winH) / flH;
|
|
365
|
+
bool windows = !blindWall;
|
|
366
|
+
if (groundFloor) {
|
|
367
|
+
if (gfKind == 1) { ww = min(0.82, (colW - 0.5) / colW); y0 = 0.4 / gfH; y1 = (gfH - 0.45) / gfH; }
|
|
368
|
+
else if (gfKind == 2) { ww *= 0.85; y0 = (gfH - 1.15) / gfH; y1 = (gfH - 0.45) / gfH; }
|
|
369
|
+
else if (gfKind == 3) windows = false;
|
|
370
|
+
if (doorColumn) windows = false;
|
|
371
|
+
}
|
|
372
|
+
if (stairColumn) windows = false;
|
|
373
|
+
// A balcony door reaches down to the floor behind the parapet.
|
|
374
|
+
if (balconyColumn) y0 = 0.06 / flH;
|
|
375
|
+
ww = min(ww, 0.86);
|
|
376
|
+
|
|
377
|
+
RCell k;
|
|
378
|
+
k.colW = colW; k.cu = cu; k.column = column; k.fu = fu; k.fwu = fwu; k.fl = fl; k.flH = flH; k.fv = fv; k.fwv = fwv;
|
|
379
|
+
k.vis = vis; k.doorH = doorH; k.top = top; k.inFloors = inFloors; k.ww = ww; k.y0 = y0; k.y1 = y1; k.c4 = c4;
|
|
380
|
+
k.groundFloor = groundFloor; k.hasDoor = hasDoor; k.doorColumn = doorColumn; k.stairColumn = stairColumn;
|
|
381
|
+
k.balconyColumn = balconyColumn; k.windows = windows;
|
|
382
|
+
return k;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
vec3 recipeWall(uint seed) {
|
|
386
|
+
float u = v_surf.x, len = v_surf.y, yRel = v_surf.z, above = v_surf.w;
|
|
387
|
+
float fh = v_bld.x;
|
|
388
|
+
float gfH = v_fac.w;
|
|
389
|
+
uint flags = v_bits.x;
|
|
390
|
+
vec3 trim = u_palette[v_mat.w].rgb;
|
|
391
|
+
vec3 frameC = u_palette[v_col.x].rgb;
|
|
392
|
+
vec3 plinthC = u_palette[v_col.y].rgb;
|
|
393
|
+
vec3 doorC = u_palette[v_col.z].rgb;
|
|
394
|
+
float plinthH = float(v_win.w) * 0.02;
|
|
395
|
+
int mullions = int(v_bits.y & 3u);
|
|
396
|
+
int gfKind = int((v_bits.y >> 2u) & 3u);
|
|
397
|
+
int doorKind = int((v_bits.y >> 4u) & 7u);
|
|
398
|
+
bool archWin = (v_bits.y & ${ARCH_WINDOW_BIT}u) != 0u;
|
|
399
|
+
float curtainShare = float(v_bits.z & 15u) / 15.0, blindShare = float(v_bits.z >> 4u) / 15.0;
|
|
400
|
+
bool loggia = (flags & ${FACADE_FLAG.loggia}u) != 0u;
|
|
401
|
+
uint wallSeed = seed + uint(len * 31.0);
|
|
402
|
+
|
|
403
|
+
// Building tint: wider spread than the simple path, so neighbours differ more. Slow plaster blotches.
|
|
404
|
+
vec3 col = u_palette[v_mat.x].rgb * (0.84 + 0.3 * hash1(seed + 1u));
|
|
405
|
+
col *= mix(vec3(1.0), vec3(1.06, 1.0, 0.88), hash1(seed + 2u));
|
|
406
|
+
col *= mix(vec3(1.0), vec3(0.95, 0.99, 1.04), hash1(seed + 4u));
|
|
407
|
+
col *= 0.95 + 0.1 * vnoise(vec2(u, yRel) * 0.4, seed);
|
|
408
|
+
${finishes ? ' col = finishWall(col, seed, u, len, yRel, above, gfH, fh, gfH + (v_bld.y - 1.0) * fh);\n' : ''}
|
|
409
|
+
float fwU = fwidth(u), fwY = fwidth(yRel);
|
|
410
|
+
RCell k = recipeCell(u, len, yRel, fwU, fwY);
|
|
411
|
+
float top = k.top, inFloors = k.inFloors;
|
|
412
|
+
float colW = k.colW, cu = k.cu, column = k.column, fu = k.fu, fwu = k.fwu;
|
|
413
|
+
bool groundFloor = k.groundFloor;
|
|
414
|
+
float fl = k.fl, flH = k.flH, fv = k.fv, fwv = k.fwv;
|
|
415
|
+
int c4 = k.c4;
|
|
416
|
+
float vis = k.vis;
|
|
417
|
+
bool hasDoor = k.hasDoor, stairColumn = k.stairColumn, balconyColumn = k.balconyColumn, windows = k.windows;
|
|
418
|
+
float doorH = k.doorH;
|
|
419
|
+
float doorTopRel = v_fac.z + doorH - (v_pat.y - yRel);
|
|
420
|
+
float ww = k.ww, y0 = k.y0, y1 = k.y1;
|
|
421
|
+
|
|
422
|
+
// Prefab panels: a slight tone per panel, joints along storeys and columns.
|
|
423
|
+
if ((flags & ${FACADE_FLAG.panelJoints}u) != 0u) {
|
|
424
|
+
float jl = (yRel - gfH) / fh;
|
|
425
|
+
float tone = hash2(ivec2(int(column), int(floor(jl))), seed + 21u) - 0.5;
|
|
426
|
+
col *= 1.0 + 0.09 * tone * detailVisible(min(colW, fh) * 0.5);
|
|
427
|
+
float jh = pulseFaded(jl + 0.5 * 0.05 / fh, fwY / fh, 0.0, 0.05 / fh);
|
|
428
|
+
float jv = pulseFaded(cu + 0.5 * 0.05 / colW, fwu, 0.0, 0.05 / colW);
|
|
429
|
+
col *= 1.0 - 0.22 * max(jh, jv) * inFloors;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// Loggia recess: the band between the parapet and the slab above lies in deep shade.
|
|
433
|
+
if (balconyColumn && loggia) {
|
|
434
|
+
float bw = min(${f(FACADE_DIM.balconyColumnShare)}, ${f(FACADE_DIM.balconyMaxWidth)} / colW);
|
|
435
|
+
float recess = cellBox(fu, fwu, 0.5 - 0.5 * bw, 0.5 + 0.5 * bw) * cellBox(fv, fwv, 0.0, 1.0 - ${f(FACADE_DIM.balconySlab)} / flH);
|
|
436
|
+
col = mix(col, col * 0.5, recess * inFloors);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// Rain streaks under windows, darkest right under the sill.
|
|
440
|
+
if (windows) {
|
|
441
|
+
float sx = cellBox(fu, fwu, 0.5 - 0.42 * ww, 0.5 + 0.42 * ww);
|
|
442
|
+
float below = clamp(1.0 - (y0 - fv) * flH / 1.1, 0.0, 1.0) * step(fv, y0);
|
|
443
|
+
col *= 1.0 - 0.07 * sx * below * inFloors * detailVisible(0.6);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
if (windows) {
|
|
447
|
+
float x0 = 0.5 - 0.5 * ww, x1 = 0.5 + 0.5 * ww;
|
|
448
|
+
float gx = cellBox(fu, fwu, x0, x1);
|
|
449
|
+
float gy = cellBox(fv, fwv, y0, y1);
|
|
450
|
+
float glass = gx * gy * inFloors;
|
|
451
|
+
float fr = 0.07 / colW, frV = 0.07 / flH;
|
|
452
|
+
float frame = cellBox(fu, fwu, x0 - fr, x1 + fr) * cellBox(fv, fwv, y0 - frV, y1 + frV) * inFloors;
|
|
453
|
+
if (archWin) {
|
|
454
|
+
// Half-round head as wide as the window: above the spring line only the half circle stays glass and frame.
|
|
455
|
+
float rr = 0.5 * (x1 - x0) * colW;
|
|
456
|
+
vec2 p = vec2((fu - 0.5) * colW, (fv - y1) * flH + rr);
|
|
457
|
+
float fwd = max(fwU, fwY);
|
|
458
|
+
float d = p.y > 0.0 ? length(p) : 0.0;
|
|
459
|
+
glass *= 1.0 - smoothstep(rr - fwd, rr + fwd, d);
|
|
460
|
+
frame *= 1.0 - smoothstep(rr + 0.07 - fwd, rr + 0.07 + fwd, d);
|
|
461
|
+
}
|
|
462
|
+
// Sill: a light ledge under the window, a little wider than the frame.
|
|
463
|
+
float sillBand = cellBox(fu, fwu, x0 - 2.0 * fr, x1 + 2.0 * fr) * cellBox(fv, fwv, y0 - 0.07 / flH - frV, y0 - frV) * inFloors;
|
|
464
|
+
// Position inside the glass (0–1) for bars, curtains and blinds.
|
|
465
|
+
float wx = (fu - x0) / max(x1 - x0, 1e-4);
|
|
466
|
+
float wy = (fv - y0) / max(y1 - y0, 1e-4);
|
|
467
|
+
float fwx = fwu / max(x1 - x0, 1e-4), fwy = fwv / max(y1 - y0, 1e-4);
|
|
468
|
+
float winWm = (x1 - x0) * colW, winHm = (y1 - y0) * flH;
|
|
469
|
+
float bar = 0.0;
|
|
470
|
+
float bw = 0.06 / winWm;
|
|
471
|
+
if (mullions == 1 || (mullions == 2 && winWm < 1.3)) bar = cellBox(wx, fwx, 0.5 - bw, 0.5 + bw);
|
|
472
|
+
else if (mullions == 2) bar = max(cellBox(wx, fwx, 0.333 - bw, 0.333 + bw), cellBox(wx, fwx, 0.667 - bw, 0.667 + bw));
|
|
473
|
+
if ((flags & ${FACADE_FLAG.transom}u) != 0u && !balconyColumn) bar = max(bar, cellBox(wy, fwy, 0.7 - 0.06 / winHm, 0.7 + 0.06 / winHm));
|
|
474
|
+
|
|
475
|
+
ivec2 cell = ivec2(int(column), int(fl));
|
|
476
|
+
float r = hash2(cell, wallSeed);
|
|
477
|
+
float bright = mix(0.3, r * r, vis);
|
|
478
|
+
vec3 glassCol = mix(u_palette[u_rows.x].rgb, u_palette[u_rows.y].rgb, bright * (0.55 + 0.45 * mix(0.5, clamp(wy, 0.0, 1.0), vis)));
|
|
479
|
+
// Curtains (side panels) and blinds (lowered from the top), chosen per window.
|
|
480
|
+
float hc = hash2(cell, wallSeed + 131u);
|
|
481
|
+
float fine = detailVisible(winWm * 0.25);
|
|
482
|
+
float curtain = 0.0, blind = 0.0;
|
|
483
|
+
if (hc < curtainShare) curtain = max(cellBox(wx, fwx, 0.0, 0.2 + 0.1 * r), cellBox(wx, fwx, 0.8 - 0.1 * r, 1.0));
|
|
484
|
+
else if (hc < curtainShare + blindShare) {
|
|
485
|
+
float depth = 0.25 + 0.65 * fract(hc * 37.0);
|
|
486
|
+
blind = cellBox(wy, fwy, 1.0 - depth, 1.0) * (0.92 + 0.08 * pulseFaded(wy * winHm / 0.07, fwy * winHm / 0.07, 0.0, 0.5));
|
|
487
|
+
}
|
|
488
|
+
vec3 cloth = mix(frameC, vec3(0.78, 0.70, 0.58), 0.55);
|
|
489
|
+
glassCol = mix(glassCol, cloth * 0.85, 0.75 * curtain * fine);
|
|
490
|
+
glassCol = mix(glassCol, frameC * 0.88, blind * fine);
|
|
491
|
+
// Mean of curtains and blinds from afar, so the wall does not change tone between zooms.
|
|
492
|
+
glassCol = mix(glassCol, mix(glassCol, cloth * 0.85, 0.12 * curtainShare + 0.3 * blindShare), 1.0 - fine);
|
|
493
|
+
|
|
494
|
+
${finishes ? SHUTTER_GLSL : ''} col = mix(col, mix(frameC, vec3(0.9, 0.88, 0.84), 0.35), sillBand * 0.85);
|
|
495
|
+
col = mix(col, frameC, frame * 0.85);
|
|
496
|
+
col = mix(col, glassCol, glass);
|
|
497
|
+
col = mix(col, frameC, glass * bar * 0.9);
|
|
498
|
+
if (u_time.z > 0.0) {
|
|
499
|
+
float share = litShare(seed, groundFloor && gfKind != 0 ? 0.5 : 1.0);
|
|
500
|
+
float h = hash2(cell, seed + 77u + uint(len * 31.0));
|
|
501
|
+
float on = litWindow(share, h, vis);
|
|
502
|
+
vec3 lamp = mix(vec3(1.0, 0.74, 0.38), vec3(0.86, 0.9, 0.82), step(0.82, r));
|
|
503
|
+
// A curtain warms and dims the light, a blind holds most of it back.
|
|
504
|
+
float pass = 1.0 - 0.75 * blind * fine - 0.3 * curtain * fine;
|
|
505
|
+
lamp *= mix(vec3(1.0), vec3(1.0, 0.85, 0.7), curtain * fine);
|
|
506
|
+
g_windowGlow = lamp * (glass * (1.0 - bar) * on * pass * (0.75 + 0.5 * mix(0.5, fract(h * 53.0), vis)));
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// Stairwell strip above the entrance: landing windows half a storey off the flat windows.
|
|
511
|
+
if (stairColumn) {
|
|
512
|
+
float tl = (yRel - gfH) / fh + 0.5;
|
|
513
|
+
float k = floor(tl);
|
|
514
|
+
float bottom = gfH + (k - 0.5) * fh + 0.5 * fh - 0.6;
|
|
515
|
+
float sw = min(0.9, colW * 0.4) / colW;
|
|
516
|
+
float ok = step(doorTopRel + 0.45, bottom) * step(bottom + 1.2, top - 0.25);
|
|
517
|
+
float sg = cellBox(fu, fwu, 0.5 - 0.5 * sw, 0.5 + 0.5 * sw) * cellBox(fract(tl), fwY / fh, 0.5 - 0.6 / fh, 0.5 + 0.6 / fh) * ok;
|
|
518
|
+
float sf = cellBox(fu, fwu, 0.5 - 0.5 * sw - 0.06 / colW, 0.5 + 0.5 * sw + 0.06 / colW) * cellBox(fract(tl), fwY / fh, 0.5 - 0.66 / fh, 0.5 + 0.66 / fh) * ok;
|
|
519
|
+
vec3 sglass = mix(u_palette[u_rows.x].rgb, u_palette[u_rows.y].rgb, 0.45);
|
|
520
|
+
col = mix(col, frameC, sf * 0.85);
|
|
521
|
+
col = mix(col, sglass, sg);
|
|
522
|
+
if (u_time.z > 0.0) {
|
|
523
|
+
// Stairwell lights run on timers: lit more often than flats, cooler light.
|
|
524
|
+
float on = litWindow(clamp(0.25 + 0.6 * u_time.w, 0.0, 0.9), hash2(ivec2(int(column), int(k)), wallSeed + 313u), vis);
|
|
525
|
+
g_windowGlow += vec3(0.92, 0.9, 0.78) * sg * on * 0.8;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
// Cornice band: geometry draws a real cornice, otherwise a painted band under the roof (and the parapet).
|
|
530
|
+
if ((flags & ${FACADE_FLAG.cornice}u) == 0u) col = mix(col, trim, 0.55 * boxCover(yRel, fwY, top - 0.18, top + 0.7));
|
|
531
|
+
else col = mix(col, trim, 0.45 * boxCover(yRel, fwY, top + 0.1, top + 0.7));
|
|
532
|
+
// Plinth: from the recipe, at least a hint where it is not given.
|
|
533
|
+
col = mix(col, plinthC, 0.85 * boxCover(above, fwY, -1000.0, max(plinthH, 0.25)));
|
|
534
|
+
|
|
535
|
+
// Entrance: frame, door leaf by kind, a lamp above at night.
|
|
536
|
+
if (hasDoor) {
|
|
537
|
+
float wy = v_pat.y;
|
|
538
|
+
float hw = 0.5 * v_fac.y;
|
|
539
|
+
float du = u - v_fac.x;
|
|
540
|
+
float fr = 0.09;
|
|
541
|
+
float outer = boxCover(du, fwU, -hw - fr, hw + fr) * boxCover(wy, fwY, v_fac.z, v_fac.z + doorH + fr);
|
|
542
|
+
float leaf = boxCover(du, fwU, -hw, hw) * boxCover(wy, fwY, v_fac.z, v_fac.z + doorH);
|
|
543
|
+
float dv = (wy - v_fac.z) / doorH;
|
|
544
|
+
vec3 dc = doorC;
|
|
545
|
+
if (doorKind == 4) {
|
|
546
|
+
// Arch: a half-round head as wide as the opening, a leaf of vertical boards.
|
|
547
|
+
vec2 p = vec2(du, wy - (v_fac.z + doorH - hw));
|
|
548
|
+
float d = p.y > 0.0 ? length(p) : 0.0;
|
|
549
|
+
float fwd = max(fwU, fwY);
|
|
550
|
+
outer *= 1.0 - smoothstep(hw + fr - fwd, hw + fr + fwd, d);
|
|
551
|
+
leaf *= 1.0 - smoothstep(hw - fwd, hw + fwd, d);
|
|
552
|
+
dc *= 0.92 + 0.1 * pulseFaded(du / 0.18, fwU / 0.18, 0.0, 0.5);
|
|
553
|
+
} else if (doorKind == 2) {
|
|
554
|
+
// Garage door: ribbed sheet metal.
|
|
555
|
+
dc *= 0.9 + 0.12 * pulseFaded(wy / 0.16, fwY / 0.16, 0.0, 0.5);
|
|
556
|
+
} else {
|
|
557
|
+
// Glass in the upper part of the leaf (door) or almost all of it (portal), split by a bar.
|
|
558
|
+
float gl0 = doorKind == 3 ? 0.06 : 0.45;
|
|
559
|
+
vec3 dglass = mix(u_palette[u_rows.x].rgb, u_palette[u_rows.y].rgb, 0.35);
|
|
560
|
+
float g = boxCover(dv, fwY / doorH, gl0, 0.94) * boxCover(abs(du), fwU, 0.0, hw - 0.1);
|
|
561
|
+
float split = boxCover(du, fwU, -0.04, 0.04);
|
|
562
|
+
dc = mix(dc, dglass, g * (1.0 - split));
|
|
563
|
+
if (u_time.z > 0.0) g_windowGlow += vec3(1.0, 0.8, 0.5) * g * (1.0 - split) * 0.55 * leaf;
|
|
564
|
+
}
|
|
565
|
+
col = mix(col, frameC * 0.95, outer * 0.9);
|
|
566
|
+
col = mix(col, dc, leaf);
|
|
567
|
+
if (u_time.z > 0.0 && doorKind != 2) {
|
|
568
|
+
float lamp = boxCover(du, fwU, -0.12, 0.12) * boxCover(wy, fwY, v_fac.z + doorH + 0.12, v_fac.z + doorH + 0.32);
|
|
569
|
+
g_windowGlow += vec3(1.0, 0.78, 0.45) * lamp * 1.5;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
return col;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
${damage ? DAMAGE_GLSL + INTERIOR_GLSL : ''}vec3 roofColor(uint seed, vec3 n) {
|
|
576
|
+
vec3 base = u_palette[v_mat.y].rgb * (0.82 + 0.18 * hash1(seed + 3u));
|
|
577
|
+
if (v_kind == 1) {
|
|
578
|
+
// Courses of roofing along the fall line. Distance up the roof from the height above the eave and the slope.
|
|
579
|
+
const float COURSE_M = 0.36;
|
|
580
|
+
float s = v_surf.z / max(sqrt(1.0 - n.y * n.y), 0.2);
|
|
581
|
+
float w = fwidth(s) / COURSE_M;
|
|
582
|
+
base *= 1.0 - 0.2 * pulseFaded(s / COURSE_M, w, 0.0, 0.25);
|
|
583
|
+
base *= 0.9 + 0.2 * vnoise(v_pat.xz * 0.55, seed);
|
|
584
|
+
${finishes ? ' if (((v_mat.z >> 4u) & 3u) != 0u) {\n // A cover of its own instead of the plain courses; across the slope in the frame of the mesh.\n vec2 fall = v_patN.xz / max(length(v_patN.xz), 1e-4);\n base = coverRoof(u_palette[v_mat.y].rgb * (0.82 + 0.18 * hash1(seed + 3u)), seed, s, dot(v_pat.xz, vec2(-fall.y, fall.x)));\n }\n' : ''} } else {
|
|
585
|
+
// Flat roof: large blotches and fine grain.
|
|
586
|
+
base *= 0.9 + 0.2 * vnoise(v_pat.xz * 0.21, seed);
|
|
587
|
+
base *= 1.0 + 0.12 * (vnoise(v_pat.xz / 0.3, 31u) - 0.5) * detailVisible(0.3);
|
|
588
|
+
}
|
|
589
|
+
return base;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
void main() {
|
|
593
|
+
vec3 n = v_normal;
|
|
594
|
+
uint seed = uint(v_bld.z * 16777215.0);
|
|
595
|
+
${damage ? ' if (v_kind == 4) {\n o_color = interiorShade(seed, n);\n return;\n }\n if (v_kind == 5) {\n o_color = wallInsideShade(seed, n);\n return;\n }\n' : ''} vec3 col;
|
|
596
|
+
float ao = 1.0;
|
|
597
|
+
if (v_kind == 0) {
|
|
598
|
+
col = (v_bits.x & ${FACADE_FLAG.recipe}u) != 0u ? recipeWall(seed) : wallColor(seed);
|
|
599
|
+
// The wall darkens at its foot, so the house sits on the ground.
|
|
600
|
+
ao = mix(0.5, 1.0, smoothstep(-0.3, ${f(dims.wallBaseShadeHeight)}, v_surf.w));
|
|
601
|
+
} else if (v_kind == 3) {
|
|
602
|
+
col = u_palette[v_mat.w].rgb * (0.92 + 0.1 * hash1(seed + 1u));
|
|
603
|
+
// Side faces darken towards their foot (parapet inner face, boxes on the roof and on the ground).
|
|
604
|
+
if (n.y < 0.5) ao = mix(0.6, 1.0, smoothstep(0.0, ${f(dims.parapetHeight)}, v_surf.z));
|
|
605
|
+
} else {
|
|
606
|
+
col = roofColor(seed, n);
|
|
607
|
+
}
|
|
608
|
+
${damage ? ' if (v_damage > 0) col = damageShade(col, seed);\n' : ''} // Wet: roofs and fittings darken more than walls, which rain wets only partly.
|
|
609
|
+
col *= 1.0 - u_weather.y * (v_kind == 0 ? 0.1 : 0.22);
|
|
610
|
+
if (v_kind != 0) {
|
|
611
|
+
// Snow on roofs, parapets, roof superstructures and cars. Flat roofs hold it longest.
|
|
612
|
+
float snow = snowOn(v_world, n, v_kind == 2 ? 0.18 : 0.06);
|
|
613
|
+
col = mix(col, u_snow.rgb * (0.97 + 0.06 * hash1(seed + 5u)), snow);
|
|
614
|
+
}
|
|
615
|
+
float sun = sunVisibility(v_world, n, 1.6);
|
|
616
|
+
vec3 light = lightOn(n, sun, ao) * mix(0.78, 1.0, ao);
|
|
617
|
+
// Windows glow on their own, independent of ambient light. Exposure is divided out so they do not blow out at night.
|
|
618
|
+
vec3 glow = g_windowGlow * (u_time.z / u_warmTint.a);
|
|
619
|
+
o_color = vec4(applyFog(toDisplay(col * u_warmTint.rgb * light + glow), v_world), 1.0);
|
|
620
|
+
}`;
|
|
621
|
+
/** Damage shading (vertex damage channel, see writer.ts). Only in the damage variant of the program. */
|
|
622
|
+
const DAMAGE_GLSL = /* glsl */ `// Damage: 1 cracked (crack network and spalled plaster in patches), 2 heavily damaged (all over, with soot),
|
|
623
|
+
// 3 cut and inner faces (bare core), 4 rubble (dusty broken material). Only damaged vertices (v_damage > 0) come here.
|
|
624
|
+
|
|
625
|
+
// Distance to the nearest cell border of a jittered grid (F2 − F1 of cellular noise), in cell units.
|
|
626
|
+
float cellEdge(vec2 p, uint seed) {
|
|
627
|
+
vec2 i = floor(p);
|
|
628
|
+
vec2 f = p - i;
|
|
629
|
+
float d1 = 8.0, d2 = 8.0;
|
|
630
|
+
for (int y = -1; y <= 1; y++) {
|
|
631
|
+
for (int x = -1; x <= 1; x++) {
|
|
632
|
+
ivec2 c = ivec2(i) + ivec2(x, y);
|
|
633
|
+
vec2 o = vec2(hash2(c, seed), hash2(c, seed + 1u));
|
|
634
|
+
float d = length(vec2(x, y) + o - f);
|
|
635
|
+
if (d < d1) { d2 = d1; d1 = d; } else if (d < d2) d2 = d;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
return d2 - d1;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
vec3 damageShade(vec3 col, uint seed) {
|
|
642
|
+
// Projected from the rest position: the pattern stays on a piece that moves.
|
|
643
|
+
vec3 m = v_patN;
|
|
644
|
+
vec2 p = abs(m.y) > 0.7 ? v_pat.xz : vec2(dot(v_pat.xz, vec2(-m.z, m.x)), v_pat.y);
|
|
645
|
+
float grain = vnoise(p * 4.0, seed + 41u);
|
|
646
|
+
if (v_damage == 3) {
|
|
647
|
+
// Broken core: dark masonry with a little brick in it.
|
|
648
|
+
return mix(col * 0.38, vec3(0.3, 0.22, 0.18), 0.45) * (0.8 + 0.4 * grain);
|
|
649
|
+
}
|
|
650
|
+
if (v_damage >= 4) {
|
|
651
|
+
// Rubble: the material broken up and covered in dust.
|
|
652
|
+
return mix(col, vec3(0.66, 0.62, 0.56), 0.55) * (0.85 + 0.35 * grain * detailVisible(0.25));
|
|
653
|
+
}
|
|
654
|
+
float heavy = v_damage >= 2 ? 1.0 : 0.0;
|
|
655
|
+
// Where the damage lies: patches when cracked, everywhere when heavy.
|
|
656
|
+
float patchN = vnoise(p * 0.3, seed + 79u);
|
|
657
|
+
float area = mix(0.25 + 0.75 * smoothstep(0.3, 0.55, patchN), 1.0, heavy);
|
|
658
|
+
// Crack network: borders of jagged cells, about a metre across, plus finer ones near the worst spots.
|
|
659
|
+
vec2 q = p * 0.9 + 0.35 * vec2(vnoise(p * 2.3, seed + 70u), vnoise(p * 2.3 + 9.0, seed + 71u));
|
|
660
|
+
float e = cellEdge(q, seed + 72u);
|
|
661
|
+
float px = length(fwidth(q));
|
|
662
|
+
float crack = 1.0 - smoothstep(0.006, 0.006 + 1.1 * px, e);
|
|
663
|
+
vec2 q2 = q * 2.6;
|
|
664
|
+
float e2 = cellEdge(q2, seed + 73u);
|
|
665
|
+
float px2 = length(fwidth(q2));
|
|
666
|
+
float fine = (1.0 - smoothstep(0.004, 0.004 + 1.1 * px2, e2)) * smoothstep(0.55, 0.75, patchN + 0.4 * heavy);
|
|
667
|
+
float lines = max(crack, 0.7 * fine) * area * detailVisible(0.08);
|
|
668
|
+
// Spalled plaster: brick shows through in blotches along the cracks.
|
|
669
|
+
float spallN = vnoise(p * 1.2, seed + 81u) + 0.25 * (1.0 - smoothstep(0.0, 0.25, e));
|
|
670
|
+
float spall = smoothstep(mix(0.8, 0.66, heavy), mix(0.86, 0.72, heavy), spallN) * area;
|
|
671
|
+
col = mix(col, vec3(0.5, 0.33, 0.26) * (0.8 + 0.3 * grain), spall * 0.85);
|
|
672
|
+
// Soot and dust.
|
|
673
|
+
float soot = smoothstep(0.4, 0.85, vnoise(p * 0.22, seed + 80u)) * (0.12 + 0.45 * heavy) * area;
|
|
674
|
+
col *= 1.0 - soot * 0.7;
|
|
675
|
+
col = mix(col, col * 0.3, lines * 0.85);
|
|
676
|
+
return col;
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
`;
|
|
680
|
+
/**
|
|
681
|
+
* Interior surfaces of a damaged structure (interior.ts): room paint, ceilings, floors by room type, bare concrete,
|
|
682
|
+
* stairs and the roof space. Daylight comes in through the openings (sun with shadows) plus a soft bounce; at night a
|
|
683
|
+
* room glows when one of its windows is lit (same hash as the window light). Only in the damage variant.
|
|
684
|
+
*/
|
|
685
|
+
const INTERIOR_GLSL = /* glsl */ `// Calm wall paints, picked per room by its hash.
|
|
686
|
+
const vec3 ROOM_PAINTS[8] = vec3[8](
|
|
687
|
+
vec3(0.74, 0.71, 0.64), vec3(0.64, 0.69, 0.62), vec3(0.78, 0.69, 0.55), vec3(0.62, 0.66, 0.70),
|
|
688
|
+
vec3(0.74, 0.63, 0.58), vec3(0.79, 0.77, 0.72), vec3(0.66, 0.63, 0.52), vec3(0.69, 0.73, 0.74));
|
|
689
|
+
|
|
690
|
+
vec3 interiorColor(uint rs, int finish, int type, vec2 p, float h, out float ao) {
|
|
691
|
+
ao = 1.0;
|
|
692
|
+
vec2 fw = fwidth(p);
|
|
693
|
+
float vis = detailVisible(0.1);
|
|
694
|
+
vec3 col;
|
|
695
|
+
if (finish == 0 || finish == 5) {
|
|
696
|
+
if (finish == 5) {
|
|
697
|
+
// Roof space: rough boards between rafters.
|
|
698
|
+
col = vec3(0.56, 0.44, 0.32) * (0.9 + 0.2 * hash1(rs + 7u));
|
|
699
|
+
col *= 1.0 - 0.35 * pulseFaded(p.x / 0.9, fw.x / 0.9, 0.0, 0.12) * vis;
|
|
700
|
+
} else {
|
|
701
|
+
col = ROOM_PAINTS[int(hash1(rs) * 8.0) & 7] * (0.95 + 0.08 * hash1(rs + 3u));
|
|
702
|
+
if (type == 1) col *= 0.8;
|
|
703
|
+
else if (type == 2) col = mix(col, vec3(0.7, 0.7, 0.68), 0.55);
|
|
704
|
+
// Skirting board and a darker band where wall meets floor and ceiling.
|
|
705
|
+
col = mix(col, col * 0.55, boxCover(p.y, fw.y, -1.0, 0.08));
|
|
706
|
+
ao = mix(0.7, 1.0, smoothstep(0.0, 0.6, p.y)) * mix(0.82, 1.0, smoothstep(0.0, 0.45, h - p.y));
|
|
707
|
+
}
|
|
708
|
+
col *= 0.96 + 0.08 * vnoise(p * 0.7, rs + 2u);
|
|
709
|
+
} else if (finish == 1) {
|
|
710
|
+
col = vec3(0.8, 0.79, 0.76) * (0.97 + 0.05 * vnoise(p * 0.5, rs + 4u));
|
|
711
|
+
} else if (finish == 2 || finish == 6) {
|
|
712
|
+
float pick = hash1(rs + 5u);
|
|
713
|
+
if (type == 1 || type == 2) {
|
|
714
|
+
// Corridor and stairwell: dark terrazzo tiles.
|
|
715
|
+
col = vec3(0.42, 0.4, 0.37) * (0.92 + 0.16 * hash1(rs + 6u));
|
|
716
|
+
vec2 q = p / 0.4;
|
|
717
|
+
col *= 1.0 - 0.18 * max(pulseFaded(q.x, fw.x / 0.4, 0.0, 0.04), pulseFaded(q.y, fw.y / 0.4, 0.0, 0.04)) * vis;
|
|
718
|
+
col *= 0.92 + 0.16 * vnoise(p * 6.0, rs + 8u) * vis;
|
|
719
|
+
} else if (finish == 6 || pick < 0.55) {
|
|
720
|
+
// Planks: parquet in rooms, boards in the roof space.
|
|
721
|
+
float wPl = finish == 6 ? 0.2 : 0.11;
|
|
722
|
+
float row = floor(p.y / wPl);
|
|
723
|
+
float along = p.x + 0.37 * row;
|
|
724
|
+
col = (finish == 6 ? vec3(0.44, 0.36, 0.27) : vec3(0.6, 0.41, 0.24)) * (0.85 + 0.25 * hash2(ivec2(int(row), int(floor(along / 0.9))), rs + 9u));
|
|
725
|
+
col *= 1.0 - 0.22 * max(pulseFaded(p.y / wPl, fw.y / wPl, 0.0, 0.06), pulseFaded(along / 0.9, fw.x / 0.9, 0.0, 0.015)) * vis;
|
|
726
|
+
} else {
|
|
727
|
+
// Linoleum in a quiet colour.
|
|
728
|
+
col = mix(vec3(0.55, 0.52, 0.45), vec3(0.5, 0.55, 0.52), hash1(rs + 10u)) * (0.95 + 0.06 * vnoise(p * 1.3, rs + 11u));
|
|
729
|
+
}
|
|
730
|
+
} else if (finish == 4) {
|
|
731
|
+
col = vec3(0.6, 0.58, 0.55) * (0.94 + 0.08 * vnoise(p * 3.0, rs + 12u));
|
|
732
|
+
} else {
|
|
733
|
+
// Bare concrete at slab edges and on partition tops.
|
|
734
|
+
col = vec3(0.56, 0.55, 0.52) * (0.85 + 0.25 * vnoise(p * 2.5, rs + 13u));
|
|
735
|
+
}
|
|
736
|
+
return col;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
// Daylight reaching into a room: a little from the sky through any gap, much more through its windows (glazed share
|
|
740
|
+
// of the floor area, 0–1), more again when they face the sun. Returns the fill light.
|
|
741
|
+
vec3 roomFill(float day, vec2 dir, float ao) {
|
|
742
|
+
float up = clamp(u_sunDir.y * 4.0, 0.0, 1.0);
|
|
743
|
+
vec2 s = u_sunDir.xz / max(length(u_sunDir.xz), 1e-3);
|
|
744
|
+
float side = max(dot(dir, s), 0.0);
|
|
745
|
+
float gain = 0.45 + day * (1.6 + 1.2 * side * up);
|
|
746
|
+
return (u_ambient.rgb * 0.45 + u_skyFill.rgb * 0.15 + u_bounce.rgb * 0.55 + u_sunColor.rgb * 0.07) * gain * ao;
|
|
747
|
+
}
|
|
748
|
+
// Is the room lamp on: rooms by their lowest lit-window threshold (own one without windows), shared spaces on timers.
|
|
749
|
+
float roomOn(int mode, float lit, float own, uint seed) {
|
|
750
|
+
if (u_time.z <= 0.0 || mode == 2) return 0.0;
|
|
751
|
+
if (mode == 1) {
|
|
752
|
+
float share = clamp(0.25 + 0.6 * u_time.w, 0.0, 0.9);
|
|
753
|
+
return 1.0 - smoothstep(share - 0.012, share + 0.012, own);
|
|
754
|
+
}
|
|
755
|
+
float share = litShare(seed, 1.0);
|
|
756
|
+
float key = lit < 1.5 ? lit : own;
|
|
757
|
+
return 1.0 - smoothstep(share - 0.012, share + 0.012, key);
|
|
758
|
+
}
|
|
759
|
+
// Warm bulbs in rooms, cooler tubes in corridors and stairwells.
|
|
760
|
+
vec3 roomLamp(int mode, uint rs) {
|
|
761
|
+
return mode == 1 ? vec3(0.9, 0.88, 0.78) : mix(vec3(1.0, 0.72, 0.4), vec3(1.0, 0.82, 0.55), hash1(rs + 14u));
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
vec4 interiorShade(uint seed, vec3 n) {
|
|
765
|
+
uint rs = uint(v_surf.w * 16777215.0) >> 16u;
|
|
766
|
+
int finish = int(v_bits.x), type = int(v_bits.y);
|
|
767
|
+
float ao;
|
|
768
|
+
vec3 col = interiorColor(rs, finish, type, v_surf.xy, v_surf.z, ao);
|
|
769
|
+
// Damage: full on walls, softer on floors and ceilings (dust and cracks rather than spalled plaster).
|
|
770
|
+
if (v_damage > 0) col = mix(col, damageShade(col, seed), abs(v_patN.y) > 0.7 ? 0.4 : 0.7);
|
|
771
|
+
// Sun through the openings (shadow map), plus the daylight of the room's windows.
|
|
772
|
+
float sun = sunVisibility(v_world, n, 1.6);
|
|
773
|
+
float day = float(v_win.x) / 255.0;
|
|
774
|
+
vec2 dir = (vec2(v_win.yz) - 128.0) / 127.0;
|
|
775
|
+
vec3 light = u_sunColor.rgb * (max(dot(n, u_sunDir.xyz), 0.0) * sun) + roomFill(day, dir, ao);
|
|
776
|
+
int mode = int(v_fac.w + 0.5);
|
|
777
|
+
vec3 glow = col * roomLamp(mode, rs) * (roomOn(mode, v_fac.x, v_fac.z, seed) * 0.95 * ao);
|
|
778
|
+
return vec4(applyFog(toDisplay(col * u_warmTint.rgb * light + glow * (u_time.z / u_warmTint.a)), v_world), 1.0);
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
// What a window shows from inside, in light units: sky above, the street and the houses opposite below.
|
|
782
|
+
vec3 viewOut(float wy) {
|
|
783
|
+
vec3 sky = vec3(0.7, 0.8, 0.95) * (u_skyFill.rgb * 1.5 + u_ambient.rgb * 0.9 + u_sunColor.rgb * 0.3);
|
|
784
|
+
vec3 street = vec3(0.6, 0.58, 0.52) * (u_ambient.rgb + u_skyFill.rgb * 0.5 + u_sunColor.rgb * 0.45);
|
|
785
|
+
return mix(street, sky, smoothstep(0.2, 0.65, wy));
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
// Inner face of an outer wall (KIND.wallInside): room paint with the wall's own windows and doors, found from the same
|
|
789
|
+
// façade data as the outside (recipeCell, or the simple window grid), so every opening sits exactly behind its
|
|
790
|
+
// outside. Each opening reads as a hole in a thick wall: plaster reveals (the soffit darker), a frame set back in it,
|
|
791
|
+
// a window board under it. The glass shows daylight, at night the dark pane mirrors the room when that window is lit.
|
|
792
|
+
vec4 wallInsideShade(uint seed, vec3 n) {
|
|
793
|
+
uint pk = uint(v_surf.w + 0.5);
|
|
794
|
+
uint rs = pk & 255u;
|
|
795
|
+
float litB = float((pk >> 8u) & 255u);
|
|
796
|
+
float lit = litB > 254.5 ? 2.0 : litB / 254.0;
|
|
797
|
+
float own = float((pk >> 16u) & 255u) / 255.0;
|
|
798
|
+
int finish = int(v_mat.x & 3u), type = int((v_mat.x >> 2u) & 3u), mode = int((v_mat.x >> 4u) & 3u);
|
|
799
|
+
float day = float(v_mat.y) / 255.0;
|
|
800
|
+
vec2 dir = (vec2(float(v_mat.w), float(v_win.w)) - 128.0) / 127.0;
|
|
801
|
+
float u = v_surf.x, len = v_surf.y, yRel = v_surf.z;
|
|
802
|
+
float fwU = fwidth(u), fwY = fwidth(yRel);
|
|
803
|
+
float fh = v_bld.x, gfH = v_fac.w;
|
|
804
|
+
bool recipe = (v_bits.x & ${FACADE_FLAG.recipe}u) != 0u;
|
|
805
|
+
// Storey of the point and the room pattern coordinates (height above that storey's floor).
|
|
806
|
+
bool gfl = yRel < gfH;
|
|
807
|
+
float sfl = gfl ? 0.0 : 1.0 + floor((yRel - gfH) / fh);
|
|
808
|
+
float base = gfl ? 0.0 : gfH + (sfl - 1.0) * fh;
|
|
809
|
+
float clear = (gfl ? gfH : fh) - ${f(INTERIOR_DIM.slab)};
|
|
810
|
+
float ao;
|
|
811
|
+
vec3 col = interiorColor(rs, finish, type, vec2(u, yRel - base), clear, ao);
|
|
812
|
+
|
|
813
|
+
// Opening masks in cell units: fu, fv position in the cell, x0–x1 × y0–y1 the window.
|
|
814
|
+
float glass = 0.0, frame = 0.0, reveal = 0.0, soffit = 0.0, board = 0.0, bar = 0.0, curtain = 0.0, blind = 0.0;
|
|
815
|
+
float wy = 0.5, on = 0.0, fine = 1.0, side = 0.0;
|
|
816
|
+
vec3 frameC = vec3(0.86, 0.85, 0.82);
|
|
817
|
+
if (recipe) frameC = mix(u_palette[v_col.x].rgb, vec3(0.9, 0.89, 0.86), 0.55);
|
|
818
|
+
float colW = 1.0, flH = 1.0, fu = 0.0, fv = 0.0, fwu = 1.0, fwv = 1.0, x0 = 0.0, x1 = 0.0, y0 = 0.0, y1 = 0.0, vis = 1.0, inFl = 0.0;
|
|
819
|
+
bool win = false;
|
|
820
|
+
ivec2 cell = ivec2(0);
|
|
821
|
+
float share = 0.0, hLit = 1.0, wallLen = len;
|
|
822
|
+
if (recipe) {
|
|
823
|
+
RCell k = recipeCell(u, len, yRel, fwU, fwY);
|
|
824
|
+
win = k.windows;
|
|
825
|
+
colW = k.colW; flH = k.flH; fu = k.fu; fv = k.fv; fwu = k.fwu; fwv = k.fwv; vis = k.vis; inFl = k.inFloors;
|
|
826
|
+
x0 = 0.5 - 0.5 * k.ww; x1 = 0.5 + 0.5 * k.ww; y0 = k.y0; y1 = k.y1;
|
|
827
|
+
cell = ivec2(int(k.column), int(k.fl));
|
|
828
|
+
int gfKind = int((v_bits.y >> 2u) & 3u);
|
|
829
|
+
share = litShare(seed, k.groundFloor && gfKind != 0 ? 0.5 : 1.0);
|
|
830
|
+
hLit = hash2(cell, seed + 77u + uint(len * 31.0));
|
|
831
|
+
} else {
|
|
832
|
+
int style = int(v_mat.z);
|
|
833
|
+
float bay = v_bld.w, floors = v_bld.y;
|
|
834
|
+
if (style != 0 && len > bay * 0.7) {
|
|
835
|
+
float nn = max(1.0, floor(len / bay + 0.5));
|
|
836
|
+
colW = len / nn; flH = fh;
|
|
837
|
+
float cu = u / colW, cv = yRel / fh;
|
|
838
|
+
fu = fract(cu); fv = fract(cv); fwu = fwU / colW; fwv = fwY / fh;
|
|
839
|
+
float ww, wh, sl;
|
|
840
|
+
if (style == 2) { ww = 0.8; wh = 0.48; sl = 0.3; }
|
|
841
|
+
else if (style == 3) { ww = 0.36; wh = 0.3; sl = 0.42; }
|
|
842
|
+
else { ww = clamp(1.5 / colW, 0.38, 0.66); wh = clamp(1.65 / fh, 0.3, 0.62); sl = 0.9 / fh; }
|
|
843
|
+
x0 = 0.5 - 0.5 * ww; x1 = 0.5 + 0.5 * ww; y0 = sl; y1 = sl + wh;
|
|
844
|
+
win = true;
|
|
845
|
+
inFl = boxCover(yRel, fwY, 0.0, floors * fh);
|
|
846
|
+
vis = detailVisible(colW * 0.6);
|
|
847
|
+
cell = ivec2(floor(cu), floor(cv));
|
|
848
|
+
share = litShare(seed, style == 1 ? 1.0 : 0.55);
|
|
849
|
+
hLit = hash2(cell, seed + 77u + uint(len * 31.0));
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
float spill = 0.0;
|
|
853
|
+
if (win && finish != 5) {
|
|
854
|
+
// Reveal: the hole is a little wider than the frame, splayed inwards; the window board closes it at the bottom.
|
|
855
|
+
float rv = 0.12 / colW, rvV = 0.12 / flH, fr = 0.06 / colW, frV = 0.06 / flH;
|
|
856
|
+
float hole = cellBox(fu, fwu, x0 - rv, x1 + rv) * cellBox(fv, fwv, y0, y1 + rvV) * inFl;
|
|
857
|
+
frame = cellBox(fu, fwu, x0, x1) * cellBox(fv, fwv, y0, y1) * inFl;
|
|
858
|
+
glass = cellBox(fu, fwu, x0 + fr, x1 - fr) * cellBox(fv, fwv, y0 + frV, y1 - frV) * inFl;
|
|
859
|
+
reveal = max(hole - frame, 0.0);
|
|
860
|
+
soffit = reveal * cellBox(fv, fwv, y1, y1 + rvV);
|
|
861
|
+
side = fu < 0.5 ? 1.0 : -1.0;
|
|
862
|
+
board = cellBox(fu, fwu, x0 - rv - 0.04 / colW, x1 + rv + 0.04 / colW) * cellBox(fv, fwv, y0 - 0.05 / flH, y0) * inFl;
|
|
863
|
+
float wx = (fu - x0) / max(x1 - x0, 1e-4);
|
|
864
|
+
wy = (fv - y0) / max(y1 - y0, 1e-4);
|
|
865
|
+
float fwx = fwu / max(x1 - x0, 1e-4), fwy = fwv / max(y1 - y0, 1e-4);
|
|
866
|
+
float winWm = (x1 - x0) * colW, winHm = (y1 - y0) * flH;
|
|
867
|
+
fine = detailVisible(winWm * 0.25);
|
|
868
|
+
if (recipe) {
|
|
869
|
+
int mullions = int(v_bits.y & 3u);
|
|
870
|
+
float bw = 0.06 / winWm;
|
|
871
|
+
if (mullions == 1 || (mullions == 2 && winWm < 1.3)) bar = cellBox(wx, fwx, 0.5 - bw, 0.5 + bw);
|
|
872
|
+
else if (mullions == 2) bar = max(cellBox(wx, fwx, 0.333 - bw, 0.333 + bw), cellBox(wx, fwx, 0.667 - bw, 0.667 + bw));
|
|
873
|
+
// Curtains and blinds: the same windows as outside (same hashes), seen from the room side.
|
|
874
|
+
uint wallSeed = seed + uint(len * 31.0);
|
|
875
|
+
float r = hash2(cell, wallSeed);
|
|
876
|
+
float hc = hash2(cell, wallSeed + 131u);
|
|
877
|
+
float curtainShare = float(v_bits.z & 15u) / 15.0, blindShare = float(v_bits.z >> 4u) / 15.0;
|
|
878
|
+
if (hc < curtainShare) curtain = max(cellBox(wx, fwx, -0.08, 0.2 + 0.1 * r), cellBox(wx, fwx, 0.8 - 0.1 * r, 1.08)) * cellBox(wy, fwy, -0.04, 1.06);
|
|
879
|
+
else if (hc < curtainShare + blindShare) {
|
|
880
|
+
float depth = 0.25 + 0.65 * fract(hc * 37.0);
|
|
881
|
+
blind = cellBox(wy, fwy, 1.0 - depth, 1.0) * cellBox(wx, fwx, 0.0, 1.0);
|
|
882
|
+
}
|
|
883
|
+
} else {
|
|
884
|
+
bar = cellBox(wx, fwx, 0.5 - 0.06 / winWm, 0.5 + 0.06 / winWm);
|
|
885
|
+
}
|
|
886
|
+
if (u_time.z > 0.0) on = litWindow(share, hLit, vis);
|
|
887
|
+
// Daylight spills onto the wall around the opening: distance to the window in metres, soft falloff.
|
|
888
|
+
float ddx = max(max((x0 - fu) * colW, (fu - x1) * colW), 0.0);
|
|
889
|
+
float ddy = max(max((y0 - fv) * flH, (fv - y1) * flH), 0.0);
|
|
890
|
+
spill = exp(-length(vec2(ddx, ddy)) / 0.7) * inFl;
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
// Entrance seen from the hall: frame and leaf; the glazed part shows daylight like a window.
|
|
894
|
+
float leaf = 0.0, leafGlass = 0.0, dframe = 0.0;
|
|
895
|
+
vec3 leafC = vec3(0.0);
|
|
896
|
+
int doorKind = int((v_bits.y >> 4u) & 7u);
|
|
897
|
+
if (recipe && doorKind > 0) {
|
|
898
|
+
// Seen from inside, an arch is a rectangle of its full height.
|
|
899
|
+
float doorH = doorKind == 4 ? v_fac.y * ${f(FACADE_DIM.archHeightPerWidth)} : doorKind == 2 ? ${f(FACADE_DIM.garageDoorHeight)} : doorKind == 3 ? ${f(FACADE_DIM.portalHeight)} : ${f(FACADE_DIM.doorHeight)};
|
|
900
|
+
float wyw = v_pat.y, hw = 0.5 * v_fac.y, du = u - v_fac.x;
|
|
901
|
+
dframe = boxCover(du, fwU, -hw - 0.1, hw + 0.1) * boxCover(wyw, fwY, v_fac.z, v_fac.z + doorH + 0.1);
|
|
902
|
+
leaf = boxCover(du, fwU, -hw, hw) * boxCover(wyw, fwY, v_fac.z, v_fac.z + doorH);
|
|
903
|
+
leafC = u_palette[v_col.z].rgb * 0.9;
|
|
904
|
+
if (doorKind == 2) leafC *= 0.9 + 0.12 * pulseFaded(wyw / 0.16, fwY / 0.16, 0.0, 0.5);
|
|
905
|
+
else if (doorKind != 4) {
|
|
906
|
+
float gl0 = doorKind == 3 ? 0.06 : 0.45;
|
|
907
|
+
float dv = (wyw - v_fac.z) / doorH;
|
|
908
|
+
leafGlass = boxCover(dv, fwY / doorH, gl0, 0.94) * boxCover(abs(du), fwU, 0.0, hw - 0.1) * (1.0 - boxCover(du, fwU, -0.04, 0.04)) * leaf;
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
// Surfaces of the wall: paint, then reveal, board, frame, bars, cloth, the door.
|
|
913
|
+
float detail = detailVisible(0.08);
|
|
914
|
+
vec3 plaster = mix(col, vec3(0.86, 0.85, 0.82), 0.6);
|
|
915
|
+
col = mix(col, plaster * (soffit > 0.01 ? 0.62 : (side > 0.0 ? 0.95 : 0.74)), reveal * detail + reveal * (1.0 - detail) * 0.6);
|
|
916
|
+
col = mix(col, vec3(0.8, 0.77, 0.72), board * 0.95);
|
|
917
|
+
col = mix(col, frameC, frame);
|
|
918
|
+
col = mix(col, frameC, dframe * 0.9);
|
|
919
|
+
col = mix(col, leafC, leaf);
|
|
920
|
+
vec3 cloth = recipe ? mix(u_palette[v_col.x].rgb, vec3(0.78, 0.70, 0.58), 0.55) : vec3(0.7, 0.65, 0.56);
|
|
921
|
+
|
|
922
|
+
if (v_damage > 0) col = mix(col, damageShade(col, seed), 0.7);
|
|
923
|
+
float sun = sunVisibility(v_world, n, 1.6);
|
|
924
|
+
vec3 light = u_sunColor.rgb * (max(dot(n, u_sunDir.xyz), 0.0) * sun) + roomFill(day, dir, ao) * (1.0 + 0.45 * spill);
|
|
925
|
+
float roomLit = roomOn(mode, lit, own, seed);
|
|
926
|
+
vec3 lamp = roomLamp(mode, rs);
|
|
927
|
+
vec3 surf = col * u_warmTint.rgb * light + col * lamp * (roomLit * 0.95 * ao) * (u_time.z / u_warmTint.a);
|
|
928
|
+
|
|
929
|
+
// The pane: daylight from outside; at night dark, with the lit room mirrored in it when this window is lit.
|
|
930
|
+
float pane = glass * (1.0 - bar * 0.9);
|
|
931
|
+
// Once the windows light up outside it is dark: the pane turns into a mirror of the room.
|
|
932
|
+
float dusk = clamp(u_time.z, 0.0, 1.0);
|
|
933
|
+
vec3 outside = viewOut(wy) * u_warmTint.rgb * (1.0 - 0.88 * dusk);
|
|
934
|
+
vec3 night = vec3(0.012, 0.016, 0.026) + plaster * lamp * on * 0.22 * (u_time.z / u_warmTint.a);
|
|
935
|
+
vec3 paneC = outside + night;
|
|
936
|
+
vec3 res = mix(surf, paneC, pane);
|
|
937
|
+
res = mix(res, frameC * u_warmTint.rgb * light + frameC * lamp * roomLit * 0.8 * (u_time.z / u_warmTint.a), glass * bar * 0.9);
|
|
938
|
+
// Cloth hangs in front of the pane: lit by the room, and by day the light comes through it.
|
|
939
|
+
vec3 clothC = cloth * 0.85 * (u_warmTint.rgb * light + lamp * roomLit * 0.9 * (u_time.z / u_warmTint.a)) + cloth * outside * 0.35;
|
|
940
|
+
res = mix(res, clothC, max(curtain * 0.9, blind) * fine * (glass + reveal + frame > 0.0 ? 1.0 : 0.0));
|
|
941
|
+
vec3 dglassC = viewOut(0.7) * u_warmTint.rgb * 0.8 * (1.0 - 0.88 * dusk) + vec3(0.012, 0.016, 0.026);
|
|
942
|
+
res = mix(res, dglassC, leafGlass);
|
|
943
|
+
return vec4(applyFog(toDisplay(res), v_world), 1.0);
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
`;
|