@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.
- package/editor/particles/effect/ParticleReferenceSimulation.d.ts +11 -0
- package/editor/particles/effect/ParticleReferenceSimulation.d.ts.map +1 -1
- package/editor/particles/effect/ParticleReferenceSimulation.js +14 -0
- package/editor/view/particles/effect/ParticleGraphEditorView.js +1 -1
- package/package.json +1 -1
- package/src/engine/asset/loaders/GroomAssetLoader.d.ts +1 -1
- package/src/engine/asset/loaders/GroomAssetLoader.d.ts.map +1 -1
- package/src/engine/asset/loaders/GroomAssetLoader.js +16 -2
- package/src/engine/graphics/ecs/hair/Hair.d.ts +7 -0
- package/src/engine/graphics/ecs/hair/Hair.d.ts.map +1 -1
- package/src/engine/graphics/ecs/hair/Hair.js +9 -0
- package/src/engine/graphics/ecs/hair/HairDynamics.d.ts +63 -0
- package/src/engine/graphics/ecs/hair/HairDynamics.d.ts.map +1 -0
- package/src/engine/graphics/ecs/hair/HairDynamics.js +82 -0
- package/src/engine/graphics/hair/Groom.d.ts +45 -0
- package/src/engine/graphics/hair/Groom.d.ts.map +1 -1
- package/src/engine/graphics/hair/Groom.js +56 -0
- package/src/engine/graphics/hair/GroomSerializationAdapter.d.ts +27 -1
- package/src/engine/graphics/hair/GroomSerializationAdapter.d.ts.map +1 -1
- package/src/engine/graphics/hair/GroomSerializationAdapter.js +105 -32
- package/src/engine/graphics/hair/GroomSerializationUpgrader_0_1.d.ts +8 -0
- package/src/engine/graphics/hair/GroomSerializationUpgrader_0_1.d.ts.map +1 -0
- package/src/engine/graphics/hair/GroomSerializationUpgrader_0_1.js +31 -0
- package/src/engine/graphics/hair/groom_bind_to_mesh.d.ts +85 -0
- package/src/engine/graphics/hair/groom_bind_to_mesh.d.ts.map +1 -0
- package/src/engine/graphics/hair/groom_bind_to_mesh.js +216 -0
- package/src/engine/graphics/hair/groom_build_group.d.ts +7 -2
- package/src/engine/graphics/hair/groom_build_group.d.ts.map +1 -1
- package/src/engine/graphics/hair/groom_build_group.js +11 -2
- package/src/engine/graphics/hair/groom_build_guides.d.ts +43 -0
- package/src/engine/graphics/hair/groom_build_guides.d.ts.map +1 -0
- package/src/engine/graphics/hair/groom_build_guides.js +267 -0
- package/src/engine/graphics/hair/groom_root_spacing.d.ts +6 -4
- package/src/engine/graphics/hair/groom_root_spacing.d.ts.map +1 -1
- package/src/engine/graphics/hair/groom_root_spacing.js +199 -66
- package/src/engine/graphics3/HairColliderSystem.d.ts +59 -0
- package/src/engine/graphics3/HairColliderSystem.d.ts.map +1 -0
- package/src/engine/graphics3/HairColliderSystem.js +270 -0
- package/src/engine/graphics3/HairSystem.d.ts +21 -4
- package/src/engine/graphics3/HairSystem.d.ts.map +1 -1
- package/src/engine/graphics3/HairSystem.js +270 -4
- package/src/engine/physics/fluid/ecs/FluidObstacleSystem.d.ts +4 -4
- package/src/shade/assets/textures/hair_scattering.bin +0 -0
- package/src/shade/playground/hair/main.js +27 -4
- package/src/shade/playground/hair_skinned/index.html +192 -0
- package/src/shade/playground/hair_skinned/main.d.ts +7 -0
- package/src/shade/playground/hair_skinned/main.d.ts.map +1 -0
- package/src/shade/playground/hair_skinned/main.js +481 -0
- package/src/shade/playground/hair_skinned/skinned_hair.d.ts +49 -0
- package/src/shade/playground/hair_skinned/skinned_hair.d.ts.map +1 -0
- package/src/shade/playground/hair_skinned/skinned_hair.js +362 -0
- package/src/shade/playground/sparks/README.md +36 -0
- package/src/shade/playground/sparks/index.html +145 -0
- package/src/shade/playground/sparks/main.d.ts +7 -0
- package/src/shade/playground/sparks/main.d.ts.map +1 -0
- package/src/shade/playground/sparks/main.js +312 -0
- package/src/shade/playground/sparks/sparks_effect.d.ts +72 -0
- package/src/shade/playground/sparks/sparks_effect.d.ts.map +1 -0
- package/src/shade/playground/sparks/sparks_effect.js +180 -0
- package/src/shade/renderer/Renderer.d.ts.map +1 -1
- package/src/shade/renderer/Renderer.js +18 -3
- package/src/shade/renderer/acoustics/GPUAcousticLattice.d.ts +1 -1
- package/src/shade/renderer/acoustics/GPUAcousticProbes.d.ts +1 -1
- package/src/shade/renderer/acoustics/GPUAcoustics.d.ts +1 -1
- package/src/shade/renderer/animation/GPUAnimationManager.d.ts +3 -2
- package/src/shade/renderer/animation/GPUAnimationManager.d.ts.map +1 -1
- package/src/shade/renderer/animation/GPUAnimationManager.js +74 -3
- package/src/shade/renderer/animation/skinning/GPUMeshSkinningContext.d.ts +13 -3
- package/src/shade/renderer/animation/skinning/GPUMeshSkinningContext.d.ts.map +1 -1
- package/src/shade/renderer/animation/skinning/GPUMeshSkinningContext.js +16 -5
- package/src/shade/renderer/animation/skinning/shader_meshlet_apply_skinning.js +8 -8
- package/src/shade/renderer/deferred/chunk_shade_direct_lights.js +2 -2
- package/src/shade/renderer/deferred/chunk_shade_directional_lights.d.ts +4 -2
- package/src/shade/renderer/deferred/chunk_shade_directional_lights.d.ts.map +1 -1
- package/src/shade/renderer/deferred/chunk_shade_directional_lights.js +7 -3
- package/src/shade/renderer/deferred/chunk_standard_material_direct_light_lobe.js +1 -1
- package/src/shade/renderer/extension/ShadowAtlas.d.ts +75 -0
- package/src/shade/renderer/extension/ShadowAtlas.d.ts.map +1 -0
- package/src/shade/renderer/extension/ShadowAtlas.js +133 -0
- package/src/shade/renderer/fluid/GPUFluidCascade.d.ts +3 -3
- package/src/shade/renderer/fluid/GPUFluidCascadeStack.d.ts +1 -1
- package/src/shade/renderer/fluid/forcing/GPUFluidForcing.d.ts +7 -7
- package/src/shade/renderer/fluid/pressure/GPUFluidPressureSolve.d.ts +1 -1
- package/src/shade/renderer/fluid/query/GPUFluidQueries.d.ts +1 -1
- package/src/shade/renderer/global_illumination/probe_clipmap/GPUProbeClipmapGI.d.ts +1 -1
- package/src/shade/renderer/global_illumination/probe_clipmap/brick/GPUSceneBrickClipmap.d.ts +37 -7
- package/src/shade/renderer/global_illumination/probe_clipmap/brick/GPUSceneBrickClipmap.d.ts.map +1 -1
- package/src/shade/renderer/global_illumination/probe_clipmap/brick/GPUSceneBrickClipmap.js +132 -8
- package/src/shade/renderer/global_illumination/probe_clipmap/brick/chunk_brick_clipmap_trace.d.ts +3 -1
- package/src/shade/renderer/global_illumination/probe_clipmap/brick/chunk_brick_clipmap_trace.d.ts.map +1 -1
- package/src/shade/renderer/global_illumination/probe_clipmap/brick/chunk_brick_clipmap_trace.js +6 -2
- package/src/shade/renderer/global_illumination/sharc/sharc_constants.d.ts +0 -18
- package/src/shade/renderer/global_illumination/sharc/sharc_constants.d.ts.map +1 -1
- package/src/shade/renderer/global_illumination/sharc/sharc_constants.js +1 -21
- package/src/shade/renderer/hair/GPUHairSystem.d.ts +121 -2
- package/src/shade/renderer/hair/GPUHairSystem.d.ts.map +1 -1
- package/src/shade/renderer/hair/GPUHairSystem.js +1187 -56
- package/src/shade/renderer/hair/HAIR.d.ts +22 -3
- package/src/shade/renderer/hair/HAIR.d.ts.map +1 -1
- package/src/shade/renderer/hair/HAIR.js +25 -4
- package/src/shade/renderer/hair/HAIR_DATABASE_SPEC.d.ts.map +1 -1
- package/src/shade/renderer/hair/HAIR_DATABASE_SPEC.js +33 -0
- package/src/shade/renderer/hair/HAIR_FRAME_STRUCTS.d.ts +4 -0
- package/src/shade/renderer/hair/HAIR_FRAME_STRUCTS.d.ts.map +1 -1
- package/src/shade/renderer/hair/HAIR_FRAME_STRUCTS.js +24 -2
- package/src/shade/renderer/hair/HAIR_SIMULATION.d.ts +139 -0
- package/src/shade/renderer/hair/HAIR_SIMULATION.d.ts.map +1 -0
- package/src/shade/renderer/hair/HAIR_SIMULATION.js +160 -0
- package/src/shade/renderer/hair/chunk_hair_dual_scattering.d.ts +9 -2
- package/src/shade/renderer/hair/chunk_hair_dual_scattering.d.ts.map +1 -1
- package/src/shade/renderer/hair/chunk_hair_dual_scattering.js +40 -13
- package/src/shade/renderer/hair/chunk_hair_guide.d.ts +59 -0
- package/src/shade/renderer/hair/chunk_hair_guide.d.ts.map +1 -0
- package/src/shade/renderer/hair/chunk_hair_guide.js +179 -0
- package/src/shade/renderer/hair/chunk_hair_volume.d.ts +4 -3
- package/src/shade/renderer/hair/chunk_hair_volume.d.ts.map +1 -1
- package/src/shade/renderer/hair/chunk_hair_volume.js +21 -12
- package/src/shade/renderer/hair/hair_lighting.d.ts.map +1 -1
- package/src/shade/renderer/hair/hair_lighting.js +16 -7
- package/src/shade/renderer/hair/hair_scattering_lut.js +13 -13
- package/src/shade/renderer/hair/hair_shadow_draw.d.ts +32 -0
- package/src/shade/renderer/hair/hair_shadow_draw.d.ts.map +1 -0
- package/src/shade/renderer/hair/hair_shadow_draw.js +123 -0
- package/src/shade/renderer/hair/shader_hair_classes.d.ts +2 -1
- package/src/shade/renderer/hair/shader_hair_classes.d.ts.map +1 -1
- package/src/shade/renderer/hair/shader_hair_classes.js +6 -2
- package/src/shade/renderer/hair/shader_hair_cull.d.ts +8 -2
- package/src/shade/renderer/hair/shader_hair_cull.d.ts.map +1 -1
- package/src/shade/renderer/hair/shader_hair_cull.js +74 -17
- package/src/shade/renderer/hair/shader_hair_lod.d.ts +9 -3
- package/src/shade/renderer/hair/shader_hair_lod.d.ts.map +1 -1
- package/src/shade/renderer/hair/shader_hair_lod.js +125 -31
- package/src/shade/renderer/hair/shader_hair_roots.d.ts +36 -0
- package/src/shade/renderer/hair/shader_hair_roots.d.ts.map +1 -0
- package/src/shade/renderer/hair/shader_hair_roots.js +261 -0
- package/src/shade/renderer/hair/shader_hair_shadow_list.d.ts +44 -0
- package/src/shade/renderer/hair/shader_hair_shadow_list.d.ts.map +1 -0
- package/src/shade/renderer/hair/shader_hair_shadow_list.js +240 -0
- package/src/shade/renderer/hair/shader_hair_simulate.d.ts +55 -0
- package/src/shade/renderer/hair/shader_hair_simulate.d.ts.map +1 -0
- package/src/shade/renderer/hair/shader_hair_simulate.js +563 -0
- package/src/shade/renderer/hair/shader_hair_volume.d.ts +3 -3
- package/src/shade/renderer/hair/shader_hair_volume.d.ts.map +1 -1
- package/src/shade/renderer/hair/shader_hair_volume.js +4 -17
- package/src/shade/renderer/loader/gltf/tiny-gltf.d.ts +1 -1
- package/src/shade/renderer/loader/usd/usd_groom_extension.d.ts +8 -3
- package/src/shade/renderer/loader/usd/usd_groom_extension.d.ts.map +1 -1
- package/src/shade/renderer/loader/usd/usd_groom_extension.js +58 -5
- package/src/shade/renderer/particles/GPUParticleSystem.d.ts +8 -0
- package/src/shade/renderer/particles/GPUParticleSystem.d.ts.map +1 -1
- package/src/shade/renderer/particles/GPUParticleSystem.js +28 -0
- package/src/shade/renderer/particles/graph/ParticleNodeRegistry.d.ts.map +1 -1
- package/src/shade/renderer/particles/graph/ParticleNodeRegistry.js +22 -0
- package/src/shade/renderer/particles/graph/groups/particle_builtin_groups.d.ts.map +1 -1
- package/src/shade/renderer/particles/graph/groups/particle_builtin_groups.js +4 -0
- package/src/shade/renderer/particles/graph/groups/particle_groups_scene.d.ts +32 -0
- package/src/shade/renderer/particles/graph/groups/particle_groups_scene.d.ts.map +1 -0
- package/src/shade/renderer/particles/graph/groups/particle_groups_scene.js +80 -0
- package/src/shade/renderer/particles/graph/particle_node_parameters.d.ts.map +1 -1
- package/src/shade/renderer/particles/graph/particle_node_parameters.js +1 -0
- package/src/shade/renderer/particles/graph/particle_node_presentation.d.ts.map +1 -1
- package/src/shade/renderer/particles/graph/particle_node_presentation.js +12 -0
- package/src/shade/renderer/particles/graph_particles.d.ts +5 -1
- package/src/shade/renderer/particles/graph_particles.d.ts.map +1 -1
- package/src/shade/renderer/particles/graph_particles.js +18 -3
- package/src/shade/renderer/particles/isa/InstructionStream.d.ts +25 -0
- package/src/shade/renderer/particles/isa/InstructionStream.d.ts.map +1 -1
- package/src/shade/renderer/particles/isa/InstructionStream.js +25 -0
- package/src/shade/renderer/particles/isa/ParticleVMISA.d.ts +9 -0
- package/src/shade/renderer/particles/isa/ParticleVMISA.d.ts.map +1 -1
- package/src/shade/renderer/particles/isa/ParticleVMISA.js +20 -0
- package/src/shade/renderer/particles/isa/particle_program_reads_scene_sdf.d.ts +9 -0
- package/src/shade/renderer/particles/isa/particle_program_reads_scene_sdf.d.ts.map +1 -0
- package/src/shade/renderer/particles/isa/particle_program_reads_scene_sdf.js +29 -0
- package/src/shade/renderer/particles/optimizer/particle_program_equivalence.d.ts +2 -1
- package/src/shade/renderer/particles/optimizer/particle_program_equivalence.d.ts.map +1 -1
- package/src/shade/renderer/particles/optimizer/particle_program_equivalence.js +27 -5
- package/src/shade/renderer/particles/optimizer/particle_program_fuzz.js +1 -1
- package/src/shade/renderer/particles/optimizer/particle_vm_semantics.d.ts.map +1 -1
- package/src/shade/renderer/particles/optimizer/particle_vm_semantics.js +5 -0
- package/src/shade/renderer/particles/runtime/EmitterRegistry.d.ts +7 -0
- package/src/shade/renderer/particles/runtime/EmitterRegistry.d.ts.map +1 -1
- package/src/shade/renderer/particles/runtime/EmitterRegistry.js +10 -0
- package/src/shade/renderer/particles/runtime/ParticleEmitter.d.ts +5 -0
- package/src/shade/renderer/particles/runtime/ParticleEmitter.d.ts.map +1 -1
- package/src/shade/renderer/particles/runtime/ParticleEmitter.js +5 -0
- package/src/shade/renderer/particles/runtime/ProgramHeap.d.ts +8 -0
- package/src/shade/renderer/particles/runtime/ProgramHeap.d.ts.map +1 -1
- package/src/shade/renderer/particles/runtime/ProgramHeap.js +25 -0
- package/src/shade/renderer/particles/shaders/shader_particle_emit.d.ts +1 -1
- package/src/shade/renderer/particles/shaders/shader_particle_emit.d.ts.map +1 -1
- package/src/shade/renderer/particles/shaders/shader_particle_emit.js +9 -3
- package/src/shade/renderer/particles/shaders/shader_particle_emit_wide.d.ts.map +1 -1
- package/src/shade/renderer/particles/shaders/shader_particle_emit_wide.js +4 -2
- package/src/shade/renderer/particles/shaders/shader_particle_simulate.d.ts +2 -2
- package/src/shade/renderer/particles/shaders/shader_particle_simulate.d.ts.map +1 -1
- package/src/shade/renderer/particles/shaders/shader_particle_simulate.js +10 -4
- package/src/shade/renderer/particles/shaders/shader_particle_simulate_wide.d.ts.map +1 -1
- package/src/shade/renderer/particles/shaders/shader_particle_simulate_wide.js +4 -2
- package/src/shade/renderer/particles/vm/ParticleVMReference.d.ts +14 -1
- package/src/shade/renderer/particles/vm/ParticleVMReference.d.ts.map +1 -1
- package/src/shade/renderer/particles/vm/ParticleVMReference.js +34 -1
- package/src/shade/renderer/particles/vm/chunk_particle_vm.d.ts.map +1 -1
- package/src/shade/renderer/particles/vm/chunk_particle_vm.js +10 -0
- package/src/shade/renderer/particles/vm/chunk_particle_vm_scene_sdf.d.ts +39 -0
- package/src/shade/renderer/particles/vm/chunk_particle_vm_scene_sdf.d.ts.map +1 -0
- package/src/shade/renderer/particles/vm/chunk_particle_vm_scene_sdf.js +90 -0
- package/src/shade/renderer/particles/warmup/graph_particle_warmup.d.ts +4 -1
- package/src/shade/renderer/particles/warmup/graph_particle_warmup.d.ts.map +1 -1
- package/src/shade/renderer/particles/warmup/graph_particle_warmup.js +14 -2
- package/src/shade/renderer/particles/warmup/shader_particle_warmup_advance.d.ts +1 -1
- package/src/shade/renderer/particles/warmup/shader_particle_warmup_advance.d.ts.map +1 -1
- package/src/shade/renderer/particles/warmup/shader_particle_warmup_advance.js +9 -3
- package/src/shade/renderer/particles/warmup/shader_particle_warmup_advance_wide.d.ts.map +1 -1
- package/src/shade/renderer/particles/warmup/shader_particle_warmup_advance_wide.js +4 -2
- package/src/shade/renderer/postprocess/nss/NSS.d.ts +1 -1
- package/src/shade/renderer/postprocess/velocity/graph_add_per_object_velocity.d.ts +7 -4
- package/src/shade/renderer/postprocess/velocity/graph_add_per_object_velocity.d.ts.map +1 -1
- package/src/shade/renderer/postprocess/velocity/graph_add_per_object_velocity.js +26 -16
- package/src/shade/renderer/scene/GPUSceneContext.d.ts +7 -0
- package/src/shade/renderer/scene/GPUSceneContext.d.ts.map +1 -1
- package/src/shade/renderer/scene/GPUSceneContext.js +18 -0
- package/src/shade/renderer/shader/chunk/sdf/chunk_shape_record_signed_distance_gradient.d.ts +20 -0
- package/src/shade/renderer/shader/chunk/sdf/chunk_shape_record_signed_distance_gradient.d.ts.map +1 -0
- package/src/shade/renderer/shader/chunk/sdf/chunk_shape_record_signed_distance_gradient.js +134 -0
- package/src/shade/renderer/shadow/map/GPUSceneShadowmapContext.d.ts +15 -0
- package/src/shade/renderer/shadow/map/GPUSceneShadowmapContext.d.ts.map +1 -1
- package/src/shade/renderer/shadow/map/GPUSceneShadowmapContext.js +69 -0
- package/src/shade/renderer/shadow/map/shader/chunk_shadowmap_directional_atlas_casters.d.ts +10 -0
- package/src/shade/renderer/shadow/map/shader/chunk_shadowmap_directional_atlas_casters.d.ts.map +1 -0
- package/src/shade/renderer/shadow/map/shader/chunk_shadowmap_directional_atlas_casters.js +22 -0
- package/src/shade/renderer/water/query/GPUWaterQueries.d.ts +1 -1
- package/src/shade/renderer/wind/GPUSceneWind.d.ts +1 -1
|
@@ -11,9 +11,15 @@ import { WebGPUArray } from "../shader/type/WebGPUArray.js";
|
|
|
11
11
|
import { WebGPUBufferType } from "../shader/type/WebGPUBufferType.js";
|
|
12
12
|
import { WebGPUStruct } from "../shader/type/WebGPUStruct.js";
|
|
13
13
|
import { chunk_hair_lod } from "./chunk_hair_strand.js";
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
HAIR_COUNTER_POINTS,
|
|
16
|
+
HAIR_COUNTER_SHADOW_STRANDS,
|
|
17
|
+
HAIR_COUNTER_VOXELS,
|
|
18
|
+
HAIR_VOLUME_DIMENSION_LIMIT
|
|
19
|
+
} from "./HAIR.js";
|
|
15
20
|
import { HAIR_INSTANCE_DESCRIPTOR } from "./HAIR_DATABASE_SPEC.js";
|
|
16
|
-
import {
|
|
21
|
+
import { HAIR_BINDING_NONE, HAIR_GUIDE_BOUNDS_WORDS, HAIR_STATE_NONE } from "./HAIR_SIMULATION.js";
|
|
22
|
+
import { HAIR_LOD_STRUCT, HAIR_SHADOW_VIEW_STRUCT } from "./HAIR_FRAME_STRUCTS.js";
|
|
17
23
|
|
|
18
24
|
/**
|
|
19
25
|
* Threads per workgroup, a row each. The page iterator wants a multiple of 32.
|
|
@@ -36,6 +42,8 @@ export const HAIR_LOD_SETTINGS = WebGPUStruct.from({
|
|
|
36
42
|
point_capacity: u32,
|
|
37
43
|
/** voxels the frame's voxel buffer holds */
|
|
38
44
|
voxel_capacity: u32,
|
|
45
|
+
/** shadow views the strands draw into this frame, the first of `hair_shadow_views`; 0 where they cast none */
|
|
46
|
+
shadow_view_count: u32,
|
|
39
47
|
}, "HairLodSettings");
|
|
40
48
|
|
|
41
49
|
const resources = new ShaderResourceSetDescriptor();
|
|
@@ -46,10 +54,13 @@ resources.createGroup()
|
|
|
46
54
|
.add(CAMERA_RESOURCE)
|
|
47
55
|
.addStorageBuffer("hair_database", WebGPUBufferType.unsized, false)
|
|
48
56
|
.addStorageBuffer("scene_database", WebGPUBufferType.unsized, false)
|
|
57
|
+
.addStorageBuffer("hair_guide_bounds", WebGPUArray.u32, false)
|
|
49
58
|
.addStorageBuffer("hair_counts", COLLECTION_U32_STRUCT_READ, true)
|
|
50
|
-
.addStorageBuffer("
|
|
59
|
+
.addStorageBuffer("hair_mip_1_counts", COLLECTION_U32_STRUCT_READ, true)
|
|
60
|
+
.addStorageBuffer("hair_mip_2_counts", COLLECTION_U32_STRUCT_READ, true)
|
|
51
61
|
.addStorageBuffer("hair_lod", WebGPUArray.from(HAIR_LOD_STRUCT), true)
|
|
52
|
-
.addStorageBuffer("hair_counters", WebGPUArray.from(atomic_u32), true)
|
|
62
|
+
.addStorageBuffer("hair_counters", WebGPUArray.from(atomic_u32), true)
|
|
63
|
+
.addStorageBuffer("hair_shadow_views", WebGPUArray.from(HAIR_SHADOW_VIEW_STRUCT), false);
|
|
53
64
|
|
|
54
65
|
const body = CodeChunk.from(
|
|
55
66
|
//language=WGSL
|
|
@@ -60,6 +71,40 @@ fn hair_decimation_error(instance: ${HAIR_INSTANCE_DESCRIPTOR.type.wgsl_ref}, le
|
|
|
60
71
|
return quad[level & 3u];
|
|
61
72
|
}
|
|
62
73
|
|
|
74
|
+
// a float from the u32 that orders as it does
|
|
75
|
+
fn hair_unordered(u: u32) -> f32 {
|
|
76
|
+
return bitcast<f32>(select(~u, u ^ 0x80000000u, (u & 0x80000000u) != 0u));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// the finest texel, world metres, of the shadow views a box reaches into, the near plane aside (the shadow draw holds
|
|
80
|
+
// what is nearer the light on it): 0 where the box reaches the eye of one, whose texels it cannot bound; negative
|
|
81
|
+
// where it reaches none
|
|
82
|
+
fn hair_shadow_texel(centre: vec3<f32>, half_extent: vec3<f32>) -> f32 {
|
|
83
|
+
var finest = -1.0;
|
|
84
|
+
|
|
85
|
+
for (var v = 0u; v < min(settings.shadow_view_count, arrayLength(&hair_shadow_views)); v++) {
|
|
86
|
+
let view = hair_shadow_views[v];
|
|
87
|
+
|
|
88
|
+
var inside = true;
|
|
89
|
+
|
|
90
|
+
for (var p = 0u; p < 5u; p++) {
|
|
91
|
+
let plane = view.planes[p];
|
|
92
|
+
|
|
93
|
+
inside = inside && dot(plane.xyz, centre) + plane.w + dot(abs(plane.xyz), half_extent) >= 0.0;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (inside) {
|
|
97
|
+
// the box's least clip w: its nearest depth to a spot light, one in an orthographic cascade
|
|
98
|
+
let w = dot(view.depth.xyz, centre) + view.depth.w - dot(abs(view.depth.xyz), half_extent);
|
|
99
|
+
let texel = view.texel * max(w, 0.0);
|
|
100
|
+
|
|
101
|
+
finest = select(texel, min(finest, texel), finest >= 0.0);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return finest;
|
|
106
|
+
}
|
|
107
|
+
|
|
63
108
|
fn hair_pack_pixel(p: vec2<f32>) -> u32 {
|
|
64
109
|
let q = vec2<u32>(clamp(p, vec2<f32>(0.0), vec2<f32>(65535.0)));
|
|
65
110
|
|
|
@@ -75,7 +120,8 @@ fn main(
|
|
|
75
120
|
// is unallocated
|
|
76
121
|
if (wg_id.x == 0u && local_id == 0u) {
|
|
77
122
|
hair_counts.count = settings.capacity;
|
|
78
|
-
|
|
123
|
+
hair_mip_1_counts.count = settings.capacity;
|
|
124
|
+
hair_mip_2_counts.count = settings.capacity;
|
|
79
125
|
}
|
|
80
126
|
|
|
81
127
|
if (!${PG}_setup(&hair_database, wg_id.x, local_id)) {
|
|
@@ -95,18 +141,52 @@ fn main(
|
|
|
95
141
|
|
|
96
142
|
var lod: ${HAIR_LOD_STRUCT.wgsl_ref};
|
|
97
143
|
|
|
98
|
-
|
|
144
|
+
// a bound group's strands are carried by the mesh's world matrix, through their root frames, and are as wide as it
|
|
145
|
+
// makes them
|
|
146
|
+
var carrier = m;
|
|
147
|
+
|
|
148
|
+
if (instance.mesh_node != ${HAIR_BINDING_NONE}u) {
|
|
149
|
+
carrier = scene_read_node(&scene_database, instance.mesh_node).global;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
lod.scale = max(length(carrier[0].xyz), max(length(carrier[1].xyz), length(carrier[2].xyz)));
|
|
99
153
|
|
|
100
154
|
// the group's box in the world: its quantization box, widened by the widest strand
|
|
101
155
|
let centre_local = instance.bounds_min + 0.5 * instance.bounds_extent;
|
|
102
156
|
let half_local = 0.5 * instance.bounds_extent + vec3<f32>(0.5 * instance.width_max);
|
|
103
157
|
|
|
104
|
-
|
|
105
|
-
|
|
158
|
+
var centre = (m * vec4<f32>(centre_local, 1.0)).xyz;
|
|
159
|
+
var half_extent = abs(m[0].xyz) * half_local.x + abs(m[1].xyz) * half_local.y + abs(m[2].xyz) * half_local.z;
|
|
160
|
+
|
|
161
|
+
// a simulated group's strands are where its guides are, as far off them as its reach and as wide as its widest; a
|
|
162
|
+
// bound group's that rides its roots as far again as its longest guide from where its roots are
|
|
163
|
+
let gathered = row * ${HAIR_GUIDE_BOUNDS_WORDS}u;
|
|
164
|
+
let gathers = instance.state != ${HAIR_STATE_NONE}u || instance.mesh_node != ${HAIR_BINDING_NONE}u;
|
|
165
|
+
|
|
166
|
+
if (gathers && hair_guide_bounds[gathered + 6u] == instance.epoch && hair_guide_bounds[gathered] != 0u) {
|
|
167
|
+
let high = vec3<f32>(hair_unordered(hair_guide_bounds[gathered]), hair_unordered(hair_guide_bounds[gathered + 1u]), hair_unordered(hair_guide_bounds[gathered + 2u]));
|
|
168
|
+
let low = vec3<f32>(hair_unordered(~hair_guide_bounds[gathered + 3u]), hair_unordered(~hair_guide_bounds[gathered + 4u]), hair_unordered(~hair_guide_bounds[gathered + 5u]));
|
|
169
|
+
|
|
170
|
+
centre = m[3].xyz + 0.5 * (low + high);
|
|
171
|
+
// rigid strands reach their length from their roots; a bound group's strands each ride their own root frame,
|
|
172
|
+
// which the skin turns apart from their guide's, so they too may reach their length from where their roots are
|
|
173
|
+
let along = select(0.0, instance.guide_length_max, instance.state == ${HAIR_STATE_NONE}u || instance.mesh_node != ${HAIR_BINDING_NONE}u);
|
|
174
|
+
|
|
175
|
+
half_extent = 0.5 * (high - low) + vec3<f32>((along + instance.guide_reach + 0.5 * instance.width_max) * lod.scale);
|
|
176
|
+
}
|
|
106
177
|
|
|
107
178
|
let box = ${AABB3_STRUCT.wgsl_ref}(centre - half_extent, centre + half_extent);
|
|
108
179
|
|
|
109
|
-
|
|
180
|
+
let seen = instance.strand_count > 0u && aabb3_intersects_frustum(box, camera.frustum);
|
|
181
|
+
|
|
182
|
+
// the world size of a pixel the strands are thinned at, and the narrowest they are drawn, pixels; negative where
|
|
183
|
+
// no view draws them
|
|
184
|
+
var pixel_size = -1.0;
|
|
185
|
+
var floor_pixels = settings.pixel_floor;
|
|
186
|
+
|
|
187
|
+
lod.fixed_pixel = -1.0;
|
|
188
|
+
|
|
189
|
+
if (seen) {
|
|
110
190
|
var depth_near = 3.4e38;
|
|
111
191
|
var depth_far = -3.4e38;
|
|
112
192
|
|
|
@@ -119,8 +199,8 @@ fn main(
|
|
|
119
199
|
}
|
|
120
200
|
|
|
121
201
|
let near = camera.clip_near_far.x;
|
|
122
|
-
|
|
123
|
-
|
|
202
|
+
|
|
203
|
+
pixel_size = hair_pixel_size(max(depth_near, near), settings.resolution.y);
|
|
124
204
|
|
|
125
205
|
// a kept strand is widened by the reciprocal of its share, which is least at the far side of the box: the
|
|
126
206
|
// rectangle holds the widest it can be drawn
|
|
@@ -157,6 +237,17 @@ fn main(
|
|
|
157
237
|
|
|
158
238
|
lod.rect_min = hair_pack_pixel(floor(max(rect_min - margin, vec2<f32>(0.0))));
|
|
159
239
|
lod.rect_max = hair_pack_pixel(ceil(min(rect_max + margin, settings.resolution)));
|
|
240
|
+
} else if (instance.strand_count > 0u && settings.shadow_view_count > 0u) {
|
|
241
|
+
// off the view, but it may cast into it: thinned at the finest texel of the shadow views that hold it, to a
|
|
242
|
+
// texel's width, the narrowest the shadow draw draws a strand
|
|
243
|
+
pixel_size = hair_shadow_texel(centre, half_extent);
|
|
244
|
+
floor_pixels = 1.0;
|
|
245
|
+
|
|
246
|
+
lod.fixed_pixel = pixel_size;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (pixel_size >= 0.0) {
|
|
250
|
+
let kept = hair_kept_fraction(instance.width_mean * lod.scale, pixel_size, floor_pixels);
|
|
160
251
|
|
|
161
252
|
var prefix = min(instance.strand_count, u32(ceil(kept * f32(instance.strand_count))));
|
|
162
253
|
|
|
@@ -181,7 +272,9 @@ fn main(
|
|
|
181
272
|
// the frame's points are full: the count asked for grows them for the frames after
|
|
182
273
|
prefix = 0u;
|
|
183
274
|
} else {
|
|
184
|
-
|
|
275
|
+
// the shadow views' own strands have a part of the class's region of their own, which the view's
|
|
276
|
+
// draws leave out
|
|
277
|
+
atomicAdd(&hair_counters[select(${HAIR_COUNTER_SHADOW_STRANDS}u, 0u, seen) + point_class], prefix);
|
|
185
278
|
|
|
186
279
|
lod.point_base = base;
|
|
187
280
|
}
|
|
@@ -193,26 +286,20 @@ fn main(
|
|
|
193
286
|
|
|
194
287
|
// the density volume: cubes a pixel across at the box's nearest point, and no finer than the strands laid into
|
|
195
288
|
// it are apart, the roots' spacing over the root of the share kept: finer would resolve single strands, which
|
|
196
|
-
// the thinning moves as the distance changes; no more than the limit along the box's longest side
|
|
197
|
-
|
|
289
|
+
// the thinning moves as the distance changes; no more than the limit along the box's longest side. Only the
|
|
290
|
+
// view lights the strands: those only the shadow views draw have none
|
|
291
|
+
if (prefix > 0u && seen) {
|
|
198
292
|
let size = 2.0 * half_extent;
|
|
199
293
|
let spacing = instance.root_spacing * lod.scale / sqrt(max(kept, 1e-6));
|
|
200
294
|
let edge = max(max(pixel_size, spacing), max(size.x, max(size.y, size.z)) / ${HAIR_VOLUME_DIMENSION_LIMIT}.0);
|
|
201
295
|
let dims = clamp(vec3<u32>(ceil(size / edge)), vec3<u32>(1u), vec3<u32>(${HAIR_VOLUME_DIMENSION_LIMIT}u));
|
|
202
296
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
voxels += n;
|
|
211
|
-
|
|
212
|
-
if (mip > 0u) {
|
|
213
|
-
coarser += n;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
297
|
+
// a level's voxels: the level under it halved, rounded up
|
|
298
|
+
let d1 = (dims + vec3<u32>(1u)) >> vec3<u32>(1u);
|
|
299
|
+
let d2 = (dims + vec3<u32>(3u)) >> vec3<u32>(2u);
|
|
300
|
+
let n1 = d1.x * d1.y * d1.z;
|
|
301
|
+
let n2 = d2.x * d2.y * d2.z;
|
|
302
|
+
let voxels = dims.x * dims.y * dims.z + n1 + n2;
|
|
216
303
|
|
|
217
304
|
let base = atomicAdd(&hair_counters[${HAIR_COUNTER_VOXELS}u], voxels);
|
|
218
305
|
|
|
@@ -223,7 +310,8 @@ fn main(
|
|
|
223
310
|
lod.volume_dims = dims;
|
|
224
311
|
lod.volume_origin = centre - 0.5 * edge * vec3<f32>(dims);
|
|
225
312
|
|
|
226
|
-
|
|
313
|
+
hair_mip_1_counts.elements[row] = n1;
|
|
314
|
+
hair_mip_2_counts.elements[row] = n2;
|
|
227
315
|
}
|
|
228
316
|
}
|
|
229
317
|
}
|
|
@@ -241,7 +329,12 @@ fn main(
|
|
|
241
329
|
/**
|
|
242
330
|
* Each instance's level of detail for the frame, a thread a row of the instance table through its page iterator:
|
|
243
331
|
*
|
|
244
|
-
* - its group's box, in the world, against the view's frustum
|
|
332
|
+
* - its group's box, in the world, against the view's frustum. A simulated group's box is its guides' bounds as the
|
|
333
|
+
* solver gathered them (`hair_guide_bounds`), widened by its reach and its widest strand. An instance outside the
|
|
334
|
+
* frustum is drawn only by the shadow views (`hair_shadow_views`, the first `settings.shadow_view_count`) its box
|
|
335
|
+
* reaches into, their near planes aside, and by no view where it reaches none. It is then thinned at the finest of
|
|
336
|
+
* their texels to a texel's width (`fixed_pixel`), its strands are counted apart from the view's
|
|
337
|
+
* (`HAIR_COUNTER_SHADOW_STRANDS`), and it has no rectangle and no volume;
|
|
245
338
|
* - its screen rectangle: the box widened by the widest a kept strand is drawn (its widest point over its share kept
|
|
246
339
|
* at the box's far side), projected, and widened again by the pixel floor; or the whole view when the box reaches
|
|
247
340
|
* behind the eye;
|
|
@@ -253,8 +346,9 @@ fn main(
|
|
|
253
346
|
* spacing (the roots' over the root of the share kept) and the box's longest side over
|
|
254
347
|
* `HAIR_VOLUME_DIMENSION_LIMIT`, every level reserved from the frame's voxels.
|
|
255
348
|
*
|
|
256
|
-
* Writes the row's points, `prefix × (2^class + 1)`, into `hair_counts`, the list the cull's scan sums; its
|
|
257
|
-
*
|
|
349
|
+
* Writes the row's points, `prefix × (2^class + 1)`, into `hair_counts`, the list the cull's scan sums; its voxels
|
|
350
|
+
* of level 1 and of level 2 into `hair_mip_1_counts` and `hair_mip_2_counts`, the lists the mip passes' scans sum;
|
|
351
|
+
* and its record into `hair_lod`. Rows it does
|
|
258
352
|
* not visit keep what the buffers were cleared to. `hair_counters` is zero on entry. Points past
|
|
259
353
|
* `settings.point_capacity` are refused: the instance draws nothing this frame, and the count it asked for stays
|
|
260
354
|
* in the counters for its owner to read.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export const HAIR_ROOTS_SETTINGS: WebGPUStruct;
|
|
2
|
+
/**
|
|
3
|
+
* A triangle's frame, Unreal's: the tangent along its first edge, the normal of its face, the bitangent the normal
|
|
4
|
+
* across the tangent, as the columns of a rotation:
|
|
5
|
+
*
|
|
6
|
+
* ```wgsl
|
|
7
|
+
* fn hair_triangle_frame(a: vec3<f32>, b: vec3<f32>, c: vec3<f32>) -> mat3x3<f32>
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* The same frame `groom_bind_to_mesh` records at the bind pose.
|
|
11
|
+
*
|
|
12
|
+
* @type {CodeChunk}
|
|
13
|
+
*/
|
|
14
|
+
export const chunk_hair_triangle_frame: CodeChunk;
|
|
15
|
+
/**
|
|
16
|
+
* Where each bound strand's root is: a thread a strand of every bound instance (`HAIR_SIMULATION.js`), the threads of
|
|
17
|
+
* a row found from the inclusive sums of the bound rows' strand counts.
|
|
18
|
+
*
|
|
19
|
+
* The strand's binding (`groom_bind_to_mesh`) names a triangle of the bound mesh, the root's weights on it, and the
|
|
20
|
+
* triangle's frame at the bind pose with the root's point as its origin. The same triangle where the mesh is now
|
|
21
|
+
* gives the frame again (`hair_triangle_frame`), and the strand's root frame is the turn and move from the rest frame
|
|
22
|
+
* to it, carried into the world by the mesh's world matrix: the groom's rest points are in the mesh's space at its
|
|
23
|
+
* bind pose, so a root on its triangle stays on it however the mesh deforms. The frame a frame ago is made the same
|
|
24
|
+
* way, from a skinned clone's previous positions, which its skinning blends against the mesh's world matrix as it is
|
|
25
|
+
* now (and so are carried by it), or a rigid mesh's own positions and its world matrix a frame ago.
|
|
26
|
+
*
|
|
27
|
+
* Both are written as affine rows into the instance's root frames in the guide state pool, and the strand's own root
|
|
28
|
+
* (which may stand off its triangle by its binding's distance), from the instance's own entity, is gathered into its row's guide bounds, reduced across the subgroup first.
|
|
29
|
+
*
|
|
30
|
+
* @type {ComputeShader}
|
|
31
|
+
*/
|
|
32
|
+
export const shader_hair_roots: ComputeShader;
|
|
33
|
+
import { WebGPUStruct } from "../shader/type/WebGPUStruct.js";
|
|
34
|
+
import { CodeChunk } from "../shader/compiler/CodeChunk.js";
|
|
35
|
+
import { ComputeShader } from "../shader/ComputeShader.js";
|
|
36
|
+
//# sourceMappingURL=shader_hair_roots.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shader_hair_roots.d.ts","sourceRoot":"","sources":["../../../../../src/shade/renderer/hair/shader_hair_roots.js"],"names":[],"mappings":"AAsBA,+CAGwB;AAkBxB;;;;;;;;;;;GAWG;AACH,wCAFU,SAAS,CAWhB;AA+KH;;;;;;;;;;;;;;;;GAgBG;AACH,gCAFU,aAAa,CAMpB;6BApP0B,gCAAgC;0BAPnC,iCAAiC;8BAE7B,4BAA4B"}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { GROOM_BINDING_WORDS } from "../../../engine/graphics/hair/groom_bind_to_mesh.js";
|
|
2
|
+
import { COLLECTION_U32_STRUCT_READ } from "../gpu_primitive/COLLECTION_U32_STRUCT_READ.js";
|
|
3
|
+
import { GEOMETRY_ATTRIBUTE_DATA_TYPE } from "../geometry/GEOMETRY_ATTRIBUTE_DATA_TYPE.js";
|
|
4
|
+
import { MESHLET_METADATA_STRUCT } from "../geometry/meshlet/encoding/MESHLET_METADATA_STRUCT.js";
|
|
5
|
+
import { chunk_scene_database_access } from "../scene/chunk_scene_database_access.js";
|
|
6
|
+
import { chunk_read_meshlet_triangle_positions } from "../shader/chunk/geometry/meshlet/chunk_read_meshlet_triangle_positions.js";
|
|
7
|
+
import { chunk_read_meshlet_resolved_index } from "../shader/chunk/geometry/meshlet/chunk_read_meshlet_resolved_index.js";
|
|
8
|
+
import { chunk_folded_workgroup_index } from "../shader/chunk/grid/chunk_folded_workgroup_index.js";
|
|
9
|
+
import { chunk_lower_bound_branchless } from "../shader/chunk/math/chunk_lower_bound_branchless.js";
|
|
10
|
+
import { CodeChunk } from "../shader/compiler/CodeChunk.js";
|
|
11
|
+
import { COMPUTE_SHADER_DEFAULT_GROUP_SIZE } from "../shader/COMPUTE_SHADER_DEFAULT_GROUP_SIZE.js";
|
|
12
|
+
import { ComputeShader } from "../shader/ComputeShader.js";
|
|
13
|
+
import { ShaderResourceSetDescriptor } from "../shader/resource/ShaderResourceSetDescriptor.js";
|
|
14
|
+
import { atomic_u32, u32, vec4f } from "../shader/type/WEBGPU_WGSL_PRIMITIVE_TYPES.js";
|
|
15
|
+
import { WebGPUArray } from "../shader/type/WebGPUArray.js";
|
|
16
|
+
import { WebGPUBufferType } from "../shader/type/WebGPUBufferType.js";
|
|
17
|
+
import { WebGPUStruct } from "../shader/type/WebGPUStruct.js";
|
|
18
|
+
import { WebGPUExtensionType } from "../../descriptor/WebGPUExtensionType.js";
|
|
19
|
+
import { chunk_hair_rest_point, HAIR_GROOMS_RESOURCE } from "./chunk_hair_strand.js";
|
|
20
|
+
import { HAIR_INSTANCE_DESCRIPTOR } from "./HAIR_DATABASE_SPEC.js";
|
|
21
|
+
import { HAIR_BINDING_NONE, HAIR_GUIDE_BOUNDS_WORDS, HAIR_ROOT_FRAME_VECTORS } from "./HAIR_SIMULATION.js";
|
|
22
|
+
|
|
23
|
+
export const HAIR_ROOTS_SETTINGS = WebGPUStruct.from({
|
|
24
|
+
/** 1 when the skinning's previous positions are bound, 0 when its buffers are placeholders */
|
|
25
|
+
skinning_active: u32,
|
|
26
|
+
}, "HairRootsSettings");
|
|
27
|
+
|
|
28
|
+
const resources = new ShaderResourceSetDescriptor();
|
|
29
|
+
|
|
30
|
+
resources.setImmediate("settings", HAIR_ROOTS_SETTINGS);
|
|
31
|
+
|
|
32
|
+
resources.createGroup()
|
|
33
|
+
.add(HAIR_GROOMS_RESOURCE)
|
|
34
|
+
.addStorageBuffer("hair_database", WebGPUBufferType.unsized, false)
|
|
35
|
+
.addStorageBuffer("scene_database", WebGPUBufferType.unsized, false)
|
|
36
|
+
.addStorageBuffer("root_sums", COLLECTION_U32_STRUCT_READ, false)
|
|
37
|
+
.addStorageBuffer("meshlet_metadata", WebGPUArray.from(MESHLET_METADATA_STRUCT), false)
|
|
38
|
+
.addStorageBuffer("meshlet_data", GEOMETRY_ATTRIBUTE_DATA_TYPE, false)
|
|
39
|
+
.addStorageBuffer("prev_position_offsets", WebGPUArray.from(u32), false)
|
|
40
|
+
.addStorageBuffer("prev_positions", WebGPUArray.from(u32), false)
|
|
41
|
+
.addStorageBuffer("hair_guide_state", WebGPUArray.from(vec4f), true)
|
|
42
|
+
.addStorageBuffer("hair_guide_bounds", WebGPUArray.from(atomic_u32), true);
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* A triangle's frame, Unreal's: the tangent along its first edge, the normal of its face, the bitangent the normal
|
|
46
|
+
* across the tangent, as the columns of a rotation:
|
|
47
|
+
*
|
|
48
|
+
* ```wgsl
|
|
49
|
+
* fn hair_triangle_frame(a: vec3<f32>, b: vec3<f32>, c: vec3<f32>) -> mat3x3<f32>
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* The same frame `groom_bind_to_mesh` records at the bind pose.
|
|
53
|
+
*
|
|
54
|
+
* @type {CodeChunk}
|
|
55
|
+
*/
|
|
56
|
+
export const chunk_hair_triangle_frame = CodeChunk.from(
|
|
57
|
+
//language=WGSL
|
|
58
|
+
`
|
|
59
|
+
fn hair_triangle_frame(a: vec3<f32>, b: vec3<f32>, c: vec3<f32>) -> mat3x3<f32> {
|
|
60
|
+
let tangent = normalize(b - a);
|
|
61
|
+
let normal = normalize(cross(b - a, c - a));
|
|
62
|
+
|
|
63
|
+
return mat3x3<f32>(tangent, cross(normal, tangent), normal);
|
|
64
|
+
}
|
|
65
|
+
`);
|
|
66
|
+
|
|
67
|
+
const body = CodeChunk.from(
|
|
68
|
+
//language=WGSL
|
|
69
|
+
`
|
|
70
|
+
// a float as a u32 that orders as the float does
|
|
71
|
+
fn hair_root_ordered(v: f32) -> u32 {
|
|
72
|
+
let bits = bitcast<u32>(v);
|
|
73
|
+
|
|
74
|
+
return bits ^ select(0x80000000u, 0xFFFFFFFFu, (bits & 0x80000000u) != 0u);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
fn hair_previous_position(base: u32, vertex: u32) -> vec3<f32> {
|
|
78
|
+
let at = base + vertex * 3u;
|
|
79
|
+
|
|
80
|
+
return vec3<f32>(bitcast<f32>(prev_positions[at]), bitcast<f32>(prev_positions[at + 1u]), bitcast<f32>(prev_positions[at + 2u]));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// a frame as the rows of an affine 3 x 4 matrix, into the pool
|
|
84
|
+
fn hair_write_root_frame(at: u32, linear: mat3x3<f32>, origin: vec3<f32>) {
|
|
85
|
+
hair_guide_state[at] = vec4<f32>(linear[0].x, linear[1].x, linear[2].x, origin.x);
|
|
86
|
+
hair_guide_state[at + 1u] = vec4<f32>(linear[0].y, linear[1].y, linear[2].y, origin.y);
|
|
87
|
+
hair_guide_state[at + 2u] = vec4<f32>(linear[0].z, linear[1].z, linear[2].z, origin.z);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// a bound strand's root frames, written; its root from the instance's own entity, returned
|
|
91
|
+
fn hair_root_place(instance: ${HAIR_INSTANCE_DESCRIPTOR.type.wgsl_ref}, strand: u32) -> vec3<f32> {
|
|
92
|
+
// the binding: the triangle, the root's weights on it, its rest frame and the root's rest point on it
|
|
93
|
+
let at = instance.bindings + strand * ${GROOM_BINDING_WORDS}u;
|
|
94
|
+
|
|
95
|
+
let triangle = hair_grooms[at];
|
|
96
|
+
let wa = bitcast<f32>(hair_grooms[at + 1u]);
|
|
97
|
+
let wb = bitcast<f32>(hair_grooms[at + 2u]);
|
|
98
|
+
let wc = 1.0 - wa - wb;
|
|
99
|
+
|
|
100
|
+
let rest_tangent = bitcast<vec3<f32>>(vec3<u32>(hair_grooms[at + 4u], hair_grooms[at + 5u], hair_grooms[at + 6u]));
|
|
101
|
+
let rest_bitangent = bitcast<vec3<f32>>(vec3<u32>(hair_grooms[at + 8u], hair_grooms[at + 9u], hair_grooms[at + 10u]));
|
|
102
|
+
let rest_normal = bitcast<vec3<f32>>(vec3<u32>(hair_grooms[at + 12u], hair_grooms[at + 13u], hair_grooms[at + 14u]));
|
|
103
|
+
let rest_origin = bitcast<vec3<f32>>(vec3<u32>(hair_grooms[at + 7u], hair_grooms[at + 11u], hair_grooms[at + 15u]));
|
|
104
|
+
|
|
105
|
+
// the rest frame's inverse: its transpose
|
|
106
|
+
let unrest = transpose(mat3x3<f32>(rest_tangent, rest_bitangent, rest_normal));
|
|
107
|
+
|
|
108
|
+
let meshlet = instance.meshlet_base + (triangle >> 8u);
|
|
109
|
+
let corner = triangle & 0xFFu;
|
|
110
|
+
|
|
111
|
+
// the triangle where the mesh is now, in its own space: a skinned clone's meshlets hold its deformed positions
|
|
112
|
+
let now = read_meshlet_triangle_positions(meshlet, corner);
|
|
113
|
+
|
|
114
|
+
let node = scene_read_node(&scene_database, instance.mesh_node);
|
|
115
|
+
let g = node.global;
|
|
116
|
+
let g_linear = mat3x3<f32>(g[0].xyz, g[1].xyz, g[2].xyz);
|
|
117
|
+
|
|
118
|
+
// a frame ago: a skinned clone's previous positions, which its skinning blends against the mesh's world matrix
|
|
119
|
+
// as it is now, so the world matrix now carries them; a rigid mesh's are its own, carried by its world matrix then
|
|
120
|
+
var before = now;
|
|
121
|
+
var g_before = g;
|
|
122
|
+
|
|
123
|
+
// the table covers the clones' rows; a rigid mesh's rows may lie past it
|
|
124
|
+
let listed = settings.skinning_active != 0u && meshlet < arrayLength(&prev_position_offsets);
|
|
125
|
+
let previous = select(0xFFFFFFFFu, prev_position_offsets[min(meshlet, arrayLength(&prev_position_offsets) - 1u)], listed);
|
|
126
|
+
|
|
127
|
+
if (previous != 0xFFFFFFFFu) {
|
|
128
|
+
let header = meshlet_metadata[meshlet];
|
|
129
|
+
let last_vertex = header.vertex_count - 1u;
|
|
130
|
+
|
|
131
|
+
before.a = hair_previous_position(previous, min(read_meshlet_resolved_index(header, corner * 3u), last_vertex));
|
|
132
|
+
before.b = hair_previous_position(previous, min(read_meshlet_resolved_index(header, corner * 3u + 1u), last_vertex));
|
|
133
|
+
before.c = hair_previous_position(previous, min(read_meshlet_resolved_index(header, corner * 3u + 2u), last_vertex));
|
|
134
|
+
} else {
|
|
135
|
+
g_before = node.prev_global;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
let g_before_linear = mat3x3<f32>(g_before[0].xyz, g_before[1].xyz, g_before[2].xyz);
|
|
139
|
+
|
|
140
|
+
// the turn and move from the rest frame to the frame now, in the mesh's space, then into the world
|
|
141
|
+
let turn = hair_triangle_frame(now.a, now.b, now.c) * unrest;
|
|
142
|
+
let origin = now.a * wa + now.b * wb + now.c * wc;
|
|
143
|
+
|
|
144
|
+
let turn_before = hair_triangle_frame(before.a, before.b, before.c) * unrest;
|
|
145
|
+
let origin_before = before.a * wa + before.b * wb + before.c * wc;
|
|
146
|
+
|
|
147
|
+
let out = instance.roots + strand * ${HAIR_ROOT_FRAME_VECTORS}u;
|
|
148
|
+
|
|
149
|
+
hair_write_root_frame(out, g_linear * turn, g_linear * (origin - turn * rest_origin) + g[3].xyz);
|
|
150
|
+
hair_write_root_frame(out + 3u, g_before_linear * turn_before, g_before_linear * (origin_before - turn_before * rest_origin) + g_before[3].xyz);
|
|
151
|
+
|
|
152
|
+
let anchor = scene_read_node(&scene_database, instance.node).global[3].xyz;
|
|
153
|
+
|
|
154
|
+
// the strand's own root, which may stand off its triangle by its binding's distance
|
|
155
|
+
return g_linear * (origin + turn * (hair_rest_point(instance, strand, 0u).xyz - rest_origin)) + g[3].xyz - anchor;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// the roots into their rows' bounds: a round a row the subgroup holds, the round's lanes reduced and the first of
|
|
159
|
+
// them gathering for all, so a row's bounds take one atomic a subgroup rather than one a strand. Called by every lane,
|
|
160
|
+
// in subgroup-uniform control flow; a lane with no root holds ${HAIR_BINDING_NONE}.
|
|
161
|
+
// the trip count is uniform across the subgroup by construction: every lane sees the same minimum
|
|
162
|
+
@diagnostic(off, subgroup_uniformity)
|
|
163
|
+
fn hair_root_gather(key: u32, root: vec3<f32>) {
|
|
164
|
+
var outstanding = key;
|
|
165
|
+
|
|
166
|
+
let high = vec3<u32>(hair_root_ordered(root.x), hair_root_ordered(root.y), hair_root_ordered(root.z));
|
|
167
|
+
let low = ~high;
|
|
168
|
+
|
|
169
|
+
loop {
|
|
170
|
+
let round = subgroupMin(outstanding);
|
|
171
|
+
|
|
172
|
+
if (round == ${HAIR_BINDING_NONE}u) {
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
let in_round = outstanding == round;
|
|
177
|
+
let first = subgroupExclusiveAdd(select(0u, 1u, in_round)) == 0u;
|
|
178
|
+
|
|
179
|
+
let round_high = subgroupMax(select(vec3<u32>(0u), high, in_round));
|
|
180
|
+
let round_low = subgroupMax(select(vec3<u32>(0u), low, in_round));
|
|
181
|
+
|
|
182
|
+
if (in_round && first) {
|
|
183
|
+
let at = round * ${HAIR_GUIDE_BOUNDS_WORDS}u;
|
|
184
|
+
|
|
185
|
+
atomicMax(&hair_guide_bounds[at], round_high.x);
|
|
186
|
+
atomicMax(&hair_guide_bounds[at + 1u], round_high.y);
|
|
187
|
+
atomicMax(&hair_guide_bounds[at + 2u], round_high.z);
|
|
188
|
+
atomicMax(&hair_guide_bounds[at + 3u], round_low.x);
|
|
189
|
+
atomicMax(&hair_guide_bounds[at + 4u], round_low.y);
|
|
190
|
+
atomicMax(&hair_guide_bounds[at + 5u], round_low.z);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (in_round) {
|
|
194
|
+
outstanding = ${HAIR_BINDING_NONE}u;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
@compute @workgroup_size(${COMPUTE_SHADER_DEFAULT_GROUP_SIZE})
|
|
200
|
+
fn main(@builtin(workgroup_id) workgroup_id: vec3<u32>, @builtin(local_invocation_index) lane: u32) {
|
|
201
|
+
let thread = folded_workgroup_index(workgroup_id) * ${COMPUTE_SHADER_DEFAULT_GROUP_SIZE}u + lane;
|
|
202
|
+
|
|
203
|
+
// the sums are inclusive: a thread belongs to the first row whose sum is past it
|
|
204
|
+
let rows = root_sums.count;
|
|
205
|
+
let row = lower_bound_branchless(&root_sums.elements, thread + 1u, rows);
|
|
206
|
+
|
|
207
|
+
var key = ${HAIR_BINDING_NONE}u;
|
|
208
|
+
var root = vec3<f32>(0.0);
|
|
209
|
+
|
|
210
|
+
if (row < rows) {
|
|
211
|
+
var strand = thread;
|
|
212
|
+
|
|
213
|
+
if (row > 0u) {
|
|
214
|
+
strand -= root_sums.elements[row - 1u];
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
let instance = ${HAIR_INSTANCE_DESCRIPTOR.marshalling_method_read}(&hair_database, row);
|
|
218
|
+
|
|
219
|
+
if (instance.mesh_node != ${HAIR_BINDING_NONE}u && strand < instance.strand_count) {
|
|
220
|
+
root = hair_root_place(instance, strand);
|
|
221
|
+
key = row;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
hair_root_gather(key, root);
|
|
226
|
+
}
|
|
227
|
+
`, [
|
|
228
|
+
HAIR_INSTANCE_DESCRIPTOR.chunk_read,
|
|
229
|
+
chunk_folded_workgroup_index,
|
|
230
|
+
chunk_lower_bound_branchless,
|
|
231
|
+
chunk_scene_database_access,
|
|
232
|
+
chunk_read_meshlet_triangle_positions,
|
|
233
|
+
chunk_read_meshlet_resolved_index,
|
|
234
|
+
chunk_hair_triangle_frame,
|
|
235
|
+
chunk_hair_rest_point,
|
|
236
|
+
]);
|
|
237
|
+
|
|
238
|
+
body.addExtension(WebGPUExtensionType.Subgroups);
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Where each bound strand's root is: a thread a strand of every bound instance (`HAIR_SIMULATION.js`), the threads of
|
|
242
|
+
* a row found from the inclusive sums of the bound rows' strand counts.
|
|
243
|
+
*
|
|
244
|
+
* The strand's binding (`groom_bind_to_mesh`) names a triangle of the bound mesh, the root's weights on it, and the
|
|
245
|
+
* triangle's frame at the bind pose with the root's point as its origin. The same triangle where the mesh is now
|
|
246
|
+
* gives the frame again (`hair_triangle_frame`), and the strand's root frame is the turn and move from the rest frame
|
|
247
|
+
* to it, carried into the world by the mesh's world matrix: the groom's rest points are in the mesh's space at its
|
|
248
|
+
* bind pose, so a root on its triangle stays on it however the mesh deforms. The frame a frame ago is made the same
|
|
249
|
+
* way, from a skinned clone's previous positions, which its skinning blends against the mesh's world matrix as it is
|
|
250
|
+
* now (and so are carried by it), or a rigid mesh's own positions and its world matrix a frame ago.
|
|
251
|
+
*
|
|
252
|
+
* Both are written as affine rows into the instance's root frames in the guide state pool, and the strand's own root
|
|
253
|
+
* (which may stand off its triangle by its binding's distance), from the instance's own entity, is gathered into its row's guide bounds, reduced across the subgroup first.
|
|
254
|
+
*
|
|
255
|
+
* @type {ComputeShader}
|
|
256
|
+
*/
|
|
257
|
+
export const shader_hair_roots = ComputeShader.from({
|
|
258
|
+
label: "Hair Roots",
|
|
259
|
+
resources,
|
|
260
|
+
body,
|
|
261
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shadow views' lists, as the passes below share them.
|
|
3
|
+
*
|
|
4
|
+
* **A shadow view's list** is laid out as the frame's draw list is (`HAIR.js`): view `v`'s from entry
|
|
5
|
+
* `v × list capacity`, each class's region from the draw list's start of it, its strands from the region's start, as
|
|
6
|
+
* many as the view's count of the class (`hair_shadow_counts`, `v × HAIR_CLASS_COUNT + class`).
|
|
7
|
+
*/
|
|
8
|
+
export const HAIR_SHADOW_LIST_SETTINGS: WebGPUStruct;
|
|
9
|
+
/**
|
|
10
|
+
* The folded command {@link shader_hair_shadow_list} is dispatched through: a thread for each entry of the frame's
|
|
11
|
+
* draw list in each shadow view. One thread.
|
|
12
|
+
*
|
|
13
|
+
* @type {ComputeShader}
|
|
14
|
+
*/
|
|
15
|
+
export const shader_hair_shadow_list_command: ComputeShader;
|
|
16
|
+
/**
|
|
17
|
+
* Lists, for each shadow view, the strands of the frame's draw list that it draws, a thread an entry of the list in
|
|
18
|
+
* a view (views apart by the list's entries), dispatched through {@link shader_hair_shadow_list_command}'s command.
|
|
19
|
+
*
|
|
20
|
+
* An entry is read where the cull wrote one: in its class's region, among the strands listed for the view or among
|
|
21
|
+
* those listed for the shadow views alone. The strand is drawn by the view when both hold:
|
|
22
|
+
*
|
|
23
|
+
* - the ball about its root as wide as its reach (its shadow words) is inside the view's planes, the near one aside;
|
|
24
|
+
* - its widest point, at the finest the view's texels are within that ball, is drawn by the shadow draw: wider than
|
|
25
|
+
* its stratified share of half a texel, the share and the test of `hair_shadow_draw.js`. Where the ball reaches
|
|
26
|
+
* the eye of a perspective view, its texels are not bounded, and the strand is drawn.
|
|
27
|
+
*
|
|
28
|
+
* A drawn strand is appended to its class's region of the view's list (`chunk_subgroup_keyed_append` on the view's
|
|
29
|
+
* count of the class).
|
|
30
|
+
*
|
|
31
|
+
* @type {ComputeShader}
|
|
32
|
+
*/
|
|
33
|
+
export const shader_hair_shadow_list: ComputeShader;
|
|
34
|
+
/**
|
|
35
|
+
* The shadow draw's indirect draws, one a point class of each shadow view (`HAIR_DRAW_ARGS_WORDS` words each, at
|
|
36
|
+
* `view × HAIR_CLASS_COUNT + class`): as the id raster's (`shader_hair_draw_args`), over the class's region of the
|
|
37
|
+
* view's list. A workgroup a view, a thread a class.
|
|
38
|
+
*
|
|
39
|
+
* @type {ComputeShader}
|
|
40
|
+
*/
|
|
41
|
+
export const shader_hair_shadow_draw_args: ComputeShader;
|
|
42
|
+
import { WebGPUStruct } from "../shader/type/WebGPUStruct.js";
|
|
43
|
+
import { ComputeShader } from "../shader/ComputeShader.js";
|
|
44
|
+
//# sourceMappingURL=shader_hair_shadow_list.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shader_hair_shadow_list.d.ts","sourceRoot":"","sources":["../../../../../src/shade/renderer/hair/shader_hair_shadow_list.js"],"names":[],"mappings":"AA2BA;;;;;;GAMG;AAEH,qDAK6B;AA6B7B;;;;;GAKG;AACH,8CAFU,aAAa,CAkBpB;AAcH;;;;;;;;;;;;;;;;GAgBG;AACH,sCAFU,aAAa,CA8EpB;AAWH;;;;;;GAMG;AACH,2CAFU,aAAa,CAyBpB;6BAjO0B,gCAAgC;8BAJ/B,4BAA4B"}
|