@woosh/meep-engine 3.11.2 → 3.11.3

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 (168) hide show
  1. package/build/bundle-worker-terrain.js +1 -1
  2. package/package.json +1 -1
  3. package/src/shade/descriptor/pipeline/PipelineLayoutDescriptor.d.ts +16 -2
  4. package/src/shade/descriptor/pipeline/PipelineLayoutDescriptor.d.ts.map +1 -1
  5. package/src/shade/descriptor/pipeline/PipelineLayoutDescriptor.js +28 -4
  6. package/src/shade/descriptor/pipeline/compute/ComputePipelineDescriptor.d.ts +1 -1
  7. package/src/shade/descriptor/pipeline/compute/ComputePipelineDescriptor.d.ts.map +1 -1
  8. package/src/shade/descriptor/pipeline/compute/ComputePipelineDescriptor.js +5 -2
  9. package/src/shade/device/IMMEDIATE_DATA_PLAN_2026_08_28.md +564 -451
  10. package/src/shade/device/ShadeGPUCommandContext.d.ts +18 -2
  11. package/src/shade/device/ShadeGPUCommandContext.d.ts.map +1 -1
  12. package/src/shade/device/ShadeGPUCommandContext.js +994 -940
  13. package/src/shade/device/immediate_data_supported.d.ts +33 -0
  14. package/src/shade/device/immediate_data_supported.d.ts.map +1 -0
  15. package/src/shade/device/immediate_data_supported.js +53 -0
  16. package/src/shade/device/mock/SoftwareGPUCommandEncoder.d.ts +18 -0
  17. package/src/shade/device/mock/SoftwareGPUCommandEncoder.d.ts.map +1 -1
  18. package/src/shade/device/mock/SoftwareGPUCommandEncoder.js +24 -0
  19. package/src/shade/device/mock/SoftwareGPUComputePassEncoder.d.ts +7 -0
  20. package/src/shade/device/mock/SoftwareGPUComputePassEncoder.d.ts.map +1 -1
  21. package/src/shade/device/mock/SoftwareGPUComputePassEncoder.js +49 -1
  22. package/src/shade/device/mock/SoftwareGPUDevice.d.ts.map +1 -1
  23. package/src/shade/device/mock/SoftwareGPUDevice.js +20 -2
  24. package/src/shade/device/mock/SoftwareGPUImmediateData.d.ts +65 -0
  25. package/src/shade/device/mock/SoftwareGPUImmediateData.d.ts.map +1 -0
  26. package/src/shade/device/mock/SoftwareGPUImmediateData.js +160 -0
  27. package/src/shade/device/mock/SoftwareGPURenderPassEncoder.d.ts +7 -0
  28. package/src/shade/device/mock/SoftwareGPURenderPassEncoder.d.ts.map +1 -1
  29. package/src/shade/device/mock/SoftwareGPURenderPassEncoder.js +50 -0
  30. package/src/shade/device/mock/pipeline_immediate_size.d.ts +11 -0
  31. package/src/shade/device/mock/pipeline_immediate_size.d.ts.map +1 -0
  32. package/src/shade/device/mock/pipeline_immediate_size.js +18 -0
  33. package/src/shade/device/pipeline/PipelineLayoutManager.d.ts.map +1 -1
  34. package/src/shade/device/pipeline/PipelineLayoutManager.js +1 -0
  35. package/src/shade/renderer/GraphicsContext.d.ts +9 -2
  36. package/src/shade/renderer/GraphicsContext.d.ts.map +1 -1
  37. package/src/shade/renderer/GraphicsContext.js +13 -1
  38. package/src/shade/renderer/atmosphere/GPUSky.d.ts.map +1 -1
  39. package/src/shade/renderer/atmosphere/GPUSky.js +145 -142
  40. package/src/shade/renderer/atmosphere/MULTISCATTER_LUT_CONFIG.d.ts +34 -0
  41. package/src/shade/renderer/atmosphere/MULTISCATTER_LUT_CONFIG.d.ts.map +1 -0
  42. package/src/shade/renderer/atmosphere/MULTISCATTER_LUT_CONFIG.js +36 -0
  43. package/src/shade/renderer/atmosphere/SAMPLER_SKY_LUT.d.ts +20 -0
  44. package/src/shade/renderer/atmosphere/SAMPLER_SKY_LUT.d.ts.map +1 -0
  45. package/src/shade/renderer/atmosphere/SAMPLER_SKY_LUT.js +25 -0
  46. package/src/shade/renderer/atmosphere/chunk_get_multiscatter_values.d.ts +14 -1
  47. package/src/shade/renderer/atmosphere/chunk_get_multiscatter_values.d.ts.map +1 -1
  48. package/src/shade/renderer/atmosphere/chunk_get_multiscatter_values.js +163 -177
  49. package/src/shade/renderer/atmosphere/chunk_multiscatter_sample_direction.d.ts +20 -0
  50. package/src/shade/renderer/atmosphere/chunk_multiscatter_sample_direction.d.ts.map +1 -0
  51. package/src/shade/renderer/atmosphere/chunk_multiscatter_sample_direction.js +46 -0
  52. package/src/shade/renderer/atmosphere/chunk_sample_multiscatter_lut.d.ts +11 -1
  53. package/src/shade/renderer/atmosphere/chunk_sample_multiscatter_lut.d.ts.map +1 -1
  54. package/src/shade/renderer/atmosphere/chunk_sample_multiscatter_lut.js +57 -27
  55. package/src/shade/renderer/atmosphere/chunk_sample_transmittance_lut.d.ts +19 -1
  56. package/src/shade/renderer/atmosphere/chunk_sample_transmittance_lut.d.ts.map +1 -1
  57. package/src/shade/renderer/atmosphere/chunk_sample_transmittance_lut.js +69 -33
  58. package/src/shade/renderer/atmosphere/chunk_sky_lut_compute_uv.d.ts +13 -0
  59. package/src/shade/renderer/atmosphere/chunk_sky_lut_compute_uv.d.ts.map +1 -1
  60. package/src/shade/renderer/atmosphere/chunk_sky_lut_compute_uv.js +35 -35
  61. package/src/shade/renderer/atmosphere/chunk_sky_lut_params.d.ts +13 -0
  62. package/src/shade/renderer/atmosphere/chunk_sky_lut_params.d.ts.map +1 -0
  63. package/src/shade/renderer/atmosphere/chunk_sky_lut_params.js +38 -0
  64. package/src/shade/renderer/atmosphere/chunk_sky_lut_texel_to_unit.d.ts +17 -0
  65. package/src/shade/renderer/atmosphere/chunk_sky_lut_texel_to_unit.d.ts.map +1 -0
  66. package/src/shade/renderer/atmosphere/chunk_sky_lut_texel_to_unit.js +29 -0
  67. package/src/shade/renderer/atmosphere/chunk_sky_lut_uv.d.ts +21 -0
  68. package/src/shade/renderer/atmosphere/chunk_sky_lut_uv.d.ts.map +1 -0
  69. package/src/shade/renderer/atmosphere/chunk_sky_lut_uv.js +42 -0
  70. package/src/shade/renderer/atmosphere/shader_multiscatter_lut.d.ts +2 -2
  71. package/src/shade/renderer/atmosphere/shader_multiscatter_lut.d.ts.map +1 -1
  72. package/src/shade/renderer/atmosphere/shader_multiscatter_lut.js +165 -84
  73. package/src/shade/renderer/atmosphere/shader_sky_irradiance_lut.d.ts.map +1 -1
  74. package/src/shade/renderer/atmosphere/shader_sky_irradiance_lut.js +215 -204
  75. package/src/shade/renderer/atmosphere/shader_transmittance_lut.d.ts.map +1 -1
  76. package/src/shade/renderer/atmosphere/shader_transmittance_lut.js +79 -67
  77. package/src/shade/renderer/light/cluster/graph_assign_clsuters.d.ts.map +1 -1
  78. package/src/shade/renderer/light/cluster/graph_assign_clsuters.js +6 -2
  79. package/src/shade/renderer/postprocess/gtao/GTAO.d.ts.map +1 -1
  80. package/src/shade/renderer/postprocess/gtao/GTAO.js +4 -0
  81. package/src/shade/renderer/rasterize/bucket/prepare_meshlet_draw_commands_by_material.d.ts.map +1 -1
  82. package/src/shade/renderer/rasterize/bucket/prepare_meshlet_draw_commands_by_material.js +341 -345
  83. package/src/shade/renderer/rasterize/bucket/shader_read_out_bucket.d.ts +0 -2
  84. package/src/shade/renderer/rasterize/bucket/shader_read_out_bucket.d.ts.map +1 -1
  85. package/src/shade/renderer/rasterize/bucket/shader_read_out_bucket.js +58 -57
  86. package/src/shade/renderer/rasterize/expand/mesh/graph_expand_meshes_to_meshlets.d.ts.map +1 -1
  87. package/src/shade/renderer/rasterize/expand/mesh/graph_expand_meshes_to_meshlets.js +7 -3
  88. package/src/shade/renderer/rasterize/fast/graph_extract_meshes_from_bucket.d.ts.map +1 -1
  89. package/src/shade/renderer/rasterize/fast/graph_extract_meshes_from_bucket.js +77 -81
  90. package/src/shade/renderer/rasterize/standard/graph_rasterize_scene.d.ts.map +1 -1
  91. package/src/shade/renderer/rasterize/standard/graph_rasterize_scene.js +5 -1
  92. package/src/shade/renderer/shader/ComputeShader.d.ts.map +1 -1
  93. package/src/shade/renderer/shader/ComputeShader.js +6 -2
  94. package/src/shade/renderer/shader/ImageShader.d.ts.map +1 -1
  95. package/src/shade/renderer/shader/ImageShader.js +4 -1
  96. package/src/shade/renderer/shader/ShaderDescriptor.d.ts.map +1 -1
  97. package/src/shade/renderer/shader/ShaderDescriptor.js +26 -0
  98. package/src/shade/renderer/shader/chunk/atmosphere/ATMOSPHERE_RADII_DECLARATION.d.ts +18 -0
  99. package/src/shade/renderer/shader/chunk/atmosphere/ATMOSPHERE_RADII_DECLARATION.d.ts.map +1 -0
  100. package/src/shade/renderer/shader/chunk/atmosphere/ATMOSPHERE_RADII_DECLARATION.js +32 -0
  101. package/src/shade/renderer/shader/chunk/atmosphere/PLANET_CENTER_DECLARATION.d.ts +7 -0
  102. package/src/shade/renderer/shader/chunk/atmosphere/PLANET_CENTER_DECLARATION.d.ts.map +1 -1
  103. package/src/shade/renderer/shader/chunk/atmosphere/PLANET_CENTER_DECLARATION.js +17 -6
  104. package/src/shade/renderer/shader/chunk/atmosphere/chunk_atmosphere_ray_bounds.d.ts +21 -0
  105. package/src/shade/renderer/shader/chunk/atmosphere/chunk_atmosphere_ray_bounds.d.ts.map +1 -0
  106. package/src/shade/renderer/shader/chunk/atmosphere/chunk_atmosphere_ray_bounds.js +69 -0
  107. package/src/shade/renderer/shader/chunk/geometry/aabb3/chunk_aabb3_contains_aabb3.d.ts +9 -0
  108. package/src/shade/renderer/shader/chunk/geometry/aabb3/chunk_aabb3_contains_aabb3.d.ts.map +1 -0
  109. package/src/shade/renderer/shader/chunk/geometry/aabb3/chunk_aabb3_contains_aabb3.js +22 -0
  110. package/src/shade/renderer/shader/chunk/geometry/aabb3/chunk_aabb3_from_transformed_corners.d.ts +16 -0
  111. package/src/shade/renderer/shader/chunk/geometry/aabb3/chunk_aabb3_from_transformed_corners.d.ts.map +1 -0
  112. package/src/shade/renderer/shader/chunk/geometry/aabb3/chunk_aabb3_from_transformed_corners.js +41 -0
  113. package/src/shade/renderer/shader/chunk/geometry/frustum/chunk_frustum_transform_m4.d.ts +11 -0
  114. package/src/shade/renderer/shader/chunk/geometry/frustum/chunk_frustum_transform_m4.d.ts.map +1 -1
  115. package/src/shade/renderer/shader/chunk/geometry/frustum/chunk_frustum_transform_m4.js +15 -19
  116. package/src/shade/renderer/shader/chunk/geometry/frustum/chunk_frustum_transform_plane_matrix.d.ts +23 -0
  117. package/src/shade/renderer/shader/chunk/geometry/frustum/chunk_frustum_transform_plane_matrix.d.ts.map +1 -0
  118. package/src/shade/renderer/shader/chunk/geometry/frustum/chunk_frustum_transform_plane_matrix.js +44 -0
  119. package/src/shade/renderer/shader/chunk/geometry/octahedron/chunk_uv_octahedral_unit_decode.d.ts.map +1 -1
  120. package/src/shade/renderer/shader/chunk/geometry/octahedron/chunk_uv_octahedral_unit_decode.js +1 -4
  121. package/src/shade/renderer/shader/compiler/CodeChunk.d.ts +7 -1
  122. package/src/shade/renderer/shader/compiler/CodeChunk.d.ts.map +1 -1
  123. package/src/shade/renderer/shader/compiler/CodeChunk.js +37 -2
  124. package/src/shade/renderer/shader/graph/compute/compute_binding_read_names.d.ts.map +1 -1
  125. package/src/shade/renderer/shader/graph/compute/compute_binding_read_names.js +6 -0
  126. package/src/shade/renderer/shader/graph/compute/graph_compute_indirect_pass.js +1 -1
  127. package/src/shade/renderer/shader/graph/compute/graph_compute_pass.js +1 -1
  128. package/src/shade/renderer/shader/graph/graph_image_pass.js +1 -1
  129. package/src/shade/renderer/shader/graph/graph_prepare_bindings.d.ts.map +1 -1
  130. package/src/shade/renderer/shader/graph/graph_prepare_bindings.js +7 -0
  131. package/src/shade/renderer/shader/graph/graph_prepare_pass_input_data.d.ts +3 -1
  132. package/src/shade/renderer/shader/graph/graph_prepare_pass_input_data.d.ts.map +1 -1
  133. package/src/shade/renderer/shader/graph/graph_prepare_pass_input_data.js +12 -1
  134. package/src/shade/renderer/shader/pass/RenderPassDescriptor.d.ts.map +1 -1
  135. package/src/shade/renderer/shader/pass/RenderPassDescriptor.js +1 -0
  136. package/src/shade/renderer/shader/resource/IMMEDIATE_DATA.d.ts +21 -0
  137. package/src/shade/renderer/shader/resource/IMMEDIATE_DATA.d.ts.map +1 -0
  138. package/src/shade/renderer/shader/resource/IMMEDIATE_DATA.js +21 -0
  139. package/src/shade/renderer/shader/resource/ShaderResourceSetDescriptor.d.ts +59 -1
  140. package/src/shade/renderer/shader/resource/ShaderResourceSetDescriptor.d.ts.map +1 -1
  141. package/src/shade/renderer/shader/resource/ShaderResourceSetDescriptor.js +195 -2
  142. package/src/shade/renderer/shader/type/type_has_arrays.d.ts +14 -0
  143. package/src/shade/renderer/shader/type/type_has_arrays.d.ts.map +1 -0
  144. package/src/shade/renderer/shader/type/type_has_arrays.js +33 -0
  145. package/src/shade/renderer/view/GPUViewSkyContext.d.ts.map +1 -1
  146. package/src/shade/renderer/view/GPUViewSkyContext.js +169 -173
  147. package/src/shade/renderer/volumetrics/NOTES.md +238 -0
  148. package/src/shade/renderer/volumetrics/chunk_volumetrics_local_light_shadow.js +145 -145
  149. package/src/shade/renderer/volumetrics/chunk_volumetrics_sun_optical_depth.d.ts.map +1 -1
  150. package/src/shade/renderer/volumetrics/chunk_volumetrics_sun_optical_depth.js +38 -15
  151. package/src/shade/renderer/volumetrics/graph_build_volumetrics.d.ts +14 -2
  152. package/src/shade/renderer/volumetrics/graph_build_volumetrics.d.ts.map +1 -1
  153. package/src/shade/renderer/volumetrics/graph_build_volumetrics.js +594 -577
  154. package/src/shade/renderer/volumetrics/shader_volumetrics_build_lighting.d.ts +16 -0
  155. package/src/shade/renderer/volumetrics/shader_volumetrics_build_lighting.d.ts.map +1 -1
  156. package/src/shade/renderer/volumetrics/shader_volumetrics_build_lighting.js +19 -2
  157. package/src/shade/renderer/volumetrics/shader_volumetrics_build_participating_media.d.ts.map +1 -1
  158. package/src/shade/renderer/volumetrics/shader_volumetrics_build_participating_media.js +29 -18
  159. package/src/shade/renderer/volumetrics/shader_volumetrics_build_scattering_lut.js +260 -260
  160. package/src/shade/renderer/volumetrics/shader_volumetrics_build_sun_shadow_volume.d.ts +53 -3
  161. package/src/shade/renderer/volumetrics/shader_volumetrics_build_sun_shadow_volume.d.ts.map +1 -1
  162. package/src/shade/renderer/volumetrics/shader_volumetrics_build_sun_shadow_volume.js +175 -59
  163. package/src/shade/wgsl/emulator/WGSLJavaScriptCompiler.js +8 -1
  164. package/src/shade/wgsl/emulator/WGSLLanguageCore.d.ts.map +1 -1
  165. package/src/shade/wgsl/emulator/WGSLLanguageCore.js +1325 -1297
  166. package/src/shade/renderer/volumetrics/VOLUMETRICS_WORKGROUP_RESOLUTION.d.ts +0 -2
  167. package/src/shade/renderer/volumetrics/VOLUMETRICS_WORKGROUP_RESOLUTION.d.ts.map +0 -1
  168. package/src/shade/renderer/volumetrics/VOLUMETRICS_WORKGROUP_RESOLUTION.js +0 -1
@@ -1,145 +1,145 @@
1
- import { LIGHT_DATABASE_SPEC } from "../light/LIGHT_DATABASE_SPEC.js";
2
- import { LIGHT_FLAGS } from "../light/model/io/LIGHT_FLAGS.js";
3
- import {
4
- chunk_uv_octahedral_unit_encode
5
- } from "../shader/chunk/geometry/octahedron/chunk_uv_octahedral_unit_encode.js";
6
- import { chunk_ndc_to_uv } from "../shader/chunk/texture/chunk_ndc_to_uv.js";
7
- import { CodeChunk } from "../shader/compiler/CodeChunk.js";
8
-
9
- const POINT_DESCRIPTOR = LIGHT_DATABASE_SPEC.get('light_point');
10
- const SPOT_DESCRIPTOR = LIGHT_DATABASE_SPEC.get('light_spot');
11
- const SHADOW_POINT_DESCRIPTOR = LIGHT_DATABASE_SPEC.get('shadow_point');
12
- const SHADOW_SPOT_DESCRIPTOR = LIGHT_DATABASE_SPEC.get('shadow_spot');
13
-
14
- /**
15
- * Shadow visibility for clustered point and spot lights, sampled the way a *volume* wants rather
16
- * than the way a surface does: one nearest texel out of the shadow atlas, no filter kernel, no
17
- * receiver bias.
18
- *
19
- * This exists alongside {@link chunk_shadowmap_get_light_visibility} rather than replacing it. The
20
- * deferred path needs its filtering — a hard shadow edge on a surface is a visible artefact — and
21
- * its cost is paid once per pixel. Here the cost is paid once per light per froxel, with up to 255
22
- * point and 255 spot lights in a cluster, and the playground scene alone carries 130 shadow-casting
23
- * point lights. The two callers want genuinely different things out of the same atlas, so they get
24
- * two functions over it; the atlas, its tile rects and its projections are untouched.
25
- *
26
- * Three reasons the cheap tap is not a compromise here:
27
- *
28
- * - The value being sampled is already an average over a froxel slab several pixels across, it is
29
- * jittered in xy and in depth every frame, and it then goes through a 3x3x3 Blackman-Harris
30
- * temporal resample at a 0.95 blend. A PCF kernel would be filtering something about to be
31
- * filtered three more times. Frostbite takes exactly this route for its froxel pass and accepts
32
- * the aliasing; Wronski's alternative (a separate pre-filtered low-resolution ESM) needs its own
33
- * target and build pass, and cannot be a downsample of THIS atlas because blurring moments
34
- * bleeds across tile borders.
35
- *
36
- * - There is no receiver bias because there is no receiver. Normal-offset and slope-scaled depth
37
- * bias exist to stop a surface shadowing itself; a medium cannot. Note that the deferred helpers
38
- * reach the same answer when a volumetric caller passes the light direction in place of a normal:
39
- * `get_shadow_offsets(N, L)` with `N == L` gives `cos_alpha = 1`, hence `sqrt(1 - 1) = 0` for the
40
- * normal scale and `0` for the depth scale, so both offsets vanish. Dropping them here therefore
41
- * does not change the sampled position relative to those helpers — only the tap count does.
42
- *
43
- * - `textureLoad` rather than `textureGatherCompare`: the comparison is one instruction either way,
44
- * and the raw load carries no uniformity requirement, so it is legal in the middle of a
45
- * non-uniform light loop without the gather dance `shadowmap_sample_filtered` needs.
46
- *
47
- * Both functions early-out to 1.0 on a light with no `CASTS_SHADOW_BIT`, so a non-shadowing light in
48
- * the cluster stays free.
49
- *
50
- * Requires `shadowmapAtlas` in the calling shader's scope.
51
- *
52
- * @type {CodeChunk}
53
- */
54
- export const chunk_volumetrics_local_light_shadow = CodeChunk.from(
55
- //language=WGSL
56
- `
57
- /**
58
- * Nearest texel of an atlas tile, given a uv over that tile. Clamped to the tile so a uv that lands
59
- * exactly on the far edge (or drifts a hair past it) cannot read a neighbouring light's slot.
60
- */
61
- fn volumetrics_shadow_atlas_texel(uv: vec2f, atlas_aabb: vec4f) -> vec2u {
62
- let local = clamp(floor(uv * atlas_aabb.zw), vec2f(0.0), atlas_aabb.zw - 1.0);
63
-
64
- return vec2u(local) + vec2u(atlas_aabb.xy);
65
- }
66
-
67
- fn volumetrics_point_light_shadow(
68
- database: ptr<storage, array<u32>>,
69
- point_index: u32,
70
- position_ws: vec3f,
71
- ) -> f32 {
72
- let light = ${POINT_DESCRIPTOR.marshalling_method_read}(database, point_index);
73
-
74
- if ((light.flags & ${LIGHT_FLAGS.CASTS_SHADOW_BIT}u) == 0u) {
75
- return 1.0;
76
- }
77
-
78
- let atlas_aabb = ${SHADOW_POINT_DESCRIPTOR.marshalling_method_read}(database, light.shadow_id);
79
-
80
- // the cube faces are captured FROM the light, so the octahedral encode takes light -> sample
81
- let to_sample = position_ws - light.position;
82
- let distance_to_center = length(to_sample);
83
-
84
- let direction_light_to_sample = to_sample / max(distance_to_center, 1e-6);
85
-
86
- // reverse-Z radial, matching what the point shadow pass stores: at the light -> 1, at or beyond
87
- // the light's range -> 0.
88
- let reference_depth = 1.0 - saturate(distance_to_center / max(light.distance, 1e-6));
89
-
90
- let texel = volumetrics_shadow_atlas_texel(
91
- uv_octahedral_unit_encode(direction_light_to_sample),
92
- atlas_aabb
93
- );
94
-
95
- let stored = textureLoad(shadowmapAtlas, texel, 0);
96
-
97
- // A larger stored value is NEARER the light, so an occluder in front of this froxel reads
98
- // greater than the froxel's own radial depth. Cleared atlas regions hold 0 and therefore never
99
- // occlude, which is the right default for a light whose map was not rendered this frame.
100
- return select(1.0, 0.0, stored > reference_depth);
101
- }
102
-
103
- fn volumetrics_spot_light_shadow(
104
- database: ptr<storage, array<u32>>,
105
- spot_index: u32,
106
- position_ws: vec3f,
107
- ) -> f32 {
108
- let light = ${SPOT_DESCRIPTOR.marshalling_method_read}(database, spot_index);
109
-
110
- if ((light.flags & ${LIGHT_FLAGS.CASTS_SHADOW_BIT}u) == 0u) {
111
- return 1.0;
112
- }
113
-
114
- let view_meta = ${SHADOW_SPOT_DESCRIPTOR.marshalling_method_read}(database, light.shadow_id);
115
-
116
- // Spot shadows are a single perspective view, so the divide is load-bearing (unlike the ortho
117
- // cascades, where w is always 1). No bias offset is added before the transform — see the header.
118
- let clip_light = view_meta.projection * vec4(position_ws, 1.0);
119
-
120
- if (clip_light.w <= 0.0) {
121
- // behind the light's apex: outside the map entirely, and the cone attenuation has already
122
- // zeroed this light's contribution, so the value is moot. Unshadowed is the safe answer.
123
- return 1.0;
124
- }
125
-
126
- let pos_light = clip_light.xyz / clip_light.w;
127
-
128
- let texel = volumetrics_shadow_atlas_texel(ndc_to_uv(pos_light.xy), view_meta.atlas);
129
-
130
- let stored = textureLoad(shadowmapAtlas, texel, 0);
131
-
132
- // SHADOWMAP_COMPARE_SAMPLER_DESCRIPTOR compares "greater" — visible where the receiver's depth
133
- // exceeds the stored one, which under reverse-Z means nearer to the light. Reproduced here by
134
- // hand because the raw load skips the comparison sampler.
135
- return select(0.0, 1.0, pos_light.z > stored);
136
- }
137
- `, [
138
- POINT_DESCRIPTOR.chunk_read,
139
- SPOT_DESCRIPTOR.chunk_read,
140
- SHADOW_POINT_DESCRIPTOR.chunk_read,
141
- SHADOW_SPOT_DESCRIPTOR.chunk_read,
142
- chunk_ndc_to_uv,
143
- chunk_uv_octahedral_unit_encode,
144
- ]
145
- );
1
+ import { LIGHT_DATABASE_SPEC } from "../light/LIGHT_DATABASE_SPEC.js";
2
+ import { LIGHT_FLAGS } from "../light/model/io/LIGHT_FLAGS.js";
3
+ import {
4
+ chunk_uv_octahedral_unit_encode
5
+ } from "../shader/chunk/geometry/octahedron/chunk_uv_octahedral_unit_encode.js";
6
+ import { chunk_ndc_to_uv } from "../shader/chunk/texture/chunk_ndc_to_uv.js";
7
+ import { CodeChunk } from "../shader/compiler/CodeChunk.js";
8
+
9
+ const POINT_DESCRIPTOR = LIGHT_DATABASE_SPEC.get('light_point');
10
+ const SPOT_DESCRIPTOR = LIGHT_DATABASE_SPEC.get('light_spot');
11
+ const SHADOW_POINT_DESCRIPTOR = LIGHT_DATABASE_SPEC.get('shadow_point');
12
+ const SHADOW_SPOT_DESCRIPTOR = LIGHT_DATABASE_SPEC.get('shadow_spot');
13
+
14
+ /**
15
+ * Shadow visibility for clustered point and spot lights, sampled the way a *volume* wants rather
16
+ * than the way a surface does: one nearest texel out of the shadow atlas, no filter kernel, no
17
+ * receiver bias.
18
+ *
19
+ * This exists alongside {@link chunk_shadowmap_get_light_visibility} rather than replacing it. The
20
+ * deferred path needs its filtering — a hard shadow edge on a surface is a visible artefact — and
21
+ * its cost is paid once per pixel. Here the cost is paid once per light per froxel, with up to 255
22
+ * point and 255 spot lights in a cluster, and the playground scene alone carries 130 shadow-casting
23
+ * point lights. The two callers want genuinely different things out of the same atlas, so they get
24
+ * two functions over it; the atlas, its tile rects and its projections are untouched.
25
+ *
26
+ * Three reasons the cheap tap is not a compromise here:
27
+ *
28
+ * - The value being sampled is already an average over a froxel slab several pixels across, it is
29
+ * jittered in xy and in depth every frame, and it then goes through a 3x3x3 Blackman-Harris
30
+ * temporal resample at a 0.95 blend. A PCF kernel would be filtering something about to be
31
+ * filtered three more times. Frostbite takes exactly this route for its froxel pass and accepts
32
+ * the aliasing; Wronski's alternative (a separate pre-filtered low-resolution ESM) needs its own
33
+ * target and build pass, and cannot be a downsample of THIS atlas because blurring moments
34
+ * bleeds across tile borders.
35
+ *
36
+ * - There is no receiver bias because there is no receiver. Normal-offset and slope-scaled depth
37
+ * bias exist to stop a surface shadowing itself; a medium cannot. Note that the deferred helpers
38
+ * reach the same answer when a volumetric caller passes the light direction in place of a normal:
39
+ * `get_shadow_offsets(N, L)` with `N == L` gives `cos_alpha = 1`, hence `sqrt(1 - 1) = 0` for the
40
+ * normal scale and `0` for the depth scale, so both offsets vanish. Dropping them here therefore
41
+ * does not change the sampled position relative to those helpers — only the tap count does.
42
+ *
43
+ * - `textureLoad` rather than `textureGatherCompare`: the comparison is one instruction either way,
44
+ * and the raw load carries no uniformity requirement, so it is legal in the middle of a
45
+ * non-uniform light loop without the gather dance `shadowmap_sample_filtered` needs.
46
+ *
47
+ * Both functions early-out to 1.0 on a light with no `CASTS_SHADOW_BIT`, so a non-shadowing light in
48
+ * the cluster stays free.
49
+ *
50
+ * Requires `shadowmapAtlas` in the calling shader's scope.
51
+ *
52
+ * @type {CodeChunk}
53
+ */
54
+ export const chunk_volumetrics_local_light_shadow = CodeChunk.from(
55
+ //language=WGSL
56
+ `
57
+ /**
58
+ * Nearest texel of an atlas tile, given a uv over that tile. Clamped to the tile so a uv that lands
59
+ * exactly on the far edge (or drifts a hair past it) cannot read a neighbouring light's slot.
60
+ */
61
+ fn volumetrics_shadow_atlas_texel(uv: vec2f, atlas_aabb: vec4f) -> vec2u {
62
+ let local = clamp(floor(uv * atlas_aabb.zw), vec2f(0.0), atlas_aabb.zw - 1.0);
63
+
64
+ return vec2u(local) + vec2u(atlas_aabb.xy);
65
+ }
66
+
67
+ fn volumetrics_point_light_shadow(
68
+ database: ptr<storage, array<u32>>,
69
+ point_index: u32,
70
+ position_ws: vec3f,
71
+ ) -> f32 {
72
+ let light = ${POINT_DESCRIPTOR.marshalling_method_read}(database, point_index);
73
+
74
+ if ((light.flags & ${LIGHT_FLAGS.CASTS_SHADOW_BIT}u) == 0u) {
75
+ return 1.0;
76
+ }
77
+
78
+ let atlas_aabb = ${SHADOW_POINT_DESCRIPTOR.marshalling_method_read}(database, light.shadow_id);
79
+
80
+ // the cube faces are captured FROM the light, so the octahedral encode takes light -> sample
81
+ let to_sample = position_ws - light.position;
82
+ let distance_to_center = length(to_sample);
83
+
84
+ let direction_light_to_sample = to_sample / max(distance_to_center, 1e-6);
85
+
86
+ // reverse-Z radial, matching what the point shadow pass stores: at the light -> 1, at or beyond
87
+ // the light's range -> 0.
88
+ let reference_depth = 1.0 - saturate(distance_to_center / max(light.distance, 1e-6));
89
+
90
+ let texel = volumetrics_shadow_atlas_texel(
91
+ uv_octahedral_unit_encode(direction_light_to_sample),
92
+ atlas_aabb
93
+ );
94
+
95
+ let stored = textureLoad(shadowmapAtlas, texel, 0);
96
+
97
+ // A larger stored value is NEARER the light, so an occluder in front of this froxel reads
98
+ // greater than the froxel's own radial depth. Cleared atlas regions hold 0 and therefore never
99
+ // occlude, which is the right default for a light whose map was not rendered this frame.
100
+ return select(1.0, 0.0, stored > reference_depth);
101
+ }
102
+
103
+ fn volumetrics_spot_light_shadow(
104
+ database: ptr<storage, array<u32>>,
105
+ spot_index: u32,
106
+ position_ws: vec3f,
107
+ ) -> f32 {
108
+ let light = ${SPOT_DESCRIPTOR.marshalling_method_read}(database, spot_index);
109
+
110
+ if ((light.flags & ${LIGHT_FLAGS.CASTS_SHADOW_BIT}u) == 0u) {
111
+ return 1.0;
112
+ }
113
+
114
+ let view_meta = ${SHADOW_SPOT_DESCRIPTOR.marshalling_method_read}(database, light.shadow_id);
115
+
116
+ // Spot shadows are a single perspective view, so the divide is load-bearing (unlike the ortho
117
+ // cascades, where w is always 1). No bias offset is added before the transform — see the header.
118
+ let clip_light = view_meta.projection * vec4(position_ws, 1.0);
119
+
120
+ if (clip_light.w <= 0.0) {
121
+ // behind the light's apex: outside the map entirely, and the cone attenuation has already
122
+ // zeroed this light's contribution, so the value is moot. Unshadowed is the safe answer.
123
+ return 1.0;
124
+ }
125
+
126
+ let pos_light = clip_light.xyz / clip_light.w;
127
+
128
+ let texel = volumetrics_shadow_atlas_texel(ndc_to_uv(pos_light.xy), view_meta.atlas);
129
+
130
+ let stored = textureLoad(shadowmapAtlas, texel, 0);
131
+
132
+ // SHADOWMAP_COMPARE_SAMPLER_DESCRIPTOR compares "greater" — visible where the receiver's depth
133
+ // exceeds the stored one, which under reverse-Z means nearer to the light. Reproduced here by
134
+ // hand because the raw load skips the comparison sampler.
135
+ return select(0.0, 1.0, pos_light.z > stored);
136
+ }
137
+ `, [
138
+ POINT_DESCRIPTOR.chunk_read,
139
+ SPOT_DESCRIPTOR.chunk_read,
140
+ SHADOW_POINT_DESCRIPTOR.chunk_read,
141
+ SHADOW_SPOT_DESCRIPTOR.chunk_read,
142
+ chunk_ndc_to_uv,
143
+ chunk_uv_octahedral_unit_encode,
144
+ ]
145
+ );
@@ -1 +1 @@
1
- {"version":3,"file":"chunk_volumetrics_sun_optical_depth.d.ts","sourceRoot":"","sources":["../../../../../src/shade/renderer/volumetrics/chunk_volumetrics_sun_optical_depth.js"],"names":[],"mappings":"AAIA;;;;;;;;;;GAUG;AACH,2DAHW,MAAM,GACJ,MAAM,CAIlB;AAkDD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,kDAFU,SAAS,CAkBjB;0BAzGwB,iCAAiC"}
1
+ {"version":3,"file":"chunk_volumetrics_sun_optical_depth.d.ts","sourceRoot":"","sources":["../../../../../src/shade/renderer/volumetrics/chunk_volumetrics_sun_optical_depth.js"],"names":[],"mappings":"AAIA;;;;;;;;;;GAUG;AACH,2DAHW,MAAM,GACJ,MAAM,CAIlB;AA2ED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,kDAFU,SAAS,CAgBjB;0BAhIwB,iCAAiC"}
@@ -29,21 +29,48 @@ export function volumetrics_sun_shadow_texture_name(index) {
29
29
  */
30
30
  const CASCADE_BLEND_START = 0.9;
31
31
 
32
- function cascade_lookup(index) {
33
- return `
32
+ /**
33
+ * Outermost cascade. It is where the selection ladder falls out to, so it is the one cascade with
34
+ * no successor to hand over to, and therefore the bound on the ladder rather than a step in it.
35
+ *
36
+ * @type {number}
37
+ */
38
+ const LAST_CASCADE = VOLUMETRICS_SUN_SHADOW_CASCADE_COUNT - 1;
39
+
40
+ /**
41
+ * One `volumetrics_sun_optical_depth_cascade_<index>` per cascade.
42
+ *
43
+ * @type {string}
44
+ */
45
+ let cascade_lookups = "";
46
+
47
+ for (let index = 0; index < VOLUMETRICS_SUN_SHADOW_CASCADE_COUNT; index++) {
48
+
49
+ //language=WGSL
50
+ cascade_lookups += `
34
51
  fn volumetrics_sun_optical_depth_cascade_${index}(position_ws: vec3<f32>) -> vec3<f32> {
35
52
 
36
53
  let uvw = (volumetrics_metadata.sun_shadow_ws_to_uvw[${index}] * vec4<f32>(position_ws, 1.0)).xyz;
37
54
 
38
55
  return textureSampleLevel(${volumetrics_sun_shadow_texture_name(index)}, sLinear, saturate(uvw), 0.0).rgb;
39
- }`;
40
56
  }
57
+ `;
58
+ }
59
+
60
+ /**
61
+ * The ladder that picks between those lookups, one block per hand-over, spliced into the body of
62
+ * `volumetrics_sun_optical_depth`. Indexed over the same cascades and one short, so a cascade
63
+ * declared above and never reached here is a function nothing samples, and a block here naming a
64
+ * cascade not declared above is a call to a function that does not exist.
65
+ *
66
+ * @type {string}
67
+ */
68
+ let cascade_selection = "";
41
69
 
42
- function cascade_selection() {
43
- const lines = [];
70
+ for (let index = 0; index < LAST_CASCADE; index++) {
44
71
 
45
- for (let index = 0; index < VOLUMETRICS_SUN_SHADOW_CASCADE_COUNT - 1; index++) {
46
- lines.push(`
72
+ //language=WGSL
73
+ cascade_selection += `
47
74
  {
48
75
  let far = volumetrics_metadata.sun_shadow_cascade_far[${index}];
49
76
  let blend_start = far * ${CASCADE_BLEND_START};
@@ -59,10 +86,8 @@ function cascade_selection() {
59
86
  (view_depth - blend_start) / (far - blend_start)
60
87
  );
61
88
  }
62
- }`);
63
89
  }
64
-
65
- return lines.join("\n");
90
+ `;
66
91
  }
67
92
 
68
93
  /**
@@ -91,15 +116,13 @@ function cascade_selection() {
91
116
  export const chunk_volumetrics_sun_optical_depth = CodeChunk.from(
92
117
  //language=WGSL
93
118
  `
94
- ${Array.from({ length: VOLUMETRICS_SUN_SHADOW_CASCADE_COUNT }, (_, index) => cascade_lookup(index)).join("\n")}
95
-
119
+ ${cascade_lookups}
96
120
  fn volumetrics_sun_optical_depth(position_ws: vec3<f32>) -> vec3<f32> {
97
121
 
98
122
  // view space looks down -Z
99
123
  let view_depth = -(camera.view_matrix * vec4<f32>(position_ws, 1.0)).z;
100
- ${cascade_selection()}
101
-
102
- return volumetrics_sun_optical_depth_cascade_${VOLUMETRICS_SUN_SHADOW_CASCADE_COUNT - 1}(position_ws);
124
+ ${cascade_selection}
125
+ return volumetrics_sun_optical_depth_cascade_${LAST_CASCADE}(position_ws);
103
126
  }
104
127
  `, [
105
128
  CAMERA_UNIFORM_STRUCT.declaration_chunk,
@@ -1,3 +1,15 @@
1
+ /**
2
+ * Transmittance LUT, then the multiple-scattering LUT that reads it. Exported for
3
+ * `graph_integrate_sky.spec.js`, which pins the dispatch shape and the transient's usage
4
+ * flags -- neither of which the WGSL validity gate can see.
5
+ *
6
+ * @param {FrameGraph} graph
7
+ * @returns {{transmittance_lut: number, multiscatted_lut: number}} resource handles
8
+ */
9
+ export function graph_integrate_sky({ graph }: FrameGraph): {
10
+ transmittance_lut: number;
11
+ multiscatted_lut: number;
12
+ };
1
13
  /**
2
14
  *
3
15
  * @param {FrameGraph} graph
@@ -18,8 +30,8 @@
18
30
  * @param {GPUCameraContext} [camera_previous] previous-frame camera, for temporal reprojection
19
31
  */
20
32
  export function graph_build_volumetrics({ graph, camera, lights, view, light_cluster_data, light_cluster_lookup, light_cluster_parameters, shadowmap_atlas, volumetric_resolution, sun_shadow_resolution, volumetrics_metadata, taa_history, taa_output, camera_previous, }: FrameGraph): {
21
- lut_transmittance: any;
22
- lut_multiple_scattering: any;
33
+ lut_transmittance: number;
34
+ lut_multiple_scattering: number;
23
35
  lut_aerial: any;
24
36
  volumetrics_metadata: FrameGraph;
25
37
  };
@@ -1 +1 @@
1
- {"version":3,"file":"graph_build_volumetrics.d.ts","sourceRoot":"","sources":["../../../../../src/shade/renderer/volumetrics/graph_build_volumetrics.js"],"names":[],"mappings":"AAyYA;;;;;;;;;;;;;;;;;;GAkBG;AACH;;;;;EAqKC"}
1
+ {"version":3,"file":"graph_build_volumetrics.d.ts","sourceRoot":"","sources":["../../../../../src/shade/renderer/volumetrics/graph_build_volumetrics.js"],"names":[],"mappings":"AA4BA;;;;;;;GAOG;AACH,4DAFa;IAAC,iBAAiB,EAAE,MAAM,CAAC;IAAC,gBAAgB,EAAE,MAAM,CAAA;CAAC,CAgEjE;AAqTD;;;;;;;;;;;;;;;;;;GAkBG;AACH;;;;;EAwKC"}