@arraypress/effects-astro 0.0.0-stage → 0.1.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.
Files changed (314) hide show
  1. package/AGENTS.md +85 -0
  2. package/COMPONENTS.md +1264 -0
  3. package/LICENSE +139 -0
  4. package/README.md +197 -2
  5. package/package.json +60 -4
  6. package/src/components/AsciiRain.astro +36 -0
  7. package/src/components/BorderSweep.astro +39 -0
  8. package/src/components/Caustics.astro +39 -0
  9. package/src/components/ColorPanels.astro +62 -0
  10. package/src/components/Cursor.astro +97 -0
  11. package/src/components/DotGrid.astro +34 -0
  12. package/src/components/DotSurface.astro +35 -0
  13. package/src/components/EffectCanvas.astro +152 -0
  14. package/src/components/FitText.astro +35 -0
  15. package/src/components/FlutedGlass.astro +36 -0
  16. package/src/components/Glass.astro +69 -0
  17. package/src/components/GlassGlyph.astro +38 -0
  18. package/src/components/GlowField.astro +177 -0
  19. package/src/components/Grain.astro +98 -0
  20. package/src/components/HaloRing.astro +38 -0
  21. package/src/components/HighlightSweep.astro +74 -0
  22. package/src/components/ImageRipple.astro +56 -0
  23. package/src/components/Ink.astro +37 -0
  24. package/src/components/InkField.astro +45 -0
  25. package/src/components/IsoCity.astro +54 -0
  26. package/src/components/LightField.astro +40 -0
  27. package/src/components/LiquidMetal.astro +41 -0
  28. package/src/components/Magnetic.astro +52 -0
  29. package/src/components/Marquee.astro +216 -0
  30. package/src/components/MosaicReveal.astro +196 -0
  31. package/src/components/NebulaLogo.astro +38 -0
  32. package/src/components/NeonSwarm.astro +38 -0
  33. package/src/components/Ocean.astro +40 -0
  34. package/src/components/OutlineWordmark.astro +222 -0
  35. package/src/components/PaperBackground.astro +40 -0
  36. package/src/components/PaperShader.astro +55 -0
  37. package/src/components/Parallax.astro +49 -0
  38. package/src/components/ParticleLogo.astro +37 -0
  39. package/src/components/PixelGlitchText.astro +70 -0
  40. package/src/components/PointCloud.astro +37 -0
  41. package/src/components/ProductStack.astro +298 -0
  42. package/src/components/PulseMark.astro +189 -0
  43. package/src/components/RadiantGlass.astro +38 -0
  44. package/src/components/RainOnGlass.astro +71 -0
  45. package/src/components/Reveal.astro +115 -0
  46. package/src/components/ScrambleText.astro +52 -0
  47. package/src/components/ScrollReveal.astro +38 -0
  48. package/src/components/ShaderBackground.astro +55 -0
  49. package/src/components/SignalLines.astro +41 -0
  50. package/src/components/SilkRibbon.astro +37 -0
  51. package/src/components/SpotlightText.astro +131 -0
  52. package/src/components/Tilt.astro +79 -0
  53. package/src/components/Topography.astro +38 -0
  54. package/src/components/Typewriter.astro +66 -0
  55. package/src/components/VariableType.astro +59 -0
  56. package/src/components/VoxelLogo.astro +46 -0
  57. package/src/components/WaveBars.astro +41 -0
  58. package/src/components/WorldRoutes.astro +41 -0
  59. package/src/components/style.js +19 -0
  60. package/src/index.d.ts +143 -0
  61. package/src/index.js +105 -0
  62. package/src/runtime/ascii-rain.d.ts +53 -0
  63. package/src/runtime/ascii-rain.js +355 -0
  64. package/src/runtime/audio-meter.d.ts +65 -0
  65. package/src/runtime/audio-meter.js +282 -0
  66. package/src/runtime/audio.d.ts +26 -0
  67. package/src/runtime/audio.js +453 -0
  68. package/src/runtime/blur.d.ts +2 -0
  69. package/src/runtime/blur.js +56 -0
  70. package/src/runtime/canvas2d.d.ts +23 -0
  71. package/src/runtime/canvas2d.js +105 -0
  72. package/src/runtime/caustics.d.ts +40 -0
  73. package/src/runtime/caustics.js +286 -0
  74. package/src/runtime/color.d.ts +33 -0
  75. package/src/runtime/color.js +213 -0
  76. package/src/runtime/curl.d.ts +5 -0
  77. package/src/runtime/curl.js +81 -0
  78. package/src/runtime/cursor.d.ts +9 -0
  79. package/src/runtime/cursor.js +80 -0
  80. package/src/runtime/device.d.ts +14 -0
  81. package/src/runtime/device.js +73 -0
  82. package/src/runtime/dot-grid.d.ts +27 -0
  83. package/src/runtime/dot-grid.js +245 -0
  84. package/src/runtime/dot-surface.d.ts +46 -0
  85. package/src/runtime/dot-surface.js +429 -0
  86. package/src/runtime/feedback.d.ts +18 -0
  87. package/src/runtime/feedback.js +131 -0
  88. package/src/runtime/fit-text.d.ts +5 -0
  89. package/src/runtime/fit-text.js +60 -0
  90. package/src/runtime/fluid.d.ts +55 -0
  91. package/src/runtime/fluid.js +504 -0
  92. package/src/runtime/fluted-glass.d.ts +27 -0
  93. package/src/runtime/fluted-glass.js +157 -0
  94. package/src/runtime/gl.d.ts +19 -0
  95. package/src/runtime/gl.js +104 -0
  96. package/src/runtime/glass-glyph.d.ts +49 -0
  97. package/src/runtime/glass-glyph.js +355 -0
  98. package/src/runtime/glass-sheen.d.ts +2 -0
  99. package/src/runtime/glass-sheen.js +30 -0
  100. package/src/runtime/glsl.d.ts +17 -0
  101. package/src/runtime/glsl.js +78 -0
  102. package/src/runtime/glyphs.d.ts +22 -0
  103. package/src/runtime/glyphs.js +107 -0
  104. package/src/runtime/halo-ring.d.ts +47 -0
  105. package/src/runtime/halo-ring.js +334 -0
  106. package/src/runtime/height-field.d.ts +50 -0
  107. package/src/runtime/height-field.js +176 -0
  108. package/src/runtime/image-ripple.d.ts +25 -0
  109. package/src/runtime/image-ripple.js +353 -0
  110. package/src/runtime/image.d.ts +11 -0
  111. package/src/runtime/image.js +81 -0
  112. package/src/runtime/in-view.d.ts +6 -0
  113. package/src/runtime/in-view.js +36 -0
  114. package/src/runtime/ink-field/shaders.js +258 -0
  115. package/src/runtime/ink-field/sim.js +582 -0
  116. package/src/runtime/ink-field.d.ts +39 -0
  117. package/src/runtime/ink-field.js +311 -0
  118. package/src/runtime/ink.d.ts +31 -0
  119. package/src/runtime/ink.js +109 -0
  120. package/src/runtime/instancing.d.ts +12 -0
  121. package/src/runtime/instancing.js +37 -0
  122. package/src/runtime/iso-camera.d.ts +35 -0
  123. package/src/runtime/iso-camera.js +85 -0
  124. package/src/runtime/iso-city/figures.d.ts +30 -0
  125. package/src/runtime/iso-city/figures.js +136 -0
  126. package/src/runtime/iso-city/look.d.ts +34 -0
  127. package/src/runtime/iso-city/look.js +105 -0
  128. package/src/runtime/iso-city/plan.d.ts +59 -0
  129. package/src/runtime/iso-city/plan.js +463 -0
  130. package/src/runtime/iso-city/roads.d.ts +64 -0
  131. package/src/runtime/iso-city/roads.js +320 -0
  132. package/src/runtime/iso-city/scene.d.ts +27 -0
  133. package/src/runtime/iso-city/scene.js +432 -0
  134. package/src/runtime/iso-city/shaders.d.ts +6 -0
  135. package/src/runtime/iso-city/shaders.js +233 -0
  136. package/src/runtime/iso-city/shadows.d.ts +13 -0
  137. package/src/runtime/iso-city/shadows.js +148 -0
  138. package/src/runtime/iso-city/traffic.d.ts +80 -0
  139. package/src/runtime/iso-city/traffic.js +457 -0
  140. package/src/runtime/iso-city.d.ts +37 -0
  141. package/src/runtime/iso-city.js +458 -0
  142. package/src/runtime/lens-map.d.ts +11 -0
  143. package/src/runtime/lens-map.js +146 -0
  144. package/src/runtime/light-field.d.ts +29 -0
  145. package/src/runtime/light-field.js +292 -0
  146. package/src/runtime/liquid-glass.d.ts +48 -0
  147. package/src/runtime/liquid-glass.js +423 -0
  148. package/src/runtime/liquid-metal/beads.js +217 -0
  149. package/src/runtime/liquid-metal/field.js +88 -0
  150. package/src/runtime/liquid-metal/look.js +64 -0
  151. package/src/runtime/liquid-metal/shaders.js +255 -0
  152. package/src/runtime/liquid-metal/wave.js +53 -0
  153. package/src/runtime/liquid-metal.d.ts +46 -0
  154. package/src/runtime/liquid-metal.js +366 -0
  155. package/src/runtime/loop.d.ts +7 -0
  156. package/src/runtime/loop.js +112 -0
  157. package/src/runtime/magnetic.d.ts +9 -0
  158. package/src/runtime/magnetic.js +46 -0
  159. package/src/runtime/marquee.d.ts +2 -0
  160. package/src/runtime/marquee.js +27 -0
  161. package/src/runtime/mesh.d.ts +30 -0
  162. package/src/runtime/mesh.js +217 -0
  163. package/src/runtime/mosaic-reveal.d.ts +34 -0
  164. package/src/runtime/mosaic-reveal.js +504 -0
  165. package/src/runtime/motion.d.ts +2 -0
  166. package/src/runtime/motion.js +21 -0
  167. package/src/runtime/mount.d.ts +13 -0
  168. package/src/runtime/mount.js +120 -0
  169. package/src/runtime/nebula-logo.d.ts +31 -0
  170. package/src/runtime/nebula-logo.js +282 -0
  171. package/src/runtime/neon-swarm.d.ts +31 -0
  172. package/src/runtime/neon-swarm.js +258 -0
  173. package/src/runtime/ocean/presets.d.ts +54 -0
  174. package/src/runtime/ocean/presets.js +184 -0
  175. package/src/runtime/ocean/shader.d.ts +14 -0
  176. package/src/runtime/ocean/shader.js +389 -0
  177. package/src/runtime/ocean/view.d.ts +24 -0
  178. package/src/runtime/ocean/view.js +98 -0
  179. package/src/runtime/ocean/waves.d.ts +29 -0
  180. package/src/runtime/ocean/waves.js +119 -0
  181. package/src/runtime/ocean.d.ts +31 -0
  182. package/src/runtime/ocean.js +173 -0
  183. package/src/runtime/palettes.d.ts +37 -0
  184. package/src/runtime/palettes.js +75 -0
  185. package/src/runtime/paper-look.d.ts +42 -0
  186. package/src/runtime/paper-look.js +91 -0
  187. package/src/runtime/paper-looks.d.ts +17 -0
  188. package/src/runtime/paper-looks.js +21 -0
  189. package/src/runtime/paper.d.ts +37 -0
  190. package/src/runtime/paper.js +303 -0
  191. package/src/runtime/particle-logo.d.ts +31 -0
  192. package/src/runtime/particle-logo.js +196 -0
  193. package/src/runtime/ping-pong.d.ts +43 -0
  194. package/src/runtime/ping-pong.js +175 -0
  195. package/src/runtime/pixel-glitch.d.ts +17 -0
  196. package/src/runtime/pixel-glitch.js +287 -0
  197. package/src/runtime/point-cloud.d.ts +33 -0
  198. package/src/runtime/point-cloud.js +287 -0
  199. package/src/runtime/pointer.d.ts +27 -0
  200. package/src/runtime/pointer.js +128 -0
  201. package/src/runtime/points.d.ts +25 -0
  202. package/src/runtime/points.js +130 -0
  203. package/src/runtime/pools.d.ts +2 -0
  204. package/src/runtime/pools.js +25 -0
  205. package/src/runtime/product-stack.d.ts +24 -0
  206. package/src/runtime/product-stack.js +210 -0
  207. package/src/runtime/radiant-glass.d.ts +29 -0
  208. package/src/runtime/radiant-glass.js +282 -0
  209. package/src/runtime/rain-on-glass/backdrop.d.ts +22 -0
  210. package/src/runtime/rain-on-glass/backdrop.js +185 -0
  211. package/src/runtime/rain-on-glass/shader.d.ts +2 -0
  212. package/src/runtime/rain-on-glass/shader.js +168 -0
  213. package/src/runtime/rain-on-glass/wipe.d.ts +16 -0
  214. package/src/runtime/rain-on-glass/wipe.js +65 -0
  215. package/src/runtime/rain-on-glass.d.ts +27 -0
  216. package/src/runtime/rain-on-glass.js +210 -0
  217. package/src/runtime/ramp.d.ts +2 -0
  218. package/src/runtime/ramp.js +30 -0
  219. package/src/runtime/random.d.ts +2 -0
  220. package/src/runtime/random.js +22 -0
  221. package/src/runtime/scroll-reveal.d.ts +22 -0
  222. package/src/runtime/scroll-reveal.js +73 -0
  223. package/src/runtime/shader-background.d.ts +42 -0
  224. package/src/runtime/shader-background.js +261 -0
  225. package/src/runtime/shader-backgrounds/band-lens.js +72 -0
  226. package/src/runtime/shader-backgrounds/common.js +53 -0
  227. package/src/runtime/shader-backgrounds/grain-gradient.js +87 -0
  228. package/src/runtime/shader-backgrounds/grid.js +33 -0
  229. package/src/runtime/shader-backgrounds/mesh-gradient.js +74 -0
  230. package/src/runtime/shader-backgrounds/silk.js +57 -0
  231. package/src/runtime/shader-backgrounds/waves.js +31 -0
  232. package/src/runtime/shape.d.ts +42 -0
  233. package/src/runtime/shape.js +313 -0
  234. package/src/runtime/silk-ribbon.d.ts +23 -0
  235. package/src/runtime/silk-ribbon.js +206 -0
  236. package/src/runtime/slideshow.d.ts +27 -0
  237. package/src/runtime/slideshow.js +234 -0
  238. package/src/runtime/spotlight.d.ts +9 -0
  239. package/src/runtime/spotlight.js +97 -0
  240. package/src/runtime/stack-poses.d.ts +53 -0
  241. package/src/runtime/stack-poses.js +273 -0
  242. package/src/runtime/stage.d.ts +47 -0
  243. package/src/runtime/stage.js +187 -0
  244. package/src/runtime/swarm.d.ts +49 -0
  245. package/src/runtime/swarm.js +199 -0
  246. package/src/runtime/text-motion.d.ts +41 -0
  247. package/src/runtime/text-motion.js +165 -0
  248. package/src/runtime/text.d.ts +11 -0
  249. package/src/runtime/text.js +90 -0
  250. package/src/runtime/tilt.d.ts +19 -0
  251. package/src/runtime/tilt.js +116 -0
  252. package/src/runtime/topography.d.ts +71 -0
  253. package/src/runtime/topography.js +650 -0
  254. package/src/runtime/trackers.d.ts +21 -0
  255. package/src/runtime/trackers.js +76 -0
  256. package/src/runtime/variable-type.d.ts +43 -0
  257. package/src/runtime/variable-type.js +358 -0
  258. package/src/runtime/voxel-logo.d.ts +31 -0
  259. package/src/runtime/voxel-logo.js +237 -0
  260. package/src/runtime/waves.d.ts +70 -0
  261. package/src/runtime/waves.js +799 -0
  262. package/src/runtime/world-labels.d.ts +29 -0
  263. package/src/runtime/world-labels.js +59 -0
  264. package/src/runtime/world-land.d.ts +8 -0
  265. package/src/runtime/world-land.js +105 -0
  266. package/src/runtime/world-map.d.ts +69 -0
  267. package/src/runtime/world-map.js +308 -0
  268. package/src/runtime/world-plan.d.ts +101 -0
  269. package/src/runtime/world-plan.js +333 -0
  270. package/src/runtime/world-routes.d.ts +75 -0
  271. package/src/runtime/world-routes.js +673 -0
  272. package/src/styles/border-sweep.css +82 -0
  273. package/src/styles/glass.css +104 -0
  274. package/src/styles/motion.css +218 -0
  275. package/src/styles/reveal.css +51 -0
  276. package/src/vendor/paper/LICENSE +201 -0
  277. package/src/vendor/paper/NOTICE +5 -0
  278. package/src/vendor/paper/README.md +8 -0
  279. package/src/vendor/paper/get-shader-color-from-string.js +100 -0
  280. package/src/vendor/paper/get-shader-noise-texture.js +17 -0
  281. package/src/vendor/paper/presets.js +3678 -0
  282. package/src/vendor/paper/shader-sizing.js +37 -0
  283. package/src/vendor/paper/shader-utils.js +130 -0
  284. package/src/vendor/paper/shaders/color-panels.js +223 -0
  285. package/src/vendor/paper/shaders/dithering.js +270 -0
  286. package/src/vendor/paper/shaders/dot-grid.js +109 -0
  287. package/src/vendor/paper/shaders/dot-orbit.js +122 -0
  288. package/src/vendor/paper/shaders/fluted-glass.js +360 -0
  289. package/src/vendor/paper/shaders/gem-smoke.js +572 -0
  290. package/src/vendor/paper/shaders/god-rays.js +132 -0
  291. package/src/vendor/paper/shaders/grain-gradient.js +300 -0
  292. package/src/vendor/paper/shaders/halftone-cmyk.js +294 -0
  293. package/src/vendor/paper/shaders/halftone-dots.js +320 -0
  294. package/src/vendor/paper/shaders/heatmap.js +383 -0
  295. package/src/vendor/paper/shaders/image-dithering.js +198 -0
  296. package/src/vendor/paper/shaders/lens-distortion.js +275 -0
  297. package/src/vendor/paper/shaders/liquid-metal.js +632 -0
  298. package/src/vendor/paper/shaders/mesh-gradient.js +130 -0
  299. package/src/vendor/paper/shaders/metaballs.js +110 -0
  300. package/src/vendor/paper/shaders/neuro-noise.js +76 -0
  301. package/src/vendor/paper/shaders/paper-texture.js +526 -0
  302. package/src/vendor/paper/shaders/perlin-noise.js +166 -0
  303. package/src/vendor/paper/shaders/pulsing-border.js +238 -0
  304. package/src/vendor/paper/shaders/simplex-noise.js +91 -0
  305. package/src/vendor/paper/shaders/smoke-ring.js +132 -0
  306. package/src/vendor/paper/shaders/spiral.js +82 -0
  307. package/src/vendor/paper/shaders/static-mesh-gradient.js +130 -0
  308. package/src/vendor/paper/shaders/static-radial-gradient.js +187 -0
  309. package/src/vendor/paper/shaders/swirl.js +103 -0
  310. package/src/vendor/paper/shaders/voronoi.js +138 -0
  311. package/src/vendor/paper/shaders/warp.js +129 -0
  312. package/src/vendor/paper/shaders/water.js +121 -0
  313. package/src/vendor/paper/shaders/waves.js +65 -0
  314. package/src/vendor/paper/vertex-shader.js +159 -0
@@ -0,0 +1,432 @@
1
+ /**
2
+ * @module @arraypress/effects-astro/iso-city/scene
3
+ *
4
+ * The city's meshes, built once from its plan: tarmac, pavements with
5
+ * rounded corners, lane markings and zebra crossings, buildings with
6
+ * windows (drawn by the shader from each wall's uv, counted in window
7
+ * cells) and cluttered roofs, parks with paths, ponds and round trees, and
8
+ * lamps. Then the pieces that move: a car shaped roughly like a modern
9
+ * electric saloon (a low wedge, a fastback glass cabin, flush wheels, light
10
+ * bars front and back, a roof sign the taxis show), a person, a pin, and
11
+ * the ribbon a taxi's route is drawn with.
12
+ *
13
+ * Each vertex's tag is its material (MAT) and a seed; the shader does the rest.
14
+ */
15
+
16
+ import { createMesh } from '../mesh.js';
17
+ import { BOX } from './roads.js';
18
+ import { CURB, PITCH, ROAD, SLAB, STOREY } from './plan.js';
19
+
20
+ /** The materials, as the shader reads them from a vertex's tag. */
21
+ export const MAT = Object.freeze({
22
+ plain: 0,
23
+ wall: 1,
24
+ glass: 2,
25
+ body: 3,
26
+ head: 4,
27
+ tail: 5,
28
+ sign: 6,
29
+ accent: 7,
30
+ lamp: 8,
31
+ water: 9,
32
+ route: 10,
33
+ blob: 11,
34
+ glow: 12,
35
+ beam: 13,
36
+ ring: 14,
37
+ });
38
+
39
+ /** A window cell's width on a wall. */
40
+ const WINDOW = 0.19;
41
+ /** How high road markings lie over the tarmac. */
42
+ const MARK_Y = 0.004;
43
+
44
+ /**
45
+ * @typedef {import('../color.js').Rgb} Rgb
46
+ * @typedef {import('../mesh.js').Mesh} Mesh
47
+ * @typedef {import('../mesh.js').Vec2} Vec2
48
+ * @typedef {import('../mesh.js').Vec3} Vec3
49
+ * @typedef {import('./plan.js').CityPlan} CityPlan
50
+ * @typedef {import('./plan.js').Rect} Rect
51
+ * @typedef {import('./look.js').Look} Look
52
+ */
53
+
54
+ /**
55
+ * A rectangle with rounded corners, as a polygon.
56
+ *
57
+ * @param {Rect} r The rectangle.
58
+ * @param {number} radius The corners' radius.
59
+ * @param {number} [steps=4] Segments a corner.
60
+ * @returns {Vec2[]} The polygon (x, z).
61
+ */
62
+ export function roundedRect(r, radius, steps = 4) {
63
+ /** @type {Vec2[]} */
64
+ const out = [];
65
+ const corners = [
66
+ [r.x1 - radius, r.z1 - radius, 0],
67
+ [r.x0 + radius, r.z1 - radius, Math.PI / 2],
68
+ [r.x0 + radius, r.z0 + radius, Math.PI],
69
+ [r.x1 - radius, r.z0 + radius, (Math.PI * 3) / 2],
70
+ ];
71
+ for (const [cx, cz, start] of corners) {
72
+ for (let k = 0; k <= steps; k++) {
73
+ const a = start + (k / steps) * (Math.PI / 2);
74
+ out.push([cx + Math.cos(a) * radius, cz + Math.sin(a) * radius]);
75
+ }
76
+ }
77
+ return out;
78
+ }
79
+
80
+ /**
81
+ * A regular polygon round a point.
82
+ *
83
+ * @param {number} x The centre's x.
84
+ * @param {number} z The centre's z.
85
+ * @param {number} r The radius.
86
+ * @param {number} sides How many sides.
87
+ * @returns {Vec2[]} The polygon.
88
+ */
89
+ function ngon(x, z, r, sides) {
90
+ return Array.from({ length: sides }, (_, k) => /** @type {Vec2} */ ([x + Math.cos((k / sides) * Math.PI * 2) * r, z + Math.sin((k / sides) * Math.PI * 2) * r]));
91
+ }
92
+
93
+ /**
94
+ * A flat quad lying on the ground, facing up.
95
+ *
96
+ * @param {Mesh} mesh The mesh.
97
+ * @param {number} x0 Its least x.
98
+ * @param {number} z0 Its least z.
99
+ * @param {number} x1 Its greatest x.
100
+ * @param {number} z1 Its greatest z.
101
+ * @param {number} y Its height.
102
+ * @param {Rgb} color Its colour.
103
+ * @param {Vec2} [tag] Its tag.
104
+ */
105
+ function flat(mesh, x0, z0, x1, z1, y, color, tag) {
106
+ mesh.quad([x0, y, z0], [x0, y, z1], [x1, y, z1], [x1, y, z0], color, tag, [[-1, -1], [-1, 1], [1, 1], [1, -1]], [x0, y - 1, z0]);
107
+ }
108
+
109
+ /**
110
+ * The static city: everything that never moves, as one opaque mesh, and
111
+ * the lamps' pools of light, drawn added on at night.
112
+ *
113
+ * @param {CityPlan} plan The plan.
114
+ * @param {Look} look The colours.
115
+ * @returns {{ solid: Float32Array, glow: Float32Array }} The two meshes.
116
+ */
117
+ export function cityMesh(plan, look) {
118
+ const mesh = createMesh();
119
+ const glow = createMesh();
120
+ const E = plan.extent;
121
+ const far = E + 40;
122
+
123
+ // Tarmac under the grid, and land round it at pavement height.
124
+ flat(mesh, -ROAD / 2, -ROAD / 2, E + ROAD / 2, E + ROAD / 2, 0, look.roads);
125
+ const ring = [
126
+ { x0: -40, z0: -40, x1: far, z1: -ROAD / 2 },
127
+ { x0: -40, z0: E + ROAD / 2, x1: far, z1: far },
128
+ { x0: -40, z0: -ROAD / 2, x1: -ROAD / 2, z1: E + ROAD / 2 },
129
+ { x0: E + ROAD / 2, z0: -ROAD / 2, x1: far, z1: E + ROAD / 2 },
130
+ ];
131
+ for (const r of ring) mesh.box([r.x0, 0, r.z0], [r.x1, SLAB, r.z1], look.pavement);
132
+
133
+ // Blocks: a pavement slab with rounded corners, and a park's grass on it.
134
+ for (const block of plan.blocks) {
135
+ mesh.prism(roundedRect(block, 0.22), 0, SLAB, look.pavement);
136
+ if (block.kind === 'park') {
137
+ const inset = CURB * 0.6;
138
+ mesh.prism(roundedRect({ x0: block.x0 + inset, z0: block.z0 + inset, x1: block.x1 - inset, z1: block.z1 - inset }, 0.14), SLAB, SLAB + 0.012, look.parks);
139
+ if (block.plaza) {
140
+ const p = block.plaza;
141
+ flat(mesh, p.x0, p.z0, p.x1, p.z1, SLAB + 0.0125, look.path);
142
+ }
143
+ }
144
+ }
145
+ for (const path of plan.paths) flat(mesh, path.x0, path.z0, path.x1, path.z1, SLAB + 0.0135, look.path);
146
+ for (const pond of plan.ponds) {
147
+ mesh.prism(ngon(pond.x, pond.z, pond.r + 0.05, 14), SLAB, SLAB + 0.03, look.path);
148
+ mesh.prism(ngon(pond.x, pond.z, pond.r, 14), SLAB + 0.03, SLAB + 0.031, look.water, [MAT.water, 0]);
149
+ }
150
+
151
+ // Markings: dashed centre lines, and zebra crossings and stop lines where three or more streets meet.
152
+ const degree = plan.nodes.map(() => 0);
153
+ for (const e of plan.edges) {
154
+ degree[e.a]++;
155
+ degree[e.b]++;
156
+ }
157
+ for (const e of plan.edges) {
158
+ const a = plan.nodes[e.a];
159
+ const along = e.axis === 'x';
160
+ /**
161
+ * A quad on the road, in the segment's own terms.
162
+ *
163
+ * @param {number} t0 From, along the segment from junction `a`'s centre.
164
+ * @param {number} t1 To.
165
+ * @param {number} w0 From, across it (right of the way from `a` is +).
166
+ * @param {number} w1 To.
167
+ * @param {Rgb} color Its colour.
168
+ */
169
+ const mark = (t0, t1, w0, w1, color) => {
170
+ if (along) flat(mesh, a.x + t0, a.z + w0, a.x + t1, a.z + w1, MARK_Y, color);
171
+ else flat(mesh, a.x - w1, a.z + t0, a.x - w0, a.z + t1, MARK_Y, color);
172
+ };
173
+ const ends = [degree[e.a] >= 3, degree[e.b] >= 3];
174
+ const start = BOX + (ends[0] ? 0.42 : 0.12);
175
+ const stop = PITCH - BOX - (ends[1] ? 0.42 : 0.12);
176
+ const dash = 0.2;
177
+ const gap = 0.15;
178
+ const count = Math.floor((stop - start + gap) / (dash + gap));
179
+ const first = start + (stop - start - (count * (dash + gap) - gap)) / 2;
180
+ for (let k = 0; k < count; k++) mark(first + k * (dash + gap), first + k * (dash + gap) + dash, -0.016, 0.016, look.marking);
181
+ for (const [end, from, dir] of /** @type {[boolean, number, number][]} */ ([[ends[0], BOX, 1], [ends[1], PITCH - BOX, -1]])) {
182
+ if (!end) continue;
183
+ // Zebra stripes across the road, then the stop line for the lane arriving here.
184
+ for (let k = 0; k < 6; k++) {
185
+ const w = -0.42 + k * 0.16;
186
+ const t0 = from + dir * 0.06;
187
+ const t1 = from + dir * 0.28;
188
+ mark(Math.min(t0, t1), Math.max(t0, t1), w, w + 0.08, look.marking);
189
+ }
190
+ const s0 = from + dir * 0.33;
191
+ const s1 = from + dir * 0.36;
192
+ // The lane arriving at junction a runs b → a, on the −w side; at b, a → b, on the +w side.
193
+ if (dir > 0) mark(s1 - 0.03, s1, -0.46, -0.02, look.marking);
194
+ else mark(s1, s0, 0.02, 0.46, look.marking);
195
+ }
196
+ }
197
+
198
+ // Lamps, and their pools of light.
199
+ for (const l of plan.lamps) {
200
+ mesh.box([l.x - 0.014, SLAB, l.z - 0.014], [l.x + 0.014, SLAB + 0.34, l.z + 0.014], look.lamp);
201
+ mesh.box([l.x - 0.03, SLAB + 0.32, l.z - 0.03], [l.x + 0.03, SLAB + 0.355, l.z + 0.03], look.lamp, [MAT.lamp, 0], { bottom: true });
202
+ flat(glow, l.x - 0.75, l.z - 0.75, l.x + 0.75, l.z + 0.75, SLAB + 0.002, [1, 0.8, 0.55], [MAT.glow, 0]);
203
+ }
204
+
205
+ // Trees: a trunk and a faceted crown.
206
+ for (const tree of plan.trees) {
207
+ const lift = tree.r * 0.75;
208
+ mesh.box([tree.x - 0.018, tree.h, tree.z - 0.018], [tree.x + 0.018, tree.h + lift + 0.02, tree.z + 0.018], look.trunk);
209
+ mesh.sphere([tree.x, tree.h + lift + tree.r * 0.85, tree.z], tree.r, look.trees[Math.floor(tree.tone * look.trees.length)], [MAT.plain, 0], 7, 4, 0.95);
210
+ }
211
+
212
+ // Buildings.
213
+ plan.buildings.forEach((b) => {
214
+ const pick = b.glass;
215
+ const base = pick < 0.14 ? look.tints[0] : pick < 0.24 ? look.tints[1] : look.buildings;
216
+ const shade = b.tone * 0.035;
217
+ /** @type {Rgb} */
218
+ const wall = /** @type {Rgb} */ (base.map((c) => Math.min(1, Math.max(0, c + shade))));
219
+ const height = b.parts[0].y1 - b.parts[0].y0;
220
+ // Window style: punched by default, ribbons on some, a curtain wall on the tall ones.
221
+ const style = height > 1.6 && b.seed < 0.6 ? 2 : b.seed < 0.28 ? 1 : 0;
222
+ b.parts.forEach((part) => {
223
+ walls(mesh, part, wall, style + b.seed * 0.999);
224
+ flat(mesh, part.x0, part.z0, part.x1, part.z1, part.y1, look.roofs);
225
+ });
226
+ const top = b.parts[b.parts.length - 1];
227
+ const rim = 0.035;
228
+ const y = top.y1;
229
+ mesh.box([top.x0, y, top.z0], [top.x1, y + rim, top.z0 + rim], wall);
230
+ mesh.box([top.x0, y, top.z1 - rim], [top.x1, y + rim, top.z1], wall);
231
+ mesh.box([top.x0, y, top.z0 + rim], [top.x0 + rim, y + rim, top.z1 - rim], wall);
232
+ mesh.box([top.x1 - rim, y, top.z0 + rim], [top.x1, y + rim, top.z1 - rim], wall);
233
+ for (const r of b.roof) {
234
+ if (r.kind === 'box') mesh.box([r.x0, r.y0, r.z0], [r.x1, r.y1, r.z1], look.detail);
235
+ else if (r.kind === 'hut') mesh.box([r.x0, r.y0, r.z0], [r.x1, r.y1, r.z1], wall);
236
+ else if (r.kind === 'tank') {
237
+ mesh.prism(ngon(r.x, r.z, r.r, 9), r.y0, r.y1, look.detail);
238
+ mesh.prism(ngon(r.x, r.z, r.r, 9), r.y1, r.y1 + 0.035, look.detail, undefined, { top: 0.15 });
239
+ } else if (r.kind === 'garden') {
240
+ mesh.box([r.x0, r.y0, r.z0], [r.x1, r.y0 + 0.018, r.z1], look.parks);
241
+ const cx = (r.x0 + r.x1) / 2;
242
+ const cz = (r.z0 + r.z1) / 2;
243
+ for (const [dx, dz] of [[-0.3, -0.3], [0.3, 0.25], [-0.2, 0.3]]) {
244
+ const sx = cx + dx * (r.x1 - r.x0);
245
+ const sz = cz + dz * (r.z1 - r.z0);
246
+ mesh.sphere([sx, r.y0 + 0.06, sz], 0.055, look.trees[1], [MAT.plain, 0], 6, 3);
247
+ }
248
+ } else if (r.kind === 'solar') {
249
+ // Rows of panels, each a thin wedge tilted up towards the back.
250
+ const depth = (r.z1 - r.z0) / r.rows;
251
+ for (let k = 0; k < r.rows; k++) {
252
+ const z0 = r.z0 + k * depth + 0.015;
253
+ const z1 = z0 + depth - 0.04;
254
+ /** @type {Vec3[]} */
255
+ const low = [[r.x0, r.y0, z0], [r.x1, r.y0, z0], [r.x1, r.y0, z1], [r.x0, r.y0, z1]];
256
+ mesh.loft(low, low.map(([x, , z]) => /** @type {Vec3} */ ([x, r.y0 + (z === z0 ? 0.015 : 0.055), z])), look.solar, [MAT.plain, 0], { caps: 'end' });
257
+ }
258
+ }
259
+ }
260
+ });
261
+ return { solid: mesh.build(), glow: glow.build() };
262
+ }
263
+
264
+ /**
265
+ * A building part's four walls, with uv counted in window cells (u across,
266
+ * v down from the band under the roof) and the window style and seed in the tag.
267
+ *
268
+ * @param {Mesh} mesh The mesh.
269
+ * @param {import('./plan.js').Part} part The part.
270
+ * @param {Rgb} color The walls' colour.
271
+ * @param {number} seed The window style (whole part) and seed (fraction).
272
+ */
273
+ function walls(mesh, part, color, seed) {
274
+ const { x0, z0, x1, z1, y0, y1 } = part;
275
+ const rows = Math.floor((y1 - y0) / STOREY + 1e-6);
276
+ const band = y1 - y0 - rows * STOREY;
277
+ const top = rows + band / STOREY;
278
+ /** @type {Vec3} */
279
+ const inside = [(x0 + x1) / 2, (y0 + y1) / 2, (z0 + z1) / 2];
280
+ /** @type {[Vec2, Vec2][]} */
281
+ const sides = [
282
+ [[x0, z1], [x1, z1]],
283
+ [[x1, z1], [x1, z0]],
284
+ [[x1, z0], [x0, z0]],
285
+ [[x0, z0], [x0, z1]],
286
+ ];
287
+ for (const [[ax, az], [bx, bz]] of sides) {
288
+ const cells = Math.max(1, Math.round(Math.hypot(bx - ax, bz - az) / WINDOW));
289
+ const v0 = rows;
290
+ const v1 = rows - top;
291
+ mesh.quad(
292
+ [ax, y0, az],
293
+ [bx, y0, bz],
294
+ [bx, y1, bz],
295
+ [ax, y1, az],
296
+ color,
297
+ [MAT.wall, seed],
298
+ [[0, v0], [cells, v0], [cells, v1], [0, v1]],
299
+ inside,
300
+ );
301
+ }
302
+ }
303
+
304
+ /**
305
+ * The car, in its own frame: x forward, y up, z across; 0.44 long. The
306
+ * opaque body, and the effects drawn over the road (a soft shadow under it,
307
+ * headlight beams and a red glow behind, the beams only at night).
308
+ *
309
+ * @param {Look} look The colours.
310
+ * @returns {{ body: Float32Array, effects: Float32Array }} The two meshes.
311
+ */
312
+ export function carMesh(look) {
313
+ const body = createMesh();
314
+ const paint = /** @type {Vec2} */ ([MAT.body, 0]);
315
+ // A low wedge: flat underneath, a short sloping nose, a long hood to a squared-off tail.
316
+ /** @type {Vec2[]} */
317
+ const profile = [[-0.215, 0.03], [0.214, 0.03], [0.222, 0.05], [0.21, 0.068], [0.1, 0.082], [-0.2, 0.088], [-0.22, 0.076], [-0.222, 0.046]];
318
+ body.extrude(profile, -0.1, 0.1, look.accent, paint);
319
+ // The glass cabin: a raked windscreen, a short roof, a long fastback, tapering in towards the top.
320
+ /** @type {[number, number][]} */
321
+ const cabin = [[-0.19, 0.08], [0.09, 0.075], [0.0, 0.132], [-0.075, 0.13], [-0.19, 0.088]];
322
+ /**
323
+ * How far out the cabin's side is at a height.
324
+ *
325
+ * @param {number} y The height.
326
+ * @returns {number} Its half-width.
327
+ */
328
+ const half = (y) => 0.088 - ((y - 0.075) / 0.057) * 0.02;
329
+ body.loft(
330
+ cabin.map(([x, y]) => /** @type {Vec3} */ ([x, y, -half(y)])),
331
+ cabin.map(([x, y]) => /** @type {Vec3} */ ([x, y, half(y)])),
332
+ [0.11, 0.13, 0.16],
333
+ [MAT.glass, 0],
334
+ );
335
+ // Flush wheels with aero covers.
336
+ for (const x of [-0.135, 0.135]) {
337
+ for (const side of [-1, 1]) {
338
+ /** @type {Vec2[]} */
339
+ const wheel = ngon(x, 0.036, 0.036, 10);
340
+ const z0 = side * 0.072;
341
+ const z1 = side * 0.101;
342
+ body.extrude(wheel, Math.min(z0, z1), Math.max(z0, z1), [0.1, 0.105, 0.115]);
343
+ const hub = side * 0.1015;
344
+ body.extrude(ngon(x, 0.036, 0.022, 10), Math.min(hub, side * 0.095), Math.max(hub, side * 0.095), [0.52, 0.55, 0.6]);
345
+ }
346
+ }
347
+ // Light bars: across the nose, and right across the tail.
348
+ body.box([0.205, 0.058, -0.084], [0.2235, 0.065, 0.084], [1, 1, 1], [MAT.head, 0], { bottom: true });
349
+ body.box([-0.2245, 0.066, -0.093], [-0.212, 0.075, 0.093], [0.8, 0.1, 0.12], [MAT.tail, 0], { bottom: true });
350
+ // The taxis' roof sign.
351
+ body.box([-0.058, 0.124, -0.042], [0.004, 0.152, 0.042], [0.97, 0.96, 0.93], [MAT.sign, 0]);
352
+
353
+ const effects = createMesh();
354
+ flat(effects, -0.27, -0.15, 0.27, 0.15, 0.008, [0, 0, 0], [MAT.blob, 0]);
355
+ // Beams: wedges of light on the road ahead, uv x along (0 at the car), y across.
356
+ effects.quad([0.21, 0.01, -0.07], [0.21, 0.01, 0.07], [1.0, 0.01, 0.32], [1.0, 0.01, -0.32], [1, 0.93, 0.78], [MAT.beam, 0], [[0, -1], [0, 1], [1, 1], [1, -1]], [0.5, -1, 0]);
357
+ effects.quad([-0.22, 0.01, -0.09], [-0.22, 0.01, 0.09], [-0.48, 0.01, 0.14], [-0.48, 0.01, -0.14], [1, 0.12, 0.1], [MAT.beam, 0], [[0, -1], [0, 1], [1, 1], [1, -1]], [-0.3, -1, 0]);
358
+ return { body: body.build(), effects: effects.build() };
359
+ }
360
+
361
+ /**
362
+ * A person, standing: a body and a head, 0.13 tall.
363
+ *
364
+ * @param {Look} look The colours.
365
+ * @returns {Float32Array} The mesh.
366
+ */
367
+ export function personMesh(look) {
368
+ const mesh = createMesh();
369
+ mesh.prism(ngon(0, 0, 0.022, 7), 0, 0.085, look.person);
370
+ mesh.sphere([0, 0.11, 0], 0.024, [0.93, 0.82, 0.72], [MAT.plain, 0], 6, 3);
371
+ return mesh.build();
372
+ }
373
+
374
+ /**
375
+ * The pin a call drops: a head in the accent colour with a white dot
376
+ * facing the camera, on a point; and the ring that pulses round its foot.
377
+ *
378
+ * @param {Vec3} eye The direction towards the camera.
379
+ * @returns {{ body: Float32Array, ring: Float32Array }} The two meshes.
380
+ */
381
+ export function pinMesh(eye) {
382
+ const body = createMesh();
383
+ const accent = /** @type {Vec2} */ ([MAT.accent, 0]);
384
+ body.sphere([0, 0.5, 0], 0.1, [1, 1, 1], accent, 10, 6);
385
+ body.prism(ngon(0, 0, 0.082, 10), 0.47, 0.17, [1, 1, 1], accent, { top: 0 });
386
+ body.sphere([eye[0] * 0.075, 0.5 + eye[1] * 0.075, eye[2] * 0.075], 0.045, [1, 1, 1], [MAT.plain, 0], 8, 5);
387
+ const ring = createMesh();
388
+ flat(ring, -0.42, -0.42, 0.42, 0.42, 0.006, [1, 1, 1], [MAT.ring, 0]);
389
+ flat(ring, -0.12, -0.12, 0.12, 0.12, 0.007, [0, 0, 0], [MAT.blob, 0]);
390
+ return { body: body.build(), ring: ring.build() };
391
+ }
392
+
393
+ /**
394
+ * A ribbon along a route, lying just over the road: uv x is the distance
395
+ * along it, y −1 to 1 across.
396
+ *
397
+ * @param {{ x: number, z: number }[]} points The route.
398
+ * @param {number} [width=0.09] Its width.
399
+ * @param {number} [y=0.014] Its height.
400
+ * @returns {Float32Array} The mesh.
401
+ */
402
+ export function ribbonMesh(points, width = 0.09, y = 0.014) {
403
+ const mesh = createMesh();
404
+ /** @type {[number, number][]} */
405
+ const sides = [];
406
+ for (let i = 0; i < points.length; i++) {
407
+ const a = points[Math.max(0, i - 1)];
408
+ const b = points[Math.min(points.length - 1, i + 1)];
409
+ const len = Math.hypot(b.x - a.x, b.z - a.z) || 1;
410
+ sides.push([(-(b.z - a.z) / len) * (width / 2), ((b.x - a.x) / len) * (width / 2)]);
411
+ }
412
+ let d = 0;
413
+ for (let i = 1; i < points.length; i++) {
414
+ const a = points[i - 1];
415
+ const b = points[i];
416
+ const step = Math.hypot(b.x - a.x, b.z - a.z);
417
+ const [ax, az] = sides[i - 1];
418
+ const [bx, bz] = sides[i];
419
+ mesh.quad(
420
+ [a.x - ax, y, a.z - az],
421
+ [a.x + ax, y, a.z + az],
422
+ [b.x + bx, y, b.z + bz],
423
+ [b.x - bx, y, b.z - bz],
424
+ [1, 1, 1],
425
+ [MAT.route, 0],
426
+ [[d, -1], [d, 1], [d + step, 1], [d + step, -1]],
427
+ [a.x, y - 1, a.z],
428
+ );
429
+ d += step;
430
+ }
431
+ return mesh.build();
432
+ }
@@ -0,0 +1,6 @@
1
+ /** The full-screen pass under the city: the backdrop it fades into. */
2
+ export const BACKGROUND: string;
3
+ /** Every mesh's vertex shader (attributes p, aNormal, aColor, aUv, aTag; instance iPlace, iPaint, iState). */
4
+ export const VERTEX: string;
5
+ /** Every mesh's fragment shader: materials, flat light, shadows, windows, fog. */
6
+ export const FRAGMENT: string;
@@ -0,0 +1,233 @@
1
+ /**
2
+ * @module @arraypress/effects-astro/iso-city/shaders
3
+ *
4
+ * The city's shaders. One program draws everything: the static city (its
5
+ * per-instance attributes left at rest), the cars and people instanced, and
6
+ * the pin, ring and route. Light is flat: an ambient, a sky term that
7
+ * favours faces turned up, and one sun, so every material shows three
8
+ * tones (roof, lit wall, shaded wall). The ground takes soft shadows from
9
+ * a baked map, walls darken towards their feet, windows are drawn from each
10
+ * wall's window-cell uv, and everything fades into the background towards
11
+ * the edges of the city, and behind copy (`quiet`).
12
+ */
13
+
14
+ import { GLSL_OKLAB } from '../color.js';
15
+ import { GLSL_QUIET } from '../glsl.js';
16
+ import { MAT } from './scene.js';
17
+ import { SLAB, STOREY } from './plan.js';
18
+
19
+ /** GLSL: `vec3 backdrop(vec2 fragCoord)`, the ground behind the city, shared so the fog meets it exactly. */
20
+ const GLSL_BACKDROP = `
21
+ uniform vec3 uBackground;
22
+ uniform vec2 uRes;
23
+ vec3 backdrop(vec2 frag) {
24
+ vec2 q = frag / uRes - vec2(0.5, 0.62);
25
+ return uBackground * (1.0 + 0.035 * (1.0 - smoothstep(0.0, 0.7, length(q * vec2(uRes.x / uRes.y, 1.0)))));
26
+ }
27
+ `;
28
+
29
+ /** The full-screen pass under the city: the backdrop. */
30
+ export const BACKGROUND = `
31
+ precision highp float;
32
+ ${GLSL_BACKDROP}
33
+ void main() { gl_FragColor = vec4(backdrop(gl_FragCoord.xy), 1.0); }
34
+ `;
35
+
36
+ /** Every mesh's vertex shader: a vertex of its own frame, turned and placed by its instance, then seen by the camera. */
37
+ export const VERTEX = `
38
+ precision highp float;
39
+ attribute vec3 p;
40
+ attribute vec3 aNormal;
41
+ attribute vec3 aColor;
42
+ attribute vec2 aUv;
43
+ attribute vec2 aTag;
44
+ attribute vec4 iPlace;
45
+ attribute vec4 iPaint;
46
+ attribute vec4 iState;
47
+ uniform mat4 uView;
48
+ uniform vec2 uShadowShift;
49
+ varying vec3 vWorld;
50
+ varying vec3 vNormal;
51
+ varying vec3 vColor;
52
+ varying vec2 vUv;
53
+ varying vec2 vTag;
54
+ varying vec4 vPaint;
55
+ varying vec2 vState;
56
+ void main() {
57
+ vec3 l = p * iState.z;
58
+ // A squash for the pickup bounce: shorter and a little wider, or taller and slimmer.
59
+ l.y *= iState.y;
60
+ l.xz *= 1.0 + (1.0 - iState.y) * 0.6;
61
+ // Only taxis wear the roof sign.
62
+ if (abs(aTag.x - ${MAT.sign}.0) < 0.5 && iPaint.w < 0.5) l = vec3(0.0);
63
+ float c = cos(iPlace.z);
64
+ float s = sin(iPlace.z);
65
+ vec3 w = vec3(c * l.x - s * l.z, l.y + iPlace.w, s * l.x + c * l.z) + vec3(iPlace.x, 0.0, iPlace.y);
66
+ if (abs(aTag.x - ${MAT.blob}.0) < 0.5) {
67
+ // Shadows stay on the ground, fall away from the sun, and shrink as their caster rises.
68
+ w.y = l.y;
69
+ w.xz += uShadowShift * (0.08 + iPlace.w);
70
+ }
71
+ vWorld = w;
72
+ vNormal = vec3(c * aNormal.x - s * aNormal.z, aNormal.y, s * aNormal.x + c * aNormal.z);
73
+ vColor = aColor;
74
+ vUv = aUv;
75
+ vTag = aTag;
76
+ vPaint = iPaint;
77
+ vState = vec2(iState.x, iState.w);
78
+ gl_Position = uView * vec4(w, 1.0);
79
+ }
80
+ `;
81
+
82
+ /** Every mesh's fragment shader: its material, lit, fogged, premultiplied. */
83
+ export const FRAGMENT = `
84
+ precision highp float;
85
+ ${GLSL_BACKDROP}
86
+ ${GLSL_OKLAB}
87
+ ${GLSL_QUIET}
88
+ varying vec3 vWorld;
89
+ varying vec3 vNormal;
90
+ varying vec3 vColor;
91
+ varying vec2 vUv;
92
+ varying vec2 vTag;
93
+ varying vec4 vPaint;
94
+ varying vec2 vState;
95
+ uniform vec3 uSun;
96
+ uniform vec3 uSunColor;
97
+ uniform vec3 uAmbient;
98
+ uniform vec3 uSky;
99
+ uniform vec3 uEye;
100
+ uniform vec3 uAccent;
101
+ uniform vec3 uWindow;
102
+ uniform float uNight;
103
+ uniform float uTime;
104
+ uniform float uPixel;
105
+ uniform sampler2D uShadow;
106
+ uniform vec3 uShadowRect;
107
+ uniform vec4 uFog;
108
+ uniform vec4 uRoute;
109
+ uniform float uPulse;
110
+
111
+ float hash(vec2 q) { return fract(sin(dot(q, vec2(127.1, 311.7))) * 43758.5453); }
112
+
113
+ // Flat light: ambient, sky (more for faces turned up), and the sun unless shadowed.
114
+ vec3 lit(vec3 base, vec3 n, float shade) {
115
+ float sun = max(dot(n, uSun), 0.0) * (1.0 - shade);
116
+ return base * (uAmbient * (1.0 - 0.22 * shade) + uSky * (0.55 + 0.45 * n.y) + uSunColor * sun);
117
+ }
118
+
119
+ // 1 inside a box of a cell (lo to hi), softened by about a pixel.
120
+ float pane(vec2 f, vec2 lo, vec2 hi, vec2 soft) {
121
+ vec2 a = smoothstep(lo - soft, lo + soft, f) * (1.0 - smoothstep(hi - soft, hi + soft, f));
122
+ return a.x * a.y;
123
+ }
124
+
125
+ void main() {
126
+ float mat = floor(vTag.x + 0.5);
127
+ vec3 n = normalize(vNormal);
128
+ float shade = 0.0;
129
+ if (vWorld.y < 0.1 && mat < 1.5) {
130
+ shade = texture2D(uShadow, (vWorld.xz - uShadowRect.xy) * uShadowRect.z).r * (1.0 - smoothstep(0.06, 0.1, vWorld.y));
131
+ }
132
+ vec3 col;
133
+ float alpha = 1.0;
134
+ float added = 0.0;
135
+ if (mat == ${MAT.plain}.0) {
136
+ col = lit(vColor, n, shade);
137
+ } else if (mat == ${MAT.wall}.0) {
138
+ // Walls darken a little towards the pavement.
139
+ float ao = mix(0.8, 1.0, smoothstep(${SLAB}, ${SLAB + 0.32}, vWorld.y));
140
+ vec3 wall = lit(vColor, n, shade) * ao;
141
+ float style = floor(vTag.y);
142
+ float seed = fract(vTag.y);
143
+ vec2 f = fract(vUv);
144
+ vec2 cell = floor(vUv);
145
+ vec2 soft = vec2(uPixel / 0.19, uPixel / ${STOREY}) * 0.9;
146
+ bool shop = vWorld.y < ${SLAB + STOREY};
147
+ float w;
148
+ if (shop) w = pane(f, vec2(0.07, 0.12), vec2(0.93, 0.8), soft);
149
+ else if (style < 0.5) w = pane(f, vec2(0.24, 0.3), vec2(0.76, 0.8), soft);
150
+ else if (style < 1.5) w = pane(vec2(0.5, f.y), vec2(0.0, 0.32), vec2(1.0, 0.78), soft);
151
+ else w = pane(f, vec2(0.05, 0.08), vec2(0.95, 0.94), soft);
152
+ w *= step(0.0, vUv.y);
153
+ // Too small to draw sharply: an even tone instead of shimmering panes.
154
+ float size = min(0.19, ${STOREY}) / uPixel;
155
+ float sharp = smoothstep(2.5, 4.5, size);
156
+ w = mix(0.3, w, sharp);
157
+ vec3 glass = lit(mix(vColor, vec3(0.5, 0.6, 0.68), 0.45), n, shade) * (0.84 + 0.1 * f.y);
158
+ if (uNight > 0.5) {
159
+ float on = step(hash(cell + seed * 61.0 + n.xz * 7.0), shop ? 0.55 : 0.2 + seed * 0.45);
160
+ vec3 warm = uWindow * (0.75 + 0.35 * hash(cell * 1.7 + seed));
161
+ glass = mix(glass * 0.6, warm, on * mix(0.5, 1.0, sharp));
162
+ }
163
+ col = mix(wall, glass, w);
164
+ } else if (mat == ${MAT.glass}.0) {
165
+ vec3 r = reflect(-uSun, n);
166
+ float spec = pow(max(dot(r, uEye), 0.0), 14.0);
167
+ float rim = pow(1.0 - max(dot(n, uEye), 0.0), 2.0);
168
+ col = lit(vColor, n, 0.0) + spec * 0.5 * (1.0 - uNight * 0.7) + rim * uSky * 0.6;
169
+ } else if (mat == ${MAT.body}.0) {
170
+ vec3 r = reflect(-uSun, n);
171
+ col = lit(vPaint.rgb, n, 0.0) + pow(max(dot(r, uEye), 0.0), 10.0) * 0.12;
172
+ } else if (mat == ${MAT.head}.0) {
173
+ col = mix(lit(vec3(0.96), n, 0.0), vec3(1.4, 1.35, 1.25), uNight);
174
+ } else if (mat == ${MAT.tail}.0) {
175
+ col = mix(lit(vColor, n, 0.0), vColor * 1.4, max(uNight * 0.8, vState.x));
176
+ } else if (mat == ${MAT.sign}.0) {
177
+ col = mix(lit(vColor, n, 0.0), vec3(1.25, 1.2, 1.05), uNight);
178
+ } else if (mat == ${MAT.accent}.0) {
179
+ col = lit(uAccent, n, 0.0) + uAccent * 0.15 * uNight;
180
+ } else if (mat == ${MAT.lamp}.0) {
181
+ col = mix(lit(vColor, n, 0.0), vec3(1.3, 1.1, 0.8), uNight);
182
+ } else if (mat == ${MAT.water}.0) {
183
+ float ripple = sin(vWorld.x * 9.0 + uTime * 0.9) * sin(vWorld.z * 7.0 - uTime * 0.7);
184
+ col = lit(vColor, n, shade) * (1.0 + 0.04 * ripple) + smoothstep(0.75, 1.0, ripple) * 0.08;
185
+ } else if (mat == ${MAT.route}.0) {
186
+ // A dashed line flowing towards the pin, shown from the taxi (trim) to as far as it has been drawn (reveal).
187
+ float d = vUv.x;
188
+ float edge = 1.0 - smoothstep(0.55, 1.0, abs(vUv.y));
189
+ float dash = smoothstep(0.0, 0.08, fract((d - uTime * 0.55) / 0.26)) * (1.0 - smoothstep(0.55, 0.63, fract((d - uTime * 0.55) / 0.26)));
190
+ float shown = smoothstep(uRoute.x, uRoute.x + 0.25, d) * (1.0 - smoothstep(uRoute.y - 0.15, uRoute.y, d));
191
+ alpha = edge * shown * mix(0.35, 1.0, dash) * uRoute.z;
192
+ col = uAccent * alpha;
193
+ added = 0.0;
194
+ } else if (mat == ${MAT.blob}.0) {
195
+ float r = length(vUv);
196
+ alpha = (1.0 - smoothstep(0.25, 1.0, r)) * mix(0.32, 0.55, uNight) * (1.0 - vState.y);
197
+ col = vec3(0.0);
198
+ } else if (mat == ${MAT.glow}.0) {
199
+ float r = length(vUv);
200
+ float g = pow(max(0.0, 1.0 - r), 2.2) * uNight;
201
+ col = vColor * g * 0.55;
202
+ alpha = 0.0;
203
+ added = 1.0;
204
+ } else if (mat == ${MAT.beam}.0) {
205
+ float g = pow(1.0 - vUv.x, 1.6) * (1.0 - smoothstep(0.35, 1.0, abs(vUv.y))) * uNight;
206
+ col = vColor * g * 0.7;
207
+ alpha = 0.0;
208
+ added = 1.0;
209
+ } else {
210
+ // The pin's ring: one pulse spreading out, and a faint resting circle.
211
+ float r = length(vUv);
212
+ float wave = 1.0 - smoothstep(0.0, 0.06, abs(r - uPulse * 0.95));
213
+ float rest = 1.0 - smoothstep(0.0, 0.035, abs(r - 0.42));
214
+ alpha = (wave * (1.0 - uPulse) * 0.8 + rest * 0.5) * uRoute.z;
215
+ col = uAccent * alpha;
216
+ }
217
+
218
+ // Fog towards the city's edges, and behind copy.
219
+ vec2 e = abs(vWorld.xz - uFog.xy);
220
+ float far = pow(pow(e.x, 4.0) + pow(e.y, 4.0), 0.25);
221
+ float fog = smoothstep(uFog.z, uFog.w, far);
222
+ vec2 q = (gl_FragCoord.xy / uRes - 0.5) * vec2(uRes.x / uRes.y, 1.0);
223
+ fog = max(fog, (1.0 - quietOpen(q)) * uQuiet.w);
224
+ // Haze towards the top of the screen, which is further away.
225
+ fog = max(fog, smoothstep(0.6, 1.08, gl_FragCoord.y / uRes.y) * 0.4);
226
+ vec3 bg = backdrop(gl_FragCoord.xy);
227
+ if (mat >= ${MAT.route}.0) {
228
+ gl_FragColor = vec4(col * (1.0 - fog), alpha * (1.0 - fog) * (1.0 - added));
229
+ } else {
230
+ gl_FragColor = vec4(oklabMix(clamp(col, 0.0, 1.0), bg, fog), 1.0);
231
+ }
232
+ }
233
+ `;
@@ -0,0 +1,13 @@
1
+ import type { CityPlan } from './plan.js';
2
+
3
+ /** World units of ground round the street grid the map covers. */
4
+ export const MARGIN: number;
5
+
6
+ /** Where the shadow of a point at a height falls (x, z shift), with `sun` the direction towards the sun. */
7
+ export function shadowShift(sun: [number, number, number], height: number): [number, number];
8
+
9
+ /** The convex hull of some points, anticlockwise. */
10
+ export function hull(points: [number, number][]): [number, number][];
11
+
12
+ /** Bakes the ground's shadows (red: 0 lit, 1 shaded) into a canvas `resolution` (default 1024) square; `rect` is its least x, z and 1 / span. */
13
+ export function bakeShadows(plan: CityPlan, sun: [number, number, number], resolution?: number): { canvas: HTMLCanvasElement; rect: [number, number, number] };