@driftengine/core 4.4.2 → 4.6.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 (339) hide show
  1. package/CHANGELOG.json +97 -0
  2. package/README.md +1 -1
  3. package/dist/geometry/boxCsg.d.ts +28 -0
  4. package/dist/geometry/boxCsg.js +139 -0
  5. package/dist/geometry/csg.d.ts +36 -0
  6. package/dist/geometry/csg.js +329 -0
  7. package/dist/geometry/meshBuilder.js +13 -0
  8. package/dist/geometry/meshConcat.js +1 -0
  9. package/dist/geometry/pixelFont.js +2 -0
  10. package/dist/geometry/solid.d.ts +61 -0
  11. package/dist/geometry/solid.js +152 -0
  12. package/dist/geometry/solidFlat.d.ts +35 -0
  13. package/dist/geometry/solidFlat.js +428 -0
  14. package/dist/geometry/solidHarness.d.ts +19 -0
  15. package/dist/geometry/solidHarness.js +66 -0
  16. package/dist/geometry/solidNormals.d.ts +17 -0
  17. package/dist/geometry/solidNormals.js +86 -0
  18. package/dist/geometry/solidRound.d.ts +41 -0
  19. package/dist/geometry/solidRound.js +323 -0
  20. package/dist/geometry/solidWriter.d.ts +16 -0
  21. package/dist/geometry/solidWriter.js +42 -0
  22. package/dist/index.d.ts +28 -3
  23. package/dist/index.js +20 -1
  24. package/dist/render/backend/api.d.ts +34 -14
  25. package/dist/render/backend/drawFog.d.ts +26 -0
  26. package/dist/render/backend/drawFog.js +30 -0
  27. package/dist/render/backend/materialChanges.d.ts +2 -1
  28. package/dist/render/backend/materialChanges.js +6 -1
  29. package/dist/render/backend/webgl2/glassTintPrograms.d.ts +13 -0
  30. package/dist/render/backend/webgl2/glassTintPrograms.js +38 -0
  31. package/dist/render/backend/webgl2/instanced.d.ts +24 -5
  32. package/dist/render/backend/webgl2/instanced.js +72 -15
  33. package/dist/render/backend/webgl2/renderer.d.ts +201 -16
  34. package/dist/render/backend/webgl2/renderer.js +596 -224
  35. package/dist/render/backend/webgpu/buffers.d.ts +29 -1
  36. package/dist/render/backend/webgpu/buffers.js +61 -4
  37. package/dist/render/backend/webgpu/depthPass.d.ts +1 -1
  38. package/dist/render/backend/webgpu/depthPass.js +7 -2
  39. package/dist/render/backend/webgpu/drawCommand.d.ts +5 -0
  40. package/dist/render/backend/webgpu/drawCommand.js +1 -0
  41. package/dist/render/backend/webgpu/flatPass.d.ts +6 -1
  42. package/dist/render/backend/webgpu/flatPass.js +57 -9
  43. package/dist/render/backend/webgpu/glassTintPass.d.ts +28 -0
  44. package/dist/render/backend/webgpu/glassTintPass.js +206 -0
  45. package/dist/render/backend/webgpu/gpuDrivenPass.d.ts +60 -1
  46. package/dist/render/backend/webgpu/gpuDrivenPass.js +305 -5
  47. package/dist/render/backend/webgpu/instanceCullPass.d.ts +34 -0
  48. package/dist/render/backend/webgpu/instanceCullPass.js +144 -0
  49. package/dist/render/backend/webgpu/instanced.d.ts +23 -2
  50. package/dist/render/backend/webgpu/instanced.js +41 -4
  51. package/dist/render/backend/webgpu/latePass.d.ts +30 -0
  52. package/dist/render/backend/webgpu/latePass.js +140 -0
  53. package/dist/render/backend/webgpu/lightVolumePass.js +5 -1
  54. package/dist/render/backend/webgpu/motionPass.d.ts +95 -0
  55. package/dist/render/backend/webgpu/motionPass.js +491 -0
  56. package/dist/render/backend/webgpu/pipelineCache.d.ts +10 -1
  57. package/dist/render/backend/webgpu/pipelineCache.js +11 -1
  58. package/dist/render/backend/webgpu/pointGlassTintPass.d.ts +32 -0
  59. package/dist/render/backend/webgpu/pointGlassTintPass.js +193 -0
  60. package/dist/render/backend/webgpu/pointShadowPass.d.ts +35 -6
  61. package/dist/render/backend/webgpu/pointShadowPass.js +105 -20
  62. package/dist/render/backend/webgpu/postPass.d.ts +3 -13
  63. package/dist/render/backend/webgpu/renderer.d.ts +271 -64
  64. package/dist/render/backend/webgpu/renderer.js +1395 -580
  65. package/dist/render/backend/webgpu/scatterPass.js +2 -1
  66. package/dist/render/backend/webgpu/sdfTextPass.js +6 -1
  67. package/dist/render/backend/webgpu/shaders/instanceCull.wgsl.d.ts +18 -0
  68. package/dist/render/backend/webgpu/shaders/instanceCull.wgsl.js +59 -0
  69. package/dist/render/backend/webgpu/skinPaletteRing.d.ts +4 -0
  70. package/dist/render/backend/webgpu/skinPaletteRing.js +4 -0
  71. package/dist/render/backend/webgpu/snapshotMips.d.ts +29 -0
  72. package/dist/render/backend/webgpu/snapshotMips.js +52 -0
  73. package/dist/render/backend/webgpu/surfaceTexturePass.d.ts +22 -3
  74. package/dist/render/backend/webgpu/surfaceTexturePass.js +78 -39
  75. package/dist/render/driftLight/bake.d.ts +7 -0
  76. package/dist/render/driftLight/bake.js +61 -56
  77. package/dist/render/driftLight/denseField.d.ts +46 -0
  78. package/dist/render/driftLight/denseField.js +109 -0
  79. package/dist/render/driftLight/lightField.d.ts +10 -5
  80. package/dist/render/driftLight/lightField.js +25 -19
  81. package/dist/render/driftLight/presence.d.ts +50 -0
  82. package/dist/render/driftLight/presence.js +43 -0
  83. package/dist/render/driftLight/uniforms.d.ts +3 -3
  84. package/dist/render/driftLight/uniforms.js +5 -6
  85. package/dist/render/driftLight/worldLightField.d.ts +41 -0
  86. package/dist/render/driftLight/worldLightField.js +66 -0
  87. package/dist/render/fixtureAtlas.d.ts +20 -0
  88. package/dist/render/fixtureAtlas.js +49 -0
  89. package/dist/render/glass.d.ts +45 -0
  90. package/dist/render/glass.js +39 -0
  91. package/dist/render/glassCasters.d.ts +40 -0
  92. package/dist/render/glassCasters.js +84 -0
  93. package/dist/render/glassShadow.d.ts +78 -0
  94. package/dist/render/glassShadow.js +125 -0
  95. package/dist/render/globalMediumPass.d.ts +2 -3
  96. package/dist/render/globalMediumPass.js +2 -8
  97. package/dist/render/gpudriven/lit.d.ts +12 -0
  98. package/dist/render/gpudriven/lit.js +23 -0
  99. package/dist/render/gpudriven/materialTable.d.ts +15 -5
  100. package/dist/render/gpudriven/materialTable.js +26 -6
  101. package/dist/render/gpudriven/pipeline.d.ts +1 -1
  102. package/dist/render/gpudriven/pipeline.js +4 -3
  103. package/dist/render/gpudriven/sunGlass.d.ts +35 -0
  104. package/dist/render/gpudriven/sunGlass.js +89 -0
  105. package/dist/render/instanceCull.d.ts +63 -0
  106. package/dist/render/instanceCull.js +160 -0
  107. package/dist/render/instances.d.ts +15 -0
  108. package/dist/render/lightBudget.d.ts +36 -35
  109. package/dist/render/lightBudget.js +38 -37
  110. package/dist/render/lightGrid.d.ts +42 -0
  111. package/dist/render/lightGrid.js +87 -0
  112. package/dist/render/mesh.d.ts +18 -24
  113. package/dist/render/mesh.js +51 -68
  114. package/dist/render/occlusion.d.ts +10 -0
  115. package/dist/render/occlusion.js +36 -7
  116. package/dist/render/pointGlassTint.d.ts +59 -0
  117. package/dist/render/pointGlassTint.js +198 -0
  118. package/dist/render/pointLightSelection.d.ts +7 -0
  119. package/dist/render/pointLightSelection.js +29 -4
  120. package/dist/render/pointShadowArray.d.ts +56 -3
  121. package/dist/render/pointShadowArray.js +127 -16
  122. package/dist/render/pointShadowMap.d.ts +23 -1
  123. package/dist/render/pointShadowMap.js +27 -1
  124. package/dist/render/rainField.d.ts +13 -0
  125. package/dist/render/rainField.js +27 -5
  126. package/dist/render/recon/changeFrames.d.ts +15 -0
  127. package/dist/render/recon/changeFrames.js +21 -0
  128. package/dist/render/recon/lateDepth.d.ts +11 -0
  129. package/dist/render/recon/lateDepth.js +70 -0
  130. package/dist/render/recon/lateRouting.d.ts +14 -0
  131. package/dist/render/recon/lateRouting.js +18 -0
  132. package/dist/render/recon/mover.d.ts +57 -0
  133. package/dist/render/recon/mover.js +86 -0
  134. package/dist/render/recon/resolve.d.ts +34 -4
  135. package/dist/render/recon/resolve.js +161 -20
  136. package/dist/render/renderQuality.d.ts +35 -0
  137. package/dist/render/renderQuality.js +7 -0
  138. package/dist/render/rendererHarness.js +16 -0
  139. package/dist/render/sceneTarget.d.ts +9 -1
  140. package/dist/render/sceneTarget.js +60 -12
  141. package/dist/render/shaders/depth.d.ts +16 -1
  142. package/dist/render/shaders/depth.js +94 -15
  143. package/dist/render/shaders/flat/directionalShadow.js +91 -6
  144. package/dist/render/shaders/flat/driftLight.d.ts +1 -1
  145. package/dist/render/shaders/flat/driftLight.js +32 -7
  146. package/dist/render/shaders/flat/glassTint.d.ts +6 -0
  147. package/dist/render/shaders/flat/glassTint.js +25 -0
  148. package/dist/render/shaders/flat/index.d.ts +13 -0
  149. package/dist/render/shaders/flat/index.js +9 -3
  150. package/dist/render/shaders/flat/lampGlass.d.ts +1 -0
  151. package/dist/render/shaders/flat/lampGlass.js +183 -0
  152. package/dist/render/shaders/flat/main.d.ts +1 -1
  153. package/dist/render/shaders/flat/main.js +190 -38
  154. package/dist/render/shaders/flat/pointShadow.d.ts +1 -1
  155. package/dist/render/shaders/flat/pointShadow.js +2 -0
  156. package/dist/render/shaders/flat/preamble.js +96 -26
  157. package/dist/render/shaders/flat/surfaceEffects.d.ts +29 -0
  158. package/dist/render/shaders/flat/surfaceEffects.js +152 -0
  159. package/dist/render/shaders/generated/depth.wgsl.d.ts +230 -7
  160. package/dist/render/shaders/generated/depth.wgsl.js +230 -7
  161. package/dist/render/shaders/generated/flat.wgsl.d.ts +1644 -1596
  162. package/dist/render/shaders/generated/flat.wgsl.js +1683 -1621
  163. package/dist/render/shaders/generated/globalMedium.wgsl.d.ts +3 -13
  164. package/dist/render/shaders/generated/globalMedium.wgsl.js +3 -13
  165. package/dist/render/shaders/generated/lightVolume.wgsl.d.ts +3 -13
  166. package/dist/render/shaders/generated/lightVolume.wgsl.js +21 -17
  167. package/dist/render/shaders/generated/octahedralResolve.wgsl.d.ts +29 -0
  168. package/dist/render/shaders/generated/octahedralResolve.wgsl.js +29 -0
  169. package/dist/render/shaders/generated/rush.wgsl.d.ts +21 -16
  170. package/dist/render/shaders/generated/rush.wgsl.js +21 -16
  171. package/dist/render/shaders/generated/sdfText.wgsl.d.ts +2 -2
  172. package/dist/render/shaders/generated/sdfText.wgsl.js +2 -2
  173. package/dist/render/shaders/generated/text.wgsl.d.ts +1 -1
  174. package/dist/render/shaders/generated/text.wgsl.js +1 -1
  175. package/dist/render/shaders/gi/driftLight.wgsl.d.ts +1 -1
  176. package/dist/render/shaders/gi/driftLight.wgsl.js +27 -4
  177. package/dist/render/shaders/globalMedium.js +6 -6
  178. package/dist/render/shaders/gpudriven/blendRaster.wgsl.d.ts +7 -0
  179. package/dist/render/shaders/gpudriven/blendRaster.wgsl.js +86 -1
  180. package/dist/render/shaders/gpudriven/cull.wgsl.d.ts +1 -1
  181. package/dist/render/shaders/gpudriven/cull.wgsl.js +11 -2
  182. package/dist/render/shaders/gpudriven/materialTable.wgsl.d.ts +1 -1
  183. package/dist/render/shaders/gpudriven/materialTable.wgsl.js +3 -1
  184. package/dist/render/shaders/gpudriven/shade.wgsl.js +50 -1
  185. package/dist/render/shaders/gpudriven/sunGlass.wgsl.d.ts +9 -0
  186. package/dist/render/shaders/gpudriven/sunGlass.wgsl.js +133 -0
  187. package/dist/render/shaders/lightVolume.js +6 -6
  188. package/dist/render/shaders/octahedralResolve.d.ts +8 -0
  189. package/dist/render/shaders/octahedralResolve.js +48 -17
  190. package/dist/render/shaders/recon/lateDepth.wgsl.d.ts +1 -0
  191. package/dist/render/shaders/recon/lateDepth.wgsl.js +69 -0
  192. package/dist/render/shaders/recon/motion.wgsl.d.ts +1 -1
  193. package/dist/render/shaders/recon/motion.wgsl.js +84 -0
  194. package/dist/render/shaders/recon/resolve.wgsl.d.ts +8 -7
  195. package/dist/render/shaders/recon/resolve.wgsl.js +161 -27
  196. package/dist/render/shaders/rush.js +11 -1
  197. package/dist/render/shaders/sdfText.d.ts +1 -1
  198. package/dist/render/shaders/sdfText.js +3 -2
  199. package/dist/render/shaders/text.d.ts +1 -1
  200. package/dist/render/shaders/text.js +18 -9
  201. package/dist/render/shadowCasters.d.ts +20 -1
  202. package/dist/render/shadowCasters.js +15 -1
  203. package/dist/render/shadowMap.d.ts +54 -5
  204. package/dist/render/shadowMap.js +190 -36
  205. package/dist/render/sunGlassTint.d.ts +25 -0
  206. package/dist/render/sunGlassTint.js +79 -0
  207. package/dist/render/surfaceEffects.d.ts +83 -0
  208. package/dist/render/surfaceEffects.js +75 -0
  209. package/dist/render/surfaceScene.d.ts +8 -0
  210. package/dist/render/surfaceScene.js +8 -0
  211. package/dist/render/surfaceTexture.d.ts +18 -2
  212. package/dist/render/surfaceTexture.js +68 -15
  213. package/dist/render/temporalAa.d.ts +25 -6
  214. package/dist/render/temporalAa.js +45 -15
  215. package/dist/render/textureSource.d.ts +30 -0
  216. package/dist/render/textureSource.js +53 -0
  217. package/dist/render/translucentQueue.d.ts +6 -0
  218. package/dist/render/translucentQueue.js +15 -1
  219. package/dist/render/vertexDefaults.js +2 -0
  220. package/dist/world/hlod.d.ts +104 -0
  221. package/dist/world/hlod.js +214 -0
  222. package/package.json +6 -6
  223. package/src/geometry/boxCsg.ts +186 -0
  224. package/src/geometry/csg.ts +384 -0
  225. package/src/geometry/meshBuilder.ts +15 -0
  226. package/src/geometry/meshConcat.ts +1 -0
  227. package/src/geometry/pixelFont.ts +2 -0
  228. package/src/geometry/solid.ts +189 -0
  229. package/src/geometry/solidFlat.ts +522 -0
  230. package/src/geometry/solidHarness.ts +83 -0
  231. package/src/geometry/solidNormals.ts +103 -0
  232. package/src/geometry/solidRound.ts +443 -0
  233. package/src/geometry/solidWriter.ts +58 -0
  234. package/src/index.ts +61 -1
  235. package/src/render/backend/api.ts +36 -11
  236. package/src/render/backend/drawFog.ts +31 -0
  237. package/src/render/backend/materialChanges.ts +9 -2
  238. package/src/render/backend/webgl2/glassTintPrograms.ts +58 -0
  239. package/src/render/backend/webgl2/instanced.ts +80 -14
  240. package/src/render/backend/webgl2/renderer.ts +700 -250
  241. package/src/render/backend/webgpu/buffers.ts +92 -5
  242. package/src/render/backend/webgpu/depthPass.ts +7 -2
  243. package/src/render/backend/webgpu/drawCommand.ts +6 -0
  244. package/src/render/backend/webgpu/flatPass.ts +62 -11
  245. package/src/render/backend/webgpu/glassTintPass.ts +245 -0
  246. package/src/render/backend/webgpu/gpuDrivenPass.ts +349 -5
  247. package/src/render/backend/webgpu/instanceCullPass.ts +165 -0
  248. package/src/render/backend/webgpu/instanced.ts +42 -4
  249. package/src/render/backend/webgpu/latePass.ts +161 -0
  250. package/src/render/backend/webgpu/lightVolumePass.ts +5 -1
  251. package/src/render/backend/webgpu/motionPass.ts +535 -0
  252. package/src/render/backend/webgpu/pipelineCache.ts +12 -1
  253. package/src/render/backend/webgpu/pointGlassTintPass.ts +233 -0
  254. package/src/render/backend/webgpu/pointShadowPass.ts +158 -26
  255. package/src/render/backend/webgpu/renderer.ts +1671 -670
  256. package/src/render/backend/webgpu/scatterPass.ts +2 -1
  257. package/src/render/backend/webgpu/sdfTextPass.ts +6 -1
  258. package/src/render/backend/webgpu/shaders/instanceCull.wgsl.ts +61 -0
  259. package/src/render/backend/webgpu/skinPaletteRing.ts +4 -0
  260. package/src/render/backend/webgpu/snapshotMips.ts +80 -0
  261. package/src/render/backend/webgpu/surfaceTexturePass.ts +91 -51
  262. package/src/render/driftLight/bake.ts +85 -62
  263. package/src/render/driftLight/denseField.ts +149 -0
  264. package/src/render/driftLight/lightField.ts +33 -18
  265. package/src/render/driftLight/presence.ts +69 -0
  266. package/src/render/driftLight/uniforms.ts +8 -9
  267. package/src/render/driftLight/worldLightField.ts +83 -0
  268. package/src/render/fixtureAtlas.ts +63 -0
  269. package/src/render/glass.ts +74 -0
  270. package/src/render/glassCasters.ts +164 -0
  271. package/src/render/glassShadow.ts +153 -0
  272. package/src/render/globalMediumPass.ts +4 -11
  273. package/src/render/gpudriven/lit.ts +31 -0
  274. package/src/render/gpudriven/materialTable.ts +28 -6
  275. package/src/render/gpudriven/pipeline.ts +4 -3
  276. package/src/render/gpudriven/sunGlass.ts +117 -0
  277. package/src/render/instanceCull.ts +205 -0
  278. package/src/render/instances.ts +16 -0
  279. package/src/render/lightBudget.ts +41 -38
  280. package/src/render/lightGrid.ts +130 -0
  281. package/src/render/mesh.ts +59 -72
  282. package/src/render/occlusion.ts +51 -7
  283. package/src/render/pointGlassTint.ts +250 -0
  284. package/src/render/pointLightSelection.ts +72 -4
  285. package/src/render/pointShadowArray.ts +188 -22
  286. package/src/render/pointShadowMap.ts +41 -0
  287. package/src/render/rainField.ts +39 -5
  288. package/src/render/recon/changeFrames.ts +24 -0
  289. package/src/render/recon/lateDepth.ts +83 -0
  290. package/src/render/recon/lateRouting.ts +29 -0
  291. package/src/render/recon/mover.ts +118 -0
  292. package/src/render/recon/resolve.ts +206 -20
  293. package/src/render/renderQuality.ts +47 -0
  294. package/src/render/rendererHarness.ts +16 -0
  295. package/src/render/sceneTarget.ts +62 -11
  296. package/src/render/shaders/depth.ts +118 -15
  297. package/src/render/shaders/flat/directionalShadow.ts +97 -6
  298. package/src/render/shaders/flat/driftLight.ts +32 -7
  299. package/src/render/shaders/flat/glassTint.ts +25 -0
  300. package/src/render/shaders/flat/index.ts +22 -3
  301. package/src/render/shaders/flat/lampGlass.ts +185 -0
  302. package/src/render/shaders/flat/main.ts +190 -38
  303. package/src/render/shaders/flat/pointShadow.ts +2 -0
  304. package/src/render/shaders/flat/preamble.ts +96 -26
  305. package/src/render/shaders/flat/surfaceEffects.ts +152 -0
  306. package/src/render/shaders/generated/depth.wgsl.ts +237 -7
  307. package/src/render/shaders/generated/flat.wgsl.ts +1685 -1621
  308. package/src/render/shaders/generated/globalMedium.wgsl.ts +3 -13
  309. package/src/render/shaders/generated/lightVolume.wgsl.ts +23 -17
  310. package/src/render/shaders/generated/octahedralResolve.wgsl.ts +30 -0
  311. package/src/render/shaders/generated/rush.wgsl.ts +21 -16
  312. package/src/render/shaders/generated/sdfText.wgsl.ts +2 -2
  313. package/src/render/shaders/generated/text.wgsl.ts +1 -1
  314. package/src/render/shaders/gi/driftLight.wgsl.ts +27 -4
  315. package/src/render/shaders/globalMedium.ts +6 -6
  316. package/src/render/shaders/gpudriven/blendRaster.wgsl.ts +88 -1
  317. package/src/render/shaders/gpudriven/cull.wgsl.ts +11 -2
  318. package/src/render/shaders/gpudriven/materialTable.wgsl.ts +3 -1
  319. package/src/render/shaders/gpudriven/shade.wgsl.ts +50 -1
  320. package/src/render/shaders/gpudriven/sunGlass.wgsl.ts +139 -0
  321. package/src/render/shaders/lightVolume.ts +6 -6
  322. package/src/render/shaders/octahedralResolve.ts +50 -17
  323. package/src/render/shaders/recon/lateDepth.wgsl.ts +72 -0
  324. package/src/render/shaders/recon/motion.wgsl.ts +84 -0
  325. package/src/render/shaders/recon/resolve.wgsl.ts +161 -27
  326. package/src/render/shaders/rush.ts +11 -1
  327. package/src/render/shaders/sdfText.ts +3 -2
  328. package/src/render/shaders/text.ts +18 -9
  329. package/src/render/shadowCasters.ts +28 -1
  330. package/src/render/shadowMap.ts +231 -37
  331. package/src/render/sunGlassTint.ts +86 -0
  332. package/src/render/surfaceEffects.ts +132 -0
  333. package/src/render/surfaceScene.ts +16 -0
  334. package/src/render/surfaceTexture.ts +110 -19
  335. package/src/render/temporalAa.ts +78 -14
  336. package/src/render/textureSource.ts +72 -0
  337. package/src/render/translucentQueue.ts +20 -1
  338. package/src/render/vertexDefaults.ts +2 -0
  339. package/src/world/hlod.ts +290 -0
@@ -49,6 +49,17 @@ export interface RainFieldOptions {
49
49
  streakSec?: number;
50
50
  /** The ground drops land on, and the roofs they do not fall through. */
51
51
  ground?: GroundSurface;
52
+ /**
53
+ * How near the viewer a streak may pass and still be drawn, metres. Default 1.
54
+ *
55
+ * **A drop that close is out of any focus a camera holds**, and drawn sharp it was a bar across
56
+ * the frame: a streak is a world-space width, so a 6 mm drop 30 cm from the eye drew fourteen
57
+ * pixels thick and as long as the frame, from a city seen from the air in the rain. A streak
58
+ * whose nearest point is inside this distance is not drawn; the drop keeps falling, as a
59
+ * sheltered one does. What it gives up is rain on a lens or a visor, which this field never
60
+ * drew as such anyway. What would make it wrong is a view that wants drops in macro: pass 0.
61
+ */
62
+ clearM?: number;
52
63
  }
53
64
  export declare class RainField {
54
65
  readonly segments: LineSegments;
@@ -71,6 +82,8 @@ export declare class RainField {
71
82
  */
72
83
  streakSec: number;
73
84
  private readonly ground;
85
+ /** How near the viewer a streak may pass and still be drawn, squared. */
86
+ private readonly clear2;
74
87
  /** Drops not drawn this update because something was over them. */
75
88
  private sheltered;
76
89
  /**
@@ -41,6 +41,8 @@ export class RainField {
41
41
  */
42
42
  streakSec;
43
43
  ground;
44
+ /** How near the viewer a streak may pass and still be drawn, squared. */
45
+ clear2;
44
46
  /** Drops not drawn this update because something was over them. */
45
47
  sheltered = 0;
46
48
  /**
@@ -68,6 +70,8 @@ export class RainField {
68
70
  this.speedMps = options.speedMps ?? 9;
69
71
  this.streakSec = options.streakSec ?? 0.04;
70
72
  this.ground = options.ground ?? null;
73
+ const clear = options.clearM ?? 1;
74
+ this.clear2 = clear * clear;
71
75
  this.segments = createLineSegments(options.count);
72
76
  this.x = new Float32Array(options.count);
73
77
  this.y = new Float32Array(options.count);
@@ -141,15 +145,33 @@ export class RainField {
141
145
  this.sheltered++;
142
146
  continue;
143
147
  }
148
+ /* Where it was a shutter-time ago, which is the streak: down by its fall and back along the
149
+ wind, so a gust leans every drop at the same angle without anything trigonometric. */
150
+ const backX = -windX * this.streakSec;
151
+ const backY = this.speedMps * this.streakSec;
152
+ const backZ = -windZ * this.streakSec;
153
+ /* Too near the eye to be drawn (`clearM`): the streak's nearest point to the viewer. */
154
+ if (this.clear2 > 0) {
155
+ const ox = dropX - viewerX;
156
+ const oy = dropY - viewerY;
157
+ const oz = dropZ - viewerZ;
158
+ const length2 = backX * backX + backY * backY + backZ * backZ;
159
+ const along = length2 > 0
160
+ ? Math.min(Math.max(-(ox * backX + oy * backY + oz * backZ) / length2, 0), 1)
161
+ : 0;
162
+ const nx = ox + backX * along;
163
+ const ny = oy + backY * along;
164
+ const nz = oz + backZ * along;
165
+ if (nx * nx + ny * ny + nz * nz < this.clear2)
166
+ continue;
167
+ }
144
168
  const at = this.segments.count;
145
169
  this.segments.from[at * 3] = dropX;
146
170
  this.segments.from[at * 3 + 1] = dropY;
147
171
  this.segments.from[at * 3 + 2] = dropZ;
148
- /* Where it was a shutter-time ago, which is the streak: down by its fall and back along the
149
- wind, so a gust leans every drop at the same angle without anything trigonometric. */
150
- this.segments.to[at * 3] = dropX - windX * this.streakSec;
151
- this.segments.to[at * 3 + 1] = dropY + this.speedMps * this.streakSec;
152
- this.segments.to[at * 3 + 2] = dropZ - windZ * this.streakSec;
172
+ this.segments.to[at * 3] = dropX + backX;
173
+ this.segments.to[at * 3 + 1] = dropY + backY;
174
+ this.segments.to[at * 3 + 2] = dropZ + backZ;
153
175
  this.segments.count = at + 1;
154
176
  }
155
177
  this.primed = true;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Which frame a change to a dynamic mesh or an instanced batch belongs to.
3
+ *
4
+ * **A consumer may change geometry in its simulation step, before `beginFrame`.** That change is
5
+ * what the *next* frame draws, so it is that frame's — counting it against the frame last begun
6
+ * would say the geometry changed a frame early and then did not change at all, which is a motion
7
+ * vector on the wrong frame and none on the right one.
8
+ *
9
+ * Only the **first** change in a frame keeps the state before it: a second rewrite in the same
10
+ * frame must not replace "where it was last frame" with "where it was a moment ago".
11
+ */
12
+ export declare function frameOfChange(serial: number, inFrame: boolean): number;
13
+ export declare function keepsPrevious(lastChange: number, frame: number): boolean;
14
+ /** Slots `0 … n-1` pair with last frame's; a slot past last frame's count is new and has no past. */
15
+ export declare function pairedInstances(previousCount: number, count: number): number;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Which frame a change to a dynamic mesh or an instanced batch belongs to.
3
+ *
4
+ * **A consumer may change geometry in its simulation step, before `beginFrame`.** That change is
5
+ * what the *next* frame draws, so it is that frame's — counting it against the frame last begun
6
+ * would say the geometry changed a frame early and then did not change at all, which is a motion
7
+ * vector on the wrong frame and none on the right one.
8
+ *
9
+ * Only the **first** change in a frame keeps the state before it: a second rewrite in the same
10
+ * frame must not replace "where it was last frame" with "where it was a moment ago".
11
+ */
12
+ export function frameOfChange(serial, inFrame) {
13
+ return inFrame ? serial : serial + 1;
14
+ }
15
+ export function keepsPrevious(lastChange, frame) {
16
+ return lastChange !== frame;
17
+ }
18
+ /** Slots `0 … n-1` pair with last frame's; a slot past last frame's count is new and has no past. */
19
+ export function pairedInstances(previousCount, count) {
20
+ return Math.min(previousCount, count);
21
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Where output pixel (`outX`, `outY`) — its centre, in pixels — falls among the render texels
3
+ * jittered by (`jitterX`, `jitterY`) render texels: into `out`, the cell's first texel and the
4
+ * fraction across it, `[x, y, fx, fy]`.
5
+ */
6
+ export declare function lateDepthCell(outX: number, outY: number, renderWidth: number, renderHeight: number, outputWidth: number, outputHeight: number, jitterX: number, jitterY: number, out: Float64Array | Float32Array): void;
7
+ /**
8
+ * The depth to test against, from `taps` — a 4x4 block of render texels, row-major, starting one
9
+ * texel up and left of the cell's first — at (`fx`, `fy`) across the cell.
10
+ */
11
+ export declare function lateDepthAt(taps: ArrayLike<number>, fx: number, fy: number): number;
@@ -0,0 +1,70 @@
1
+ /**
2
+ * The depth a reconstructing frame's late draws are tested against at an output pixel, taken from
3
+ * the render's jittered depth. `shaders/recon/lateDepth.wgsl.ts` is the same arithmetic on the device.
4
+ *
5
+ * **Each surface taken to the pixel, and the nearest of them.** A late draw — a glow, a pane, a
6
+ * caption — is drawn unjittered at the output size, and it has to meet the depth of what it lies on
7
+ * where *it* is. Each of the four render texels about the pixel, placed where the jitter put it,
8
+ * carries its surface on to the pixel's unjittered centre along that surface's own slope; the
9
+ * nearest of the four so carried stands, and a quarter of its slope is given back toward the far
10
+ * side so that a draw lying exactly on the surface is not decided by rounding. On a plane all four
11
+ * arrive at the plane's own depth at the pixel: exact, and the same whatever the jitter was.
12
+ *
13
+ * **A texel's slope is the smaller of its two differences along each axis, and none where they
14
+ * disagree in sign** — the minmod limiter. Beside an edge one difference is the jump, so it is the
15
+ * other, the surface's own, that is taken; a sliver one texel wide disagrees both ways and keeps its
16
+ * own depth, the nearest of the four as before. So a translucent draw still never comes through an
17
+ * opaque edge the render covered by more than the render's own texel.
18
+ *
19
+ * **Why this replaced the nearest of the four.** On a wall seen aslant the nearest of four neighbours
20
+ * stands up to a texel's step in front of the wall at the pixel, so a glow lying a few centimetres
21
+ * proud of it was judged behind the wall; and which neighbour was nearest moved with the jitter, so
22
+ * the glow was drawn one frame and not the next. Measured on a street of lit facades: every strip of
23
+ * glow on every tower flickered frame by frame, 12,415 pixels of one tower between two frames.
24
+ *
25
+ * What it gives up: a surface curving within a texel is carried on as a plane, which a quarter-step
26
+ * tolerance covers. What would make it wrong is depth that is not affine on a plane — a depth written
27
+ * from the fragment stage — which nothing drawn before the late pass writes.
28
+ */
29
+ import { REVERSED_DEPTH } from '../depthConvention.js';
30
+ /** The share of a surface's slope given back toward the far side, for a draw lying on it. */
31
+ const TOLERANCE_SHARE = 0.25;
32
+ /** The smaller of two differences, or none where they disagree in sign. */
33
+ function minmod(a, b) {
34
+ if (a * b <= 0)
35
+ return 0;
36
+ return Math.abs(a) < Math.abs(b) ? a : b;
37
+ }
38
+ /**
39
+ * Where output pixel (`outX`, `outY`) — its centre, in pixels — falls among the render texels
40
+ * jittered by (`jitterX`, `jitterY`) render texels: into `out`, the cell's first texel and the
41
+ * fraction across it, `[x, y, fx, fy]`.
42
+ */
43
+ export function lateDepthCell(outX, outY, renderWidth, renderHeight, outputWidth, outputHeight, jitterX, jitterY, out) {
44
+ /* A texel stands at its index plus a half less the jitter, as the resolve places it. */
45
+ const x = (outX * renderWidth) / outputWidth - 0.5 + jitterX;
46
+ const y = (outY * renderHeight) / outputHeight - 0.5 + jitterY;
47
+ out[0] = Math.floor(x);
48
+ out[1] = Math.floor(y);
49
+ out[2] = x - Math.floor(x);
50
+ out[3] = y - Math.floor(y);
51
+ }
52
+ /**
53
+ * The depth to test against, from `taps` — a 4x4 block of render texels, row-major, starting one
54
+ * texel up and left of the cell's first — at (`fx`, `fy`) across the cell.
55
+ */
56
+ export function lateDepthAt(taps, fx, fy) {
57
+ const t = (x, y) => taps[(y + 1) * 4 + x + 1];
58
+ let depth = REVERSED_DEPTH ? -Infinity : Infinity;
59
+ for (let oy = 0; oy < 2; oy += 1) {
60
+ for (let ox = 0; ox < 2; ox += 1) {
61
+ const d = t(ox, oy);
62
+ const gx = minmod(t(ox + 1, oy) - d, d - t(ox - 1, oy));
63
+ const gy = minmod(t(ox, oy + 1) - d, d - t(ox, oy - 1));
64
+ const carried = d + gx * (fx - ox) + gy * (fy - oy);
65
+ const give = TOLERANCE_SHARE * Math.max(Math.abs(gx), Math.abs(gy));
66
+ depth = REVERSED_DEPTH ? Math.max(depth, carried - give) : Math.min(depth, carried + give);
67
+ }
68
+ }
69
+ return depth;
70
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Two decisions about one draw in a reconstructing frame, and why they are the same set.
3
+ *
4
+ * A blended draw goes **late** — after the reconstruction, at output resolution, unjittered — and a
5
+ * mover's motion is **tracked**, only for draws that land in the picture being reconstructed. A
6
+ * planar mirror and a probe bake are other pictures drawn through the same verbs, and the overlay
7
+ * after `endFrame` is past the picture altogether; routing any of them late, or counting a mirrored
8
+ * draw as a mover's second draw of the frame, would be wrong in the way that reads as a ghost.
9
+ *
10
+ * Plain booleans rather than a state object, so the per-draw call allocates nothing.
11
+ */
12
+ export declare function routesLate(reconstructing: boolean, mirror: boolean, probe: boolean, presented: boolean): boolean;
13
+ /** The same set as `routesLate`, named for the other reader. */
14
+ export declare function tracksMotion(reconstructing: boolean, mirror: boolean, probe: boolean, presented: boolean): boolean;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Two decisions about one draw in a reconstructing frame, and why they are the same set.
3
+ *
4
+ * A blended draw goes **late** — after the reconstruction, at output resolution, unjittered — and a
5
+ * mover's motion is **tracked**, only for draws that land in the picture being reconstructed. A
6
+ * planar mirror and a probe bake are other pictures drawn through the same verbs, and the overlay
7
+ * after `endFrame` is past the picture altogether; routing any of them late, or counting a mirrored
8
+ * draw as a mover's second draw of the frame, would be wrong in the way that reads as a ghost.
9
+ *
10
+ * Plain booleans rather than a state object, so the per-draw call allocates nothing.
11
+ */
12
+ export function routesLate(reconstructing, mirror, probe, presented) {
13
+ return reconstructing && !mirror && !probe && !presented;
14
+ }
15
+ /** The same set as `routesLate`, named for the other reader. */
16
+ export function tracksMotion(reconstructing, mirror, probe, presented) {
17
+ return routesLate(reconstructing, mirror, probe, presented);
18
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Which object a draw is, so a reconstruction can find where that object was last frame.
3
+ *
4
+ * **The engine cannot infer this and does not try.** `drawMesh` is immediate: a mesh drawn three
5
+ * times is three objects, and nothing in the call says which of last frame's three each one is. A
6
+ * consumer that makes one `Mover` per moving object and passes it with every draw of that object
7
+ * says exactly that, and the renderer keeps the rest — last frame's model and, for a skinned
8
+ * draw, last frame's palette.
9
+ *
10
+ * **Plain data, advanced by the renderer.** No renderer is needed to make one, so a consumer holds
11
+ * it beside the object it belongs to. Only a reconstructing WebGPU renderer reads or writes it; it
12
+ * costs nothing anywhere else. The fields past `kind` are the renderer's and a caller leaves them
13
+ * alone.
14
+ *
15
+ * **What would make this wrong** is a consumer whose objects are rebuilt every frame with no state
16
+ * of their own to hold a mover in; the identity then has to live in whatever *does* persist.
17
+ */
18
+ export declare const MOVER_KIND: 'drift.mover';
19
+ export interface Mover {
20
+ readonly kind: typeof MOVER_KIND;
21
+ /** The renderer that last drew it, from `claimRendererId`; -1 before its first draw. */
22
+ renderer: number;
23
+ /** That renderer's frame serial at the last draw. */
24
+ frame: number;
25
+ readonly model: Float32Array;
26
+ readonly previousModel: Float32Array;
27
+ /**
28
+ * This frame's palette, exactly `paletteLength` floats long once a skinned draw has set it.
29
+ * Swapped with the previous one each frame and reallocated only when the rig changes.
30
+ */
31
+ palette: Float32Array;
32
+ previousPalette: Float32Array;
33
+ paletteLength: number;
34
+ previousPaletteLength: number;
35
+ }
36
+ /** Nothing to reproject from: first draw, a missed frame, another renderer, or a changed rig. */
37
+ export declare const MOVER_NONE = 0;
38
+ /** Drawn on the frame before by this renderer: `previousModel` and `previousPalette` are real. */
39
+ export declare const MOVER_MOTION = 1;
40
+ /** Drawn already this frame. The second draw is a different object and the caller's error. */
41
+ export declare const MOVER_TWICE = 2;
42
+ export type MoverVerdict = typeof MOVER_NONE | typeof MOVER_MOTION | typeof MOVER_TWICE;
43
+ /** A number no other renderer in this page holds, so a mover can tell renderers apart. */
44
+ export declare function claimRendererId(): number;
45
+ export declare function createMover(): Mover;
46
+ export declare function isMover(value: unknown): value is Mover;
47
+ /**
48
+ * Advance a mover to this draw, and say whether last frame's state is usable.
49
+ *
50
+ * **A second draw in one frame changes nothing**, so the first draw's motion stands; the caller
51
+ * warns. Otherwise what the mover held becomes its previous and this draw becomes its current —
52
+ * the palettes by swapping two arrays, so a steady rig allocates nothing after its first frame.
53
+ *
54
+ * **A changed joint count is no motion**: skinning a vertex with a palette of a different rig is
55
+ * not an old pose of this one.
56
+ */
57
+ export declare function advanceMover(mover: Mover, renderer: number, frame: number, model: ArrayLike<number>, palette: Float32Array | null): MoverVerdict;
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Which object a draw is, so a reconstruction can find where that object was last frame.
3
+ *
4
+ * **The engine cannot infer this and does not try.** `drawMesh` is immediate: a mesh drawn three
5
+ * times is three objects, and nothing in the call says which of last frame's three each one is. A
6
+ * consumer that makes one `Mover` per moving object and passes it with every draw of that object
7
+ * says exactly that, and the renderer keeps the rest — last frame's model and, for a skinned
8
+ * draw, last frame's palette.
9
+ *
10
+ * **Plain data, advanced by the renderer.** No renderer is needed to make one, so a consumer holds
11
+ * it beside the object it belongs to. Only a reconstructing WebGPU renderer reads or writes it; it
12
+ * costs nothing anywhere else. The fields past `kind` are the renderer's and a caller leaves them
13
+ * alone.
14
+ *
15
+ * **What would make this wrong** is a consumer whose objects are rebuilt every frame with no state
16
+ * of their own to hold a mover in; the identity then has to live in whatever *does* persist.
17
+ */
18
+ export const MOVER_KIND = 'drift.mover';
19
+ /** Nothing to reproject from: first draw, a missed frame, another renderer, or a changed rig. */
20
+ export const MOVER_NONE = 0;
21
+ /** Drawn on the frame before by this renderer: `previousModel` and `previousPalette` are real. */
22
+ export const MOVER_MOTION = 1;
23
+ /** Drawn already this frame. The second draw is a different object and the caller's error. */
24
+ export const MOVER_TWICE = 2;
25
+ let nextRendererId = 1;
26
+ /** A number no other renderer in this page holds, so a mover can tell renderers apart. */
27
+ export function claimRendererId() {
28
+ const id = nextRendererId;
29
+ nextRendererId += 1;
30
+ return id;
31
+ }
32
+ export function createMover() {
33
+ return {
34
+ kind: MOVER_KIND,
35
+ renderer: -1,
36
+ frame: -2,
37
+ model: new Float32Array(16),
38
+ previousModel: new Float32Array(16),
39
+ palette: new Float32Array(0),
40
+ previousPalette: new Float32Array(0),
41
+ paletteLength: 0,
42
+ previousPaletteLength: 0,
43
+ };
44
+ }
45
+ export function isMover(value) {
46
+ return (typeof value === 'object' && value !== null && value.kind === MOVER_KIND);
47
+ }
48
+ /**
49
+ * Advance a mover to this draw, and say whether last frame's state is usable.
50
+ *
51
+ * **A second draw in one frame changes nothing**, so the first draw's motion stands; the caller
52
+ * warns. Otherwise what the mover held becomes its previous and this draw becomes its current —
53
+ * the palettes by swapping two arrays, so a steady rig allocates nothing after its first frame.
54
+ *
55
+ * **A changed joint count is no motion**: skinning a vertex with a palette of a different rig is
56
+ * not an old pose of this one.
57
+ */
58
+ export function advanceMover(mover, renderer, frame, model, palette) {
59
+ if (mover.renderer === renderer && mover.frame === frame)
60
+ return MOVER_TWICE;
61
+ const drawnLast = mover.renderer === renderer && mover.frame === frame - 1;
62
+ mover.previousModel.set(mover.model);
63
+ const spare = mover.previousPalette;
64
+ mover.previousPalette = mover.palette;
65
+ mover.palette = spare;
66
+ mover.previousPaletteLength = mover.paletteLength;
67
+ mover.model.set(model);
68
+ if (palette === null) {
69
+ mover.paletteLength = 0;
70
+ }
71
+ else {
72
+ /* Exactly the rig's length, because the array is uploaded as it stands; reallocated only when
73
+ the rig changes, which a steady character never does. */
74
+ if (mover.palette.length !== palette.length)
75
+ mover.palette = new Float32Array(palette.length);
76
+ mover.palette.set(palette);
77
+ mover.paletteLength = palette.length;
78
+ }
79
+ mover.renderer = renderer;
80
+ mover.frame = frame;
81
+ if (!drawnLast)
82
+ return MOVER_NONE;
83
+ if (mover.paletteLength !== mover.previousPaletteLength)
84
+ return MOVER_NONE;
85
+ return MOVER_MOTION;
86
+ }
@@ -54,6 +54,12 @@ export interface ResolveFrame {
54
54
  readonly inverseViewProj: ArrayLike<number>;
55
55
  /** Last frame's view-projection and its inverse, unjittered. */
56
56
  readonly previousViewProj: ArrayLike<number>;
57
+ /**
58
+ * Last frame's view-projection times this frame's inverse: where a texel's clip position was
59
+ * last frame. Derived from the two when absent; a caller holding its matrices at a lower precision
60
+ * than it multiplies at passes its own product, as the renderer does.
61
+ */
62
+ readonly reprojection?: ArrayLike<number>;
57
63
  readonly previousInverseViewProj: ArrayLike<number>;
58
64
  readonly eye: ArrayLike<number>;
59
65
  readonly previousEye: ArrayLike<number>;
@@ -62,6 +68,22 @@ export interface ResolveFrame {
62
68
  readonly previousJitter: ArrayLike<number>;
63
69
  readonly quality: ReconQuality;
64
70
  readonly disocclusion: DisocclusionParams;
71
+ /**
72
+ * Last frame's flicker records, output size, four floats a pixel — the spread, this period's
73
+ * running sum, the last period's mean, and how many periods running repeated, as `Flicker` holds
74
+ * them — or absent for the resolve without its anti-flicker.
75
+ */
76
+ readonly flicker?: ArrayLike<number> | null;
77
+ /**
78
+ * Last frame's depth swings, output size, one float a pixel: the largest miss, relative to the
79
+ * depth, of last frame's depth against the one this pixel's surface should have had, seen lately
80
+ * — held, and halving over a period. Carried with `flicker` and read only with it.
81
+ */
82
+ readonly depthSwing?: ArrayLike<number> | null;
83
+ /** Whether this frame samples the first phase of the jitter's period. */
84
+ readonly periodStart?: boolean;
85
+ /** The jitter's period: the reconstruction's own phase count, not the temporal resolve's. */
86
+ readonly flickerPhases?: number;
65
87
  }
66
88
  /**
67
89
  * How far a render sample's contribution reaches, in output pixels: a Gaussian's standard deviation.
@@ -78,13 +100,21 @@ export declare function reconstructionWeight(dx: number, dy: number): number;
78
100
  * pixel away.
79
101
  */
80
102
  export declare const CONFIDENT_WEIGHT = 1;
103
+ /**
104
+ * How many of its held depth swings a still pixel's depth test tolerates. The peak halves over a
105
+ * period, so the frame before the next once-a-period miss holds just over half of it: tolerating
106
+ * twice the peak passes that miss outright, and three leaves the same room again.
107
+ */
108
+ export declare const DEPTH_SWING_WIDTH = 3;
81
109
  /**
82
110
  * One output pixel: the history's next colour, before sharpening, and the weight it has gathered —
83
- * four values into `out`.
111
+ * four values into `out` — and, where the frame carries records, the pixel's next one into `record`.
84
112
  */
85
- export declare function resolvePixel(frame: ResolveFrame, ox: number, oy: number, out: Float32Array): void;
113
+ export declare function resolvePixel(frame: ResolveFrame, ox: number, oy: number, out: Float32Array, record?: Float32Array, swingOut?: Float32Array): void;
86
114
  /**
87
115
  * The whole frame: the next history into `history`, four floats a pixel, and the picture shown into
88
- * `shown`, three — the history sharpened against the four direct neighbours it has just been given.
116
+ * `shown`, three — the history sharpened against the four direct neighbours it has just been given —
117
+ * and, where the frame carries records, the next ones into `records`, four floats a pixel, and the
118
+ * next depth swings into `swings`, one.
89
119
  */
90
- export declare function resolveFrame(frame: ResolveFrame, history: Float32Array, shown: Float32Array): void;
120
+ export declare function resolveFrame(frame: ResolveFrame, history: Float32Array, shown: Float32Array, records?: Float32Array, swings?: Float32Array): void;