@woosh/meep-engine 3.76.0 → 3.77.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 (233) hide show
  1. package/editor/particles/effect/ParticleReferenceSimulation.d.ts +11 -0
  2. package/editor/particles/effect/ParticleReferenceSimulation.d.ts.map +1 -1
  3. package/editor/particles/effect/ParticleReferenceSimulation.js +14 -0
  4. package/editor/view/particles/effect/ParticleGraphEditorView.js +1 -1
  5. package/package.json +1 -1
  6. package/src/engine/asset/loaders/GroomAssetLoader.d.ts +1 -1
  7. package/src/engine/asset/loaders/GroomAssetLoader.d.ts.map +1 -1
  8. package/src/engine/asset/loaders/GroomAssetLoader.js +16 -2
  9. package/src/engine/graphics/ecs/hair/Hair.d.ts +7 -0
  10. package/src/engine/graphics/ecs/hair/Hair.d.ts.map +1 -1
  11. package/src/engine/graphics/ecs/hair/Hair.js +9 -0
  12. package/src/engine/graphics/ecs/hair/HairDynamics.d.ts +63 -0
  13. package/src/engine/graphics/ecs/hair/HairDynamics.d.ts.map +1 -0
  14. package/src/engine/graphics/ecs/hair/HairDynamics.js +82 -0
  15. package/src/engine/graphics/hair/Groom.d.ts +45 -0
  16. package/src/engine/graphics/hair/Groom.d.ts.map +1 -1
  17. package/src/engine/graphics/hair/Groom.js +56 -0
  18. package/src/engine/graphics/hair/GroomSerializationAdapter.d.ts +27 -1
  19. package/src/engine/graphics/hair/GroomSerializationAdapter.d.ts.map +1 -1
  20. package/src/engine/graphics/hair/GroomSerializationAdapter.js +105 -32
  21. package/src/engine/graphics/hair/GroomSerializationUpgrader_0_1.d.ts +8 -0
  22. package/src/engine/graphics/hair/GroomSerializationUpgrader_0_1.d.ts.map +1 -0
  23. package/src/engine/graphics/hair/GroomSerializationUpgrader_0_1.js +31 -0
  24. package/src/engine/graphics/hair/groom_bind_to_mesh.d.ts +85 -0
  25. package/src/engine/graphics/hair/groom_bind_to_mesh.d.ts.map +1 -0
  26. package/src/engine/graphics/hair/groom_bind_to_mesh.js +216 -0
  27. package/src/engine/graphics/hair/groom_build_group.d.ts +7 -2
  28. package/src/engine/graphics/hair/groom_build_group.d.ts.map +1 -1
  29. package/src/engine/graphics/hair/groom_build_group.js +11 -2
  30. package/src/engine/graphics/hair/groom_build_guides.d.ts +43 -0
  31. package/src/engine/graphics/hair/groom_build_guides.d.ts.map +1 -0
  32. package/src/engine/graphics/hair/groom_build_guides.js +267 -0
  33. package/src/engine/graphics/hair/groom_root_spacing.d.ts +6 -4
  34. package/src/engine/graphics/hair/groom_root_spacing.d.ts.map +1 -1
  35. package/src/engine/graphics/hair/groom_root_spacing.js +199 -66
  36. package/src/engine/graphics3/HairColliderSystem.d.ts +59 -0
  37. package/src/engine/graphics3/HairColliderSystem.d.ts.map +1 -0
  38. package/src/engine/graphics3/HairColliderSystem.js +270 -0
  39. package/src/engine/graphics3/HairSystem.d.ts +21 -4
  40. package/src/engine/graphics3/HairSystem.d.ts.map +1 -1
  41. package/src/engine/graphics3/HairSystem.js +270 -4
  42. package/src/engine/physics/fluid/ecs/FluidObstacleSystem.d.ts +4 -4
  43. package/src/shade/assets/textures/hair_scattering.bin +0 -0
  44. package/src/shade/playground/hair/main.js +27 -4
  45. package/src/shade/playground/hair_skinned/index.html +192 -0
  46. package/src/shade/playground/hair_skinned/main.d.ts +7 -0
  47. package/src/shade/playground/hair_skinned/main.d.ts.map +1 -0
  48. package/src/shade/playground/hair_skinned/main.js +481 -0
  49. package/src/shade/playground/hair_skinned/skinned_hair.d.ts +49 -0
  50. package/src/shade/playground/hair_skinned/skinned_hair.d.ts.map +1 -0
  51. package/src/shade/playground/hair_skinned/skinned_hair.js +362 -0
  52. package/src/shade/playground/sparks/README.md +36 -0
  53. package/src/shade/playground/sparks/index.html +145 -0
  54. package/src/shade/playground/sparks/main.d.ts +7 -0
  55. package/src/shade/playground/sparks/main.d.ts.map +1 -0
  56. package/src/shade/playground/sparks/main.js +312 -0
  57. package/src/shade/playground/sparks/sparks_effect.d.ts +72 -0
  58. package/src/shade/playground/sparks/sparks_effect.d.ts.map +1 -0
  59. package/src/shade/playground/sparks/sparks_effect.js +180 -0
  60. package/src/shade/renderer/Renderer.d.ts.map +1 -1
  61. package/src/shade/renderer/Renderer.js +18 -3
  62. package/src/shade/renderer/acoustics/GPUAcousticLattice.d.ts +1 -1
  63. package/src/shade/renderer/acoustics/GPUAcousticProbes.d.ts +1 -1
  64. package/src/shade/renderer/acoustics/GPUAcoustics.d.ts +1 -1
  65. package/src/shade/renderer/animation/GPUAnimationManager.d.ts +3 -2
  66. package/src/shade/renderer/animation/GPUAnimationManager.d.ts.map +1 -1
  67. package/src/shade/renderer/animation/GPUAnimationManager.js +74 -3
  68. package/src/shade/renderer/animation/skinning/GPUMeshSkinningContext.d.ts +13 -3
  69. package/src/shade/renderer/animation/skinning/GPUMeshSkinningContext.d.ts.map +1 -1
  70. package/src/shade/renderer/animation/skinning/GPUMeshSkinningContext.js +16 -5
  71. package/src/shade/renderer/animation/skinning/shader_meshlet_apply_skinning.js +8 -8
  72. package/src/shade/renderer/deferred/chunk_shade_direct_lights.js +2 -2
  73. package/src/shade/renderer/deferred/chunk_shade_directional_lights.d.ts +4 -2
  74. package/src/shade/renderer/deferred/chunk_shade_directional_lights.d.ts.map +1 -1
  75. package/src/shade/renderer/deferred/chunk_shade_directional_lights.js +7 -3
  76. package/src/shade/renderer/deferred/chunk_standard_material_direct_light_lobe.js +1 -1
  77. package/src/shade/renderer/extension/ShadowAtlas.d.ts +75 -0
  78. package/src/shade/renderer/extension/ShadowAtlas.d.ts.map +1 -0
  79. package/src/shade/renderer/extension/ShadowAtlas.js +133 -0
  80. package/src/shade/renderer/fluid/GPUFluidCascade.d.ts +3 -3
  81. package/src/shade/renderer/fluid/GPUFluidCascadeStack.d.ts +1 -1
  82. package/src/shade/renderer/fluid/forcing/GPUFluidForcing.d.ts +7 -7
  83. package/src/shade/renderer/fluid/pressure/GPUFluidPressureSolve.d.ts +1 -1
  84. package/src/shade/renderer/fluid/query/GPUFluidQueries.d.ts +1 -1
  85. package/src/shade/renderer/global_illumination/probe_clipmap/GPUProbeClipmapGI.d.ts +1 -1
  86. package/src/shade/renderer/global_illumination/probe_clipmap/brick/GPUSceneBrickClipmap.d.ts +37 -7
  87. package/src/shade/renderer/global_illumination/probe_clipmap/brick/GPUSceneBrickClipmap.d.ts.map +1 -1
  88. package/src/shade/renderer/global_illumination/probe_clipmap/brick/GPUSceneBrickClipmap.js +132 -8
  89. package/src/shade/renderer/global_illumination/probe_clipmap/brick/chunk_brick_clipmap_trace.d.ts +3 -1
  90. package/src/shade/renderer/global_illumination/probe_clipmap/brick/chunk_brick_clipmap_trace.d.ts.map +1 -1
  91. package/src/shade/renderer/global_illumination/probe_clipmap/brick/chunk_brick_clipmap_trace.js +6 -2
  92. package/src/shade/renderer/global_illumination/sharc/sharc_constants.d.ts +0 -18
  93. package/src/shade/renderer/global_illumination/sharc/sharc_constants.d.ts.map +1 -1
  94. package/src/shade/renderer/global_illumination/sharc/sharc_constants.js +1 -21
  95. package/src/shade/renderer/hair/GPUHairSystem.d.ts +121 -2
  96. package/src/shade/renderer/hair/GPUHairSystem.d.ts.map +1 -1
  97. package/src/shade/renderer/hair/GPUHairSystem.js +1187 -56
  98. package/src/shade/renderer/hair/HAIR.d.ts +22 -3
  99. package/src/shade/renderer/hair/HAIR.d.ts.map +1 -1
  100. package/src/shade/renderer/hair/HAIR.js +25 -4
  101. package/src/shade/renderer/hair/HAIR_DATABASE_SPEC.d.ts.map +1 -1
  102. package/src/shade/renderer/hair/HAIR_DATABASE_SPEC.js +33 -0
  103. package/src/shade/renderer/hair/HAIR_FRAME_STRUCTS.d.ts +4 -0
  104. package/src/shade/renderer/hair/HAIR_FRAME_STRUCTS.d.ts.map +1 -1
  105. package/src/shade/renderer/hair/HAIR_FRAME_STRUCTS.js +24 -2
  106. package/src/shade/renderer/hair/HAIR_SIMULATION.d.ts +139 -0
  107. package/src/shade/renderer/hair/HAIR_SIMULATION.d.ts.map +1 -0
  108. package/src/shade/renderer/hair/HAIR_SIMULATION.js +160 -0
  109. package/src/shade/renderer/hair/chunk_hair_dual_scattering.d.ts +9 -2
  110. package/src/shade/renderer/hair/chunk_hair_dual_scattering.d.ts.map +1 -1
  111. package/src/shade/renderer/hair/chunk_hair_dual_scattering.js +40 -13
  112. package/src/shade/renderer/hair/chunk_hair_guide.d.ts +59 -0
  113. package/src/shade/renderer/hair/chunk_hair_guide.d.ts.map +1 -0
  114. package/src/shade/renderer/hair/chunk_hair_guide.js +179 -0
  115. package/src/shade/renderer/hair/chunk_hair_volume.d.ts +4 -3
  116. package/src/shade/renderer/hair/chunk_hair_volume.d.ts.map +1 -1
  117. package/src/shade/renderer/hair/chunk_hair_volume.js +21 -12
  118. package/src/shade/renderer/hair/hair_lighting.d.ts.map +1 -1
  119. package/src/shade/renderer/hair/hair_lighting.js +16 -7
  120. package/src/shade/renderer/hair/hair_scattering_lut.js +13 -13
  121. package/src/shade/renderer/hair/hair_shadow_draw.d.ts +32 -0
  122. package/src/shade/renderer/hair/hair_shadow_draw.d.ts.map +1 -0
  123. package/src/shade/renderer/hair/hair_shadow_draw.js +123 -0
  124. package/src/shade/renderer/hair/shader_hair_classes.d.ts +2 -1
  125. package/src/shade/renderer/hair/shader_hair_classes.d.ts.map +1 -1
  126. package/src/shade/renderer/hair/shader_hair_classes.js +6 -2
  127. package/src/shade/renderer/hair/shader_hair_cull.d.ts +8 -2
  128. package/src/shade/renderer/hair/shader_hair_cull.d.ts.map +1 -1
  129. package/src/shade/renderer/hair/shader_hair_cull.js +74 -17
  130. package/src/shade/renderer/hair/shader_hair_lod.d.ts +9 -3
  131. package/src/shade/renderer/hair/shader_hair_lod.d.ts.map +1 -1
  132. package/src/shade/renderer/hair/shader_hair_lod.js +125 -31
  133. package/src/shade/renderer/hair/shader_hair_roots.d.ts +36 -0
  134. package/src/shade/renderer/hair/shader_hair_roots.d.ts.map +1 -0
  135. package/src/shade/renderer/hair/shader_hair_roots.js +261 -0
  136. package/src/shade/renderer/hair/shader_hair_shadow_list.d.ts +44 -0
  137. package/src/shade/renderer/hair/shader_hair_shadow_list.d.ts.map +1 -0
  138. package/src/shade/renderer/hair/shader_hair_shadow_list.js +240 -0
  139. package/src/shade/renderer/hair/shader_hair_simulate.d.ts +55 -0
  140. package/src/shade/renderer/hair/shader_hair_simulate.d.ts.map +1 -0
  141. package/src/shade/renderer/hair/shader_hair_simulate.js +563 -0
  142. package/src/shade/renderer/hair/shader_hair_volume.d.ts +3 -3
  143. package/src/shade/renderer/hair/shader_hair_volume.d.ts.map +1 -1
  144. package/src/shade/renderer/hair/shader_hair_volume.js +4 -17
  145. package/src/shade/renderer/loader/gltf/tiny-gltf.d.ts +1 -1
  146. package/src/shade/renderer/loader/usd/usd_groom_extension.d.ts +8 -3
  147. package/src/shade/renderer/loader/usd/usd_groom_extension.d.ts.map +1 -1
  148. package/src/shade/renderer/loader/usd/usd_groom_extension.js +58 -5
  149. package/src/shade/renderer/particles/GPUParticleSystem.d.ts +8 -0
  150. package/src/shade/renderer/particles/GPUParticleSystem.d.ts.map +1 -1
  151. package/src/shade/renderer/particles/GPUParticleSystem.js +28 -0
  152. package/src/shade/renderer/particles/graph/ParticleNodeRegistry.d.ts.map +1 -1
  153. package/src/shade/renderer/particles/graph/ParticleNodeRegistry.js +22 -0
  154. package/src/shade/renderer/particles/graph/groups/particle_builtin_groups.d.ts.map +1 -1
  155. package/src/shade/renderer/particles/graph/groups/particle_builtin_groups.js +4 -0
  156. package/src/shade/renderer/particles/graph/groups/particle_groups_scene.d.ts +32 -0
  157. package/src/shade/renderer/particles/graph/groups/particle_groups_scene.d.ts.map +1 -0
  158. package/src/shade/renderer/particles/graph/groups/particle_groups_scene.js +80 -0
  159. package/src/shade/renderer/particles/graph/particle_node_parameters.d.ts.map +1 -1
  160. package/src/shade/renderer/particles/graph/particle_node_parameters.js +1 -0
  161. package/src/shade/renderer/particles/graph/particle_node_presentation.d.ts.map +1 -1
  162. package/src/shade/renderer/particles/graph/particle_node_presentation.js +12 -0
  163. package/src/shade/renderer/particles/graph_particles.d.ts +5 -1
  164. package/src/shade/renderer/particles/graph_particles.d.ts.map +1 -1
  165. package/src/shade/renderer/particles/graph_particles.js +18 -3
  166. package/src/shade/renderer/particles/isa/InstructionStream.d.ts +25 -0
  167. package/src/shade/renderer/particles/isa/InstructionStream.d.ts.map +1 -1
  168. package/src/shade/renderer/particles/isa/InstructionStream.js +25 -0
  169. package/src/shade/renderer/particles/isa/ParticleVMISA.d.ts +9 -0
  170. package/src/shade/renderer/particles/isa/ParticleVMISA.d.ts.map +1 -1
  171. package/src/shade/renderer/particles/isa/ParticleVMISA.js +20 -0
  172. package/src/shade/renderer/particles/isa/particle_program_reads_scene_sdf.d.ts +9 -0
  173. package/src/shade/renderer/particles/isa/particle_program_reads_scene_sdf.d.ts.map +1 -0
  174. package/src/shade/renderer/particles/isa/particle_program_reads_scene_sdf.js +29 -0
  175. package/src/shade/renderer/particles/optimizer/particle_program_equivalence.d.ts +2 -1
  176. package/src/shade/renderer/particles/optimizer/particle_program_equivalence.d.ts.map +1 -1
  177. package/src/shade/renderer/particles/optimizer/particle_program_equivalence.js +27 -5
  178. package/src/shade/renderer/particles/optimizer/particle_program_fuzz.js +1 -1
  179. package/src/shade/renderer/particles/optimizer/particle_vm_semantics.d.ts.map +1 -1
  180. package/src/shade/renderer/particles/optimizer/particle_vm_semantics.js +5 -0
  181. package/src/shade/renderer/particles/runtime/EmitterRegistry.d.ts +7 -0
  182. package/src/shade/renderer/particles/runtime/EmitterRegistry.d.ts.map +1 -1
  183. package/src/shade/renderer/particles/runtime/EmitterRegistry.js +10 -0
  184. package/src/shade/renderer/particles/runtime/ParticleEmitter.d.ts +5 -0
  185. package/src/shade/renderer/particles/runtime/ParticleEmitter.d.ts.map +1 -1
  186. package/src/shade/renderer/particles/runtime/ParticleEmitter.js +5 -0
  187. package/src/shade/renderer/particles/runtime/ProgramHeap.d.ts +8 -0
  188. package/src/shade/renderer/particles/runtime/ProgramHeap.d.ts.map +1 -1
  189. package/src/shade/renderer/particles/runtime/ProgramHeap.js +25 -0
  190. package/src/shade/renderer/particles/shaders/shader_particle_emit.d.ts +1 -1
  191. package/src/shade/renderer/particles/shaders/shader_particle_emit.d.ts.map +1 -1
  192. package/src/shade/renderer/particles/shaders/shader_particle_emit.js +9 -3
  193. package/src/shade/renderer/particles/shaders/shader_particle_emit_wide.d.ts.map +1 -1
  194. package/src/shade/renderer/particles/shaders/shader_particle_emit_wide.js +4 -2
  195. package/src/shade/renderer/particles/shaders/shader_particle_simulate.d.ts +2 -2
  196. package/src/shade/renderer/particles/shaders/shader_particle_simulate.d.ts.map +1 -1
  197. package/src/shade/renderer/particles/shaders/shader_particle_simulate.js +10 -4
  198. package/src/shade/renderer/particles/shaders/shader_particle_simulate_wide.d.ts.map +1 -1
  199. package/src/shade/renderer/particles/shaders/shader_particle_simulate_wide.js +4 -2
  200. package/src/shade/renderer/particles/vm/ParticleVMReference.d.ts +14 -1
  201. package/src/shade/renderer/particles/vm/ParticleVMReference.d.ts.map +1 -1
  202. package/src/shade/renderer/particles/vm/ParticleVMReference.js +34 -1
  203. package/src/shade/renderer/particles/vm/chunk_particle_vm.d.ts.map +1 -1
  204. package/src/shade/renderer/particles/vm/chunk_particle_vm.js +10 -0
  205. package/src/shade/renderer/particles/vm/chunk_particle_vm_scene_sdf.d.ts +39 -0
  206. package/src/shade/renderer/particles/vm/chunk_particle_vm_scene_sdf.d.ts.map +1 -0
  207. package/src/shade/renderer/particles/vm/chunk_particle_vm_scene_sdf.js +90 -0
  208. package/src/shade/renderer/particles/warmup/graph_particle_warmup.d.ts +4 -1
  209. package/src/shade/renderer/particles/warmup/graph_particle_warmup.d.ts.map +1 -1
  210. package/src/shade/renderer/particles/warmup/graph_particle_warmup.js +14 -2
  211. package/src/shade/renderer/particles/warmup/shader_particle_warmup_advance.d.ts +1 -1
  212. package/src/shade/renderer/particles/warmup/shader_particle_warmup_advance.d.ts.map +1 -1
  213. package/src/shade/renderer/particles/warmup/shader_particle_warmup_advance.js +9 -3
  214. package/src/shade/renderer/particles/warmup/shader_particle_warmup_advance_wide.d.ts.map +1 -1
  215. package/src/shade/renderer/particles/warmup/shader_particle_warmup_advance_wide.js +4 -2
  216. package/src/shade/renderer/postprocess/nss/NSS.d.ts +1 -1
  217. package/src/shade/renderer/postprocess/velocity/graph_add_per_object_velocity.d.ts +7 -4
  218. package/src/shade/renderer/postprocess/velocity/graph_add_per_object_velocity.d.ts.map +1 -1
  219. package/src/shade/renderer/postprocess/velocity/graph_add_per_object_velocity.js +26 -16
  220. package/src/shade/renderer/scene/GPUSceneContext.d.ts +7 -0
  221. package/src/shade/renderer/scene/GPUSceneContext.d.ts.map +1 -1
  222. package/src/shade/renderer/scene/GPUSceneContext.js +18 -0
  223. package/src/shade/renderer/shader/chunk/sdf/chunk_shape_record_signed_distance_gradient.d.ts +20 -0
  224. package/src/shade/renderer/shader/chunk/sdf/chunk_shape_record_signed_distance_gradient.d.ts.map +1 -0
  225. package/src/shade/renderer/shader/chunk/sdf/chunk_shape_record_signed_distance_gradient.js +134 -0
  226. package/src/shade/renderer/shadow/map/GPUSceneShadowmapContext.d.ts +15 -0
  227. package/src/shade/renderer/shadow/map/GPUSceneShadowmapContext.d.ts.map +1 -1
  228. package/src/shade/renderer/shadow/map/GPUSceneShadowmapContext.js +69 -0
  229. package/src/shade/renderer/shadow/map/shader/chunk_shadowmap_directional_atlas_casters.d.ts +10 -0
  230. package/src/shade/renderer/shadow/map/shader/chunk_shadowmap_directional_atlas_casters.d.ts.map +1 -0
  231. package/src/shade/renderer/shadow/map/shader/chunk_shadowmap_directional_atlas_casters.js +22 -0
  232. package/src/shade/renderer/water/query/GPUWaterQueries.d.ts +1 -1
  233. package/src/shade/renderer/wind/GPUSceneWind.d.ts +1 -1
@@ -19,14 +19,21 @@ export const HAIR_SCATTERING_LUT_RESOURCE = ShaderResourceDescriptor.texture("tH
19
19
  * ```wgsl
20
20
  * fn hair_scattering(l: vec3<f32>, v: vec3<f32>, t: vec3<f32>, absorption: vec3<f32>, roughness: f32,
21
21
  * hair_count: f32, backlit: f32, area: f32) -> vec3<f32>
22
+ * fn hair_forward_transmittance(l: vec3<f32>, t: vec3<f32>, absorption: vec3<f32>, roughness: f32,
23
+ * hair_count: f32) -> vec3<f32>
22
24
  * ```
23
25
  *
24
26
  * `hair_count` is the number of strands between the point and the light (the density volume's march); one is taken
25
27
  * off it for the strand's own. The global term passes the light through them, attenuated by the average front
26
28
  * scattering to the power of their count and spread by their roughness; the local term adds what scatters back
27
29
  * from the strands around the point. The average scatterings come from the table at the light's angle to the fibre,
28
- * the roughness and the colour. Unreal's clamp of the roughness to [0.18, 0.6] here, which its source calls "a bit
29
- * adhoc", is not taken. Its Kajiya-Kay term is not either: this is the multiple scattering it stands in for.
30
+ * the roughness and the colour. As in Unreal, the table is read at the fibre's roughness and the lobes' spreads take
31
+ * it clamped to [0.18, 0.6]: the spreads are Gaussians, and a narrower one would let a single smooth strand in front
32
+ * block all but the light along its own cone (at roughness 0.1 one strand passes a fortieth of what the clamp passes).
33
+ * Unreal's Kajiya-Kay term is not taken: this is the multiple scattering it stands in for.
34
+ *
35
+ * `hair_forward_transmittance` is the global term's energy alone, the average front scattering to the power of the
36
+ * strands passed: what reaches the point from a source as wide as the sky, over which the spread integrates to one.
30
37
  *
31
38
  * @type {CodeChunk}
32
39
  */
@@ -38,13 +45,14 @@ fn hair_gaussian_unnormalized(v: f32, theta: f32) -> f32 {
38
45
  return exp(-0.5 * theta * theta / max(v, 1e-10));
39
46
  }
40
47
 
41
- fn hair_scattering(l: vec3<f32>, v: vec3<f32>, t: vec3<f32>, absorption: vec3<f32>, roughness: f32, hair_count: f32, backlit: f32, area: f32) -> vec3<f32> {
42
- let single = hair_shading(l, v, t, absorption, roughness, backlit, area);
43
-
44
- let sin_l = clamp(dot(t, l), -1.0, 1.0);
45
- let sin_v = clamp(dot(t, v), -1.0, 1.0);
48
+ // the table's average front and back scattering, a channel each
49
+ struct HairAverageScattering {
50
+ front: vec3<f32>,
51
+ back: vec3<f32>,
52
+ }
46
53
 
47
- // the table, a channel at a time, at the colour's square root
54
+ // the table, a channel at a time, at the colour's square root
55
+ fn hair_average_scattering(sin_l: f32, absorption: vec3<f32>, roughness: f32) -> HairAverageScattering {
48
56
  let color = hair_absorption_to_color(absorption);
49
57
  let z = sqrt(saturate(color));
50
58
  let x = saturate(abs(sin_l));
@@ -54,8 +62,25 @@ fn hair_scattering(l: vec3<f32>, v: vec3<f32>, t: vec3<f32>, absorption: vec3<f3
54
62
  let s_g = textureSampleLevel(tHairScattering, sLinear, vec3<f32>(x, y, z.g), 0.0).rg;
55
63
  let s_b = textureSampleLevel(tHairScattering, sLinear, vec3<f32>(x, y, z.b), 0.0).rg;
56
64
 
57
- let a_front = vec3<f32>(s_r.x, s_g.x, s_b.x);
58
- let a_back = vec3<f32>(s_r.y, s_g.y, s_b.y);
65
+ return HairAverageScattering(vec3<f32>(s_r.x, s_g.x, s_b.x), vec3<f32>(s_r.y, s_g.y, s_b.y));
66
+ }
67
+
68
+ fn hair_forward_transmittance(l: vec3<f32>, t: vec3<f32>, absorption: vec3<f32>, roughness: f32, hair_count: f32) -> vec3<f32> {
69
+ let average = hair_average_scattering(clamp(dot(t, l), -1.0, 1.0), absorption, roughness);
70
+
71
+ return pow(average.front, vec3<f32>(max(0.0, hair_count - 1.0)));
72
+ }
73
+
74
+ fn hair_scattering(l: vec3<f32>, v: vec3<f32>, t: vec3<f32>, absorption: vec3<f32>, roughness: f32, hair_count: f32, backlit: f32, area: f32) -> vec3<f32> {
75
+ let single = hair_shading(l, v, t, absorption, roughness, backlit, area);
76
+
77
+ let sin_l = clamp(dot(t, l), -1.0, 1.0);
78
+ let sin_v = clamp(dot(t, v), -1.0, 1.0);
79
+
80
+ let average = hair_average_scattering(sin_l, absorption, roughness);
81
+
82
+ let a_front = average.front;
83
+ let a_back = average.back;
59
84
 
60
85
  const MAX_AVERAGE = 0.99;
61
86
 
@@ -69,9 +94,11 @@ fn hair_scattering(l: vec3<f32>, v: vec3<f32>, t: vec3<f32>, absorption: vec3<f3
69
94
  let a3 = ab * ab2 * af2 / (one_minus_af2 * one_minus_af2 * one_minus_af2);
70
95
  let a_b = a1 + a3;
71
96
 
72
- let beta_r = roughness * roughness;
73
- let beta_tt = (roughness * 0.5) * (roughness * 0.5);
74
- let beta_trt = (roughness * 2.0) * (roughness * 2.0);
97
+ let spread_roughness = clamp(roughness, 0.18, 0.6);
98
+
99
+ let beta_r = spread_roughness * spread_roughness;
100
+ let beta_tt = (spread_roughness * 0.5) * (spread_roughness * 0.5);
101
+ let beta_trt = (spread_roughness * 2.0) * (spread_roughness * 2.0);
75
102
 
76
103
  const SHIFT_R = -0.035 * 2.0;
77
104
  const SHIFT_TT = 0.035;
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Epochs as an f32 holds them exactly, in a guide state header's `w`.
3
+ * @type {number}
4
+ */
5
+ export const HAIR_EPOCH_MASK: number;
6
+ /**
7
+ * Every simulated instance's guide state, a run an instance (`HAIR_SIMULATION.js`).
8
+ *
9
+ * @type {ShaderResourceDescriptor}
10
+ */
11
+ export const HAIR_GUIDE_STATE_RESOURCE: ShaderResourceDescriptor;
12
+ /**
13
+ * Where a simulated instance's guide state is, and what its guides are:
14
+ *
15
+ * ```wgsl
16
+ * fn hair_strand_frame(instance: HairInstance, strand: u32, entity: mat4x4<f32>, last: bool) -> mat4x4<f32>
17
+ * fn hair_state_live(instance: HairInstance) -> bool
18
+ * fn hair_state_index(instance: HairInstance, plane: u32, node: u32, guide: u32) -> u32
19
+ * fn hair_guide_record(instance: HairInstance, guide: u32) -> vec4<u32>
20
+ * fn hair_quat_nlerp(a: vec4<f32>, b: vec4<f32>, t: f32) -> vec4<f32>
21
+ * fn hair_drag_rate(speed: f32, diameter: f32, mass_per_length: f32) -> f32
22
+ * ```
23
+ *
24
+ * `hair_strand_frame` is what carries a strand's rest points into the world: its root frame (`shader_hair_roots.js`)
25
+ * when the instance is bound to a mesh, the `entity` matrix given otherwise; with `last`, a frame ago.
26
+ * `hair_state_live` is whether the instance is simulated and its state was laid for it: a state allocated since the
27
+ * frame's step holds another tenant's nodes, or none, and its strands ride the entity until the next step lays it.
28
+ * Reads the state's header. `hair_state_index` is a vector of the state pool, node-interleaved. `hair_guide_record` is a guide's four words in
29
+ * the groom pool: its strand's rank, its wisp's strand count, its wisp's diameter and its length (f32 bits).
30
+ * `hair_quat_nlerp` blends two unit quaternions along the shorter arc. `hair_drag_rate` is `hair_drag_rate`'s twin
31
+ * (`HAIR_SIMULATION.js`): the rate a node's velocity relaxes toward the air's.
32
+ *
33
+ * @type {CodeChunk}
34
+ */
35
+ export const chunk_hair_guide: CodeChunk;
36
+ /**
37
+ * A point of a simulated strand, carried by its guide:
38
+ *
39
+ * ```wgsl
40
+ * fn hair_guided_point(instance: HairInstance, strand: u32, point: u32, entity: mat4x4<f32>, anchor: vec3<f32>,
41
+ * last: bool) -> vec3<f32>
42
+ * ```
43
+ *
44
+ * The strand follows its guide (its strand word's high 16 bits). The point's rest place is taken from the chord
45
+ * between the guide's nodes either side of it at the same share of the length, and placed by the strand's own frame
46
+ * (`hair_strand_frame`) applied to three terms: the rest chord, carried by the strand's frame; the guide's move
47
+ * there, the chord where its nodes are less the rest chord carried by the guide's frame; and the point's offset from
48
+ * the rest chord, carried by the strand's frame's linear part and turned by the guide's frame there (the nodes' frames
49
+ * blended along the chord). Exact for any rigid motion of a wisp, so a guide at rest draws its strands as they were
50
+ * made; for strands that ride their entity both frames are the entity's. With `last`, where it was a frame ago: the
51
+ * nodes, frames and root frames of a frame ago, and `entity` the entity's matrix then; `anchor` is this frame's,
52
+ * which the nodes of a frame ago are kept from. World metres.
53
+ *
54
+ * @type {CodeChunk}
55
+ */
56
+ export const chunk_hair_guided_point: CodeChunk;
57
+ import { ShaderResourceDescriptor } from "../shader/resource/ShaderResourceDescriptor.js";
58
+ import { CodeChunk } from "../shader/compiler/CodeChunk.js";
59
+ //# sourceMappingURL=chunk_hair_guide.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chunk_hair_guide.d.ts","sourceRoot":"","sources":["../../../../../src/shade/renderer/hair/chunk_hair_guide.js"],"names":[],"mappings":"AAqBA;;;GAGG;AACH,8BAFU,MAAM,CAEwB;AAExC;;;;GAIG;AACH,wCAFU,wBAAwB,CAE2F;AAE7H;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,+BAFU,SAAS,CAwDhB;AAKH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,sCAFU,SAAS,CAyChB;yCA7KsC,gDAAgD;0BAD/D,iCAAiC"}
@@ -0,0 +1,179 @@
1
+ import { chunk_quat_rotate_v3 } from "../shader/chunk/geometry/quaternion/chunk_v3_apply_quat.js";
2
+ import { CodeChunk } from "../shader/compiler/CodeChunk.js";
3
+ import { ShaderResourceDescriptor } from "../shader/resource/ShaderResourceDescriptor.js";
4
+ import { WebGPUArray } from "../shader/type/WebGPUArray.js";
5
+ import { vec4f } from "../shader/type/WEBGPU_WGSL_PRIMITIVE_TYPES.js";
6
+ import { chunk_hair_rest_point, HAIR_GROOMS_RESOURCE } from "./chunk_hair_strand.js";
7
+ import { HAIR_INSTANCE_STRUCT } from "./HAIR_DATABASE_SPEC.js";
8
+ import {
9
+ HAIR_AIR_DENSITY,
10
+ HAIR_AIR_VISCOSITY,
11
+ HAIR_BINDING_NONE,
12
+ HAIR_ROOT_FRAME_VECTORS,
13
+ HAIR_GUIDE_RECORD_WORDS,
14
+ HAIR_STATE_FRAME,
15
+ HAIR_STATE_HEADER,
16
+ HAIR_STATE_LAST_FRAME,
17
+ HAIR_STATE_LAST_POSITION,
18
+ HAIR_STATE_NONE,
19
+ HAIR_STATE_POSITION
20
+ } from "./HAIR_SIMULATION.js";
21
+
22
+ /**
23
+ * Epochs as an f32 holds them exactly, in a guide state header's `w`.
24
+ * @type {number}
25
+ */
26
+ export const HAIR_EPOCH_MASK = 0xFFFFFF;
27
+
28
+ /**
29
+ * Every simulated instance's guide state, a run an instance (`HAIR_SIMULATION.js`).
30
+ *
31
+ * @type {ShaderResourceDescriptor}
32
+ */
33
+ export const HAIR_GUIDE_STATE_RESOURCE = ShaderResourceDescriptor.storageBuffer("hair_guide_state", WebGPUArray.from(vec4f));
34
+
35
+ /**
36
+ * Where a simulated instance's guide state is, and what its guides are:
37
+ *
38
+ * ```wgsl
39
+ * fn hair_strand_frame(instance: HairInstance, strand: u32, entity: mat4x4<f32>, last: bool) -> mat4x4<f32>
40
+ * fn hair_state_live(instance: HairInstance) -> bool
41
+ * fn hair_state_index(instance: HairInstance, plane: u32, node: u32, guide: u32) -> u32
42
+ * fn hair_guide_record(instance: HairInstance, guide: u32) -> vec4<u32>
43
+ * fn hair_quat_nlerp(a: vec4<f32>, b: vec4<f32>, t: f32) -> vec4<f32>
44
+ * fn hair_drag_rate(speed: f32, diameter: f32, mass_per_length: f32) -> f32
45
+ * ```
46
+ *
47
+ * `hair_strand_frame` is what carries a strand's rest points into the world: its root frame (`shader_hair_roots.js`)
48
+ * when the instance is bound to a mesh, the `entity` matrix given otherwise; with `last`, a frame ago.
49
+ * `hair_state_live` is whether the instance is simulated and its state was laid for it: a state allocated since the
50
+ * frame's step holds another tenant's nodes, or none, and its strands ride the entity until the next step lays it.
51
+ * Reads the state's header. `hair_state_index` is a vector of the state pool, node-interleaved. `hair_guide_record` is a guide's four words in
52
+ * the groom pool: its strand's rank, its wisp's strand count, its wisp's diameter and its length (f32 bits).
53
+ * `hair_quat_nlerp` blends two unit quaternions along the shorter arc. `hair_drag_rate` is `hair_drag_rate`'s twin
54
+ * (`HAIR_SIMULATION.js`): the rate a node's velocity relaxes toward the air's.
55
+ *
56
+ * @type {CodeChunk}
57
+ */
58
+ export const chunk_hair_guide = CodeChunk.from(
59
+ //language=WGSL
60
+ `
61
+ fn hair_strand_frame(instance: ${HAIR_INSTANCE_STRUCT.wgsl_ref}, strand: u32, entity: mat4x4<f32>, last: bool) -> mat4x4<f32> {
62
+ if (instance.mesh_node == ${HAIR_BINDING_NONE}u) {
63
+ return entity;
64
+ }
65
+
66
+ let at = instance.roots + strand * ${HAIR_ROOT_FRAME_VECTORS}u + select(0u, 3u, last);
67
+
68
+ let r0 = hair_guide_state[at];
69
+ let r1 = hair_guide_state[at + 1u];
70
+ let r2 = hair_guide_state[at + 2u];
71
+
72
+ return mat4x4<f32>(
73
+ vec4<f32>(r0.x, r1.x, r2.x, 0.0),
74
+ vec4<f32>(r0.y, r1.y, r2.y, 0.0),
75
+ vec4<f32>(r0.z, r1.z, r2.z, 0.0),
76
+ vec4<f32>(r0.w, r1.w, r2.w, 1.0),
77
+ );
78
+ }
79
+
80
+ fn hair_state_live(instance: ${HAIR_INSTANCE_STRUCT.wgsl_ref}) -> bool {
81
+ if (instance.state == ${HAIR_STATE_NONE}u) {
82
+ return false;
83
+ }
84
+
85
+ return hair_guide_state[instance.state].w == f32(instance.epoch & ${HAIR_EPOCH_MASK}u);
86
+ }
87
+
88
+ fn hair_state_index(instance: ${HAIR_INSTANCE_STRUCT.wgsl_ref}, plane: u32, node: u32, guide: u32) -> u32 {
89
+ return instance.state + ${HAIR_STATE_HEADER}u + (plane * instance.guide_point_count + node) * instance.guide_count + guide;
90
+ }
91
+
92
+ fn hair_guide_record(instance: ${HAIR_INSTANCE_STRUCT.wgsl_ref}, guide: u32) -> vec4<u32> {
93
+ let at = instance.guides + guide * ${HAIR_GUIDE_RECORD_WORDS}u;
94
+
95
+ return vec4<u32>(hair_grooms[at], hair_grooms[at + 1u], hair_grooms[at + 2u], hair_grooms[at + 3u]);
96
+ }
97
+
98
+ fn hair_quat_nlerp(a: vec4<f32>, b: vec4<f32>, t: f32) -> vec4<f32> {
99
+ let side = select(1.0, -1.0, dot(a, b) < 0.0);
100
+
101
+ return normalize(mix(a, b * side, t));
102
+ }
103
+
104
+ fn hair_drag_rate(speed: f32, diameter: f32, mass_per_length: f32) -> f32 {
105
+ let reynolds_per_speed = ${HAIR_AIR_DENSITY} * diameter / ${HAIR_AIR_VISCOSITY};
106
+
107
+ return 0.5 * ${HAIR_AIR_DENSITY} * diameter / mass_per_length
108
+ * (speed + 10.0 * pow(speed, 1.0 / 3.0) * pow(reynolds_per_speed, -2.0 / 3.0));
109
+ }
110
+ `, [
111
+ HAIR_INSTANCE_STRUCT.declaration_chunk,
112
+ ]);
113
+
114
+ chunk_hair_guide.requireResource(HAIR_GROOMS_RESOURCE);
115
+ chunk_hair_guide.requireResource(HAIR_GUIDE_STATE_RESOURCE);
116
+
117
+ /**
118
+ * A point of a simulated strand, carried by its guide:
119
+ *
120
+ * ```wgsl
121
+ * fn hair_guided_point(instance: HairInstance, strand: u32, point: u32, entity: mat4x4<f32>, anchor: vec3<f32>,
122
+ * last: bool) -> vec3<f32>
123
+ * ```
124
+ *
125
+ * The strand follows its guide (its strand word's high 16 bits). The point's rest place is taken from the chord
126
+ * between the guide's nodes either side of it at the same share of the length, and placed by the strand's own frame
127
+ * (`hair_strand_frame`) applied to three terms: the rest chord, carried by the strand's frame; the guide's move
128
+ * there, the chord where its nodes are less the rest chord carried by the guide's frame; and the point's offset from
129
+ * the rest chord, carried by the strand's frame's linear part and turned by the guide's frame there (the nodes' frames
130
+ * blended along the chord). Exact for any rigid motion of a wisp, so a guide at rest draws its strands as they were
131
+ * made; for strands that ride their entity both frames are the entity's. With `last`, where it was a frame ago: the
132
+ * nodes, frames and root frames of a frame ago, and `entity` the entity's matrix then; `anchor` is this frame's,
133
+ * which the nodes of a frame ago are kept from. World metres.
134
+ *
135
+ * @type {CodeChunk}
136
+ */
137
+ export const chunk_hair_guided_point = CodeChunk.from(
138
+ //language=WGSL
139
+ `
140
+ fn hair_guided_point(instance: ${HAIR_INSTANCE_STRUCT.wgsl_ref}, strand: u32, point: u32, entity: mat4x4<f32>, anchor: vec3<f32>, last: bool) -> vec3<f32> {
141
+ let guide = hair_grooms[instance.strands + strand] >> 16u;
142
+ let record = hair_guide_record(instance, guide);
143
+
144
+ // the node before the point and how far past it, along the guide
145
+ let step = (instance.point_count - 1u) / (instance.guide_point_count - 1u);
146
+ let node = min(point / step, instance.guide_point_count - 2u);
147
+ let t = f32(point - node * step) / f32(step);
148
+
149
+ let rest_a = hair_rest_point(instance, record.x, node * step).xyz;
150
+ let rest_b = hair_rest_point(instance, record.x, (node + 1u) * step).xyz;
151
+ let offset = hair_rest_point(instance, strand, point).xyz - mix(rest_a, rest_b, t);
152
+
153
+
154
+ let position_plane = select(${HAIR_STATE_POSITION}u, ${HAIR_STATE_LAST_POSITION}u, last);
155
+ let frame_plane = select(${HAIR_STATE_FRAME}u, ${HAIR_STATE_LAST_FRAME}u, last);
156
+
157
+ let a = hair_guide_state[hair_state_index(instance, position_plane, node, guide)].xyz;
158
+ let b = hair_guide_state[hair_state_index(instance, position_plane, node + 1u, guide)].xyz;
159
+ let qa = hair_guide_state[hair_state_index(instance, frame_plane, node, guide)];
160
+ let qb = hair_guide_state[hair_state_index(instance, frame_plane, node + 1u, guide)];
161
+
162
+ let rest_chord = mix(rest_a, rest_b, t);
163
+ let strand_frame = hair_strand_frame(instance, strand, entity, last);
164
+ let guide_frame = hair_strand_frame(instance, record.x, entity, last);
165
+ let strand_linear = mat3x3<f32>(strand_frame[0].xyz, strand_frame[1].xyz, strand_frame[2].xyz);
166
+
167
+ let moved = anchor + mix(a, b, t) - (guide_frame * vec4<f32>(rest_chord, 1.0)).xyz;
168
+
169
+ return (strand_frame * vec4<f32>(rest_chord, 1.0)).xyz + moved + quat_rotate_v3(hair_quat_nlerp(qa, qb, t), strand_linear * offset);
170
+ }
171
+ `, [
172
+ HAIR_INSTANCE_STRUCT.declaration_chunk,
173
+ chunk_hair_rest_point,
174
+ chunk_hair_guide,
175
+ chunk_quat_rotate_v3,
176
+ ]);
177
+
178
+ chunk_hair_guided_point.requireResource(HAIR_GUIDE_STATE_RESOURCE);
179
+
@@ -13,15 +13,16 @@
13
13
  */
14
14
  export const chunk_hair_volume_layout: CodeChunk;
15
15
  /**
16
- * The number of strands between a point and the edge of its instance's volume, along a direction:
16
+ * The number of strands between a point and the edge of its instance's volume, or a point `distance` away, along a
17
+ * direction:
17
18
  *
18
19
  * ```wgsl
19
- * fn hair_count_along(lod: HairLod, position: vec3<f32>, direction: vec3<f32>, jitter: f32) -> f32
20
+ * fn hair_count_along(lod: HairLod, position: vec3<f32>, direction: vec3<f32>, jitter: f32, distance: f32) -> f32
20
21
  * ```
21
22
  *
22
23
  * Eight taps, a constant trip count: the march starts one voxel out, steps one voxel twice, then doubles its step
23
24
  * each tap, reading the mip whose voxel matches the step (the last, past it), so it reaches 128 voxels. A tap outside
24
- * the volume reads nothing. `jitter` in [0, 1) moves the taps along the ray by up to a step, for the frame's
25
+ * the volume, or past `distance`, reads nothing. `jitter` in [0, 1) moves the taps along the ray by up to a step, for the frame's
25
26
  * accumulation to filter the voxels' edges. Reads `hair_volume`.
26
27
  *
27
28
  * @type {CodeChunk}
@@ -1 +1 @@
1
- {"version":3,"file":"chunk_hair_volume.d.ts","sourceRoot":"","sources":["../../../../../src/shade/renderer/hair/chunk_hair_volume.js"],"names":[],"mappings":"AAIA;;;;;;;;;;;;GAYG;AACH,uCAFU,SAAS,CA0BqB;AAExC;;;;;;;;;;;;;GAaG;AACH,qCAFU,SAAS,CAkDY;0BAzGL,iCAAiC"}
1
+ {"version":3,"file":"chunk_hair_volume.d.ts","sourceRoot":"","sources":["../../../../../src/shade/renderer/hair/chunk_hair_volume.js"],"names":[],"mappings":"AAIA;;;;;;;;;;;;GAYG;AACH,uCAFU,SAAS,CA0BqB;AAExC;;;;;;;;;;;;;;GAcG;AACH,qCAFU,SAAS,CA0DY;0BAlHL,iCAAiC"}
@@ -42,15 +42,16 @@ fn hair_volume_index(lod: ${HAIR_LOD_STRUCT.wgsl_ref}, cell: vec3<u32>, mip: u32
42
42
  `, [HAIR_LOD_STRUCT.declaration_chunk]);
43
43
 
44
44
  /**
45
- * The number of strands between a point and the edge of its instance's volume, along a direction:
45
+ * The number of strands between a point and the edge of its instance's volume, or a point `distance` away, along a
46
+ * direction:
46
47
  *
47
48
  * ```wgsl
48
- * fn hair_count_along(lod: HairLod, position: vec3<f32>, direction: vec3<f32>, jitter: f32) -> f32
49
+ * fn hair_count_along(lod: HairLod, position: vec3<f32>, direction: vec3<f32>, jitter: f32, distance: f32) -> f32
49
50
  * ```
50
51
  *
51
52
  * Eight taps, a constant trip count: the march starts one voxel out, steps one voxel twice, then doubles its step
52
53
  * each tap, reading the mip whose voxel matches the step (the last, past it), so it reaches 128 voxels. A tap outside
53
- * the volume reads nothing. `jitter` in [0, 1) moves the taps along the ray by up to a step, for the frame's
54
+ * the volume, or past `distance`, reads nothing. `jitter` in [0, 1) moves the taps along the ray by up to a step, for the frame's
54
55
  * accumulation to filter the voxels' edges. Reads `hair_volume`.
55
56
  *
56
57
  * @type {CodeChunk}
@@ -58,11 +59,12 @@ fn hair_volume_index(lod: ${HAIR_LOD_STRUCT.wgsl_ref}, cell: vec3<u32>, mip: u32
58
59
  export const chunk_hair_count_along = CodeChunk.from(
59
60
  //language=WGSL
60
61
  `
61
- // the voxel of one level under a point, its level's size and first voxel given; nothing outside the volume
62
- fn hair_volume_read(voxel: vec3<f32>, mip: u32, dims: vec3<u32>, offset: u32) -> f32 {
62
+ // the voxel of one level under a point, the tap "along" voxels down the march, its level's size and first voxel
63
+ // given; nothing outside the volume, nor past "reach" voxels
64
+ fn hair_volume_read(voxel: vec3<f32>, along: f32, reach: f32, mip: u32, dims: vec3<u32>, offset: u32) -> f32 {
63
65
  let cell = floor(voxel / f32(1u << mip));
64
66
 
65
- if (any(cell < vec3<f32>(0.0)) || any(cell >= vec3<f32>(dims))) {
67
+ if (along > reach || any(cell < vec3<f32>(0.0)) || any(cell >= vec3<f32>(dims))) {
66
68
  return 0.0;
67
69
  }
68
70
 
@@ -71,7 +73,7 @@ fn hair_volume_read(voxel: vec3<f32>, mip: u32, dims: vec3<u32>, offset: u32) ->
71
73
  return f32(hair_volume[offset + (c.z * dims.y + c.y) * dims.x + c.x]) * (1.0 / ${HAIR_VOLUME_FIXED_ONE}.0);
72
74
  }
73
75
 
74
- fn hair_count_along(lod: ${HAIR_LOD_STRUCT.wgsl_ref}, position: vec3<f32>, direction: vec3<f32>, jitter: f32) -> f32 {
76
+ fn hair_count_along(lod: ${HAIR_LOD_STRUCT.wgsl_ref}, position: vec3<f32>, direction: vec3<f32>, jitter: f32, distance: f32) -> f32 {
75
77
  if (lod.voxel_size <= 0.0) {
76
78
  return 0.0;
77
79
  }
@@ -85,19 +87,26 @@ fn hair_count_along(lod: ${HAIR_LOD_STRUCT.wgsl_ref}, position: vec3<f32>, direc
85
87
  let o2 = o1 + d1.x * d1.y * d1.z;
86
88
 
87
89
  let start = (position - lod.volume_origin) / lod.voxel_size;
90
+ let reach = distance / lod.voxel_size;
88
91
 
89
92
  // 1, 1, 2, 4, then 8, 16, 32, 64 voxels a tap, the last four from the coarsest level
90
- var count = hair_volume_read(start + direction * (1.0 + jitter), 0u, d0, o0)
91
- + hair_volume_read(start + direction * (2.0 + jitter), 0u, d0, o0)
92
- + 2.0 * hair_volume_read(start + direction * (3.0 + 2.0 * jitter), 1u, d1, o1)
93
- + 4.0 * hair_volume_read(start + direction * (5.0 + 4.0 * jitter), 2u, d2, o2);
93
+ let t0 = 1.0 + jitter;
94
+ let t1 = 2.0 + jitter;
95
+ let t2 = 3.0 + 2.0 * jitter;
96
+ let t3 = 5.0 + 4.0 * jitter;
97
+
98
+ var count = hair_volume_read(start + direction * t0, t0, reach, 0u, d0, o0)
99
+ + hair_volume_read(start + direction * t1, t1, reach, 0u, d0, o0)
100
+ + 2.0 * hair_volume_read(start + direction * t2, t2, reach, 1u, d1, o1)
101
+ + 4.0 * hair_volume_read(start + direction * t3, t3, reach, 2u, d2, o2);
94
102
 
95
103
  var travelled = 9.0;
96
104
 
97
105
  for (var k = 0u; k < 4u; k++) {
98
106
  let size = f32(8u << k);
107
+ let t = travelled + size * jitter;
99
108
 
100
- count += size * hair_volume_read(start + direction * (travelled + size * jitter), 2u, d2, o2);
109
+ count += size * hair_volume_read(start + direction * t, t, reach, 2u, d2, o2);
101
110
  travelled += size;
102
111
  }
103
112
 
@@ -1 +1 @@
1
- {"version":3,"file":"hair_lighting.d.ts","sourceRoot":"","sources":["../../../../../src/shade/renderer/hair/hair_lighting.js"],"names":[],"mappings":"AAyNA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,iDAJW,OAAO,uCAAuC,EAAE,eAAe,6BAE7D,wBAAwB,CA+BpC;AA7OD;;;GAGG;AACH,uCAFU,6BAA6B,CAM8B;AAErE;;;;GAIG;AACH,uCAFU,6BAA6B,CAaA;AAYvC;;;;;GAKG;AACH,sCAFU,2BAA2B,CAEY;AAgIjD;;;;GAIG;AACH,qCAFU,gBAAgB,CAEgC;yCA/MjB,8DAA8D;8CAYzD,qDAAqD;4CACvD,mDAAmD;iCAC9D,+BAA+B"}
1
+ {"version":3,"file":"hair_lighting.d.ts","sourceRoot":"","sources":["../../../../../src/shade/renderer/hair/hair_lighting.js"],"names":[],"mappings":"AAkOA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,iDAJW,OAAO,uCAAuC,EAAE,eAAe,6BAE7D,wBAAwB,CA+BpC;AAtPD;;;GAGG;AACH,uCAFU,6BAA6B,CAM8B;AAErE;;;;GAIG;AACH,uCAFU,6BAA6B,CAaA;AAYvC;;;;;GAKG;AACH,sCAFU,2BAA2B,CAEY;AAyIjD;;;;GAIG;AACH,qCAFU,gBAAgB,CAEgC;yCAxNjB,8DAA8D;8CAYzD,qDAAqD;4CACvD,mDAAmD;iCAC9D,+BAA+B"}
@@ -102,9 +102,16 @@ struct DirectLightContext {
102
102
  lod: ${HAIR_LOD_STRUCT.wgsl_ref},
103
103
  }
104
104
 
105
- // the strands between the point and the light, from the instance's density volume, scatter the light that reaches it
106
- fn direct_light_lobe(context: ptr<function, DirectLightContext>, light: ${INCIDENT_LIGHT_STRUCT.wgsl_ref}) {
107
- let count = hair_count_along((*context).lod, (*context).position, light.direction, (*context).jitter);
105
+ // the strands between the point and the light, from the instance's density volume, scatter the light that reaches it;
106
+ // strands drawn into the light's shadow map are shadowed toward it by the map, their own among the casters, and the
107
+ // volume would take them off twice
108
+ fn direct_light_lobe(context: ptr<function, DirectLightContext>, light: ${INCIDENT_LIGHT_STRUCT.wgsl_ref}, atlas_casters: bool) {
109
+ var count = 0.0;
110
+
111
+ if (hair_view.casts_shadows == 0u || !atlas_casters) {
112
+ // only the strands short of the light: a local light inside the hair has strands beyond it too
113
+ count = hair_count_along((*context).lod, (*context).position, light.direction, (*context).jitter, light.distance);
114
+ }
108
115
 
109
116
  (*context).radiance += light.color * hair_scattering(light.direction, (*context).view_direction, (*context).tangent, (*context).absorption, (*context).roughness, count, 1.0, 0.0);
110
117
  }
@@ -172,10 +179,12 @@ fn fs_main(in: HairQuadVertex) -> @location(0) vec4<f32> {
172
179
 
173
180
  forward_sample_indirect(position, view_direction, normal, instance.roughness, &radiance, &irradiance);
174
181
 
175
- // through the strands between the point and the open air about its normal: sky occlusion
176
- let count_around = hair_count_along(lod, position, normal, noise.y);
177
- let indirect_shading = min(vec3<f32>(1.0), 3.14159265 * hair_scattering(normal, view_direction, towards_root, absorption, instance.roughness, count_around, 0.0, 0.2));
178
- let indirect = irradiance * (1.0 / 3.14159265) * indirect_shading;
182
+ // through the strands between the point and the open air about its normal: sky occlusion, the energy they pass
183
+ // forward
184
+ let count_around = hair_count_along(lod, position, normal, noise.y, 1e30);
185
+ let indirect_shading = min(vec3<f32>(1.0), 3.14159265 * hair_shading(normal, view_direction, towards_root, absorption, instance.roughness, 0.0, 0.2));
186
+ let transmittance = hair_forward_transmittance(normal, towards_root, absorption, instance.roughness, count_around);
187
+ let indirect = irradiance * (1.0 / 3.14159265) * indirect_shading * transmittance;
179
188
 
180
189
  // the fog between the eye and the strand: the composite has already put its in-scatter here, over a surface it
181
190
  // took to be black metal; the strand's own light is attenuated by the same transmittance, and the colour
@@ -158,7 +158,7 @@ export function hair_shading_twin(u, cos_phi, u_v, absorption, roughness) {
158
158
  return Math.max(sum, 0);
159
159
  }
160
160
 
161
- // Gauss-Hermite, 16 nodes: the positive half of the nodes and their weights over sqrt(pi)
161
+ // Gauss-Hermite, 16 nodes: the positive half of the nodes and their weights, which sum to sqrt(pi) over all 16
162
162
  const GH_X = [0.27348104613815, 0.82295144914466, 1.38025853919888, 1.95178799091625, 2.54620215784748, 3.17699916197996, 3.86944790486012, 4.68873893930582];
163
163
  const GH_W = [0.50792947901661, 0.28064745852853, 0.08381004139899, 0.01288031153551, 0.00093228400862, 0.00002711860093, 0.00000023209808, 0.00000000026548];
164
164
  const SQRT_PI = Math.sqrt(Math.PI);
@@ -188,38 +188,38 @@ export function hair_average_scattering(u_v, roughness, color, phi_steps = 128)
188
188
  let sum = 0;
189
189
 
190
190
  for (let p = 0; p < 3; p++) {
191
- // the Gaussian's width and centre do not depend on u
191
+ // the Gaussian's width and centre away from the pole, where they do not depend on u
192
192
  hair_lobe(p, 0, cos_phi, u_v, absorption, roughness, lobe);
193
193
 
194
194
  const beta = Math.max(lobe[0], 1e-5);
195
195
  const centre = lobe[1];
196
+ const reach = Math.SQRT2 * beta * GH_X[7];
196
197
 
197
- if (beta < 0.06) {
198
- // narrow: Gauss-Hermite about the centre, nodes outside [-1, 1] dropped
198
+ if (beta < 0.06 && Math.abs(centre) + reach <= 1) {
199
+ // narrow, every node inside [-1, 1]: Gauss-Hermite about the centre
199
200
  for (let i = 0; i < 8; i++) {
200
201
  for (const sign of [-1, 1]) {
201
202
  const u = centre + sign * Math.SQRT2 * beta * GH_X[i];
202
203
 
203
- if (u < -1 || u > 1) {
204
- continue;
205
- }
206
-
207
204
  hair_lobe(p, u, cos_phi, u_v, absorption, roughness, lobe);
208
205
 
209
206
  sum += GH_W[i] / SQRT_PI * lobe[2];
210
207
  }
211
208
  }
212
209
  } else {
213
- // wide: the midpoint rule over [-1, 1], 32 steps a width at least
214
- const steps = Math.min(1024, Math.max(64, Math.ceil(64 / beta)));
215
- const du = 2 / steps;
210
+ // otherwise the integrand as it is, the lobe's width and centre taken at each u, by the midpoint rule
211
+ // over its support within [-1, 1]: eight widths either side of its centre, 32 steps a width
212
+ const lo = Math.max(-1, centre - 8 * beta);
213
+ const hi = Math.min(1, centre + 8 * beta);
214
+ const steps = Math.min(8192, Math.max(64, Math.ceil(32 * (hi - lo) / beta)));
215
+ const du = (hi - lo) / steps;
216
216
 
217
217
  for (let i = 0; i < steps; i++) {
218
- const u = -1 + (i + 0.5) * du;
218
+ const u = lo + (i + 0.5) * du;
219
219
 
220
220
  hair_lobe(p, u, cos_phi, u_v, absorption, roughness, lobe);
221
221
 
222
- sum += gaussian(beta, u - centre) * lobe[2] * du;
222
+ sum += gaussian(lobe[0], u - lobe[1]) * lobe[2] * du;
223
223
  }
224
224
  }
225
225
  }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * A shadow view's rectangle as the hair draws into it.
3
+ * @type {WebGPUStruct}
4
+ */
5
+ export const HAIR_SHADOW_TARGET_STRUCT: WebGPUStruct;
6
+ /**
7
+ * The bindings of {@link HAIR_SHADOW_PIPELINE}: `camera` (the shadow view's), `hair_shadow_view`, `hair_list` (the
8
+ * shadow views' lists) and `hair_points` (the frame's deformed points).
9
+ *
10
+ * @type {ShaderResourceSetDescriptor}
11
+ */
12
+ export const HAIR_SHADOW_RESOURCES: ShaderResourceSetDescriptor;
13
+ /**
14
+ * Draws the frame's strands into a shadow view's depth, as the scene's casters are drawn
15
+ * (`DEPTH_STENCIL_STATE_SHADOW`).
16
+ *
17
+ * An instance is an entry of the view's list (`shader_hair_shadow_list`), a strand, drawn as `hair_id_draw.js` draws
18
+ * it for the eye: a triangle strip a pair of vertices at each of its points, `2 (2^class + 1)` vertices, one draw a
19
+ * point class (`shader_hair_shadow_draw_args`),
20
+ * across the strand's tangent and the way to the light. Its width is the strand's own, as its point carries it, also
21
+ * where the camera's view drew it at none. Under a texel, a point is drawn a texel wide by the strands whose
22
+ * stratified share is under its width's fraction of the texel, and at none by the rest, so the covered area is the
23
+ * strands' own at any texel size. A point nearer the light than the view's near plane is drawn on the plane. Both faces
24
+ * are drawn.
25
+ *
26
+ * @type {RenderPipelineDescriptor}
27
+ */
28
+ export const HAIR_SHADOW_PIPELINE: RenderPipelineDescriptor;
29
+ import { WebGPUStruct } from "../shader/type/WebGPUStruct.js";
30
+ import { ShaderResourceSetDescriptor } from "../shader/resource/ShaderResourceSetDescriptor.js";
31
+ import { RenderPipelineDescriptor } from "../../descriptor/pipeline/render/RenderPipelineDescriptor.js";
32
+ //# sourceMappingURL=hair_shadow_draw.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hair_shadow_draw.d.ts","sourceRoot":"","sources":["../../../../../src/shade/renderer/hair/hair_shadow_draw.js"],"names":[],"mappings":"AAWA;;;GAGG;AACH,wCAFU,YAAY,CAKQ;AA2E9B;;;;;GAKG;AACH,oCAFU,2BAA2B,CAEU;AAE/C;;;;;;;;;;;;;;GAcG;AACH,mCAFU,wBAAwB,CAQ/B;6BAlH0B,gCAAgC;4CAJjB,mDAAmD;yCAJtD,8DAA8D"}