@woosh/meep-engine 3.14.1 → 3.14.2

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 (220) hide show
  1. package/README.md +31 -24
  2. package/package.json +1 -1
  3. package/src/avif/native/DECISIONS.md +544 -536
  4. package/src/avif/native/heif/parse_avif_file.d.ts.map +1 -1
  5. package/src/avif/native/heif/parse_avif_file.js +384 -383
  6. package/src/avif/native/heif/parse_image_grid.d.ts.map +1 -1
  7. package/src/avif/native/heif/parse_image_grid.js +49 -48
  8. package/src/basis/BasisBitReader.d.ts +77 -0
  9. package/src/basis/BasisBitReader.d.ts.map +1 -0
  10. package/src/basis/BasisBitReader.js +231 -0
  11. package/src/basis/BasisHuffmanTable.d.ts +53 -0
  12. package/src/basis/BasisHuffmanTable.d.ts.map +1 -0
  13. package/src/basis/BasisHuffmanTable.js +263 -0
  14. package/src/basis/basis_read_huffman_table.d.ts +20 -0
  15. package/src/basis/basis_read_huffman_table.d.ts.map +1 -0
  16. package/src/basis/basis_read_huffman_table.js +187 -0
  17. package/src/basis/etc1s/Etc1sSelectorHistory.d.ts +50 -0
  18. package/src/basis/etc1s/Etc1sSelectorHistory.d.ts.map +1 -0
  19. package/src/basis/etc1s/Etc1sSelectorHistory.js +89 -0
  20. package/src/basis/etc1s/etc1s_block_colors.d.ts +14 -0
  21. package/src/basis/etc1s/etc1s_block_colors.d.ts.map +1 -0
  22. package/src/basis/etc1s/etc1s_block_colors.js +75 -0
  23. package/src/basis/etc1s/etc1s_decode_slice.d.ts +57 -0
  24. package/src/basis/etc1s/etc1s_decode_slice.d.ts.map +1 -0
  25. package/src/basis/etc1s/etc1s_decode_slice.js +258 -0
  26. package/src/basis/etc1s/etc1s_read_endpoint_codebook.d.ts +48 -0
  27. package/src/basis/etc1s/etc1s_read_endpoint_codebook.d.ts.map +1 -0
  28. package/src/basis/etc1s/etc1s_read_endpoint_codebook.js +111 -0
  29. package/src/basis/etc1s/etc1s_read_selector_codebook.d.ts +42 -0
  30. package/src/basis/etc1s/etc1s_read_selector_codebook.d.ts.map +1 -0
  31. package/src/basis/etc1s/etc1s_read_selector_codebook.js +127 -0
  32. package/src/basis/etc1s/etc1s_read_slice_tables.d.ts +54 -0
  33. package/src/basis/etc1s/etc1s_read_slice_tables.d.ts.map +1 -0
  34. package/src/basis/etc1s/etc1s_read_slice_tables.js +47 -0
  35. package/src/basis/transcode/build_range_plan.js +54 -0
  36. package/src/basis/transcode/etc1s_to_bc1.d.ts +24 -0
  37. package/src/basis/transcode/etc1s_to_bc1.d.ts.map +1 -0
  38. package/src/basis/transcode/etc1s_to_bc1.js +205 -0
  39. package/src/basis/transcode/etc1s_to_bc7.d.ts +30 -0
  40. package/src/basis/transcode/etc1s_to_bc7.d.ts.map +1 -0
  41. package/src/basis/transcode/etc1s_to_bc7.js +496 -0
  42. package/src/basis/transcode/fit_endpoints.d.ts +59 -0
  43. package/src/basis/transcode/fit_endpoints.d.ts.map +1 -0
  44. package/src/basis/transcode/fit_endpoints.js +226 -0
  45. package/src/{avif/native/isobmff → core/binary}/ByteCursor.d.ts +19 -6
  46. package/src/core/binary/ByteCursor.d.ts.map +1 -0
  47. package/src/{avif/native/isobmff → core/binary}/ByteCursor.js +41 -14
  48. package/src/engine/EngineHarness.js +1 -1
  49. package/src/engine/asset/codec/Codec.d.ts.map +1 -0
  50. package/src/engine/asset/codec/CodecWithFallback.d.ts.map +1 -0
  51. package/src/engine/asset/{loaders/image/codec → codec}/CodecWithFallback.js +2 -2
  52. package/src/engine/asset/loaders/image/IMAGE_CODEC_REVIEW_2026_08_28.md +4 -4
  53. package/src/engine/asset/loaders/image/ImageRGBADataLoader.d.ts +1 -1
  54. package/src/engine/asset/loaders/image/ImageRGBADataLoader.d.ts.map +1 -1
  55. package/src/engine/asset/loaders/image/ImageRGBADataLoader.js +1 -1
  56. package/src/engine/asset/loaders/image/codec/NativeImageDecoder.d.ts +1 -1
  57. package/src/engine/asset/loaders/image/codec/NativeImageDecoder.d.ts.map +1 -1
  58. package/src/engine/asset/loaders/image/codec/NativeImageDecoder.js +1 -1
  59. package/src/engine/asset/loaders/image/codec/ThreadedImageDecoder.d.ts +1 -1
  60. package/src/engine/asset/loaders/image/codec/ThreadedImageDecoder.d.ts.map +1 -1
  61. package/src/engine/asset/loaders/image/codec/ThreadedImageDecoder.js +1 -1
  62. package/src/engine/graphics/texture/atlas/TextureAtlas.d.ts.map +1 -1
  63. package/src/engine/graphics/texture/atlas/TextureAtlas.js +13 -0
  64. package/src/engine/physics/broadphase/generate_pairs.d.ts.map +1 -1
  65. package/src/engine/physics/broadphase/generate_pairs.js +7 -1
  66. package/src/engine/physics/fluid/ecs/FluidObstacleSystem.d.ts +4 -4
  67. package/src/ktx2/KTX2_IDENTIFIER.d.ts +14 -0
  68. package/src/ktx2/KTX2_IDENTIFIER.d.ts.map +1 -0
  69. package/src/ktx2/KTX2_IDENTIFIER.js +15 -0
  70. package/src/ktx2/KhrDfModel.d.ts +35 -0
  71. package/src/ktx2/KhrDfModel.d.ts.map +1 -0
  72. package/src/ktx2/KhrDfModel.js +49 -0
  73. package/src/ktx2/SupercompressionScheme.d.ts +16 -0
  74. package/src/ktx2/SupercompressionScheme.d.ts.map +1 -0
  75. package/src/ktx2/SupercompressionScheme.js +23 -0
  76. package/src/ktx2/ktx2_read.d.ts +71 -0
  77. package/src/ktx2/ktx2_read.d.ts.map +1 -0
  78. package/src/ktx2/ktx2_read.js +581 -0
  79. package/src/ktx2/ktx2_read_basis_lz_global_data.d.ts +27 -0
  80. package/src/ktx2/ktx2_read_basis_lz_global_data.d.ts.map +1 -0
  81. package/src/ktx2/ktx2_read_basis_lz_global_data.js +189 -0
  82. package/src/ktx2/vk_format_to_texture_format.d.ts +55 -0
  83. package/src/ktx2/vk_format_to_texture_format.d.ts.map +1 -0
  84. package/src/ktx2/vk_format_to_texture_format.js +290 -0
  85. package/src/shade/descriptor/GPUTextureUsage.d.ts +23 -0
  86. package/src/shade/descriptor/GPUTextureUsage.d.ts.map +1 -0
  87. package/src/shade/descriptor/GPUTextureUsage.js +24 -0
  88. package/src/shade/descriptor/WebGPUExtensionType.d.ts +3 -0
  89. package/src/shade/descriptor/WebGPUExtensionType.js +26 -0
  90. package/src/shade/descriptor/texture/TextureDescriptor.d.ts +2 -6
  91. package/src/shade/descriptor/texture/TextureDescriptor.d.ts.map +1 -1
  92. package/src/shade/descriptor/texture/TextureDescriptor.js +24 -40
  93. package/src/shade/descriptor/texture/format/TextureFormat.d.ts +125 -0
  94. package/src/shade/descriptor/texture/format/TextureFormat.d.ts.map +1 -0
  95. package/src/shade/descriptor/texture/format/TextureFormat.js +146 -0
  96. package/src/shade/descriptor/texture/format/gpu_texture_format_info.d.ts +60 -0
  97. package/src/shade/descriptor/texture/format/gpu_texture_format_info.d.ts.map +1 -1
  98. package/src/shade/descriptor/texture/format/gpu_texture_format_info.js +102 -0
  99. package/src/shade/device/graph/TextureResourceDescriptor.d.ts.map +1 -1
  100. package/src/shade/device/graph/TextureResourceDescriptor.js +160 -155
  101. package/src/shade/device/mock/SoftwareGPUQueue.d.ts +11 -4
  102. package/src/shade/device/mock/SoftwareGPUQueue.d.ts.map +1 -1
  103. package/src/shade/device/mock/SoftwareGPUQueue.js +31 -37
  104. package/src/shade/device/mock/SoftwareGPUTexture.d.ts.map +1 -1
  105. package/src/shade/device/mock/SoftwareGPUTexture.js +8 -4
  106. package/src/shade/device/timing/profile/frame_graph_extract_topology.d.ts.map +1 -1
  107. package/src/shade/device/timing/profile/frame_graph_extract_topology.js +164 -174
  108. package/src/shade/playground/ground_seam/README.md +235 -0
  109. package/src/shade/playground/ground_seam/capture_scene_color.d.ts +45 -0
  110. package/src/shade/playground/ground_seam/capture_scene_color.d.ts.map +1 -0
  111. package/src/shade/playground/ground_seam/capture_scene_color.js +242 -0
  112. package/src/shade/playground/ground_seam/depth_step_across_seam.d.ts +11 -0
  113. package/src/shade/playground/ground_seam/depth_step_across_seam.d.ts.map +1 -0
  114. package/src/shade/playground/ground_seam/depth_step_across_seam.js +185 -0
  115. package/src/shade/playground/ground_seam/index.html +195 -0
  116. package/src/shade/playground/ground_seam/main.d.ts +2 -0
  117. package/src/shade/playground/ground_seam/main.d.ts.map +1 -0
  118. package/src/shade/playground/ground_seam/main.js +879 -0
  119. package/src/shade/playground/ground_seam/make_grid_texture.d.ts +29 -0
  120. package/src/shade/playground/ground_seam/make_grid_texture.d.ts.map +1 -0
  121. package/src/shade/playground/ground_seam/make_grid_texture.js +105 -0
  122. package/src/shade/playground/ground_seam/make_ground.d.ts +70 -0
  123. package/src/shade/playground/ground_seam/make_ground.d.ts.map +1 -0
  124. package/src/shade/playground/ground_seam/make_ground.js +161 -0
  125. package/src/shade/playground/ground_seam/measure_flicker.d.ts +71 -0
  126. package/src/shade/playground/ground_seam/measure_flicker.d.ts.map +1 -0
  127. package/src/shade/playground/ground_seam/measure_flicker.js +531 -0
  128. package/src/shade/renderer/Renderer.d.ts.map +1 -1
  129. package/src/shade/renderer/Renderer.js +2519 -2511
  130. package/src/shade/renderer/hiz/HierarchicalZBuffer.d.ts.map +1 -1
  131. package/src/shade/renderer/hiz/HierarchicalZBuffer.js +275 -274
  132. package/src/shade/renderer/light/GPULightCollection.d.ts.map +1 -1
  133. package/src/shade/renderer/light/GPULightCollection.js +323 -314
  134. package/src/shade/renderer/lightmap/GPULightMap.js +336 -336
  135. package/src/shade/renderer/material/resident/GPUResidentMaterialContext.d.ts.map +1 -1
  136. package/src/shade/renderer/material/resident/GPUResidentMaterialContext.js +12 -2
  137. package/src/shade/renderer/material/standard/fragment_gbuffer.d.ts.map +1 -1
  138. package/src/shade/renderer/material/standard/fragment_gbuffer.js +3 -1
  139. package/src/shade/renderer/material/standard/fragment_gbuffer_vt.js +169 -169
  140. package/src/shade/renderer/path_tracer/shader/chunk_sample_material_data.d.ts.map +1 -1
  141. package/src/shade/renderer/path_tracer/shader/chunk_sample_material_data.js +3 -1
  142. package/src/shade/renderer/postprocess/nss/NSS.d.ts +1 -1
  143. package/src/shade/renderer/rasterize/native/oit/chunk_forward_shade_standard_fragment_brick4.d.ts.map +1 -1
  144. package/src/shade/renderer/rasterize/native/oit/chunk_forward_shade_standard_fragment_brick4.js +3 -1
  145. package/src/shade/renderer/rasterize/native/oit/chunk_forward_shade_standard_fragment_ibl.d.ts.map +1 -1
  146. package/src/shade/renderer/rasterize/native/oit/chunk_forward_shade_standard_fragment_ibl.js +3 -1
  147. package/src/shade/renderer/shader/chunk/geometry/normal/chunk_decode_tangent_normal.d.ts +28 -0
  148. package/src/shade/renderer/shader/chunk/geometry/normal/chunk_decode_tangent_normal.d.ts.map +1 -0
  149. package/src/shade/renderer/shader/chunk/geometry/normal/chunk_decode_tangent_normal.js +39 -0
  150. package/src/shade/renderer/shader/chunk/geometry/triangle/chunk_barycentric_full.d.ts +45 -0
  151. package/src/shade/renderer/shader/chunk/geometry/triangle/chunk_barycentric_full.d.ts.map +1 -1
  152. package/src/shade/renderer/shader/chunk/geometry/triangle/chunk_barycentric_full.js +94 -61
  153. package/src/shade/renderer/shader/chunk/geometry/triangle/chunk_barycentric_solve.d.ts +24 -0
  154. package/src/shade/renderer/shader/chunk/geometry/triangle/chunk_barycentric_solve.d.ts.map +1 -0
  155. package/src/shade/renderer/shader/chunk/geometry/triangle/chunk_barycentric_solve.js +43 -0
  156. package/src/shade/renderer/texture/COMPRESSED_TEXTURE_PLAN_2026_09_01.md +1462 -0
  157. package/src/shade/renderer/texture/TextureManager.d.ts.map +1 -1
  158. package/src/shade/renderer/texture/TextureManager.js +20 -8
  159. package/src/shade/renderer/texture/TextureRole.d.ts +19 -0
  160. package/src/shade/renderer/texture/TextureRole.d.ts.map +1 -0
  161. package/src/shade/renderer/texture/TextureRole.js +26 -0
  162. package/src/shade/renderer/texture/TextureVariantSet.d.ts +71 -0
  163. package/src/shade/renderer/texture/TextureVariantSet.d.ts.map +1 -0
  164. package/src/shade/renderer/texture/TextureVariantSet.js +105 -0
  165. package/src/shade/renderer/texture/download_texture_data.d.ts.map +1 -1
  166. package/src/shade/renderer/texture/download_texture_data.js +22 -0
  167. package/src/shade/renderer/texture/format/gpu_texture_compression_support.d.ts +15 -0
  168. package/src/shade/renderer/texture/format/gpu_texture_compression_support.d.ts.map +1 -0
  169. package/src/shade/renderer/texture/format/gpu_texture_compression_support.js +50 -0
  170. package/src/shade/renderer/texture/format/gpu_texture_format_can_generate_mipmaps.d.ts +27 -0
  171. package/src/shade/renderer/texture/format/gpu_texture_format_can_generate_mipmaps.d.ts.map +1 -0
  172. package/src/shade/renderer/texture/format/gpu_texture_format_can_generate_mipmaps.js +65 -0
  173. package/src/shade/renderer/texture/format/infer_format_from_parameters.d.ts +11 -0
  174. package/src/shade/renderer/texture/format/infer_format_from_parameters.d.ts.map +1 -0
  175. package/src/shade/renderer/texture/format/infer_format_from_parameters.js +88 -0
  176. package/src/shade/renderer/texture/format/texture_format_from_shade_image.d.ts +24 -0
  177. package/src/shade/renderer/texture/format/texture_format_from_shade_image.d.ts.map +1 -0
  178. package/src/shade/renderer/texture/format/texture_format_from_shade_image.js +71 -0
  179. package/src/shade/renderer/texture/format/texture_format_preference.d.ts +22 -0
  180. package/src/shade/renderer/texture/format/texture_format_preference.d.ts.map +1 -0
  181. package/src/shade/renderer/texture/format/texture_format_preference.js +89 -0
  182. package/src/shade/renderer/texture/format/texture_variant_select.d.ts +24 -0
  183. package/src/shade/renderer/texture/format/texture_variant_select.d.ts.map +1 -0
  184. package/src/shade/renderer/texture/format/texture_variant_select.js +38 -0
  185. package/src/shade/renderer/texture/shade_texture_might_have_alpha.d.ts +9 -1
  186. package/src/shade/renderer/texture/shade_texture_might_have_alpha.d.ts.map +1 -1
  187. package/src/shade/renderer/texture/shade_texture_might_have_alpha.js +73 -8
  188. package/src/shade/renderer/texture/source/AlphaMode.d.ts +27 -0
  189. package/src/shade/renderer/texture/source/AlphaMode.d.ts.map +1 -0
  190. package/src/shade/renderer/texture/source/AlphaMode.js +52 -0
  191. package/src/shade/renderer/texture/source/ShadeImage.d.ts +33 -0
  192. package/src/shade/renderer/texture/source/ShadeImage.d.ts.map +1 -1
  193. package/src/shade/renderer/texture/source/ShadeImage.js +74 -0
  194. package/src/shade/renderer/texture/source/ShadeTexelData.d.ts +78 -0
  195. package/src/shade/renderer/texture/source/ShadeTexelData.d.ts.map +1 -0
  196. package/src/shade/renderer/texture/source/ShadeTexelData.js +158 -0
  197. package/src/shade/renderer/texture/texture_descriptor_from_texture_shade.d.ts +0 -10
  198. package/src/shade/renderer/texture/texture_descriptor_from_texture_shade.d.ts.map +1 -1
  199. package/src/shade/renderer/texture/texture_descriptor_from_texture_shade.js +73 -175
  200. package/src/shade/renderer/texture/texture_write_level.d.ts +32 -0
  201. package/src/shade/renderer/texture/texture_write_level.d.ts.map +1 -0
  202. package/src/shade/renderer/texture/texture_write_level.js +77 -0
  203. package/src/shade/renderer/texture/texture_write_to_gpu.d.ts +8 -1
  204. package/src/shade/renderer/texture/texture_write_to_gpu.d.ts.map +1 -1
  205. package/src/shade/renderer/texture/texture_write_to_gpu.js +62 -37
  206. package/src/shade/renderer/texture/virtual/source/VTSourceImage.d.ts +8 -0
  207. package/src/shade/renderer/texture/virtual/source/VTSourceImage.d.ts.map +1 -1
  208. package/src/shade/renderer/texture/virtual/source/VTSourceImage.js +8 -0
  209. package/src/shade/util/texture_mip_extent.d.ts +49 -0
  210. package/src/shade/util/texture_mip_extent.d.ts.map +1 -0
  211. package/src/shade/util/texture_mip_extent.js +87 -0
  212. package/src/avif/native/isobmff/ByteCursor.d.ts.map +0 -1
  213. package/src/engine/asset/loaders/image/codec/Codec.d.ts.map +0 -1
  214. package/src/engine/asset/loaders/image/codec/CodecWithFallback.d.ts.map +0 -1
  215. package/src/shade/util/compute_max_mip_count.d.ts +0 -8
  216. package/src/shade/util/compute_max_mip_count.d.ts.map +0 -1
  217. package/src/shade/util/compute_max_mip_count.js +0 -27
  218. /package/src/engine/asset/{loaders/image/codec → codec}/Codec.d.ts +0 -0
  219. /package/src/engine/asset/{loaders/image/codec → codec}/Codec.js +0 -0
  220. /package/src/engine/asset/{loaders/image/codec → codec}/CodecWithFallback.d.ts +0 -0
@@ -1,337 +1,337 @@
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 { compute_max_mip_count } from "../../util/compute_max_mip_count.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
- compute_max_mip_count(resolution, resolution)
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.scene);
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.scene);
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
+
337
337
  }