@woosh/meep-engine 3.29.0 → 3.30.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 (226) hide show
  1. package/build/bundle-worker-image-decoder.js +1 -1
  2. package/build/bundle-worker-terrain.js +1 -1
  3. package/package.json +1 -1
  4. package/src/core/binary/BinaryBuffer.d.ts.map +1 -1
  5. package/src/core/binary/BinaryBuffer.js +14 -2
  6. package/src/core/bvh2/bvh3/BVH.d.ts.map +1 -1
  7. package/src/core/bvh2/bvh3/BVH.js +14 -1
  8. package/src/core/cache/FrequencySketch.d.ts +3 -1
  9. package/src/core/cache/FrequencySketch.d.ts.map +1 -1
  10. package/src/core/cache/FrequencySketch.js +10 -4
  11. package/src/core/cache/wtinylfu/CacheWTinylfu.d.ts.map +1 -1
  12. package/src/core/cache/wtinylfu/CacheWTinylfu.js +24 -2
  13. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_compute_vertex_quadrics.d.ts +20 -0
  14. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_compute_vertex_quadrics.d.ts.map +1 -1
  15. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_compute_vertex_quadrics.js +69 -4
  16. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_simplify.d.ts +48 -18
  17. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_simplify.d.ts.map +1 -1
  18. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_simplify.js +262 -70
  19. package/src/core/geom/3d/topology/struct/binary/query/bt_edge_collapse_fold_limit.d.ts +25 -0
  20. package/src/core/geom/3d/topology/struct/binary/query/bt_edge_collapse_fold_limit.d.ts.map +1 -0
  21. package/src/core/geom/3d/topology/struct/binary/query/bt_edge_collapse_fold_limit.js +228 -0
  22. package/src/core/geom/3d/topology/struct/binary/query/bt_edge_collapse_would_fold.d.ts +13 -0
  23. package/src/core/geom/3d/topology/struct/binary/query/bt_edge_collapse_would_fold.d.ts.map +1 -1
  24. package/src/core/geom/3d/topology/struct/binary/query/bt_edge_collapse_would_fold.js +10 -128
  25. package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_build_face_bvh.d.ts.map +1 -1
  26. package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_build_face_bvh.js +11 -1
  27. package/src/core/graph/mn_graph_collapse_weighted_edge.js +6 -6
  28. package/src/core/math/lookup/ParameterLookupTable.d.ts.map +1 -1
  29. package/src/core/math/lookup/ParameterLookupTable.js +10 -5
  30. package/src/core/math/noise/sdnoise.d.ts.map +1 -1
  31. package/src/core/math/noise/sdnoise.js +16 -10
  32. package/src/core/model/object/ImmutableObjectPool.d.ts.map +1 -1
  33. package/src/core/model/object/ImmutableObjectPool.js +17 -7
  34. package/src/core/process/executor/ConcurrentExecutor.d.ts +1 -5
  35. package/src/core/process/executor/ConcurrentExecutor.d.ts.map +1 -1
  36. package/src/core/process/executor/ConcurrentExecutor.js +95 -1
  37. package/src/core/process/task/task_find_dependency_cycle.d.ts +17 -0
  38. package/src/core/process/task/task_find_dependency_cycle.d.ts.map +1 -0
  39. package/src/core/process/task/task_find_dependency_cycle.js +81 -0
  40. package/src/core/wfc/WFCCellChoice.d.ts +17 -0
  41. package/src/core/wfc/WFCCellChoice.d.ts.map +1 -0
  42. package/src/core/wfc/WFCCellChoice.js +36 -0
  43. package/src/core/wfc/WFCLattice.d.ts +105 -0
  44. package/src/core/wfc/WFCLattice.d.ts.map +1 -0
  45. package/src/core/wfc/WFCLattice.js +235 -0
  46. package/src/core/wfc/WFCRuleTable.d.ts +172 -0
  47. package/src/core/wfc/WFCRuleTable.d.ts.map +1 -0
  48. package/src/core/wfc/WFCRuleTable.js +334 -0
  49. package/src/core/wfc/WFCState.d.ts +273 -0
  50. package/src/core/wfc/WFCState.d.ts.map +1 -0
  51. package/src/core/wfc/WFCState.js +552 -0
  52. package/src/core/wfc/WFCStatus.d.ts +11 -0
  53. package/src/core/wfc/WFCStatus.d.ts.map +1 -0
  54. package/src/core/wfc/WFCStatus.js +28 -0
  55. package/src/core/wfc/WFCTileWeights.d.ts +48 -0
  56. package/src/core/wfc/WFCTileWeights.d.ts.map +1 -0
  57. package/src/core/wfc/WFCTileWeights.js +86 -0
  58. package/src/core/wfc/WFC_UNRESOLVED.d.ts +12 -0
  59. package/src/core/wfc/WFC_UNRESOLVED.d.ts.map +1 -0
  60. package/src/core/wfc/WFC_UNRESOLVED.js +11 -0
  61. package/src/core/wfc/wfc_estimate_bytes.d.ts +24 -0
  62. package/src/core/wfc/wfc_estimate_bytes.d.ts.map +1 -0
  63. package/src/core/wfc/wfc_estimate_bytes.js +47 -0
  64. package/src/core/wfc/wfc_rule_table_tile_components.d.ts +27 -0
  65. package/src/core/wfc/wfc_rule_table_tile_components.d.ts.map +1 -0
  66. package/src/core/wfc/wfc_rule_table_tile_components.js +80 -0
  67. package/src/core/wfc/wfc_solve.d.ts +21 -0
  68. package/src/core/wfc/wfc_solve.d.ts.map +1 -0
  69. package/src/core/wfc/wfc_solve.js +154 -0
  70. package/src/core/wfc/wfc_state_apply_boundary.d.ts +18 -0
  71. package/src/core/wfc/wfc_state_apply_boundary.d.ts.map +1 -0
  72. package/src/core/wfc/wfc_state_apply_boundary.js +61 -0
  73. package/src/core/wfc/wfc_state_assign.d.ts +11 -0
  74. package/src/core/wfc/wfc_state_assign.d.ts.map +1 -0
  75. package/src/core/wfc/wfc_state_assign.js +36 -0
  76. package/src/core/wfc/wfc_state_ban_bits.d.ts +17 -0
  77. package/src/core/wfc/wfc_state_ban_bits.d.ts.map +1 -0
  78. package/src/core/wfc/wfc_state_ban_bits.js +81 -0
  79. package/src/core/wfc/wfc_state_collapse.d.ts +12 -0
  80. package/src/core/wfc/wfc_state_collapse.d.ts.map +1 -0
  81. package/src/core/wfc/wfc_state_collapse.js +73 -0
  82. package/src/core/wfc/wfc_state_flush_dirty.d.ts +12 -0
  83. package/src/core/wfc/wfc_state_flush_dirty.d.ts.map +1 -0
  84. package/src/core/wfc/wfc_state_flush_dirty.js +39 -0
  85. package/src/core/wfc/wfc_state_propagate.d.ts +14 -0
  86. package/src/core/wfc/wfc_state_propagate.d.ts.map +1 -0
  87. package/src/core/wfc/wfc_state_propagate.js +155 -0
  88. package/src/core/wfc/wfc_state_read.d.ts +11 -0
  89. package/src/core/wfc/wfc_state_read.d.ts.map +1 -0
  90. package/src/core/wfc/wfc_state_read.js +38 -0
  91. package/src/core/wfc/wfc_state_restrict.d.ts +18 -0
  92. package/src/core/wfc/wfc_state_restrict.d.ts.map +1 -0
  93. package/src/core/wfc/wfc_state_restrict.js +39 -0
  94. package/src/core/wfc/wfc_state_set_eligible.d.ts +24 -0
  95. package/src/core/wfc/wfc_state_set_eligible.d.ts.map +1 -0
  96. package/src/core/wfc/wfc_state_set_eligible.js +49 -0
  97. package/src/core/wfc/wfc_state_undo_to.d.ts +13 -0
  98. package/src/core/wfc/wfc_state_undo_to.d.ts.map +1 -0
  99. package/src/core/wfc/wfc_state_undo_to.js +84 -0
  100. package/src/core/wfc/wfc_words_per_cell.d.ts +11 -0
  101. package/src/core/wfc/wfc_words_per_cell.d.ts.map +1 -0
  102. package/src/core/wfc/wfc_words_per_cell.js +16 -0
  103. package/src/engine/ecs/EntityComponentDataset.d.ts +8 -0
  104. package/src/engine/ecs/EntityComponentDataset.d.ts.map +1 -1
  105. package/src/engine/ecs/EntityComponentDataset.js +37 -14
  106. package/src/engine/ecs/fow/FogOfWarRevealerSystem.d.ts +8 -1
  107. package/src/engine/ecs/fow/FogOfWarRevealerSystem.d.ts.map +1 -1
  108. package/src/engine/ecs/fow/FogOfWarRevealerSystem.js +37 -2
  109. package/src/engine/ecs/guid/UUID.d.ts.map +1 -1
  110. package/src/engine/ecs/guid/UUID.js +45 -17
  111. package/src/engine/ecs/ik/OneBoneSurfaceAlignmentSolver.d.ts.map +1 -1
  112. package/src/engine/ecs/ik/OneBoneSurfaceAlignmentSolver.js +3 -1
  113. package/src/engine/ecs/terrain/ecs/cling/ClingToTerrainSystem.d.ts.map +1 -1
  114. package/src/engine/ecs/terrain/ecs/cling/ClingToTerrainSystem.js +366 -360
  115. package/src/engine/graphics/texture/sampler/resize/sampler2d_scale_down_linear.d.ts.map +1 -1
  116. package/src/engine/graphics/texture/sampler/resize/sampler2d_scale_down_linear.js +24 -10
  117. package/src/engine/grid/grid2transform/GridPosition2TransformSystem.d.ts.map +1 -1
  118. package/src/engine/grid/grid2transform/GridPosition2TransformSystem.js +24 -5
  119. package/src/engine/interpolation/Interpoland.d.ts +7 -1
  120. package/src/engine/interpolation/Interpoland.d.ts.map +1 -1
  121. package/src/engine/interpolation/Interpoland.js +8 -1
  122. package/src/engine/interpolation/InterpolationSystem.d.ts.map +1 -1
  123. package/src/engine/interpolation/InterpolationSystem.js +3 -0
  124. package/src/engine/interpolation/TransformPoseSerializationAdapter.d.ts +5 -3
  125. package/src/engine/interpolation/TransformPoseSerializationAdapter.d.ts.map +1 -1
  126. package/src/engine/interpolation/TransformPoseSerializationAdapter.js +14 -3
  127. package/src/engine/interpolation/pose_interpoland.d.ts.map +1 -1
  128. package/src/engine/interpolation/pose_interpoland.js +2 -0
  129. package/src/engine/network/orchestrator/NetworkPeer.d.ts.map +1 -1
  130. package/src/engine/network/orchestrator/NetworkPeer.js +15 -10
  131. package/src/engine/physics/cloth/ecs/ClothWorld.d.ts.map +1 -1
  132. package/src/engine/physics/cloth/ecs/ClothWorld.js +17 -0
  133. package/src/engine/physics/mls-mpm/MLS_MPM.d.ts.map +1 -1
  134. package/src/engine/physics/mls-mpm/MLS_MPM.js +14 -0
  135. package/src/engine/sound/sopra/definition/clip/AbstractAudioClip.d.ts +2 -1
  136. package/src/engine/sound/sopra/definition/clip/AbstractAudioClip.d.ts.map +1 -1
  137. package/src/engine/sound/sopra/definition/clip/AbstractAudioClip.js +1 -1
  138. package/src/engine/sound/sopra/definition/clip/BlendContainerAudioClip.d.ts +1 -0
  139. package/src/engine/sound/sopra/definition/clip/BlendContainerAudioClip.d.ts.map +1 -1
  140. package/src/engine/sound/sopra/definition/clip/RandomContainerAudioClip.d.ts +1 -0
  141. package/src/engine/sound/sopra/definition/clip/RandomContainerAudioClip.d.ts.map +1 -1
  142. package/src/engine/sound/sopra/definition/clip/SampleAudioClip.d.ts +2 -1
  143. package/src/engine/sound/sopra/definition/clip/SampleAudioClip.d.ts.map +1 -1
  144. package/src/engine/sound/sopra/definition/clip/SampleAudioClip.js +12 -3
  145. package/src/engine/sound/sopra/definition/clip/SequenceContainerAudioClip.d.ts +1 -0
  146. package/src/engine/sound/sopra/definition/clip/SequenceContainerAudioClip.d.ts.map +1 -1
  147. package/src/engine/sound/sopra/definition/clip/SwitchContainerAudioClip.d.ts +1 -0
  148. package/src/engine/sound/sopra/definition/clip/SwitchContainerAudioClip.d.ts.map +1 -1
  149. package/src/engine/sound/sopra/runtime/EventInstance.d.ts.map +1 -1
  150. package/src/engine/sound/sopra/runtime/EventInstance.js +4 -1
  151. package/src/format/image/avif/av1/decode/decode_coefficients.d.ts.map +1 -1
  152. package/src/format/image/avif/av1/decode/decode_coefficients.js +248 -259
  153. package/src/format/image/avif/av1/decode/read_golomb.d.ts +21 -0
  154. package/src/format/image/avif/av1/decode/read_golomb.d.ts.map +1 -0
  155. package/src/format/image/avif/av1/decode/read_golomb.js +49 -0
  156. package/src/format/image/avif/av1/filter/loop_restoration.js +461 -451
  157. package/src/format/image/avif/av1/util/round2.d.ts +19 -2
  158. package/src/format/image/avif/av1/util/round2.d.ts.map +1 -1
  159. package/src/format/image/avif/av1/util/round2.js +51 -27
  160. package/src/format/image/avif/heif/parse_avif_file.js +24 -0
  161. package/src/shade/renderer/buffer/table/GPUTypedTable.d.ts.map +1 -1
  162. package/src/shade/renderer/buffer/table/GPUTypedTable.js +14 -0
  163. package/src/shade/renderer/geometry/virtual/VIRTUAL_GEOMETRY_DESIGN.md +46 -3
  164. package/src/shade/renderer/geometry/virtual/WEDGE_PLAN_2026_09_18.md +91 -1
  165. package/src/shade/renderer/geometry/virtual/build/VGeoBuildOptions.d.ts +0 -13
  166. package/src/shade/renderer/geometry/virtual/build/VGeoBuildOptions.d.ts.map +1 -1
  167. package/src/shade/renderer/geometry/virtual/build/VGeoBuildOptions.js +0 -15
  168. package/src/shade/renderer/geometry/virtual/build/level/vgeo_build_group_step.js +5 -5
  169. package/src/shade/renderer/geometry/virtual/build/mesh/VGEO_DEFAULT_ATTRIBUTE_WEIGHT_RATIOS.d.ts +11 -1
  170. package/src/shade/renderer/geometry/virtual/build/mesh/VGEO_DEFAULT_ATTRIBUTE_WEIGHT_RATIOS.d.ts.map +1 -1
  171. package/src/shade/renderer/geometry/virtual/build/mesh/VGEO_DEFAULT_ATTRIBUTE_WEIGHT_RATIOS.js +11 -1
  172. package/src/shade/renderer/geometry/virtual/build/mesh/vgeo_compute_vertex_normals.d.ts +18 -9
  173. package/src/shade/renderer/geometry/virtual/build/mesh/vgeo_compute_vertex_normals.d.ts.map +1 -1
  174. package/src/shade/renderer/geometry/virtual/build/mesh/vgeo_compute_vertex_normals.js +20 -26
  175. package/src/shade/renderer/geometry/virtual/build/mesh/vgeo_normalize_source.d.ts +1 -3
  176. package/src/shade/renderer/geometry/virtual/build/mesh/vgeo_normalize_source.d.ts.map +1 -1
  177. package/src/shade/renderer/geometry/virtual/build/mesh/vgeo_normalize_source.js +2 -5
  178. package/src/shade/renderer/geometry/virtual/build/vgeo_build.js +1 -1
  179. package/src/shade/renderer/geometry/virtual/runtime/VGeoResidency.d.ts.map +1 -1
  180. package/src/shade/renderer/geometry/virtual/runtime/VGeoResidency.js +14 -1
  181. package/src/shade/renderer/global_illumination/probe/octahedral/GPUProbeAtlas.d.ts.map +1 -1
  182. package/src/shade/renderer/global_illumination/probe/octahedral/GPUProbeAtlas.js +12 -3
  183. package/src/shade/renderer/light/environment/rgbe/RGBE_ReadPixels_RLE.d.ts.map +1 -1
  184. package/src/shade/renderer/light/environment/rgbe/RGBE_ReadPixels_RLE.js +7 -1
  185. package/src/shade/renderer/lightmap/GPULightMap.d.ts.map +1 -1
  186. package/src/shade/renderer/lightmap/GPULightMap.js +349 -336
  187. package/src/shade/renderer/loader/gltf/load_gltf.d.ts.map +1 -1
  188. package/src/shade/renderer/loader/gltf/load_gltf.js +1137 -1128
  189. package/src/shade/renderer/particles/DESIGN.md +14 -5
  190. package/src/shade/renderer/particles/GPUParticleSystem.d.ts +25 -10
  191. package/src/shade/renderer/particles/GPUParticleSystem.d.ts.map +1 -1
  192. package/src/shade/renderer/particles/GPUParticleSystem.js +182 -38
  193. package/src/shade/renderer/particles/graph/groups/simplex_reference.d.ts.map +1 -1
  194. package/src/shade/renderer/particles/graph/groups/simplex_reference.js +16 -10
  195. package/src/shade/renderer/particles/graph_particles.d.ts +4 -2
  196. package/src/shade/renderer/particles/graph_particles.d.ts.map +1 -1
  197. package/src/shade/renderer/particles/graph_particles.js +8 -2
  198. package/src/shade/renderer/particles/optimizer/particle_vm_semantics.d.ts.map +1 -1
  199. package/src/shade/renderer/particles/optimizer/particle_vm_semantics.js +8 -2
  200. package/src/shade/renderer/particles/optimizer/pass_fold_constants.d.ts.map +1 -1
  201. package/src/shade/renderer/particles/optimizer/pass_fold_constants.js +10 -4
  202. package/src/shade/renderer/particles/shaders/shader_particle_init_free_list.d.ts +31 -0
  203. package/src/shade/renderer/particles/shaders/shader_particle_init_free_list.d.ts.map +1 -0
  204. package/src/shade/renderer/particles/shaders/shader_particle_init_free_list.js +62 -0
  205. package/src/shade/renderer/particles/vm/ParticleVMReference.d.ts +13 -0
  206. package/src/shade/renderer/particles/vm/ParticleVMReference.d.ts.map +1 -1
  207. package/src/shade/renderer/particles/vm/ParticleVMReference.js +95 -17
  208. package/src/shade/renderer/rasterize/bucket/rasterization_has_opaque_bucket.d.ts +21 -0
  209. package/src/shade/renderer/rasterize/bucket/rasterization_has_opaque_bucket.d.ts.map +1 -0
  210. package/src/shade/renderer/rasterize/bucket/rasterization_has_opaque_bucket.js +28 -0
  211. package/src/shade/renderer/rasterize/fast/graph_rasterize_scene_fast.d.ts.map +1 -1
  212. package/src/shade/renderer/rasterize/fast/graph_rasterize_scene_fast.js +19 -2
  213. package/src/shade/renderer/rasterize/standard/graph_rasterize_scene.d.ts.map +1 -1
  214. package/src/shade/renderer/rasterize/standard/graph_rasterize_scene.js +19 -2
  215. package/src/shade/renderer/shader/type/WebGPUStruct.d.ts.map +1 -1
  216. package/src/shade/renderer/shader/type/WebGPUStruct.js +12 -0
  217. package/src/shade/renderer/texture/mipmaps/WebGPUMipmapGenerator.d.ts +8 -2
  218. package/src/shade/renderer/texture/mipmaps/WebGPUMipmapGenerator.d.ts.map +1 -1
  219. package/src/shade/renderer/texture/mipmaps/WebGPUMipmapGenerator.js +41 -6
  220. package/src/shade/wgsl/emulator/WGSLJavaScriptCompiler.js +2383 -2356
  221. package/src/view/tooltip/DomTooltipManager.d.ts +7 -0
  222. package/src/view/tooltip/DomTooltipManager.d.ts.map +1 -1
  223. package/src/view/tooltip/DomTooltipManager.js +22 -0
  224. package/src/view/tooltip/DomTooltipObserver.d.ts.map +1 -1
  225. package/src/view/tooltip/DomTooltipObserver.js +13 -3
  226. package/src/shade/renderer/geometry/virtual/build/mesh/VGEO_CREASE_ANGLE.js +0 -45
@@ -1,337 +1,350 @@
1
- import { assert } from "../../../core/assert.js";
2
- import { FrameGraph } from "../../../engine/graphics/render/frame_graph/FrameGraph.js";
3
- import { ShadeGPUCommandContext } from "../../device/ShadeGPUCommandContext.js";
4
- import { graph_image_pass } from "../shader/graph/graph_image_pass.js";
5
- import { graph_import_texture } from "../shader/graph/graph_import_texture.js";
6
- import { GPUTextureContext } from "../texture/GPUTextureContext.js";
7
- import { texture_mip_level_count } from "../../util/texture_mip_extent.js";
8
- import { HILBERT_R2_INDEX_TEXTURE } from "../texture/noise/HILBERT_R2_INDEX_TEXTURE.js";
9
- import { TextureFilterType } from "../texture/TextureFilterType.js";
10
- import { graph_draw_lightmap_viz_buffer } from "./bake/raster/graph_draw_lightmap_viz_buffer.js";
11
- import { shader_lightmap_denoise_sh } from "./bake/shader_lightmap_denoise_sh.js";
12
- import { shader_lightmap_dilate } from "./bake/shader_lightmap_dilate.js";
13
- import { shader_lightmap_viz_to_sh } from "./bake/shader_lightmap_viz_to_sh.js";
14
- import { DEFAULT_LIGHTMAP_RESOLUTION } from "./DEFAULT_LIGHTMAP_RESOLUTION.js";
15
-
16
- const MAX_LIGHT_MAP_SIZE = DEFAULT_LIGHTMAP_RESOLUTION;
17
- const BAKE_TILE_SIZE = 256;
18
-
19
-
20
- export class GPULightMap {
21
-
22
- /**
23
- *
24
- * @type {GPUTextureContext|null}
25
- */
26
- texture_Y = null;
27
- /**
28
- *
29
- * @type {GPUTextureContext|null}
30
- */
31
- texture_CoCg = null;
32
- /**
33
- *
34
- * @type {GPUTextureContext|null}
35
- */
36
- texture_flat = null;
37
-
38
- /**
39
- * Stores [mesh_id, triangle_id] as vec2<u32>
40
- * @type {GPUTextureContext|null}
41
- */
42
- texture_viz = null;
43
-
44
- /**
45
- *
46
- * @return {number}
47
- */
48
- get resolution() {
49
- return this.texture_Y.descriptor.size.width;
50
- }
51
-
52
- /**
53
- *
54
- * @param {GPUDevice} device
55
- */
56
- constructor(device) {
57
- const resolution = MAX_LIGHT_MAP_SIZE;
58
-
59
- const mip_count = Math.min(
60
- 3,
61
- texture_mip_level_count(resolution, resolution, 1, "2d")
62
- );
63
-
64
- const texture_Y = new GPUTextureContext(device);
65
-
66
- texture_Y.resize(resolution, resolution);
67
- texture_Y.descriptor.label = "Lightmap Y/ sh2";
68
- texture_Y.descriptor.format = "rgba16float";
69
- texture_Y.descriptor.usage |= GPUTextureUsage.RENDER_ATTACHMENT;
70
- texture_Y.descriptor.mipLevelCount = mip_count;
71
-
72
- const texture_CoCg = new GPUTextureContext(device);
73
- texture_CoCg.resize(resolution, resolution);
74
- texture_CoCg.descriptor.label = "Lightmap CoCg";
75
- texture_CoCg.descriptor.format = "rg16float";
76
- texture_CoCg.descriptor.usage |= GPUTextureUsage.RENDER_ATTACHMENT;
77
- texture_CoCg.descriptor.mipLevelCount = mip_count;
78
-
79
- this.texture_Y = texture_Y;
80
- this.texture_CoCg = texture_CoCg;
81
-
82
- // flat
83
-
84
- const texture_flat = new GPUTextureContext(device);
85
- texture_flat.resize(resolution, resolution);
86
- texture_flat.descriptor.label = "Lightmap flat";
87
- texture_flat.descriptor.format = "rgba16float";
88
- texture_flat.descriptor.usage |= GPUTextureUsage.RENDER_ATTACHMENT;
89
- texture_flat.descriptor.mipLevelCount = mip_count;
90
-
91
- this.texture_flat = texture_flat;
92
-
93
- const texture_viz = new GPUTextureContext(device);
94
- texture_viz.resize(resolution, resolution);
95
- texture_viz.descriptor.label = "Lightmap viz";
96
- texture_viz.descriptor.format = "rg32uint";
97
- texture_viz.descriptor.usage |= GPUTextureUsage.RENDER_ATTACHMENT;
98
- texture_viz.descriptor.mipLevelCount = 1;
99
-
100
- this.texture_viz = texture_viz;
101
- }
102
-
103
- /**
104
- * @type {GPUSceneContext}
105
- */
106
- #scene
107
-
108
- /**
109
- * @type {GraphicsContext}
110
- */
111
- #graphics
112
-
113
- /**
114
- * @type {GPUTextureContext}
115
- */
116
- #bake_tile_sh_Y = null;
117
- /**
118
- *
119
- * @type {GPUTextureContext}
120
- */
121
- #bake_tile_sh_CoCg = null;
122
- #bake_tile_next = 0;
123
- #bake_full_iteration_count = 0;
124
-
125
- /**
126
- *
127
- * @param {GPUSceneContext} scene_ctx
128
- * @param {GraphicsContext} graphics
129
- */
130
- bake_start(scene_ctx, graphics) {
131
- assert.isNull(this.#bake_tile_sh_Y, 'bake_tiles'); // didn't clean up
132
-
133
- this.#scene = scene_ctx;
134
- this.#graphics = graphics;
135
-
136
- const graph = new FrameGraph("Lightmap Bake/start");
137
- // prepare viz buffer
138
-
139
- const r_materials = graphics.materials_resident;
140
-
141
-
142
- r_materials.ensure_scene_materials(scene_ctx);
143
- r_materials.update();
144
-
145
- const viz_buffer = graph_import_texture(graph, this.texture_viz);
146
-
147
- graph_draw_lightmap_viz_buffer({
148
- graph,
149
- output: viz_buffer,
150
- scene: scene_ctx,
151
- });
152
-
153
- const cmd = ShadeGPUCommandContext.create(graphics, 'Lightmap Bake/start');
154
-
155
- cmd.encodeGraph(graph);
156
-
157
-
158
- cmd.finish();
159
-
160
- // create bake tiles
161
- this.#create_bake_tile();
162
-
163
- this.#bake_tile_next = 0;
164
- this.#bake_full_iteration_count = 0;
165
- }
166
-
167
- #create_bake_tile() {
168
-
169
- const device = this.#graphics.device;
170
-
171
- const tile_Y = new GPUTextureContext(device);
172
-
173
- tile_Y.descriptor.dimension = "2d";
174
- tile_Y.descriptor.label = "Lightmap bake tile / Y";
175
- tile_Y.descriptor.format = "rgba32float";
176
- tile_Y.descriptor.usage |= GPUTextureUsage.RENDER_ATTACHMENT;
177
- tile_Y.descriptor.mipLevelCount = 1;
178
- tile_Y.resize(BAKE_TILE_SIZE, BAKE_TILE_SIZE);
179
-
180
- this.#bake_tile_sh_Y = tile_Y;
181
-
182
- const tile_CoCg = new GPUTextureContext(device);
183
-
184
- tile_CoCg.descriptor.dimension = "2d";
185
- tile_CoCg.descriptor.label = "Lightmap bake tile / CoCg";
186
- tile_CoCg.descriptor.format = "rg32float";
187
- tile_CoCg.descriptor.usage |= GPUTextureUsage.RENDER_ATTACHMENT;
188
- tile_CoCg.descriptor.mipLevelCount = 1;
189
- tile_CoCg.resize(BAKE_TILE_SIZE, BAKE_TILE_SIZE);
190
-
191
- this.#bake_tile_sh_CoCg = tile_CoCg;
192
- }
193
-
194
- /**
195
- * Perform a single step of baking
196
- */
197
- bake_update() {
198
- const graphics = this.#graphics;
199
- const scene_ctx = this.#scene;
200
- const r_materials = graphics.materials_resident;
201
-
202
-
203
- const graph = new FrameGraph("Lightmap Bake/update");
204
-
205
- // pick a tile to update
206
- const bake_tile_index = this.#bake_tile_next;
207
- this.#bake_tile_next = (bake_tile_index + 1) % this.#bake_tile_sh_Y.descriptor.size.width;
208
-
209
- if (this.#bake_tile_next === 0) {
210
- // full cycle
211
- this.#bake_full_iteration_count++;
212
- }
213
-
214
- const viz_buffer = graph_import_texture(graph, this.texture_viz);
215
-
216
- // load the tile from the light map to update
217
-
218
- // bake a single tile of the light map
219
- graph_image_pass({
220
- graph,
221
- shader: shader_lightmap_viz_to_sh,
222
- output: [
223
- graph_import_texture(graph, this.texture_Y),
224
- graph_import_texture(graph, this.texture_CoCg),
225
- ],
226
- inputs: {
227
- viz_buffer,
228
-
229
- materials: r_materials.buffer_materials,
230
- textures: r_materials.textureView,
231
- tNoise: graphics.textures.obtain(HILBERT_R2_INDEX_TEXTURE).obtainView(),
232
-
233
- light_data: scene_ctx.lights.buffer_data,
234
- tEnvironment: scene_ctx.lights.environment.obtainView(),
235
-
236
- tlas: scene_ctx.tlas.buffer,
237
- blas_lookup: scene_ctx.geometries.blas.buffer_metadata,
238
- blas_data: scene_ctx.geometries.blas.buffer_data,
239
-
240
- scene_database: scene_ctx.scene_database_buffer,
241
- geometries: scene_ctx.geometries.buffer_metadata,
242
- }
243
- });
244
-
245
- // after enough accumulation, use baking shader with feedback - sampling light map along the way to improve convergence and get infinite bounce
246
-
247
-
248
- // write the tile out to the light map
249
- const cmd = ShadeGPUCommandContext.create(graphics, 'Lightmap Bake/update');
250
-
251
- cmd.encodeGraph(graph);
252
-
253
-
254
- cmd.finish();
255
- }
256
-
257
- bake_end() {
258
- const graphics = this.#graphics;
259
- const graph = new FrameGraph("Lightmap Bake/end");
260
-
261
- const cmd = ShadeGPUCommandContext.create(graphics, 'Lightmap Bake/end');
262
-
263
-
264
- const resolution1 = this.resolution;
265
-
266
- const texture_Y1 = graph_import_texture(graph, this.texture_Y);
267
- const texture_CoCg1 = graph_import_texture(graph, this.texture_CoCg);
268
- const texture_viz1 = graph_import_texture(graph, this.texture_viz);
269
-
270
- // denoise
271
- const [temp_Y, temp_CoCg] = graph_image_pass({
272
- graph,
273
- shader: shader_lightmap_denoise_sh,
274
- output_resolution: [resolution1, resolution1],
275
- inputs: {
276
- lightmap_Y: texture_Y1,
277
- lightmap_CoCg: texture_CoCg1,
278
- viz_buffer: texture_viz1,
279
- settings: {
280
- step_size: 1
281
- }
282
- }
283
- });
284
-
285
- // TODO blend seams
286
-
287
- // dilate the chart to provide a margin for mipmaps
288
- graph_image_pass({
289
- graph,
290
- output: [
291
- texture_Y1,
292
- texture_CoCg1,
293
- ],
294
- shader: shader_lightmap_dilate,
295
- inputs: {
296
- lightmap_Y: temp_Y,
297
- lightmap_CoCg: temp_CoCg,
298
- viz_buffer: texture_viz1,
299
- }
300
- });
301
-
302
- // generate mips
303
- const mipmaps = graphics.textures.mipmaps;
304
-
305
-
306
- cmd.encodeGraph(graph);
307
-
308
- mipmaps.generateMipmap(this.texture_Y.gpu_texture, this.texture_Y.descriptor, TextureFilterType.Linear, cmd.gpu_encoder);
309
- mipmaps.generateMipmap(this.texture_CoCg.gpu_texture, this.texture_CoCg.descriptor, TextureFilterType.Linear, cmd.gpu_encoder);
310
-
311
-
312
- cmd.finish();
313
-
314
- // cleanup bake tiles
315
- this.#bake_tile_sh_Y.destroy();
316
- this.#bake_tile_sh_Y = null;
317
-
318
- this.#bake_tile_sh_CoCg.destroy();
319
- this.#bake_tile_sh_CoCg = null;
320
- }
321
-
322
- /**
323
- *
324
- * @param {GPUSceneContext} scene_ctx
325
- * @param {GraphicsContext} graphics
326
- */
327
- bake(scene_ctx, graphics) {
328
- assert.defined(scene_ctx, 'scene_ctx');
329
- assert.defined(graphics, 'graphics');
330
-
331
- this.bake_start(scene_ctx, graphics);
332
- this.bake_update();
333
- this.bake_end();
334
-
335
- }
336
-
1
+ import { assert } from "../../../core/assert.js";
2
+ import { FrameGraph } from "../../../engine/graphics/render/frame_graph/FrameGraph.js";
3
+ import { ShadeGPUCommandContext } from "../../device/ShadeGPUCommandContext.js";
4
+ import { graph_image_pass } from "../shader/graph/graph_image_pass.js";
5
+ import { graph_import_texture } from "../shader/graph/graph_import_texture.js";
6
+ import { GPUTextureContext } from "../texture/GPUTextureContext.js";
7
+ import { texture_mip_level_count } from "../../util/texture_mip_extent.js";
8
+ import { HILBERT_R2_INDEX_TEXTURE } from "../texture/noise/HILBERT_R2_INDEX_TEXTURE.js";
9
+ import { TextureFilterType } from "../texture/TextureFilterType.js";
10
+ import { graph_draw_lightmap_viz_buffer } from "./bake/raster/graph_draw_lightmap_viz_buffer.js";
11
+ import { shader_lightmap_denoise_sh } from "./bake/shader_lightmap_denoise_sh.js";
12
+ import { shader_lightmap_dilate } from "./bake/shader_lightmap_dilate.js";
13
+ import { shader_lightmap_viz_to_sh } from "./bake/shader_lightmap_viz_to_sh.js";
14
+ import { DEFAULT_LIGHTMAP_RESOLUTION } from "./DEFAULT_LIGHTMAP_RESOLUTION.js";
15
+
16
+ const MAX_LIGHT_MAP_SIZE = DEFAULT_LIGHTMAP_RESOLUTION;
17
+ const BAKE_TILE_SIZE = 256;
18
+
19
+
20
+ export class GPULightMap {
21
+
22
+ /**
23
+ *
24
+ * @type {GPUTextureContext|null}
25
+ */
26
+ texture_Y = null;
27
+ /**
28
+ *
29
+ * @type {GPUTextureContext|null}
30
+ */
31
+ texture_CoCg = null;
32
+ /**
33
+ *
34
+ * @type {GPUTextureContext|null}
35
+ */
36
+ texture_flat = null;
37
+
38
+ /**
39
+ * Stores [mesh_id, triangle_id] as vec2<u32>
40
+ * @type {GPUTextureContext|null}
41
+ */
42
+ texture_viz = null;
43
+
44
+ /**
45
+ *
46
+ * @return {number}
47
+ */
48
+ get resolution() {
49
+ return this.texture_Y.descriptor.size.width;
50
+ }
51
+
52
+ /**
53
+ *
54
+ * @param {GPUDevice} device
55
+ */
56
+ constructor(device) {
57
+ const resolution = MAX_LIGHT_MAP_SIZE;
58
+
59
+ const mip_count = Math.min(
60
+ 3,
61
+ texture_mip_level_count(resolution, resolution, 1, "2d")
62
+ );
63
+
64
+ const texture_Y = new GPUTextureContext(device);
65
+
66
+ texture_Y.resize(resolution, resolution);
67
+ texture_Y.descriptor.label = "Lightmap Y/ sh2";
68
+ texture_Y.descriptor.format = "rgba16float";
69
+ texture_Y.descriptor.usage |= GPUTextureUsage.RENDER_ATTACHMENT;
70
+ texture_Y.descriptor.mipLevelCount = mip_count;
71
+
72
+ const texture_CoCg = new GPUTextureContext(device);
73
+ texture_CoCg.resize(resolution, resolution);
74
+ texture_CoCg.descriptor.label = "Lightmap CoCg";
75
+ texture_CoCg.descriptor.format = "rg16float";
76
+ texture_CoCg.descriptor.usage |= GPUTextureUsage.RENDER_ATTACHMENT;
77
+ texture_CoCg.descriptor.mipLevelCount = mip_count;
78
+
79
+ this.texture_Y = texture_Y;
80
+ this.texture_CoCg = texture_CoCg;
81
+
82
+ // flat
83
+
84
+ const texture_flat = new GPUTextureContext(device);
85
+ texture_flat.resize(resolution, resolution);
86
+ texture_flat.descriptor.label = "Lightmap flat";
87
+ texture_flat.descriptor.format = "rgba16float";
88
+ texture_flat.descriptor.usage |= GPUTextureUsage.RENDER_ATTACHMENT;
89
+ texture_flat.descriptor.mipLevelCount = mip_count;
90
+
91
+ this.texture_flat = texture_flat;
92
+
93
+ const texture_viz = new GPUTextureContext(device);
94
+ texture_viz.resize(resolution, resolution);
95
+ texture_viz.descriptor.label = "Lightmap viz";
96
+ texture_viz.descriptor.format = "rg32uint";
97
+ texture_viz.descriptor.usage |= GPUTextureUsage.RENDER_ATTACHMENT;
98
+ texture_viz.descriptor.mipLevelCount = 1;
99
+
100
+ this.texture_viz = texture_viz;
101
+ }
102
+
103
+ /**
104
+ * @type {GPUSceneContext}
105
+ */
106
+ #scene
107
+
108
+ /**
109
+ * @type {GraphicsContext}
110
+ */
111
+ #graphics
112
+
113
+ /**
114
+ * @type {GPUTextureContext}
115
+ */
116
+ #bake_tile_sh_Y = null;
117
+ /**
118
+ *
119
+ * @type {GPUTextureContext}
120
+ */
121
+ #bake_tile_sh_CoCg = null;
122
+ #bake_tile_next = 0;
123
+ #bake_full_iteration_count = 0;
124
+
125
+ /**
126
+ *
127
+ * @param {GPUSceneContext} scene_ctx
128
+ * @param {GraphicsContext} graphics
129
+ */
130
+ bake_start(scene_ctx, graphics) {
131
+ assert.isNull(this.#bake_tile_sh_Y, 'bake_tiles'); // didn't clean up
132
+
133
+ this.#scene = scene_ctx;
134
+ this.#graphics = graphics;
135
+
136
+ const graph = new FrameGraph("Lightmap Bake/start");
137
+ // prepare viz buffer
138
+
139
+ const r_materials = graphics.materials_resident;
140
+
141
+
142
+ r_materials.ensure_scene_materials(scene_ctx);
143
+ r_materials.update();
144
+
145
+ const viz_buffer = graph_import_texture(graph, this.texture_viz);
146
+
147
+ graph_draw_lightmap_viz_buffer({
148
+ graph,
149
+ output: viz_buffer,
150
+ scene: scene_ctx,
151
+ });
152
+
153
+ const cmd = ShadeGPUCommandContext.create(graphics, 'Lightmap Bake/start');
154
+
155
+ cmd.encodeGraph(graph);
156
+
157
+
158
+ cmd.finish();
159
+
160
+ // create bake tiles
161
+ this.#create_bake_tile();
162
+
163
+ this.#bake_tile_next = 0;
164
+ this.#bake_full_iteration_count = 0;
165
+ }
166
+
167
+ #create_bake_tile() {
168
+
169
+ const device = this.#graphics.device;
170
+
171
+ const tile_Y = new GPUTextureContext(device);
172
+
173
+ tile_Y.descriptor.dimension = "2d";
174
+ tile_Y.descriptor.label = "Lightmap bake tile / Y";
175
+ tile_Y.descriptor.format = "rgba32float";
176
+ tile_Y.descriptor.usage |= GPUTextureUsage.RENDER_ATTACHMENT;
177
+ tile_Y.descriptor.mipLevelCount = 1;
178
+ tile_Y.resize(BAKE_TILE_SIZE, BAKE_TILE_SIZE);
179
+
180
+ this.#bake_tile_sh_Y = tile_Y;
181
+
182
+ const tile_CoCg = new GPUTextureContext(device);
183
+
184
+ tile_CoCg.descriptor.dimension = "2d";
185
+ tile_CoCg.descriptor.label = "Lightmap bake tile / CoCg";
186
+ tile_CoCg.descriptor.format = "rg32float";
187
+ tile_CoCg.descriptor.usage |= GPUTextureUsage.RENDER_ATTACHMENT;
188
+ tile_CoCg.descriptor.mipLevelCount = 1;
189
+ tile_CoCg.resize(BAKE_TILE_SIZE, BAKE_TILE_SIZE);
190
+
191
+ this.#bake_tile_sh_CoCg = tile_CoCg;
192
+ }
193
+
194
+ /**
195
+ * Perform a single step of baking
196
+ */
197
+ bake_update() {
198
+ const graphics = this.#graphics;
199
+ const scene_ctx = this.#scene;
200
+ const r_materials = graphics.materials_resident;
201
+
202
+
203
+ const graph = new FrameGraph("Lightmap Bake/update");
204
+
205
+ // pick a tile to update
206
+ const bake_tile_index = this.#bake_tile_next;
207
+ this.#bake_tile_next = (bake_tile_index + 1) % this.#bake_tile_sh_Y.descriptor.size.width;
208
+
209
+ if (this.#bake_tile_next === 0) {
210
+ // full cycle
211
+ this.#bake_full_iteration_count++;
212
+ }
213
+
214
+ const viz_buffer = graph_import_texture(graph, this.texture_viz);
215
+
216
+ // load the tile from the light map to update
217
+
218
+ // bake a single tile of the light map
219
+ graph_image_pass({
220
+ graph,
221
+ shader: shader_lightmap_viz_to_sh,
222
+ output: [
223
+ graph_import_texture(graph, this.texture_Y),
224
+ graph_import_texture(graph, this.texture_CoCg),
225
+ ],
226
+ inputs: {
227
+ viz_buffer,
228
+
229
+ materials: r_materials.buffer_materials,
230
+ textures: r_materials.textureView,
231
+ tNoise: graphics.textures.obtain(HILBERT_R2_INDEX_TEXTURE).obtainView(),
232
+
233
+ light_data: scene_ctx.lights.buffer_data,
234
+ tEnvironment: scene_ctx.lights.environment.obtainView(),
235
+
236
+ tlas: scene_ctx.tlas.buffer,
237
+ blas_lookup: scene_ctx.geometries.blas.buffer_metadata,
238
+ blas_data: scene_ctx.geometries.blas.buffer_data,
239
+
240
+ scene_database: scene_ctx.scene_database_buffer,
241
+ geometries: scene_ctx.geometries.buffer_metadata,
242
+ }
243
+ });
244
+
245
+ // after enough accumulation, use baking shader with feedback - sampling light map along the way to improve convergence and get infinite bounce
246
+
247
+
248
+ // write the tile out to the light map
249
+ const cmd = ShadeGPUCommandContext.create(graphics, 'Lightmap Bake/update');
250
+
251
+ cmd.encodeGraph(graph);
252
+
253
+
254
+ cmd.finish();
255
+ }
256
+
257
+ bake_end() {
258
+ const graphics = this.#graphics;
259
+ const graph = new FrameGraph("Lightmap Bake/end");
260
+
261
+ const cmd = ShadeGPUCommandContext.create(graphics, 'Lightmap Bake/end');
262
+
263
+
264
+ const resolution1 = this.resolution;
265
+
266
+ const texture_Y1 = graph_import_texture(graph, this.texture_Y);
267
+ const texture_CoCg1 = graph_import_texture(graph, this.texture_CoCg);
268
+ const texture_viz1 = graph_import_texture(graph, this.texture_viz);
269
+
270
+ // denoise
271
+ const [temp_Y, temp_CoCg] = graph_image_pass({
272
+ graph,
273
+ shader: shader_lightmap_denoise_sh,
274
+ output_resolution: [resolution1, resolution1],
275
+ inputs: {
276
+ lightmap_Y: texture_Y1,
277
+ lightmap_CoCg: texture_CoCg1,
278
+ viz_buffer: texture_viz1,
279
+ settings: {
280
+ step_size: 1
281
+ }
282
+ }
283
+ });
284
+
285
+ // TODO blend seams
286
+
287
+ // dilate the chart to provide a margin for mipmaps
288
+ graph_image_pass({
289
+ graph,
290
+ output: [
291
+ texture_Y1,
292
+ texture_CoCg1,
293
+ ],
294
+ shader: shader_lightmap_dilate,
295
+ inputs: {
296
+ lightmap_Y: temp_Y,
297
+ lightmap_CoCg: temp_CoCg,
298
+ viz_buffer: texture_viz1,
299
+ }
300
+ });
301
+
302
+ // generate mips
303
+ const mipmaps = graphics.textures.mipmaps;
304
+
305
+
306
+ cmd.encodeGraph(graph);
307
+
308
+ /**
309
+ * The mip passes record into our encoder, so their scratch buffer and textures are still
310
+ * referenced by commands that have not been submitted. They are destroyed after `finish()`,
311
+ * not before it: a destroyed resource in a submit has the whole command buffer rejected, and
312
+ * that command buffer is the lightmap bake.
313
+ * @type {{destroy: function():void}[]}
314
+ */
315
+ const mip_scratch = [];
316
+
317
+ mipmaps.generateMipmap(this.texture_Y.gpu_texture, this.texture_Y.descriptor, TextureFilterType.Linear, cmd.gpu_encoder, mip_scratch);
318
+ mipmaps.generateMipmap(this.texture_CoCg.gpu_texture, this.texture_CoCg.descriptor, TextureFilterType.Linear, cmd.gpu_encoder, mip_scratch);
319
+
320
+
321
+ cmd.finish();
322
+
323
+ for (const resource of mip_scratch) {
324
+ resource.destroy();
325
+ }
326
+
327
+ // cleanup bake tiles
328
+ this.#bake_tile_sh_Y.destroy();
329
+ this.#bake_tile_sh_Y = null;
330
+
331
+ this.#bake_tile_sh_CoCg.destroy();
332
+ this.#bake_tile_sh_CoCg = null;
333
+ }
334
+
335
+ /**
336
+ *
337
+ * @param {GPUSceneContext} scene_ctx
338
+ * @param {GraphicsContext} graphics
339
+ */
340
+ bake(scene_ctx, graphics) {
341
+ assert.defined(scene_ctx, 'scene_ctx');
342
+ assert.defined(graphics, 'graphics');
343
+
344
+ this.bake_start(scene_ctx, graphics);
345
+ this.bake_update();
346
+ this.bake_end();
347
+
348
+ }
349
+
337
350
  }