threedog 0.5.0 → 0.7.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.
Files changed (511) hide show
  1. package/CHANGELOG.md +81 -1
  2. package/README.md +21 -13
  3. package/core/Assets.js +23 -12
  4. package/core/Audio.js +1 -1
  5. package/core/Baked.js +14 -23
  6. package/core/Budget.js +2 -2
  7. package/core/DebugOverrides.js +33 -18
  8. package/core/Describe.js +10 -11
  9. package/core/Engine.js +50 -46
  10. package/core/I18n.js +2 -2
  11. package/core/Input.js +11 -5
  12. package/core/Inspect.js +6 -3
  13. package/core/InspectMaterials.js +2 -3
  14. package/core/InspectPerf.js +11 -4
  15. package/core/MaterialInfo.js +7 -5
  16. package/core/Rays.js +7 -2
  17. package/core/Stream.js +2 -3
  18. package/core/UrlState.js +49 -9
  19. package/core/Views.js +1 -0
  20. package/core/adaptive.js +2 -2
  21. package/core/assetEntry.js +5 -2
  22. package/core/assetLoad.js +13 -15
  23. package/core/assetManifest.js +6 -3
  24. package/core/assetReport.js +4 -4
  25. package/core/batchGroups.js +9 -1
  26. package/core/catalog.js +16 -3
  27. package/core/chunkStream.js +1 -1
  28. package/core/copies.js +1 -1
  29. package/core/debugView.js +4 -4
  30. package/core/describeRender.js +104 -28
  31. package/core/describeText.js +6 -6
  32. package/core/errorCodes.js +72 -45
  33. package/core/errorHints.js +4 -1
  34. package/core/errors.js +4 -4
  35. package/core/events.generated.js +1 -0
  36. package/core/gameLights.js +9 -2
  37. package/core/lifecycle.js +2 -4
  38. package/core/lightWatch.js +5 -3
  39. package/core/loop.js +18 -11
  40. package/core/math.js +7 -0
  41. package/core/moduleSlots.js +32 -7
  42. package/core/moduleTypes.js +20 -7
  43. package/core/modules.js +7 -7
  44. package/core/namedModel.js +8 -4
  45. package/core/owned.js +33 -30
  46. package/core/page.js +43 -10
  47. package/core/pictureSlots.js +33 -0
  48. package/core/pictureWriters.js +343 -0
  49. package/core/plugins.js +64 -96
  50. package/core/sceneDelta.js +12 -4
  51. package/core/sceneMethods.js +2 -9
  52. package/core/services.js +1 -1
  53. package/core/shadowTypes.js +1 -1
  54. package/core/shadows.js +405 -0
  55. package/core/sharedPoint.js +5 -19
  56. package/core/stackFrames.js +16 -5
  57. package/core/stacks.js +6 -6
  58. package/core/startup.js +9 -11
  59. package/core/thingExplain.js +1 -1
  60. package/core/things.js +1 -1
  61. package/core/tier.js +1 -1
  62. package/core/util.js +1 -1
  63. package/core/validate.js +1 -1
  64. package/core/view.js +43 -0
  65. package/docs/AI.md +62 -58
  66. package/docs/API.md +15 -15
  67. package/docs/CODEMAP.md +36 -54
  68. package/docs/COMMANDS.md +28 -25
  69. package/docs/CONVENTIONS.md +36 -30
  70. package/docs/MIGRATING-0.4.md +93 -1
  71. package/docs/MIGRATING-0.6.md +126 -0
  72. package/docs/MIGRATING-0.7.md +39 -0
  73. package/docs/THREE.md +24 -22
  74. package/docs/api/assets.md +5 -3
  75. package/docs/api/audio.md +2 -2
  76. package/docs/api/budget.md +4 -0
  77. package/docs/api/characters.md +3 -1
  78. package/docs/api/collision.md +2 -2
  79. package/docs/api/engine.md +47 -20
  80. package/docs/api/events.md +2 -1
  81. package/docs/api/grids.md +8 -1
  82. package/docs/api/ground.md +1 -1
  83. package/docs/api/hud.md +3 -0
  84. package/docs/api/input.md +3 -2
  85. package/docs/api/interactions.md +3 -1
  86. package/docs/api/inventory.md +1 -2
  87. package/docs/api/level.md +0 -1
  88. package/docs/api/lightPool.md +1 -1
  89. package/docs/api/occlusion.md +5 -0
  90. package/docs/api/particles.md +6 -3
  91. package/docs/api/pickups.md +6 -0
  92. package/docs/api/post.md +5 -3
  93. package/docs/api/sky.md +12 -10
  94. package/docs/api/terrain.md +12 -6
  95. package/docs/api/terrainDraw.md +12 -0
  96. package/docs/api/tools.md +8 -7
  97. package/docs/api/triggers.md +2 -0
  98. package/docs/api/vegetation.md +7 -2
  99. package/docs/api/vegetationDraw.md +10 -0
  100. package/docs/api/water.md +6 -2
  101. package/docs/api/weather.md +5 -0
  102. package/docs/api/weatherDraw.md +10 -0
  103. package/docs/api/world.md +1 -1
  104. package/docs/recipes/01-new-game.md +19 -23
  105. package/docs/recipes/03-items-pickups.md +25 -4
  106. package/docs/recipes/05-props-bake.md +53 -37
  107. package/docs/recipes/06-clock-events.md +3 -3
  108. package/docs/recipes/07-flow-scenes-pause.md +12 -3
  109. package/docs/recipes/08-weather-sky.md +45 -57
  110. package/docs/recipes/09-materials-lights-models.md +185 -0
  111. package/docs/recipes/10-blender-level.md +2 -2
  112. package/docs/recipes/11-vehicles.md +3 -3
  113. package/docs/recipes/13-animation.md +13 -7
  114. package/docs/recipes/14-custom-module.md +7 -5
  115. package/docs/recipes/15-perf.md +3 -3
  116. package/docs/recipes/16-dev-bridge.md +22 -12
  117. package/docs/recipes/18-world.md +10 -8
  118. package/docs/recipes/19-shooting-picking.md +7 -5
  119. package/docs/recipes/20-content-actions-save.md +6 -2
  120. package/docs/recipes/21-camera.md +8 -3
  121. package/docs/recipes/23-ops.md +1 -1
  122. package/docs/recipes/26-ui-parts.md +35 -11
  123. package/docs/recipes/28-terrain.md +12 -12
  124. package/docs/recipes/29-grid.md +14 -5
  125. package/docs/recipes/30-templates.md +8 -3
  126. package/docs/recipes/31-audio.md +4 -4
  127. package/docs/recipes/32-action-game.md +18 -4
  128. package/docs/recipes/34-environment-lighting.md +102 -38
  129. package/docs/recipes/35-picture-from-reference.md +147 -0
  130. package/docs/recipes/36-sky-ground-plants.md +158 -0
  131. package/docs/recipes/{37-terrain-look-hooks.md → 37-terrain-hooks.md} +9 -13
  132. package/docs/recipes/38-environment-hooks.md +67 -0
  133. package/docs/recipes/40-scene.md +106 -27
  134. package/docs/recipes/42-terrain-shape.md +1 -1
  135. package/docs/recipes/{43-shader-patches-surface-looks.md → 43-shader-patches-surfaces.md} +66 -77
  136. package/docs/recipes/44-water-weather-hooks.md +191 -0
  137. package/docs/recipes/45-cascaded-shadows.md +121 -23
  138. package/docs/recipes/46-blender-art-route.md +17 -20
  139. package/docs/recipes/47-island-snow-backdrop.md +10 -12
  140. package/docs/recipes/49-game-module-contract.md +1 -1
  141. package/docs/recipes/50-own-renderer.md +3 -3
  142. package/docs/recipes/52-around-the-picture.md +181 -0
  143. package/docs/recipes/53-ground-up-close.md +12 -12
  144. package/docs/recipes/54-three-idioms.md +18 -18
  145. package/docs/recipes/55-mods-time-wrap.md +17 -5
  146. package/docs/recipes/56-webgpu-tsl.md +66 -23
  147. package/docs/recipes/57-control.md +39 -0
  148. package/docs/recipes/58-input.md +3 -0
  149. package/docs/recipes/59-depth-post-effects.md +5 -5
  150. package/docs/recipes/60-judge-the-picture.md +39 -24
  151. package/docs/recipes/61-deploy.md +27 -0
  152. package/docs/recipes/62-picture-code.md +244 -0
  153. package/docs/recipes/63-third-person-start.md +77 -0
  154. package/docs/recipes/64-particles.md +35 -0
  155. package/examples/action/.threedog/content-index.json +1 -1
  156. package/examples/action/GAMEMAP.md +7 -5
  157. package/examples/action/main.js +5 -4
  158. package/examples/action/models.js +12 -14
  159. package/examples/action/picture/index.js +13 -0
  160. package/examples/action/picture/lights.js +35 -0
  161. package/examples/action/picture/materials.js +8 -0
  162. package/examples/action/picture/palette.js +33 -0
  163. package/examples/plain-picture/.threedog/content-index.json +1 -0
  164. package/examples/plain-picture/FINDINGS.md +53 -0
  165. package/examples/plain-picture/GAMEMAP.md +90 -0
  166. package/examples/plain-picture/main.js +48 -0
  167. package/examples/plain-picture/picture/index.js +21 -0
  168. package/examples/plain-picture/picture/lights.js +54 -0
  169. package/examples/plain-picture/picture/materials.js +24 -0
  170. package/examples/plain-picture/picture/palette.js +16 -0
  171. package/examples/plain-picture/picture/sky.js +37 -0
  172. package/examples/pullable.json +31 -9
  173. package/examples/rc2d/GAMEMAP.md +8 -3
  174. package/examples/rc2d/README.md +11 -6
  175. package/examples/rc2d/main.js +25 -33
  176. package/examples/rc2d/picture/index.js +18 -0
  177. package/examples/rc2d/picture/lights.js +11 -0
  178. package/examples/rc2d/picture/materials.js +18 -0
  179. package/examples/rc2d/picture/palette.js +15 -0
  180. package/examples/rc2d/picture/post.js +11 -0
  181. package/examples/rc2d/rc2d.js +18 -28
  182. package/examples/sheepisland/.threedog/content-index.json +1 -1
  183. package/examples/sheepisland/GAMEMAP.md +13 -10
  184. package/examples/sheepisland/assets.js +2 -2
  185. package/examples/sheepisland/content/templates.js +1 -1
  186. package/examples/sheepisland/content/vegetation.js +3 -1
  187. package/examples/sheepisland/main.js +15 -9
  188. package/examples/sheepisland/{style/models.js → models.js} +13 -24
  189. package/examples/sheepisland/picture/index.js +20 -0
  190. package/examples/sheepisland/picture/lights.js +34 -0
  191. package/examples/sheepisland/picture/materials.js +61 -0
  192. package/examples/sheepisland/picture/palette.js +60 -0
  193. package/examples/sheepisland/picture/sky.js +20 -0
  194. package/examples/sheepisland/views.js +1 -1
  195. package/examples/styletest/.threedog/content-index.json +1 -1
  196. package/examples/styletest/GAMEMAP.md +15 -11
  197. package/examples/styletest/main.js +20 -30
  198. package/examples/styletest/models.js +29 -29
  199. package/examples/styletest/params.js +1 -4
  200. package/examples/styletest/picture/env.js +38 -0
  201. package/examples/styletest/picture/index.js +16 -0
  202. package/examples/styletest/picture/lights.js +9 -0
  203. package/examples/styletest/picture/materials.js +28 -0
  204. package/examples/styletest/picture/palette.js +22 -0
  205. package/examples/techniques/contact-shadows/README.md +22 -23
  206. package/examples/techniques/contact-shadows/contactShadows.js +32 -16
  207. package/examples/techniques/contact-shadows/main.js +20 -18
  208. package/examples/techniques/contact-shadows/picture/index.js +14 -0
  209. package/examples/techniques/contact-shadows/picture/lights.js +34 -0
  210. package/examples/techniques/contact-shadows/picture/materials.js +12 -0
  211. package/examples/techniques/contact-shadows/picture/palette.js +17 -0
  212. package/examples/techniques/day-night-grade/README.md +13 -16
  213. package/examples/techniques/day-night-grade/main.js +15 -25
  214. package/examples/techniques/day-night-grade/picture/index.js +20 -0
  215. package/examples/techniques/day-night-grade/picture/lights.js +45 -0
  216. package/examples/techniques/day-night-grade/picture/materials.js +15 -0
  217. package/examples/techniques/day-night-grade/picture/palette.js +59 -0
  218. package/examples/techniques/day-night-grade/picture/post.js +25 -0
  219. package/examples/techniques/day-night-grade/picture/sky.js +33 -0
  220. package/examples/techniques/interior-light/README.md +16 -13
  221. package/examples/techniques/interior-light/interiorLight.js +19 -17
  222. package/examples/techniques/interior-light/main.js +30 -67
  223. package/examples/techniques/interior-light/picture/index.js +24 -0
  224. package/examples/techniques/interior-light/picture/lights.js +52 -0
  225. package/examples/techniques/interior-light/picture/materials.js +13 -0
  226. package/examples/techniques/interior-light/picture/palette.js +32 -0
  227. package/examples/techniques/interior-light/picture/sky.js +40 -0
  228. package/examples/techniques/modular-building/README.md +4 -3
  229. package/examples/techniques/modular-building/kit.js +2 -2
  230. package/examples/techniques/modular-building/main.js +9 -17
  231. package/examples/techniques/modular-building/picture/index.js +17 -0
  232. package/examples/techniques/modular-building/picture/lights.js +26 -0
  233. package/examples/techniques/modular-building/picture/materials.js +13 -0
  234. package/examples/techniques/modular-building/picture/palette.js +23 -0
  235. package/examples/techniques/night-lights/README.md +15 -14
  236. package/examples/techniques/night-lights/main.js +20 -43
  237. package/examples/techniques/night-lights/nightLights.js +25 -21
  238. package/examples/techniques/night-lights/picture/index.js +18 -0
  239. package/examples/techniques/night-lights/picture/lights.js +44 -0
  240. package/examples/techniques/night-lights/picture/materials.js +15 -0
  241. package/examples/techniques/night-lights/picture/palette.js +34 -0
  242. package/examples/techniques/night-lights/picture/post.js +9 -0
  243. package/examples/techniques/night-lights/picture/sky.js +36 -0
  244. package/examples/techniques/outlines-and-rim/README.md +2 -2
  245. package/examples/techniques/outlines-and-rim/main.js +15 -38
  246. package/examples/techniques/outlines-and-rim/outlines.js +3 -3
  247. package/examples/techniques/outlines-and-rim/picture/index.js +16 -0
  248. package/examples/techniques/outlines-and-rim/picture/lights.js +18 -0
  249. package/examples/techniques/outlines-and-rim/picture/materials.js +11 -0
  250. package/examples/techniques/outlines-and-rim/picture/palette.js +16 -0
  251. package/examples/techniques/outlines-and-rim/picture/post.js +10 -0
  252. package/examples/techniques/procedural-animation/README.md +5 -3
  253. package/examples/techniques/procedural-animation/main.js +9 -7
  254. package/examples/techniques/procedural-animation/picture/index.js +15 -0
  255. package/examples/techniques/procedural-animation/picture/lights.js +35 -0
  256. package/examples/techniques/procedural-animation/picture/materials.js +10 -0
  257. package/examples/techniques/procedural-animation/picture/palette.js +16 -0
  258. package/examples/techniques/procedural-animation/picture/sky.js +31 -0
  259. package/examples/techniques/procedural-animation/proceduralAnim.js +1 -1
  260. package/examples/techniques/procedural-surface/README.md +2 -0
  261. package/examples/techniques/procedural-surface/main.js +17 -55
  262. package/examples/techniques/procedural-surface/picture/index.js +14 -0
  263. package/examples/techniques/procedural-surface/picture/lights.js +18 -0
  264. package/examples/techniques/procedural-surface/picture/materials.js +34 -0
  265. package/examples/techniques/procedural-surface/picture/palette.js +15 -0
  266. package/examples/techniques/stylized-shading/README.md +13 -14
  267. package/examples/techniques/stylized-shading/main.js +11 -42
  268. package/examples/techniques/stylized-shading/picture/index.js +14 -0
  269. package/examples/techniques/stylized-shading/picture/lights.js +23 -0
  270. package/examples/techniques/stylized-shading/picture/materials.js +18 -0
  271. package/examples/techniques/stylized-shading/picture/palette.js +19 -0
  272. package/examples/techniques/stylized-shading/shading.js +2 -2
  273. package/examples/techniques/sun-and-key-light/README.md +20 -22
  274. package/examples/techniques/sun-and-key-light/keyLight.js +47 -29
  275. package/examples/techniques/sun-and-key-light/main.js +19 -63
  276. package/examples/techniques/sun-and-key-light/picture/index.js +13 -0
  277. package/examples/techniques/sun-and-key-light/picture/lights.js +33 -0
  278. package/examples/techniques/sun-and-key-light/picture/materials.js +9 -0
  279. package/examples/techniques/sun-and-key-light/picture/palette.js +29 -0
  280. package/examples/techniques/sun-and-key-light/picture/sky.js +16 -0
  281. package/examples/techniques/three-looks/README.md +21 -0
  282. package/examples/techniques/three-looks/main.js +58 -0
  283. package/examples/techniques/three-looks/picture/cartoon.js +23 -0
  284. package/examples/techniques/three-looks/picture/cinematic.js +27 -0
  285. package/examples/techniques/three-looks/picture/comic.js +27 -0
  286. package/examples/techniques/three-looks/picture/index.js +14 -0
  287. package/examples/techniques/three-looks/picture/sun.js +23 -0
  288. package/examples/techniques/wet-road/README.md +7 -4
  289. package/examples/techniques/wet-road/main.js +18 -38
  290. package/examples/techniques/wet-road/picture/index.js +17 -0
  291. package/examples/techniques/wet-road/picture/lights.js +57 -0
  292. package/examples/techniques/wet-road/picture/materials.js +16 -0
  293. package/examples/techniques/wet-road/picture/palette.js +24 -0
  294. package/examples/techniques/wet-road/picture/sky.js +46 -0
  295. package/examples/webgpu-tsl/GAMEMAP.md +9 -4
  296. package/examples/webgpu-tsl/README.md +13 -10
  297. package/examples/webgpu-tsl/main.js +30 -7
  298. package/examples/webgpu-tsl/picture/index.js +18 -0
  299. package/examples/webgpu-tsl/picture/lights.js +25 -0
  300. package/examples/webgpu-tsl/picture/materials.js +36 -0
  301. package/examples/webgpu-tsl/picture/palette.js +23 -0
  302. package/examples/webgpu-tsl/picture/post.js +16 -0
  303. package/examples/webgpu-tsl/picture/sky.js +30 -0
  304. package/examples/world/.threedog/content-index.json +1 -1
  305. package/examples/world/GAMEMAP.md +15 -12
  306. package/examples/world/art/humanoid.js +9 -13
  307. package/examples/world/art/index.js +2 -2
  308. package/examples/world/art/models.js +3 -4
  309. package/examples/world/art/shapes.js +2 -2
  310. package/examples/world/assets.js +2 -2
  311. package/examples/world/content/audio.js +1 -1
  312. package/examples/world/content/items.js +1 -1
  313. package/examples/world/content/props.js +1 -1
  314. package/examples/world/content/templates.js +1 -1
  315. package/examples/world/content/vegetation.js +1 -1
  316. package/examples/world/main.js +10 -10
  317. package/examples/world/models.js +17 -7
  318. package/examples/world/picture/index.js +20 -0
  319. package/examples/world/picture/lights.js +41 -0
  320. package/examples/world/picture/materials.js +34 -0
  321. package/examples/world/picture/palette.js +74 -0
  322. package/examples/world/picture/post.js +9 -0
  323. package/examples/world/picture/sky.js +39 -0
  324. package/index.d.ts +7 -16
  325. package/index.js +7 -7
  326. package/llms.txt +15 -13
  327. package/modules/ambience/Ambience.js +1 -1
  328. package/modules/calendar/Calendar.js +1 -1
  329. package/modules/calendar/index.js +1 -0
  330. package/modules/camera/FirstPersonCamera.js +1 -1
  331. package/modules/camera/FixedCamera.js +2 -2
  332. package/modules/camera/RtsCamera.js +1 -1
  333. package/modules/camera/common.js +7 -5
  334. package/modules/characters/Character.js +15 -10
  335. package/modules/characters/NPC.js +5 -5
  336. package/modules/characters/assetModel.js +5 -4
  337. package/modules/characters/index.js +28 -3
  338. package/modules/characters/movers/common.js +6 -1
  339. package/modules/characters/movers/manual.js +3 -0
  340. package/modules/characters/movers/support.js +25 -11
  341. package/modules/characters/npcSim.js +5 -1
  342. package/modules/characters/proceduralRig.js +18 -4
  343. package/modules/characters/useModel.js +2 -2
  344. package/modules/collision/Collision.js +4 -2
  345. package/modules/content/index.js +8 -0
  346. package/modules/content/models.js +56 -11
  347. package/modules/content/props.js +5 -3
  348. package/modules/content/rules.js +12 -4
  349. package/modules/content/templates.js +5 -3
  350. package/modules/gameplay/Interactions.js +91 -16
  351. package/modules/gameplay/Inventory.js +3 -3
  352. package/modules/gameplay/dialogueBox.js +1 -1
  353. package/modules/gameplay/dialogueBubbles.js +1 -1
  354. package/modules/gameplay/interactionPrompt.js +1 -1
  355. package/modules/gameplay/interactions.contract.js +1 -1
  356. package/modules/gameplay/inventoryOps.js +2 -2
  357. package/modules/gameplay/pickups.js +62 -24
  358. package/modules/gameplay/questLog.js +2 -2
  359. package/modules/grid/Layer.js +13 -0
  360. package/modules/grid/index.js +40 -11
  361. package/modules/grid/preview.js +24 -15
  362. package/modules/grid/tiles.js +15 -19
  363. package/modules/hlod/index.js +3 -2
  364. package/modules/hud/index.js +13 -0
  365. package/modules/hud/parts.js +9 -7
  366. package/modules/level/index.js +5 -4
  367. package/modules/lights/index.js +12 -8
  368. package/modules/music/Music.js +1 -1
  369. package/modules/particles/Particles.js +41 -20
  370. package/modules/particles/effect.js +21 -6
  371. package/modules/photo/Photo.js +11 -10
  372. package/modules/settings/Settings.js +7 -7
  373. package/modules/settings/apply.js +5 -5
  374. package/modules/settings/sections.js +2 -2
  375. package/modules/settings/strings.js +1 -1
  376. package/modules/sky/Sky.js +104 -89
  377. package/modules/sky/clouds.js +16 -17
  378. package/modules/sky/dome.js +100 -0
  379. package/modules/sky/domeLayers.js +5 -5
  380. package/modules/sky/environment.js +45 -169
  381. package/modules/sky/fog.js +5 -180
  382. package/modules/sky/frame.js +26 -90
  383. package/modules/sky/season.js +3 -3
  384. package/modules/sky/shader.js +35 -29
  385. package/modules/sky/skyModule.js +25 -22
  386. package/modules/sky/tint.js +9 -11
  387. package/modules/terrain/ChunkManager.js +29 -12
  388. package/modules/terrain/draw.js +154 -0
  389. package/modules/terrain/index.js +44 -66
  390. package/modules/terrain/terrainDefaults.js +2 -2
  391. package/modules/terrain/terrainEdit.js +1 -1
  392. package/modules/terrain/terrainGen.js +2 -2
  393. package/modules/triggers/index.js +10 -6
  394. package/modules/vegetation/Vegetation.js +58 -17
  395. package/modules/vegetation/draw.js +191 -0
  396. package/modules/vegetation/groundChunks.js +1 -1
  397. package/modules/vegetation/index.js +10 -10
  398. package/modules/water/Water.js +135 -88
  399. package/modules/water/surface.js +53 -53
  400. package/modules/weather/Weather.js +52 -17
  401. package/modules/weather/particles.js +13 -5
  402. package/modules/weather/shaders.js +1 -1
  403. package/modules/weather/weatherDraw.js +141 -0
  404. package/modules/world/World.js +2 -2
  405. package/modules/world/views.js +1 -1
  406. package/package.json +3 -2
  407. package/presets.js +2 -2
  408. package/render/PostFX.js +199 -41
  409. package/render/backend.js +52 -6
  410. package/render/cascades.js +195 -0
  411. package/render/cascades.tsl.js +96 -0
  412. package/render/daylight.js +39 -0
  413. package/render/detail.js +5 -5
  414. package/render/effects.js +41 -26
  415. package/render/fx/cel.tsl.js +42 -0
  416. package/render/fx/index.js +7 -5
  417. package/render/fx/patchNodes.tsl.js +1 -1
  418. package/render/fx/postWebGPU.tsl.js +30 -7
  419. package/render/fx/sky.tsl.js +19 -92
  420. package/render/fx/water.tsl.js +1 -1
  421. package/render/layers.js +14 -0
  422. package/render/lighting.js +6 -5
  423. package/render/lightmap.js +142 -0
  424. package/render/lights.js +23 -201
  425. package/render/materials.js +44 -160
  426. package/render/neutral.js +23 -0
  427. package/render/occlusion.js +184 -0
  428. package/render/ownFrame.js +1 -1
  429. package/render/patches.js +34 -29
  430. package/render/postWebGL.js +11 -3
  431. package/render/probes.js +179 -122
  432. package/render/slots.js +4 -4
  433. package/render/terms.js +53 -101
  434. package/render/uniformDecl.js +1 -1
  435. package/types/core.d.ts +333 -296
  436. package/types/gameplay.d.ts +65 -26
  437. package/types/generated/core/Audio.d.ts +1 -1
  438. package/types/generated/core/DebugOverrides.d.ts +14 -6
  439. package/types/generated/core/Input.d.ts +9 -2
  440. package/types/generated/core/page.d.ts +9 -2
  441. package/types/generated/modules/grid/Layer.d.ts +8 -0
  442. package/types/generated/modules/grid/index.d.ts +29 -5
  443. package/types/generated/modules/particles/Particles.d.ts +13 -6
  444. package/types/generated/modules/sky/Sky.d.ts +85 -18
  445. package/types/generated/modules/sky/skyModule.d.ts +1 -1
  446. package/types/generated/modules/water/Water.d.ts +50 -3
  447. package/types/generated/modules/weather/Weather.d.ts +33 -3
  448. package/types/generated/modules/weather/weatherDraw.d.ts +11 -0
  449. package/types/generated/modules/world/World.d.ts +2 -2
  450. package/types/generated/render/PostFX.d.ts +53 -10
  451. package/types/generated/render/lighting.d.ts +29 -0
  452. package/types/generated/render/materials.d.ts +19 -44
  453. package/types/generated/render/occlusion.d.ts +13 -0
  454. package/types/physics.d.ts +5 -3
  455. package/types/tsl.d.ts +8 -0
  456. package/types/world.d.ts +376 -57
  457. package/ui/Focus.js +12 -2
  458. package/ui/LoadingScreen.js +2 -2
  459. package/ui/Parts.js +8 -4
  460. package/ui/UI.js +10 -10
  461. package/ui/cursor.js +1 -1
  462. package/ui/theme.js +33 -27
  463. package/ui/touchPart.js +1 -1
  464. package/core/look/coreParts.js +0 -219
  465. package/core/look/part.js +0 -253
  466. package/core/look/points.js +0 -255
  467. package/core/look/report.js +0 -96
  468. package/core/look/shadowPart.js +0 -63
  469. package/core/look/state.js +0 -45
  470. package/core/look/write.js +0 -70
  471. package/core/styleParts.js +0 -114
  472. package/docs/api/style.md +0 -136
  473. package/docs/api/terrainLook.md +0 -10
  474. package/docs/api/vegetationLook.md +0 -10
  475. package/docs/api/weatherLook.md +0 -10
  476. package/docs/recipes/09-style.md +0 -218
  477. package/docs/recipes/35-style-from-reference.md +0 -153
  478. package/docs/recipes/36-sky-ground-plant-looks.md +0 -118
  479. package/docs/recipes/38-environment-look-hooks.md +0 -99
  480. package/docs/recipes/41-thing-registry.md +0 -97
  481. package/docs/recipes/44-water-weather-look-hooks.md +0 -144
  482. package/docs/recipes/48-make-material.md +0 -75
  483. package/docs/recipes/52-look.md +0 -282
  484. package/examples/action/look.js +0 -5
  485. package/examples/sheepisland/style/index.js +0 -79
  486. package/examples/styletest/look.js +0 -11
  487. package/examples/techniques/day-night-grade/dayNightGrade.js +0 -76
  488. package/examples/webgpu-tsl/tslScene.js +0 -75
  489. package/examples/world/style/index.js +0 -61
  490. package/examples/world/style/plugins/10-bloom.js +0 -5
  491. package/modules/sky/cascades.js +0 -186
  492. package/modules/sky/cascades.tsl.js +0 -82
  493. package/modules/sky/look.js +0 -54
  494. package/modules/sky/lookFog.js +0 -76
  495. package/modules/sky/lookShadow.js +0 -62
  496. package/modules/sky/lookSky.js +0 -169
  497. package/modules/sky/shadow.js +0 -98
  498. package/modules/terrain/look.js +0 -83
  499. package/modules/terrain/lookGround.js +0 -66
  500. package/modules/vegetation/look.js +0 -119
  501. package/modules/vegetation/lookWind.js +0 -98
  502. package/modules/water/look.js +0 -91
  503. package/modules/water/surfaceDefaults.js +0 -3
  504. package/modules/weather/look.js +0 -74
  505. package/modules/weather/weatherLook.js +0 -135
  506. package/render/lookGlow.js +0 -139
  507. package/render/lookSurface.js +0 -224
  508. package/render/postLook.js +0 -164
  509. package/render/surface.js +0 -105
  510. package/types/generated/modules/weather/weatherLook.d.ts +0 -12
  511. package/types/style.d.ts +0 -671
@@ -9,7 +9,7 @@ never imports this folder.
9
9
  ## The principle
10
10
  A shaded surface is read through three things: where light turns into shade (the terminator), how hard that turn is, and what color the
11
11
  shade has. Stylizing is choosing those three on purpose instead of leaving them to a physical default. The columns are routes, not a ranking;
12
- choose from what the game's look should feel like.
12
+ choose from what the game's picture should feel like.
13
13
  - **Bands** (toon): the light share is cut into a few levels. Few bands read from far away; more bands drift back towards smooth shading.
14
14
  - **Soft wrap** (painterly): light wraps past the terminator, so forms read soft and light; a warm band at the terminator and colored shadows
15
15
  are what a painter adds and a renderer does not.
@@ -21,8 +21,8 @@ choose from what the game's look should feel like.
21
21
  brightest, sharpest thing in the shot? Then roughness is doing the styling instead of the art.
22
22
 
23
23
  How to judge it: shoot at the game's real camera (`threedog shot /your-page --gpu`). The bands, terminator or shade color should still be
24
- visible at that distance; if a technique only shows in a close-up, it is not part of the game's look. A very low contrast with no clipped
25
- areas in the shot's look numbers usually means the fill light (hemisphere, environment) is as strong as the sun.
24
+ visible at that distance; if a technique only shows in a close-up, it is not part of the game's picture. A very low contrast with no clipped
25
+ areas in the shot's picture numbers usually means the fill light (hemisphere, environment) is as strong as the sun.
26
26
 
27
27
  ## Plain three.js
28
28
  - Toon: [MeshToonMaterial](https://threejs.org/docs/#api/en/materials/MeshToonMaterial) with a `gradientMap` (a small `DataTexture`,
@@ -45,31 +45,30 @@ areas in the shot's look numbers usually means the fill light (hemisphere, envir
45
45
  - **Pixel art**: two or three hard bands from a palette, nearest-filtered ramp. Same cost as toon.
46
46
 
47
47
  ## The engine helper (optional convenience)
48
- Copy `shading.js` into a game; `main.js` is only the demo scene (knobs in its `PARAMS`). Every route is a patch in three's own lit material
48
+ Copy `shading.js` into a game; `main.js` (shapes) and `picture/` (this page's whole picture, plain three.js; knobs in `picture/palette.js`) are only the demo. Every route is a patch in three's own lit material
49
49
  (`applyEffects(material, { patches })`, slots `lightsPars` and `lighting`, recipe 43). The patch runs after three has summed the lights,
50
50
  re-reads the sun's direction and its shadow-map value, and changes only the sun's share (or the ambient's color). Because the light loop is
51
- untouched, the materials keep the engine's sun and shadows, hemisphere and point lights, fog, cloud shadows and seasons. Nothing edits
51
+ untouched, the materials keep your sun and shadows, hemisphere and point lights, fog, cloud shadows and seasons. Nothing edits
52
52
  `THREE.ShaderChunk`, and every number is a uniform, so materials that differ only in values share one shader program.
53
53
  Functions: `rampTexture(stops)`, `toonMaterial({ color, ramp, bands, soft, shade })`, `toonPatch(...)` for your own material,
54
54
  `painterlyMaterial({ color, wrap, terminator, shadow })`, `stylizedPbrMaterial({ color, roughness, lift })`.
55
55
 
56
- | route | what the patch does | knobs (`PARAMS` in main.js) |
56
+ | route | what the patch does | knobs (`picture/palette.js`) |
57
57
  |---|---|---|
58
- | toon, ramp texture | sun share (n.l times shadow, 0-1) looks up a 1-D texture; the texture can carry color per band | `toonRamp` stops |
59
- | toon, smoothstep | the same share cut into `bands` levels by smoothstep, `soft` = border width | `toonBands` |
60
- | both toons | the dark band's ambient leans to `shade` at the same brightness | `toonShade` |
61
- | painterly | wrapped diffuse (`threedogWrapDiffuse`), a warm band at the terminator, shade and cast shadow lean to a cool hue (`threedogShadowTint`) | `painterly` |
62
- | stylized PBR | MeshStandardMaterial with roughness and albedo chosen per surface, and here a floor under the ambient so shade keeps some color | `pbrRoughness`, `pbrLift` |
58
+ | toon, ramp texture | sun share (n.l times shadow, 0-1) looks up a 1-D texture; the texture can carry color per band | `TOON_RAMP` stops |
59
+ | toon, smoothstep | the same share cut into `bands` levels by smoothstep, `soft` = border width | `TOON_BANDS` |
60
+ | both toons | the dark band's ambient leans to `shade` at the same brightness | `TOON_SHADE` |
61
+ | painterly | wrapped diffuse (`threedogWrapDiffuse`), a warm band at the terminator, shade and cast shadow lean to a cool hue (`threedogShadowTint`) | `PAINTERLY` |
62
+ | stylized PBR | MeshStandardMaterial with roughness and albedo chosen per surface, and here a floor under the ambient so shade keeps some color | `PBR_ROUGHNESS`, `PBR_LIFT` |
63
63
 
64
64
  Cost: a few ALU operations per pixel and one texture read for the ramp route; no extra draw, render target or pass. The shadow value is read
65
65
  once more per pixel (three has already read it once), which is the most expensive part on large shadow kernels.
66
66
 
67
67
  Rules (correctness):
68
- - Patch, do not replace: keep three's light loop (`lighting` slot, not `lightingModel`) so engine shadows, fog and lights keep working.
68
+ - Patch, do not replace: keep three's light loop (`lighting` slot, not `lightingModel`) so shadows, fog and lights keep working.
69
69
  - Index 0 of `directionalLights` is the sun only when it is the shadow-casting light (three sorts casters first). A game with several
70
70
  shadow-casting directional lights must pick its own.
71
- - The demo writes `engine.lights.sun.position` and intensities directly because no sky drives them; with a sky module installed, take
72
- them with `engine.look.lights.manual(...)` first (recipe 52).
71
+ - The demo's lights are its own (`picture/lights.js`, `createEngine({ lights: false })`): the sun has to be a shadow-casting light for the patches to read its shadow map. Its `RoomEnvironment` is plain three.js too; the plastic column's hot spots are that room.
73
72
 
74
73
  Sources: written for this engine from common practice: half-Lambert / wrapped diffuse (Valve, "Shading in Valve's Source Engine", 2006),
75
74
  toon ramps (three.js `MeshToonMaterial` and its examples), colored shadows and terminator color as taught in traditional painting. No code copied.
@@ -1,46 +1,15 @@
1
1
  // @ts-check
2
2
  // Stylized shading demo (page /technique-shading.html): the same neutral models (a house block, a character-sized capsule, a ball, a ground
3
3
  // tile) five times, one column per route: toon by ramp texture, toon by smoothstep, painterly soft light, stylized PBR, and the "plastic"
4
- // mistake for comparison. The engine's default sun (with its shadow map), hemisphere light and fog light every column.
5
- // Test page for tests/specs/technique-looks.mjs: window.techTest = { THREE, columns, sun }.
4
+ // mistake for comparison. Shapes only here; the whole picture, sun with its shadow map included, is picture/.
5
+ // Test page for tests/specs/technique-pictures.mjs: window.techTest = { THREE, columns, sun, hemi }.
6
6
  import { createEngine, fixedCamera, THREE } from 'threedog';
7
- import { rampTexture, toonMaterial, painterlyMaterial, stylizedPbrMaterial } from './shading.js';
7
+ import { createPicture } from './picture/index.js';
8
8
 
9
- // ---------- parameters: change these first ----------
10
- const PARAMS = {
11
- sun: [36, 44, -8], sunIntensity: 3.2, hemi: 0.35, env: 0.35, // sun offset from its target (direction only); key / fill strengths: the fill sets how dark shade gets
12
- // neutral bases, the same in every column so only the shading differs (sRGB hex)
13
- colors: { wall: 0xc2bcb2, roof: 0x7d756e, body: 0xb0b2b8, ball: 0xaaa59d, tile: 0x96948f },
14
- toonRamp: [[0, 0.0], [0.12, 0.45], [0.55, 0xfff2df]], // [sun share where a band starts, light]: shade, mid band, a warm lit band
15
- toonBands: { bands: 3, soft: 0.02 },
16
- toonShade: { shade: 0x6a78b8, shadeStrength: 0.35 }, // the dark band leans blue-violet
17
- painterly: { wrap: 0.5, terminator: 0xff7a45, terminatorStrength: 0.35, shadow: 0x5a6fb0, shadowStrength: 0.45 },
18
- pbrRoughness: { wall: 0.9, roof: 0.75, body: 0.6, ball: 0.45, tile: 0.95 }, // designed per surface, never one value for all
19
- pbrLift: 0.12,
20
- plasticRoughness: 0.2, // the mistake: one low roughness everywhere
21
- spacing: 3.5,
22
- };
23
-
24
- const engine = createEngine({ canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), ui: { loading: false }, saveKey: 'threedog-technique-shading' });
25
- const sky = new THREE.Color(0xa3acb6);
26
- engine.scene.background = sky;
27
- engine.scene.fog = new THREE.Fog(sky, 30, 90);
28
- // no sky drives the sun here, so its position is a plain write (with a sky: look.lights.manual('sun.direction') first). From the right, lower than the default, so every model shows a lit side, a turn and a shaded side
29
- engine.lights.sun.position.copy(engine.lights.sun.target.position).add(new THREE.Vector3(...PARAMS.sun));
30
- engine.lights.sun.intensity = PARAMS.sunIntensity; // plain three.js writes: with no sky nothing else drives these
31
- engine.lights.hemi.intensity = PARAMS.hemi;
32
- engine.look.lights.set({ env: { intensity: PARAMS.env } }); // the neutral room reflection Standard materials get; strong, it flattens PBR shade // plain three.js fog: every route's material keeps three's fog chunk
9
+ const SPACING = 3.5;
10
+ const engine = createEngine({ canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), lights: false, ui: { loading: false }, saveKey: 'threedog-technique-shading' });
33
11
  engine.use(fixedCamera({ shots: { main: { position: [0, 5.2, 13.5], lookAt: [0, 0.9, 0], fov: 45 } }, start: 'main' }));
34
-
35
- const ramp = rampTexture(/** @type {[number, number][]} */ (PARAMS.toonRamp));
36
- /** @type {Record<string, (part: keyof typeof PARAMS.colors) => THREE.Material>} */
37
- const routes = {
38
- 'toon (ramp texture)': part => toonMaterial({ color: PARAMS.colors[part], ramp, ...PARAMS.toonShade }),
39
- 'toon (smoothstep)': part => toonMaterial({ color: PARAMS.colors[part], ...PARAMS.toonBands, ...PARAMS.toonShade }),
40
- painterly: part => painterlyMaterial({ color: PARAMS.colors[part], ...PARAMS.painterly }),
41
- 'stylized PBR': part => stylizedPbrMaterial({ color: PARAMS.colors[part], roughness: PARAMS.pbrRoughness[part], lift: PARAMS.pbrLift }),
42
- 'plastic (mistake)': part => new THREE.MeshStandardMaterial({ color: PARAMS.colors[part], roughness: PARAMS.plasticRoughness, metalness: 0 }),
43
- };
12
+ const picture = createPicture(engine);
44
13
 
45
14
  /** A gable roof as an extruded triangle, w wide, d deep, h high */
46
15
  function roofGeometry(w, d, h) {
@@ -62,10 +31,10 @@ function place(g, m, at) {
62
31
  engine.scene.add(mesh);
63
32
  return mesh;
64
33
  }
65
- const names = Object.keys(routes), columns = [];
34
+ const names = Object.keys(picture.routes), columns = [];
66
35
  names.forEach((name, i) => {
67
- const x = (i - (names.length - 1) / 2) * PARAMS.spacing, make = routes[name];
68
- const mats = Object.fromEntries(Object.keys(PARAMS.colors).map(p => [p, make(/** @type {any} */ (p))]));
36
+ const x = (i - (names.length - 1) / 2) * SPACING, make = picture.routes[name];
37
+ const mats = Object.fromEntries(picture.parts.map(p => [p, make(/** @type {any} */ (p))]));
69
38
  place(geo.tile, mats.tile, [x, 0.03, 0]);
70
39
  const house = place(geo.wall, mats.wall, [x, 0.86, -1.2]);
71
40
  place(geo.roof, mats.roof, [x, 1.66, -1.2]);
@@ -75,7 +44,7 @@ names.forEach((name, i) => {
75
44
  columns.push({ name, x, house, body, ball, shadowSpot: [x - 1.35, 0.06, -0.6], openSpot: [x + 1.2, 0.06, 1.9] });
76
45
  });
77
46
  // a darker ground around the tiles so their edges read
78
- const ground = new THREE.Mesh(new THREE.PlaneGeometry(200, 200), new THREE.MeshLambertMaterial({ color: 0x6c6a66 }));
47
+ const ground = new THREE.Mesh(new THREE.PlaneGeometry(200, 200), picture.ground);
79
48
  ground.rotation.x = -Math.PI / 2; ground.receiveShadow = true;
80
49
  engine.scene.add(ground);
81
50
 
@@ -89,5 +58,5 @@ if (labels) {
89
58
  }));
90
59
  }
91
60
 
92
- Object.assign(window, { engine, techTest: { THREE, columns, sun: engine.lights.sun } });
61
+ Object.assign(window, { engine, techTest: { THREE, columns, sun: picture.sun, hemi: picture.hemi } });
93
62
  engine.start();
@@ -0,0 +1,14 @@
1
+ // @ts-check
2
+ // The picture of the shading demo: wiring only. Nothing here moves, so there is no onRender; a picture with signals would call each part from one.
3
+ import { THREE } from 'threedog';
4
+ import { COLORS, FOG, PARTS, TONE_MAPPING } from './palette.js';
5
+ import { createLights } from './lights.js';
6
+ import { createMaterials } from './materials.js';
7
+
8
+ /** Returns { routes, ground, parts, sun, hemi } @param {any} engine */
9
+ export function createPicture(engine) {
10
+ engine.renderer.toneMapping = TONE_MAPPING;
11
+ engine.scene.background = new THREE.Color(COLORS.sky);
12
+ engine.scene.fog = new THREE.Fog(COLORS.sky, FOG.near, FOG.far); // every route keeps three's fog chunk
13
+ return { ...createLights(engine), ...createMaterials(), parts: Object.keys(PARTS) };
14
+ }
@@ -0,0 +1,23 @@
1
+ // @ts-check
2
+ // One sun, one ambient and a room to reflect, all fixed: the scene never changes, so the page has no signals to read.
3
+ import { THREE } from 'threedog';
4
+ import { RoomEnvironment } from 'three/addons/environments/RoomEnvironment.js';
5
+ import { COLORS, LIGHT } from './palette.js';
6
+
7
+ /** @param {any} engine */
8
+ export function createLights(engine) {
9
+ const { scene, renderer } = engine;
10
+ const hemi = new THREE.HemisphereLight(0xffffff, COLORS.shade, LIGHT.ambient);
11
+ const sun = new THREE.DirectionalLight(0xffffff, LIGHT.sunIntensity);
12
+ sun.position.set(LIGHT.sun[0], LIGHT.sun[1], LIGHT.sun[2]);
13
+ sun.castShadow = true; // index 0 of three's lit directional lights, which is the one shading.js bands
14
+ sun.shadow.mapSize.setScalar(engine.tier === 'low' ? 1024 : 2048);
15
+ Object.assign(sun.shadow.camera, { left: -30, right: 30, top: 30, bottom: -30, near: 1, far: 250 });
16
+ sun.shadow.bias = -0.0001; sun.shadow.normalBias = 0.03; sun.shadow.radius = 3;
17
+ scene.add(hemi, sun, sun.target);
18
+ const pmrem = new THREE.PMREMGenerator(renderer);
19
+ scene.environment = pmrem.fromScene(new RoomEnvironment(), 0.04).texture;
20
+ scene.environmentIntensity = LIGHT.room;
21
+ pmrem.dispose();
22
+ return { sun, hemi };
23
+ }
@@ -0,0 +1,18 @@
1
+ // @ts-check
2
+ // Materials by name: one maker per route, called with a part's name, so a column differs from the next only here.
3
+ import { THREE } from 'threedog';
4
+ import { rampTexture, toonMaterial, painterlyMaterial, stylizedPbrMaterial } from '../shading.js';
5
+ import { COLORS, PARTS, PBR_LIFT, PBR_ROUGHNESS, PAINTERLY, PLASTIC_ROUGHNESS, TOON_BANDS, TOON_RAMP, TOON_SHADE } from './palette.js';
6
+
7
+ export function createMaterials() {
8
+ const ramp = rampTexture(TOON_RAMP);
9
+ /** @type {Record<string, (part: keyof typeof PARTS) => THREE.Material>} */
10
+ const routes = {
11
+ 'toon (ramp texture)': part => toonMaterial({ color: PARTS[part], ramp, ...TOON_SHADE }),
12
+ 'toon (smoothstep)': part => toonMaterial({ color: PARTS[part], ...TOON_BANDS, ...TOON_SHADE }),
13
+ painterly: part => painterlyMaterial({ color: PARTS[part], ...PAINTERLY }),
14
+ 'stylized PBR': part => stylizedPbrMaterial({ color: PARTS[part], roughness: PBR_ROUGHNESS[part], lift: PBR_LIFT }),
15
+ 'plastic (mistake)': part => new THREE.MeshStandardMaterial({ color: PARTS[part], roughness: PLASTIC_ROUGHNESS, metalness: 0 }),
16
+ };
17
+ return { routes, ground: new THREE.MeshLambertMaterial({ color: COLORS.ground }) };
18
+ }
@@ -0,0 +1,19 @@
1
+ // @ts-check
2
+ // Shading demo palette: neutral bases, the same in every column so only the shading differs, and the values each route takes.
3
+ import { THREE } from 'threedog';
4
+
5
+ /** sRGB hex per model part; ground and sky around the columns */
6
+ export const PARTS = { wall: 0xc2bcb2, roof: 0x7d756e, body: 0xb0b2b8, ball: 0xaaa59d, tile: 0x96948f };
7
+ export const COLORS = { ground: 0x6c6a66, sky: 0xa3acb6, shade: 0xb0b0b0 };
8
+ export const TOON_RAMP = /** @type {[number, number][]} */ ([[0, 0.0], [0.12, 0.45], [0.55, 0xfff2df]]); // [sun share where a band starts, light]: shade, mid band, a warm lit band
9
+ export const TOON_BANDS = { bands: 3, soft: 0.02 };
10
+ export const TOON_SHADE = { shade: 0x6a78b8, shadeStrength: 0.35 }; // the dark band leans blue-violet
11
+ export const PAINTERLY = { wrap: 0.5, terminator: 0xff7a45, terminatorStrength: 0.35, shadow: 0x5a6fb0, shadowStrength: 0.45 };
12
+ export const PBR_ROUGHNESS = { wall: 0.9, roof: 0.75, body: 0.6, ball: 0.45, tile: 0.95 }; // designed per surface, never one value for all
13
+ export const PBR_LIFT = 0.12;
14
+ export const PLASTIC_ROUGHNESS = 0.2; // the mistake: one low roughness everywhere
15
+ /** sun: offset from its target (direction only), from the right and behind, so every model shows a lit side, a turn and a shaded side. ambient sets how dark shade
16
+ * gets; room: the reflection Standard materials get, which is what the plastic column's hot spots are made of (strong, it flattens PBR shade) */
17
+ export const LIGHT = { sun: [36, 44, -8], sunIntensity: 3.2, ambient: 0.35, room: 0.35 };
18
+ export const FOG = { near: 30, far: 90 };
19
+ export const TONE_MAPPING = THREE.AgXToneMapping;
@@ -1,7 +1,7 @@
1
1
  // @ts-check
2
2
  // Stylized shading: three routes that reshape how light lands on a surface, all as patches on three's own lit materials, so every route still
3
- // takes the engine's sun, its shadow map, hemisphere / point lights and fog (nothing here replaces the light loop or edits ShaderChunk).
4
- // Copy this file into a game (for example src/look/shading.js); it imports only three and threedog. Numbers live in uniforms, so materials
3
+ // takes the game's sun, its shadow map, hemisphere / point lights and fog (nothing here replaces the light loop or edits ShaderChunk).
4
+ // Copy this file into a game (for example src/picture/shading.js); it imports only three and threedog. Numbers live in uniforms, so materials
5
5
  // that differ only in values share one shader program.
6
6
  import * as THREE from 'three';
7
7
  import { applyEffects } from 'threedog';
@@ -60,7 +60,7 @@ off once) and how much darker the shadowed areas are, with the light parameters
60
60
  - Shadow: `renderer.shadowMap.type` (`BasicShadowMap`, `PCFShadowMap`, `VSMShadowMap`), `light.shadow.radius`, `shadow.blurSamples` (VSM),
61
61
  `shadow.mapSize`, `shadow.camera` bounds, `shadow.bias`, `shadow.normalBias`
62
62
  ([LightShadow](https://threejs.org/docs/#api/en/lights/shadows/LightShadow), [webgl_shadowmap_vsm](https://threejs.org/examples/#webgl_shadowmap_vsm)).
63
- - Large views: `CSM` from `three/addons/csm` ([webgl_shadowmap_csm](https://threejs.org/examples/#webgl_shadowmap_csm)).
63
+ - Large views: `engine.shadows.cascades(light, { count: 3 })` (recipe 45).
64
64
  - Debugging the box: `CameraHelper(light.shadow.camera)` ([CameraHelper](https://threejs.org/docs/#api/en/helpers/CameraHelper)).
65
65
 
66
66
  ## Style routes
@@ -73,10 +73,11 @@ off once) and how much darker the shadowed areas are, with the light parameters
73
73
  - **Noir / horror**: low or back key, very low fill, little color in the fill; the silhouette carries the scene.
74
74
  - **Pixel art**: `basic` shadows, hard and aliased on purpose, with a map sized so a texel matches the art's pixel.
75
75
 
76
- ## The engine helper (optional convenience)
77
- `threedog examples pull sun-and-key-light` copies `keyLight.js` and this README into the game: `applyKeyFill(engine, route, { tint })` sets
78
- key and fill colors and strengths (owner `key-light`), `aimSun(engine, { elevation, azimuth, camera })` places the sun relative to the camera,
79
- `fitSunShadow(engine, { extent, biasCm, normalBias })` fits the box and converts the bias from centimeters.
76
+ ## The helper (optional convenience)
77
+ `threedog examples pull sun-and-key-light` copies `keyLight.js` and this README into the game. It writes plain three.js on your own lights:
78
+ `applyKeyFill({ sun, hemi, scene }, route, { tint })` sets key and fill colors and strengths, `aimSun(sun, { elevation, azimuth, camera })` places
79
+ the sun relative to the camera, `fitSunShadow(sun, { extent, biasCm, normalBias })` fits the box and converts the bias from centimeters.
80
+ `applyKeyFill` and `fitSunShadow` return `{ remove() }`, which writes back the values they found. The demo's own picture is in `picture/`.
80
81
 
81
82
  The three routes, side by side:
82
83
 
@@ -87,10 +88,10 @@ The three routes, side by side:
87
88
  | fill (hemi + env) | 0.35 + 0.1, blue | 1.5 + 0.3, pale gray-blue | 0.55 + 0.1, blue |
88
89
  | shadow | pcf, radius 1 | vsm, radius 14 | pcf, radius 2 |
89
90
  | measured ground lit : shadow (linear light) | about 4.3 : 1 | about 1.25 : 1 | about 1.9 : 1 |
90
- | look numbers (`threedog shot`) | luminance 0.60, contrast 0.07 | 0.63, 0.06 | 0.51, 0.12 |
91
+ | picture numbers (`threedog shot`) | luminance 0.60, contrast 0.07 | 0.63, 0.06 | 0.51, 0.12 |
91
92
 
92
93
  The measured ratios are what this scene gives, not targets. The golden route has a lower ratio *on the ground* than noon (the key arrives at
93
- 13°) and a much higher one on walls facing the sun. The light-number estimate in `main.js` (`ratio`) overstates every ratio because the room
94
+ 13°) and a much higher one on walls facing the sun. The light-number estimate in `picture/lights.js` (`ratio`) overstates every ratio because the room
94
95
  environment adds more fill than its intensity number suggests. `tint=0` is a neutral studio, `tint=1` a natural afternoon, `tint=1.5` a
95
96
  painterly or stylized look.
96
97
 
@@ -100,32 +101,29 @@ Shadow softness and cost (GPU path):
100
101
  or a smaller map. Cost grows little with radius.
101
102
  - `vsm` + `radius` + `blurSamples`: the softest, wide penumbras for overcast or stylized looks; a blur pass and float targets (the engine's
102
103
  rough estimate: 1.6x the pcf shadow pass). Can show light bleeding where two casters overlap.
103
- - This yard fits +-12 m, 1.2 cm per texel (the texel formula and the engine default are in recipe 52, "Atmosphere parts").
104
+ - This yard fits +-12 m, 1.2 cm per texel (one texel is `2 x extent / mapSize`).
104
105
  - Cost scales with the casters drawn into the map (each shadow-casting light draws them once more) and the map's pixel count.
105
106
  `engine.budget.byTag()` and `threedog stress` show it for your scene; this example does not measure milliseconds.
106
107
 
107
- Cascades vs one fitted shadow: one fitted box (this example, `follow: false`, `extent` around the play area) is the sharpest and cheapest when
108
+ Cascades vs one fitted shadow: one fitted box (this example, `extent` around the play area) is the sharpest and cheapest when
108
109
  the camera sees a bounded area: a room, an arena, a top-down board. A large open world with a free camera wants cascades (`?cascades=3`,
109
- `look.shadow.set({ cascades: 3, maxFar })`, recipe 45): sharp near the camera, coarse far away, at the cost of drawing the casters once per
110
+ `engine.shadows.cascades(sun, { count: 3, maxFar })`, recipe 45): sharp near the camera, coarse far away, at the cost of drawing the casters once per
110
111
  cascade and a recompile when switched. Before adding cascades, try a smaller `extent` or `maxFar`.
111
112
 
112
113
  Lessons from real demos:
113
- - **Bias too large removed contact shadows.** The old sky bias was about 25 cm in world depth, so anything resting on the ground lost the
114
- shadow at its base. The engine default is now about 2 cm (`bias: -0.00005` over a 420 m shadow depth), with `normalBias` (meters) doing
115
- most of the work against acne. Try `?bias=25` and look at the small cube and ball: their shadows detach or vanish.
114
+ - **Bias too large removes contact shadows.** A bias of about 25 cm in world depth takes the shadow off the base of anything resting on the
115
+ ground. About 2 cm is plenty here, with `normalBias` (meters) doing most of the work against acne. Try `?bias=25` and look at the small cube and ball: their shadows detach or vanish.
116
116
  - **Strong hemisphere + environment washes shadows out.** The shot check reports "shadows on but none measurable". Lower the fill
117
- (`look.lights.set({ hemi })`, `env`) or the sky's ambient before blaming the shadow settings.
117
+ (`hemi.intensity`, `scene.environmentIntensity`) before blaming the shadow settings.
118
118
  - **A +-70 m shadow box blurs small objects in a compact scene.** Try `?extent=70`: the 10 cm cube's shadow turns into a smudge. Fit the box.
119
119
 
120
120
  Rules (correctness):
121
- - The engine's sky owns the sun, hemisphere, fog and shadow box. Change them through it: `engine.look.lights.set({ sun, hemi, env })`
122
- (an override layer over the keyframes), `engine.look.shadow.set({...})`, `engine.look.sky.set({ backdrop })`. To aim the sun yourself,
123
- take only its direction: `engine.look.lights.manual('sun.direction')`, then place `sun.position` relative to `sun.target`. A plain write
124
- without `manual` also works but the engine warns that it stopped writing the value (recipe 52, the ownership table).
125
- - With the sky, a game that wants a fixed sun direction also wants `look.shadow.set({ follow: false })`, or the shadow box keeps moving
126
- with `engine.focus` (here the box is centered on the yard).
127
- - `PCFSoftShadowMap` is gone in three 0.187 (three warns and uses PCF). Soft PCF edges come from `radius`; the engine's types are
128
- `basic`, `pcf`, `vsm` (`look.shadow.set({ type })`). Switching the type recompiles every lit material: do it on a settings screen.
121
+ - The lights are yours: `createEngine({ lights: false })`, your own `DirectionalLight` and `HemisphereLight`, nothing else writes them. A sun's
122
+ direction is `sun.position` relative to `sun.target`; keep the target in the scene (`scene.add(sun.target)`) so a moved target takes effect.
123
+ - The shadow box centers on `sun.target`: a fixed sun over a compact scene keeps it there (here the yard); a moving player needs the target to follow.
124
+ - After writing the box call `sun.shadow.camera.updateProjectionMatrix()`: three.js does not do it for a directional light.
125
+ - `PCFSoftShadowMap` is gone in three 0.187 (three warns and uses PCF). Soft PCF edges come from `radius`; the types are
126
+ `BasicShadowMap`, `PCFShadowMap`, `VSMShadowMap` (`renderer.shadowMap.type`). Switching the type recompiles every lit material: do it on a settings screen.
129
127
  - `bias` is in the shadow camera's 0-1 depth, so its size in meters is `bias x (far - near)`. The page converts from centimeters:
130
128
  `bias = -cm / 100 / (shadow.camera.far - shadow.camera.near)`. `normalBias` is already in meters.
131
129
  - Do not name your page's URL parameters `time`, `view`, `weather`, `pos`, `season`, `state`, `save`, `wait` or `cutscene`: those are the
@@ -1,36 +1,43 @@
1
1
  // @ts-check
2
- // Sun and key light helpers (technique example, README.md next to this file). Imports only three; works on any engine with the sky module.
3
- // Why helpers at all: aiming the sun and fitting its shadow each take three engine calls in a set order (take the direction, place position
4
- // relative to target, stop the box following); written once here so a game's lighting code holds only its own numbers.
2
+ // Sun and key light helpers (technique example, README.md next to this file). Imports only three and writes only the lights you pass in.
3
+ // Why helpers at all: aiming a sun relative to the camera and fitting its shadow are a few writes in a set order; written once here so a game's
4
+ // lighting code holds only its own numbers.
5
5
  import * as THREE from 'three';
6
6
 
7
7
  /**
8
- * Key and fill from one route: the sun is the key, the hemisphere light + room environment the fill. tint 0 = white light, 1 = the route's
9
- * colors, more = pushed further apart (warm key / cool shadows). Writes the override layer of look.lights (owner), so the sky's keyframes stay
10
- * underneath and remove() gives them back.
11
- * @param {any} engine
8
+ * Key and fill from one route: the sun is the key, the hemisphere light + the scene's environment the fill. tint 0 = white light, 1 = the route's
9
+ * colors, more = pushed further apart (warm key / cool shadows). Returns { remove() }: it writes back the values it found.
10
+ * @param {{ sun: THREE.DirectionalLight, hemi: THREE.HemisphereLight, scene?: THREE.Scene }} lights scene: for environmentIntensity; leave it out without an environment
12
11
  * @param {{ key: { intensity: number, color: string }, fill: { intensity: number, color: string, ground: string }, env: number }} route
13
- * @param {{ tint?: number, owner?: string }} [o]
12
+ * @param {{ tint?: number }} [o]
14
13
  */
15
- export function applyKeyFill(engine, route, { tint = 1, owner = 'key-light' } = {}) {
16
- const push = (/** @type {string} */ c) => '#' + new THREE.Color('#ffffff').lerp(new THREE.Color(c), tint).getHexString();
17
- return engine.look.lights.set({
18
- sun: { intensity: route.key.intensity, color: push(route.key.color) },
19
- hemi: { intensity: route.fill.intensity, color: push(route.fill.color), ground: route.fill.ground },
20
- env: { intensity: route.env },
21
- }, { owner });
14
+ export function applyKeyFill({ sun, hemi, scene }, route, { tint = 1 } = {}) {
15
+ const saved = { key: sun.intensity, keyColor: sun.color.clone(), fill: hemi.intensity, fillColor: hemi.color.clone(), ground: hemi.groundColor.clone(), env: scene?.environmentIntensity };
16
+ const white = new THREE.Color('#ffffff');
17
+ sun.intensity = route.key.intensity;
18
+ sun.color.copy(white).lerp(new THREE.Color(route.key.color), tint);
19
+ hemi.intensity = route.fill.intensity;
20
+ hemi.color.copy(white).lerp(new THREE.Color(route.fill.color), tint);
21
+ hemi.groundColor.set(route.fill.ground);
22
+ if (scene) scene.environmentIntensity = route.env;
23
+ return {
24
+ remove() {
25
+ sun.intensity = saved.key; sun.color.copy(saved.keyColor);
26
+ hemi.intensity = saved.fill; hemi.color.copy(saved.fillColor); hemi.groundColor.copy(saved.ground);
27
+ if (scene) scene.environmentIntensity = /** @type {number} */ (saved.env);
28
+ },
29
+ };
22
30
  }
23
31
 
24
32
  /**
25
33
  * Aim the sun for the composition. azimuth is measured around `target` from the camera: 0 = behind the camera (front light), 90 = from the
26
- * side, 180 = facing the camera (back light). Takes only the direction from the sky (look.lights.manual('sun.direction')); color and
27
- * intensity stay where they were. Returns the unit direction toward the sun.
28
- * @param {any} engine
34
+ * side, 180 = facing the camera (back light). Writes only the direction; color and intensity stay where they were. Returns the unit direction
35
+ * toward the sun.
36
+ * @param {THREE.DirectionalLight} sun
29
37
  * @param {{ elevation: number, azimuth: number, camera: number[], target?: number[] }} o degrees; camera / target positions
30
38
  */
31
- export function aimSun(engine, { elevation, azimuth, camera, target = [0, 0, 0] }) {
32
- engine.look.lights.manual('sun.direction');
33
- const sun = engine.lights.sun, t = new THREE.Vector3(target[0], target[1], target[2]);
39
+ export function aimSun(sun, { elevation, azimuth, camera, target = [0, 0, 0] }) {
40
+ const t = new THREE.Vector3(target[0], target[1], target[2]);
34
41
  const toCam = new THREE.Vector3(camera[0] - t.x, 0, camera[2] - t.z).normalize();
35
42
  const el = THREE.MathUtils.degToRad(elevation);
36
43
  const h = toCam.applyAxisAngle(new THREE.Vector3(0, 1, 0), THREE.MathUtils.degToRad(azimuth));
@@ -41,13 +48,24 @@ export function aimSun(engine, { elevation, azimuth, camera, target = [0, 0, 0]
41
48
  }
42
49
 
43
50
  /**
44
- * One shadow box fitted to a compact scene and centered on the sun's target (follow: false). biasCm is the depth bias in centimeters: three
45
- * adds bias in the shadow camera's 0-1 depth, i.e. a world offset of bias x (far - near). Other look.shadow keys (type, radius, blurSamples,
46
- * cascades, mapSize) pass through.
47
- * @param {any} engine
48
- * @param {{ extent: number, biasCm?: number, normalBias?: number, owner?: string } & Record<string, any>} o
51
+ * One shadow box fitted to a compact scene, centered on the sun's target. biasCm is the depth bias in centimeters: three adds bias in the shadow
52
+ * camera's 0-1 depth, i.e. a world offset of bias x (far - near). Returns { remove() }: it writes back the values it found.
53
+ * @param {THREE.DirectionalLight} sun
54
+ * @param {{ extent: number, biasCm?: number, normalBias?: number, mapSize?: number, radius?: number, blurSamples?: number }} o
49
55
  */
50
- export function fitSunShadow(engine, { extent, biasCm = 2, normalBias = 0.02, owner = 'key-light', ...rest }) {
51
- const c = engine.lights.sun.shadow.camera;
52
- return engine.look.shadow.set({ follow: false, extent, bias: -biasCm / 100 / (c.far - c.near), normalBias, ...rest }, { owner });
56
+ export function fitSunShadow(sun, { extent, biasCm = 2, normalBias = 0.02, mapSize = sun.shadow.mapSize.x, radius = sun.shadow.radius, blurSamples = sun.shadow.blurSamples }) {
57
+ const s = sun.shadow, c = s.camera;
58
+ const write = (/** @type {number} */ half, /** @type {number} */ size, /** @type {Partial<THREE.DirectionalLightShadow>} */ values) => {
59
+ Object.assign(c, { left: -half, right: half, top: half, bottom: -half });
60
+ c.updateProjectionMatrix(); // three.js does not do this for a DirectionalLight's shadow camera
61
+ Object.assign(s, values);
62
+ if (s.mapSize.x !== size) { // a map keeps the size it was made with: drop it and three.js makes the new one
63
+ s.mapSize.setScalar(size);
64
+ s.map?.dispose();
65
+ s.map = null;
66
+ }
67
+ };
68
+ const before = c.right, beforeSize = s.mapSize.x, saved = { bias: s.bias, normalBias: s.normalBias, radius: s.radius, blurSamples: s.blurSamples };
69
+ write(extent, mapSize, { bias: -biasCm / 100 / (c.far - c.near), normalBias, radius, blurSamples });
70
+ return { remove() { write(before, beforeSize, saved); } };
53
71
  }
@@ -6,66 +6,27 @@
6
6
  // &sun=front|side|back|low|top override the route's sun direction (relative to the camera)
7
7
  // &tint=0..1.5 how far key and fill are pushed apart in color (warm key / cool shadows); default per route
8
8
  // &shadow=basic|pcf|vsm &radius=N &extent=M &bias=cm &cascades=1..4 shadow filter, softness, box half size, depth bias in cm, cascades
9
- // Test page for tests/specs/techniques-light.mjs: window.sunTest = { THREE, route, ratio, points }.
10
- import { createEngine, sky, fixedCamera, THREE } from 'threedog';
11
- import { applyKeyFill, aimSun, fitSunShadow } from './keyLight.js';
9
+ // Test page for tests/specs/techniques-light.mjs: window.sunTest = { THREE, route, picture, points }. Shapes only here; the whole picture is picture/.
10
+ import { createEngine, fixedCamera, THREE } from 'threedog';
11
+ import { createPicture } from './picture/index.js';
12
+ import { DIRECTIONS, ROUTES, SHADOW_FIT } from './picture/palette.js';
12
13
 
13
- // ---- parameters: change these ----------------------------------------------------------------------------------------------------------
14
- // elevation / azimuth in degrees. azimuth is measured around the subject from the camera: 0 = sun behind the camera (front light),
15
- // 90 = from the side, 180 = facing the camera (back light). key = the sun (DirectionalLight), fill = the hemisphere light + the room environment.
16
- /** @type {Record<string, { elevation: number, azimuth: number, key: { intensity: number, color: string }, fill: { intensity: number, color: string, ground: string }, env: number, tint: number, backdrop: string, shadow: { type: 'basic' | 'pcf' | 'vsm', radius: number, blurSamples?: number } }>} */
17
- const ROUTES = {
18
- // hard noon: a strong high key, a weak blue fill -> short dark shadows, key:fill about 5:1 on the ground. Clear, graphic, a bit harsh.
19
- noon: { elevation: 72, azimuth: 35, key: { intensity: 2.7, color: '#fff3e2' }, fill: { intensity: 0.35, color: '#9fbfe8', ground: '#6d675e' }, env: 0.1,
20
- tint: 1, backdrop: '#a8c4e4', shadow: { type: 'pcf', radius: 1 } },
21
- // soft overcast: the sky is the light. A weak key, a strong near-white fill, a very soft shadow -> key:fill about 1.4:1, forms read by
22
- // gentle gradients and contact darkening only. Calm, can turn gray-flat if the fill is also dim or colorless.
23
- overcast: { elevation: 58, azimuth: 40, key: { intensity: 0.9, color: '#f1f0ec' }, fill: { intensity: 1.5, color: '#d9dee6', ground: '#8b8a86' }, env: 0.3,
24
- tint: 1, backdrop: '#c8cdd4', shadow: { type: 'vsm', radius: 14, blurSamples: 16 } },
25
- // golden hour: a low warm key from the side, a cool fill -> long shadows, lit faces glow orange, shadows read blue, rims on round tops.
26
- golden: { elevation: 13, azimuth: 50, key: { intensity: 5, color: '#ffb877' }, fill: { intensity: 0.55, color: '#7f9fdc', ground: '#5c4d40' }, env: 0.1,
27
- tint: 1, backdrop: '#e6b98f', shadow: { type: 'pcf', radius: 2 } },
28
- };
29
- // sun direction overrides (?sun=...), same units as above
30
- const DIRECTIONS = { front: [35, 0], side: [35, 90], back: [22, 165], low: [9, 60], top: [88, 0] };
31
- // one shadow box fitted to this compact yard: 2048 px over +-12 m = 1.2 cm texels (the engine's open-world default +-70 m is 6.8 cm)
32
- const SHADOW_FIT = { extent: 12, mapSize: 2048, bias: 2, normalBias: 0.02 }; // bias in centimeters here (converted below)
33
14
  const CAMERA = { position: [5.5, 3.6, 7.2], lookAt: [0, 0.8, 0] };
34
- // ------------------------------------------------------------------------------------------------------------------------------------------
35
-
36
15
  const url = new URLSearchParams(location.search);
37
16
  const routeName = url.get('route') ?? 'golden';
38
17
  const route = ROUTES[routeName];
39
18
  if (!route) throw new Error(`?route=${routeName}: use one of ${Object.keys(ROUTES).join(', ')}`);
40
19
  const num = (/** @type {string} */ k, /** @type {number} */ d) => (url.has(k) ? Number(url.get(k)) : d);
41
20
  const [elevation, azimuth] = url.has('sun') ? DIRECTIONS[/** @type {keyof typeof DIRECTIONS} */ (url.get('sun'))] ?? [route.elevation, route.azimuth] : [route.elevation, route.azimuth];
42
- const tint = num('tint', route.tint);
43
21
 
44
- const engine = createEngine({ canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), ui: { loading: false }, saveKey: 'threedog-sun-key' });
45
- // sky with a fixed time: it still owns the sun, hemisphere, fog and shadow box; the values below are layers on top of what it drives
46
- engine.use(sky({ time: '12:00' }));
22
+ // no sky module: a route fixes the sun, so nothing here needs the time of day
23
+ const engine = createEngine({ canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), lights: false, ui: { loading: false }, saveKey: 'threedog-sun-key' });
47
24
  engine.use(fixedCamera({ position: CAMERA.position, lookAt: CAMERA.lookAt }));
25
+ const picture = createPicture(engine, { route, tint: num('tint', route.tint), elevation, azimuth, camera: CAMERA.position, shadow: {
26
+ type: url.get('shadow') ?? route.shadow.type, radius: num('radius', route.shadow.radius), extent: num('extent', SHADOW_FIT.extent), biasCm: num('bias', SHADOW_FIT.bias),
27
+ normalBias: SHADOW_FIT.normalBias, mapSize: SHADOW_FIT.mapSize, cascades: num('cascades', 1), ...(route.shadow.blurSamples ? { blurSamples: route.shadow.blurSamples } : {}),
28
+ } }), { mat } = picture;
48
29
 
49
- // ---- key and fill: the override layer of look.lights (the sun is exactly this, whatever the keyframes say); keyLight.js ----
50
- applyKeyFill(engine, route, { tint, owner: 'technique' });
51
- // a flat backdrop in the fill color and fog that fades the ground into it: no dome gradient or sun disc at the wrong place
52
- engine.look.sky.set({ backdrop: route.backdrop }, { owner: 'technique' });
53
- engine.look.fog.set({ color: route.backdrop, far: 70 }, { owner: 'technique' });
54
-
55
- // ---- sun direction: taken from the sky (it would follow the time of day) and aimed for the composition ----
56
- const sunDir = aimSun(engine, { elevation, azimuth, camera: CAMERA.position });
57
- const el = THREE.MathUtils.degToRad(elevation);
58
-
59
- // ---- the shadow: one box fitted to the yard, centered on it (follow: false), filter from the route or the URL ----
60
- const biasCm = num('bias', SHADOW_FIT.bias);
61
- fitSunShadow(engine, {
62
- extent: num('extent', SHADOW_FIT.extent), biasCm, normalBias: SHADOW_FIT.normalBias, mapSize: SHADOW_FIT.mapSize, cascades: num('cascades', 1),
63
- type: url.get('shadow') ?? route.shadow.type, radius: num('radius', route.shadow.radius),
64
- ...(route.shadow.blurSamples ? { blurSamples: route.shadow.blurSamples } : {}), owner: 'technique',
65
- });
66
-
67
- // ---- the neutral gray scene (plain three.js) ----
68
- const mat = (/** @type {number} */ c, roughness = 0.85) => new THREE.MeshStandardMaterial({ color: c, roughness });
69
30
  const add = (/** @type {THREE.BufferGeometry} */ g, /** @type {THREE.Material} */ m, /** @type {number[]} */ [x, y, z]) => {
70
31
  const mesh = new THREE.Mesh(g, m);
71
32
  mesh.position.set(x, y, z);
@@ -73,23 +34,18 @@ const add = (/** @type {THREE.BufferGeometry} */ g, /** @type {THREE.Material} *
73
34
  engine.scene.add(mesh);
74
35
  return mesh;
75
36
  };
76
- const ground = add(new THREE.PlaneGeometry(160, 160), mat(0x8e8e8e, 0.95), [0, 0, 0]);
37
+ const ground = add(new THREE.PlaneGeometry(160, 160), mat.ground, [0, 0, 0]);
77
38
  ground.rotation.x = -Math.PI / 2;
78
39
  ground.castShadow = false;
79
- add(new THREE.BoxGeometry(2, 2, 2), mat(0xb8b8b8), [-2.6, 1, -1.2]); // three faces: top / sun side / shade side read the form
80
- add(new THREE.SphereGeometry(1, 48, 32), mat(0xc4c4c4, 0.6), [0.6, 1, -2.4]); // a terminator: hard or soft depends on the route
81
- add(new THREE.CylinderGeometry(0.7, 0.7, 1.4, 40), mat(0xa8a8a8), [2.8, 0.7, -0.6]);
82
- add(new THREE.CylinderGeometry(0.08, 0.08, 3, 12), mat(0x9a9a9a), [0, 1.5, 1.6]); // the pole: its shadow length is the sun elevation
83
- add(new THREE.CapsuleGeometry(0.28, 1.2, 8, 20), mat(0xbdbdbd), [-0.4, 0.88, 3.2]); // figure height (1.76 m)
84
- add(new THREE.BoxGeometry(0.1, 0.1, 0.1), mat(0xd0d0d0), [1.6, 0.05, 2.6]); // small objects: lose their contact shadow when the bias is too large
85
- add(new THREE.SphereGeometry(0.12, 24, 16), mat(0xd0d0d0), [2.1, 0.12, 2.2]);
40
+ add(new THREE.BoxGeometry(2, 2, 2), mat.cube, [-2.6, 1, -1.2]); // three faces: top / sun side / shade side read the form
41
+ add(new THREE.SphereGeometry(1, 48, 32), mat.ball, [0.6, 1, -2.4]); // a terminator: hard or soft depends on the route
42
+ add(new THREE.CylinderGeometry(0.7, 0.7, 1.4, 40), mat.drum, [2.8, 0.7, -0.6]);
43
+ add(new THREE.CylinderGeometry(0.08, 0.08, 3, 12), mat.pole, [0, 1.5, 1.6]); // the pole: its shadow length is the sun elevation
44
+ add(new THREE.CapsuleGeometry(0.28, 1.2, 8, 20), mat.figure, [-0.4, 0.88, 3.2]); // figure height (1.76 m)
45
+ add(new THREE.BoxGeometry(0.1, 0.1, 0.1), mat.small, [1.6, 0.05, 2.6]); // small objects: lose their contact shadow when the bias is too large
46
+ add(new THREE.SphereGeometry(0.12, 24, 16), mat.small, [2.1, 0.12, 2.2]);
86
47
 
87
- // key:fill from the light numbers: a surface facing the sun gets key + fill, one in shadow only fill. The ground gets the key at sin(elevation),
88
- // which is why a low sun darkens the ground and brightens the walls facing it. A rough guide only: the room environment adds more fill than its
89
- // intensity number says, so the measured ratio is lower (README "Measured"); read the real one in a shot
90
- const fillUp = route.fill.intensity + route.env;
91
- const ratio = { ground: +((route.key.intensity * Math.sin(el) + fillUp) / fillUp).toFixed(2), facing: +((route.key.intensity + fillUp) / fillUp).toFixed(2) };
92
48
  // the pole base: the spec walks from it away from the sun to measure the shadow length
93
49
  const points = { poleBase: [0, 0, 1.6] };
94
- Object.assign(window, { engine, sunTest: { THREE, route: routeName, elevation, azimuth, sunDir, ratio, points, biasCm } });
50
+ Object.assign(window, { engine, sunTest: { THREE, route: routeName, elevation, azimuth, picture, points } });
95
51
  engine.start();
@@ -0,0 +1,13 @@
1
+ // @ts-check
2
+ // The picture of the sun-and-key-light demo: wiring only. A route is fixed, so nothing here runs per frame.
3
+ import { TONE_MAPPING } from './palette.js';
4
+ import { createLights } from './lights.js';
5
+ import { createMaterials } from './materials.js';
6
+ import { createSky } from './sky.js';
7
+
8
+ /** Returns { mat, sun, hemi, sunDir, ratio }. @param {any} engine @param {Parameters<typeof createLights>[1]} o */
9
+ export function createPicture(engine, o) {
10
+ engine.renderer.toneMapping = TONE_MAPPING;
11
+ createSky(engine, o.route.backdrop);
12
+ return { ...createMaterials(), ...createLights(engine, o) };
13
+ }
@@ -0,0 +1,33 @@
1
+ // @ts-check
2
+ // Key, fill and the sun's shadow for one route. No signals: a route is a fixed composition, so everything is written once.
3
+ import { THREE } from 'threedog';
4
+ import { applyKeyFill, aimSun, fitSunShadow } from '../keyLight.js';
5
+ import { SHADOW_TYPES } from './palette.js';
6
+
7
+ /**
8
+ * @param {any} engine
9
+ * @param {{ route: any, tint: number, elevation: number, azimuth: number, camera: number[], shadow: { type: string, extent: number, biasCm: number, normalBias: number, mapSize: number, radius: number, blurSamples?: number, cascades: number } }} o
10
+ */
11
+ export function createLights(engine, { route, tint, elevation, azimuth, camera, shadow }) {
12
+ const { scene, renderer } = engine, { type, cascades, ...fit } = shadow;
13
+ const filter = SHADOW_TYPES[/** @type {keyof typeof SHADOW_TYPES} */ (type)];
14
+ if (filter === undefined) throw new Error(`?shadow=${type}: use one of ${Object.keys(SHADOW_TYPES).join(', ')}`);
15
+ renderer.shadowMap.type = filter;
16
+
17
+ const hemi = new THREE.HemisphereLight(), sun = new THREE.DirectionalLight();
18
+ sun.castShadow = true;
19
+ Object.assign(sun.shadow.camera, { near: 1, far: 320 }); // the sun stands 160 m from its target: the box reaches past it on both sides
20
+ scene.add(hemi, sun, sun.target);
21
+
22
+ applyKeyFill({ sun, hemi, scene }, route, { tint });
23
+ const sunDir = aimSun(sun, { elevation, azimuth, camera });
24
+ fitSunShadow(sun, fit);
25
+ if (cascades > 1) engine.shadows.cascades(sun, { count: cascades });
26
+
27
+ // key:fill from the light numbers: a surface facing the sun gets key + fill, one in shadow only fill. The ground gets the key at sin(elevation),
28
+ // which is why a low sun darkens the ground and brightens the walls facing it. A rough guide only: the room environment adds more fill than its
29
+ // intensity number says, so the measured ratio is lower (README "Measured"); read the real one in a shot
30
+ const fillUp = route.fill.intensity + route.env, up = Math.sin(THREE.MathUtils.degToRad(elevation));
31
+ const ratio = { ground: +((route.key.intensity * up + fillUp) / fillUp).toFixed(2), facing: +((route.key.intensity + fillUp) / fillUp).toFixed(2) };
32
+ return { sun, hemi, sunDir, ratio };
33
+ }