@zephyr3d/scene 0.9.27 → 0.10.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 (502) hide show
  1. package/README.md +60 -27
  2. package/dist/animation/animation_bank.js +634 -0
  3. package/dist/animation/animation_bank.js.map +1 -0
  4. package/dist/animation/animation_bank_gpu.js +256 -0
  5. package/dist/animation/animation_bank_gpu.js.map +1 -0
  6. package/dist/animation/animationset.js +54 -0
  7. package/dist/animation/animationset.js.map +1 -1
  8. package/dist/animation/cloth/gpu_cloth_component.js +406 -0
  9. package/dist/animation/cloth/gpu_cloth_component.js.map +1 -0
  10. package/dist/animation/cloth/gpu_cloth_system.js +332 -202
  11. package/dist/animation/cloth/gpu_cloth_system.js.map +1 -1
  12. package/dist/animation/gpu_animation_driver.js +289 -0
  13. package/dist/animation/gpu_animation_driver.js.map +1 -0
  14. package/dist/animation/joint_dynamics/collision.js +112 -1
  15. package/dist/animation/joint_dynamics/collision.js.map +1 -1
  16. package/dist/animation/joint_dynamics/controller.js +6 -0
  17. package/dist/animation/joint_dynamics/controller.js.map +1 -1
  18. package/dist/animation/joint_dynamics/joint_dynamics_system.js +11 -0
  19. package/dist/animation/joint_dynamics/joint_dynamics_system.js.map +1 -1
  20. package/dist/animation/joint_dynamics/solver.js +50 -12
  21. package/dist/animation/joint_dynamics/solver.js.map +1 -1
  22. package/dist/animation/joint_dynamics/types.js.map +1 -1
  23. package/dist/animation/skeleton.js +279 -55
  24. package/dist/animation/skeleton.js.map +1 -1
  25. package/dist/animation/skin_palette_atlas.js +252 -0
  26. package/dist/animation/skin_palette_atlas.js.map +1 -0
  27. package/dist/animation/spring/multi_chain_spring_system.js +298 -38
  28. package/dist/animation/spring/multi_chain_spring_system.js.map +1 -1
  29. package/dist/animation/spring/spring_chain.js +2 -0
  30. package/dist/animation/spring/spring_chain.js.map +1 -1
  31. package/dist/animation/spring/spring_collider.js +159 -21
  32. package/dist/animation/spring/spring_collider.js.map +1 -1
  33. package/dist/animation/spring/spring_particle.js +1 -0
  34. package/dist/animation/spring/spring_particle.js.map +1 -1
  35. package/dist/animation/spring/spring_solver.js +173 -0
  36. package/dist/animation/spring/spring_solver.js.map +1 -0
  37. package/dist/animation/spring/spring_system.js +249 -24
  38. package/dist/animation/spring/spring_system.js.map +1 -1
  39. package/dist/animation/spring_modifier.js +32 -1
  40. package/dist/animation/spring_modifier.js.map +1 -1
  41. package/dist/app/app.js +26 -0
  42. package/dist/app/app.js.map +1 -1
  43. package/dist/app/engine.js +86 -15
  44. package/dist/app/engine.js.map +1 -1
  45. package/dist/app/gamepad.js +191 -0
  46. package/dist/app/gamepad.js.map +1 -0
  47. package/dist/app/inputactions.js +271 -0
  48. package/dist/app/inputactions.js.map +1 -0
  49. package/dist/app/inputmgr.js +331 -22
  50. package/dist/app/inputmgr.js.map +1 -1
  51. package/dist/app/loading.js +138 -0
  52. package/dist/app/loading.js.map +1 -0
  53. package/dist/app/pipelinecache.js +209 -0
  54. package/dist/app/pipelinecache.js.map +1 -0
  55. package/dist/app/runtimescript.js +25 -0
  56. package/dist/app/runtimescript.js.map +1 -1
  57. package/dist/app/scriptingsystem.js +54 -0
  58. package/dist/app/scriptingsystem.js.map +1 -1
  59. package/dist/app/scriptregistry.js +7 -2
  60. package/dist/app/scriptregistry.js.map +1 -1
  61. package/dist/asset/asset_manifest.js +59 -0
  62. package/dist/asset/asset_manifest.js.map +1 -0
  63. package/dist/asset/asset_preload.js +258 -0
  64. package/dist/asset/asset_preload.js.map +1 -0
  65. package/dist/asset/assetmanager.js +117 -65
  66. package/dist/asset/assetmanager.js.map +1 -1
  67. package/dist/asset/loaders/ktx2/basis/LICENSE +201 -0
  68. package/dist/asset/loaders/ktx2/basis/basis_transcoder.js +2 -0
  69. package/dist/asset/loaders/ktx2/basis/basis_transcoder.wasm +0 -0
  70. package/dist/asset/loaders/ktx2/basis_location.js +17 -0
  71. package/dist/asset/loaders/ktx2/basis_location.js.map +1 -0
  72. package/dist/asset/loaders/ktx2/ktx2_loader.js +88 -0
  73. package/dist/asset/loaders/ktx2/ktx2_loader.js.map +1 -0
  74. package/dist/asset/loaders/ktx2/ktx2_targets.js +118 -0
  75. package/dist/asset/loaders/ktx2/ktx2_targets.js.map +1 -0
  76. package/dist/asset/loaders/ktx2/transcoder_pool.js +259 -0
  77. package/dist/asset/loaders/ktx2/transcoder_pool.js.map +1 -0
  78. package/dist/asset/mesh_lod_builder.js +104 -0
  79. package/dist/asset/mesh_lod_builder.js.map +1 -0
  80. package/dist/asset/mesh_settings.js +111 -0
  81. package/dist/asset/mesh_settings.js.map +1 -0
  82. package/dist/asset/meshopt_decoder.js +18 -0
  83. package/dist/asset/meshopt_decoder.js.map +1 -0
  84. package/dist/asset/meshopt_simplifier.js +26 -0
  85. package/dist/asset/meshopt_simplifier.js.map +1 -0
  86. package/dist/asset/model.js +171 -1
  87. package/dist/asset/model.js.map +1 -1
  88. package/dist/asset/texture_settings.js +231 -0
  89. package/dist/asset/texture_settings.js.map +1 -0
  90. package/dist/asset/zmsh_binary.js +131 -0
  91. package/dist/asset/zmsh_binary.js.map +1 -0
  92. package/dist/asset/zsdf_binary.js +111 -0
  93. package/dist/asset/zsdf_binary.js.map +1 -0
  94. package/dist/blitter/bilateralblur.js +1 -2
  95. package/dist/blitter/bilateralblur.js.map +1 -1
  96. package/dist/blitter/gaussianblur.js +1 -6
  97. package/dist/blitter/gaussianblur.js.map +1 -1
  98. package/dist/camera/base.js +31 -10
  99. package/dist/camera/base.js.map +1 -1
  100. package/dist/camera/camera.js +104 -178
  101. package/dist/camera/camera.js.map +1 -1
  102. package/dist/camera/follow.js +342 -0
  103. package/dist/camera/follow.js.map +1 -0
  104. package/dist/camera/fps.js +9 -7
  105. package/dist/camera/fps.js.map +1 -1
  106. package/dist/camera/orbit.js +46 -19
  107. package/dist/camera/orbit.js.map +1 -1
  108. package/dist/index.d.ts +25436 -15990
  109. package/dist/index.js +65 -11
  110. package/dist/index.js.map +1 -1
  111. package/dist/material/blinn.js +3 -0
  112. package/dist/material/blinn.js.map +1 -1
  113. package/dist/material/eye.js +1 -1
  114. package/dist/material/eye.js.map +1 -1
  115. package/dist/material/hair.js +2 -3
  116. package/dist/material/hair.js.map +1 -1
  117. package/dist/material/lambert.js +4 -1
  118. package/dist/material/lambert.js.map +1 -1
  119. package/dist/material/material.js +66 -4
  120. package/dist/material/material.js.map +1 -1
  121. package/dist/material/meshmaterial.js +118 -45
  122. package/dist/material/meshmaterial.js.map +1 -1
  123. package/dist/material/mixins/lightmodel/blinnphong.js +1 -1
  124. package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -1
  125. package/dist/material/mixins/lightmodel/lambert.js +1 -1
  126. package/dist/material/mixins/lightmodel/lambert.js.map +1 -1
  127. package/dist/material/mixins/lightmodel/pbrblueprintmixin.js +34 -61
  128. package/dist/material/mixins/lightmodel/pbrblueprintmixin.js.map +1 -1
  129. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +16 -2
  130. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
  131. package/dist/material/mixins/lightmodel/pbrspecularglossness.js +2 -1
  132. package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
  133. package/dist/material/mixins/lit.js +191 -83
  134. package/dist/material/mixins/lit.js.map +1 -1
  135. package/dist/material/mixins/pbr/common.js +31 -206
  136. package/dist/material/mixins/pbr/common.js.map +1 -1
  137. package/dist/material/mtoon.js +1 -1
  138. package/dist/material/mtoon.js.map +1 -1
  139. package/dist/material/pbrmr.js +3 -0
  140. package/dist/material/pbrmr.js.map +1 -1
  141. package/dist/material/pbrsg.js +3 -0
  142. package/dist/material/pbrsg.js.map +1 -1
  143. package/dist/material/sdf_debug.js +78 -0
  144. package/dist/material/sdf_debug.js.map +1 -0
  145. package/dist/material/shader/helper.js +333 -191
  146. package/dist/material/shader/helper.js.map +1 -1
  147. package/dist/material/shader/terrain_blend.js +204 -43
  148. package/dist/material/shader/terrain_blend.js.map +1 -1
  149. package/dist/material/skin.js +331 -297
  150. package/dist/material/skin.js.map +1 -1
  151. package/dist/material/skinprofile.js +1058 -0
  152. package/dist/material/skinprofile.js.map +1 -0
  153. package/dist/material/sss.js +353 -0
  154. package/dist/material/sss.js.map +1 -0
  155. package/dist/material/sss_kernel.js +265 -0
  156. package/dist/material/sss_kernel.js.map +1 -0
  157. package/dist/material/sssprofile.js +879 -0
  158. package/dist/material/sssprofile.js.map +1 -0
  159. package/dist/material/subsurfaceprofile.js +4 -8
  160. package/dist/material/subsurfaceprofile.js.map +1 -1
  161. package/dist/material/terrain-cm.js +464 -188
  162. package/dist/material/terrain-cm.js.map +1 -1
  163. package/dist/material/unlit.js +3 -0
  164. package/dist/material/unlit.js.map +1 -1
  165. package/dist/material/water.js +1261 -1438
  166. package/dist/material/water.js.map +1 -1
  167. package/dist/node_modules/meshoptimizer/LICENSE +21 -0
  168. package/dist/node_modules/meshoptimizer/meshopt_decoder.js +197 -0
  169. package/dist/node_modules/meshoptimizer/meshopt_decoder.js.map +1 -0
  170. package/dist/node_modules/meshoptimizer/meshopt_simplifier.js +677 -0
  171. package/dist/node_modules/meshoptimizer/meshopt_simplifier.js.map +1 -0
  172. package/dist/physics/character.js +226 -0
  173. package/dist/physics/character.js.map +1 -0
  174. package/dist/physics/collider.js +209 -0
  175. package/dist/physics/collider.js.map +1 -0
  176. package/dist/physics/events.js +79 -0
  177. package/dist/physics/events.js.map +1 -0
  178. package/dist/physics/joint.js +272 -0
  179. package/dist/physics/joint.js.map +1 -0
  180. package/dist/physics/node_physics.js +234 -0
  181. package/dist/physics/node_physics.js.map +1 -0
  182. package/dist/physics/part.js +91 -0
  183. package/dist/physics/part.js.map +1 -0
  184. package/dist/physics/rigid_body.js +379 -0
  185. package/dist/physics/rigid_body.js.map +1 -0
  186. package/dist/physics/vehicle.js +335 -0
  187. package/dist/physics/vehicle.js.map +1 -0
  188. package/dist/physics/world.js +25 -0
  189. package/dist/physics/world.js.map +1 -0
  190. package/dist/posteffect/bloom.js +49 -14
  191. package/dist/posteffect/bloom.js.map +1 -1
  192. package/dist/posteffect/motionblur.js +106 -106
  193. package/dist/posteffect/motionblur.js.map +1 -1
  194. package/dist/posteffect/postsss.js +572 -0
  195. package/dist/posteffect/postsss.js.map +1 -0
  196. package/dist/posteffect/sao.js +2 -6
  197. package/dist/posteffect/sao.js.map +1 -1
  198. package/dist/posteffect/skinsss.js +605 -355
  199. package/dist/posteffect/skinsss.js.map +1 -1
  200. package/dist/posteffect/ssgi.js +91 -162
  201. package/dist/posteffect/ssgi.js.map +1 -1
  202. package/dist/posteffect/ssr.js +3 -11
  203. package/dist/posteffect/ssr.js.map +1 -1
  204. package/dist/posteffect/sss.js +4 -13
  205. package/dist/posteffect/sss.js.map +1 -1
  206. package/dist/posteffect/taa.js +1 -0
  207. package/dist/posteffect/taa.js.map +1 -1
  208. package/dist/render/abuffer_oit.js +3 -2
  209. package/dist/render/abuffer_oit.js.map +1 -1
  210. package/dist/render/clipmap.js +179 -64
  211. package/dist/render/clipmap.js.map +1 -1
  212. package/dist/render/cluster_light.js +958 -224
  213. package/dist/render/cluster_light.js.map +1 -1
  214. package/dist/render/cull_visitor.js +25 -5
  215. package/dist/render/cull_visitor.js.map +1 -1
  216. package/dist/render/debug_views.js +37 -0
  217. package/dist/render/debug_views.js.map +1 -0
  218. package/dist/render/depthpass.js +5 -1
  219. package/dist/render/depthpass.js.map +1 -1
  220. package/dist/render/drawable_mixin.js +53 -6
  221. package/dist/render/drawable_mixin.js.map +1 -1
  222. package/dist/render/dualdepthpeeling_oit.js +5 -5
  223. package/dist/render/dualdepthpeeling_oit.js.map +1 -1
  224. package/dist/render/envlight.js +196 -113
  225. package/dist/render/envlight.js.map +1 -1
  226. package/dist/render/fbm_wavegenerator.js +5 -10
  227. package/dist/render/fbm_wavegenerator.js.map +1 -1
  228. package/dist/render/fft_wavegenerator.js +247 -157
  229. package/dist/render/fft_wavegenerator.js.map +1 -1
  230. package/dist/render/gerstner_wavegenerator.js +16 -38
  231. package/dist/render/gerstner_wavegenerator.js.map +1 -1
  232. package/dist/render/gi/probe_volume.js +1334 -0
  233. package/dist/render/gi/probe_volume.js.map +1 -0
  234. package/dist/render/gi/scene_gi.js +282 -0
  235. package/dist/render/gi/scene_gi.js.map +1 -0
  236. package/dist/render/gi/voxel_atlas.js +198 -0
  237. package/dist/render/gi/voxel_atlas.js.map +1 -0
  238. package/dist/render/gi/voxel_lighting.js +652 -0
  239. package/dist/render/gi/voxel_lighting.js.map +1 -0
  240. package/dist/render/gi/voxel_scene.js +642 -0
  241. package/dist/render/gi/voxel_scene.js.map +1 -0
  242. package/dist/render/gi/voxelize_pass.js +223 -0
  243. package/dist/render/gi/voxelize_pass.js.map +1 -0
  244. package/dist/render/globalbindgroup_allocator.js +3 -2
  245. package/dist/render/globalbindgroup_allocator.js.map +1 -1
  246. package/dist/render/gpu_picking.js +9 -36
  247. package/dist/render/gpu_picking.js.map +1 -1
  248. package/dist/render/instance_culling.js +499 -0
  249. package/dist/render/instance_culling.js.map +1 -0
  250. package/dist/render/lightpass.js +19 -8
  251. package/dist/render/lightpass.js.map +1 -1
  252. package/dist/render/lod.js +46 -0
  253. package/dist/render/lod.js.map +1 -0
  254. package/dist/render/primitive.js +301 -9
  255. package/dist/render/primitive.js.map +1 -1
  256. package/dist/render/primitive_readback.js +209 -0
  257. package/dist/render/primitive_readback.js.map +1 -0
  258. package/dist/render/render_queue.js +162 -11
  259. package/dist/render/render_queue.js.map +1 -1
  260. package/dist/render/renderer.js +10 -7
  261. package/dist/render/renderer.js.map +1 -1
  262. package/dist/render/rendergraph/blackboard.js +14 -1
  263. package/dist/render/rendergraph/blackboard.js.map +1 -1
  264. package/dist/render/rendergraph/executor.js +136 -0
  265. package/dist/render/rendergraph/executor.js.map +1 -1
  266. package/dist/render/rendergraph/forward_plus_builder.js +272 -55
  267. package/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
  268. package/dist/render/rendergraph/frame_graph_context.js +41 -0
  269. package/dist/render/rendergraph/frame_graph_context.js.map +1 -0
  270. package/dist/render/rendergraph/scene_render_context.js +31 -2
  271. package/dist/render/rendergraph/scene_render_context.js.map +1 -1
  272. package/dist/render/rendergraph/types.js.map +1 -1
  273. package/dist/render/renderpass.js +28 -5
  274. package/dist/render/renderpass.js.map +1 -1
  275. package/dist/render/sdf/box_allocator.js +98 -0
  276. package/dist/render/sdf/box_allocator.js.map +1 -0
  277. package/dist/render/sdf/global_sdf.js +865 -0
  278. package/dist/render/sdf/global_sdf.js.map +1 -0
  279. package/dist/render/sdf/scene_sdf.js +562 -0
  280. package/dist/render/sdf/scene_sdf.js.map +1 -0
  281. package/dist/render/sdf/sdf_atlas.js +227 -0
  282. package/dist/render/sdf/sdf_atlas.js.map +1 -0
  283. package/dist/render/sdf/sdf_programs.js +42 -0
  284. package/dist/render/sdf/sdf_programs.js.map +1 -0
  285. package/dist/render/sdf/sdf_view.js +199 -0
  286. package/dist/render/sdf/sdf_view.js.map +1 -0
  287. package/dist/render/sdf/waterline.js +610 -0
  288. package/dist/render/sdf/waterline.js.map +1 -0
  289. package/dist/render/shadow_mask_pass.js +142 -25
  290. package/dist/render/shadow_mask_pass.js.map +1 -1
  291. package/dist/render/shore_wave_generator.js +1193 -0
  292. package/dist/render/shore_wave_generator.js.map +1 -0
  293. package/dist/render/sky.js +516 -86
  294. package/dist/render/sky.js.map +1 -1
  295. package/dist/render/transmission_thickness_pass.js +477 -0
  296. package/dist/render/transmission_thickness_pass.js.map +1 -0
  297. package/dist/render/underwater.js +58 -158
  298. package/dist/render/underwater.js.map +1 -1
  299. package/dist/render/virtualtexture/virtual_texture.js +1214 -0
  300. package/dist/render/virtualtexture/virtual_texture.js.map +1 -0
  301. package/dist/render/volumetric_cloud/cloud_common.js +472 -0
  302. package/dist/render/volumetric_cloud/cloud_common.js.map +1 -0
  303. package/dist/render/volumetric_cloud/cloud_noise.js +189 -0
  304. package/dist/render/volumetric_cloud/cloud_noise.js.map +1 -0
  305. package/dist/render/volumetric_cloud/debug_view.js +131 -0
  306. package/dist/render/volumetric_cloud/debug_view.js.map +1 -0
  307. package/dist/render/volumetric_cloud/resources.js +380 -0
  308. package/dist/render/volumetric_cloud/resources.js.map +1 -0
  309. package/dist/render/volumetric_cloud/sky_cache.js +380 -0
  310. package/dist/render/volumetric_cloud/sky_cache.js.map +1 -0
  311. package/dist/render/volumetric_cloud/volumetric_cloud.js +318 -0
  312. package/dist/render/volumetric_cloud/volumetric_cloud.js.map +1 -0
  313. package/dist/render/water_caustics.js +134 -319
  314. package/dist/render/water_caustics.js.map +1 -1
  315. package/dist/render/water_foam.js +627 -0
  316. package/dist/render/water_foam.js.map +1 -0
  317. package/dist/render/water_interaction.js +1795 -0
  318. package/dist/render/water_interaction.js.map +1 -0
  319. package/dist/render/weightedblended_oit.js +3 -3
  320. package/dist/render/weightedblended_oit.js.map +1 -1
  321. package/dist/scene/basesprite.js +9 -4
  322. package/dist/scene/basesprite.js.map +1 -1
  323. package/dist/scene/batchgroup.js +108 -12
  324. package/dist/scene/batchgroup.js.map +1 -1
  325. package/dist/scene/environment.js +28 -7
  326. package/dist/scene/environment.js.map +1 -1
  327. package/dist/scene/foliage.js +1020 -0
  328. package/dist/scene/foliage.js.map +1 -0
  329. package/dist/scene/foliage_buckets.js +147 -0
  330. package/dist/scene/foliage_buckets.js.map +1 -0
  331. package/dist/scene/foliage_mask.js +358 -0
  332. package/dist/scene/foliage_mask.js.map +1 -0
  333. package/dist/scene/hair.js +15 -4
  334. package/dist/scene/hair.js.map +1 -1
  335. package/dist/scene/light.js +179 -13
  336. package/dist/scene/light.js.map +1 -1
  337. package/dist/scene/mesh.js +327 -45
  338. package/dist/scene/mesh.js.map +1 -1
  339. package/dist/scene/meshdrawable.js +6 -0
  340. package/dist/scene/meshdrawable.js.map +1 -1
  341. package/dist/scene/msdftext.js +9 -3
  342. package/dist/scene/msdftext.js.map +1 -1
  343. package/dist/scene/msdftextsprite.js +9 -3
  344. package/dist/scene/msdftextsprite.js.map +1 -1
  345. package/dist/scene/particlesys.js +8 -2
  346. package/dist/scene/particlesys.js.map +1 -1
  347. package/dist/scene/physics_settings.js +157 -0
  348. package/dist/scene/physics_settings.js.map +1 -0
  349. package/dist/scene/scene.js +190 -44
  350. package/dist/scene/scene.js.map +1 -1
  351. package/dist/scene/scene_node.js +147 -6
  352. package/dist/scene/scene_node.js.map +1 -1
  353. package/dist/scene/terrain-cm/bladegrassmaterial.js +735 -0
  354. package/dist/scene/terrain-cm/bladegrassmaterial.js.map +1 -0
  355. package/dist/scene/terrain-cm/grass.js +881 -42
  356. package/dist/scene/terrain-cm/grass.js.map +1 -1
  357. package/dist/scene/terrain-cm/grass_gpu.js +929 -0
  358. package/dist/scene/terrain-cm/grass_gpu.js.map +1 -0
  359. package/dist/scene/terrain-cm/grassmaterial.js +180 -9
  360. package/dist/scene/terrain-cm/grassmaterial.js.map +1 -1
  361. package/dist/scene/terrain-cm/terrain-cm.js +465 -36
  362. package/dist/scene/terrain-cm/terrain-cm.js.map +1 -1
  363. package/dist/scene/terrain-cm/terrain_gi_albedo.js +257 -0
  364. package/dist/scene/terrain-cm/terrain_gi_albedo.js.map +1 -0
  365. package/dist/scene/terrain-cm/terrain_rvt.js +395 -0
  366. package/dist/scene/terrain-cm/terrain_rvt.js.map +1 -0
  367. package/dist/scene/update_queue.js +54 -0
  368. package/dist/scene/update_queue.js.map +1 -0
  369. package/dist/scene/water.js +633 -268
  370. package/dist/scene/water.js.map +1 -1
  371. package/dist/scene/water_surface_sampler.js +324 -0
  372. package/dist/scene/water_surface_sampler.js.map +1 -0
  373. package/dist/scene/wind.js +317 -0
  374. package/dist/scene/wind.js.map +1 -0
  375. package/dist/shaders/atmosphere.js +388 -166
  376. package/dist/shaders/atmosphere.js.map +1 -1
  377. package/dist/shaders/fog.js +100 -32
  378. package/dist/shaders/fog.js.map +1 -1
  379. package/dist/shaders/gi.js +365 -0
  380. package/dist/shaders/gi.js.map +1 -0
  381. package/dist/shaders/ltc_rect.js +202 -0
  382. package/dist/shaders/ltc_rect.js.map +1 -0
  383. package/dist/shaders/misc.js +1 -10
  384. package/dist/shaders/misc.js.map +1 -1
  385. package/dist/shaders/noise.js +5 -1
  386. package/dist/shaders/noise.js.map +1 -1
  387. package/dist/shaders/probes.js +309 -0
  388. package/dist/shaders/probes.js.map +1 -0
  389. package/dist/shaders/sdf.js +537 -0
  390. package/dist/shaders/sdf.js.map +1 -0
  391. package/dist/shaders/shadow.js +104 -70
  392. package/dist/shaders/shadow.js.map +1 -1
  393. package/dist/shaders/skin_brdf.js +243 -0
  394. package/dist/shaders/skin_brdf.js.map +1 -0
  395. package/dist/shaders/ssgi.js +63 -0
  396. package/dist/shaders/ssgi.js.map +1 -0
  397. package/dist/shaders/ssgi_reprojection.js +118 -0
  398. package/dist/shaders/ssgi_reprojection.js.map +1 -0
  399. package/dist/shaders/ssr.js +6 -159
  400. package/dist/shaders/ssr.js.map +1 -1
  401. package/dist/shaders/temporal.js +38 -27
  402. package/dist/shaders/temporal.js.map +1 -1
  403. package/dist/shaders/water.js +32 -82
  404. package/dist/shaders/water.js.map +1 -1
  405. package/dist/shaders/water_medium.js +7 -21
  406. package/dist/shaders/water_medium.js.map +1 -1
  407. package/dist/shadow/dom.js +110 -19
  408. package/dist/shadow/dom.js.map +1 -1
  409. package/dist/shadow/esm.js +3 -3
  410. package/dist/shadow/esm.js.map +1 -1
  411. package/dist/shadow/pcf_opt.js +15 -48
  412. package/dist/shadow/pcf_opt.js.map +1 -1
  413. package/dist/shadow/pcf_pd.js +15 -53
  414. package/dist/shadow/pcf_pd.js.map +1 -1
  415. package/dist/shadow/pcss.js +34 -9
  416. package/dist/shadow/pcss.js.map +1 -1
  417. package/dist/shadow/shadow_impl.js +3 -8
  418. package/dist/shadow/shadow_impl.js.map +1 -1
  419. package/dist/shadow/shadow_region.js +40 -2
  420. package/dist/shadow/shadow_region.js.map +1 -1
  421. package/dist/shadow/shadowmapper.js +93 -53
  422. package/dist/shadow/shadowmapper.js.map +1 -1
  423. package/dist/shadow/ssm.js +18 -72
  424. package/dist/shadow/ssm.js.map +1 -1
  425. package/dist/shadow/vsm.js +3 -3
  426. package/dist/shadow/vsm.js.map +1 -1
  427. package/dist/shapes/shape.js +44 -1
  428. package/dist/shapes/shape.js.map +1 -1
  429. package/dist/utility/buoyancy.js +287 -0
  430. package/dist/utility/buoyancy.js.map +1 -0
  431. package/dist/utility/physical.js +10 -1
  432. package/dist/utility/physical.js.map +1 -1
  433. package/dist/utility/pmrem.js +17 -43
  434. package/dist/utility/pmrem.js.map +1 -1
  435. package/dist/utility/sdf/bake.js +435 -0
  436. package/dist/utility/sdf/bake.js.map +1 -0
  437. package/dist/utility/sdf/bvh.js +576 -0
  438. package/dist/utility/sdf/bvh.js.map +1 -0
  439. package/dist/utility/serialization/manager.js +34 -6
  440. package/dist/utility/serialization/manager.js.map +1 -1
  441. package/dist/utility/serialization/scene/animation.js +46 -5
  442. package/dist/utility/serialization/scene/animation.js.map +1 -1
  443. package/dist/utility/serialization/scene/batch.js +11 -4
  444. package/dist/utility/serialization/scene/batch.js.map +1 -1
  445. package/dist/utility/serialization/scene/camera.js +87 -254
  446. package/dist/utility/serialization/scene/camera.js.map +1 -1
  447. package/dist/utility/serialization/scene/cloth.js +25 -0
  448. package/dist/utility/serialization/scene/cloth.js.map +1 -0
  449. package/dist/utility/serialization/scene/common.js +14 -6
  450. package/dist/utility/serialization/scene/common.js.map +1 -1
  451. package/dist/utility/serialization/scene/foliage.js +821 -0
  452. package/dist/utility/serialization/scene/foliage.js.map +1 -0
  453. package/dist/utility/serialization/scene/hair.js +11 -4
  454. package/dist/utility/serialization/scene/hair.js.map +1 -1
  455. package/dist/utility/serialization/scene/light.js +115 -7
  456. package/dist/utility/serialization/scene/light.js.map +1 -1
  457. package/dist/utility/serialization/scene/material.js +388 -220
  458. package/dist/utility/serialization/scene/material.js.map +1 -1
  459. package/dist/utility/serialization/scene/mesh.js +69 -4
  460. package/dist/utility/serialization/scene/mesh.js.map +1 -1
  461. package/dist/utility/serialization/scene/node.js +140 -5
  462. package/dist/utility/serialization/scene/node.js.map +1 -1
  463. package/dist/utility/serialization/scene/node_physics.js +1318 -0
  464. package/dist/utility/serialization/scene/node_physics.js.map +1 -0
  465. package/dist/utility/serialization/scene/particle.js +11 -4
  466. package/dist/utility/serialization/scene/particle.js.map +1 -1
  467. package/dist/utility/serialization/scene/physics.js +120 -0
  468. package/dist/utility/serialization/scene/physics.js.map +1 -0
  469. package/dist/utility/serialization/scene/primitive.js +124 -10
  470. package/dist/utility/serialization/scene/primitive.js.map +1 -1
  471. package/dist/utility/serialization/scene/scene.js +1687 -51
  472. package/dist/utility/serialization/scene/scene.js.map +1 -1
  473. package/dist/utility/serialization/scene/sprite.js +11 -4
  474. package/dist/utility/serialization/scene/sprite.js.map +1 -1
  475. package/dist/utility/serialization/scene/terrain.js +163 -33
  476. package/dist/utility/serialization/scene/terrain.js.map +1 -1
  477. package/dist/utility/serialization/scene/text.js +11 -4
  478. package/dist/utility/serialization/scene/text.js.map +1 -1
  479. package/dist/utility/serialization/scene/water.js +1543 -264
  480. package/dist/utility/serialization/scene/water.js.map +1 -1
  481. package/dist/utility/serialization/types.js.map +1 -1
  482. package/dist/utility/shprojector.js +10 -22
  483. package/dist/utility/shprojector.js.map +1 -1
  484. package/dist/utility/textures/foam.js +170 -0
  485. package/dist/utility/textures/foam.js.map +1 -0
  486. package/dist/utility/textures/ggxlut.js +17 -43
  487. package/dist/utility/textures/ggxlut.js.map +1 -1
  488. package/dist/utility/textures/ltcdata.js +4 -4
  489. package/dist/utility/textures/ltcdata.js.map +1 -1
  490. package/dist/utility/textures/ltclut.js +16 -6
  491. package/dist/utility/textures/ltclut.js.map +1 -1
  492. package/dist/utility/unsupported.js +24 -0
  493. package/dist/utility/unsupported.js.map +1 -0
  494. package/dist/values.js +13 -1
  495. package/dist/values.js.map +1 -1
  496. package/package.json +25 -12
  497. package/src/asset/loaders/ktx2/basis/LICENSE +201 -0
  498. package/src/asset/loaders/ktx2/basis/basis_transcoder.js +2 -0
  499. package/src/asset/loaders/ktx2/basis/basis_transcoder.wasm +0 -0
  500. package/src/asset/meshoptimizer/LICENSE +21 -0
  501. package/dist/animation/joint_dynamics/convex_collider.js +0 -320
  502. package/dist/animation/joint_dynamics/convex_collider.js.map +0 -1
@@ -0,0 +1,243 @@
1
+ import { distributionGGX, visGGX, fresnelSchlick } from './pbr.js';
2
+ import { SSSProfile, SKIN_TRANSMISSION_NO_DATA_ENCODING } from '../material/sssprofile.js';
3
+
4
+ /** Opacity below which the dual-lobe specular fades back to a single lobe. */ const OPACITY_THRESHOLD_EPS = 0.1;
5
+ /**
6
+ * Multiple-scattering energy terms for a GGX specular lobe.
7
+ *
8
+ * @param scope - Shader scope.
9
+ * @param roughness - Roughness of the lobe being corrected.
10
+ * @param NoV - Clamped dot(normal, viewDir).
11
+ * @param F0 - Fresnel reflectance at normal incidence.
12
+ * @returns `vec2(W, A)`: specular gain and reflected share.
13
+ *
14
+ * @internal
15
+ */ function skinSpecularEnergyTerms(scope, roughness, NoV, F0) {
16
+ const pb = scope.$builder;
17
+ const funcName = 'lib_skinSpecularEnergyTerms';
18
+ pb.func(funcName, [
19
+ pb.float('roughness'),
20
+ pb.float('NoV'),
21
+ pb.float('F0')
22
+ ], function() {
23
+ this.$l.r = pb.max(this.roughness, 1e-3);
24
+ this.$l.c = pb.max(this.NoV, 1e-3);
25
+ this.$l.E = pb.sub(1, pb.clamp(pb.mul(pb.pow(this.r, pb.div(this.c, this.r)), pb.div(pb.add(pb.mul(this.r, this.c), 0.0266916), pb.add(0.466495, this.c))), 0, 1));
26
+ this.E = pb.max(this.E, 1e-4);
27
+ this.$l.oneMinusC = pb.sub(1, this.c);
28
+ this.$l.pow5 = pb.mul(pb.mul(this.oneMinusC, this.oneMinusC), pb.mul(this.oneMinusC, this.oneMinusC), this.oneMinusC);
29
+ this.$l.Ef = pb.mul(this.pow5, pb.pow(pb.add(pb.mul(2.36651, pb.pow(this.c, pb.mul(4.7703, this.r))), 0.0387332), this.r));
30
+ this.$l.F90 = pb.clamp(pb.mul(50, this.F0), 0, 1);
31
+ this.$l.W = pb.add(1, pb.mul(this.F0, pb.div(pb.sub(1, this.E), this.E)));
32
+ this.$l.A = pb.mul(this.W, pb.add(pb.mul(this.E, this.F0), pb.mul(this.Ef, pb.sub(this.F90, this.F0))));
33
+ this.$return(pb.vec2(this.W, pb.clamp(this.A, 0, 1)));
34
+ });
35
+ return pb.getGlobalScope()[funcName](roughness, NoV, F0);
36
+ }
37
+ /**
38
+ * Burley diffuse BRDF.
39
+ *
40
+ * @param scope - Shader scope.
41
+ * @param NdotV - Clamped dot(normal, viewDir).
42
+ * @param NdotL - Clamped dot(normal, lightDir).
43
+ * @param VdotH - dot(viewDir, halfVector).
44
+ * @param roughness - Material roughness.
45
+ * @returns Scalar diffuse BRDF value; the caller applies albedo and `NoL`.
46
+ *
47
+ * @internal
48
+ */ function skinDiffuseBRDF(scope, NdotV, NdotL, VdotH, roughness) {
49
+ const pb = scope.$builder;
50
+ const funcName = 'lib_skinDiffuseBurley';
51
+ pb.func(funcName, [
52
+ pb.float('NdotV'),
53
+ pb.float('NdotL'),
54
+ pb.float('VdotH'),
55
+ pb.float('roughness')
56
+ ], function() {
57
+ this.$l.fd90 = pb.add(0.5, pb.mul(2, this.VdotH, this.VdotH, this.roughness));
58
+ this.$l.fd90m1 = pb.sub(this.fd90, 1);
59
+ this.$l.oneMinusNoV = pb.sub(1, this.NdotV);
60
+ this.$l.pow5V = pb.mul(pb.mul(this.oneMinusNoV, this.oneMinusNoV), pb.mul(this.oneMinusNoV, this.oneMinusNoV), this.oneMinusNoV);
61
+ this.$l.oneMinusNoL = pb.sub(1, this.NdotL);
62
+ this.$l.pow5L = pb.mul(pb.mul(this.oneMinusNoL, this.oneMinusNoL), pb.mul(this.oneMinusNoL, this.oneMinusNoL), this.oneMinusNoL);
63
+ this.$l.fdV = pb.add(1, pb.mul(this.fd90m1, this.pow5V));
64
+ this.$l.fdL = pb.add(1, pb.mul(this.fd90m1, this.pow5L));
65
+ this.$return(pb.mul(1 / Math.PI, this.fdV, this.fdL));
66
+ });
67
+ return pb.getGlobalScope()[funcName](NdotV, NdotL, VdotH, roughness);
68
+ }
69
+ /**
70
+ * Resolves the two specular lobe roughnesses from the profile.
71
+ *
72
+ * @param scope - Shader scope.
73
+ * @param roughness - Material roughness.
74
+ * @param opacity - Subsurface opacity, used to fade the effect out.
75
+ * @param lobe0Scale - Profile roughness multiplier for the narrow lobe.
76
+ * @param lobe1Scale - Profile roughness multiplier for the wide lobe.
77
+ * @returns `vec2(lobe0Roughness, lobe1Roughness)`.
78
+ *
79
+ * @internal
80
+ */ function skinDualSpecularRoughness(scope, roughness, opacity, lobe0Scale, lobe1Scale) {
81
+ const pb = scope.$builder;
82
+ const funcName = 'lib_skinDualSpecularRoughness';
83
+ pb.func(funcName, [
84
+ pb.float('roughness'),
85
+ pb.float('opacity'),
86
+ pb.float('lobe0Scale'),
87
+ pb.float('lobe1Scale')
88
+ ], function() {
89
+ this.$l.fade = pb.clamp(pb.mul(pb.sub(this.opacity, OPACITY_THRESHOLD_EPS), 10), 0, 1);
90
+ this.$l.scale0 = pb.mix(pb.float(1), this.lobe0Scale, this.fade);
91
+ this.$l.scale1 = pb.mix(pb.float(1), this.lobe1Scale, this.fade);
92
+ this.$return(pb.vec2(pb.max(pb.clamp(pb.mul(this.roughness, this.scale0), 0, 1), 0.02), pb.clamp(pb.mul(this.roughness, this.scale1), 0, 1)));
93
+ });
94
+ return pb.getGlobalScope()[funcName](roughness, opacity, lobe0Scale, lobe1Scale);
95
+ }
96
+ /**
97
+ * Dual-lobe GGX specular for skin.
98
+ *
99
+ * @param scope - Shader scope.
100
+ * @param NoH - dot(normal, halfVector).
101
+ * @param NoV - dot(normal, viewDir).
102
+ * @param NoL - dot(normal, lightDir).
103
+ * @param VoH - dot(viewDir, halfVector).
104
+ * @param lobeRoughness - `vec2` of the two lobe roughnesses.
105
+ * @param lobeMix - Blend between the narrow and wide lobe.
106
+ * @param F0 - Specular colour at normal incidence.
107
+ * @returns vec3 specular contribution; the caller applies light colour and `NoL`.
108
+ *
109
+ * @internal
110
+ */ function skinDualLobeSpecular(scope, NoH, NoV, NoL, VoH, lobeRoughness, lobeMix, F0) {
111
+ const pb = scope.$builder;
112
+ const funcName = 'lib_skinDualLobeSpecular';
113
+ pb.func(funcName, [
114
+ pb.float('NoH'),
115
+ pb.float('NoV'),
116
+ pb.float('NoL'),
117
+ pb.float('VoH'),
118
+ pb.vec2('lobeRoughness'),
119
+ pb.float('lobeMix'),
120
+ pb.float('F0')
121
+ ], function() {
122
+ this.$l.a0 = pb.mul(this.lobeRoughness.x, this.lobeRoughness.x);
123
+ this.$l.a1 = pb.mul(this.lobeRoughness.y, this.lobeRoughness.y);
124
+ this.$l.avgRoughness = pb.mix(this.lobeRoughness.x, this.lobeRoughness.y, this.lobeMix);
125
+ this.$l.avgAlpha = pb.mul(this.avgRoughness, this.avgRoughness);
126
+ this.$l.D = pb.mix(distributionGGX(this, this.NoH, this.a0), distributionGGX(this, this.NoH, this.a1), this.lobeMix);
127
+ this.$l.Vis = visGGX(this, this.NoV, this.NoL, this.avgAlpha);
128
+ this.$l.F = fresnelSchlick(this, this.VoH, pb.vec3(this.F0), pb.vec3(1));
129
+ this.$return(pb.mul(this.F, pb.mul(this.D, this.Vis)));
130
+ });
131
+ return pb.getGlobalScope()[funcName](NoH, NoV, NoL, VoH, lobeRoughness, lobeMix, F0);
132
+ }
133
+ /**
134
+ * Fetches one column of a profile row from the packed table.
135
+ *
136
+ * @remarks
137
+ * The table is `rgba32f`, hence `unfilterable-float` on WebGPU: the sampler must
138
+ * be non-filtering, so this is an exact texel fetch and anything wanting
139
+ * interpolation between columns has to lerp two fetches by hand.
140
+ *
141
+ * Emitted inline rather than behind a shader function: on WebGPU a texture
142
+ * parameter needs its sampler passed alongside it, and `textureSampleLevel` on
143
+ * the parameter alone compiles to nothing usable.
144
+ *
145
+ * @param scope - Shader scope.
146
+ * @param tex - The packed profile table, as declared in the caller's scope.
147
+ * @param texelSize - `vec2(1 / columns, 1 / rows)`.
148
+ * @param row - Precomputed `v` coordinate of the profile's row.
149
+ * @param column - Column to read, as a float.
150
+ * @returns The `vec4` stored at that column.
151
+ *
152
+ * @internal
153
+ */ function readSSSProfileColumn(scope, tex, texelSize, row, column) {
154
+ const pb = scope.$builder;
155
+ return pb.textureSampleLevel(tex, pb.vec2(pb.mul(pb.add(column, 0.5), texelSize.x), row), 0);
156
+ }
157
+ /**
158
+ * Back-lit subsurface transmission.
159
+ *
160
+ * @param scope - Shader scope.
161
+ * @param profileTex - The packed profile table.
162
+ * @param profileTexelSize - `vec2(1 / columns, 1 / rows)` of that table.
163
+ * @param profileId - Normalized profile id.
164
+ * @param thickness - Encoded optical depth from the thickness pass, where 1
165
+ * means "nothing in the way".
166
+ * @param normal - Shading normal.
167
+ * @param viewVec - Unit vector from the surface towards the eye.
168
+ * @param lightDir - Unit vector from the surface towards the light.
169
+ * @returns vec3 transmitted radiance; the caller applies light colour,
170
+ * attenuation and the transmission shadow.
171
+ *
172
+ * @internal
173
+ */ function skinTransmission(scope, profileTex, profileTexelSize, profileId, thickness, normal, viewVec, lightDir) {
174
+ const pb = scope.$builder;
175
+ const lutOffset = SSSProfile.transmissionLutOffset;
176
+ const lutSize = SSSProfile.transmissionLutSize;
177
+ const lastLutColumn = lutOffset + lutSize - 1;
178
+ // Table reads stay inline (see readSSSProfileColumn); the locals are prefixed
179
+ // so they cannot collide with the caller's. Rows are addressed by the profile
180
+ // id, which arrives normalized because it rides in an 8-bit channel.
181
+ scope.$l.zSkinTrRow = pb.mul(pb.add(pb.mul(pb.clamp(profileId, 0, 1), 255), 0.5), profileTexelSize.y);
182
+ // GetTransmissionProfile. The index is `opticalDepth / MAX * (size - 1)` and
183
+ // the decode is `opticalDepth = (1 - thickness) * MAX`, so the MAX cancels and
184
+ // the encoded thickness maps onto the table directly.
185
+ scope.$l.zSkinTrIndex = pb.mul(pb.clamp(pb.sub(1, thickness), 0, 1), lutSize - 1);
186
+ scope.$l.zSkinTrI0 = pb.floor(scope.zSkinTrIndex);
187
+ scope.$l.zSkinTrC0 = pb.add(scope.zSkinTrI0, lutOffset);
188
+ scope.$l.zSkinTrC1 = pb.min(pb.add(scope.zSkinTrC0, 1), lastLutColumn);
189
+ scope.$l.zSkinTrProfile = pb.mix(readSSSProfileColumn(scope, profileTex, profileTexelSize, scope.zSkinTrRow, scope.zSkinTrC0).rgb, readSSSProfileColumn(scope, profileTex, profileTexelSize, scope.zSkinTrRow, scope.zSkinTrC1).rgb, pb.sub(scope.zSkinTrIndex, scope.zSkinTrI0));
190
+ // (extinctionScale, normalScale, scatteringDistribution, 1 / ior)
191
+ scope.$l.zSkinTrParams = readSSSProfileColumn(scope, profileTex, profileTexelSize, scope.zSkinTrRow, pb.float(SSSProfile.transmissionParamColumn));
192
+ return skinTransmissionPhase(scope, scope.zSkinTrProfile, scope.zSkinTrParams, thickness, normal, viewVec, lightDir);
193
+ }
194
+ /**
195
+ * The part of the transmission BxDF that touches no textures.
196
+ *
197
+ * @remarks
198
+ * Split out so the math can live behind a shader function while the table reads
199
+ * stay inline at the call site, where the sampler is in scope.
200
+ *
201
+ * @param scope - Shader scope.
202
+ * @param profile - The interpolated transmission profile, `rgb`.
203
+ * @param params - `(extinctionScale, normalScale, scatteringDistribution, 1 / ior)`.
204
+ * @param thickness - The raw encoding, still needed to spot the "no data" sentinel.
205
+ * @param normal - Shading normal.
206
+ * @param viewVec - Unit vector from the surface towards the eye.
207
+ * @param lightDir - Unit vector from the surface towards the light.
208
+ * @returns vec3 transmitted radiance.
209
+ *
210
+ * @internal
211
+ */ function skinTransmissionPhase(scope, profile, params, thickness, normal, viewVec, lightDir) {
212
+ const pb = scope.$builder;
213
+ const funcName = 'lib_skinTransmissionPhase';
214
+ pb.func(funcName, [
215
+ pb.vec3('profile'),
216
+ pb.vec4('params'),
217
+ pb.float('thickness'),
218
+ pb.vec3('normal'),
219
+ pb.vec3('viewVec'),
220
+ pb.vec3('lightDir')
221
+ ], function() {
222
+ // "No data" must be rejected rather than decoded: it decodes to zero
223
+ // optical depth, the *most* transmissive entry, so letting it through lights
224
+ // the subject from behind with a light that was never behind it. The
225
+ // threshold sits in the gap between the largest encoding the pass can write
226
+ // and the sentinel, so it clips no real measurement.
227
+ this.$if(pb.greaterThan(this.thickness, 0.5 * (1 + SKIN_TRANSMISSION_NO_DATA_ENCODING)), function() {
228
+ this.$return(pb.vec3(0));
229
+ });
230
+ this.$l.refracV = pb.refract(this.viewVec, pb.neg(this.normal), this.params.w);
231
+ this.$l.cosJ = pb.dot(pb.neg(this.lightDir), this.refracV);
232
+ this.$l.g = this.params.z;
233
+ this.$l.g2 = pb.mul(this.g, this.g);
234
+ this.$l.gcos = pb.sub(1, pb.mul(this.g, this.cosJ));
235
+ this.$l.gcos2 = pb.mul(this.gcos, this.gcos);
236
+ this.$l.phase = pb.div(pb.mul(0.5, pb.sub(1, this.g2)), pb.max(this.gcos2, 1e-5));
237
+ this.$return(pb.mul(this.profile, this.phase));
238
+ });
239
+ return pb.getGlobalScope()[funcName](profile, params, thickness, normal, viewVec, lightDir);
240
+ }
241
+
242
+ export { skinDiffuseBRDF, skinDualLobeSpecular, skinDualSpecularRoughness, skinSpecularEnergyTerms, skinTransmission };
243
+ //# sourceMappingURL=skin_brdf.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skin_brdf.js","sources":["../../src/shaders/skin_brdf.ts"],"sourcesContent":["import type { PBInsideFunctionScope, PBShaderExp } from '@zephyr3d/device';\r\nimport { distributionGGX, fresnelSchlick, visGGX } from './pbr';\r\nimport { SKIN_TRANSMISSION_NO_DATA_ENCODING, SSSProfile } from '../material/sssprofile';\r\n\r\n/** Opacity below which the dual-lobe specular fades back to a single lobe. */\r\nconst OPACITY_THRESHOLD_EPS = 0.1;\r\n\r\n/**\r\n * Multiple-scattering energy terms for a GGX specular lobe.\r\n *\r\n * @param scope - Shader scope.\r\n * @param roughness - Roughness of the lobe being corrected.\r\n * @param NoV - Clamped dot(normal, viewDir).\r\n * @param F0 - Fresnel reflectance at normal incidence.\r\n * @returns `vec2(W, A)`: specular gain and reflected share.\r\n *\r\n * @internal\r\n */\r\nexport function skinSpecularEnergyTerms(\r\n scope: PBInsideFunctionScope,\r\n roughness: PBShaderExp,\r\n NoV: PBShaderExp,\r\n F0: PBShaderExp\r\n): PBShaderExp {\r\n const pb = scope.$builder;\r\n const funcName = 'lib_skinSpecularEnergyTerms';\r\n pb.func(funcName, [pb.float('roughness'), pb.float('NoV'), pb.float('F0')], function () {\r\n this.$l.r = pb.max(this.roughness, 1e-3);\r\n this.$l.c = pb.max(this.NoV, 1e-3);\r\n this.$l.E = pb.sub(\r\n 1,\r\n pb.clamp(\r\n pb.mul(\r\n pb.pow(this.r, pb.div(this.c, this.r)),\r\n pb.div(pb.add(pb.mul(this.r, this.c), 0.0266916), pb.add(0.466495, this.c))\r\n ),\r\n 0,\r\n 1\r\n )\r\n );\r\n this.E = pb.max(this.E, 1e-4);\r\n this.$l.oneMinusC = pb.sub(1, this.c);\r\n this.$l.pow5 = pb.mul(\r\n pb.mul(this.oneMinusC, this.oneMinusC),\r\n pb.mul(this.oneMinusC, this.oneMinusC),\r\n this.oneMinusC\r\n );\r\n this.$l.Ef = pb.mul(\r\n this.pow5,\r\n pb.pow(pb.add(pb.mul(2.36651, pb.pow(this.c, pb.mul(4.7703, this.r))), 0.0387332), this.r)\r\n );\r\n this.$l.F90 = pb.clamp(pb.mul(50, this.F0), 0, 1);\r\n this.$l.W = pb.add(1, pb.mul(this.F0, pb.div(pb.sub(1, this.E), this.E)));\r\n this.$l.A = pb.mul(this.W, pb.add(pb.mul(this.E, this.F0), pb.mul(this.Ef, pb.sub(this.F90, this.F0))));\r\n this.$return(pb.vec2(this.W, pb.clamp(this.A, 0, 1)));\r\n });\r\n return pb.getGlobalScope()[funcName](roughness, NoV, F0) as PBShaderExp;\r\n}\r\n\r\n/**\r\n * Burley diffuse BRDF.\r\n *\r\n * @param scope - Shader scope.\r\n * @param NdotV - Clamped dot(normal, viewDir).\r\n * @param NdotL - Clamped dot(normal, lightDir).\r\n * @param VdotH - dot(viewDir, halfVector).\r\n * @param roughness - Material roughness.\r\n * @returns Scalar diffuse BRDF value; the caller applies albedo and `NoL`.\r\n *\r\n * @internal\r\n */\r\nexport function skinDiffuseBRDF(\r\n scope: PBInsideFunctionScope,\r\n NdotV: PBShaderExp,\r\n NdotL: PBShaderExp,\r\n VdotH: PBShaderExp,\r\n roughness: PBShaderExp\r\n): PBShaderExp {\r\n const pb = scope.$builder;\r\n const funcName = 'lib_skinDiffuseBurley';\r\n pb.func(\r\n funcName,\r\n [pb.float('NdotV'), pb.float('NdotL'), pb.float('VdotH'), pb.float('roughness')],\r\n function () {\r\n this.$l.fd90 = pb.add(0.5, pb.mul(2, this.VdotH, this.VdotH, this.roughness));\r\n this.$l.fd90m1 = pb.sub(this.fd90, 1);\r\n this.$l.oneMinusNoV = pb.sub(1, this.NdotV);\r\n this.$l.pow5V = pb.mul(\r\n pb.mul(this.oneMinusNoV, this.oneMinusNoV),\r\n pb.mul(this.oneMinusNoV, this.oneMinusNoV),\r\n this.oneMinusNoV\r\n );\r\n this.$l.oneMinusNoL = pb.sub(1, this.NdotL);\r\n this.$l.pow5L = pb.mul(\r\n pb.mul(this.oneMinusNoL, this.oneMinusNoL),\r\n pb.mul(this.oneMinusNoL, this.oneMinusNoL),\r\n this.oneMinusNoL\r\n );\r\n this.$l.fdV = pb.add(1, pb.mul(this.fd90m1, this.pow5V));\r\n this.$l.fdL = pb.add(1, pb.mul(this.fd90m1, this.pow5L));\r\n this.$return(pb.mul(1 / Math.PI, this.fdV, this.fdL));\r\n }\r\n );\r\n return pb.getGlobalScope()[funcName](NdotV, NdotL, VdotH, roughness) as PBShaderExp;\r\n}\r\n\r\n/**\r\n * Resolves the two specular lobe roughnesses from the profile.\r\n *\r\n * @param scope - Shader scope.\r\n * @param roughness - Material roughness.\r\n * @param opacity - Subsurface opacity, used to fade the effect out.\r\n * @param lobe0Scale - Profile roughness multiplier for the narrow lobe.\r\n * @param lobe1Scale - Profile roughness multiplier for the wide lobe.\r\n * @returns `vec2(lobe0Roughness, lobe1Roughness)`.\r\n *\r\n * @internal\r\n */\r\nexport function skinDualSpecularRoughness(\r\n scope: PBInsideFunctionScope,\r\n roughness: PBShaderExp,\r\n opacity: PBShaderExp,\r\n lobe0Scale: PBShaderExp,\r\n lobe1Scale: PBShaderExp\r\n): PBShaderExp {\r\n const pb = scope.$builder;\r\n const funcName = 'lib_skinDualSpecularRoughness';\r\n pb.func(\r\n funcName,\r\n [pb.float('roughness'), pb.float('opacity'), pb.float('lobe0Scale'), pb.float('lobe1Scale')],\r\n function () {\r\n this.$l.fade = pb.clamp(pb.mul(pb.sub(this.opacity, OPACITY_THRESHOLD_EPS), 10), 0, 1);\r\n this.$l.scale0 = pb.mix(pb.float(1), this.lobe0Scale, this.fade);\r\n this.$l.scale1 = pb.mix(pb.float(1), this.lobe1Scale, this.fade);\r\n this.$return(\r\n pb.vec2(\r\n pb.max(pb.clamp(pb.mul(this.roughness, this.scale0), 0, 1), 0.02),\r\n pb.clamp(pb.mul(this.roughness, this.scale1), 0, 1)\r\n )\r\n );\r\n }\r\n );\r\n return pb.getGlobalScope()[funcName](roughness, opacity, lobe0Scale, lobe1Scale) as PBShaderExp;\r\n}\r\n\r\n/**\r\n * Dual-lobe GGX specular for skin.\r\n *\r\n * @param scope - Shader scope.\r\n * @param NoH - dot(normal, halfVector).\r\n * @param NoV - dot(normal, viewDir).\r\n * @param NoL - dot(normal, lightDir).\r\n * @param VoH - dot(viewDir, halfVector).\r\n * @param lobeRoughness - `vec2` of the two lobe roughnesses.\r\n * @param lobeMix - Blend between the narrow and wide lobe.\r\n * @param F0 - Specular colour at normal incidence.\r\n * @returns vec3 specular contribution; the caller applies light colour and `NoL`.\r\n *\r\n * @internal\r\n */\r\nexport function skinDualLobeSpecular(\r\n scope: PBInsideFunctionScope,\r\n NoH: PBShaderExp,\r\n NoV: PBShaderExp,\r\n NoL: PBShaderExp,\r\n VoH: PBShaderExp,\r\n lobeRoughness: PBShaderExp,\r\n lobeMix: PBShaderExp,\r\n F0: PBShaderExp\r\n): PBShaderExp {\r\n const pb = scope.$builder;\r\n const funcName = 'lib_skinDualLobeSpecular';\r\n pb.func(\r\n funcName,\r\n [\r\n pb.float('NoH'),\r\n pb.float('NoV'),\r\n pb.float('NoL'),\r\n pb.float('VoH'),\r\n pb.vec2('lobeRoughness'),\r\n pb.float('lobeMix'),\r\n pb.float('F0')\r\n ],\r\n function () {\r\n this.$l.a0 = pb.mul(this.lobeRoughness.x, this.lobeRoughness.x);\r\n this.$l.a1 = pb.mul(this.lobeRoughness.y, this.lobeRoughness.y);\r\n this.$l.avgRoughness = pb.mix(this.lobeRoughness.x, this.lobeRoughness.y, this.lobeMix);\r\n this.$l.avgAlpha = pb.mul(this.avgRoughness, this.avgRoughness);\r\n this.$l.D = pb.mix(\r\n distributionGGX(this, this.NoH, this.a0),\r\n distributionGGX(this, this.NoH, this.a1),\r\n this.lobeMix\r\n );\r\n this.$l.Vis = visGGX(this, this.NoV, this.NoL, this.avgAlpha);\r\n this.$l.F = fresnelSchlick(this, this.VoH, pb.vec3(this.F0), pb.vec3(1));\r\n this.$return(pb.mul(this.F, pb.mul(this.D, this.Vis)));\r\n }\r\n );\r\n return pb.getGlobalScope()[funcName](NoH, NoV, NoL, VoH, lobeRoughness, lobeMix, F0) as PBShaderExp;\r\n}\r\n\r\n/**\r\n * Fetches one column of a profile row from the packed table.\r\n *\r\n * @remarks\r\n * The table is `rgba32f`, hence `unfilterable-float` on WebGPU: the sampler must\r\n * be non-filtering, so this is an exact texel fetch and anything wanting\r\n * interpolation between columns has to lerp two fetches by hand.\r\n *\r\n * Emitted inline rather than behind a shader function: on WebGPU a texture\r\n * parameter needs its sampler passed alongside it, and `textureSampleLevel` on\r\n * the parameter alone compiles to nothing usable.\r\n *\r\n * @param scope - Shader scope.\r\n * @param tex - The packed profile table, as declared in the caller's scope.\r\n * @param texelSize - `vec2(1 / columns, 1 / rows)`.\r\n * @param row - Precomputed `v` coordinate of the profile's row.\r\n * @param column - Column to read, as a float.\r\n * @returns The `vec4` stored at that column.\r\n *\r\n * @internal\r\n */\r\nfunction readSSSProfileColumn(\r\n scope: PBInsideFunctionScope,\r\n tex: PBShaderExp,\r\n texelSize: PBShaderExp,\r\n row: PBShaderExp,\r\n column: PBShaderExp\r\n): PBShaderExp {\r\n const pb = scope.$builder;\r\n return pb.textureSampleLevel(tex, pb.vec2(pb.mul(pb.add(column, 0.5), texelSize.x), row), 0);\r\n}\r\n\r\n/**\r\n * Back-lit subsurface transmission.\r\n *\r\n * @param scope - Shader scope.\r\n * @param profileTex - The packed profile table.\r\n * @param profileTexelSize - `vec2(1 / columns, 1 / rows)` of that table.\r\n * @param profileId - Normalized profile id.\r\n * @param thickness - Encoded optical depth from the thickness pass, where 1\r\n * means \"nothing in the way\".\r\n * @param normal - Shading normal.\r\n * @param viewVec - Unit vector from the surface towards the eye.\r\n * @param lightDir - Unit vector from the surface towards the light.\r\n * @returns vec3 transmitted radiance; the caller applies light colour,\r\n * attenuation and the transmission shadow.\r\n *\r\n * @internal\r\n */\r\nexport function skinTransmission(\r\n scope: PBInsideFunctionScope,\r\n profileTex: PBShaderExp,\r\n profileTexelSize: PBShaderExp,\r\n profileId: PBShaderExp,\r\n thickness: PBShaderExp,\r\n normal: PBShaderExp,\r\n viewVec: PBShaderExp,\r\n lightDir: PBShaderExp\r\n): PBShaderExp {\r\n const pb = scope.$builder;\r\n const lutOffset = SSSProfile.transmissionLutOffset;\r\n const lutSize = SSSProfile.transmissionLutSize;\r\n const lastLutColumn = lutOffset + lutSize - 1;\r\n // Table reads stay inline (see readSSSProfileColumn); the locals are prefixed\r\n // so they cannot collide with the caller's. Rows are addressed by the profile\r\n // id, which arrives normalized because it rides in an 8-bit channel.\r\n scope.$l.zSkinTrRow = pb.mul(pb.add(pb.mul(pb.clamp(profileId, 0, 1), 255), 0.5), profileTexelSize.y);\r\n // GetTransmissionProfile. The index is `opticalDepth / MAX * (size - 1)` and\r\n // the decode is `opticalDepth = (1 - thickness) * MAX`, so the MAX cancels and\r\n // the encoded thickness maps onto the table directly.\r\n scope.$l.zSkinTrIndex = pb.mul(pb.clamp(pb.sub(1, thickness), 0, 1), lutSize - 1);\r\n scope.$l.zSkinTrI0 = pb.floor(scope.zSkinTrIndex);\r\n scope.$l.zSkinTrC0 = pb.add(scope.zSkinTrI0, lutOffset);\r\n scope.$l.zSkinTrC1 = pb.min(pb.add(scope.zSkinTrC0, 1), lastLutColumn);\r\n scope.$l.zSkinTrProfile = pb.mix(\r\n readSSSProfileColumn(scope, profileTex, profileTexelSize, scope.zSkinTrRow, scope.zSkinTrC0).rgb,\r\n readSSSProfileColumn(scope, profileTex, profileTexelSize, scope.zSkinTrRow, scope.zSkinTrC1).rgb,\r\n pb.sub(scope.zSkinTrIndex, scope.zSkinTrI0)\r\n );\r\n // (extinctionScale, normalScale, scatteringDistribution, 1 / ior)\r\n scope.$l.zSkinTrParams = readSSSProfileColumn(\r\n scope,\r\n profileTex,\r\n profileTexelSize,\r\n scope.zSkinTrRow,\r\n pb.float(SSSProfile.transmissionParamColumn)\r\n );\r\n return skinTransmissionPhase(\r\n scope,\r\n scope.zSkinTrProfile,\r\n scope.zSkinTrParams,\r\n thickness,\r\n normal,\r\n viewVec,\r\n lightDir\r\n );\r\n}\r\n\r\n/**\r\n * The part of the transmission BxDF that touches no textures.\r\n *\r\n * @remarks\r\n * Split out so the math can live behind a shader function while the table reads\r\n * stay inline at the call site, where the sampler is in scope.\r\n *\r\n * @param scope - Shader scope.\r\n * @param profile - The interpolated transmission profile, `rgb`.\r\n * @param params - `(extinctionScale, normalScale, scatteringDistribution, 1 / ior)`.\r\n * @param thickness - The raw encoding, still needed to spot the \"no data\" sentinel.\r\n * @param normal - Shading normal.\r\n * @param viewVec - Unit vector from the surface towards the eye.\r\n * @param lightDir - Unit vector from the surface towards the light.\r\n * @returns vec3 transmitted radiance.\r\n *\r\n * @internal\r\n */\r\nfunction skinTransmissionPhase(\r\n scope: PBInsideFunctionScope,\r\n profile: PBShaderExp,\r\n params: PBShaderExp,\r\n thickness: PBShaderExp,\r\n normal: PBShaderExp,\r\n viewVec: PBShaderExp,\r\n lightDir: PBShaderExp\r\n): PBShaderExp {\r\n const pb = scope.$builder;\r\n const funcName = 'lib_skinTransmissionPhase';\r\n pb.func(\r\n funcName,\r\n [\r\n pb.vec3('profile'),\r\n pb.vec4('params'),\r\n pb.float('thickness'),\r\n pb.vec3('normal'),\r\n pb.vec3('viewVec'),\r\n pb.vec3('lightDir')\r\n ],\r\n function () {\r\n // \"No data\" must be rejected rather than decoded: it decodes to zero\r\n // optical depth, the *most* transmissive entry, so letting it through lights\r\n // the subject from behind with a light that was never behind it. The\r\n // threshold sits in the gap between the largest encoding the pass can write\r\n // and the sentinel, so it clips no real measurement.\r\n this.$if(pb.greaterThan(this.thickness, 0.5 * (1 + SKIN_TRANSMISSION_NO_DATA_ENCODING)), function () {\r\n this.$return(pb.vec3(0));\r\n });\r\n this.$l.refracV = pb.refract(this.viewVec, pb.neg(this.normal), this.params.w);\r\n this.$l.cosJ = pb.dot(pb.neg(this.lightDir), this.refracV);\r\n this.$l.g = this.params.z;\r\n this.$l.g2 = pb.mul(this.g, this.g);\r\n this.$l.gcos = pb.sub(1, pb.mul(this.g, this.cosJ));\r\n this.$l.gcos2 = pb.mul(this.gcos, this.gcos);\r\n this.$l.phase = pb.div(pb.mul(0.5, pb.sub(1, this.g2)), pb.max(this.gcos2, 1e-5));\r\n this.$return(pb.mul(this.profile, this.phase));\r\n }\r\n );\r\n return pb.getGlobalScope()[funcName](profile, params, thickness, normal, viewVec, lightDir) as PBShaderExp;\r\n}\r\n"],"names":["OPACITY_THRESHOLD_EPS","skinSpecularEnergyTerms","scope","roughness","NoV","F0","pb","$builder","funcName","func","float","$l","r","max","c","E","sub","clamp","mul","pow","div","add","oneMinusC","pow5","Ef","F90","W","A","$return","vec2","getGlobalScope","skinDiffuseBRDF","NdotV","NdotL","VdotH","fd90","fd90m1","oneMinusNoV","pow5V","oneMinusNoL","pow5L","fdV","fdL","Math","PI","skinDualSpecularRoughness","opacity","lobe0Scale","lobe1Scale","fade","scale0","mix","scale1","skinDualLobeSpecular","NoH","NoL","VoH","lobeRoughness","lobeMix","a0","x","a1","y","avgRoughness","avgAlpha","D","distributionGGX","Vis","visGGX","F","fresnelSchlick","vec3","readSSSProfileColumn","tex","texelSize","row","column","textureSampleLevel","skinTransmission","profileTex","profileTexelSize","profileId","thickness","normal","viewVec","lightDir","lutOffset","SSSProfile","transmissionLutOffset","lutSize","transmissionLutSize","lastLutColumn","zSkinTrRow","zSkinTrIndex","zSkinTrI0","floor","zSkinTrC0","zSkinTrC1","min","zSkinTrProfile","rgb","zSkinTrParams","transmissionParamColumn","skinTransmissionPhase","profile","params","vec4","$if","greaterThan","SKIN_TRANSMISSION_NO_DATA_ENCODING","refracV","refract","neg","w","cosJ","dot","g","z","g2","gcos","gcos2","phase"],"mappings":";;;AAIA,+EACA,MAAMA,qBAAwB,GAAA,GAAA;AAE9B;;;;;;;;;;IAWO,SAASC,uBACdC,CAAAA,KAA4B,EAC5BC,SAAsB,EACtBC,GAAgB,EAChBC,EAAe,EAAA;IAEf,MAAMC,EAAAA,GAAKJ,MAAMK,QAAQ;AACzB,IAAA,MAAMC,QAAW,GAAA,6BAAA;IACjBF,EAAGG,CAAAA,IAAI,CAACD,QAAU,EAAA;AAACF,QAAAA,EAAAA,CAAGI,KAAK,CAAC,WAAA,CAAA;AAAcJ,QAAAA,EAAAA,CAAGI,KAAK,CAAC,KAAA,CAAA;AAAQJ,QAAAA,EAAAA,CAAGI,KAAK,CAAC,IAAA;KAAM,EAAE,WAAA;QAC1E,IAAI,CAACC,EAAE,CAACC,CAAC,GAAGN,EAAGO,CAAAA,GAAG,CAAC,IAAI,CAACV,SAAS,EAAE,IAAA,CAAA;QACnC,IAAI,CAACQ,EAAE,CAACG,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,CAAAA,GAAG,CAAC,IAAI,CAACkG,CAAC,EAAE,IAAI,CAACA,CAAC,CAAA;AAClC,QAAA,IAAI,CAACzG,EAAE,CAAC4G,IAAI,GAAGjH,EAAAA,CAAGU,GAAG,CAAC,CAAA,EAAGV,EAAGY,CAAAA,GAAG,CAAC,IAAI,CAACkG,CAAC,EAAE,IAAI,CAACF,IAAI,CAAA,CAAA;AACjD,QAAA,IAAI,CAACvG,EAAE,CAAC6G,KAAK,GAAGlH,EAAGY,CAAAA,GAAG,CAAC,IAAI,CAACqG,IAAI,EAAE,IAAI,CAACA,IAAI,CAAA;QAC3C,IAAI,CAAC5G,EAAE,CAAC8G,KAAK,GAAGnH,EAAGc,CAAAA,GAAG,CAACd,EAAAA,CAAGY,GAAG,CAAC,GAAKZ,EAAAA,EAAAA,CAAGU,GAAG,CAAC,CAAA,EAAG,IAAI,CAACsG,EAAE,CAAA,CAAA,EAAIhH,EAAGO,CAAAA,GAAG,CAAC,IAAI,CAAC2G,KAAK,EAAE,IAAA,CAAA,CAAA;AAC3E,QAAA,IAAI,CAAC5F,OAAO,CAACtB,EAAAA,CAAGY,GAAG,CAAC,IAAI,CAACsF,OAAO,EAAE,IAAI,CAACiB,KAAK,CAAA,CAAA;AAC9C,KAAA,CAAA;IAEF,OAAOnH,EAAAA,CAAGwB,cAAc,EAAE,CAACtB,QAAAA,CAAS,CAACgG,OAASC,EAAAA,MAAAA,EAAQvB,SAAWC,EAAAA,MAAAA,EAAQC,OAASC,EAAAA,QAAAA,CAAAA;AACpF;;;;"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Animated interleaved-gradient-noise pair used to decorrelate SSGI rays.
3
+ *
4
+ * Produces two low-discrepancy random numbers in [0, 1) for a given fragment,
5
+ * advanced per sample/frame through golden-ratio sequences so the temporal
6
+ * resolve pass converges the Monte-Carlo estimate.
7
+ *
8
+ * @param scope - The shader scope
9
+ * @param fragCoord - Fragment coordinate in pixels
10
+ * @param seed - Sequence index (frameIndex * sampleCount + sampleIndex)
11
+ * @returns A vec2 of pseudo random numbers in [0, 1)
12
+ *
13
+ * @internal
14
+ */ function SSGI_rand2(scope, fragCoord, seed) {
15
+ const pb = scope.$builder;
16
+ pb.func('SSGI_ign', [
17
+ pb.vec2('p')
18
+ ], function() {
19
+ this.$return(pb.fract(pb.mul(52.9829189, pb.fract(pb.add(pb.mul(0.06711056, this.p.x), pb.mul(0.00583715, this.p.y))))));
20
+ });
21
+ pb.func('SSGI_rand2', [
22
+ pb.vec2('fragCoord'),
23
+ pb.float('seed')
24
+ ], function() {
25
+ this.$l.n1 = this.SSGI_ign(this.fragCoord);
26
+ this.$l.n2 = this.SSGI_ign(pb.add(this.fragCoord, pb.vec2(5.588238, 5.588238)));
27
+ // Golden-ratio (and its square) sequences advance the pair every sample
28
+ this.$return(pb.fract(pb.add(pb.vec2(this.n1, this.n2), pb.mul(pb.vec2(0.61803398875, 0.38196601125), this.seed))));
29
+ });
30
+ return scope.SSGI_rand2(fragCoord, seed);
31
+ }
32
+ /**
33
+ * Cosine-weighted hemisphere sampling around a normal.
34
+ *
35
+ * With cosine-weighted sampling the Monte-Carlo estimator of the rendering
36
+ * equation's diffuse term reduces to the plain average of the sampled
37
+ * radiances, so the SSGI trace pass can simply accumulate hit colors.
38
+ *
39
+ * @param scope - The shader scope
40
+ * @param normal - Unit normal the hemisphere is oriented around
41
+ * @param rand - Two random numbers in [0, 1)
42
+ * @returns A unit direction inside the hemisphere
43
+ *
44
+ * @internal
45
+ */ function SSGI_cosineSampleHemisphere(scope, normal, rand) {
46
+ const pb = scope.$builder;
47
+ pb.func('SSGI_cosineSampleHemisphere', [
48
+ pb.vec3('n'),
49
+ pb.vec2('u')
50
+ ], function() {
51
+ this.$l.up = this.$choice(pb.lessThan(pb.abs(this.n.z), 0.999), pb.vec3(0, 0, 1), pb.vec3(1, 0, 0));
52
+ this.$l.tangent = pb.normalize(pb.cross(this.up, this.n));
53
+ this.$l.bitangent = pb.cross(this.n, this.tangent);
54
+ this.$l.r = pb.sqrt(this.u.x);
55
+ this.$l.phi = pb.mul(this.u.y, Math.PI * 2);
56
+ this.$l.dir = pb.add(pb.mul(this.tangent, pb.mul(this.r, pb.cos(this.phi))), pb.mul(this.bitangent, pb.mul(this.r, pb.sin(this.phi))), pb.mul(this.n, pb.sqrt(pb.max(0, pb.sub(1, this.u.x)))));
57
+ this.$return(pb.normalize(this.dir));
58
+ });
59
+ return scope.SSGI_cosineSampleHemisphere(normal, rand);
60
+ }
61
+
62
+ export { SSGI_cosineSampleHemisphere, SSGI_rand2 };
63
+ //# sourceMappingURL=ssgi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ssgi.js","sources":["../../src/shaders/ssgi.ts"],"sourcesContent":["import type { PBInsideFunctionScope, PBShaderExp } from '@zephyr3d/device';\n\n/**\n * Animated interleaved-gradient-noise pair used to decorrelate SSGI rays.\n *\n * Produces two low-discrepancy random numbers in [0, 1) for a given fragment,\n * advanced per sample/frame through golden-ratio sequences so the temporal\n * resolve pass converges the Monte-Carlo estimate.\n *\n * @param scope - The shader scope\n * @param fragCoord - Fragment coordinate in pixels\n * @param seed - Sequence index (frameIndex * sampleCount + sampleIndex)\n * @returns A vec2 of pseudo random numbers in [0, 1)\n *\n * @internal\n */\nexport function SSGI_rand2(scope: PBInsideFunctionScope, fragCoord: PBShaderExp, seed: PBShaderExp) {\n const pb = scope.$builder;\n pb.func('SSGI_ign', [pb.vec2('p')], function () {\n this.$return(\n pb.fract(\n pb.mul(52.9829189, pb.fract(pb.add(pb.mul(0.06711056, this.p.x), pb.mul(0.00583715, this.p.y))))\n )\n );\n });\n pb.func('SSGI_rand2', [pb.vec2('fragCoord'), pb.float('seed')], function () {\n this.$l.n1 = this.SSGI_ign(this.fragCoord);\n this.$l.n2 = this.SSGI_ign(pb.add(this.fragCoord, pb.vec2(5.588238, 5.588238)));\n // Golden-ratio (and its square) sequences advance the pair every sample\n this.$return(\n pb.fract(pb.add(pb.vec2(this.n1, this.n2), pb.mul(pb.vec2(0.61803398875, 0.38196601125), this.seed)))\n );\n });\n return scope.SSGI_rand2(fragCoord, seed);\n}\n\n/**\n * Cosine-weighted hemisphere sampling around a normal.\n *\n * With cosine-weighted sampling the Monte-Carlo estimator of the rendering\n * equation's diffuse term reduces to the plain average of the sampled\n * radiances, so the SSGI trace pass can simply accumulate hit colors.\n *\n * @param scope - The shader scope\n * @param normal - Unit normal the hemisphere is oriented around\n * @param rand - Two random numbers in [0, 1)\n * @returns A unit direction inside the hemisphere\n *\n * @internal\n */\nexport function SSGI_cosineSampleHemisphere(\n scope: PBInsideFunctionScope,\n normal: PBShaderExp,\n rand: PBShaderExp\n) {\n const pb = scope.$builder;\n pb.func('SSGI_cosineSampleHemisphere', [pb.vec3('n'), pb.vec2('u')], function () {\n this.$l.up = this.$choice(pb.lessThan(pb.abs(this.n.z), 0.999), pb.vec3(0, 0, 1), pb.vec3(1, 0, 0));\n this.$l.tangent = pb.normalize(pb.cross(this.up, this.n));\n this.$l.bitangent = pb.cross(this.n, this.tangent);\n this.$l.r = pb.sqrt(this.u.x);\n this.$l.phi = pb.mul(this.u.y, Math.PI * 2);\n this.$l.dir = pb.add(\n pb.mul(this.tangent, pb.mul(this.r, pb.cos(this.phi))),\n pb.mul(this.bitangent, pb.mul(this.r, pb.sin(this.phi))),\n pb.mul(this.n, pb.sqrt(pb.max(0, pb.sub(1, this.u.x))))\n );\n this.$return(pb.normalize(this.dir));\n });\n return scope.SSGI_cosineSampleHemisphere(normal, rand);\n}\n"],"names":["SSGI_rand2","scope","fragCoord","seed","pb","$builder","func","vec2","$return","fract","mul","add","p","x","y","float","$l","n1","SSGI_ign","n2","SSGI_cosineSampleHemisphere","normal","rand","vec3","up","$choice","lessThan","abs","n","z","tangent","normalize","cross","bitangent","r","sqrt","u","phi","Math","PI","dir","cos","sin","max","sub"],"mappings":"AAEA;;;;;;;;;;;;;AAaC,IACM,SAASA,UAAAA,CAAWC,KAA4B,EAAEC,SAAsB,EAAEC,IAAiB,EAAA;I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AAC,CAACtB,CAAC,EAAEwB,IAAAA,CAAKC,EAAE,GAAG,CAAA,CAAA;AACzC,QAAA,IAAI,CAACvB,EAAE,CAACwB,GAAG,GAAGpC,EAAGO,CAAAA,GAAG,CAClBP,EAAAA,CAAGM,GAAG,CAAC,IAAI,CAACoB,OAAO,EAAE1B,EAAGM,CAAAA,GAAG,CAAC,IAAI,CAACwB,CAAC,EAAE9B,EAAAA,CAAGqC,GAAG,CAAC,IAAI,CAACJ,GAAG,KACnDjC,EAAGM,CAAAA,GAAG,CAAC,IAAI,CAACuB,SAAS,EAAE7B,EAAGM,CAAAA,GAAG,CAAC,IAAI,CAACwB,CAAC,EAAE9B,EAAGsC,CAAAA,GAAG,CAAC,IAAI,CAACL,GAAG,CAAA,CAAA,CAAA,EACrDjC,EAAGM,CAAAA,GAAG,CAAC,IAAI,CAACkB,CAAC,EAAExB,EAAG+B,CAAAA,IAAI,CAAC/B,EAAAA,CAAGuC,GAAG,CAAC,CAAA,EAAGvC,EAAGwC,CAAAA,GAAG,CAAC,CAAG,EAAA,IAAI,CAACR,CAAC,CAACvB,CAAC,CAAA,CAAA,CAAA,CAAA,CAAA;QAErD,IAAI,CAACL,OAAO,CAACJ,EAAAA,CAAG2B,SAAS,CAAC,IAAI,CAACS,GAAG,CAAA,CAAA;AACpC,KAAA,CAAA;IACA,OAAOvC,KAAAA,CAAMmB,2BAA2B,CAACC,MAAQC,EAAAA,IAAAA,CAAAA;AACnD;;;;"}
@@ -0,0 +1,118 @@
1
+ import { Matrix4x4 } from '@zephyr3d/base';
2
+
3
+ /**
4
+ * Shared helpers for validating SSGI temporal history across frames.
5
+ *
6
+ * SSGI stores the surface depth of a frame as that frame's view-space Z (the
7
+ * distance along the camera forward axis, in world units). Comparing such a
8
+ * value against the *current* frame's view-space Z is only meaningful while the
9
+ * camera is still: rotating the camera turns the forward axis, so a static world
10
+ * point changes its view-space Z by roughly
11
+ *
12
+ * dz ~ dTheta * viewZ * tan(halfFovX) * |ndc.x|
13
+ *
14
+ * which is zero at the screen center and grows with both depth and screen
15
+ * eccentricity. At a plain mouse-look rate that already exceeds any reasonable
16
+ * absolute tolerance for distant off-center pixels, so history gets rejected in
17
+ * screen-edge bands even though it is perfectly valid. Every consumer therefore
18
+ * has to convert the current depth into the *previous* frame's view space before
19
+ * comparing.
20
+ *
21
+ * @internal
22
+ */ /**
23
+ * Relative share of the compared depth added to the absolute tolerance. 2% keeps
24
+ * a 10m surface within 0.2m, comfortably above rgba16f depth quantization while
25
+ * still separating surfaces that a bounce should not share.
26
+ * @internal
27
+ */ const SSGI_DEPTH_TOLERANCE_SLOPE = 0.02;
28
+ /**
29
+ * `prevVP * inverse(currentVP)`: maps a current-frame clip position onto the
30
+ * previous frame's clip space, where `w` is the previous view-space Z.
31
+ *
32
+ * The current half uses the jittered inverse VP because every consumer
33
+ * reconstructs from a depth buffer that was rasterized with jitter applied.
34
+ * Jitter only shifts clip x/y, so pairing it with the unjittered `prevVPMatrix`
35
+ * still produces the correct `w`.
36
+ *
37
+ * Falls back to the current VP before any previous transform exists, which
38
+ * degenerates into comparing the current depth against itself - harmless,
39
+ * because the history textures are empty on that frame anyway.
40
+ *
41
+ * @param ctx - Current draw context
42
+ * @returns The reprojection matrix
43
+ * @internal
44
+ */ function ssgiCurrentToPrevClipMatrix(ctx) {
45
+ const camera = ctx.camera;
46
+ const prevVP = camera.prevVPMatrix ?? camera.viewProjectionMatrix;
47
+ return Matrix4x4.multiply(prevVP, camera.jitteredInvVPMatrix);
48
+ }
49
+ /**
50
+ * Converts the current frame's linear depth at `uv` into the view-space Z it
51
+ * would have had in the previous frame, so it can be compared against the depth
52
+ * stored in the SSGI surface history.
53
+ *
54
+ * `currentToPrevClipMatrix` must be `prevViewProjection * inverse(currentViewProjection)`,
55
+ * mapping a current-frame clip position onto the previous frame's clip space. In
56
+ * a perspective projection the resulting `w` is exactly the previous view-space
57
+ * Z in world units, which is the quantity the surface pass wrote.
58
+ *
59
+ * @param scope - Current shader scope
60
+ * @param currentToPrevClipMatrix - `prevVP * invCurrentVP`, as a mat4
61
+ * @param uv - Screen uv of the pixel being validated
62
+ * @param linearDepth - Normalized linear depth (viewZ / far) at `uv`
63
+ * @param nearFar - Camera near and far planes
64
+ * @returns Previous-frame view-space Z, in world units
65
+ * @internal
66
+ */ function ssgiPreviousViewDepth(scope, currentToPrevClipMatrix, uv, linearDepth, nearFar) {
67
+ const pb = scope.$builder;
68
+ const funcName = 'Z_ssgiPreviousViewDepth';
69
+ pb.func(funcName, [
70
+ pb.mat4('toPrevClip'),
71
+ pb.vec2('uv'),
72
+ pb.float('linearDepth'),
73
+ pb.vec2('nearFar')
74
+ ], function() {
75
+ // Invert the perspective depth mapping. `linearDepth` is the normalized
76
+ // viewZ / far that the depth prepass stored, so the non-linear depth is
77
+ // (near / linearDepth - far) / (near - far) - identical to the
78
+ // reconstruction in SSGI_getPosition. Operating on the normalized value
79
+ // directly matters: converting to world-unit viewZ first and reusing the
80
+ // same expression silently drops a factor of `far`, which pins every
81
+ // pixel at the far plane and rejects all history.
82
+ this.$l.safeLinearDepth = pb.max(this.linearDepth, 1e-6);
83
+ this.$l.ndcZ = pb.div(pb.sub(pb.div(this.nearFar.x, this.safeLinearDepth), this.nearFar.y), pb.sub(this.nearFar.x, this.nearFar.y));
84
+ this.$l.clipPos = pb.vec4(pb.sub(pb.mul(this.uv, 2), pb.vec2(1)), pb.sub(pb.mul(pb.clamp(this.ndcZ, 0, 1), 2), 1), 1);
85
+ // clipPos is already normalized (w = 1 after the NDC divide), so the
86
+ // reprojected w is directly the previous view-space Z.
87
+ this.$return(pb.mul(this.toPrevClip, this.clipPos).w);
88
+ });
89
+ return scope[funcName](currentToPrevClipMatrix, uv, linearDepth, nearFar);
90
+ }
91
+ /**
92
+ * Depth tolerance for a history comparison at a given depth.
93
+ *
94
+ * A single absolute tolerance cannot serve the whole depth range: it is far too
95
+ * loose next to the camera, where a few centimetres separate distinct surfaces,
96
+ * and too tight in the distance, where depth precision and residual reprojection
97
+ * error both scale with viewZ. Scaling the floor by depth keeps the test at a
98
+ * roughly constant relative strictness.
99
+ *
100
+ * @param scope - Current shader scope
101
+ * @param baseTolerance - Configured absolute tolerance, in world units
102
+ * @param viewDepth - View-space Z the comparison happens at, in world units
103
+ * @returns Effective tolerance, in world units
104
+ * @internal
105
+ */ function ssgiDepthTolerance(scope, baseTolerance, viewDepth) {
106
+ const pb = scope.$builder;
107
+ const funcName = 'Z_ssgiDepthTolerance';
108
+ pb.func(funcName, [
109
+ pb.float('baseTolerance'),
110
+ pb.float('viewDepth')
111
+ ], function() {
112
+ this.$return(pb.max(pb.max(this.baseTolerance, 1e-4), pb.mul(pb.abs(this.viewDepth), SSGI_DEPTH_TOLERANCE_SLOPE)));
113
+ });
114
+ return scope[funcName](baseTolerance, viewDepth);
115
+ }
116
+
117
+ export { SSGI_DEPTH_TOLERANCE_SLOPE, ssgiCurrentToPrevClipMatrix, ssgiDepthTolerance, ssgiPreviousViewDepth };
118
+ //# sourceMappingURL=ssgi_reprojection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ssgi_reprojection.js","sources":["../../src/shaders/ssgi_reprojection.ts"],"sourcesContent":["import { Matrix4x4 } from '@zephyr3d/base';\nimport type { PBInsideFunctionScope, PBShaderExp } from '@zephyr3d/device';\nimport type { DrawContext } from '../render/drawable';\n\n/**\n * Shared helpers for validating SSGI temporal history across frames.\n *\n * SSGI stores the surface depth of a frame as that frame's view-space Z (the\n * distance along the camera forward axis, in world units). Comparing such a\n * value against the *current* frame's view-space Z is only meaningful while the\n * camera is still: rotating the camera turns the forward axis, so a static world\n * point changes its view-space Z by roughly\n *\n * dz ~ dTheta * viewZ * tan(halfFovX) * |ndc.x|\n *\n * which is zero at the screen center and grows with both depth and screen\n * eccentricity. At a plain mouse-look rate that already exceeds any reasonable\n * absolute tolerance for distant off-center pixels, so history gets rejected in\n * screen-edge bands even though it is perfectly valid. Every consumer therefore\n * has to convert the current depth into the *previous* frame's view space before\n * comparing.\n *\n * @internal\n */\n\n/**\n * Relative share of the compared depth added to the absolute tolerance. 2% keeps\n * a 10m surface within 0.2m, comfortably above rgba16f depth quantization while\n * still separating surfaces that a bounce should not share.\n * @internal\n */\nexport const SSGI_DEPTH_TOLERANCE_SLOPE = 0.02;\n\n/**\n * `prevVP * inverse(currentVP)`: maps a current-frame clip position onto the\n * previous frame's clip space, where `w` is the previous view-space Z.\n *\n * The current half uses the jittered inverse VP because every consumer\n * reconstructs from a depth buffer that was rasterized with jitter applied.\n * Jitter only shifts clip x/y, so pairing it with the unjittered `prevVPMatrix`\n * still produces the correct `w`.\n *\n * Falls back to the current VP before any previous transform exists, which\n * degenerates into comparing the current depth against itself - harmless,\n * because the history textures are empty on that frame anyway.\n *\n * @param ctx - Current draw context\n * @returns The reprojection matrix\n * @internal\n */\nexport function ssgiCurrentToPrevClipMatrix(ctx: DrawContext): Matrix4x4 {\n const camera = ctx.camera;\n const prevVP = camera.prevVPMatrix ?? camera.viewProjectionMatrix;\n return Matrix4x4.multiply(prevVP, camera.jitteredInvVPMatrix);\n}\n\n/**\n * Converts the current frame's linear depth at `uv` into the view-space Z it\n * would have had in the previous frame, so it can be compared against the depth\n * stored in the SSGI surface history.\n *\n * `currentToPrevClipMatrix` must be `prevViewProjection * inverse(currentViewProjection)`,\n * mapping a current-frame clip position onto the previous frame's clip space. In\n * a perspective projection the resulting `w` is exactly the previous view-space\n * Z in world units, which is the quantity the surface pass wrote.\n *\n * @param scope - Current shader scope\n * @param currentToPrevClipMatrix - `prevVP * invCurrentVP`, as a mat4\n * @param uv - Screen uv of the pixel being validated\n * @param linearDepth - Normalized linear depth (viewZ / far) at `uv`\n * @param nearFar - Camera near and far planes\n * @returns Previous-frame view-space Z, in world units\n * @internal\n */\nexport function ssgiPreviousViewDepth(\n scope: PBInsideFunctionScope,\n currentToPrevClipMatrix: PBShaderExp,\n uv: PBShaderExp,\n linearDepth: PBShaderExp,\n nearFar: PBShaderExp\n): PBShaderExp {\n const pb = scope.$builder;\n const funcName = 'Z_ssgiPreviousViewDepth';\n pb.func(\n funcName,\n [pb.mat4('toPrevClip'), pb.vec2('uv'), pb.float('linearDepth'), pb.vec2('nearFar')],\n function () {\n // Invert the perspective depth mapping. `linearDepth` is the normalized\n // viewZ / far that the depth prepass stored, so the non-linear depth is\n // (near / linearDepth - far) / (near - far) - identical to the\n // reconstruction in SSGI_getPosition. Operating on the normalized value\n // directly matters: converting to world-unit viewZ first and reusing the\n // same expression silently drops a factor of `far`, which pins every\n // pixel at the far plane and rejects all history.\n this.$l.safeLinearDepth = pb.max(this.linearDepth, 1e-6);\n this.$l.ndcZ = pb.div(\n pb.sub(pb.div(this.nearFar.x, this.safeLinearDepth), this.nearFar.y),\n pb.sub(this.nearFar.x, this.nearFar.y)\n );\n this.$l.clipPos = pb.vec4(\n pb.sub(pb.mul(this.uv, 2), pb.vec2(1)),\n pb.sub(pb.mul(pb.clamp(this.ndcZ, 0, 1), 2), 1),\n 1\n );\n // clipPos is already normalized (w = 1 after the NDC divide), so the\n // reprojected w is directly the previous view-space Z.\n this.$return(pb.mul(this.toPrevClip, this.clipPos).w);\n }\n );\n return scope[funcName](currentToPrevClipMatrix, uv, linearDepth, nearFar) as PBShaderExp;\n}\n\n/**\n * Depth tolerance for a history comparison at a given depth.\n *\n * A single absolute tolerance cannot serve the whole depth range: it is far too\n * loose next to the camera, where a few centimetres separate distinct surfaces,\n * and too tight in the distance, where depth precision and residual reprojection\n * error both scale with viewZ. Scaling the floor by depth keeps the test at a\n * roughly constant relative strictness.\n *\n * @param scope - Current shader scope\n * @param baseTolerance - Configured absolute tolerance, in world units\n * @param viewDepth - View-space Z the comparison happens at, in world units\n * @returns Effective tolerance, in world units\n * @internal\n */\nexport function ssgiDepthTolerance(\n scope: PBInsideFunctionScope,\n baseTolerance: PBShaderExp,\n viewDepth: PBShaderExp\n): PBShaderExp {\n const pb = scope.$builder;\n const funcName = 'Z_ssgiDepthTolerance';\n pb.func(funcName, [pb.float('baseTolerance'), pb.float('viewDepth')], function () {\n this.$return(\n pb.max(pb.max(this.baseTolerance, 1e-4), pb.mul(pb.abs(this.viewDepth), SSGI_DEPTH_TOLERANCE_SLOPE))\n );\n });\n return scope[funcName](baseTolerance, viewDepth) as PBShaderExp;\n}\n"],"names":["SSGI_DEPTH_TOLERANCE_SLOPE","ssgiCurrentToPrevClipMatrix","ctx","camera","prevVP","prevVPMatrix","viewProjectionMatrix","Matrix4x4","multiply","jitteredInvVPMatrix","ssgiPreviousViewDepth","scope","currentToPrevClipMatrix","uv","linearDepth","nearFar","pb","$builder","funcName","func","mat4","vec2","float","$l","safeLinearDepth","max","ndcZ","div","sub","x","y","clipPos","vec4","mul","clamp","$return","toPrevClip","w","ssgiDepthTolerance","baseTolerance","viewDepth","abs"],"mappings":";;AAIA;;;;;;;;;;;;;;;;;;;;;;;;IA2BaA,MAAAA,0BAAAA,GAA6B;AAE1C;;;;;;;;;;;;;;;;IAiBO,SAASC,2BAAAA,CAA4BC,GAAgB,EAAA;IAC1D,MAAMC,MAAAA,GAASD,IAAIC,MAAM;AACzB,IAAA,MAAMC,MAASD,GAAAA,MAAAA,CAAOE,YAAY,IAAIF,OAAOG,oBAAoB;AACjE,IAAA,OAAOC,SAAUC,CAAAA,QAAQ,CAACJ,MAAAA,EAAQD,OAAOM,mBAAmB,CAAA;AAC9D;AAEA;;;;;;;;;;;;;;;;;IAkBO,SAASC,qBAAAA,CACdC,KAA4B,EAC5BC,uBAAoC,EACpCC,EAAe,EACfC,WAAwB,EACxBC,OAAoB,EAAA;IAEpB,MAAMC,EAAAA,GAAKL,MAAMM,QAAQ;AACzB,IAAA,MAAMC,QAAW,GAAA,yBAAA;IACjBF,EAAGG,CAAAA,IAAI,CACLD,QACA,EAAA;AAACF,QAAAA,EAAAA,CAAGI,IAAI,CAAC,YAAA,CAAA;AAAeJ,QAAAA,EAAAA,CAAGK,IAAI,CAAC,IAAA,CAAA;AAAOL,QAAAA,EAAAA,CAAGM,KAAK,CAAC,aAAA,CAAA;AAAgBN,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