@zephyr3d/scene 0.9.25 → 0.9.27

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 (299) hide show
  1. package/dist/animation/animationset.js +92 -30
  2. package/dist/animation/animationset.js.map +1 -1
  3. package/dist/animation/hair/gpu_hair_simulation.js +1090 -0
  4. package/dist/animation/hair/gpu_hair_simulation.js.map +1 -0
  5. package/dist/animation/joint_dynamics/controller.js +7 -5
  6. package/dist/animation/joint_dynamics/controller.js.map +1 -1
  7. package/dist/animation/joint_dynamics/convex_collider.js +320 -0
  8. package/dist/animation/joint_dynamics/convex_collider.js.map +1 -0
  9. package/dist/animation/joint_dynamics/joint_dynamics_system.js +81 -5
  10. package/dist/animation/joint_dynamics/joint_dynamics_system.js.map +1 -1
  11. package/dist/animation/morphtrack.js +3 -4
  12. package/dist/animation/morphtrack.js.map +1 -1
  13. package/dist/animation/skeleton.js +79 -25
  14. package/dist/animation/skeleton.js.map +1 -1
  15. package/dist/animation/spring/multi_chain_spring_system.js +577 -179
  16. package/dist/animation/spring/multi_chain_spring_system.js.map +1 -1
  17. package/dist/animation/spring/spring_collider.js +4 -3
  18. package/dist/animation/spring/spring_collider.js.map +1 -1
  19. package/dist/animation/spring/spring_node_pose_tracker.js +40 -0
  20. package/dist/animation/spring/spring_node_pose_tracker.js.map +1 -0
  21. package/dist/animation/spring/spring_particle.js +2 -0
  22. package/dist/animation/spring/spring_particle.js.map +1 -1
  23. package/dist/animation/spring/spring_system.js +11 -3
  24. package/dist/animation/spring/spring_system.js.map +1 -1
  25. package/dist/animation/spring_modifier.js +10 -0
  26. package/dist/animation/spring_modifier.js.map +1 -1
  27. package/dist/app/engine.js +53 -43
  28. package/dist/app/engine.js.map +1 -1
  29. package/dist/app/scriptingsystem.js +119 -6
  30. package/dist/app/scriptingsystem.js.map +1 -1
  31. package/dist/app/scriptregistry.js +3 -2
  32. package/dist/app/scriptregistry.js.map +1 -1
  33. package/dist/asset/assetmanager.js +284 -67
  34. package/dist/asset/assetmanager.js.map +1 -1
  35. package/dist/asset/loaders/zhair/zhair_format.js +288 -0
  36. package/dist/asset/loaders/zhair/zhair_format.js.map +1 -0
  37. package/dist/asset/loaders/zhair/zhair_loader.js +221 -0
  38. package/dist/asset/loaders/zhair/zhair_loader.js.map +1 -0
  39. package/dist/asset/model.js +184 -69
  40. package/dist/asset/model.js.map +1 -1
  41. package/dist/camera/camera.js +268 -44
  42. package/dist/camera/camera.js.map +1 -1
  43. package/dist/camera/perspectivecamera.js +3 -1
  44. package/dist/camera/perspectivecamera.js.map +1 -1
  45. package/dist/index.d.ts +9044 -5139
  46. package/dist/index.js +17 -6
  47. package/dist/index.js.map +1 -1
  48. package/dist/material/eye.js +932 -0
  49. package/dist/material/eye.js.map +1 -0
  50. package/dist/material/hair.js +917 -0
  51. package/dist/material/hair.js.map +1 -0
  52. package/dist/material/hairstrand.js +842 -0
  53. package/dist/material/hairstrand.js.map +1 -0
  54. package/dist/material/hairstrand_data.js +162 -0
  55. package/dist/material/hairstrand_data.js.map +1 -0
  56. package/dist/material/lambert.js +5 -2
  57. package/dist/material/lambert.js.map +1 -1
  58. package/dist/material/material.js +48 -10
  59. package/dist/material/material.js.map +1 -1
  60. package/dist/material/meshmaterial.js +120 -19
  61. package/dist/material/meshmaterial.js.map +1 -1
  62. package/dist/material/mixins/albedocolor.js +1 -1
  63. package/dist/material/mixins/albedocolor.js.map +1 -1
  64. package/dist/material/mixins/lightmodel/blinnphong.js +5 -3
  65. package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -1
  66. package/dist/material/mixins/lightmodel/lambert.js +5 -4
  67. package/dist/material/mixins/lightmodel/lambert.js.map +1 -1
  68. package/dist/material/mixins/lightmodel/pbrblueprintmixin.js +3 -3
  69. package/dist/material/mixins/lightmodel/pbrblueprintmixin.js.map +1 -1
  70. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +5 -5
  71. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
  72. package/dist/material/mixins/lightmodel/pbrspecularglossness.js +3 -3
  73. package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
  74. package/dist/material/mixins/lit.js +106 -19
  75. package/dist/material/mixins/lit.js.map +1 -1
  76. package/dist/material/mixins/pbr/common.js +4 -4
  77. package/dist/material/mixins/pbr/common.js.map +1 -1
  78. package/dist/material/mixins/texture.js +48 -11
  79. package/dist/material/mixins/texture.js.map +1 -1
  80. package/dist/material/mtoon.js +6 -5
  81. package/dist/material/mtoon.js.map +1 -1
  82. package/dist/material/pbrblueprint.js +146 -28
  83. package/dist/material/pbrblueprint.js.map +1 -1
  84. package/dist/material/pbrblueprint_instance.js +501 -0
  85. package/dist/material/pbrblueprint_instance.js.map +1 -0
  86. package/dist/material/pbrmr.js +15 -16
  87. package/dist/material/pbrmr.js.map +1 -1
  88. package/dist/material/shader/helper.js +734 -23
  89. package/dist/material/shader/helper.js.map +1 -1
  90. package/dist/material/shader/terrain_blend.js +55 -0
  91. package/dist/material/shader/terrain_blend.js.map +1 -0
  92. package/dist/material/skin.js +192 -32
  93. package/dist/material/skin.js.map +1 -1
  94. package/dist/material/spriteblueprint.js +16 -1
  95. package/dist/material/spriteblueprint.js.map +1 -1
  96. package/dist/material/subsurfaceprofile.js +86 -23
  97. package/dist/material/subsurfaceprofile.js.map +1 -1
  98. package/dist/material/water.js +2059 -72
  99. package/dist/material/water.js.map +1 -1
  100. package/dist/posteffect/bloom.js +167 -7
  101. package/dist/posteffect/bloom.js.map +1 -1
  102. package/dist/posteffect/coloradjust.js +2 -1
  103. package/dist/posteffect/coloradjust.js.map +1 -1
  104. package/dist/posteffect/compositor.js.map +1 -1
  105. package/dist/posteffect/fxaa.js +2 -1
  106. package/dist/posteffect/fxaa.js.map +1 -1
  107. package/dist/posteffect/grayscale.js +3 -1
  108. package/dist/posteffect/grayscale.js.map +1 -1
  109. package/dist/posteffect/motionblur.js +664 -56
  110. package/dist/posteffect/motionblur.js.map +1 -1
  111. package/dist/posteffect/posteffect.js +12 -1
  112. package/dist/posteffect/posteffect.js.map +1 -1
  113. package/dist/posteffect/sao.js +46 -44
  114. package/dist/posteffect/sao.js.map +1 -1
  115. package/dist/posteffect/skinsss.js +368 -69
  116. package/dist/posteffect/skinsss.js.map +1 -1
  117. package/dist/posteffect/ssgi.js +16 -9
  118. package/dist/posteffect/ssgi.js.map +1 -1
  119. package/dist/posteffect/ssr.js +3 -0
  120. package/dist/posteffect/ssr.js.map +1 -1
  121. package/dist/posteffect/sss.js +121 -36
  122. package/dist/posteffect/sss.js.map +1 -1
  123. package/dist/posteffect/taa.js.map +1 -1
  124. package/dist/posteffect/tonemap.js +44 -1
  125. package/dist/posteffect/tonemap.js.map +1 -1
  126. package/dist/render/abuffer_oit.js +8 -2
  127. package/dist/render/abuffer_oit.js.map +1 -1
  128. package/dist/render/clipmap.js +156 -5
  129. package/dist/render/clipmap.js.map +1 -1
  130. package/dist/render/cull_visitor.js +20 -0
  131. package/dist/render/cull_visitor.js.map +1 -1
  132. package/dist/render/depthpass.js +36 -2
  133. package/dist/render/depthpass.js.map +1 -1
  134. package/dist/render/drawable_mixin.js +26 -1
  135. package/dist/render/drawable_mixin.js.map +1 -1
  136. package/dist/render/dualdepthpeeling_oit.js +3 -2
  137. package/dist/render/dualdepthpeeling_oit.js.map +1 -1
  138. package/dist/render/envlight.js +1 -1
  139. package/dist/render/envlight.js.map +1 -1
  140. package/dist/render/fbm_wavegenerator.js +6 -3
  141. package/dist/render/fbm_wavegenerator.js.map +1 -1
  142. package/dist/render/fft_wavegenerator.js +57 -15
  143. package/dist/render/fft_wavegenerator.js.map +1 -1
  144. package/dist/render/gerstner_wavegenerator.js +130 -20
  145. package/dist/render/gerstner_wavegenerator.js.map +1 -1
  146. package/dist/render/globalbindgroup_allocator.js +3 -0
  147. package/dist/render/globalbindgroup_allocator.js.map +1 -1
  148. package/dist/render/hzb.js +80 -22
  149. package/dist/render/hzb.js.map +1 -1
  150. package/dist/render/lightpass.js +6 -3
  151. package/dist/render/lightpass.js.map +1 -1
  152. package/dist/render/oit.js +29 -0
  153. package/dist/render/oit.js.map +1 -0
  154. package/dist/render/render_queue.js +39 -0
  155. package/dist/render/render_queue.js.map +1 -1
  156. package/dist/render/renderer.js +4 -0
  157. package/dist/render/renderer.js.map +1 -1
  158. package/dist/render/rendergraph/blackboard.js +1 -0
  159. package/dist/render/rendergraph/blackboard.js.map +1 -1
  160. package/dist/render/rendergraph/device_pool_allocator.js.map +1 -1
  161. package/dist/render/rendergraph/executor.js +2 -0
  162. package/dist/render/rendergraph/executor.js.map +1 -1
  163. package/dist/render/rendergraph/forward_plus_builder.js +379 -10
  164. package/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
  165. package/dist/render/rendergraph/frame_resource_requirements.js +1 -0
  166. package/dist/render/rendergraph/frame_resource_requirements.js.map +1 -1
  167. package/dist/render/rendergraph/history_resources.js +8 -1
  168. package/dist/render/rendergraph/history_resources.js.map +1 -1
  169. package/dist/render/rendergraph/rendergraph.js.map +1 -1
  170. package/dist/render/rendergraph/texture_affinity_cache.js +1 -1
  171. package/dist/render/rendergraph/texture_affinity_cache.js.map +1 -1
  172. package/dist/render/rendergraph/types.js.map +1 -1
  173. package/dist/render/shadow_mask_pass.js +73 -8
  174. package/dist/render/shadow_mask_pass.js.map +1 -1
  175. package/dist/render/sky.js +166 -126
  176. package/dist/render/sky.js.map +1 -1
  177. package/dist/render/underwater.js +624 -0
  178. package/dist/render/underwater.js.map +1 -0
  179. package/dist/render/water_caustics.js +1380 -0
  180. package/dist/render/water_caustics.js.map +1 -0
  181. package/dist/render/weightedblended_oit.js +3 -2
  182. package/dist/render/weightedblended_oit.js.map +1 -1
  183. package/dist/scene/basesprite.js +8 -0
  184. package/dist/scene/basesprite.js.map +1 -1
  185. package/dist/scene/batchgroup.js +3 -0
  186. package/dist/scene/batchgroup.js.map +1 -1
  187. package/dist/scene/environment.js +4 -1
  188. package/dist/scene/environment.js.map +1 -1
  189. package/dist/scene/hair.js +963 -0
  190. package/dist/scene/hair.js.map +1 -0
  191. package/dist/scene/light.js +5 -1
  192. package/dist/scene/light.js.map +1 -1
  193. package/dist/scene/mesh.js +481 -47
  194. package/dist/scene/mesh.js.map +1 -1
  195. package/dist/scene/meshdrawable.js +6 -0
  196. package/dist/scene/meshdrawable.js.map +1 -1
  197. package/dist/scene/msdftext.js +3 -0
  198. package/dist/scene/msdftext.js.map +1 -1
  199. package/dist/scene/msdftextsprite.js +3 -0
  200. package/dist/scene/msdftextsprite.js.map +1 -1
  201. package/dist/scene/particlesys.js +6 -0
  202. package/dist/scene/particlesys.js.map +1 -1
  203. package/dist/scene/scene.js +3 -0
  204. package/dist/scene/scene.js.map +1 -1
  205. package/dist/scene/scene_node.js +6 -1
  206. package/dist/scene/scene_node.js.map +1 -1
  207. package/dist/scene/terrain-cm/grass.js +3 -0
  208. package/dist/scene/terrain-cm/grass.js.map +1 -1
  209. package/dist/scene/terrain-cm/grassmaterial.js +3 -0
  210. package/dist/scene/terrain-cm/grassmaterial.js.map +1 -1
  211. package/dist/scene/terrain-cm/terrain-cm.js +6 -0
  212. package/dist/scene/terrain-cm/terrain-cm.js.map +1 -1
  213. package/dist/scene/terrain-cm/texture_cache.js +309 -0
  214. package/dist/scene/terrain-cm/texture_cache.js.map +1 -0
  215. package/dist/scene/water.js +546 -4
  216. package/dist/scene/water.js.map +1 -1
  217. package/dist/shaders/atmosphere.js.map +1 -1
  218. package/dist/shaders/diffusion.js +54 -0
  219. package/dist/shaders/diffusion.js.map +1 -0
  220. package/dist/shaders/shadow.js +33 -21
  221. package/dist/shaders/shadow.js.map +1 -1
  222. package/dist/shaders/temporal.js +71 -33
  223. package/dist/shaders/temporal.js.map +1 -1
  224. package/dist/shaders/water.js +22 -19
  225. package/dist/shaders/water.js.map +1 -1
  226. package/dist/shaders/water_medium.js +56 -0
  227. package/dist/shaders/water_medium.js.map +1 -0
  228. package/dist/shadow/dom.js +546 -0
  229. package/dist/shadow/dom.js.map +1 -0
  230. package/dist/shadow/pcf_opt.js +3 -5
  231. package/dist/shadow/pcf_opt.js.map +1 -1
  232. package/dist/shadow/pcf_pd.js +1 -1
  233. package/dist/shadow/pcf_pd.js.map +1 -1
  234. package/dist/shadow/receiver_bias.js +41 -0
  235. package/dist/shadow/receiver_bias.js.map +1 -0
  236. package/dist/shadow/shader.js +20 -60
  237. package/dist/shadow/shader.js.map +1 -1
  238. package/dist/shadow/shadow_impl.js +89 -0
  239. package/dist/shadow/shadow_impl.js.map +1 -1
  240. package/dist/shadow/shadow_region.js +1 -1
  241. package/dist/shadow/shadow_region.js.map +1 -1
  242. package/dist/shadow/shadowmapper.js +150 -37
  243. package/dist/shadow/shadowmapper.js.map +1 -1
  244. package/dist/shapes/shape.js +11 -2
  245. package/dist/shapes/shape.js.map +1 -1
  246. package/dist/shapes/sphere.js +50 -9
  247. package/dist/shapes/sphere.js.map +1 -1
  248. package/dist/utility/blueprint/common/constants.js +112 -2
  249. package/dist/utility/blueprint/common/constants.js.map +1 -1
  250. package/dist/utility/blueprint/material/func.js +142 -49
  251. package/dist/utility/blueprint/material/func.js.map +1 -1
  252. package/dist/utility/blueprint/material/ir.js +490 -25
  253. package/dist/utility/blueprint/material/ir.js.map +1 -1
  254. package/dist/utility/blueprint/material/texture.js +898 -4
  255. package/dist/utility/blueprint/material/texture.js.map +1 -1
  256. package/dist/utility/serialization/manager.js +434 -101
  257. package/dist/utility/serialization/manager.js.map +1 -1
  258. package/dist/utility/serialization/scene/animation.js +401 -5
  259. package/dist/utility/serialization/scene/animation.js.map +1 -1
  260. package/dist/utility/serialization/scene/batch.js +4 -0
  261. package/dist/utility/serialization/scene/batch.js.map +1 -1
  262. package/dist/utility/serialization/scene/camera.js +186 -26
  263. package/dist/utility/serialization/scene/camera.js.map +1 -1
  264. package/dist/utility/serialization/scene/common.js +26 -5
  265. package/dist/utility/serialization/scene/common.js.map +1 -1
  266. package/dist/utility/serialization/scene/hair.js +1141 -0
  267. package/dist/utility/serialization/scene/hair.js.map +1 -0
  268. package/dist/utility/serialization/scene/light.js +84 -4
  269. package/dist/utility/serialization/scene/light.js.map +1 -1
  270. package/dist/utility/serialization/scene/material.js +1867 -166
  271. package/dist/utility/serialization/scene/material.js.map +1 -1
  272. package/dist/utility/serialization/scene/mesh.js +231 -14
  273. package/dist/utility/serialization/scene/mesh.js.map +1 -1
  274. package/dist/utility/serialization/scene/node.js +141 -7
  275. package/dist/utility/serialization/scene/node.js.map +1 -1
  276. package/dist/utility/serialization/scene/particle.js +4 -0
  277. package/dist/utility/serialization/scene/particle.js.map +1 -1
  278. package/dist/utility/serialization/scene/primitive.js +18 -0
  279. package/dist/utility/serialization/scene/primitive.js.map +1 -1
  280. package/dist/utility/serialization/scene/sprite.js +4 -0
  281. package/dist/utility/serialization/scene/sprite.js.map +1 -1
  282. package/dist/utility/serialization/scene/terrain.js +4 -0
  283. package/dist/utility/serialization/scene/terrain.js.map +1 -1
  284. package/dist/utility/serialization/scene/text.js +4 -0
  285. package/dist/utility/serialization/scene/text.js.map +1 -1
  286. package/dist/utility/serialization/scene/water.js +1105 -21
  287. package/dist/utility/serialization/scene/water.js.map +1 -1
  288. package/dist/utility/serialization/types.js.map +1 -1
  289. package/dist/utility/shprojector.js +9 -8
  290. package/dist/utility/shprojector.js.map +1 -1
  291. package/dist/values.js +49 -2
  292. package/dist/values.js.map +1 -1
  293. package/package.json +3 -3
  294. package/dist/render/rendergraph/frame_graph_context.js +0 -41
  295. package/dist/render/rendergraph/frame_graph_context.js.map +0 -1
  296. package/dist/shaders/ssgi.js +0 -63
  297. package/dist/shaders/ssgi.js.map +0 -1
  298. package/dist/shaders/ssgi_reprojection.js +0 -118
  299. package/dist/shaders/ssgi_reprojection.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"underwater.js","sources":["../../src/render/underwater.ts"],"sourcesContent":["import type { Nullable } from '@zephyr3d/base';\r\nimport { DEPTH_FARTHEST, Vector3, Vector4 } from '@zephyr3d/base';\r\nimport type {\r\n AbstractDevice,\r\n BindGroup,\r\n FrameBuffer,\r\n GPUProgram,\r\n RenderStateSet,\r\n Texture2D\r\n} from '@zephyr3d/device';\r\nimport type { Camera } from '../camera/camera';\r\nimport type { WaterMaterial } from '../material/water';\r\nimport { ShaderHelper } from '../material/shader/helper';\r\nimport type { PunctualLight } from '../scene/light';\r\nimport type { ShadowMapParams } from '../shadow/shadowmapper';\r\nimport type { Water } from '../scene/water';\r\nimport { waterScatterPhase } from '../shaders/water_medium';\r\nimport { LIGHT_TYPE_DIRECTIONAL } from '../values';\r\nimport { interleavedGradientNoise } from '../shaders/noise';\r\nimport { SkyRenderer } from './sky';\r\nimport { fetchSampler } from '../utility/misc';\r\nimport { drawFullscreenQuad } from './fullscreenquad';\r\nimport type { DrawContext } from './drawable';\r\n\r\n/**\r\n * The body of water a camera is currently inside, and how deep.\r\n * @public\r\n */\r\nexport interface UnderwaterState {\r\n /** The water node the camera is submerged in. */\r\n water: Water;\r\n /** Its material, which owns the medium coefficients and the underwater settings. */\r\n material: WaterMaterial;\r\n /** World Y of that water's rest plane. */\r\n surfaceY: number;\r\n /** How far the eye is below the rest plane, in meters. Always positive. */\r\n eyeDepth: number;\r\n}\r\n\r\n/**\r\n * Which waters each camera is currently inside, and the rest plane of each.\r\n *\r\n * Written by {@link Water.updatePerCamera}, which runs for every water every\r\n * frame whether or not the surface survived culling. Reading the render queue\r\n * instead would lose the state the moment the surface left the frustum - which\r\n * is exactly what happens to a camera deep underwater looking down.\r\n *\r\n * Keyed on the camera so multiple views stay independent. The inner map holds a\r\n * strong reference to the water, which a disposed node would keep alive; entries\r\n * are pruned on read rather than on dispose, since a disposed water simply stops\r\n * updating its own entry.\r\n *\r\n * @internal\r\n */\r\nconst _submergence = new WeakMap<Camera, Map<Water, number>>();\r\n\r\n/**\r\n * Record whether `camera` is inside `water` this frame.\r\n *\r\n * @param camera - Camera being updated.\r\n * @param water - Water reporting its own state.\r\n * @param submerged - Whether the camera is inside this body.\r\n * @param surfaceY - World Y of the water's rest plane.\r\n * @internal\r\n */\r\nexport function setWaterSubmergence(\r\n camera: Camera,\r\n water: Water,\r\n submerged: boolean,\r\n surfaceY: number\r\n): void {\r\n let bodies = _submergence.get(camera);\r\n if (submerged) {\r\n if (!bodies) {\r\n bodies = new Map();\r\n _submergence.set(camera, bodies);\r\n }\r\n bodies.set(water, surfaceY);\r\n } else if (bodies) {\r\n bodies.delete(water);\r\n }\r\n}\r\n\r\n/**\r\n * The water the camera is currently inside, or null when it is above all of them.\r\n *\r\n * Several can qualify - a pool inside a lake, water on terraces - and the one\r\n * that matters is the highest of them: that is the last surface the eye crossed\r\n * on its way down, so it owns the column the eye is looking through.\r\n *\r\n * @param ctx - Frame draw context.\r\n * @returns The submerged state, or null.\r\n * @internal\r\n */\r\nexport function selectUnderwaterSource(ctx: DrawContext): Nullable<UnderwaterState> {\r\n const bodies = _submergence.get(ctx.camera);\r\n if (!bodies || bodies.size === 0) {\r\n return null;\r\n }\r\n let best: Nullable<Water> = null;\r\n let bestY = 0;\r\n for (const [water, surfaceY] of bodies) {\r\n // A node disposed since its last update never clears its own entry.\r\n if (water.disposed) {\r\n bodies.delete(water);\r\n continue;\r\n }\r\n if (!best || surfaceY > bestY) {\r\n best = water;\r\n bestY = surfaceY;\r\n }\r\n }\r\n const material = best?.material;\r\n if (!best || !material || !material.underwaterEnabled) {\r\n return null;\r\n }\r\n return {\r\n water: best,\r\n material,\r\n surfaceY: bestY,\r\n eyeDepth: Math.max(0, bestY - ctx.camera.getWorldPosition().y)\r\n };\r\n}\r\n\r\n/**\r\n * Optical depth at which a channel is taken to have died completely.\r\n *\r\n * exp(-30) is about 1e-13, which is zero in any format the scene color uses. The\r\n * path length fed to the medium is capped at whatever distance reaches this on\r\n * the least attenuated channel, so a huge far plane cannot push the exponent\r\n * anywhere unpleasant.\r\n * @internal\r\n */\r\nconst OPTICAL_DEPTH_CAP = 30;\r\n\r\n/**\r\n * Global name of the shadow map the receiver helpers sample.\r\n *\r\n * Fixed by `ShaderHelper`, which declares it under this name for materials and\r\n * reads it from the implementation's `computeShadow`; a standalone pass sampling\r\n * shadows has to use the same one.\r\n * @internal\r\n */\r\nconst SHADOW_MAP_UNIFORM = 'Z_UniformShadowMap';\r\n\r\n/**\r\n * Composites the water body a submerged camera is looking through.\r\n *\r\n * Two draws over the opaque scene, both in place on the scene color target:\r\n *\r\n * 1. multiply by the medium's transmittance, then\r\n * 2. add what the medium scatters back towards the eye.\r\n *\r\n * Two rather than one because the transmittance is per channel - red dies within\r\n * a metre or two of clear water while blue carries tens of metres, which is the\r\n * entire reason water reads as water - and a single blend equation only has a\r\n * scalar `src-alpha` to attenuate the destination with. Splitting them lets the\r\n * first draw use `src-color` as the destination factor and keep the colour.\r\n *\r\n * The pass runs after the sky, and treats a sky pixel as a ray that never left\r\n * the water: its path length is the cap above, so its transmittance is zero and\r\n * the horizon is pure medium. That is what replaces the sky underwater, rather\r\n * than any separate handling of it.\r\n *\r\n * @internal\r\n */\r\nexport class UnderwaterRenderer {\r\n /** Multiplies the scene by the medium transmittance. */\r\n private _extinctionProgram: Nullable<GPUProgram>;\r\n private _extinctionBindGroup: Nullable<BindGroup>;\r\n private _extinctionStates: Nullable<RenderStateSet>;\r\n /**\r\n * Adds what the medium scatters towards the eye. Two variants: ambient alone,\r\n * and ambient plus a march for the sun shafts. Keyed on the step count as well\r\n * as on whether the shafts are on, because the loop is unrolled at that count.\r\n */\r\n private readonly _inscatterPrograms: Map<string, { program: GPUProgram; bindGroup: BindGroup }>;\r\n private _inscatterStates: Nullable<RenderStateSet>;\r\n /** (ambientScale, surfaceY, maxPathLength, godRayIntensity) */\r\n private readonly _params: Vector4;\r\n /** (scatterAnisotropy, unused, unused, unused) */\r\n private readonly _phaseParams: Vector4;\r\n private readonly _extinction: Vector3;\r\n private readonly _albedo: Vector3;\r\n private readonly _sunDir: Vector3;\r\n private readonly _sunColor: Vector3;\r\n /** Shadow receiver uniforms, only touched while the shafts are shadowed. */\r\n private readonly _cameraPosition: Vector4;\r\n private readonly _cameraParams: Vector4;\r\n private readonly _implParams: Vector4;\r\n private readonly _cameraForward: Vector4;\r\n /**\r\n * Scratch for the cascade matrices. Copied rather than passed through, because\r\n * the uniform setter wants an array it owns the buffer type of; reused so the\r\n * copy does not allocate every frame.\r\n */\r\n private _shadowMatrices: Nullable<Float32Array<ArrayBuffer>>;\r\n constructor() {\r\n this._extinctionProgram = null;\r\n this._extinctionBindGroup = null;\r\n this._extinctionStates = null;\r\n this._inscatterPrograms = new Map();\r\n this._inscatterStates = null;\r\n this._params = new Vector4();\r\n this._phaseParams = new Vector4();\r\n this._extinction = new Vector3();\r\n this._albedo = new Vector3();\r\n this._sunDir = new Vector3();\r\n this._sunColor = new Vector3();\r\n this._cameraPosition = new Vector4();\r\n this._cameraParams = new Vector4();\r\n this._implParams = new Vector4();\r\n this._cameraForward = new Vector4();\r\n this._shadowMatrices = null;\r\n }\r\n /**\r\n * Composite the medium over the opaque scene.\r\n *\r\n * @param ctx - Frame draw context.\r\n * @param state - The water the camera is inside.\r\n * @param colorFramebuffer - Color-only target holding the opaque scene and the\r\n * sky. The depth attachment is deliberately absent: this pass samples the\r\n * scene depth, which it could not do while that texture is still attached.\r\n * @param depthTexture - Scene depth attachment, sampled for the path length.\r\n */\r\n render(\r\n ctx: DrawContext,\r\n state: UnderwaterState,\r\n colorFramebuffer: FrameBuffer,\r\n depthTexture: Texture2D\r\n ): void {\r\n const device = ctx.device;\r\n const material = state.material;\r\n // Shafts need the caustic map as the surface's transmittance, and the sun\r\n // that map was built for. Without one the march has nothing to modulate and\r\n // would paint a uniform cone, so it degrades to the ambient term alone.\r\n const sun = ctx.waterCausticLight;\r\n const godRays =\r\n material.underwaterGodRays && !!ctx.waterCaustics && !!sun && material.underwaterGodRayIntensity > 0;\r\n const steps = godRays ? material.underwaterGodRaySteps : 0;\r\n // The caustic light is required to cast shadows for the map to exist at all,\r\n // so its params are normally there; the lookup stays defensive because this\r\n // runs a module later and nothing re-checks in between.\r\n const shadowMapParams =\r\n godRays && material.underwaterGodRayShadow ? (ctx.shadowMapInfo?.get(sun!) ?? null) : null;\r\n const shadow = shadowMapParams?.shadowMap ? shadowMapParams : null;\r\n const { extinctionPass, inscatterPass } = this._prepare(device, steps, shadow);\r\n const extinction = material.extinction;\r\n this._extinction.set(extinction);\r\n this._albedo.set(material.scatterAlbedo);\r\n // Far enough that the least attenuated channel has died. A channel with no\r\n // extinction at all has no such distance, and the far plane stands in.\r\n const minExtinction = Math.min(extinction.x, extinction.y, extinction.z);\r\n const far = ctx.camera.getFarPlane();\r\n this._params.setXYZW(\r\n // The distant-sky LUT is baked exposure-independently, as everywhere else\r\n // it is read from.\r\n SkyRenderer.getBakeToPreExposedScale(ctx) * material.underwaterAmbientIntensity,\r\n state.surfaceY,\r\n minExtinction > 0 ? Math.min(far, OPTICAL_DEPTH_CAP / minExtinction) : far,\r\n godRays ? material.underwaterGodRayIntensity : 0\r\n );\r\n this._phaseParams.setXYZW(material.scatterAnisotropy, 0, 0, 0);\r\n if (sun) {\r\n // Direction the light travels, matching what calculateWaterCaustic\r\n // compares its own against.\r\n const dir = sun.directionAndCutoff;\r\n this._sunDir.setXYZ(dir.x, dir.y, dir.z);\r\n const color = sun.diffuseAndIntensity;\r\n // Pre-exposed, like every other radiance this pass adds to the scene.\r\n const intensity = color.w * ShaderHelper.getPreExposure(ctx);\r\n this._sunColor.setXYZ(color.x * intensity, color.y * intensity, color.z * intensity);\r\n } else {\r\n this._sunDir.setXYZ(0, -1, 0);\r\n this._sunColor.setXYZ(0, 0, 0);\r\n }\r\n // Same rule the post effects use (AbstractPostEffect.needFlip): WebGPU's\r\n // render target has the opposite vertical convention to the screen.\r\n const flip = device.type === 'webgpu' && colorFramebuffer ? 1 : 0;\r\n const nearestSampler = fetchSampler('clamp_nearest_nomip');\r\n const skyLut = ctx.scene.env.sky.getSkyDistantLightLUT(ctx);\r\n const invProjView = ctx.camera.invViewProjectionMatrix;\r\n const cameraPos = ctx.camera.getWorldPosition();\r\n const passes = [extinctionPass, inscatterPass];\r\n\r\n device.pushDeviceStates();\r\n try {\r\n device.setFramebuffer(colorFramebuffer);\r\n device.setViewport(null);\r\n device.setScissor(null);\r\n for (const pass of passes) {\r\n const bindGroup = pass.bindGroup;\r\n bindGroup.setTexture('depthTex', depthTexture, nearestSampler);\r\n bindGroup.setTexture('skyLut', skyLut, nearestSampler);\r\n bindGroup.setValue('invProjViewMatrix', invProjView);\r\n bindGroup.setValue('cameraPosition', cameraPos);\r\n bindGroup.setValue('mediumExtinction', this._extinction);\r\n bindGroup.setValue('mediumAlbedo', this._albedo);\r\n bindGroup.setValue('params', this._params);\r\n bindGroup.setValue('flip', flip);\r\n if (pass === inscatterPass && godRays) {\r\n bindGroup.setValue('sunDirection', this._sunDir);\r\n bindGroup.setValue('sunColor', this._sunColor);\r\n bindGroup.setValue('phaseParams', this._phaseParams);\r\n // Same uniforms the lit materials bind, so the shafts and the caustics\r\n // on the sea bed are reading one map through one projection.\r\n ShaderHelper.setWaterCausticUniforms(bindGroup, ctx);\r\n if (shadow) {\r\n this._setShadowUniforms(bindGroup, ctx, sun!, shadow);\r\n }\r\n }\r\n device.setProgram(pass.program);\r\n device.setBindGroup(0, bindGroup);\r\n drawFullscreenQuad(pass.states);\r\n }\r\n } finally {\r\n device.popDeviceStates();\r\n }\r\n }\r\n /**\r\n * Upload the shadow receiver uniforms the march samples.\r\n *\r\n * The names and the struct layouts are dictated by the helpers that read them\r\n * (`ShaderHelper.calculateShadowSpaceVertex`, the shadow implementation's\r\n * `computeShadow`), which expect the material light pass's globals. This is\r\n * the same arrangement the shadow mask pass makes for the same reason - see\r\n * `ShadowMaskRenderer.setUniforms`.\r\n * @internal\r\n */\r\n private _setShadowUniforms(\r\n bindGroup: BindGroup,\r\n ctx: DrawContext,\r\n light: PunctualLight,\r\n shadowMapParams: ShadowMapParams\r\n ): void {\r\n const camera = ctx.camera;\r\n const near = camera.getNearPlane();\r\n const far = camera.getFarPlane();\r\n const cameraPos = camera.getWorldPosition();\r\n this._cameraPosition.setXYZW(cameraPos.x, cameraPos.y, cameraPos.z, 0);\r\n this._cameraParams.setXYZW(near, far, 1, 1);\r\n bindGroup.setValue('camera', {\r\n position: this._cameraPosition,\r\n params: this._cameraParams,\r\n shadowDebugCascades: camera.shadowDebugCascades ? 1 : 0,\r\n framestamp: ctx.device.frameInfo.frameCounter\r\n });\r\n shadowMapParams.impl!.getParams(this._implParams);\r\n const matrices = shadowMapParams.shadowMatrices;\r\n if (!this._shadowMatrices || this._shadowMatrices.length !== matrices.length) {\r\n this._shadowMatrices = new Float32Array(matrices.length);\r\n }\r\n this._shadowMatrices.set(matrices);\r\n bindGroup.setValue('light', {\r\n sunDir: ctx.sunLight ? ctx.sunLight.directionAndCutoff.xyz().scaleBy(-1) : Vector3.axisPY(),\r\n shadowCascades: shadowMapParams.numShadowCascades,\r\n positionAndRange: light.positionAndRange,\r\n directionAndCutoff: light.directionAndCutoff,\r\n diffuseAndIntensity: ShaderHelper.getPreExposedColorIntensity(light, ctx),\r\n extraParams: light.extraParams,\r\n cascadeDistances: shadowMapParams.cascadeDistances,\r\n depthBiasValues: shadowMapParams.depthBiasValues[0],\r\n shadowCameraParams: shadowMapParams.cameraParams,\r\n depthBiasScales: shadowMapParams.depthBiasScales,\r\n implParams: this._implParams,\r\n shadowMatrices: this._shadowMatrices,\r\n shadowStrength: light.shadow.shadowStrength,\r\n envLightStrength: ShaderHelper.getEnvLightLuminance(ctx),\r\n envLightSpecularStrength: ctx.env?.light.specularStrength ?? 1\r\n });\r\n // Which way the camera looks, for the cascade split test. The march knows\r\n // how far along its ray a sample is, and the splits are measured in view\r\n // depth; using the radial distance instead would pick a coarser cascade\r\n // towards the edges of a wide frustum and bend the cascade seam.\r\n camera.worldMatrix.getRow(2, this._cameraForward);\r\n this._cameraForward.scaleBy(-1);\r\n bindGroup.setValue('cameraForward', this._cameraForward.xyz());\r\n bindGroup.setTexture(SHADOW_MAP_UNIFORM, shadowMapParams.shadowMap!, shadowMapParams.shadowMapSampler);\r\n }\r\n /**\r\n * Build or fetch the two programs this frame needs.\r\n *\r\n * @param device - Rendering device.\r\n * @param steps - Ray-march steps for the shafts, 0 for the ambient-only variant.\r\n * @param shadow - Shadow params for the caustic light when the shafts should be\r\n * occluded by geometry, null when they should not.\r\n * @internal\r\n */\r\n private _prepare(device: AbstractDevice, steps: number, shadow: Nullable<ShadowMapParams>) {\r\n if (!this._extinctionProgram) {\r\n this._extinctionProgram = UnderwaterRenderer._createProgram(device, false, 0, null);\r\n this._extinctionBindGroup = device.createBindGroup(this._extinctionProgram.bindGroupLayouts[0]);\r\n this._extinctionStates = device.createRenderStateSet();\r\n this._extinctionStates.useRasterizerState().setCullMode('none');\r\n this._extinctionStates.useDepthState().enableTest(false).enableWrite(false);\r\n // dst.rgb *= src.rgb. The whole reason this is its own draw: the\r\n // destination factor has to be the per-channel transmittance.\r\n this._extinctionStates\r\n .useBlendingState()\r\n .enable(true)\r\n .setBlendFuncRGB('zero', 'src-color')\r\n .setBlendFuncAlpha('zero', 'one');\r\n }\r\n if (!this._inscatterStates) {\r\n this._inscatterStates = device.createRenderStateSet();\r\n this._inscatterStates.useRasterizerState().setCullMode('none');\r\n this._inscatterStates.useDepthState().enableTest(false).enableWrite(false);\r\n // dst.rgb += src.rgb. Alpha is left alone, as in the fog pass: folding a\r\n // transmittance into the framebuffer coverage makes a dense medium show\r\n // the page through the canvas.\r\n this._inscatterStates\r\n .useBlendingState()\r\n .enable(true)\r\n .setBlendFuncRGB('one', 'one')\r\n .setBlendFuncAlpha('zero', 'one');\r\n }\r\n // The march is unrolled, so the step count is part of the program identity.\r\n // Authoring it as a uniform loop bound instead would cost a dynamic loop in\r\n // every variant including the one with no shafts at all. The shadow hash\r\n // joins it because the receiver code is generated from the implementation,\r\n // the cascade count and the shadow map's own type.\r\n const key = `${steps}|${shadow ? shadow.shaderHash : ''}`;\r\n let inscatter = this._inscatterPrograms.get(key);\r\n if (!inscatter) {\r\n const program = UnderwaterRenderer._createProgram(device, true, steps, shadow);\r\n inscatter = { program, bindGroup: device.createBindGroup(program.bindGroupLayouts[0]) };\r\n this._inscatterPrograms.set(key, inscatter);\r\n }\r\n return {\r\n extinctionPass: {\r\n program: this._extinctionProgram,\r\n bindGroup: this._extinctionBindGroup!,\r\n states: this._extinctionStates!\r\n },\r\n inscatterPass: {\r\n program: inscatter.program,\r\n bindGroup: inscatter.bindGroup,\r\n states: this._inscatterStates\r\n }\r\n };\r\n }\r\n /**\r\n * @param device - Rendering device.\r\n * @param inscatter - Build the in-scattering half rather than the extinction one.\r\n * @param steps - Ray-march steps for the sun shafts; 0 leaves them out entirely.\r\n * @param shadowMapParams - Shadow params when the shafts should be occluded by\r\n * geometry, null when they should not.\r\n * @internal\r\n */\r\n private static _createProgram(\r\n device: AbstractDevice,\r\n inscatter: boolean,\r\n steps: number,\r\n shadowMapParams: Nullable<ShadowMapParams>\r\n ): GPUProgram {\r\n const godRays = inscatter && steps > 0;\r\n const shadow = godRays ? shadowMapParams : null;\r\n const numCascades = shadow?.numShadowCascades ?? 0;\r\n const program = device.buildRenderProgram({\r\n label: inscatter ? 'UnderwaterInscatter' : 'UnderwaterExtinction',\r\n vertex(pb) {\r\n this.flip = pb.int().uniform(0);\r\n this.$inputs.pos = pb.vec2().attrib('position');\r\n this.$outputs.uv = pb.vec2();\r\n pb.main(function () {\r\n this.$builtins.position = pb.vec4(this.$inputs.pos, DEPTH_FARTHEST, 1);\r\n this.$outputs.uv = pb.add(pb.mul(this.$inputs.pos.xy, 0.5), pb.vec2(0.5));\r\n this.$if(pb.notEqual(this.flip, 0), function () {\r\n this.$builtins.position.y = pb.neg(this.$builtins.position.y);\r\n });\r\n });\r\n },\r\n fragment(pb) {\r\n this.depthTex = pb.tex2D().sampleType('unfilterable-float').uniform(0);\r\n this.skyLut = pb.tex2D().uniform(0);\r\n this.invProjViewMatrix = pb.mat4().uniform(0);\r\n this.cameraPosition = pb.vec3().uniform(0);\r\n this.mediumExtinction = pb.vec3().uniform(0);\r\n this.mediumAlbedo = pb.vec3().uniform(0);\r\n /** (ambientScale, surfaceY, maxPathLength, godRayIntensity) */\r\n this.params = pb.vec4().uniform(0);\r\n if (godRays) {\r\n /** Direction the sun travels, as `directionAndCutoff.xyz`. */\r\n this.sunDirection = pb.vec3().uniform(0);\r\n /** Pre-exposed sun radiance. */\r\n this.sunColor = pb.vec3().uniform(0);\r\n /** (scatterAnisotropy, unused, unused, unused) */\r\n this.phaseParams = pb.vec4().uniform(0);\r\n // The same caustic uniforms every lit material declares, so the shafts\r\n // read the map through the exact projection the sea bed does.\r\n ShaderHelper.declareWaterCausticUniforms(pb);\r\n }\r\n if (shadow) {\r\n // The shadow receiver helpers read the material light pass's globals by\r\n // name, so a standalone pass has to reproduce them field for field.\r\n // Same arrangement, and same reason, as ShadowMaskRenderer.\r\n const cameraStruct = pb.defineStruct([\r\n pb.vec4('position'),\r\n pb.vec4('params'),\r\n pb.float('shadowDebugCascades'),\r\n // Read by the PCSS implementation's temporal jitter.\r\n pb.int('framestamp')\r\n ]);\r\n const lightStruct = pb.defineStruct([\r\n pb.vec3('sunDir'),\r\n pb.int('shadowCascades'),\r\n pb.vec4('positionAndRange'),\r\n pb.vec4('directionAndCutoff'),\r\n pb.vec4('diffuseAndIntensity'),\r\n pb.vec4('extraParams'),\r\n pb.vec4('cascadeDistances'),\r\n pb.vec4('depthBiasValues'),\r\n pb.vec4('shadowCameraParams'),\r\n pb.vec4('depthBiasScales'),\r\n pb.vec4('implParams'),\r\n pb.vec4[16]('shadowMatrices'),\r\n pb.float('shadowStrength'),\r\n pb.float('envLightStrength'),\r\n pb.float('envLightSpecularStrength')\r\n ]);\r\n this.camera = cameraStruct().uniform(0);\r\n this.light = lightStruct().uniform(0);\r\n this.cameraForward = pb.vec3().uniform(0);\r\n const shadowMap = shadow.shadowMap!;\r\n const shadowTex = shadowMap.isTextureCube()\r\n ? shadowMap.isDepth()\r\n ? pb.texCubeShadow()\r\n : pb.texCube()\r\n : shadowMap.isTexture2D()\r\n ? shadowMap.isDepth()\r\n ? pb.tex2DShadow()\r\n : pb.tex2D()\r\n : shadowMap.isDepth()\r\n ? pb.tex2DArrayShadow()\r\n : pb.tex2DArray();\r\n if (\r\n !shadowMap.isDepth() &&\r\n !device.getDeviceCaps().textureCaps.getTextureFormatInfo(shadowMap.format).filterable\r\n ) {\r\n shadowTex.sampleType('unfilterable-float');\r\n }\r\n this[SHADOW_MAP_UNIFORM] = shadowTex.uniform(0);\r\n // How much sun reaches a point inside the water column.\r\n //\r\n // No normal offset bias: that exists to stop a surface shadowing\r\n // itself at grazing incidence, and a point floating in the medium has\r\n // no surface to do it with. NoL is passed as 1 for the same reason -\r\n // there is no receiver orientation, and 1 is the value that asks the\r\n // depth bias for its smallest correction.\r\n pb.func('zUnderwaterShadow', [pb.vec3('worldPos'), pb.float('viewDepth')], function () {\r\n if (numCascades > 1) {\r\n this.$l.comparison = pb.vec4(\r\n pb.greaterThan(pb.vec4(this.viewDepth), this.light.cascadeDistances)\r\n );\r\n this.$l.cascadeFlags = pb.vec4(\r\n pb.float(pb.greaterThan(this.light.shadowCascades, 0)),\r\n pb.float(pb.greaterThan(this.light.shadowCascades, 1)),\r\n pb.float(pb.greaterThan(this.light.shadowCascades, 2)),\r\n pb.float(pb.greaterThan(this.light.shadowCascades, 3))\r\n );\r\n this.$l.split = pb.int(pb.dot(this.comparison, this.cascadeFlags));\r\n if (device.type === 'webgl') {\r\n // WebGL1 cannot index the matrix array dynamically.\r\n this.$l.shadowVertex = pb.vec4();\r\n this.$for(pb.int('cascade'), 0, 4, function () {\r\n this.$if(pb.equal(this.cascade, this.split), function () {\r\n this.shadowVertex = ShaderHelper.calculateShadowSpaceVertex(\r\n this,\r\n pb.vec4(this.worldPos, 1),\r\n this.cascade\r\n );\r\n this.$break();\r\n });\r\n });\r\n } else {\r\n this.$l.shadowVertex = ShaderHelper.calculateShadowSpaceVertex(\r\n this,\r\n pb.vec4(this.worldPos, 1),\r\n this.split\r\n );\r\n }\r\n this.$l.shadow = shadow.impl!.computeShadowCSM(\r\n shadow,\r\n this,\r\n this.shadowVertex,\r\n pb.float(1),\r\n this.split\r\n );\r\n } else {\r\n this.$l.shadowVertex = ShaderHelper.calculateShadowSpaceVertex(this, pb.vec4(this.worldPos, 1));\r\n this.$l.shadow = shadow.impl!.computeShadow(shadow, this, this.shadowVertex, pb.float(1));\r\n }\r\n // Past the shadow distance there is no map left to read, so the\r\n // shafts have to come back to unshadowed rather than to whatever the\r\n // last cascade's border holds. Same fade the surfaces use, so a shaft\r\n // and the sea bed under it stop being shadowed together.\r\n this.$l.shadowDistance = this.light.shadowCameraParams.w;\r\n this.shadow = pb.mix(\r\n this.shadow,\r\n 1,\r\n pb.smoothStep(\r\n pb.mul(this.shadowDistance, 0.8),\r\n this.shadowDistance,\r\n pb.distance(this.camera.position.xyz, this.worldPos)\r\n )\r\n );\r\n this.shadow = pb.mix(1, this.shadow, this.light.shadowStrength);\r\n this.$return(pb.clamp(this.shadow, 0, 1));\r\n });\r\n }\r\n this.$outputs.outColor = pb.vec4();\r\n pb.main(function () {\r\n this.$l.depthValue = pb.textureSample(this.depthTex, this.$inputs.uv).r;\r\n this.$l.clipSpacePos = pb.vec4(\r\n pb.sub(pb.mul(this.$inputs.uv, 2), pb.vec2(1)),\r\n ShaderHelper.deviceDepthToClipZ(this, this.depthValue),\r\n 1\r\n );\r\n this.$l.hPos = pb.mul(this.invProjViewMatrix, this.clipSpacePos);\r\n this.$l.worldPos = pb.div(this.hPos, this.hPos.w).xyz;\r\n this.$l.isSky = ShaderHelper.isFarthestDepth(this, this.depthValue);\r\n // Direction the eye is looking, as a unit vector. Normalised from the\r\n // raw difference rather than divided by the capped path length below:\r\n // the cap is a limit on how far the medium is integrated, not on where\r\n // the geometry is, so dividing by it scaled this to |worldPos - eye| /\r\n // cap - up to 2.4 in the turbid ocean preset. That put cosTheta outside\r\n // [-1, 1], drove the Henyey-Greenstein denominator negative, and the\r\n // clamp guarding pow() then returned a phase of some 40000 in a flat\r\n // band across the distance.\r\n this.$l.viewDir = pb.normalize(pb.sub(this.worldPos, this.cameraPosition));\r\n // A ray that reached the sky never left the water, so it takes the\r\n // whole cap rather than the far plane's world position. That is the\r\n // one thing that makes the horizon converge to the medium instead of\r\n // showing the sky through it.\r\n this.$l.pathLength = this.$choice(\r\n this.isSky,\r\n this.params.z,\r\n pb.min(pb.distance(this.worldPos, this.cameraPosition), this.params.z)\r\n );\r\n this.$l.transmittance = pb.exp(pb.neg(pb.mul(this.mediumExtinction, this.pathLength)));\r\n if (!inscatter) {\r\n this.$outputs.outColor = pb.vec4(this.transmittance, 1);\r\n } else {\r\n // Downwelling sky light reaching the column, attenuated over the\r\n // vertical depth rather than along the view ray: what lights the\r\n // water is the sun and sky above it, and how far down this stretch\r\n // of column sits is what decides how much of that is left. Averaged\r\n // over the two ends of the path, which is exact for a column at\r\n // constant depth and a fair stand-in when it is not.\r\n this.$l.endY = this.$choice(this.isSky, this.cameraPosition.y, this.worldPos.y);\r\n this.$l.columnDepth = pb.mul(\r\n 0.5,\r\n pb.add(\r\n pb.max(pb.sub(this.params.y, this.cameraPosition.y), 0),\r\n pb.max(pb.sub(this.params.y, this.endY), 0)\r\n )\r\n );\r\n this.$l.ambient = pb.mul(\r\n pb.textureSampleLevel(this.skyLut, pb.vec2(0.5), 0).rgb,\r\n this.params.x,\r\n pb.exp(pb.neg(pb.mul(this.mediumExtinction, this.columnDepth)))\r\n );\r\n // Single scattering: the albedo is the share of the extinguished\r\n // energy that comes back rather than being absorbed, the same form\r\n // getScattering() uses on the surface.\r\n this.$l.inscatter = pb.mul(\r\n this.mediumAlbedo,\r\n pb.sub(pb.vec3(1), this.transmittance),\r\n this.ambient\r\n );\r\n if (godRays) {\r\n // Shafts of sunlight through the column. The ambient term above is\r\n // directionless and cannot produce them; this is the same single\r\n // scattering integral evaluated against the sun instead, and the\r\n // only way to get it is to walk the ray, because how much sun\r\n // reaches a point depends on the surface overhead at that point.\r\n //\r\n // Angle between the sun's travel and the direction the scattered\r\n // light has to leave in to reach the eye, which is back along the\r\n // view ray. Constant along a ray from a directional light, so it\r\n // is hoisted out of the march. Clamped because both inputs are\r\n // unit vectors only up to rounding, and the phase function below\r\n // is not defined outside the range.\r\n this.$l.cosTheta = pb.clamp(pb.neg(pb.dot(this.sunDirection, this.viewDir)), -1, 1);\r\n this.$l.phase = waterScatterPhase(this, this.cosTheta, this.phaseParams.x);\r\n // Dithered sample offset. A fixed one puts every ray's samples on\r\n // the same set of distances, and the shafts then show as concentric\r\n // bands rather than as beams; the noise turns that structure into\r\n // grain the eye reads as the water itself.\r\n this.$l.jitter = interleavedGradientNoise(this, this.$builtins.fragCoord.xy);\r\n // The integral is sigma_s * integral(sunAtP(t) * exp(-sigma_t * t) dt),\r\n // and only `sunAtP` needs sampling - the exponential is analytic.\r\n // So the march estimates the transmittance-weighted *mean* of\r\n // sunAtP and the closed form below supplies the rest.\r\n //\r\n // Samples are placed by inverting that exponential rather than\r\n // spread evenly along the ray. Evenly spaced ones broke the turbid\r\n // ocean preset: at sigma_t = 0.46/m over a 125m cap, 24 steps sit\r\n // 5.2m apart against a 2.2m mean free path, so the first sample\r\n // outweighed the second tenfold and the red channel was decided by\r\n // a single jittered position - noise per pixel. Importance\r\n // sampling packs them into the few metres that carry the weight,\r\n // where consecutive samples land close enough that the jitter\r\n // barely moves them.\r\n //\r\n // Placement goes by the *least* attenuated channel, not by the\r\n // luminance-weighted mean. The per-channel correction is\r\n // exp(-sigma_c * t) / pdf, which grows like\r\n // exp((sigma_place - sigma_c) * t): any channel thinner than the\r\n // placement rate gets an exponentially growing weight, and its\r\n // mean ends up decided by the single furthest sample. The\r\n // luminance mean did exactly that here - sigma_lum = 0.30 against\r\n // a blue 0.24 put a factor of 2000 on the last sample at 125m,\r\n // which is both far outside the caustic map (so no pattern, hence\r\n // no visible shafts) and violently jittered (hence the grain).\r\n // Taking the minimum makes every exponent non-positive, so no\r\n // weight can ever run away.\r\n this.$l.sigmaPlace = pb.max(\r\n pb.min(pb.min(this.mediumExtinction.x, this.mediumExtinction.y), this.mediumExtinction.z),\r\n 1e-3\r\n );\r\n // Renormalises the exponential to the finite path, so the samples\r\n // span exactly the visible stretch however short it is.\r\n this.$l.cdfMax = pb.sub(1, pb.exp(pb.neg(pb.mul(this.sigmaPlace, this.pathLength))));\r\n this.$l.shafts = pb.vec3(0);\r\n this.$l.weightSum = pb.vec3(0);\r\n this.$for(pb.int('i'), 0, steps, function () {\r\n this.$l.u = pb.div(pb.add(pb.float(this.i), this.jitter), steps);\r\n this.$l.t = pb.min(\r\n pb.div(\r\n pb.neg(pb.log(pb.max(pb.sub(1, pb.mul(this.u, this.cdfMax)), 1e-6))),\r\n this.sigmaPlace\r\n ),\r\n this.pathLength\r\n );\r\n this.$l.samplePos = pb.add(this.cameraPosition, pb.mul(this.viewDir, this.t));\r\n // How much sun survives to this point: the caustic map's own\r\n // answer, which already carries both the Beer-Lambert\r\n // transmittance down the sun ray and the focusing pattern the\r\n // waves impose on it. Sharing it is what makes a shaft line up\r\n // with the caustic cell it lands in.\r\n this.$l.sunAtP = ShaderHelper.sampleWaterCaustic(\r\n this,\r\n this.samplePos,\r\n pb.int(LIGHT_TYPE_DIRECTIONAL),\r\n this.sunDirection,\r\n false\r\n );\r\n if (shadow) {\r\n // What the caustic map cannot know: it describes what the\r\n // *surface* did to the sunlight and nothing about what stands\r\n // under it, so without this a shaft runs straight through a\r\n // piling. The sea bed's own shadow is unaffected either way -\r\n // that comes from the ordinary lighting path.\r\n this.$l.viewDepth = pb.dot(pb.sub(this.samplePos, this.cameraPosition), this.cameraForward);\r\n this.sunAtP = pb.mul(this.sunAtP, this.zUnderwaterShadow(this.samplePos, this.viewDepth));\r\n }\r\n // Transmittance back to the eye over the density the sample was\r\n // drawn from. The constant factors of the pdf - sigmaPlace and\r\n // cdfMax - are the same for every sample, so they cancel in the\r\n // ratio below and only the exponentials are kept.\r\n this.$l.weight = pb.exp(\r\n pb.mul(pb.sub(pb.vec3(this.sigmaPlace), this.mediumExtinction), this.t)\r\n );\r\n this.shafts = pb.add(this.shafts, pb.mul(this.sunAtP, this.weight));\r\n this.weightSum = pb.add(this.weightSum, this.weight);\r\n });\r\n // The closed form of the same integral with sunAtP held at its\r\n // sampled mean: sigma_s/sigma_t * (1 - exp(-sigma_t * path)) is\r\n // exactly the (1 - transmittance) factor the ambient term uses, so\r\n // the two halves of the in-scattering share one normalisation and\r\n // a shaft can never exceed the light available to it.\r\n this.$l.meanSun = pb.div(this.shafts, pb.max(this.weightSum, pb.vec3(1e-6)));\r\n this.inscatter = pb.add(\r\n this.inscatter,\r\n pb.mul(\r\n this.meanSun,\r\n this.mediumAlbedo,\r\n pb.sub(pb.vec3(1), this.transmittance),\r\n this.sunColor,\r\n pb.mul(this.phase, this.params.w)\r\n )\r\n );\r\n }\r\n this.$outputs.outColor = pb.vec4(this.inscatter, 1);\r\n }\r\n });\r\n }\r\n })!;\r\n program.name = inscatter ? '@UnderwaterInscatter' : '@UnderwaterExtinction';\r\n return program;\r\n }\r\n}\r\n"],"names":["_submergence","WeakMap","setWaterSubmergence","camera","water","submerged","surfaceY","bodies","get","Map","set","delete","selectUnderwaterSource","ctx","size","best","bestY","disposed","material","underwaterEnabled","eyeDepth","Math","max","getWorldPosition","y","OPTICAL_DEPTH_CAP","SHADOW_MAP_UNIFORM","UnderwaterRenderer","_extinctionBindGroup","_extinctionStates","_inscatterStates","_extinction","_albedo","_sunDir","_sunColor","_cameraParams","_implParams","_cameraForward","_extinctionProgram","_inscatterPrograms","_params","Vector4","_phaseParams","Vector3","_cameraPosition","_shadowMatrices","render","state","colorFramebuffer","depthTexture","device","sun","waterCausticLight","godRays","underwaterGodRays","waterCaustics","underwaterGodRayIntensity","steps","underwaterGodRaySteps","shadowMapParams","underwaterGodRayShadow","shadowMapInfo","shadow","shadowMap","extinctionPass","inscatterPass","_prepare","extinction","scatterAlbedo","minExtinction","min","x","z","far","getFarPlane","setXYZW","SkyRenderer","getBakeToPreExposedScale","underwaterAmbientIntensity","scatterAnisotropy","dir","directionAndCutoff","setXYZ","color","diffuseAndIntensity","intensity","w","ShaderHelper","getPreExposure","flip","type","nearestSampler","fetchSampler","skyLut","scene","env","sky","getSkyDistantLightLUT","invProjView","invViewProjectionMatrix","cameraPos","passes","pushDeviceStates","setFramebuffer","setViewport","setScissor","pass","bindGroup","setTexture","setValue","setWaterCausticUniforms","_setShadowUniforms","setProgram","program","setBindGroup","drawFullscreenQuad","states","popDeviceStates","light","near","getNearPlane","position","params","shadowDebugCascades","framestamp","frameInfo","frameCounter","impl","getParams","matrices","shadowMatrices","length","Float32Array","sunDir","sunLight","xyz","scaleBy","axisPY","shadowCascades","numShadowCascades","positionAndRange","getPreExposedColorIntensity","extraParams","cascadeDistances","depthBiasValues","shadowCameraParams","cameraParams","depthBiasScales","implParams","shadowStrength","envLightStrength","getEnvLightLuminance","envLightSpecularStrength","specularStrength","worldMatrix","getRow","shadowMapSampler","_createProgram","createBindGroup","bindGroupLayouts","createRenderStateSet","useRasterizerState","setCullMode","useDepthState","enableTest","enableWrite","useBlendingState","enable","setBlendFuncRGB","setBlendFuncAlpha","key","shaderHash","inscatter","numCascades","buildRenderProgram","label","vertex","pb","int","uniform","$inputs","pos","vec2","attrib","$outputs","uv","main","$builtins","vec4","DEPTH_FARTHEST","add","mul","xy","$if","notEqual","neg","fragment","depthTex","tex2D","sampleType","invProjViewMatrix","mat4","cameraPosition","vec3","mediumExtinction","mediumAlbedo","sunDirection","sunColor","phaseParams","declareWaterCausticUniforms","cameraStruct","defineStruct","float","lightStruct","cameraForward","shadowTex","isTextureCube","isDepth","texCubeShadow","texCube","isTexture2D","tex2DShadow","tex2DArrayShadow","tex2DArray","getDeviceCaps","textureCaps","getTextureFormatInfo","format","filterable","func","$l","comparison","greaterThan","viewDepth","cascadeFlags","split","dot","shadowVertex","$for","equal","cascade","calculateShadowSpaceVertex","worldPos","$break","computeShadowCSM","computeShadow","shadowDistance","mix","smoothStep","distance","$return","clamp","outColor","depthValue","textureSample","r","clipSpacePos","sub","deviceDepthToClipZ","hPos","div","isSky","isFarthestDepth","viewDir","normalize","pathLength","$choice","transmittance","exp","endY","columnDepth","ambient","textureSampleLevel","rgb","cosTheta","phase","waterScatterPhase","jitter","interleavedGradientNoise","fragCoord","sigmaPlace","cdfMax","shafts","weightSum","u","i","t","log","samplePos","sunAtP","sampleWaterCaustic","LIGHT_TYPE_DIRECTIONAL","zUnderwaterShadow","weight","meanSun","name"],"mappings":";;;;;;;;;AAuCA;;;;;;;;;;;;;;IAeA,MAAMA,eAAe,IAAIC,OAAAA,EAAAA;AAEzB;;;;;;;;IASO,SAASC,mBACdC,CAAAA,MAAc,EACdC,KAAY,EACZC,SAAkB,EAClBC,QAAgB,EAAA;IAEhB,IAAIC,MAAAA,GAASP,YAAaQ,CAAAA,GAAG,CAACL,MAAAA,CAAAA;AAC9B,IAAA,IAAIE,SAAW,EAAA;AACb,QAAA,IAAI,CAACE,MAAQ,EAAA;AACXA,YAAAA,MAAAA,GAAS,IAAIE,GAAAA,EAAAA;YACbT,YAAaU,CAAAA,GAAG,CAACP,MAAQI,EAAAA,MAAAA,CAAAA;AAC3B;QACAA,MAAOG,CAAAA,GAAG,CAACN,KAAOE,EAAAA,QAAAA,CAAAA;AACpB,KAAA,MAAO,IAAIC,MAAQ,EAAA;AACjBA,QAAAA,MAAAA,CAAOI,MAAM,CAACP,KAAAA,CAAAA;AAChB;AACF;AAEA;;;;;;;;;;IAWO,SAASQ,sBAAAA,CAAuBC,GAAgB,EAAA;AACrD,IAAA,MAAMN,MAASP,GAAAA,YAAAA,CAAaQ,GAAG,CAACK,IAAIV,MAAM,CAAA;AAC1C,IAAA,IAAI,CAACI,MAAAA,IAAUA,MAAOO,CAAAA,IAAI,KAAK,CAAG,EAAA;QAChC,OAAO,IAAA;AACT;AACA,IAAA,IAAIC,IAAwB,GAAA,IAAA;AAC5B,IAAA,IAAIC,KAAQ,GAAA,CAAA;AACZ,IAAA,KAAK,MAAM,CAACZ,KAAOE,EAAAA,QAA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