@woosh/meep-engine 3.60.9 → 3.61.1

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 (109) hide show
  1. package/CHANGELOG.md +90 -0
  2. package/package.json +1 -1
  3. package/src/engine/ecs/EntityManager.d.ts +3 -3
  4. package/src/engine/ecs/EntityManager.js +3 -3
  5. package/src/engine/ecs/storage/populateEngineSerializationRegistry.d.ts.map +1 -1
  6. package/src/engine/ecs/storage/populateEngineSerializationRegistry.js +4 -0
  7. package/src/engine/graphics/ecs/decal/v2/Decal.d.ts +46 -2
  8. package/src/engine/graphics/ecs/decal/v2/Decal.d.ts.map +1 -1
  9. package/src/engine/graphics/ecs/decal/v2/Decal.js +74 -5
  10. package/src/engine/graphics/ecs/decal/v2/DecalSerializationAdapter.d.ts.map +1 -1
  11. package/src/engine/graphics/ecs/decal/v2/DecalSerializationAdapter.js +13 -1
  12. package/src/engine/graphics/ecs/decal/v2/DecalSerializationUpgrader_1_2.d.ts +9 -0
  13. package/src/engine/graphics/ecs/decal/v2/DecalSerializationUpgrader_1_2.d.ts.map +1 -0
  14. package/src/engine/graphics/ecs/decal/v2/DecalSerializationUpgrader_1_2.js +37 -0
  15. package/src/engine/graphics3/DecalSystem.d.ts.map +1 -1
  16. package/src/engine/graphics3/DecalSystem.js +462 -447
  17. package/src/engine/graphics3/decal/DECAL_GPU_RECORD.d.ts +14 -0
  18. package/src/engine/graphics3/decal/DECAL_GPU_RECORD.d.ts.map +1 -1
  19. package/src/engine/graphics3/decal/DECAL_GPU_RECORD.js +53 -13
  20. package/src/engine/graphics3/decal/chunk_decal_record.d.ts +6 -1
  21. package/src/engine/graphics3/decal/chunk_decal_record.d.ts.map +1 -1
  22. package/src/engine/graphics3/decal/chunk_decal_record.js +28 -9
  23. package/src/engine/graphics3/decal/decal_gpu_records.d.ts +2 -1
  24. package/src/engine/graphics3/decal/decal_gpu_records.d.ts.map +1 -1
  25. package/src/engine/graphics3/decal/decal_gpu_records.js +26 -5
  26. package/src/engine/graphics3/decal/decal_material_samplers.d.ts +6 -0
  27. package/src/engine/graphics3/decal/decal_material_samplers.d.ts.map +1 -1
  28. package/src/engine/graphics3/decal/decal_material_samplers.js +13 -0
  29. package/src/engine/graphics3/decal/shader_cluster_assign_decals.js +1 -1
  30. package/src/engine/graphics3/decal/shader_cull_decals_frustum.js +1 -1
  31. package/src/engine/graphics3/decal/shader_decal_composite.d.ts +5 -0
  32. package/src/engine/graphics3/decal/shader_decal_composite.d.ts.map +1 -1
  33. package/src/engine/graphics3/decal/shader_decal_composite.js +69 -28
  34. package/src/engine/network/NetworkSession.d.ts +3 -0
  35. package/src/engine/network/NetworkSession.d.ts.map +1 -1
  36. package/src/engine/network/NetworkSession.js +68 -10
  37. package/src/engine/network/README.md +6 -3
  38. package/src/engine/network/orchestrator/ServerAuthoritativeClient.d.ts +51 -5
  39. package/src/engine/network/orchestrator/ServerAuthoritativeClient.d.ts.map +1 -1
  40. package/src/engine/network/orchestrator/ServerAuthoritativeClient.js +308 -34
  41. package/src/engine/network/replication/Replicator.d.ts +8 -2
  42. package/src/engine/network/replication/Replicator.d.ts.map +1 -1
  43. package/src/engine/network/replication/Replicator.js +13 -4
  44. package/src/engine/network/sim/ActionLog.d.ts +16 -2
  45. package/src/engine/network/sim/ActionLog.d.ts.map +1 -1
  46. package/src/engine/network/sim/ActionLog.js +33 -2
  47. package/src/engine/network/sim/RewindEngine.d.ts +9 -0
  48. package/src/engine/network/sim/RewindEngine.d.ts.map +1 -1
  49. package/src/engine/network/sim/RewindEngine.js +15 -1
  50. package/src/engine/network/state/FrameBufferRing.d.ts +12 -5
  51. package/src/engine/network/state/FrameBufferRing.d.ts.map +1 -1
  52. package/src/engine/network/state/FrameBufferRing.js +32 -6
  53. package/src/engine/network/time/TimeDilation.d.ts +30 -14
  54. package/src/engine/network/time/TimeDilation.d.ts.map +1 -1
  55. package/src/engine/network/time/TimeDilation.js +47 -17
  56. package/src/engine/physics/fluid/ecs/FluidObstacleSystem.d.ts +4 -4
  57. package/src/generation/foliage/skeleton/ShootWoodHash.d.ts +3 -2
  58. package/src/generation/foliage/skeleton/ShootWoodHash.d.ts.map +1 -1
  59. package/src/generation/foliage/skeleton/ShootWoodHash.js +25 -2
  60. package/src/shade/renderer/buffer/graph_read_buffer.d.ts +3 -1
  61. package/src/shade/renderer/buffer/graph_read_buffer.d.ts.map +1 -1
  62. package/src/shade/renderer/buffer/graph_read_buffer.js +9 -6
  63. package/src/shade/renderer/buffer/util/shader_buffer_copy_storage_to_storage.d.ts +5 -0
  64. package/src/shade/renderer/buffer/util/shader_buffer_copy_storage_to_storage.d.ts.map +1 -1
  65. package/src/shade/renderer/buffer/util/shader_buffer_copy_storage_to_storage.js +48 -43
  66. package/src/shade/renderer/material/GPUMaterialManager.d.ts.map +1 -1
  67. package/src/shade/renderer/material/GPUMaterialManager.js +117 -35
  68. package/src/shade/renderer/material/standard/fragment_gbuffer.d.ts +2 -2
  69. package/src/shade/renderer/material/standard/fragment_gbuffer.d.ts.map +1 -1
  70. package/src/shade/renderer/material/standard/fragment_gbuffer.js +10 -3
  71. package/src/shade/renderer/material/standard/material_gbuffer_vertex.d.ts +15 -3
  72. package/src/shade/renderer/material/standard/material_gbuffer_vertex.d.ts.map +1 -1
  73. package/src/shade/renderer/material/standard/material_gbuffer_vertex.js +25 -4
  74. package/src/shade/renderer/particles/GPUParticleSystem.d.ts +23 -5
  75. package/src/shade/renderer/particles/GPUParticleSystem.d.ts.map +1 -1
  76. package/src/shade/renderer/particles/GPUParticleSystem.js +294 -20
  77. package/src/shade/renderer/particles/resize/shader_particle_shrink_alive_list.d.ts +21 -0
  78. package/src/shade/renderer/particles/resize/shader_particle_shrink_alive_list.d.ts.map +1 -0
  79. package/src/shade/renderer/particles/resize/shader_particle_shrink_alive_list.js +83 -0
  80. package/src/shade/renderer/particles/resize/shader_particle_shrink_free_list.d.ts +21 -0
  81. package/src/shade/renderer/particles/resize/shader_particle_shrink_free_list.d.ts.map +1 -0
  82. package/src/shade/renderer/particles/resize/shader_particle_shrink_free_list.js +64 -0
  83. package/src/shade/renderer/restir/di/chunk_restir_resolve.d.ts.map +1 -1
  84. package/src/shade/renderer/restir/di/chunk_restir_resolve.js +91 -94
  85. package/src/shade/renderer/restir/reservoir/chunk_rtxdi_stream_sample.js +1 -1
  86. package/src/shade/renderer/shader/chunk/color/rgbe9995/chunk_rgbe9995_decode.d.ts +14 -0
  87. package/src/shade/renderer/shader/chunk/color/rgbe9995/chunk_rgbe9995_decode.d.ts.map +1 -1
  88. package/src/shade/renderer/shader/chunk/color/rgbe9995/chunk_rgbe9995_decode.js +36 -21
  89. package/src/shade/renderer/shader/chunk/color/rgbe9995/chunk_rgbe9995_sample_gather.d.ts +22 -0
  90. package/src/shade/renderer/shader/chunk/color/rgbe9995/chunk_rgbe9995_sample_gather.d.ts.map +1 -0
  91. package/src/shade/renderer/shader/chunk/color/rgbe9995/chunk_rgbe9995_sample_gather.js +64 -0
  92. package/src/shade/renderer/shader/chunk/geometry/normal/chunk_decode_vertex_normal.d.ts.map +1 -1
  93. package/src/shade/renderer/shader/chunk/geometry/normal/chunk_decode_vertex_normal.js +13 -18
  94. package/src/shade/renderer/shader/chunk/geometry/normal/chunk_encode_vertex_normal.d.ts.map +1 -1
  95. package/src/shade/renderer/shader/chunk/geometry/normal/chunk_encode_vertex_normal.js +28 -30
  96. package/src/shade/renderer/shader/chunk/geometry/vec2/chunk_unit_u32_to_vec2.d.ts.map +1 -1
  97. package/src/shade/renderer/shader/chunk/geometry/vec2/chunk_unit_u32_to_vec2.js +15 -16
  98. package/src/shade/renderer/shader/chunk/geometry/vec2/chunk_unit_vec2_to_u32.d.ts +0 -1
  99. package/src/shade/renderer/shader/chunk/geometry/vec2/chunk_unit_vec2_to_u32.d.ts.map +1 -1
  100. package/src/shade/renderer/shader/chunk/geometry/vec2/chunk_unit_vec2_to_u32.js +15 -18
  101. package/src/shade/renderer/shader/chunk/subgroup/chunk_subgroup_bitset_or.d.ts +32 -0
  102. package/src/shade/renderer/shader/chunk/subgroup/chunk_subgroup_bitset_or.d.ts.map +1 -0
  103. package/src/shade/renderer/shader/chunk/subgroup/chunk_subgroup_bitset_or.js +73 -0
  104. package/src/shade/wgsl/emulator/WGSLJavaScriptCompiler.js +8 -1
  105. package/src/shade/wgsl/emulator/WGSLLanguageCore.d.ts.map +1 -1
  106. package/src/shade/wgsl/emulator/WGSLLanguageCore.js +7 -3
  107. package/src/shade/renderer/global_illumination/brick4/cpu/brick4_sh3_color_encode.d.ts +0 -2
  108. package/src/shade/renderer/global_illumination/brick4/cpu/brick4_sh3_color_encode.d.ts.map +0 -1
  109. package/src/shade/renderer/global_illumination/brick4/cpu/brick4_sh3_color_encode.js +0 -6
@@ -1,94 +1,91 @@
1
- import { REFLECTED_LIGHT_STRUCT } from "../../shader/chunk/light/REFLECTED_LIGHT_STRUCT.js";
2
- import { chunk_re_direct_multiscatter } from "../../shader/chunk/material/chunk_re_direct_multiscatter.js";
3
- import { chunk_re_direct_physical } from "../../shader/chunk/material/chunk_re_direct_physical.js";
4
- import { GEOMETRIC_SHADING_INFO_STRUCT } from "../../shader/chunk/material/GEOMETRIC_SHADING_INFO_STRUCT.js";
5
- import { MATERIAL_SHADING_INFO_STRUCT } from "../../shader/chunk/material/MATERIAL_SHADING_INFO_STRUCT.js";
6
- import { RTXDI_Reservoir } from "../reservoir/RTXDI_Reservoir.js";
7
- import { CodeChunk } from "../../shader/compiler/CodeChunk.js";
8
- import { chunk_restir_get_light_info } from "./chunk_restir_get_light_info.js";
9
- import { chunk_restir_light_ref } from "./chunk_restir_light_ref.js";
10
- import { chunk_restir_sample_light_record } from "./chunk_restir_sample_light_record.js";
11
- import { chunk_restir_trace_visibility } from "./chunk_restir_trace_visibility.js";
12
-
13
- /**
14
- * Resolve a finalized reservoir to outgoing radiance for the selected light:
15
- *
16
- * radiance = BRDF·Le·G (full RGB, unshadowed) · W · V
17
- *
18
- * where W == reservoir.weightSum after FinalizeResampling (it already folds in
19
- * 1/p_hat and 1/M) and V is the traced visibility (the RTXDI `f_rgb · weightSum`
20
- * identity). p_hat is the luminance of the single-scattering BRDF·Le·G; this
21
- * BRDF also carries `re_direct_multiscatter`'s per-pixel scale of the specular,
22
- * so f / p_hat is no longer 1 but stays within [1, that scale]. The estimate is
23
- * unbiased either way: f and p_hat are positive on the same lights.
24
- *
25
- * Visibility is a single opaque shadow ray toward the survivor's sampled emitter
26
- * point — matching the brute-force NEE reference (`ray_sample_light`), which also
27
- * uses `ray_query_occluded`. Requires the RTX resource group to be bound.
28
- *
29
- * Emissive is intentionally excluded; the deferred pass adds it once.
30
- *
31
- * @type {CodeChunk}
32
- */
33
- export const chunk_restir_resolve = CodeChunk.from(
34
- //language=WGSL
35
- `
36
- fn restir_resolve(
37
- i_coord: vec2<u32>,
38
- reservoir: ${RTXDI_Reservoir.wgsl_ref},
39
- geometry: ${GEOMETRIC_SHADING_INFO_STRUCT.wgsl_ref},
40
- material: ${MATERIAL_SHADING_INFO_STRUCT.wgsl_ref},
41
- use_screen_space_shadow: u32
42
- ) -> vec3<f32> {
43
- if (!restir_light_ref_is_valid(reservoir.lightData) || reservoir.weightSum <= 0.0) {
44
- return vec3<f32>(0.0);
45
- }
46
-
47
- let light_type = restir_light_ref_type(reservoir.lightData);
48
- let light_index = restir_light_ref_index(reservoir.lightData);
49
-
50
- // Full RGB unshadowed contribution via the representative-point incident light.
51
- let incident = restir_get_light_info(light_type, light_index, geometry.position);
52
- var reflected: ${REFLECTED_LIGHT_STRUCT.wgsl_ref};
53
- re_direct_physical(incident, geometry, material, &reflected);
54
- re_direct_multiscatter(geometry, material, &reflected);
55
- let radiance = reflected.diffuse + reflected.specular;
56
-
57
- if (all(radiance <= vec3<f32>(0.0))) {
58
- return vec3<f32>(0.0);
59
- }
60
-
61
- // Decode the stored 16-bit-fixed-point area-light sample point.
62
- let uv = vec2<f32>(
63
- f32(reservoir.uvData & 0xFFFFu) / 65535.0,
64
- f32((reservoir.uvData >> 16u) & 0xFFFFu) / 65535.0
65
- );
66
- let record = restir_sample_light_record(light_type, light_index, geometry.position, uv);
67
-
68
- var visibility = 1.0;
69
- if (record.distance > 0.0) {
70
- visibility = restir_trace_visibility(
71
- i_coord,
72
- geometry.position,
73
- geometry.geometric_normal,
74
- record.direction,
75
- record.distance,
76
- use_screen_space_shadow != 0u,
77
- );
78
- }
79
-
80
- return radiance * reservoir.weightSum * visibility;
81
- }
82
- `, [
83
- RTXDI_Reservoir.declaration_chunk,
84
- REFLECTED_LIGHT_STRUCT.declaration_chunk,
85
- GEOMETRIC_SHADING_INFO_STRUCT.declaration_chunk,
86
- MATERIAL_SHADING_INFO_STRUCT.declaration_chunk,
87
- chunk_re_direct_physical,
88
- chunk_re_direct_multiscatter,
89
- chunk_restir_get_light_info,
90
- chunk_restir_light_ref,
91
- chunk_restir_sample_light_record,
92
- chunk_restir_trace_visibility,
93
- ]
94
- );
1
+ import { REFLECTED_LIGHT_STRUCT } from "../../shader/chunk/light/REFLECTED_LIGHT_STRUCT.js";
2
+ import { chunk_re_direct_multiscatter } from "../../shader/chunk/material/chunk_re_direct_multiscatter.js";
3
+ import { chunk_re_direct_physical } from "../../shader/chunk/material/chunk_re_direct_physical.js";
4
+ import { GEOMETRIC_SHADING_INFO_STRUCT } from "../../shader/chunk/material/GEOMETRIC_SHADING_INFO_STRUCT.js";
5
+ import { MATERIAL_SHADING_INFO_STRUCT } from "../../shader/chunk/material/MATERIAL_SHADING_INFO_STRUCT.js";
6
+ import { RTXDI_Reservoir } from "../reservoir/RTXDI_Reservoir.js";
7
+ import { CodeChunk } from "../../shader/compiler/CodeChunk.js";
8
+ import { chunk_restir_get_light_info } from "./chunk_restir_get_light_info.js";
9
+ import { chunk_restir_light_ref } from "./chunk_restir_light_ref.js";
10
+ import { chunk_restir_sample_light_record } from "./chunk_restir_sample_light_record.js";
11
+ import { chunk_restir_trace_visibility } from "./chunk_restir_trace_visibility.js";
12
+
13
+ /**
14
+ * Resolve a finalized reservoir to outgoing radiance for the selected light:
15
+ *
16
+ * radiance = BRDF·Le·G (full RGB, unshadowed) · W · V
17
+ *
18
+ * where W == reservoir.weightSum after FinalizeResampling (it already folds in
19
+ * 1/p_hat and 1/M) and V is the traced visibility (the RTXDI `f_rgb · weightSum`
20
+ * identity). p_hat is the luminance of the single-scattering BRDF·Le·G; this
21
+ * BRDF also carries `re_direct_multiscatter`'s per-pixel scale of the specular,
22
+ * so f / p_hat is no longer 1 but stays within [1, that scale]. The estimate is
23
+ * unbiased either way: f and p_hat are positive on the same lights.
24
+ *
25
+ * Visibility is a single opaque shadow ray toward the survivor's sampled emitter
26
+ * point — matching the brute-force NEE reference (`ray_sample_light`), which also
27
+ * uses `ray_query_occluded`. Requires the RTX resource group to be bound.
28
+ *
29
+ * Emissive is intentionally excluded; the deferred pass adds it once.
30
+ *
31
+ * @type {CodeChunk}
32
+ */
33
+ export const chunk_restir_resolve = CodeChunk.from(
34
+ //language=WGSL
35
+ `
36
+ fn restir_resolve(
37
+ i_coord: vec2<u32>,
38
+ reservoir: ${RTXDI_Reservoir.wgsl_ref},
39
+ geometry: ${GEOMETRIC_SHADING_INFO_STRUCT.wgsl_ref},
40
+ material: ${MATERIAL_SHADING_INFO_STRUCT.wgsl_ref},
41
+ use_screen_space_shadow: u32
42
+ ) -> vec3<f32> {
43
+ if (!restir_light_ref_is_valid(reservoir.lightData) || reservoir.weightSum <= 0.0) {
44
+ return vec3<f32>(0.0);
45
+ }
46
+
47
+ let light_type = restir_light_ref_type(reservoir.lightData);
48
+ let light_index = restir_light_ref_index(reservoir.lightData);
49
+
50
+ // Full RGB unshadowed contribution via the representative-point incident light.
51
+ let incident = restir_get_light_info(light_type, light_index, geometry.position);
52
+ var reflected: ${REFLECTED_LIGHT_STRUCT.wgsl_ref};
53
+ re_direct_physical(incident, geometry, material, &reflected);
54
+ re_direct_multiscatter(geometry, material, &reflected);
55
+ let radiance = reflected.diffuse + reflected.specular;
56
+
57
+ if (all(radiance <= vec3<f32>(0.0))) {
58
+ return vec3<f32>(0.0);
59
+ }
60
+
61
+ // Decode the stored 16-bit-fixed-point area-light sample point.
62
+ let uv = unpack2x16unorm(reservoir.uvData);
63
+ let record = restir_sample_light_record(light_type, light_index, geometry.position, uv);
64
+
65
+ var visibility = 1.0;
66
+ if (record.distance > 0.0) {
67
+ visibility = restir_trace_visibility(
68
+ i_coord,
69
+ geometry.position,
70
+ geometry.geometric_normal,
71
+ record.direction,
72
+ record.distance,
73
+ use_screen_space_shadow != 0u,
74
+ );
75
+ }
76
+
77
+ return radiance * reservoir.weightSum * visibility;
78
+ }
79
+ `, [
80
+ RTXDI_Reservoir.declaration_chunk,
81
+ REFLECTED_LIGHT_STRUCT.declaration_chunk,
82
+ GEOMETRIC_SHADING_INFO_STRUCT.declaration_chunk,
83
+ MATERIAL_SHADING_INFO_STRUCT.declaration_chunk,
84
+ chunk_re_direct_physical,
85
+ chunk_re_direct_multiscatter,
86
+ chunk_restir_get_light_info,
87
+ chunk_restir_light_ref,
88
+ chunk_restir_sample_light_record,
89
+ chunk_restir_trace_visibility,
90
+ ]
91
+ );
@@ -36,7 +36,7 @@ fn rtxdi_stream_sample(
36
36
  if (selectSample)
37
37
  {
38
38
  reservoir.lightData = lightIndex | RTXDI_Reservoir_LightValidBit;
39
- reservoir.uvData = u32(saturate(uv.x) * 0xffff) | (u32(saturate(uv.y) * 0xffff) << 16);
39
+ reservoir.uvData = pack2x16unorm(uv);
40
40
  reservoir.targetPdf = targetPdf;
41
41
  }
42
42
 
@@ -1,4 +1,18 @@
1
1
  /**
2
+ * Decodes a packed RGBE 9-9-9-5 (`u32`) word into linear RGB (`vec3<f32>`).
3
+ *
4
+ * Bit layout:
5
+ * - `[0..8]`: 9-bit R mantissa
6
+ * - `[9..17]`: 9-bit G mantissa
7
+ * - `[18..26]`: 9-bit B mantissa
8
+ * - `[27..31]`: 5-bit biased exponent E (bias = 15, mantissa bits = 9)
9
+ *
10
+ * Rather than evaluating a transcendental `exp2(E - 24.0)` on the SFU, `2^(E - 24)` is
11
+ * constructed directly in IEEE-754 binary32 bits: shifting E from `[27..31]` down to the
12
+ * float exponent field `[23..27]` and adding the combined exponent bias `(127 - 24) << 23 = 0x33800000u`.
13
+ * Because `E` is in `[0, 31]`, the biased IEEE-754 exponent `E + 103` is in `[103, 134]`,
14
+ * which is always a normal positive float.
15
+ *
2
16
  * @see https://en.wikipedia.org/wiki/RGBE_image_format
3
17
  * @see https://github.com/zhangjiangen11/godot/blob/b64ac6341347906dacdda712dc78b574334ff4af/servers/rendering/renderer_rd/shaders/environment/hddagi_direct_light.glsl#L331
4
18
  * @type {CodeChunk}
@@ -1 +1 @@
1
- {"version":3,"file":"chunk_rgbe9995_decode.d.ts","sourceRoot":"","sources":["../../../../../../../../src/shade/renderer/shader/chunk/color/rgbe9995/chunk_rgbe9995_decode.js"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,oCAFU,SAAS,CAejB;0BApBwB,gCAAgC"}
1
+ {"version":3,"file":"chunk_rgbe9995_decode.d.ts","sourceRoot":"","sources":["../../../../../../../../src/shade/renderer/shader/chunk/color/rgbe9995/chunk_rgbe9995_decode.js"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;GAkBG;AACH,oCAFU,SAAS,CAgBjB;0BAnCwB,gCAAgC"}
@@ -1,21 +1,36 @@
1
- import { CodeChunk } from "../../../compiler/CodeChunk.js";
2
-
3
- /**
4
- * @see https://en.wikipedia.org/wiki/RGBE_image_format
5
- * @see https://github.com/zhangjiangen11/godot/blob/b64ac6341347906dacdda712dc78b574334ff4af/servers/rendering/renderer_rd/shaders/environment/hddagi_direct_light.glsl#L331
6
- * @type {CodeChunk}
7
- */
8
- export const chunk_rgbe9995_decode = CodeChunk.from(
9
- //language=WGSL
10
- `
11
- fn rgbe9995_decode(p_rgbe:u32) -> vec3<f32>{
12
- // shift and mask
13
- let rgbef = vec4<f32>(
14
- (vec4(p_rgbe) >> vec4<u32>(0, 9, 18, 27))
15
- & vec4<u32>(0x1FF, 0x1FF, 0x1FF, 0x1F)
16
- );
17
-
18
- return rgbef.rgb * exp2(rgbef.a - 15.0 - 9.0);
19
- }
20
- `
21
- );
1
+ import { CodeChunk } from "../../../compiler/CodeChunk.js";
2
+
3
+ /**
4
+ * Decodes a packed RGBE 9-9-9-5 (`u32`) word into linear RGB (`vec3<f32>`).
5
+ *
6
+ * Bit layout:
7
+ * - `[0..8]`: 9-bit R mantissa
8
+ * - `[9..17]`: 9-bit G mantissa
9
+ * - `[18..26]`: 9-bit B mantissa
10
+ * - `[27..31]`: 5-bit biased exponent E (bias = 15, mantissa bits = 9)
11
+ *
12
+ * Rather than evaluating a transcendental `exp2(E - 24.0)` on the SFU, `2^(E - 24)` is
13
+ * constructed directly in IEEE-754 binary32 bits: shifting E from `[27..31]` down to the
14
+ * float exponent field `[23..27]` and adding the combined exponent bias `(127 - 24) << 23 = 0x33800000u`.
15
+ * Because `E` is in `[0, 31]`, the biased IEEE-754 exponent `E + 103` is in `[103, 134]`,
16
+ * which is always a normal positive float.
17
+ *
18
+ * @see https://en.wikipedia.org/wiki/RGBE_image_format
19
+ * @see https://github.com/zhangjiangen11/godot/blob/b64ac6341347906dacdda712dc78b574334ff4af/servers/rendering/renderer_rd/shaders/environment/hddagi_direct_light.glsl#L331
20
+ * @type {CodeChunk}
21
+ */
22
+ export const chunk_rgbe9995_decode = CodeChunk.from(
23
+ //language=WGSL
24
+ `
25
+ fn rgbe9995_decode(p_rgbe: u32) -> vec3<f32> {
26
+ let rgb = vec3<f32>(
27
+ (vec3<u32>(p_rgbe) >> vec3<u32>(0u, 9u, 18u))
28
+ & vec3<u32>(0x1FFu)
29
+ );
30
+ let exp_bits = ((p_rgbe >> 4u) & 0x0F800000u) + 0x33800000u;
31
+ let scale = bitcast<f32>(exp_bits);
32
+
33
+ return rgb * scale;
34
+ }
35
+ `
36
+ );
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Software-bilinear sample of an RGBE 9-9-9-5 (`r32uint`) 2D texture using a single `textureGather`.
3
+ *
4
+ * WebGPU's `rgb9e5ufloat` format is hardware-filterable, but cannot be written as a storage texture
5
+ * (`STORAGE_BINDING`) or render attachment, nor view-aliased with `r32uint`. When an HDR texture is
6
+ * produced on the GPU via `textureStore` into `r32uint`, this function performs a 4-texel bilinear
7
+ * tap using one `textureGather`:
8
+ *
9
+ * 1. Snaps the gather UV to `(floor(uv * tex_size - 0.5) + 1.0) * inv_tex_size` (dead-center
10
+ * between the 4 texels) so the TMU's 16.8 fixed-point floor never disagrees with the ALU's
11
+ * `f32` fractional weights near half-texel boundaries.
12
+ * 2. Constructs the four `2^(E - 24)` scale factors directly in IEEE-754 float bits via shift,
13
+ * mask, bias addition (`103 << 23 = 0x33800000u`), and `bitcast<vec4<f32>>`, avoiding 4 SFU
14
+ * `exp2` instructions.
15
+ * 3. Folds the 4 shared-exponent scales into the 4 bilinear weights (`w = bilinear * scale`) and
16
+ * evaluates each RGB channel as a single `dot(mantissa, w)`.
17
+ *
18
+ * @type {CodeChunk}
19
+ */
20
+ export const chunk_rgbe9995_sample_gather: CodeChunk;
21
+ import { CodeChunk } from "../../../compiler/CodeChunk.js";
22
+ //# sourceMappingURL=chunk_rgbe9995_sample_gather.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chunk_rgbe9995_sample_gather.d.ts","sourceRoot":"","sources":["../../../../../../../../src/shade/renderer/shader/chunk/color/rgbe9995/chunk_rgbe9995_sample_gather.js"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;GAkBG;AACH,2CAFU,SAAS,CA4CjB;0BA/DwB,gCAAgC"}
@@ -0,0 +1,64 @@
1
+ import { CodeChunk } from "../../../compiler/CodeChunk.js";
2
+
3
+ /**
4
+ * Software-bilinear sample of an RGBE 9-9-9-5 (`r32uint`) 2D texture using a single `textureGather`.
5
+ *
6
+ * WebGPU's `rgb9e5ufloat` format is hardware-filterable, but cannot be written as a storage texture
7
+ * (`STORAGE_BINDING`) or render attachment, nor view-aliased with `r32uint`. When an HDR texture is
8
+ * produced on the GPU via `textureStore` into `r32uint`, this function performs a 4-texel bilinear
9
+ * tap using one `textureGather`:
10
+ *
11
+ * 1. Snaps the gather UV to `(floor(uv * tex_size - 0.5) + 1.0) * inv_tex_size` (dead-center
12
+ * between the 4 texels) so the TMU's 16.8 fixed-point floor never disagrees with the ALU's
13
+ * `f32` fractional weights near half-texel boundaries.
14
+ * 2. Constructs the four `2^(E - 24)` scale factors directly in IEEE-754 float bits via shift,
15
+ * mask, bias addition (`103 << 23 = 0x33800000u`), and `bitcast<vec4<f32>>`, avoiding 4 SFU
16
+ * `exp2` instructions.
17
+ * 3. Folds the 4 shared-exponent scales into the 4 bilinear weights (`w = bilinear * scale`) and
18
+ * evaluates each RGB channel as a single `dot(mantissa, w)`.
19
+ *
20
+ * @type {CodeChunk}
21
+ */
22
+ export const chunk_rgbe9995_sample_gather = CodeChunk.from(
23
+ //language=WGSL
24
+ `
25
+ fn rgbe9995_sample_gather(
26
+ tex: texture_2d<u32>,
27
+ samp: sampler,
28
+ uv: vec2<f32>,
29
+ tex_size: vec2<f32>,
30
+ inv_tex_size: vec2<f32>
31
+ ) -> vec3<f32> {
32
+ // 1. Align UV to prevent 16.8 fixed-point TMU vs f32 ALU boundary mismatch
33
+ let coord = uv * tex_size - 0.5;
34
+ let base = floor(coord);
35
+ let f = coord - base;
36
+ let gather_uv = (base + 1.0) * inv_tex_size;
37
+
38
+ // WebGPU textureGather component order:
39
+ // .x = (u0, v1) [bottom-left], .y = (u1, v1) [bottom-right]
40
+ // .z = (u1, v0) [top-right], .w = (u0, v0) [top-left]
41
+ let raw: vec4<u32> = textureGather(0, tex, samp, gather_uv);
42
+
43
+ // 2. Construct 2^(E - 24) directly in IEEE-754 float bits:
44
+ // Shift E from [27..31] to [23..27] and add bias (103 << 23 = 0x33800000u)
45
+ let exp_bits = ((raw >> vec4<u32>(4u)) & vec4<u32>(0x0F800000u)) + vec4<u32>(0x33800000u);
46
+ let scale = bitcast<vec4<f32>>(exp_bits);
47
+
48
+ // 3. Fold bilinear weights and shared-exponent scales into a single vec4 weight
49
+ let w = vec4<f32>(
50
+ (1.0 - f.x) * f.y, // .x: (u0, v1)
51
+ f.x * f.y, // .y: (u1, v1)
52
+ f.x * (1.0 - f.y), // .z: (u1, v0)
53
+ (1.0 - f.x) * (1.0 - f.y)// .w: (u0, v0)
54
+ ) * scale;
55
+
56
+ // 4. Extract 9-bit mantissas and dot with combined weights
57
+ let r = vec4<f32>(raw & vec4<u32>(0x1FFu));
58
+ let g = vec4<f32>((raw >> vec4<u32>(9u)) & vec4<u32>(0x1FFu));
59
+ let b = vec4<f32>((raw >> vec4<u32>(18u)) & vec4<u32>(0x1FFu));
60
+
61
+ return vec3<f32>(dot(r, w), dot(g, w), dot(b, w));
62
+ }
63
+ `
64
+ );
@@ -1 +1 @@
1
- {"version":3,"file":"chunk_decode_vertex_normal.d.ts","sourceRoot":"","sources":["../../../../../../../../src/shade/renderer/shader/chunk/geometry/normal/chunk_decode_vertex_normal.js"],"names":[],"mappings":"AAGA,mDAcE;0BAjBwB,gCAAgC"}
1
+ {"version":3,"file":"chunk_decode_vertex_normal.d.ts","sourceRoot":"","sources":["../../../../../../../../src/shade/renderer/shader/chunk/geometry/normal/chunk_decode_vertex_normal.js"],"names":[],"mappings":"AAGA,mDASE;0BAZwB,gCAAgC"}
@@ -1,18 +1,13 @@
1
- import { CodeChunk } from "../../../compiler/CodeChunk.js";
2
- import { chunk_uv_octahedral_unit_decode } from "../octahedron/chunk_uv_octahedral_unit_decode.js";
3
-
4
- export const chunk_decode_vertex_normal = CodeChunk.from(
5
- //language=WGSL
6
- `
7
- fn decode_vertex_normal(base: u32) -> vec3<f32>{
8
-
9
- let decode = (vec2(base) >> vec2(0u, 16u)) & vec2(0xFFFFu, 0xFFFFu);
10
-
11
- let norm = vec2<f32>(decode) / vec2(65535.0, 65535.0);
12
-
13
- return uv_octahedral_unit_decode(norm);
14
- }
15
- `, [
16
- chunk_uv_octahedral_unit_decode,
17
- ]
18
- );
1
+ import { CodeChunk } from "../../../compiler/CodeChunk.js";
2
+ import { chunk_uv_octahedral_unit_decode } from "../octahedron/chunk_uv_octahedral_unit_decode.js";
3
+
4
+ export const chunk_decode_vertex_normal = CodeChunk.from(
5
+ //language=WGSL
6
+ `
7
+ fn decode_vertex_normal(base: u32) -> vec3<f32>{
8
+ return uv_octahedral_unit_decode(unpack2x16unorm(base));
9
+ }
10
+ `, [
11
+ chunk_uv_octahedral_unit_decode,
12
+ ]
13
+ );
@@ -1 +1 @@
1
- {"version":3,"file":"chunk_encode_vertex_normal.d.ts","sourceRoot":"","sources":["../../../../../../../../src/shade/renderer/shader/chunk/geometry/normal/chunk_encode_vertex_normal.js"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;GAcG;AACH,yCAFU,SAAS,CAajB;0BA7BwB,gCAAgC"}
1
+ {"version":3,"file":"chunk_encode_vertex_normal.d.ts","sourceRoot":"","sources":["../../../../../../../../src/shade/renderer/shader/chunk/geometry/normal/chunk_encode_vertex_normal.js"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;GAcG;AACH,yCAFU,SAAS,CAWjB;0BA3BwB,gCAAgC"}
@@ -1,30 +1,28 @@
1
- import { CodeChunk } from "../../../compiler/CodeChunk.js";
2
- import { chunk_uv_octahedral_unit_encode } from "../octahedron/chunk_uv_octahedral_unit_encode.js";
3
-
4
- /**
5
- * Inverse of `decode_vertex_normal` — packs a unit normal into a single
6
- * `u32` via octahedral-unit encoding into two 16-bit u-norms (one per
7
- * u32 half).
8
- *
9
- * Layout matches the decoder:
10
- * - bits [0, 15]: oct.x (16-bit u-norm of `uv_octahedral_unit_encode(n).x`)
11
- * - bits [16, 31]: oct.y
12
- *
13
- * Round-trips lossily — the 16-bit quantization gives ~1.5° worst-case
14
- * angular error, which is what the format buys us in exchange for the
15
- * 4-byte stride.
16
- *
17
- * @type {CodeChunk}
18
- */
19
- export const chunk_encode_vertex_normal = CodeChunk.from(
20
- //language=WGSL
21
- `
22
- fn encode_vertex_normal(n: vec3<f32>) -> u32 {
23
- let oct = uv_octahedral_unit_encode(n);
24
- let q = vec2<u32>(oct * 65535.0) & vec2<u32>(0xFFFFu, 0xFFFFu);
25
- return q.x | (q.y << 16u);
26
- }
27
- `, [
28
- chunk_uv_octahedral_unit_encode,
29
- ]
30
- );
1
+ import { CodeChunk } from "../../../compiler/CodeChunk.js";
2
+ import { chunk_uv_octahedral_unit_encode } from "../octahedron/chunk_uv_octahedral_unit_encode.js";
3
+
4
+ /**
5
+ * Inverse of `decode_vertex_normal` — packs a unit normal into a single
6
+ * `u32` via octahedral-unit encoding into two 16-bit u-norms (one per
7
+ * u32 half).
8
+ *
9
+ * Layout matches the decoder:
10
+ * - bits [0, 15]: oct.x (16-bit u-norm of `uv_octahedral_unit_encode(n).x`)
11
+ * - bits [16, 31]: oct.y
12
+ *
13
+ * Round-trips lossily — the 16-bit quantization gives ~1.5° worst-case
14
+ * angular error, which is what the format buys us in exchange for the
15
+ * 4-byte stride.
16
+ *
17
+ * @type {CodeChunk}
18
+ */
19
+ export const chunk_encode_vertex_normal = CodeChunk.from(
20
+ //language=WGSL
21
+ `
22
+ fn encode_vertex_normal(n: vec3<f32>) -> u32 {
23
+ return pack2x16unorm(uv_octahedral_unit_encode(n));
24
+ }
25
+ `, [
26
+ chunk_uv_octahedral_unit_encode,
27
+ ]
28
+ );
@@ -1 +1 @@
1
- {"version":3,"file":"chunk_unit_u32_to_vec2.d.ts","sourceRoot":"","sources":["../../../../../../../../src/shade/renderer/shader/chunk/geometry/vec2/chunk_unit_u32_to_vec2.js"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,qCAFU,SAAS,CAUlB;0BAfyB,gCAAgC"}
1
+ {"version":3,"file":"chunk_unit_u32_to_vec2.d.ts","sourceRoot":"","sources":["../../../../../../../../src/shade/renderer/shader/chunk/geometry/vec2/chunk_unit_u32_to_vec2.js"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,qCAFU,SAAS,CASlB;0BAdyB,gCAAgC"}
@@ -1,16 +1,15 @@
1
- import { CodeChunk } from "../../../compiler/CodeChunk.js";
2
-
3
- /**
4
- * Quantized vec2 decoding, vector values must be in [0..1] range
5
- * @see https://github.com/zhangjiangen11/godot/blob/b64ac6341347906dacdda712dc78b574334ff4af/servers/rendering/renderer_rd/shaders/skeleton.glsl#L66
6
- * @type {CodeChunk}
7
- */
8
- export const chunk_unit_u32_to_vec2 = CodeChunk.from(
9
- //language=WGSL
10
- `
11
- fn unit_u32_to_vec2(base: u32) -> vec2<f32>{
12
- let decode = (vec2(base) >> vec2(0u, 16u)) & vec2(0xFFFFu, 0xFFFFu);
13
- return vec2<f32>(decode) / vec2(65535.0, 65535.0) * 2.0 - 1.0;
14
- }
15
- `
16
- )
1
+ import { CodeChunk } from "../../../compiler/CodeChunk.js";
2
+
3
+ /**
4
+ * Quantized vec2 decoding, vector values must be in [0..1] range
5
+ * @see https://github.com/zhangjiangen11/godot/blob/b64ac6341347906dacdda712dc78b574334ff4af/servers/rendering/renderer_rd/shaders/skeleton.glsl#L66
6
+ * @type {CodeChunk}
7
+ */
8
+ export const chunk_unit_u32_to_vec2 = CodeChunk.from(
9
+ //language=WGSL
10
+ `
11
+ fn unit_u32_to_vec2(base: u32) -> vec2<f32>{
12
+ return unpack2x16unorm(base) * 2.0 - 1.0;
13
+ }
14
+ `
15
+ )
@@ -1,5 +1,4 @@
1
1
  /**
2
- * TODO consider pack2x16unorm instead
3
2
  * Quantized vec2 encoding, values must be in [0..1] range
4
3
  * @see https://github.com/zhangjiangen11/godot/blob/b64ac6341347906dacdda712dc78b574334ff4af/servers/rendering/renderer_rd/shaders/skeleton.glsl#L93
5
4
  * @type {CodeChunk}
@@ -1 +1 @@
1
- {"version":3,"file":"chunk_unit_vec2_to_u32.d.ts","sourceRoot":"","sources":["../../../../../../../../src/shade/renderer/shader/chunk/geometry/vec2/chunk_unit_vec2_to_u32.js"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,qCAFU,SAAS,CAUjB;0BAhBwB,gCAAgC"}
1
+ {"version":3,"file":"chunk_unit_vec2_to_u32.d.ts","sourceRoot":"","sources":["../../../../../../../../src/shade/renderer/shader/chunk/geometry/vec2/chunk_unit_vec2_to_u32.js"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,qCAFU,SAAS,CASjB;0BAdwB,gCAAgC"}
@@ -1,18 +1,15 @@
1
- import { CodeChunk } from "../../../compiler/CodeChunk.js";
2
-
3
- /**
4
- * TODO consider pack2x16unorm instead
5
- * Quantized vec2 encoding, values must be in [0..1] range
6
- * @see https://github.com/zhangjiangen11/godot/blob/b64ac6341347906dacdda712dc78b574334ff4af/servers/rendering/renderer_rd/shaders/skeleton.glsl#L93
7
- * @type {CodeChunk}
8
- */
9
- export const chunk_unit_vec2_to_u32 = CodeChunk.from(
10
- //language=WGSL
11
- `
12
- fn unit_vec2_to_u32(base:vec2<f32>) -> u32{
13
- let enc = vec2<u32>(clamp(vec2<i32>(base * vec2(65535, 65535)), vec2(0), vec2(0xFFFF, 0xFFFF))) << vec2(0u, 16u);
14
- return enc.x | enc.y;
15
- }
16
- `
17
- );
18
-
1
+ import { CodeChunk } from "../../../compiler/CodeChunk.js";
2
+
3
+ /**
4
+ * Quantized vec2 encoding, values must be in [0..1] range
5
+ * @see https://github.com/zhangjiangen11/godot/blob/b64ac6341347906dacdda712dc78b574334ff4af/servers/rendering/renderer_rd/shaders/skeleton.glsl#L93
6
+ * @type {CodeChunk}
7
+ */
8
+ export const chunk_unit_vec2_to_u32 = CodeChunk.from(
9
+ //language=WGSL
10
+ `
11
+ fn unit_vec2_to_u32(base:vec2<f32>) -> u32{
12
+ return pack2x16unorm(base);
13
+ }
14
+ `
15
+ );
@@ -0,0 +1,32 @@
1
+ /**
2
+ * The index {@link chunk_subgroup_bitset_or} skips.
3
+ *
4
+ * @type {number}
5
+ */
6
+ export const SUBGROUP_BITSET_OR_NONE: number;
7
+ /**
8
+ * Set bit `index` of a bitset, one atomic per distinct word the subgroup holds: the lanes holding
9
+ * the first outstanding word take a round, OR together the bits they hold in it — or skip that when
10
+ * they all hold the same bit — one of them sets them with one `atomicOr`, and the rounds repeat
11
+ * until no word is left.
12
+ *
13
+ * `fn subgroup_bitset_or(bits: ptr<storage, array<atomic<u32>>, read_write>, index: u32)`
14
+ *
15
+ * Bit `index` is bit `index & 31` of word `index >> 5`. An index of {@link SUBGROUP_BITSET_OR_NONE},
16
+ * or one whose word is past the end of `bits`, sets nothing. Every lane of the subgroup calls it,
17
+ * from subgroup-uniform control flow.
18
+ *
19
+ * The atomic is made by a lane of the round, so a lane that holds nothing never stands in for one
20
+ * that does — in a fragment shader, a helper invocation given {@link SUBGROUP_BITSET_OR_NONE} can
21
+ * never be the one that writes, and its write would be discarded.
22
+ *
23
+ * A subgroup runs one round per distinct word it holds, so the loop is bounded by its lane count.
24
+ * Indices that follow the screen — a material per pixel — come in runs, and a subgroup ordinarily
25
+ * holds one or two.
26
+ *
27
+ * @see chunk_subgroup_keyed_append for the counting twin
28
+ * @type {CodeChunk}
29
+ */
30
+ export const chunk_subgroup_bitset_or: CodeChunk;
31
+ import { CodeChunk } from "../../compiler/CodeChunk.js";
32
+ //# sourceMappingURL=chunk_subgroup_bitset_or.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chunk_subgroup_bitset_or.d.ts","sourceRoot":"","sources":["../../../../../../../src/shade/renderer/shader/chunk/subgroup/chunk_subgroup_bitset_or.js"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,sCAFU,MAAM,CAEkC;AAElD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,uCAFU,SAAS,CAsChB;0BApEuB,6BAA6B"}