@woosh/meep-engine 3.74.0 → 3.75.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 (161) hide show
  1. package/CHANGELOG.md +20 -19
  2. package/package.json +1 -1
  3. package/src/core/geom/2d/hilbert/v2_hilbert_encode.d.ts +11 -0
  4. package/src/core/geom/2d/hilbert/v2_hilbert_encode.d.ts.map +1 -0
  5. package/src/core/geom/2d/hilbert/v2_hilbert_encode.js +46 -0
  6. package/src/engine/graphics/render/frame_graph/FrameGraph.d.ts +6 -0
  7. package/src/engine/graphics/render/frame_graph/FrameGraph.d.ts.map +1 -1
  8. package/src/engine/graphics/render/frame_graph/FrameGraph.js +9 -0
  9. package/src/engine/graphics3/GPUAcousticSystem.d.ts +29 -32
  10. package/src/engine/graphics3/GPUAcousticSystem.d.ts.map +1 -1
  11. package/src/engine/graphics3/GPUAcousticSystem.js +87 -162
  12. package/src/engine/physics/fluid/ecs/FluidObstacleSystem.d.ts +4 -4
  13. package/src/engine/sound/ecs/audio/AudioEmitterSystem.d.ts.map +1 -1
  14. package/src/engine/sound/ecs/audio/AudioEmitterSystem.js +35 -17
  15. package/src/engine/sound/ecs/audio/LiveEmitterSet.d.ts.map +1 -1
  16. package/src/engine/sound/ecs/audio/LiveEmitterSet.js +2 -3
  17. package/src/engine/sound/simulation/AcousticSimulator.d.ts +7 -0
  18. package/src/engine/sound/simulation/AcousticSimulator.d.ts.map +1 -1
  19. package/src/engine/sound/simulation/AcousticSimulator.js +27 -0
  20. package/src/engine/sound/simulation/README.md +121 -107
  21. package/src/engine/sound/sopra/README.md +8 -3
  22. package/src/engine/sound/sopra/definition/effect/AcousticReverbEffect.d.ts +2 -2
  23. package/src/engine/sound/sopra/definition/effect/AcousticReverbEffect.d.ts.map +1 -1
  24. package/src/engine/sound/sopra/definition/effect/AcousticReverbEffect.js +4 -3
  25. package/src/engine/sound/sopra/runtime/AcousticReverbConvolution.d.ts +118 -0
  26. package/src/engine/sound/sopra/runtime/AcousticReverbConvolution.d.ts.map +1 -0
  27. package/src/engine/sound/sopra/runtime/AcousticReverbConvolution.js +472 -0
  28. package/src/engine/sound/sopra/runtime/AcousticReverbLines.d.ts +166 -0
  29. package/src/engine/sound/sopra/runtime/AcousticReverbLines.d.ts.map +1 -0
  30. package/src/engine/sound/sopra/runtime/AcousticReverbLines.js +447 -0
  31. package/src/engine/sound/sopra/runtime/AcousticReverbNetwork.d.ts +69 -113
  32. package/src/engine/sound/sopra/runtime/AcousticReverbNetwork.d.ts.map +1 -1
  33. package/src/engine/sound/sopra/runtime/AcousticReverbNetwork.js +143 -491
  34. package/src/engine/sound/sopra/runtime/AcousticSpeakers.d.ts +102 -0
  35. package/src/engine/sound/sopra/runtime/AcousticSpeakers.d.ts.map +1 -0
  36. package/src/engine/sound/sopra/runtime/AcousticSpeakers.js +232 -0
  37. package/src/engine/sound/sopra/runtime/BusGraph.d.ts +17 -3
  38. package/src/engine/sound/sopra/runtime/BusGraph.d.ts.map +1 -1
  39. package/src/engine/sound/sopra/runtime/BusGraph.js +55 -5
  40. package/src/engine/sound/sopra/runtime/EventInstance.d.ts +8 -6
  41. package/src/engine/sound/sopra/runtime/EventInstance.d.ts.map +1 -1
  42. package/src/engine/sound/sopra/runtime/EventInstance.js +113 -105
  43. package/src/engine/sound/sopra/runtime/acoustic_reverb_decay.d.ts +13 -0
  44. package/src/engine/sound/sopra/runtime/acoustic_reverb_decay.d.ts.map +1 -0
  45. package/src/engine/sound/sopra/runtime/acoustic_reverb_decay.js +15 -0
  46. package/src/generation/grid/generation/discrete/GridTaskConnectRooms.d.ts.map +1 -1
  47. package/src/generation/grid/generation/discrete/GridTaskConnectRooms.js +4 -6
  48. package/src/shade/playground/skinned_blas_refit/diff_traced_against_rasterized.d.ts.map +1 -1
  49. package/src/shade/playground/skinned_blas_refit/diff_traced_against_rasterized.js +4 -5
  50. package/src/shade/playground/skinned_blas_refit/main.d.ts.map +1 -1
  51. package/src/shade/playground/skinned_blas_refit/main.js +6 -12
  52. package/src/shade/playground/skinned_mesh_soup/main.d.ts.map +1 -1
  53. package/src/shade/playground/skinned_mesh_soup/main.js +1 -2
  54. package/src/shade/playground/vgeo_scene/README.md +12 -2
  55. package/src/shade/playground/vgeo_scene/main.js +1 -1
  56. package/src/shade/playground/volumetrics_froxel/README.md +191 -191
  57. package/src/shade/playground/volumetrics_froxel/measure.d.ts +3 -3
  58. package/src/shade/playground/volumetrics_froxel/measure.d.ts.map +1 -1
  59. package/src/shade/playground/volumetrics_froxel/measure.js +11 -13
  60. package/src/shade/playground/vsm/main.d.ts.map +1 -1
  61. package/src/shade/playground/vsm/main.js +5 -6
  62. package/src/shade/renderer/Renderer.d.ts.map +1 -1
  63. package/src/shade/renderer/Renderer.js +31 -8
  64. package/src/shade/renderer/acoustics/ACOUSTIC_LISTENER_RESOURCES.d.ts +28 -0
  65. package/src/shade/renderer/acoustics/ACOUSTIC_LISTENER_RESOURCES.d.ts.map +1 -0
  66. package/src/shade/renderer/acoustics/ACOUSTIC_LISTENER_RESOURCES.js +42 -0
  67. package/src/shade/renderer/acoustics/ACOUSTIC_PROBE_DATABASE_SPEC.d.ts +58 -0
  68. package/src/shade/renderer/acoustics/ACOUSTIC_PROBE_DATABASE_SPEC.d.ts.map +1 -0
  69. package/src/shade/renderer/acoustics/ACOUSTIC_PROBE_DATABASE_SPEC.js +108 -0
  70. package/src/shade/renderer/acoustics/GPUAcousticLattice.d.ts +1 -1
  71. package/src/shade/renderer/acoustics/GPUAcousticProbes.d.ts +161 -0
  72. package/src/shade/renderer/acoustics/GPUAcousticProbes.d.ts.map +1 -0
  73. package/src/shade/renderer/acoustics/GPUAcousticProbes.js +760 -0
  74. package/src/shade/renderer/acoustics/GPUAcoustics.d.ts +1 -1
  75. package/src/shade/renderer/acoustics/acoustic_listener_order.d.ts +12 -0
  76. package/src/shade/renderer/acoustics/acoustic_listener_order.d.ts.map +1 -0
  77. package/src/shade/renderer/acoustics/acoustic_listener_order.js +56 -0
  78. package/src/shade/renderer/acoustics/chunk_acoustic_direct.d.ts.map +1 -1
  79. package/src/shade/renderer/acoustics/chunk_acoustic_direct.js +5 -0
  80. package/src/shade/renderer/acoustics/chunk_acoustic_direct_cone.d.ts +57 -0
  81. package/src/shade/renderer/acoustics/chunk_acoustic_direct_cone.d.ts.map +1 -0
  82. package/src/shade/renderer/acoustics/chunk_acoustic_direct_cone.js +314 -0
  83. package/src/shade/renderer/acoustics/chunk_acoustic_finite.d.ts +15 -0
  84. package/src/shade/renderer/acoustics/chunk_acoustic_finite.d.ts.map +1 -0
  85. package/src/shade/renderer/acoustics/chunk_acoustic_finite.js +21 -0
  86. package/src/shade/renderer/acoustics/chunk_acoustic_gather.js +1 -1
  87. package/src/shade/renderer/acoustics/chunk_acoustic_lean.d.ts +27 -0
  88. package/src/shade/renderer/acoustics/chunk_acoustic_lean.d.ts.map +1 -0
  89. package/src/shade/renderer/acoustics/chunk_acoustic_lean.js +42 -0
  90. package/src/shade/renderer/acoustics/chunk_acoustic_listener.d.ts +80 -0
  91. package/src/shade/renderer/acoustics/chunk_acoustic_listener.d.ts.map +1 -0
  92. package/src/shade/renderer/acoustics/chunk_acoustic_listener.js +274 -0
  93. package/src/shade/renderer/acoustics/chunk_acoustic_partials.d.ts +2 -2
  94. package/src/shade/renderer/acoustics/chunk_acoustic_partials.js +2 -2
  95. package/src/shade/renderer/acoustics/chunk_acoustic_phonon.d.ts +7 -0
  96. package/src/shade/renderer/acoustics/chunk_acoustic_phonon.d.ts.map +1 -1
  97. package/src/shade/renderer/acoustics/chunk_acoustic_phonon.js +24 -1
  98. package/src/shade/renderer/acoustics/chunk_acoustic_resample.js +1 -1
  99. package/src/shade/renderer/acoustics/chunk_acoustic_reservoir.js +1 -1
  100. package/src/shade/renderer/acoustics/chunk_acoustic_through.d.ts +43 -0
  101. package/src/shade/renderer/acoustics/chunk_acoustic_through.d.ts.map +1 -0
  102. package/src/shade/renderer/acoustics/chunk_acoustic_through.js +153 -0
  103. package/src/shade/renderer/acoustics/chunk_acoustic_trace.d.ts +3 -1
  104. package/src/shade/renderer/acoustics/chunk_acoustic_trace.d.ts.map +1 -1
  105. package/src/shade/renderer/acoustics/chunk_acoustic_trace.js +10 -1
  106. package/src/shade/renderer/acoustics/shader_acoustic_combine.d.ts +7 -3
  107. package/src/shade/renderer/acoustics/shader_acoustic_combine.d.ts.map +1 -1
  108. package/src/shade/renderer/acoustics/shader_acoustic_combine.js +22 -6
  109. package/src/shade/renderer/acoustics/shader_acoustic_coupling.d.ts +14 -0
  110. package/src/shade/renderer/acoustics/shader_acoustic_coupling.d.ts.map +1 -0
  111. package/src/shade/renderer/acoustics/shader_acoustic_coupling.js +102 -0
  112. package/src/shade/renderer/acoustics/shader_acoustic_listener.d.ts +12 -0
  113. package/src/shade/renderer/acoustics/shader_acoustic_listener.d.ts.map +1 -0
  114. package/src/shade/renderer/acoustics/shader_acoustic_listener.js +80 -0
  115. package/src/shade/renderer/acoustics/shader_acoustic_receive.d.ts.map +1 -1
  116. package/src/shade/renderer/acoustics/shader_acoustic_receive.js +27 -6
  117. package/src/shade/renderer/acoustics/shader_acoustic_room.d.ts +11 -0
  118. package/src/shade/renderer/acoustics/shader_acoustic_room.d.ts.map +1 -0
  119. package/src/shade/renderer/acoustics/shader_acoustic_room.js +111 -0
  120. package/src/shade/renderer/acoustics/shader_acoustic_source.d.ts +18 -0
  121. package/src/shade/renderer/acoustics/shader_acoustic_source.d.ts.map +1 -0
  122. package/src/shade/renderer/acoustics/shader_acoustic_source.js +130 -0
  123. package/src/shade/renderer/fluid/GPUFluidCascade.d.ts +3 -3
  124. package/src/shade/renderer/fluid/GPUFluidCascadeStack.d.ts +1 -1
  125. package/src/shade/renderer/fluid/forcing/GPUFluidForcing.d.ts +7 -7
  126. package/src/shade/renderer/fluid/pressure/GPUFluidPressureSolve.d.ts +1 -1
  127. package/src/shade/renderer/fluid/query/GPUFluidQueries.d.ts +1 -1
  128. package/src/shade/renderer/geometry/virtual/build/level/VGeoFrontier.d.ts +2 -2
  129. package/src/shade/renderer/geometry/virtual/build/level/VGeoFrontier.js +2 -2
  130. package/src/shade/renderer/geometry/virtual/build/level/VGeoLevelOptions.d.ts +5 -2
  131. package/src/shade/renderer/geometry/virtual/build/level/VGeoLevelOptions.d.ts.map +1 -1
  132. package/src/shade/renderer/geometry/virtual/build/level/VGeoLevelOptions.js +5 -2
  133. package/src/shade/renderer/geometry/virtual/build/level/vgeo_build_group_step.d.ts +9 -2
  134. package/src/shade/renderer/geometry/virtual/build/level/vgeo_build_group_step.d.ts.map +1 -1
  135. package/src/shade/renderer/geometry/virtual/build/level/vgeo_build_group_step.js +48 -12
  136. package/src/shade/renderer/geometry/virtual/format/read/VGeoContainerReader.d.ts +0 -22
  137. package/src/shade/renderer/geometry/virtual/format/read/VGeoContainerReader.d.ts.map +1 -1
  138. package/src/shade/renderer/geometry/virtual/format/read/VGeoContainerReader.js +0 -42
  139. package/src/shade/renderer/geometry/virtual/format/read/VGeoReadOptions.d.ts +2 -18
  140. package/src/shade/renderer/geometry/virtual/format/read/VGeoReadOptions.d.ts.map +1 -1
  141. package/src/shade/renderer/geometry/virtual/format/read/VGeoReadOptions.js +2 -19
  142. package/src/shade/renderer/geometry/virtual/format/read/vgeo_page_worker_serve.d.ts.map +1 -1
  143. package/src/shade/renderer/geometry/virtual/format/read/vgeo_page_worker_serve.js +0 -1
  144. package/src/shade/renderer/geometry/virtual/runtime/GPUVirtualGeometryRuntime.d.ts +5 -4
  145. package/src/shade/renderer/geometry/virtual/runtime/GPUVirtualGeometryRuntime.d.ts.map +1 -1
  146. package/src/shade/renderer/geometry/virtual/runtime/GPUVirtualGeometryRuntime.js +3 -1
  147. package/src/shade/renderer/geometry/virtual/runtime/VGeoFeedbackLoop.d.ts.map +1 -1
  148. package/src/shade/renderer/geometry/virtual/runtime/VGeoFeedbackLoop.js +3 -1
  149. package/src/shade/renderer/geometry/virtual/runtime/VGeoPageFetcher.d.ts.map +1 -1
  150. package/src/shade/renderer/geometry/virtual/runtime/VGeoPageFetcher.js +0 -1
  151. package/src/shade/renderer/geometry/virtual/runtime/VGeoViewCut.d.ts +60 -14
  152. package/src/shade/renderer/geometry/virtual/runtime/VGeoViewCut.d.ts.map +1 -1
  153. package/src/shade/renderer/geometry/virtual/runtime/VGeoViewCut.js +75 -39
  154. package/src/shade/renderer/global_illumination/probe_clipmap/brick/GPUSceneBrickClipmap.d.ts +0 -9
  155. package/src/shade/renderer/global_illumination/probe_clipmap/brick/GPUSceneBrickClipmap.d.ts.map +1 -1
  156. package/src/shade/renderer/global_illumination/probe_clipmap/brick/GPUSceneBrickClipmap.js +45 -17
  157. package/src/shade/renderer/global_illumination/probe_clipmap/brick/chunk_brick_clipmap_trace.d.ts +7 -3
  158. package/src/shade/renderer/global_illumination/probe_clipmap/brick/chunk_brick_clipmap_trace.d.ts.map +1 -1
  159. package/src/shade/renderer/global_illumination/probe_clipmap/brick/chunk_brick_clipmap_trace.js +43 -7
  160. package/src/shade/renderer/loader/gltf/tiny-gltf.d.ts +1 -1
  161. package/src/shade/renderer/water/query/GPUWaterQueries.d.ts +1 -1
@@ -0,0 +1,153 @@
1
+ import { MESH_SDF_BRICK_VOXELS } from "../geometry/sdf/MESH_SDF.js";
2
+ import {
3
+ BRICK_TRACE_HIT_VOXELS,
4
+ BRICK_TRACE_STEPS,
5
+ chunk_brick_clipmap_distance,
6
+ chunk_brick_clipmap_trace
7
+ } from "../global_illumination/probe_clipmap/brick/chunk_brick_clipmap_trace.js";
8
+ import { CLIPMAP_LEVEL_LIMIT } from "../shader/chunk/clipmap/CLIPMAP_LEVEL_STRUCT.js";
9
+ import { chunk_aabb3_distance_to_ray_v2 } from "../shader/chunk/geometry/aabb3/chunk_aabb3_distance_to_ray_v2.js";
10
+ import { CodeChunk } from "../shader/compiler/CodeChunk.js";
11
+ import { chunk_acoustic_trace } from "./chunk_acoustic_trace.js";
12
+ import { chunk_brick_acoustics } from "./chunk_brick_acoustics.js";
13
+
14
+ /**
15
+ * Samples a ray reads between its first wall and its last: as many as a 0.5 m wall's half voxels at the finest
16
+ * cascade, so one wall's interval is read as finely as the tracer reads a surface. Chosen.
17
+ * @type {number}
18
+ */
19
+ export const ACOUSTIC_THROUGH_SAMPLES = 8;
20
+
21
+ /**
22
+ * The walls between a ray's first and its last, read at a fixed number of points; and what reaches a point from
23
+ * another through what stands between, by a trace from each end and that reading between them.
24
+ *
25
+ * ```wgsl
26
+ * fn acoustic_window_reach(origin: vec3<f32>, direction: vec3<f32>, distance: f32, cascade_count: u32) -> f32
27
+ * fn acoustic_through_interval(origin: vec3<f32>, direction: vec3<f32>, front: f32, back: f32, jitter: f32, shell: f32, back_passing: vec3<f32>, fallback: vec4<u32>, cascade_count: u32, atlas_shift: u32) -> vec4<f32>
28
+ * fn acoustic_through(origin: vec3<f32>, end: vec3<f32>, jitter: f32, fallback: vec4<u32>, cascade_count: u32, atlas_shift: u32) -> vec4<f32>
29
+ * ```
30
+ *
31
+ * `acoustic_window_reach`: how far along the ray, up to `distance`, it stays a voxel inside the coarsest window.
32
+ *
33
+ * `acoustic_through_interval`: the ray stands in a wall at `front` and in a wall at `back`. Between them the field is
34
+ * read at {@link ACOUSTIC_THROUGH_SAMPLES} points, stratified with `jitter` in [0, 1): a point counts as open where the
35
+ * field stands half a voxel of its cascade or more outside a surface, the tracer's own hit rule, and at least `shell`,
36
+ * so the seam where two solids meet stays one wall, and so does the gap a trace's hit stands off a face by. Every solid run after an open one is one more wall, taking the transmission of the brick there
37
+ * (`brick_acoustics_read`, `fallback` for a cell deep inside a solid, which holds no record), and the wall at `back`,
38
+ * past an open run, `back_passing`. The answer is `(what those walls pass per band, the walls after the first)`, or
39
+ * `w` −1 where a point stands in space not built yet. Where nothing was open the two walls are one.
40
+ *
41
+ * `acoustic_through`: a trace from `origin` toward `end` (`acoustic_trace`): one that reaches it is clear, 1. Otherwise
42
+ * it met the first wall, which takes its transmission, and a trace back toward it, from `end` or from where the path
43
+ * leaves the coarsest window if `end` lies past it (nothing beyond is known to stand), meets the last. One that meets
44
+ * nothing leaves the first wall alone. The interval between is read as above, `shell` the half voxel of the coarser
45
+ * cascade the two hits stood in; every wall multiplies, however many there are.
46
+ *
47
+ * A wall thinner than the samples' spacing, or a gap narrower, may fall between two of them: read with a different
48
+ * jitter by each ray, the rays that carry a quantity between them read it, on the mean, near the walls' share of the
49
+ * interval. Two traces of `BRICK_TRACE_STEPS` steps between them and the samples are all a ray costs, however many
50
+ * walls stand between. A trace that spends its steps, or a sample in space not built yet, has no answer: `w` 0. An
51
+ * answer is `(energy per band, 1)`.
52
+ *
53
+ * @type {CodeChunk}
54
+ */
55
+ export const chunk_acoustic_through = CodeChunk.from(
56
+ //language=WGSL
57
+ `
58
+ const ACOUSTIC_THROUGH_SAMPLES = ${ACOUSTIC_THROUGH_SAMPLES}u;
59
+
60
+ fn acoustic_window_reach(origin: vec3<f32>, direction: vec3<f32>, distance: f32, cascade_count: u32) -> f32 {
61
+ let level = brick_levels[min(max(cascade_count, 1u), ${CLIPMAP_LEVEL_LIMIT}u) - 1u];
62
+ // a voxel in, past the half voxel a march must stand inside a window by to start there
63
+ let inset = level.cell_size / ${MESH_SDF_BRICK_VOXELS}.0;
64
+ let low = vec3<f32>(level.corner) * level.cell_size + inset;
65
+ let high = vec3<f32>(level.corner + level.size) * level.cell_size - inset;
66
+
67
+ return clamp(aabb3_distance_to_ray(low, high, origin, direction).y, 0.0, distance);
68
+ }
69
+
70
+ fn acoustic_through_interval(origin: vec3<f32>, direction: vec3<f32>, front: f32, back: f32, jitter: f32, shell: f32, back_passing: vec3<f32>, fallback: vec4<u32>, cascade_count: u32, atlas_shift: u32) -> vec4<f32> {
71
+ let interval = max(back - front, 0.0);
72
+
73
+ var energy = vec3<f32>(1.0);
74
+ var walls = 0u;
75
+ var solid = true;
76
+
77
+ for (var k = 0u; k < ACOUSTIC_THROUGH_SAMPLES; k++) {
78
+ let t = front + interval * (f32(k) + jitter) / f32(ACOUSTIC_THROUGH_SAMPLES);
79
+ let point = brick_clipmap_point(origin + t * direction, cascade_count, atlas_shift);
80
+
81
+ if (point.entry == BRICK_CLIPMAP_UNKNOWN) {
82
+ return vec4<f32>(0.0, 0.0, 0.0, -1.0);
83
+ }
84
+
85
+ if (point.distance >= max(${BRICK_TRACE_HIT_VOXELS} * point.voxel, shell)) {
86
+ solid = false;
87
+ } else if (!solid) {
88
+ solid = true;
89
+ walls++;
90
+ energy *= brick_acoustics_read(point.entry, fallback).transmission;
91
+ }
92
+ }
93
+
94
+ // past an open run, the wall at the back is one more
95
+ if (!solid) {
96
+ walls++;
97
+ energy *= back_passing;
98
+ }
99
+
100
+ return vec4<f32>(energy, f32(walls));
101
+ }
102
+
103
+ fn acoustic_through(origin: vec3<f32>, end: vec3<f32>, jitter: f32, fallback: vec4<u32>, cascade_count: u32, atlas_shift: u32) -> vec4<f32> {
104
+ let span = end - origin;
105
+ let distance = length(span);
106
+
107
+ if (!(distance > 0.0)) {
108
+ return vec4<f32>(1.0);
109
+ }
110
+
111
+ let direction = span / distance;
112
+ let front = acoustic_trace(origin, direction, 0.0, distance, cascade_count, atlas_shift, ${BRICK_TRACE_STEPS}u);
113
+
114
+ if (front.kind == BRICK_TRACE_MISS) {
115
+ return vec4<f32>(1.0);
116
+ }
117
+
118
+ if (front.kind == BRICK_TRACE_UNRESOLVED) {
119
+ return vec4<f32>(0.0);
120
+ }
121
+
122
+ let first = brick_acoustics_read(front.slot, fallback).transmission;
123
+
124
+ // from where the path leaves the coarsest window, if the end lies past it: beyond, nothing is known to stand
125
+ let reach = acoustic_window_reach(origin, direction, distance, cascade_count);
126
+ let back = acoustic_trace(origin + reach * direction, -direction, 0.0, max(reach - front.t, 0.0), cascade_count, atlas_shift, ${BRICK_TRACE_STEPS}u - min(front.steps, ${BRICK_TRACE_STEPS}u));
127
+
128
+ if (back.kind == BRICK_TRACE_UNRESOLVED) {
129
+ return vec4<f32>(0.0);
130
+ }
131
+
132
+ // a trace back that meets nothing before the front hit leaves the front's wall alone
133
+ if (back.kind == BRICK_TRACE_MISS) {
134
+ return vec4<f32>(first, 1.0);
135
+ }
136
+
137
+ // a hit stands up to half a voxel of its own cascade off the face: no sample in that shell is open space
138
+ let shell = ${BRICK_TRACE_HIT_VOXELS} * max(brick_levels[front.cascade].cell_size, brick_levels[back.cascade].cell_size) / ${MESH_SDF_BRICK_VOXELS}.0;
139
+ let between = acoustic_through_interval(origin, direction, front.t, reach - back.t, jitter, shell, brick_acoustics_read(back.slot, fallback).transmission, fallback, cascade_count, atlas_shift);
140
+
141
+ if (between.w < 0.0) {
142
+ return vec4<f32>(0.0);
143
+ }
144
+
145
+ return vec4<f32>(first * between.xyz, 1.0);
146
+ }
147
+ `, [
148
+ chunk_brick_clipmap_trace,
149
+ chunk_brick_clipmap_distance,
150
+ chunk_aabb3_distance_to_ray_v2,
151
+ chunk_acoustic_trace,
152
+ chunk_brick_acoustics,
153
+ ]);
@@ -22,7 +22,9 @@ export const ACOUSTIC_TRACE_WALKS: number;
22
22
  * - any other (it began in the shell, passes along it, or ends in it) steps on by `hit.distance`, which the field
23
23
  * says is clear, and is traced again, at most {@link ACOUSTIC_TRACE_WALKS} times.
24
24
  *
25
- * A hit inside a solid, a miss and a march that spent its steps are the tracer's own. `steps` is the budget for all
25
+ * A miss through space no cascade has built yet (`hit.unknown`) is not open air: what is there is not known, and
26
+ * the ray is unresolved, at `t_min`, as a march that spent its steps is. A hit inside a solid, any other miss and a
27
+ * march that spent its steps are the tracer's own. `steps` is the budget for all
26
28
  * of it, and the hit's `steps` what was spent.
27
29
  *
28
30
  * @type {CodeChunk}
@@ -1 +1 @@
1
- {"version":3,"file":"chunk_acoustic_trace.d.ts","sourceRoot":"","sources":["../../../../../src/shade/renderer/acoustics/chunk_acoustic_trace.js"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,mCAFU,MAAM,CAEsB;AAEtC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,mCAFU,SAAS,CA+Ca;0BA7EN,iCAAiC"}
1
+ {"version":3,"file":"chunk_acoustic_trace.d.ts","sourceRoot":"","sources":["../../../../../src/shade/renderer/acoustics/chunk_acoustic_trace.js"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,mCAFU,MAAM,CAEsB;AAEtC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,mCAFU,SAAS,CAsDa;0BAtFN,iCAAiC"}
@@ -26,7 +26,9 @@ export const ACOUSTIC_TRACE_WALKS = 8;
26
26
  * - any other (it began in the shell, passes along it, or ends in it) steps on by `hit.distance`, which the field
27
27
  * says is clear, and is traced again, at most {@link ACOUSTIC_TRACE_WALKS} times.
28
28
  *
29
- * A hit inside a solid, a miss and a march that spent its steps are the tracer's own. `steps` is the budget for all
29
+ * A miss through space no cascade has built yet (`hit.unknown`) is not open air: what is there is not known, and
30
+ * the ray is unresolved, at `t_min`, as a march that spent its steps is. A hit inside a solid, any other miss and a
31
+ * march that spent its steps are the tracer's own. `steps` is the budget for all
30
32
  * of it, and the hit's `steps` what was spent.
31
33
  *
32
34
  * @type {CodeChunk}
@@ -47,6 +49,13 @@ fn acoustic_trace(origin: vec3<f32>, direction: vec3<f32>, t_min: f32, t_max: f3
47
49
  left -= min(left, hit.steps);
48
50
  hit.steps = steps - left;
49
51
 
52
+ if (hit.kind == BRICK_TRACE_MISS && hit.unknown) {
53
+ hit.kind = BRICK_TRACE_UNRESOLVED;
54
+ hit.t = t_min;
55
+
56
+ return hit;
57
+ }
58
+
50
59
  if (hit.kind != BRICK_TRACE_HIT || !(hit.distance > 0.0)) {
51
60
  return hit;
52
61
  }
@@ -4,10 +4,14 @@ export const ACOUSTIC_COMBINE_LANES: 32;
4
4
  * A frame's receivers made whole from their parts (`shader_acoustic_receive`), a workgroup a receiver: lane `k` of the
5
5
  * first {@link ACOUSTIC_GATHER_STRATA} sums stratum `k` over every part, lane `16 + p` makes part `p`'s own estimate
6
6
  * of the reflected energy, and lane 0 the result. The direct path is the mean over every part's points that
7
- * resolved; each stratum's answers over every part's lanes that answered, scaled by the stratum's vertices over that
7
+ * resolved, the last estimate where none did, or the neutral solution for a source never estimated; each stratum's
8
+ * answers over every part's lanes that answered, scaled by the stratum's vertices over that
8
9
  * count, `P_k / n_k` a lane, times the emission's `1/M`. A stratum no lane of which answered adds nothing: energy is
9
- * lost, never invented. With two parts or more, the spread of one part's estimate over the parts, as a share of their
10
- * mean, is the result's `spread`. The frame's estimates are the receiver's result at its row of `acoustic_results`,
10
+ * lost, never invented. The early and the late lean are each answer's energy along its arrival direction, summed as
11
+ * the energies are, with the answers' own self terms taken out (`acoustic_unbiased_lean`): a lean read from n
12
+ * answers from every side alike would otherwise point about 1/√n of the energy wherever the draw fell. With two
13
+ * parts or more, the spread of one part's estimate over the parts, as a share of their mean, is the result's
14
+ * `spread`. The frame's estimates are the receiver's result at its row of `acoustic_results`,
11
15
  * whole, with nothing of the frames before.
12
16
  *
13
17
  * @type {ComputeShader}
@@ -1 +1 @@
1
- {"version":3,"file":"shader_acoustic_combine.d.ts","sourceRoot":"","sources":["../../../../../src/shade/renderer/acoustics/shader_acoustic_combine.js"],"names":[],"mappings":"AAYA,mGAAmG;AACnG,wCAAyC;AAWzC;;;;;;;;;;;GAWG;AACH,sCAFU,aAAa,CA0JpB;8BA1L2B,4BAA4B"}
1
+ {"version":3,"file":"shader_acoustic_combine.d.ts","sourceRoot":"","sources":["../../../../../src/shade/renderer/acoustics/shader_acoustic_combine.js"],"names":[],"mappings":"AAaA,mGAAmG;AACnG,wCAAyC;AAWzC;;;;;;;;;;;;;;;GAeG;AACH,sCAFU,aAAa,CAqKpB;8BA1M2B,4BAA4B"}
@@ -8,6 +8,7 @@ import { WebGPUBufferType } from "../shader/type/WebGPUBufferType.js";
8
8
  import { ACOUSTIC_RESULT_DESCRIPTOR } from "./ACOUSTIC_DATABASE_SPEC.js";
9
9
  import { ACOUSTIC_GATHER_STRATA, ACOUSTIC_RECEIVER_PARTS } from "./ACOUSTICS.js";
10
10
  import { chunk_acoustic_age } from "./chunk_acoustic_age.js";
11
+ import { chunk_acoustic_lean } from "./chunk_acoustic_lean.js";
11
12
  import { ACOUSTIC_PARTIAL_VEC4S, ACOUSTIC_PARTIALS_RESOURCE, chunk_acoustic_receiver_entry } from "./chunk_acoustic_partials.js";
12
13
 
13
14
  /** Lanes of a combine workgroup, a receiver each: one a stratum, and one a part for the spread. */
@@ -26,10 +27,14 @@ resources.createGroup()
26
27
  * A frame's receivers made whole from their parts (`shader_acoustic_receive`), a workgroup a receiver: lane `k` of the
27
28
  * first {@link ACOUSTIC_GATHER_STRATA} sums stratum `k` over every part, lane `16 + p` makes part `p`'s own estimate
28
29
  * of the reflected energy, and lane 0 the result. The direct path is the mean over every part's points that
29
- * resolved; each stratum's answers over every part's lanes that answered, scaled by the stratum's vertices over that
30
+ * resolved, the last estimate where none did, or the neutral solution for a source never estimated; each stratum's
31
+ * answers over every part's lanes that answered, scaled by the stratum's vertices over that
30
32
  * count, `P_k / n_k` a lane, times the emission's `1/M`. A stratum no lane of which answered adds nothing: energy is
31
- * lost, never invented. With two parts or more, the spread of one part's estimate over the parts, as a share of their
32
- * mean, is the result's `spread`. The frame's estimates are the receiver's result at its row of `acoustic_results`,
33
+ * lost, never invented. The early and the late lean are each answer's energy along its arrival direction, summed as
34
+ * the energies are, with the answers' own self terms taken out (`acoustic_unbiased_lean`): a lean read from n
35
+ * answers from every side alike would otherwise point about 1/√n of the energy wherever the draw fell. With two
36
+ * parts or more, the spread of one part's estimate over the parts, as a share of their mean, is the result's
37
+ * `spread`. The frame's estimates are the receiver's result at its row of `acoustic_results`,
33
38
  * whole, with nothing of the frames before.
34
39
  *
35
40
  * @type {ComputeShader}
@@ -43,7 +48,7 @@ export const shader_acoustic_combine = ComputeShader.from({
43
48
  const ACOUSTIC_COMBINE_STRATA = ${ACOUSTIC_GATHER_STRATA}u;
44
49
  const ACOUSTIC_COMBINE_PART_LANE = 16u;
45
50
 
46
- /** a stratum's sums over the parts: (early, n), (late), (moment), (early lean), (late lean) */
51
+ /** a stratum's sums over the parts: (early, n), (late), (moment), (early lean, its squares), (late lean, its squares) */
47
52
  var<workgroup> acoustic_stratum: array<array<vec4<f32>, 5>, ${ACOUSTIC_GATHER_STRATA}>;
48
53
 
49
54
  /** each part's estimate of the reflected energy, band mean */
@@ -122,6 +127,10 @@ fn main(
122
127
  if (direct.w > 0.0) {
123
128
  result.direct = direct.xyz / direct.w;
124
129
  result.age = acoustic_age_after(result.age);
130
+ } else if (!(result.age > 0.0)) {
131
+ // never estimated, and no point resolved this frame either (space not built yet, or every march spent its
132
+ // steps): the neutral solution, as the host hears a source before its first result
133
+ result.direct = vec3<f32>(1.0);
125
134
  }
126
135
 
127
136
  var early = vec3<f32>(0.0);
@@ -129,6 +138,9 @@ fn main(
129
138
  var late = vec3<f32>(0.0);
130
139
  var late_direction = vec3<f32>(0.0);
131
140
  var moment = vec3<f32>(0.0);
141
+ // each answer's lean squared, as scaled: Σ |xᵢ|²
142
+ var early_squares = 0.0;
143
+ var late_squares = 0.0;
132
144
 
133
145
  for (var k = 0u; k < ACOUSTIC_COMBINE_STRATA; k++) {
134
146
  let sums = acoustic_stratum[k];
@@ -147,6 +159,8 @@ fn main(
147
159
  moment += scale * sums[2].xyz;
148
160
  early_direction += scale * sums[3].xyz;
149
161
  late_direction += scale * sums[4].xyz;
162
+ early_squares += scale * scale * sums[3].w;
163
+ late_squares += scale * scale * sums[4].w;
150
164
  }
151
165
 
152
166
  // the spread of one part's estimate, where there are two or more to measure it by
@@ -171,9 +185,10 @@ fn main(
171
185
  }
172
186
 
173
187
  result.early = early;
174
- result.early_direction = early_direction;
188
+ // the leans over the band-mean energies they were summed with
189
+ result.early_direction = acoustic_unbiased_lean(early_direction, early_squares, (early.x + early.y + early.z) / 3.0);
175
190
  result.late = late;
176
- result.late_direction = late_direction;
191
+ result.late_direction = acoustic_unbiased_lean(late_direction, late_squares, (late.x + late.y + late.z) / 3.0);
177
192
  result.moment = moment;
178
193
  result.reflected_age = acoustic_age_after(result.reflected_age);
179
194
 
@@ -182,6 +197,7 @@ fn main(
182
197
  `, [
183
198
  chunk_folded_workgroup_index,
184
199
  chunk_acoustic_age,
200
+ chunk_acoustic_lean,
185
201
  chunk_acoustic_receiver_entry,
186
202
  ACOUSTIC_RESULT_DESCRIPTOR.chunk_read_rw,
187
203
  ACOUSTIC_RESULT_DESCRIPTOR.chunk_write,
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Each heard source's first-order reflections off the listener's hits: a workgroup a chunk of 64 of the hits (`x`) and
3
+ * a source of `source_list` (`y`, folded over `z` past the 65,535 a dimension is sure to hold), a lane a hit, one path
4
+ * from the hit to the source
5
+ * (`acoustic_listener_reflection`). The chunk's sum, and how many of its rays hit anything, go to the source's place in
6
+ * `acoustic_coupling_partials`. A source in the room lights the walls about the listener; one through a doorway what
7
+ * the opening shows it, as far off as it is; one behind a wall all of them, as dimly and as darkened per band as the
8
+ * wall lets it.
9
+ *
10
+ * @type {ComputeShader}
11
+ */
12
+ export const shader_acoustic_coupling: ComputeShader;
13
+ import { ComputeShader } from "../shader/ComputeShader.js";
14
+ //# sourceMappingURL=shader_acoustic_coupling.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shader_acoustic_coupling.d.ts","sourceRoot":"","sources":["../../../../../src/shade/renderer/acoustics/shader_acoustic_coupling.js"],"names":[],"mappings":"AA+CA;;;;;;;;;;GAUG;AACH,uCAFU,aAAa,CA6CpB;8BA5F2B,4BAA4B"}
@@ -0,0 +1,102 @@
1
+ import {
2
+ BRICK_ATLAS_TEXTURE_RESOURCE,
3
+ BRICK_LEVELS_RESOURCE,
4
+ BRICK_MAP_TEXTURE_RESOURCE,
5
+ BRICK_OCCUPANCY_TEXTURE_RESOURCE,
6
+ BRICK_SAMPLER_RESOURCE
7
+ } from "../global_illumination/probe_clipmap/brick/chunk_brick_clipmap_trace.js";
8
+ import { chunk_workgroup_sum_vec4 } from "../shader/chunk/subgroup/chunk_workgroup_sum_vec4.js";
9
+ import { CodeChunk } from "../shader/compiler/CodeChunk.js";
10
+ import { ComputeShader } from "../shader/ComputeShader.js";
11
+ import { ShaderResourceSetDescriptor } from "../shader/resource/ShaderResourceSetDescriptor.js";
12
+ import { u32 } from "../shader/type/WEBGPU_WGSL_PRIMITIVE_TYPES.js";
13
+ import { WebGPUArray } from "../shader/type/WebGPUArray.js";
14
+ import { WebGPUBufferType } from "../shader/type/WebGPUBufferType.js";
15
+ import { ACOUSTIC_FRAME_STRUCT } from "./ACOUSTIC_FRAME_STRUCT.js";
16
+ import {
17
+ ACOUSTIC_COUPLING_PARTIAL_VEC4S,
18
+ ACOUSTIC_COUPLING_PARTIALS_STORE_RESOURCE,
19
+ ACOUSTIC_LISTENER_GROUPS,
20
+ ACOUSTIC_LISTENER_HITS_RESOURCE
21
+ } from "./ACOUSTIC_LISTENER_RESOURCES.js";
22
+ import {
23
+ WEBGPU_GUARANTEED_MAX_COMPUTE_WORKGROUPS_PER_DIMENSION
24
+ } from "../gpu_primitive/indirect/WEBGPU_GUARANTEED_MAX_COMPUTE_WORKGROUPS_PER_DIMENSION.js";
25
+ import { ACOUSTIC_SOURCE_DESCRIPTOR } from "./ACOUSTIC_PROBE_DATABASE_SPEC.js";
26
+ import { chunk_acoustic_listener } from "./chunk_acoustic_listener.js";
27
+ import { BRICK_ACOUSTICS_RESOURCE } from "./chunk_brick_acoustics.js";
28
+
29
+ const resources = new ShaderResourceSetDescriptor();
30
+
31
+ resources.setImmediate("source_count", u32);
32
+
33
+ resources.createGroup()
34
+ .addUniform("acoustic_frame", ACOUSTIC_FRAME_STRUCT)
35
+ .addStorageBuffer("database", WebGPUBufferType.unsized, true)
36
+ .addStorageBuffer("source_list", WebGPUArray.from(u32), false)
37
+ .add(ACOUSTIC_LISTENER_HITS_RESOURCE)
38
+ .add(ACOUSTIC_COUPLING_PARTIALS_STORE_RESOURCE);
39
+
40
+ resources.createGroup()
41
+ .add(BRICK_LEVELS_RESOURCE)
42
+ .add(BRICK_MAP_TEXTURE_RESOURCE)
43
+ .add(BRICK_OCCUPANCY_TEXTURE_RESOURCE)
44
+ .add(BRICK_ATLAS_TEXTURE_RESOURCE)
45
+ .add(BRICK_SAMPLER_RESOURCE)
46
+ .add(BRICK_ACOUSTICS_RESOURCE);
47
+
48
+ /**
49
+ * Each heard source's first-order reflections off the listener's hits: a workgroup a chunk of 64 of the hits (`x`) and
50
+ * a source of `source_list` (`y`, folded over `z` past the 65,535 a dimension is sure to hold), a lane a hit, one path
51
+ * from the hit to the source
52
+ * (`acoustic_listener_reflection`). The chunk's sum, and how many of its rays hit anything, go to the source's place in
53
+ * `acoustic_coupling_partials`. A source in the room lights the walls about the listener; one through a doorway what
54
+ * the opening shows it, as far off as it is; one behind a wall all of them, as dimly and as darkened per band as the
55
+ * wall lets it.
56
+ *
57
+ * @type {ComputeShader}
58
+ */
59
+ export const shader_acoustic_coupling = ComputeShader.from({
60
+ label: "Acoustic Coupling",
61
+ resources,
62
+ body: CodeChunk.from(
63
+ //language=WGSL
64
+ `
65
+ @compute @workgroup_size(64)
66
+ fn main(
67
+ @builtin(workgroup_id) workgroup_id: vec3<u32>,
68
+ @builtin(local_invocation_index) lane: u32,
69
+ @builtin(subgroup_invocation_id) subgroup_lane: u32,
70
+ @builtin(subgroup_size) subgroup_size: u32,
71
+ ) {
72
+ // the source folded over y and z, no dimension past the guaranteed count
73
+ let chunk = workgroup_id.x;
74
+ let index = workgroup_id.y + workgroup_id.z * ${WEBGPU_GUARANTEED_MAX_COMPUTE_WORKGROUPS_PER_DIMENSION}u;
75
+
76
+ // the same for the whole workgroup: it leaves together, before the sums
77
+ if (index >= source_count) {
78
+ return;
79
+ }
80
+
81
+ let source = ${ACOUSTIC_SOURCE_DESCRIPTOR.marshalling_method_read_rw}(&database, source_list[index]);
82
+ let slot = chunk * 64u + lane;
83
+ let hit = acoustic_listener_hits[slot];
84
+
85
+ // the golden-ratio sequence over the hits: neighbouring hits, which neighbouring lanes hold, read their walls at
86
+ // well-spread offsets, the same every frame
87
+ let jitter = fract(0.5 + f32(slot) * ${(Math.sqrt(5) - 1) / 2});
88
+
89
+ let reflected = acoustic_listener_reflection(hit, source.position, source.radius, jitter, acoustic_frame.fallback, acoustic_frame.cascade_count, acoustic_frame.atlas_shift);
90
+ let any_hit = select(0.0, 1.0, hit.kind == ACOUSTIC_LISTENER_HIT);
91
+ let sum = workgroup_sum_vec4(vec4<f32>(reflected, any_hit), lane, subgroup_lane, subgroup_size);
92
+
93
+ if (lane == 0u) {
94
+ acoustic_coupling_partials[(index * ${ACOUSTIC_LISTENER_GROUPS}u + chunk) * ${ACOUSTIC_COUPLING_PARTIAL_VEC4S}u] = sum;
95
+ }
96
+ }
97
+ `, [
98
+ chunk_workgroup_sum_vec4,
99
+ chunk_acoustic_listener,
100
+ ACOUSTIC_SOURCE_DESCRIPTOR.chunk_read_rw,
101
+ ]),
102
+ });
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The listener's rays, one a lane, to their first hits (`acoustic_listener_ray`), lane `k` tracing Fibonacci point
3
+ * `acoustic_listener_order[k]`, so a subgroup's rays look into one patch of the sphere: each hit written at the lane's
4
+ * place in `acoustic_listener_hits` for the sources' coupling, whose workgroups then take hits that stand together,
5
+ * and the workgroup's sums of them (`acoustic_listener_sums`) at its own place in `acoustic_listener_partials` for the
6
+ * room.
7
+ *
8
+ * @type {ComputeShader}
9
+ */
10
+ export const shader_acoustic_listener: ComputeShader;
11
+ import { ComputeShader } from "../shader/ComputeShader.js";
12
+ //# sourceMappingURL=shader_acoustic_listener.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shader_acoustic_listener.d.ts","sourceRoot":"","sources":["../../../../../src/shade/renderer/acoustics/shader_acoustic_listener.js"],"names":[],"mappings":"AAqCA;;;;;;;;GAQG;AACH,uCAFU,aAAa,CAmCpB;8BAtE2B,4BAA4B"}
@@ -0,0 +1,80 @@
1
+ import {
2
+ BRICK_ATLAS_TEXTURE_RESOURCE,
3
+ BRICK_LEVELS_RESOURCE,
4
+ BRICK_MAP_TEXTURE_RESOURCE,
5
+ BRICK_OCCUPANCY_TEXTURE_RESOURCE,
6
+ BRICK_SAMPLER_RESOURCE
7
+ } from "../global_illumination/probe_clipmap/brick/chunk_brick_clipmap_trace.js";
8
+ import { chunk_workgroup_sum_vec4 } from "../shader/chunk/subgroup/chunk_workgroup_sum_vec4.js";
9
+ import { CodeChunk } from "../shader/compiler/CodeChunk.js";
10
+ import { ComputeShader } from "../shader/ComputeShader.js";
11
+ import { ShaderResourceSetDescriptor } from "../shader/resource/ShaderResourceSetDescriptor.js";
12
+ import { ACOUSTIC_FRAME_STRUCT } from "./ACOUSTIC_FRAME_STRUCT.js";
13
+ import {
14
+ ACOUSTIC_LISTENER_HITS_STORE_RESOURCE,
15
+ ACOUSTIC_LISTENER_ORDER_RESOURCE,
16
+ ACOUSTIC_LISTENER_PARTIAL_VEC4S,
17
+ ACOUSTIC_LISTENER_PARTIALS_STORE_RESOURCE
18
+ } from "./ACOUSTIC_LISTENER_RESOURCES.js";
19
+ import { chunk_acoustic_listener } from "./chunk_acoustic_listener.js";
20
+ import { BRICK_ACOUSTICS_RESOURCE } from "./chunk_brick_acoustics.js";
21
+
22
+ const resources = new ShaderResourceSetDescriptor();
23
+
24
+ resources.createGroup()
25
+ .addUniform("acoustic_frame", ACOUSTIC_FRAME_STRUCT)
26
+ .add(ACOUSTIC_LISTENER_ORDER_RESOURCE)
27
+ .add(ACOUSTIC_LISTENER_HITS_STORE_RESOURCE)
28
+ .add(ACOUSTIC_LISTENER_PARTIALS_STORE_RESOURCE);
29
+
30
+ resources.createGroup()
31
+ .add(BRICK_LEVELS_RESOURCE)
32
+ .add(BRICK_MAP_TEXTURE_RESOURCE)
33
+ .add(BRICK_OCCUPANCY_TEXTURE_RESOURCE)
34
+ .add(BRICK_ATLAS_TEXTURE_RESOURCE)
35
+ .add(BRICK_SAMPLER_RESOURCE)
36
+ .add(BRICK_ACOUSTICS_RESOURCE);
37
+
38
+ /**
39
+ * The listener's rays, one a lane, to their first hits (`acoustic_listener_ray`), lane `k` tracing Fibonacci point
40
+ * `acoustic_listener_order[k]`, so a subgroup's rays look into one patch of the sphere: each hit written at the lane's
41
+ * place in `acoustic_listener_hits` for the sources' coupling, whose workgroups then take hits that stand together,
42
+ * and the workgroup's sums of them (`acoustic_listener_sums`) at its own place in `acoustic_listener_partials` for the
43
+ * room.
44
+ *
45
+ * @type {ComputeShader}
46
+ */
47
+ export const shader_acoustic_listener = ComputeShader.from({
48
+ label: "Acoustic Listener",
49
+ resources,
50
+ body: CodeChunk.from(
51
+ //language=WGSL
52
+ `
53
+ @compute @workgroup_size(64)
54
+ fn main(
55
+ @builtin(workgroup_id) workgroup_id: vec3<u32>,
56
+ @builtin(local_invocation_index) lane: u32,
57
+ @builtin(subgroup_invocation_id) subgroup_lane: u32,
58
+ @builtin(subgroup_size) subgroup_size: u32,
59
+ ) {
60
+ let slot = workgroup_id.x * 64u + lane;
61
+ let listener = acoustic_frame.listener;
62
+ let hit = acoustic_listener_ray(listener, acoustic_listener_order[slot], acoustic_frame.fallback, acoustic_frame.cascade_count, acoustic_frame.atlas_shift);
63
+
64
+ acoustic_listener_hits[slot] = hit;
65
+
66
+ let sums = acoustic_listener_sums(listener, hit);
67
+ let s0 = workgroup_sum_vec4(sums[0], lane, subgroup_lane, subgroup_size);
68
+ let s1 = workgroup_sum_vec4(sums[1], lane, subgroup_lane, subgroup_size);
69
+ let s2 = workgroup_sum_vec4(sums[2], lane, subgroup_lane, subgroup_size);
70
+
71
+ if (lane == 0u) {
72
+ let at = workgroup_id.x * ${ACOUSTIC_LISTENER_PARTIAL_VEC4S}u;
73
+
74
+ acoustic_listener_partials[at] = s0;
75
+ acoustic_listener_partials[at + 1u] = s1;
76
+ acoustic_listener_partials[at + 2u] = s2;
77
+ }
78
+ }
79
+ `, [chunk_workgroup_sum_vec4, chunk_acoustic_listener]),
80
+ });
@@ -1 +1 @@
1
- {"version":3,"file":"shader_acoustic_receive.d.ts","sourceRoot":"","sources":["../../../../../src/shade/renderer/acoustics/shader_acoustic_receive.js"],"names":[],"mappings":"AA2EA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,sCAFU,aAAa,CA0MpB;8BAtS2B,4BAA4B"}
1
+ {"version":3,"file":"shader_acoustic_receive.d.ts","sourceRoot":"","sources":["../../../../../src/shade/renderer/acoustics/shader_acoustic_receive.js"],"names":[],"mappings":"AA4EA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,sCAFU,aAAa,CA8NpB;8BA1T2B,4BAA4B"}
@@ -8,6 +8,7 @@ import {
8
8
  } from "../global_illumination/probe_clipmap/brick/chunk_brick_clipmap_trace.js";
9
9
  import { chunk_sphere_fibonacci_point } from "../shader/chunk/geometry/sphere/chunk_sphere_fibonacci_point.js";
10
10
  import { chunk_folded_workgroup_index } from "../shader/chunk/grid/chunk_folded_workgroup_index.js";
11
+ import { chunk_acoustic_finite } from "./chunk_acoustic_finite.js";
11
12
  import { CodeChunk } from "../shader/compiler/CodeChunk.js";
12
13
  import { ComputeShader } from "../shader/ComputeShader.js";
13
14
  import { ShaderResourceSetDescriptor } from "../shader/resource/ShaderResourceSetDescriptor.js";
@@ -205,12 +206,25 @@ fn main(
205
206
  acoustic_frame.atlas_shift
206
207
  );
207
208
 
209
+ // an answer no sum can hold is no answer: left out of its stratum, and nothing of it kept
210
+ let finite = acoustic_finite3(answer.energy) && acoustic_finite3(answer.arrival)
211
+ && acoustic_finite3(vec3<f32>(answer.delay, answer.reservoir.weight, 0.0));
212
+
208
213
  if (receiver.history > 0u) {
209
- acoustic_reservoirs[slot] = answer.reservoir;
214
+ var kept = answer.reservoir;
215
+
216
+ if (!finite) {
217
+ // empty, its confidence kept, as a reservoir that kept nothing is
218
+ kept.weight = 0.0;
219
+ }
220
+
221
+ acoustic_reservoirs[slot] = kept;
210
222
  }
211
223
 
212
- energy = vec4<f32>(answer.energy, answer.delay);
213
- direction = vec4<f32>(answer.arrival, select(0.0, 1.0, answer.resolved));
224
+ if (finite) {
225
+ energy = vec4<f32>(answer.energy, answer.delay);
226
+ direction = vec4<f32>(answer.arrival, select(0.0, 1.0, answer.resolved));
227
+ }
214
228
  }
215
229
 
216
230
  acoustic_lane_energy[lane] = energy;
@@ -257,21 +271,27 @@ fn main(
257
271
  var moment = vec3<f32>(0.0);
258
272
  var early_direction = vec3<f32>(0.0);
259
273
  var late_direction = vec3<f32>(0.0);
274
+ // each answer's own lean squared, its energy squared: what the lean's self terms are taken out by
275
+ var early_squares = 0.0;
276
+ var late_squares = 0.0;
260
277
 
261
278
  for (var i = 0u; i < ACOUSTIC_STRATUM_LANES; i++) {
262
279
  let a = acoustic_lane_energy[first + i];
263
280
  let b = acoustic_lane_direction[first + i];
264
281
  let e = b.w * a.xyz;
265
- let lean = ((e.x + e.y + e.z) / 3.0) * b.xyz;
282
+ let mean = (e.x + e.y + e.z) / 3.0;
283
+ let lean = mean * b.xyz;
266
284
 
267
285
  n += b.w;
268
286
 
269
287
  if (a.w < ACOUSTIC_EARLY_TIME) {
270
288
  early += e;
271
289
  early_direction += lean;
290
+ early_squares += mean * mean;
272
291
  } else {
273
292
  late += e;
274
293
  late_direction += lean;
294
+ late_squares += mean * mean;
275
295
  moment += e * (a.w - ACOUSTIC_EARLY_TIME);
276
296
  }
277
297
  }
@@ -281,8 +301,8 @@ fn main(
281
301
  acoustic_partials[s] = vec4<f32>(early, n);
282
302
  acoustic_partials[s + 1u] = vec4<f32>(late, 0.0);
283
303
  acoustic_partials[s + 2u] = vec4<f32>(moment, 0.0);
284
- acoustic_partials[s + 3u] = vec4<f32>(early_direction, 0.0);
285
- acoustic_partials[s + 4u] = vec4<f32>(late_direction, 0.0);
304
+ acoustic_partials[s + 3u] = vec4<f32>(early_direction, early_squares);
305
+ acoustic_partials[s + 4u] = vec4<f32>(late_direction, late_squares);
286
306
  }
287
307
 
288
308
  if (part == 0u) {
@@ -293,6 +313,7 @@ fn main(
293
313
  }
294
314
  `, [
295
315
  chunk_folded_workgroup_index,
316
+ chunk_acoustic_finite,
296
317
  chunk_sphere_fibonacci_point,
297
318
  chunk_acoustic_direct,
298
319
  chunk_acoustic_direct_target,
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The room about the listener, one workgroup: the listener workgroups' sums added, the room they make
3
+ * (`acoustic_room`), where its reflecting surface lies, the share of the rays that left (into open air, or into space not
4
+ * built yet) and how many rays were summed, written whole at row 0 of `acoustic_room`. A listener inside a solid has no
5
+ * room.
6
+ *
7
+ * @type {ComputeShader}
8
+ */
9
+ export const shader_acoustic_room: ComputeShader;
10
+ import { ComputeShader } from "../shader/ComputeShader.js";
11
+ //# sourceMappingURL=shader_acoustic_room.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shader_acoustic_room.d.ts","sourceRoot":"","sources":["../../../../../src/shade/renderer/acoustics/shader_acoustic_room.js"],"names":[],"mappings":"AAsCA;;;;;;;GAOG;AACH,mCAFU,aAAa,CAkEpB;8BApG2B,4BAA4B"}