@woosh/meep-engine 3.14.1 → 3.14.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1282) hide show
  1. package/README.md +31 -24
  2. package/editor/prototypeEditorShell.js +6 -0
  3. package/package.json +1 -1
  4. package/src/CODEC_LAYOUT_VERIFICATION.md +420 -0
  5. package/src/core/binary/ByteCursor.d.ts +138 -0
  6. package/src/core/binary/ByteCursor.d.ts.map +1 -0
  7. package/src/core/binary/ByteCursor.js +325 -0
  8. package/src/core/binary/zstd/ZstdReverseBitReader.d.ts +76 -0
  9. package/src/core/binary/zstd/ZstdReverseBitReader.d.ts.map +1 -0
  10. package/src/core/binary/zstd/ZstdReverseBitReader.js +223 -0
  11. package/src/core/binary/zstd/zstd_decompress.d.ts +31 -0
  12. package/src/core/binary/zstd/zstd_decompress.d.ts.map +1 -0
  13. package/src/core/binary/zstd/zstd_decompress.js +628 -0
  14. package/src/core/binary/zstd/zstd_fse.d.ts +83 -0
  15. package/src/core/binary/zstd/zstd_fse.d.ts.map +1 -0
  16. package/src/core/binary/zstd/zstd_fse.js +265 -0
  17. package/src/core/binary/zstd/zstd_huffman.d.ts +56 -0
  18. package/src/core/binary/zstd/zstd_huffman.d.ts.map +1 -0
  19. package/src/core/binary/zstd/zstd_huffman.js +244 -0
  20. package/src/core/binary/zstd/zstd_sequence_tables.d.ts +62 -0
  21. package/src/core/binary/zstd/zstd_sequence_tables.d.ts.map +1 -0
  22. package/src/core/binary/zstd/zstd_sequence_tables.js +98 -0
  23. package/src/core/color/COLOR_REVIEW_2026_08_28.md +1 -1
  24. package/src/core/color/PQ/PQ_constants.d.ts +1 -1
  25. package/src/core/color/PQ/PQ_constants.js +1 -1
  26. package/src/engine/EngineHarness.js +1 -1
  27. package/src/engine/asset/GameAssetType.d.ts +1 -0
  28. package/src/engine/asset/GameAssetType.js +8 -0
  29. package/src/engine/asset/codec/Codec.d.ts.map +1 -0
  30. package/src/engine/asset/codec/CodecWithFallback.d.ts.map +1 -0
  31. package/src/engine/asset/codec/CodecWithFallback.js +105 -0
  32. package/src/engine/asset/codec/DecodedImage.d.ts +39 -0
  33. package/src/engine/asset/codec/DecodedImage.d.ts.map +1 -0
  34. package/src/engine/asset/codec/DecodedImage.js +26 -0
  35. package/src/engine/asset/guessAssetType.d.ts.map +1 -1
  36. package/src/engine/asset/guessAssetType.js +10 -0
  37. package/src/engine/asset/load_model_scene_bundle.d.ts +1 -1
  38. package/src/engine/asset/load_model_scene_bundle.d.ts.map +1 -1
  39. package/src/engine/asset/load_model_scene_bundle.js +6 -2
  40. package/src/engine/asset/loaders/USDSceneBundleAssetLoader.d.ts +37 -0
  41. package/src/engine/asset/loaders/USDSceneBundleAssetLoader.d.ts.map +1 -0
  42. package/src/engine/asset/loaders/USDSceneBundleAssetLoader.js +104 -0
  43. package/src/engine/asset/loaders/image/IMAGE_CODEC_REVIEW_2026_08_28.md +87 -75
  44. package/src/engine/asset/loaders/image/ImageDecoderWorker.js +2 -2
  45. package/src/engine/asset/loaders/image/ImageRGBADataLoader.d.ts +9 -10
  46. package/src/engine/asset/loaders/image/ImageRGBADataLoader.d.ts.map +1 -1
  47. package/src/engine/asset/loaders/image/ImageRGBADataLoader.js +13 -4
  48. package/src/engine/asset/loaders/image/avif/encode_image_source.d.ts +70 -0
  49. package/src/engine/asset/loaders/image/avif/encode_image_source.d.ts.map +1 -0
  50. package/src/engine/asset/loaders/image/avif/encode_image_source.js +117 -0
  51. package/src/engine/asset/loaders/image/avif/encoder_worker.d.ts.map +1 -0
  52. package/src/engine/asset/loaders/image/avif/threaded_image_encoder.d.ts.map +1 -0
  53. package/src/engine/asset/loaders/image/codec/AvifCodec.d.ts +34 -0
  54. package/src/engine/asset/loaders/image/codec/AvifCodec.d.ts.map +1 -0
  55. package/src/engine/asset/loaders/image/codec/AvifCodec.js +85 -0
  56. package/src/engine/asset/loaders/image/codec/JpegCodec.d.ts +26 -0
  57. package/src/engine/asset/loaders/image/codec/JpegCodec.d.ts.map +1 -0
  58. package/src/engine/asset/loaders/image/codec/JpegCodec.js +66 -0
  59. package/src/engine/asset/loaders/image/codec/NativeImageDecoder.d.ts +5 -17
  60. package/src/engine/asset/loaders/image/codec/NativeImageDecoder.d.ts.map +1 -1
  61. package/src/engine/asset/loaders/image/codec/NativeImageDecoder.js +3 -3
  62. package/src/engine/asset/loaders/image/codec/ThreadedImageDecoder.d.ts +22 -2
  63. package/src/engine/asset/loaders/image/codec/ThreadedImageDecoder.d.ts.map +1 -1
  64. package/src/engine/asset/loaders/image/codec/ThreadedImageDecoder.js +22 -2
  65. package/src/engine/asset/loaders/image/prototypePNG.d.ts.map +1 -0
  66. package/src/engine/asset/loaders/image/prototypePNG.js +37 -0
  67. package/src/engine/asset/preloader/extractAssetListFromManager.d.ts.map +1 -1
  68. package/src/engine/asset/preloader/extractAssetListFromManager.js +2 -1
  69. package/src/engine/graphics/ecs/mesh/assetTypeByPath.d.ts.map +1 -1
  70. package/src/engine/graphics/ecs/mesh/assetTypeByPath.js +6 -0
  71. package/src/engine/graphics/texture/atlas/TextureAtlas.d.ts.map +1 -1
  72. package/src/engine/graphics/texture/atlas/TextureAtlas.js +13 -0
  73. package/src/engine/graphics/texture/sampler/avif_to_sampler2d.d.ts +25 -0
  74. package/src/engine/graphics/texture/sampler/avif_to_sampler2d.d.ts.map +1 -0
  75. package/src/engine/graphics/texture/sampler/avif_to_sampler2d.js +42 -0
  76. package/src/engine/graphics/texture/sampler/compare/sampler2d_compare.d.ts.map +1 -0
  77. package/src/engine/graphics/texture/sampler/compare/sampler2d_compare.js +94 -0
  78. package/src/engine/graphics/texture/sampler/compare/sampler2d_max_absolute_difference.d.ts +19 -0
  79. package/src/engine/graphics/texture/sampler/compare/sampler2d_max_absolute_difference.d.ts.map +1 -0
  80. package/src/engine/graphics/texture/sampler/compare/sampler2d_max_absolute_difference.js +62 -0
  81. package/src/engine/graphics/texture/sampler/compare/sampler2d_psnr.d.ts +30 -0
  82. package/src/engine/graphics/texture/sampler/compare/sampler2d_psnr.d.ts.map +1 -0
  83. package/src/engine/graphics/texture/sampler/compare/sampler2d_psnr.js +115 -0
  84. package/src/engine/graphics/texture/sampler/sampler2d_to_avif.d.ts.map +1 -0
  85. package/src/engine/graphics/texture/sampler/sampler2d_to_avif.js +108 -0
  86. package/src/engine/graphics/texture/sampler/sampler2d_to_f16.d.ts +7 -1
  87. package/src/engine/graphics/texture/sampler/sampler2d_to_f16.d.ts.map +1 -1
  88. package/src/engine/graphics/texture/sampler/sampler2d_to_f16.js +28 -21
  89. package/src/engine/graphics/texture/sampler/sampler2d_to_uint8_RGBA.d.ts.map +1 -1
  90. package/src/engine/graphics/texture/sampler/sampler2d_to_uint8_RGBA.js +3 -0
  91. package/src/engine/physics/broadphase/generate_pairs.d.ts.map +1 -1
  92. package/src/engine/physics/broadphase/generate_pairs.js +7 -1
  93. package/src/engine/physics/fluid/ecs/FluidObstacleSystem.d.ts +4 -4
  94. package/src/format/image/avif/DECISIONS.md +545 -0
  95. package/src/format/image/avif/api/AvifDecoder.d.ts.map +1 -0
  96. package/src/format/image/avif/api/apply_transformations.d.ts.map +1 -0
  97. package/src/format/image/avif/api/convert_to_rgba.d.ts.map +1 -0
  98. package/src/format/image/avif/api/convert_to_rgba.js +204 -0
  99. package/src/format/image/avif/api/decode_avif.d.ts.map +1 -0
  100. package/src/format/image/avif/api/decode_image_item.d.ts.map +1 -0
  101. package/src/format/image/avif/api/encode_avif.d.ts.map +1 -0
  102. package/src/format/image/avif/av1/decode/Av1FrameContext.d.ts.map +1 -0
  103. package/src/format/image/avif/av1/decode/block_decoded.d.ts.map +1 -0
  104. package/src/format/image/avif/av1/decode/decode_av1_still.d.ts.map +1 -0
  105. package/src/format/image/avif/av1/decode/decode_coefficients.d.ts.map +1 -0
  106. package/src/format/image/avif/av1/decode/decode_palette.d.ts.map +1 -0
  107. package/src/format/image/avif/av1/decode/decode_palette.js +442 -0
  108. package/src/format/image/avif/av1/decode/decode_tile.d.ts.map +1 -0
  109. package/src/format/image/avif/av1/decode/decode_tile.js +1213 -0
  110. package/src/format/image/avif/av1/decode/get_scan.d.ts.map +1 -0
  111. package/src/format/image/avif/av1/decode/read_lr.d.ts.map +1 -0
  112. package/src/format/image/avif/av1/decode/read_lr.js +277 -0
  113. package/src/format/image/avif/av1/decode/read_transform_type.d.ts.map +1 -0
  114. package/src/format/image/avif/av1/decode/read_transform_type.js +92 -0
  115. package/src/format/image/avif/av1/decode/reconstruct.d.ts.map +1 -0
  116. package/src/format/image/avif/av1/decode/reconstruct.js +241 -0
  117. package/src/format/image/avif/av1/decode/transform_type.d.ts.map +1 -0
  118. package/src/format/image/avif/av1/encode/Av1BlockSnapshot.d.ts.map +1 -0
  119. package/src/format/image/avif/av1/encode/Av1EncodeContext.d.ts.map +1 -0
  120. package/src/format/image/avif/av1/encode/build_headers.d.ts.map +1 -0
  121. package/src/format/image/avif/av1/encode/choose_chroma_alpha.d.ts.map +1 -0
  122. package/src/format/image/avif/av1/encode/choose_filters.d.ts.map +1 -0
  123. package/src/format/image/avif/av1/encode/choose_restoration.d.ts.map +1 -0
  124. package/src/format/image/avif/av1/encode/choose_restoration.js +616 -0
  125. package/src/format/image/avif/av1/encode/decode_effort.d.ts.map +1 -0
  126. package/src/format/image/avif/av1/encode/encode_av1_still.d.ts.map +1 -0
  127. package/src/format/image/avif/av1/encode/encode_effort.d.ts.map +1 -0
  128. package/src/format/image/avif/av1/encode/encode_tile.d.ts.map +1 -0
  129. package/src/format/image/avif/av1/encode/encode_tile.js +2331 -0
  130. package/src/format/image/avif/av1/encode/quantise.d.ts.map +1 -0
  131. package/src/format/image/avif/av1/encode/write_coefficients.d.ts.map +1 -0
  132. package/src/format/image/avif/av1/encode/write_lr.d.ts.map +1 -0
  133. package/src/format/image/avif/av1/encode/write_transform_type.d.ts.map +1 -0
  134. package/src/format/image/avif/av1/entropy/CdfContext.d.ts.map +1 -0
  135. package/src/format/image/avif/av1/entropy/SymbolReader.d.ts.map +1 -0
  136. package/src/format/image/avif/av1/entropy/SymbolWriter.d.ts.map +1 -0
  137. package/src/format/image/avif/av1/entropy/coefficient_context.d.ts.map +1 -0
  138. package/src/format/image/avif/av1/entropy/partition_cdf.d.ts.map +1 -0
  139. package/src/format/image/avif/av1/entropy/symbol_cost.d.ts.map +1 -0
  140. package/src/format/image/avif/av1/filter/cdef.d.ts.map +1 -0
  141. package/src/format/image/avif/av1/filter/cdef.js +313 -0
  142. package/src/format/image/avif/av1/filter/loop_filter.d.ts.map +1 -0
  143. package/src/format/image/avif/av1/filter/loop_filter.js +377 -0
  144. package/src/format/image/avif/av1/filter/loop_restoration.d.ts.map +1 -0
  145. package/src/format/image/avif/av1/filter/loop_restoration.js +451 -0
  146. package/src/format/image/avif/av1/filter/superres.d.ts.map +1 -0
  147. package/src/format/image/avif/av1/filter/superres.js +86 -0
  148. package/src/format/image/avif/av1/grain/FilmGrainState.d.ts.map +1 -0
  149. package/src/format/image/avif/av1/grain/film_grain.d.ts.map +1 -0
  150. package/src/format/image/avif/av1/grain/film_grain.js +623 -0
  151. package/src/format/image/avif/av1/obu/FrameHeader.d.ts.map +1 -0
  152. package/src/format/image/avif/av1/obu/ObuHeader.d.ts.map +1 -0
  153. package/src/format/image/avif/av1/obu/SequenceHeader.d.ts.map +1 -0
  154. package/src/format/image/avif/av1/obu/for_each_obu.d.ts.map +1 -0
  155. package/src/format/image/avif/av1/obu/parse_frame_header.d.ts.map +1 -0
  156. package/src/format/image/avif/av1/obu/parse_frame_header.js +841 -0
  157. package/src/format/image/avif/av1/obu/parse_obu_header.d.ts.map +1 -0
  158. package/src/format/image/avif/av1/obu/parse_sequence_header.d.ts.map +1 -0
  159. package/src/format/image/avif/av1/obu/write_frame_header.d.ts.map +1 -0
  160. package/src/format/image/avif/av1/obu/write_sequence_header.d.ts.map +1 -0
  161. package/src/format/image/avif/av1/predict/IntraPredictionState.d.ts.map +1 -0
  162. package/src/format/image/avif/av1/predict/intra_filter_type.d.ts.map +1 -0
  163. package/src/format/image/avif/av1/predict/predict_chroma_from_luma.d.ts.map +1 -0
  164. package/src/format/image/avif/av1/predict/predict_chroma_from_luma.js +153 -0
  165. package/src/format/image/avif/av1/predict/predict_intra.d.ts.map +1 -0
  166. package/src/format/image/avif/av1/predict/predict_intra.js +803 -0
  167. package/src/format/image/avif/av1/predict/predict_palette.d.ts.map +1 -0
  168. package/src/format/image/avif/av1/tables/av1_symbols.d.ts.map +1 -0
  169. package/src/format/image/avif/av1/tables/av1_symbols.js +419 -0
  170. package/src/format/image/avif/av1/tables/block_tables.d.ts.map +1 -0
  171. package/src/format/image/avif/av1/tables/block_tables.js +270 -0
  172. package/src/format/image/avif/av1/tables/cdf_tables.d.ts.map +1 -0
  173. package/src/format/image/avif/av1/tables/cdf_tables.js +1893 -0
  174. package/src/format/image/avif/av1/tables/coefficient_tables.d.ts.map +1 -0
  175. package/src/format/image/avif/av1/tables/coefficient_tables.js +82 -0
  176. package/src/format/image/avif/av1/tables/derived_block_tables.d.ts.map +1 -0
  177. package/src/format/image/avif/av1/tables/filter_tables.d.ts.map +1 -0
  178. package/src/format/image/avif/av1/tables/filter_tables.js +313 -0
  179. package/src/format/image/avif/av1/tables/grain_tables.d.ts.map +1 -0
  180. package/src/format/image/avif/av1/tables/grain_tables.js +190 -0
  181. package/src/format/image/avif/av1/tables/prediction_tables.d.ts.map +1 -0
  182. package/src/format/image/avif/av1/tables/prediction_tables.js +223 -0
  183. package/src/format/image/avif/av1/tables/quantizer_matrix_tables.d.ts.map +1 -0
  184. package/src/format/image/avif/av1/tables/quantizer_matrix_tables.js +38 -0
  185. package/src/format/image/avif/av1/tables/quantizer_tables.d.ts.map +1 -0
  186. package/src/format/image/avif/av1/tables/quantizer_tables.js +160 -0
  187. package/src/format/image/avif/av1/tables/scan_tables.d.ts.map +1 -0
  188. package/src/format/image/avif/av1/tables/scan_tables.js +727 -0
  189. package/src/format/image/avif/av1/tables/segmentation_tables.d.ts.map +1 -0
  190. package/src/format/image/avif/av1/tables/segmentation_tables.js +48 -0
  191. package/src/format/image/avif/av1/tables/transform_tables.d.ts.map +1 -0
  192. package/src/format/image/avif/av1/tables/transform_tables.js +140 -0
  193. package/src/format/image/avif/av1/tables/unpack_table.d.ts.map +1 -0
  194. package/src/format/image/avif/av1/tables/unpack_table.js +73 -0
  195. package/src/format/image/avif/av1/transform/forward_transform_2d.d.ts.map +1 -0
  196. package/src/format/image/avif/av1/transform/inverse_transform_1d.d.ts.map +1 -0
  197. package/src/format/image/avif/av1/transform/inverse_transform_1d.js +590 -0
  198. package/src/format/image/avif/av1/transform/inverse_transform_2d.d.ts.map +1 -0
  199. package/src/format/image/avif/av1/transform/inverse_transform_2d.js +180 -0
  200. package/src/format/image/avif/av1/util/ceil_log2.d.ts.map +1 -0
  201. package/src/format/image/avif/av1/util/floor_log2.d.ts +20 -0
  202. package/src/format/image/avif/av1/util/floor_log2.d.ts.map +1 -0
  203. package/src/format/image/avif/av1/util/floor_log2.js +20 -0
  204. package/src/format/image/avif/av1/util/round2.d.ts.map +1 -0
  205. package/src/format/image/avif/av1/util/round2_signed.d.ts.map +1 -0
  206. package/src/format/image/avif/av1/util/tile_log2.d.ts.map +1 -0
  207. package/src/format/image/avif/bitstream/BitReader.d.ts.map +1 -0
  208. package/src/format/image/avif/bitstream/BitWriter.d.ts.map +1 -0
  209. package/src/format/image/avif/color/ColourTransform.d.ts.map +1 -0
  210. package/src/format/image/avif/color/YuvImage.d.ts.map +1 -0
  211. package/src/format/image/avif/color/clamp_sample.d.ts.map +1 -0
  212. package/src/format/image/avif/color/linear_to_transfer.d.ts.map +1 -0
  213. package/src/format/image/avif/color/linear_to_transfer.js +126 -0
  214. package/src/format/image/avif/color/primaries.d.ts.map +1 -0
  215. package/src/format/image/avif/color/rgb_row_to_ycbcr.d.ts.map +1 -0
  216. package/src/format/image/avif/color/transfer_to_linear.d.ts.map +1 -0
  217. package/src/format/image/avif/color/transfer_to_linear.js +171 -0
  218. package/src/format/image/avif/color/upsample_chroma_row.d.ts.map +1 -0
  219. package/src/format/image/avif/color/upsample_chroma_row.js +89 -0
  220. package/src/format/image/avif/color/ycbcr_row_to_rgb.d.ts.map +1 -0
  221. package/src/format/image/avif/color/ycbcr_row_to_rgb.js +78 -0
  222. package/src/format/image/avif/heif/AvifFile.d.ts.map +1 -0
  223. package/src/format/image/avif/heif/ItemProperty.d.ts.map +1 -0
  224. package/src/format/image/avif/heif/find_item_property.d.ts.map +1 -0
  225. package/src/format/image/avif/heif/find_item_references.d.ts.map +1 -0
  226. package/src/format/image/avif/heif/find_items_referencing.d.ts.map +1 -0
  227. package/src/format/image/avif/heif/parse_avif_file.d.ts.map +1 -0
  228. package/src/format/image/avif/heif/parse_avif_file.js +384 -0
  229. package/src/format/image/avif/heif/parse_image_grid.d.ts.map +1 -0
  230. package/src/format/image/avif/heif/parse_image_grid.js +49 -0
  231. package/src/format/image/avif/heif/parse_item_property.d.ts.map +1 -0
  232. package/src/format/image/avif/heif/read_item_data.d.ts.map +1 -0
  233. package/src/format/image/avif/heif/write_avif_file.d.ts.map +1 -0
  234. package/src/format/image/avif/heif/write_item_property.d.ts.map +1 -0
  235. package/src/format/image/avif/index.d.ts +12 -0
  236. package/src/format/image/avif/index.d.ts.map +1 -0
  237. package/src/format/image/avif/index.js +58 -0
  238. package/src/format/image/avif/isobmff/BoxHeader.d.ts.map +1 -0
  239. package/src/format/image/avif/isobmff/BoxWriter.d.ts +118 -0
  240. package/src/format/image/avif/isobmff/BoxWriter.d.ts.map +1 -0
  241. package/src/format/image/avif/isobmff/BoxWriter.js +264 -0
  242. package/src/format/image/avif/isobmff/for_each_box.d.ts.map +1 -0
  243. package/src/format/image/avif/isobmff/read_box_header.d.ts.map +1 -0
  244. package/src/format/image/avif/isobmff/read_full_box_header.d.ts.map +1 -0
  245. package/src/format/image/jpeg/JpegFrame.d.ts.map +1 -0
  246. package/src/format/image/jpeg/JpegFrameComponent.d.ts.map +1 -0
  247. package/src/format/image/jpeg/JpegImage.d.ts.map +1 -0
  248. package/src/format/image/jpeg/JpegImage.js +664 -0
  249. package/src/format/image/jpeg/buildComponentData.d.ts.map +1 -0
  250. package/src/format/image/jpeg/buildHuffmanTable.d.ts.map +1 -0
  251. package/src/format/image/jpeg/decodeScan.d.ts.map +1 -0
  252. package/src/format/image/jpeg/idct8x8_float.d.ts.map +1 -0
  253. package/src/format/image/jpeg/idct8x8_float.js +31 -0
  254. package/src/format/image/jpeg/jpeg_component_row.d.ts.map +1 -0
  255. package/src/format/image/jpeg/jpeg_decode.d.ts.map +1 -0
  256. package/src/format/image/png/PNG.d.ts.map +1 -0
  257. package/src/format/image/png/PNGReader.d.ts +158 -0
  258. package/src/format/image/png/PNGReader.d.ts.map +1 -0
  259. package/src/format/image/png/PNGReader.js +656 -0
  260. package/src/format/image/png/PNG_HEADER_BYTES.d.ts.map +1 -0
  261. package/src/format/image/png/chunk/png_chunk_decode_iTXt.d.ts.map +1 -0
  262. package/src/format/image/png/chunk/png_chunk_decode_iTXt.js +53 -0
  263. package/src/format/image/png/chunk/png_chunk_decode_zTXt.d.ts.map +1 -0
  264. package/src/format/image/png/chunk/png_chunk_decode_zTXt.js +42 -0
  265. package/src/format/image/png/crc32.d.ts +2 -0
  266. package/src/format/image/png/crc32.d.ts.map +1 -0
  267. package/src/format/image/png/crc32.js +8 -0
  268. package/src/format/image/png/filter/png_filter_unFilterAverage.d.ts.map +1 -0
  269. package/src/format/image/png/filter/png_filter_unFilterNone.d.ts.map +1 -0
  270. package/src/format/image/png/filter/png_filter_unFilterPaeth.d.ts.map +1 -0
  271. package/src/format/image/png/filter/png_filter_unFilterSub.d.ts.map +1 -0
  272. package/src/format/image/png/filter/png_filter_unFilterUp.d.ts.map +1 -0
  273. package/src/format/image/png/filter/png_unfilter.d.ts.map +1 -0
  274. package/src/format/image/png/filter/png_unfilter.js +68 -0
  275. package/src/format/image/png/png_inflate.d.ts.map +1 -0
  276. package/src/format/image/png/png_unpack_samples.d.ts.map +1 -0
  277. package/src/format/scene/gltf/GLTF_PRIMITIVE_MODE.d.ts.map +1 -0
  278. package/src/format/scene/gltf/MESHOPT_COMPRESSION_PLAN.md +793 -0
  279. package/src/format/scene/gltf/coalesce_array_duplicates.d.ts.map +1 -0
  280. package/src/format/scene/gltf/ext/GltfBufferViewExtension.d.ts.map +1 -0
  281. package/src/format/scene/gltf/ext/GltfBufferViewExtensionSet.d.ts.map +1 -0
  282. package/src/format/scene/gltf/ext/GltfBufferViewExtensionSet.js +109 -0
  283. package/src/format/scene/gltf/ext/gltf_apply_buffer_view_extensions.d.ts.map +1 -0
  284. package/src/format/scene/gltf/ext/gltf_buffer_view_extensions.d.ts.map +1 -0
  285. package/src/format/scene/gltf/ext/gltf_geometry_extensions.d.ts.map +1 -0
  286. package/src/format/scene/gltf/ext/meshopt/MeshoptBufferViewExtension.d.ts.map +1 -0
  287. package/src/format/scene/gltf/ext/meshopt/MeshoptBufferViewExtension.js +301 -0
  288. package/src/format/scene/gltf/gltf_component_type.d.ts.map +1 -0
  289. package/src/format/scene/gltf/gltf_node_world_matrices.d.ts.map +1 -0
  290. package/src/format/scene/gltf/gltf_node_world_matrices.js +137 -0
  291. package/src/format/scene/gltf/gltf_parse_container.d.ts.map +1 -0
  292. package/src/format/scene/gltf/gltf_read_accessor.d.ts.map +1 -0
  293. package/src/format/scene/gltf/gltf_read_accessor.js +294 -0
  294. package/src/format/scene/gltf/gltf_used_image_indices.d.ts +51 -0
  295. package/src/format/scene/gltf/gltf_used_image_indices.d.ts.map +1 -0
  296. package/src/format/scene/gltf/gltf_used_image_indices.js +122 -0
  297. package/src/format/scene/usd/UsdError.d.ts.map +1 -0
  298. package/src/format/scene/usd/parse_usda.d.ts.map +1 -0
  299. package/src/format/scene/usd/unpack_usdz.d.ts.map +1 -0
  300. package/src/format/scene/usd/unpack_usdz.js +106 -0
  301. package/src/format/scene/usd/usd_compose_transform.d.ts.map +1 -0
  302. package/src/format/scene/usd/usd_compose_transform.js +258 -0
  303. package/src/format/scene/usd/usd_lz4.d.ts.map +1 -0
  304. package/src/format/scene/usd/usd_lz4.js +182 -0
  305. package/src/format/scene/usd/usd_triangulate.d.ts.map +1 -0
  306. package/src/format/texture/TexelPayload.d.ts +55 -0
  307. package/src/format/texture/TexelPayload.d.ts.map +1 -0
  308. package/src/format/texture/TexelPayload.js +39 -0
  309. package/src/format/texture/basis/BasisBitReader.d.ts +77 -0
  310. package/src/format/texture/basis/BasisBitReader.d.ts.map +1 -0
  311. package/src/format/texture/basis/BasisBitReader.js +231 -0
  312. package/src/format/texture/basis/BasisHuffmanTable.d.ts +53 -0
  313. package/src/format/texture/basis/BasisHuffmanTable.d.ts.map +1 -0
  314. package/src/format/texture/basis/BasisHuffmanTable.js +263 -0
  315. package/src/format/texture/basis/astc_block.d.ts +92 -0
  316. package/src/format/texture/basis/astc_block.d.ts.map +1 -0
  317. package/src/format/texture/basis/astc_block.js +164 -0
  318. package/src/format/texture/basis/astc_integer_sequence.d.ts +59 -0
  319. package/src/format/texture/basis/astc_integer_sequence.d.ts.map +1 -0
  320. package/src/format/texture/basis/astc_integer_sequence.js +251 -0
  321. package/src/format/texture/basis/astc_partition.d.ts +56 -0
  322. package/src/format/texture/basis/astc_partition.d.ts.map +1 -0
  323. package/src/format/texture/basis/astc_partition.js +199 -0
  324. package/src/format/texture/basis/basis_read_huffman_table.d.ts +20 -0
  325. package/src/format/texture/basis/basis_read_huffman_table.d.ts.map +1 -0
  326. package/src/format/texture/basis/basis_read_huffman_table.js +187 -0
  327. package/src/format/texture/basis/etc1s/Etc1sSelectorHistory.d.ts +50 -0
  328. package/src/format/texture/basis/etc1s/Etc1sSelectorHistory.d.ts.map +1 -0
  329. package/src/format/texture/basis/etc1s/Etc1sSelectorHistory.js +89 -0
  330. package/src/format/texture/basis/etc1s/etc1s_block_colors.d.ts +14 -0
  331. package/src/format/texture/basis/etc1s/etc1s_block_colors.d.ts.map +1 -0
  332. package/src/format/texture/basis/etc1s/etc1s_block_colors.js +75 -0
  333. package/src/format/texture/basis/etc1s/etc1s_decode_slice.d.ts +57 -0
  334. package/src/format/texture/basis/etc1s/etc1s_decode_slice.d.ts.map +1 -0
  335. package/src/format/texture/basis/etc1s/etc1s_decode_slice.js +290 -0
  336. package/src/format/texture/basis/etc1s/etc1s_read_endpoint_codebook.d.ts +48 -0
  337. package/src/format/texture/basis/etc1s/etc1s_read_endpoint_codebook.d.ts.map +1 -0
  338. package/src/format/texture/basis/etc1s/etc1s_read_endpoint_codebook.js +111 -0
  339. package/src/format/texture/basis/etc1s/etc1s_read_selector_codebook.d.ts +42 -0
  340. package/src/format/texture/basis/etc1s/etc1s_read_selector_codebook.d.ts.map +1 -0
  341. package/src/format/texture/basis/etc1s/etc1s_read_selector_codebook.js +127 -0
  342. package/src/format/texture/basis/etc1s/etc1s_read_slice_tables.d.ts +54 -0
  343. package/src/format/texture/basis/etc1s/etc1s_read_slice_tables.d.ts.map +1 -0
  344. package/src/format/texture/basis/etc1s/etc1s_read_slice_tables.js +47 -0
  345. package/src/format/texture/basis/transcode/build_range_plan.d.ts +46 -0
  346. package/src/format/texture/basis/transcode/build_range_plan.d.ts.map +1 -0
  347. package/src/format/texture/basis/transcode/build_range_plan.js +54 -0
  348. package/src/format/texture/basis/transcode/etc1s_to_astc.d.ts +30 -0
  349. package/src/format/texture/basis/transcode/etc1s_to_astc.d.ts.map +1 -0
  350. package/src/format/texture/basis/transcode/etc1s_to_astc.js +328 -0
  351. package/src/format/texture/basis/transcode/etc1s_to_bc1.d.ts +34 -0
  352. package/src/format/texture/basis/transcode/etc1s_to_bc1.d.ts.map +1 -0
  353. package/src/format/texture/basis/transcode/etc1s_to_bc1.js +486 -0
  354. package/src/format/texture/basis/transcode/etc1s_to_bc7.d.ts +27 -0
  355. package/src/format/texture/basis/transcode/etc1s_to_bc7.d.ts.map +1 -0
  356. package/src/format/texture/basis/transcode/etc1s_to_bc7.js +496 -0
  357. package/src/format/texture/basis/transcode/etc1s_to_etc2.d.ts +31 -0
  358. package/src/format/texture/basis/transcode/etc1s_to_etc2.d.ts.map +1 -0
  359. package/src/format/texture/basis/transcode/etc1s_to_etc2.js +332 -0
  360. package/src/format/texture/basis/transcode/etc1s_to_rgba8.d.ts +39 -0
  361. package/src/format/texture/basis/transcode/etc1s_to_rgba8.d.ts.map +1 -0
  362. package/src/format/texture/basis/transcode/etc1s_to_rgba8.js +115 -0
  363. package/src/format/texture/basis/transcode/fit_endpoints.d.ts +79 -0
  364. package/src/format/texture/basis/transcode/fit_endpoints.d.ts.map +1 -0
  365. package/src/format/texture/basis/transcode/fit_endpoints.js +297 -0
  366. package/src/format/texture/basis/transcode_basis.d.ts +109 -0
  367. package/src/format/texture/basis/transcode_basis.d.ts.map +1 -0
  368. package/src/format/texture/basis/transcode_basis.js +250 -0
  369. package/src/format/texture/basis/transcode_uastc.d.ts +55 -0
  370. package/src/format/texture/basis/transcode_uastc.d.ts.map +1 -0
  371. package/src/format/texture/basis/transcode_uastc.js +117 -0
  372. package/src/format/texture/basis/uastc/bc7_tables.d.ts +111 -0
  373. package/src/format/texture/basis/uastc/bc7_tables.d.ts.map +1 -0
  374. package/src/format/texture/basis/uastc/bc7_tables.js +276 -0
  375. package/src/format/texture/basis/uastc/bc7_write_block.d.ts +124 -0
  376. package/src/format/texture/basis/uastc/bc7_write_block.d.ts.map +1 -0
  377. package/src/format/texture/basis/uastc/bc7_write_block.js +227 -0
  378. package/src/format/texture/basis/uastc/uastc_decode_block.d.ts +105 -0
  379. package/src/format/texture/basis/uastc/uastc_decode_block.d.ts.map +1 -0
  380. package/src/format/texture/basis/uastc/uastc_decode_block.js +480 -0
  381. package/src/format/texture/basis/uastc/uastc_tables.d.ts +240 -0
  382. package/src/format/texture/basis/uastc/uastc_tables.d.ts.map +1 -0
  383. package/src/format/texture/basis/uastc/uastc_tables.js +383 -0
  384. package/src/format/texture/basis/uastc/uastc_to_astc.d.ts +30 -0
  385. package/src/format/texture/basis/uastc/uastc_to_astc.d.ts.map +1 -0
  386. package/src/format/texture/basis/uastc/uastc_to_astc.js +421 -0
  387. package/src/format/texture/basis/uastc/uastc_to_bc5.d.ts +26 -0
  388. package/src/format/texture/basis/uastc/uastc_to_bc5.d.ts.map +1 -0
  389. package/src/format/texture/basis/uastc/uastc_to_bc5.js +115 -0
  390. package/src/format/texture/basis/uastc/uastc_to_bc7.d.ts +36 -0
  391. package/src/format/texture/basis/uastc/uastc_to_bc7.d.ts.map +1 -0
  392. package/src/format/texture/basis/uastc/uastc_to_bc7.js +602 -0
  393. package/src/format/texture/basis/uastc/uastc_to_rgba8.d.ts +37 -0
  394. package/src/format/texture/basis/uastc/uastc_to_rgba8.d.ts.map +1 -0
  395. package/src/format/texture/basis/uastc/uastc_to_rgba8.js +87 -0
  396. package/src/format/texture/bc/bc1_write_block.d.ts +28 -0
  397. package/src/format/texture/bc/bc1_write_block.d.ts.map +1 -0
  398. package/src/format/texture/bc/bc1_write_block.js +41 -0
  399. package/src/format/texture/bc/bc4_write_block.d.ts +32 -0
  400. package/src/format/texture/bc/bc4_write_block.d.ts.map +1 -0
  401. package/src/format/texture/bc/bc4_write_block.js +50 -0
  402. package/src/format/texture/bc/bc6h_write_block_mode11.d.ts +30 -0
  403. package/src/format/texture/bc/bc6h_write_block_mode11.d.ts.map +1 -0
  404. package/src/format/texture/bc/bc6h_write_block_mode11.js +62 -0
  405. package/src/format/texture/ktx2/KTX2_IDENTIFIER.d.ts +14 -0
  406. package/src/format/texture/ktx2/KTX2_IDENTIFIER.d.ts.map +1 -0
  407. package/src/format/texture/ktx2/KTX2_IDENTIFIER.js +15 -0
  408. package/src/format/texture/ktx2/KhrDfModel.d.ts +35 -0
  409. package/src/format/texture/ktx2/KhrDfModel.d.ts.map +1 -0
  410. package/src/format/texture/ktx2/KhrDfModel.js +49 -0
  411. package/src/format/texture/ktx2/SupercompressionScheme.d.ts +16 -0
  412. package/src/format/texture/ktx2/SupercompressionScheme.d.ts.map +1 -0
  413. package/src/format/texture/ktx2/SupercompressionScheme.js +23 -0
  414. package/src/format/texture/ktx2/ktx2_read.d.ts +105 -0
  415. package/src/format/texture/ktx2/ktx2_read.d.ts.map +1 -0
  416. package/src/format/texture/ktx2/ktx2_read.js +909 -0
  417. package/src/format/texture/ktx2/ktx2_read_basis_lz_global_data.d.ts +27 -0
  418. package/src/format/texture/ktx2/ktx2_read_basis_lz_global_data.d.ts.map +1 -0
  419. package/src/format/texture/ktx2/ktx2_read_basis_lz_global_data.js +189 -0
  420. package/src/format/texture/ktx2/vk_format_to_texture_format.d.ts +55 -0
  421. package/src/format/texture/ktx2/vk_format_to_texture_format.d.ts.map +1 -0
  422. package/src/format/texture/ktx2/vk_format_to_texture_format.js +290 -0
  423. package/src/shade/descriptor/GPUTextureUsage.d.ts +23 -0
  424. package/src/shade/descriptor/GPUTextureUsage.d.ts.map +1 -0
  425. package/src/shade/descriptor/GPUTextureUsage.js +24 -0
  426. package/src/shade/descriptor/WebGPUExtensionType.d.ts +3 -0
  427. package/src/shade/descriptor/WebGPUExtensionType.js +26 -0
  428. package/src/shade/descriptor/texture/TextureDescriptor.d.ts +2 -6
  429. package/src/shade/descriptor/texture/TextureDescriptor.d.ts.map +1 -1
  430. package/src/shade/descriptor/texture/TextureDescriptor.js +24 -40
  431. package/src/shade/descriptor/texture/format/TextureFormat.d.ts +125 -0
  432. package/src/shade/descriptor/texture/format/TextureFormat.d.ts.map +1 -0
  433. package/src/shade/descriptor/texture/format/TextureFormat.js +146 -0
  434. package/src/shade/descriptor/texture/format/gpu_texture_format_feature.d.ts +16 -0
  435. package/src/shade/descriptor/texture/format/gpu_texture_format_feature.d.ts.map +1 -0
  436. package/src/shade/descriptor/texture/format/gpu_texture_format_feature.js +44 -0
  437. package/src/shade/descriptor/texture/format/gpu_texture_format_info.d.ts +76 -0
  438. package/src/shade/descriptor/texture/format/gpu_texture_format_info.d.ts.map +1 -1
  439. package/src/shade/descriptor/texture/format/gpu_texture_format_info.js +126 -0
  440. package/src/shade/descriptor/texture/format/gpu_texture_format_srgb.d.ts +19 -0
  441. package/src/shade/descriptor/texture/format/gpu_texture_format_srgb.d.ts.map +1 -0
  442. package/src/shade/descriptor/texture/format/gpu_texture_format_srgb.js +50 -0
  443. package/src/shade/device/COPY_BYTES_PER_ROW_ALIGNMENT.d.ts +14 -0
  444. package/src/shade/device/COPY_BYTES_PER_ROW_ALIGNMENT.d.ts.map +1 -0
  445. package/src/shade/device/COPY_BYTES_PER_ROW_ALIGNMENT.js +13 -0
  446. package/src/shade/device/graph/TextureResourceDescriptor.d.ts.map +1 -1
  447. package/src/shade/device/graph/TextureResourceDescriptor.js +160 -155
  448. package/src/shade/device/mock/SoftwareGPUDevice.d.ts.map +1 -1
  449. package/src/shade/device/mock/SoftwareGPUDevice.js +37 -3
  450. package/src/shade/device/mock/SoftwareGPUQueue.d.ts +11 -4
  451. package/src/shade/device/mock/SoftwareGPUQueue.d.ts.map +1 -1
  452. package/src/shade/device/mock/SoftwareGPUQueue.js +31 -37
  453. package/src/shade/device/mock/SoftwareGPUTexture.d.ts +4 -2
  454. package/src/shade/device/mock/SoftwareGPUTexture.d.ts.map +1 -1
  455. package/src/shade/device/mock/SoftwareGPUTexture.js +47 -7
  456. package/src/shade/device/mock/SoftwareGPUTextureView.d.ts +7 -0
  457. package/src/shade/device/mock/SoftwareGPUTextureView.d.ts.map +1 -1
  458. package/src/shade/device/mock/SoftwareGPUTextureView.js +8 -0
  459. package/src/shade/device/mock/texture_copy.d.ts.map +1 -1
  460. package/src/shade/device/mock/texture_copy.js +74 -12
  461. package/src/shade/device/timing/profile/frame_graph_extract_topology.d.ts.map +1 -1
  462. package/src/shade/device/timing/profile/frame_graph_extract_topology.js +164 -174
  463. package/src/shade/playground/basis_textures/README.md +105 -0
  464. package/src/shade/playground/basis_textures/index.html +141 -0
  465. package/src/shade/playground/basis_textures/main.d.ts +8 -0
  466. package/src/shade/playground/basis_textures/main.d.ts.map +1 -0
  467. package/src/shade/playground/basis_textures/main.js +351 -0
  468. package/src/shade/playground/basis_textures/make_basis_gltf.d.mts +2 -0
  469. package/src/shade/playground/basis_textures/make_basis_gltf.d.mts.map +1 -0
  470. package/src/shade/playground/basis_textures/make_basis_gltf.mjs +197 -0
  471. package/src/shade/playground/basis_textures/node_modules/basis_universal/bin/basisu.exe +0 -0
  472. package/src/shade/playground/basis_textures/texture_inventory.d.ts +28 -0
  473. package/src/shade/playground/basis_textures/texture_inventory.d.ts.map +1 -0
  474. package/src/shade/playground/basis_textures/texture_inventory.js +98 -0
  475. package/src/shade/playground/ground_seam/README.md +235 -0
  476. package/src/shade/playground/ground_seam/capture_scene_color.d.ts +45 -0
  477. package/src/shade/playground/ground_seam/capture_scene_color.d.ts.map +1 -0
  478. package/src/shade/playground/ground_seam/capture_scene_color.js +242 -0
  479. package/src/shade/playground/ground_seam/depth_step_across_seam.d.ts +11 -0
  480. package/src/shade/playground/ground_seam/depth_step_across_seam.d.ts.map +1 -0
  481. package/src/shade/playground/ground_seam/depth_step_across_seam.js +185 -0
  482. package/src/shade/playground/ground_seam/index.html +195 -0
  483. package/src/shade/playground/ground_seam/main.d.ts +2 -0
  484. package/src/shade/playground/ground_seam/main.d.ts.map +1 -0
  485. package/src/shade/playground/ground_seam/main.js +879 -0
  486. package/src/shade/playground/ground_seam/make_grid_texture.d.ts +29 -0
  487. package/src/shade/playground/ground_seam/make_grid_texture.d.ts.map +1 -0
  488. package/src/shade/playground/ground_seam/make_grid_texture.js +105 -0
  489. package/src/shade/playground/ground_seam/make_ground.d.ts +70 -0
  490. package/src/shade/playground/ground_seam/make_ground.d.ts.map +1 -0
  491. package/src/shade/playground/ground_seam/make_ground.js +161 -0
  492. package/src/shade/playground/ground_seam/measure_flicker.d.ts +71 -0
  493. package/src/shade/playground/ground_seam/measure_flicker.d.ts.map +1 -0
  494. package/src/shade/playground/ground_seam/measure_flicker.js +531 -0
  495. package/src/shade/playground/image_decode_bench/README.md +42 -0
  496. package/src/shade/playground/image_decode_bench/decode_worker.d.ts +2 -0
  497. package/src/shade/playground/image_decode_bench/decode_worker.d.ts.map +1 -0
  498. package/src/shade/playground/image_decode_bench/decode_worker.js +19 -0
  499. package/src/shade/playground/image_decode_bench/index.html +34 -0
  500. package/src/shade/playground/image_decode_bench/main.d.ts +2 -0
  501. package/src/shade/playground/image_decode_bench/main.d.ts.map +1 -0
  502. package/src/shade/playground/image_decode_bench/main.js +211 -0
  503. package/src/shade/playground/skinned_blas_refit/README.md +1 -1
  504. package/src/shade/playground/skinned_blas_refit/index.html +15 -1
  505. package/src/shade/playground/skinned_blas_refit/main.d.ts.map +1 -1
  506. package/src/shade/playground/skinned_blas_refit/main.js +339 -3
  507. package/src/shade/playground/skinned_blas_refit/shader_blas_audit_leaf_triangles.d.ts +8 -1
  508. package/src/shade/playground/skinned_blas_refit/shader_blas_audit_leaf_triangles.d.ts.map +1 -1
  509. package/src/shade/playground/skinned_blas_refit/shader_blas_audit_leaf_triangles.js +27 -5
  510. package/src/shade/playground/skinned_blas_refit/verify_clone_leaves.d.ts +27 -0
  511. package/src/shade/playground/skinned_blas_refit/verify_clone_leaves.d.ts.map +1 -0
  512. package/src/shade/playground/skinned_blas_refit/verify_clone_leaves.js +127 -0
  513. package/src/shade/playground/skinned_blas_refit/verify_leaf_triangles.d.ts.map +1 -1
  514. package/src/shade/playground/skinned_blas_refit/verify_leaf_triangles.js +3 -3
  515. package/src/shade/playground/skinned_blas_refit/verify_skinned_blas_refit.d.ts.map +1 -1
  516. package/src/shade/playground/skinned_blas_refit/verify_skinned_blas_refit.js +10 -8
  517. package/src/shade/playground/texture_encode/README.md +109 -0
  518. package/src/shade/playground/texture_encode/index.html +133 -0
  519. package/src/shade/playground/texture_encode/main.d.ts +24 -0
  520. package/src/shade/playground/texture_encode/main.d.ts.map +1 -0
  521. package/src/shade/playground/texture_encode/main.js +1430 -0
  522. package/src/shade/playground/texture_encode/panel_view.d.ts +118 -0
  523. package/src/shade/playground/texture_encode/panel_view.d.ts.map +1 -0
  524. package/src/shade/playground/texture_encode/panel_view.js +363 -0
  525. package/src/shade/renderer/Renderer.d.ts.map +1 -1
  526. package/src/shade/renderer/Renderer.js +2519 -2511
  527. package/src/shade/renderer/animation/GPUAnimationManager.d.ts.map +1 -1
  528. package/src/shade/renderer/animation/GPUAnimationManager.js +49 -5
  529. package/src/shade/renderer/animation/skinning/GPUMeshSkinningContext.d.ts.map +1 -1
  530. package/src/shade/renderer/animation/skinning/GPUMeshSkinningContext.js +32 -14
  531. package/src/shade/renderer/geometry/GPUGeometryManager.d.ts.map +1 -1
  532. package/src/shade/renderer/geometry/GPUGeometryManager.js +591 -497
  533. package/src/shade/renderer/geometry/GPUGeometryMetadata.d.ts +9 -0
  534. package/src/shade/renderer/geometry/GPUGeometryMetadata.d.ts.map +1 -1
  535. package/src/shade/renderer/geometry/GPUGeometryMetadata.js +10 -0
  536. package/src/shade/renderer/geometry/bvh/BLAS_REFIT_BATCH_PLAN.md +606 -0
  537. package/src/shade/renderer/geometry/bvh/BLAS_REFIT_TARGET_STRUCT.d.ts +17 -0
  538. package/src/shade/renderer/geometry/bvh/BLAS_REFIT_TARGET_STRUCT.d.ts.map +1 -0
  539. package/src/shade/renderer/geometry/bvh/BLAS_REFIT_TARGET_STRUCT.js +44 -0
  540. package/src/shade/renderer/geometry/bvh/GPUBLASRefitBatch.d.ts +58 -0
  541. package/src/shade/renderer/geometry/bvh/GPUBLASRefitBatch.d.ts.map +1 -0
  542. package/src/shade/renderer/geometry/bvh/GPUBLASRefitBatch.js +362 -0
  543. package/src/shade/renderer/geometry/bvh/GPUGeometryBVHManager.d.ts +38 -0
  544. package/src/shade/renderer/geometry/bvh/GPUGeometryBVHManager.d.ts.map +1 -1
  545. package/src/shade/renderer/geometry/bvh/GPUGeometryBVHManager.js +730 -617
  546. package/src/shade/renderer/geometry/bvh/GPUGeometryMeshletsBVH.d.ts +15 -2
  547. package/src/shade/renderer/geometry/bvh/GPUGeometryMeshletsBVH.d.ts.map +1 -1
  548. package/src/shade/renderer/geometry/bvh/GPUGeometryMeshletsBVH.js +15 -1
  549. package/src/shade/renderer/geometry/bvh/shader_blas_refit_batch.d.ts +39 -0
  550. package/src/shade/renderer/geometry/bvh/shader_blas_refit_batch.d.ts.map +1 -0
  551. package/src/shade/renderer/geometry/bvh/shader_blas_refit_batch.js +134 -0
  552. package/src/shade/renderer/geometry/virtual/build/gltf/gltf_collect_geometries.js +3 -3
  553. package/src/shade/renderer/geometry/virtual/build/gltf/gltf_open_document.js +3 -3
  554. package/src/shade/renderer/geometry/virtual/build/gltf/gltf_read_geometry.js +1 -1
  555. package/src/shade/renderer/gpu_primitive/bvh/BVH_NODE_LAYOUT_DEFINITION.d.ts +17 -0
  556. package/src/shade/renderer/gpu_primitive/bvh/BVH_NODE_LAYOUT_DEFINITION.d.ts.map +1 -0
  557. package/src/shade/renderer/gpu_primitive/bvh/BVH_NODE_LAYOUT_DEFINITION.js +30 -0
  558. package/src/shade/renderer/gpu_primitive/bvh/GPU_BVH_BUILD_PLAN.md +8 -1
  559. package/src/shade/renderer/gpu_primitive/bvh/chunk_bvh_refit_climb.d.ts +34 -0
  560. package/src/shade/renderer/gpu_primitive/bvh/chunk_bvh_refit_climb.d.ts.map +1 -0
  561. package/src/shade/renderer/gpu_primitive/bvh/chunk_bvh_refit_climb.js +102 -0
  562. package/src/shade/renderer/gpu_primitive/bvh/shader_bvh_refit.d.ts +11 -9
  563. package/src/shade/renderer/gpu_primitive/bvh/shader_bvh_refit.d.ts.map +1 -1
  564. package/src/shade/renderer/gpu_primitive/bvh/shader_bvh_refit.js +24 -86
  565. package/src/shade/renderer/hiz/HierarchicalZBuffer.d.ts.map +1 -1
  566. package/src/shade/renderer/hiz/HierarchicalZBuffer.js +275 -274
  567. package/src/shade/renderer/light/GPULightCollection.d.ts.map +1 -1
  568. package/src/shade/renderer/light/GPULightCollection.js +323 -314
  569. package/src/shade/renderer/lightmap/GPULightMap.js +336 -336
  570. package/src/shade/renderer/loader/gltf/gltf_create_texture.d.ts +18 -0
  571. package/src/shade/renderer/loader/gltf/gltf_create_texture.d.ts.map +1 -0
  572. package/src/shade/renderer/loader/gltf/gltf_create_texture.js +103 -0
  573. package/src/shade/renderer/loader/gltf/gltf_image_roles.d.ts +26 -0
  574. package/src/shade/renderer/loader/gltf/gltf_image_roles.d.ts.map +1 -0
  575. package/src/shade/renderer/loader/gltf/gltf_image_roles.js +108 -0
  576. package/src/shade/renderer/loader/gltf/load_gltf.d.ts +10 -3
  577. package/src/shade/renderer/loader/gltf/load_gltf.d.ts.map +1 -1
  578. package/src/shade/renderer/loader/gltf/load_gltf.js +1179 -1253
  579. package/src/shade/renderer/loader/gltf/tiny-gltf.d.ts +18 -1
  580. package/src/shade/renderer/loader/gltf/tiny-gltf.d.ts.map +1 -1
  581. package/src/shade/renderer/loader/gltf/tiny-gltf.js +837 -646
  582. package/src/shade/renderer/loader/usd/load_usd.js +3 -3
  583. package/src/shade/renderer/loader/usd/usd_build_scene.js +2 -2
  584. package/src/shade/renderer/loader/usd/usd_decode_image.d.ts +6 -5
  585. package/src/shade/renderer/loader/usd/usd_decode_image.d.ts.map +1 -1
  586. package/src/shade/renderer/loader/usd/usd_decode_image.js +197 -384
  587. package/src/shade/renderer/material/resident/GPUResidentMaterialContext.d.ts.map +1 -1
  588. package/src/shade/renderer/material/resident/GPUResidentMaterialContext.js +12 -2
  589. package/src/shade/renderer/material/standard/fragment_gbuffer.d.ts.map +1 -1
  590. package/src/shade/renderer/material/standard/fragment_gbuffer.js +3 -1
  591. package/src/shade/renderer/material/standard/fragment_gbuffer_vt.js +169 -169
  592. package/src/shade/renderer/path_tracer/shader/chunk_sample_material_data.d.ts.map +1 -1
  593. package/src/shade/renderer/path_tracer/shader/chunk_sample_material_data.js +3 -1
  594. package/src/shade/renderer/postprocess/nss/NSS.d.ts +1 -1
  595. package/src/shade/renderer/postprocess/taa/TAA.d.ts +3 -3
  596. package/src/shade/renderer/postprocess/taa/TAA.d.ts.map +1 -1
  597. package/src/shade/renderer/postprocess/taa/TAA.js +2 -6
  598. package/src/shade/renderer/postprocess/taa/chunk_depth_clip_offset_codec.d.ts +18 -0
  599. package/src/shade/renderer/postprocess/taa/chunk_depth_clip_offset_codec.d.ts.map +1 -0
  600. package/src/shade/renderer/postprocess/taa/chunk_depth_clip_offset_codec.js +36 -0
  601. package/src/shade/renderer/postprocess/taa/chunk_taa_history_color_bounding_box_YCoCg.d.ts.map +1 -1
  602. package/src/shade/renderer/postprocess/taa/chunk_taa_history_color_bounding_box_YCoCg.js +4 -1
  603. package/src/shade/renderer/postprocess/taa/shader_depth_occlusion_clip.d.ts.map +1 -1
  604. package/src/shade/renderer/postprocess/taa/shader_depth_occlusion_clip.js +13 -8
  605. package/src/shade/renderer/postprocess/taa/shader_taa.d.ts +1 -1
  606. package/src/shade/renderer/postprocess/taa/shader_taa.d.ts.map +1 -1
  607. package/src/shade/renderer/postprocess/taa/shader_taa.js +52 -38
  608. package/src/shade/renderer/rasterize/native/oit/chunk_forward_shade_standard_fragment_brick4.d.ts.map +1 -1
  609. package/src/shade/renderer/rasterize/native/oit/chunk_forward_shade_standard_fragment_brick4.js +3 -1
  610. package/src/shade/renderer/rasterize/native/oit/chunk_forward_shade_standard_fragment_ibl.d.ts.map +1 -1
  611. package/src/shade/renderer/rasterize/native/oit/chunk_forward_shade_standard_fragment_ibl.js +3 -1
  612. package/src/shade/renderer/restir/di/chunk_restir_temporal_reuse.d.ts +4 -2
  613. package/src/shade/renderer/restir/di/chunk_restir_temporal_reuse.d.ts.map +1 -1
  614. package/src/shade/renderer/restir/di/chunk_restir_temporal_reuse.js +9 -6
  615. package/src/shade/renderer/scene/optimization/deduplicate_images.js +93 -93
  616. package/src/shade/renderer/scene/optimization/downscale_images.js +216 -216
  617. package/src/shade/renderer/scene/serialization/decode_image_source_hdr.js +1 -1
  618. package/src/shade/renderer/scene/serialization/deserialize_scene.js +1 -1
  619. package/src/shade/renderer/scene/serialization/write_image_source.js +1 -1
  620. package/src/shade/renderer/shader/chunk/color/iCtCp/chunk_eotf_st2084.d.ts +1 -1
  621. package/src/shade/renderer/shader/chunk/color/iCtCp/chunk_eotf_st2084.js +1 -1
  622. package/src/shade/renderer/shader/chunk/geometry/normal/chunk_decode_tangent_normal.d.ts +28 -0
  623. package/src/shade/renderer/shader/chunk/geometry/normal/chunk_decode_tangent_normal.d.ts.map +1 -0
  624. package/src/shade/renderer/shader/chunk/geometry/normal/chunk_decode_tangent_normal.js +39 -0
  625. package/src/shade/renderer/shader/chunk/geometry/triangle/chunk_barycentric_full.d.ts +45 -0
  626. package/src/shade/renderer/shader/chunk/geometry/triangle/chunk_barycentric_full.d.ts.map +1 -1
  627. package/src/shade/renderer/shader/chunk/geometry/triangle/chunk_barycentric_full.js +94 -61
  628. package/src/shade/renderer/shader/chunk/geometry/triangle/chunk_barycentric_solve.d.ts +24 -0
  629. package/src/shade/renderer/shader/chunk/geometry/triangle/chunk_barycentric_solve.d.ts.map +1 -0
  630. package/src/shade/renderer/shader/chunk/geometry/triangle/chunk_barycentric_solve.js +43 -0
  631. package/src/shade/renderer/shader/chunk/texture/sample/chunk_texture_sample_catmullrom_hardware_5tap_uv.d.ts +2 -1
  632. package/src/shade/renderer/shader/chunk/texture/sample/chunk_texture_sample_catmullrom_hardware_5tap_uv.d.ts.map +1 -1
  633. package/src/shade/renderer/shader/chunk/texture/sample/chunk_texture_sample_catmullrom_hardware_5tap_uv.js +2 -1
  634. package/src/shade/renderer/texture/COMPRESSED_TEXTURE_PLAN_2026_09_01.md +2345 -0
  635. package/src/shade/renderer/texture/TextureManager.d.ts.map +1 -1
  636. package/src/shade/renderer/texture/TextureManager.js +20 -8
  637. package/src/shade/renderer/texture/TextureRole.d.ts +19 -0
  638. package/src/shade/renderer/texture/TextureRole.d.ts.map +1 -0
  639. package/src/shade/renderer/texture/TextureRole.js +26 -0
  640. package/src/shade/renderer/texture/TextureVariantSet.d.ts +71 -0
  641. package/src/shade/renderer/texture/TextureVariantSet.d.ts.map +1 -0
  642. package/src/shade/renderer/texture/TextureVariantSet.js +105 -0
  643. package/src/shade/renderer/texture/download_texture_data.d.ts.map +1 -1
  644. package/src/shade/renderer/texture/download_texture_data.js +22 -0
  645. package/src/shade/renderer/texture/encode/ENCODE_NOTES_2026_09_02.md +462 -0
  646. package/src/shade/renderer/texture/encode/chunk_astc_encode_block_4x4_rgb.d.ts +33 -0
  647. package/src/shade/renderer/texture/encode/chunk_astc_encode_block_4x4_rgb.d.ts.map +1 -0
  648. package/src/shade/renderer/texture/encode/chunk_astc_encode_block_4x4_rgb.js +310 -0
  649. package/src/shade/renderer/texture/encode/chunk_astc_pack_4x4_rgb.d.ts +17 -0
  650. package/src/shade/renderer/texture/encode/chunk_astc_pack_4x4_rgb.d.ts.map +1 -0
  651. package/src/shade/renderer/texture/encode/chunk_astc_pack_4x4_rgb.js +51 -0
  652. package/src/shade/renderer/texture/encode/chunk_bc1_encode_block.d.ts +42 -0
  653. package/src/shade/renderer/texture/encode/chunk_bc1_encode_block.d.ts.map +1 -0
  654. package/src/shade/renderer/texture/encode/chunk_bc1_encode_block.js +375 -0
  655. package/src/shade/renderer/texture/encode/chunk_bc1_pack_block.d.ts +12 -0
  656. package/src/shade/renderer/texture/encode/chunk_bc1_pack_block.d.ts.map +1 -0
  657. package/src/shade/renderer/texture/encode/chunk_bc1_pack_block.js +24 -0
  658. package/src/shade/renderer/texture/encode/chunk_bc4_encode_block.d.ts +45 -0
  659. package/src/shade/renderer/texture/encode/chunk_bc4_encode_block.d.ts.map +1 -0
  660. package/src/shade/renderer/texture/encode/chunk_bc4_encode_block.js +348 -0
  661. package/src/shade/renderer/texture/encode/chunk_bc4_pack_block.d.ts +16 -0
  662. package/src/shade/renderer/texture/encode/chunk_bc4_pack_block.d.ts.map +1 -0
  663. package/src/shade/renderer/texture/encode/chunk_bc4_pack_block.js +33 -0
  664. package/src/shade/renderer/texture/encode/chunk_bc6h_encode_block_mode11.d.ts +32 -0
  665. package/src/shade/renderer/texture/encode/chunk_bc6h_encode_block_mode11.d.ts.map +1 -0
  666. package/src/shade/renderer/texture/encode/chunk_bc6h_encode_block_mode11.js +346 -0
  667. package/src/shade/renderer/texture/encode/chunk_bc6h_pack_mode11.d.ts +10 -0
  668. package/src/shade/renderer/texture/encode/chunk_bc6h_pack_mode11.d.ts.map +1 -0
  669. package/src/shade/renderer/texture/encode/chunk_bc6h_pack_mode11.js +54 -0
  670. package/src/shade/renderer/texture/encode/chunk_bc7_encode_block_mode6.d.ts +36 -0
  671. package/src/shade/renderer/texture/encode/chunk_bc7_encode_block_mode6.d.ts.map +1 -0
  672. package/src/shade/renderer/texture/encode/chunk_bc7_encode_block_mode6.js +327 -0
  673. package/src/shade/renderer/texture/encode/chunk_bc7_pack_mode6.d.ts +22 -0
  674. package/src/shade/renderer/texture/encode/chunk_bc7_pack_mode6.d.ts.map +1 -0
  675. package/src/shade/renderer/texture/encode/chunk_bc7_pack_mode6.js +71 -0
  676. package/src/shade/renderer/texture/encode/chunk_texture_encode_level.d.ts +20 -0
  677. package/src/shade/renderer/texture/encode/chunk_texture_encode_level.d.ts.map +1 -0
  678. package/src/shade/renderer/texture/encode/chunk_texture_encode_level.js +73 -0
  679. package/src/shade/renderer/texture/encode/chunk_texture_encode_load_block.d.ts +16 -0
  680. package/src/shade/renderer/texture/encode/chunk_texture_encode_load_block.d.ts.map +1 -0
  681. package/src/shade/renderer/texture/encode/chunk_texture_encode_load_block.js +36 -0
  682. package/src/shade/renderer/texture/encode/shader_texture_encode_astc_4x4.d.ts +13 -0
  683. package/src/shade/renderer/texture/encode/shader_texture_encode_astc_4x4.d.ts.map +1 -0
  684. package/src/shade/renderer/texture/encode/shader_texture_encode_astc_4x4.js +63 -0
  685. package/src/shade/renderer/texture/encode/shader_texture_encode_bc1.d.ts +12 -0
  686. package/src/shade/renderer/texture/encode/shader_texture_encode_bc1.d.ts.map +1 -0
  687. package/src/shade/renderer/texture/encode/shader_texture_encode_bc1.js +60 -0
  688. package/src/shade/renderer/texture/encode/shader_texture_encode_bc4.d.ts +28 -0
  689. package/src/shade/renderer/texture/encode/shader_texture_encode_bc4.d.ts.map +1 -0
  690. package/src/shade/renderer/texture/encode/shader_texture_encode_bc4.js +76 -0
  691. package/src/shade/renderer/texture/encode/shader_texture_encode_bc4_snorm.d.ts +16 -0
  692. package/src/shade/renderer/texture/encode/shader_texture_encode_bc4_snorm.d.ts.map +1 -0
  693. package/src/shade/renderer/texture/encode/shader_texture_encode_bc4_snorm.js +64 -0
  694. package/src/shade/renderer/texture/encode/shader_texture_encode_bc5.d.ts +14 -0
  695. package/src/shade/renderer/texture/encode/shader_texture_encode_bc5.d.ts.map +1 -0
  696. package/src/shade/renderer/texture/encode/shader_texture_encode_bc5.js +67 -0
  697. package/src/shade/renderer/texture/encode/shader_texture_encode_bc5_snorm.d.ts +10 -0
  698. package/src/shade/renderer/texture/encode/shader_texture_encode_bc5_snorm.d.ts.map +1 -0
  699. package/src/shade/renderer/texture/encode/shader_texture_encode_bc5_snorm.js +63 -0
  700. package/src/shade/renderer/texture/encode/shader_texture_encode_bc6h.d.ts +12 -0
  701. package/src/shade/renderer/texture/encode/shader_texture_encode_bc6h.d.ts.map +1 -0
  702. package/src/shade/renderer/texture/encode/shader_texture_encode_bc6h.js +62 -0
  703. package/src/shade/renderer/texture/encode/shader_texture_encode_bc7.d.ts +14 -0
  704. package/src/shade/renderer/texture/encode/shader_texture_encode_bc7.d.ts.map +1 -0
  705. package/src/shade/renderer/texture/encode/shader_texture_encode_bc7.js +58 -0
  706. package/src/shade/renderer/texture/encode/texture_encode.d.ts +84 -0
  707. package/src/shade/renderer/texture/encode/texture_encode.d.ts.map +1 -0
  708. package/src/shade/renderer/texture/encode/texture_encode.js +168 -0
  709. package/src/shade/renderer/texture/encode/texture_encode_layout.d.ts +196 -0
  710. package/src/shade/renderer/texture/encode/texture_encode_layout.d.ts.map +1 -0
  711. package/src/shade/renderer/texture/encode/texture_encode_layout.js +248 -0
  712. package/src/shade/renderer/texture/encode/texture_encode_resources.d.ts +15 -0
  713. package/src/shade/renderer/texture/encode/texture_encode_resources.d.ts.map +1 -0
  714. package/src/shade/renderer/texture/encode/texture_encode_resources.js +25 -0
  715. package/src/shade/renderer/texture/encode/texture_encode_shader.d.ts +30 -0
  716. package/src/shade/renderer/texture/encode/texture_encode_shader.d.ts.map +1 -0
  717. package/src/shade/renderer/texture/encode/texture_encode_shader.js +108 -0
  718. package/src/shade/renderer/texture/format/gpu_texture_compression_support.d.ts +17 -0
  719. package/src/shade/renderer/texture/format/gpu_texture_compression_support.d.ts.map +1 -0
  720. package/src/shade/renderer/texture/format/gpu_texture_compression_support.js +33 -0
  721. package/src/shade/renderer/texture/format/gpu_texture_format_can_generate_mipmaps.d.ts +27 -0
  722. package/src/shade/renderer/texture/format/gpu_texture_format_can_generate_mipmaps.d.ts.map +1 -0
  723. package/src/shade/renderer/texture/format/gpu_texture_format_can_generate_mipmaps.js +65 -0
  724. package/src/shade/renderer/texture/format/infer_format_from_parameters.d.ts +11 -0
  725. package/src/shade/renderer/texture/format/infer_format_from_parameters.d.ts.map +1 -0
  726. package/src/shade/renderer/texture/format/infer_format_from_parameters.js +88 -0
  727. package/src/shade/renderer/texture/format/texture_format_from_shade_image.d.ts +24 -0
  728. package/src/shade/renderer/texture/format/texture_format_from_shade_image.d.ts.map +1 -0
  729. package/src/shade/renderer/texture/format/texture_format_from_shade_image.js +95 -0
  730. package/src/shade/renderer/texture/format/texture_format_preference.d.ts +22 -0
  731. package/src/shade/renderer/texture/format/texture_format_preference.d.ts.map +1 -0
  732. package/src/shade/renderer/texture/format/texture_format_preference.js +89 -0
  733. package/src/shade/renderer/texture/format/texture_variant_select.d.ts +24 -0
  734. package/src/shade/renderer/texture/format/texture_variant_select.d.ts.map +1 -0
  735. package/src/shade/renderer/texture/format/texture_variant_select.js +38 -0
  736. package/src/shade/renderer/texture/shade_texture_might_have_alpha.d.ts +9 -1
  737. package/src/shade/renderer/texture/shade_texture_might_have_alpha.d.ts.map +1 -1
  738. package/src/shade/renderer/texture/shade_texture_might_have_alpha.js +73 -8
  739. package/src/shade/renderer/texture/source/AlphaMode.d.ts +27 -0
  740. package/src/shade/renderer/texture/source/AlphaMode.d.ts.map +1 -0
  741. package/src/shade/renderer/texture/source/AlphaMode.js +52 -0
  742. package/src/shade/renderer/texture/source/ShadeImage.d.ts +33 -0
  743. package/src/shade/renderer/texture/source/ShadeImage.d.ts.map +1 -1
  744. package/src/shade/renderer/texture/source/ShadeImage.js +74 -0
  745. package/src/shade/renderer/texture/source/ShadeTexelData.d.ts +78 -0
  746. package/src/shade/renderer/texture/source/ShadeTexelData.d.ts.map +1 -0
  747. package/src/shade/renderer/texture/source/ShadeTexelData.js +158 -0
  748. package/src/shade/renderer/texture/source/texel_data_from_ktx2.d.ts +32 -0
  749. package/src/shade/renderer/texture/source/texel_data_from_ktx2.d.ts.map +1 -0
  750. package/src/shade/renderer/texture/source/texel_data_from_ktx2.js +48 -0
  751. package/src/shade/renderer/texture/texture_descriptor_from_texture_shade.d.ts +0 -10
  752. package/src/shade/renderer/texture/texture_descriptor_from_texture_shade.d.ts.map +1 -1
  753. package/src/shade/renderer/texture/texture_descriptor_from_texture_shade.js +73 -175
  754. package/src/shade/renderer/texture/texture_write_level.d.ts +32 -0
  755. package/src/shade/renderer/texture/texture_write_level.d.ts.map +1 -0
  756. package/src/shade/renderer/texture/texture_write_level.js +87 -0
  757. package/src/shade/renderer/texture/texture_write_to_gpu.d.ts +8 -1
  758. package/src/shade/renderer/texture/texture_write_to_gpu.d.ts.map +1 -1
  759. package/src/shade/renderer/texture/texture_write_to_gpu.js +62 -37
  760. package/src/shade/renderer/texture/virtual/source/VTSourceImage.d.ts +8 -0
  761. package/src/shade/renderer/texture/virtual/source/VTSourceImage.d.ts.map +1 -1
  762. package/src/shade/renderer/texture/virtual/source/VTSourceImage.js +8 -0
  763. package/src/shade/renderer/volumetrics/GPUViewVolumetrics.d.ts.map +1 -1
  764. package/src/shade/renderer/volumetrics/GPUViewVolumetrics.js +20 -0
  765. package/src/shade/renderer/volumetrics/NOTES.md +28 -0
  766. package/src/shade/renderer/volumetrics/taa/chunk_volumetric_history_bounding_box.d.ts.map +1 -1
  767. package/src/shade/renderer/volumetrics/taa/chunk_volumetric_history_bounding_box.js +7 -2
  768. package/src/shade/renderer/volumetrics/taa/chunk_volumetrics_taa_reproject.d.ts +17 -0
  769. package/src/shade/renderer/volumetrics/taa/chunk_volumetrics_taa_reproject.d.ts.map +1 -0
  770. package/src/shade/renderer/volumetrics/taa/chunk_volumetrics_taa_reproject.js +168 -0
  771. package/src/shade/renderer/volumetrics/taa/chunk_volumetrics_taa_resolve.d.ts +13 -0
  772. package/src/shade/renderer/volumetrics/taa/chunk_volumetrics_taa_resolve.d.ts.map +1 -0
  773. package/src/shade/renderer/volumetrics/taa/chunk_volumetrics_taa_resolve.js +56 -0
  774. package/src/shade/renderer/volumetrics/taa/shader_volumetrics_taa.d.ts.map +1 -1
  775. package/src/shade/renderer/volumetrics/taa/shader_volumetrics_taa.js +134 -334
  776. package/src/shade/util/texture_mip_extent.d.ts +49 -0
  777. package/src/shade/util/texture_mip_extent.d.ts.map +1 -0
  778. package/src/shade/util/texture_mip_extent.js +87 -0
  779. package/src/shade/wgsl/emulator/WGSLJavaScriptCompiler.d.ts.map +1 -1
  780. package/src/shade/wgsl/emulator/WGSLJavaScriptCompiler.js +49 -21
  781. package/src/avif/encode_image_source.d.ts +0 -70
  782. package/src/avif/encode_image_source.d.ts.map +0 -1
  783. package/src/avif/encode_image_source.js +0 -117
  784. package/src/avif/encoder_worker.d.ts.map +0 -1
  785. package/src/avif/index.d.ts +0 -5
  786. package/src/avif/index.d.ts.map +0 -1
  787. package/src/avif/index.js +0 -21
  788. package/src/avif/native/DECISIONS.md +0 -537
  789. package/src/avif/native/api/AvifDecoder.d.ts.map +0 -1
  790. package/src/avif/native/api/apply_transformations.d.ts.map +0 -1
  791. package/src/avif/native/api/avif_to_sampler2d.d.ts +0 -25
  792. package/src/avif/native/api/avif_to_sampler2d.d.ts.map +0 -1
  793. package/src/avif/native/api/avif_to_sampler2d.js +0 -42
  794. package/src/avif/native/api/convert_to_rgba.d.ts.map +0 -1
  795. package/src/avif/native/api/convert_to_rgba.js +0 -204
  796. package/src/avif/native/api/decode_avif.d.ts.map +0 -1
  797. package/src/avif/native/api/decode_image_item.d.ts.map +0 -1
  798. package/src/avif/native/api/encode_avif.d.ts.map +0 -1
  799. package/src/avif/native/api/sampler2d_to_avif.d.ts.map +0 -1
  800. package/src/avif/native/api/sampler2d_to_avif.js +0 -108
  801. package/src/avif/native/av1/decode/Av1FrameContext.d.ts.map +0 -1
  802. package/src/avif/native/av1/decode/block_decoded.d.ts.map +0 -1
  803. package/src/avif/native/av1/decode/decode_av1_still.d.ts.map +0 -1
  804. package/src/avif/native/av1/decode/decode_coefficients.d.ts.map +0 -1
  805. package/src/avif/native/av1/decode/decode_palette.d.ts.map +0 -1
  806. package/src/avif/native/av1/decode/decode_palette.js +0 -442
  807. package/src/avif/native/av1/decode/decode_tile.d.ts.map +0 -1
  808. package/src/avif/native/av1/decode/decode_tile.js +0 -1213
  809. package/src/avif/native/av1/decode/get_scan.d.ts.map +0 -1
  810. package/src/avif/native/av1/decode/read_lr.d.ts.map +0 -1
  811. package/src/avif/native/av1/decode/read_lr.js +0 -277
  812. package/src/avif/native/av1/decode/read_transform_type.d.ts.map +0 -1
  813. package/src/avif/native/av1/decode/read_transform_type.js +0 -92
  814. package/src/avif/native/av1/decode/reconstruct.d.ts.map +0 -1
  815. package/src/avif/native/av1/decode/reconstruct.js +0 -241
  816. package/src/avif/native/av1/decode/transform_type.d.ts.map +0 -1
  817. package/src/avif/native/av1/encode/Av1BlockSnapshot.d.ts.map +0 -1
  818. package/src/avif/native/av1/encode/Av1EncodeContext.d.ts.map +0 -1
  819. package/src/avif/native/av1/encode/build_headers.d.ts.map +0 -1
  820. package/src/avif/native/av1/encode/choose_chroma_alpha.d.ts.map +0 -1
  821. package/src/avif/native/av1/encode/choose_filters.d.ts.map +0 -1
  822. package/src/avif/native/av1/encode/choose_restoration.d.ts.map +0 -1
  823. package/src/avif/native/av1/encode/choose_restoration.js +0 -616
  824. package/src/avif/native/av1/encode/decode_effort.d.ts.map +0 -1
  825. package/src/avif/native/av1/encode/encode_av1_still.d.ts.map +0 -1
  826. package/src/avif/native/av1/encode/encode_effort.d.ts.map +0 -1
  827. package/src/avif/native/av1/encode/encode_tile.d.ts.map +0 -1
  828. package/src/avif/native/av1/encode/encode_tile.js +0 -2331
  829. package/src/avif/native/av1/encode/quantise.d.ts.map +0 -1
  830. package/src/avif/native/av1/encode/write_coefficients.d.ts.map +0 -1
  831. package/src/avif/native/av1/encode/write_lr.d.ts.map +0 -1
  832. package/src/avif/native/av1/encode/write_transform_type.d.ts.map +0 -1
  833. package/src/avif/native/av1/entropy/CdfContext.d.ts.map +0 -1
  834. package/src/avif/native/av1/entropy/SymbolReader.d.ts.map +0 -1
  835. package/src/avif/native/av1/entropy/SymbolWriter.d.ts.map +0 -1
  836. package/src/avif/native/av1/entropy/coefficient_context.d.ts.map +0 -1
  837. package/src/avif/native/av1/entropy/partition_cdf.d.ts.map +0 -1
  838. package/src/avif/native/av1/entropy/symbol_cost.d.ts.map +0 -1
  839. package/src/avif/native/av1/filter/cdef.d.ts.map +0 -1
  840. package/src/avif/native/av1/filter/cdef.js +0 -313
  841. package/src/avif/native/av1/filter/loop_filter.d.ts.map +0 -1
  842. package/src/avif/native/av1/filter/loop_filter.js +0 -377
  843. package/src/avif/native/av1/filter/loop_restoration.d.ts.map +0 -1
  844. package/src/avif/native/av1/filter/loop_restoration.js +0 -451
  845. package/src/avif/native/av1/filter/superres.d.ts.map +0 -1
  846. package/src/avif/native/av1/filter/superres.js +0 -86
  847. package/src/avif/native/av1/grain/FilmGrainState.d.ts.map +0 -1
  848. package/src/avif/native/av1/grain/film_grain.d.ts.map +0 -1
  849. package/src/avif/native/av1/grain/film_grain.js +0 -623
  850. package/src/avif/native/av1/obu/FrameHeader.d.ts.map +0 -1
  851. package/src/avif/native/av1/obu/ObuHeader.d.ts.map +0 -1
  852. package/src/avif/native/av1/obu/SequenceHeader.d.ts.map +0 -1
  853. package/src/avif/native/av1/obu/for_each_obu.d.ts.map +0 -1
  854. package/src/avif/native/av1/obu/parse_frame_header.d.ts.map +0 -1
  855. package/src/avif/native/av1/obu/parse_frame_header.js +0 -841
  856. package/src/avif/native/av1/obu/parse_obu_header.d.ts.map +0 -1
  857. package/src/avif/native/av1/obu/parse_sequence_header.d.ts.map +0 -1
  858. package/src/avif/native/av1/obu/write_frame_header.d.ts.map +0 -1
  859. package/src/avif/native/av1/obu/write_sequence_header.d.ts.map +0 -1
  860. package/src/avif/native/av1/predict/IntraPredictionState.d.ts.map +0 -1
  861. package/src/avif/native/av1/predict/intra_filter_type.d.ts.map +0 -1
  862. package/src/avif/native/av1/predict/predict_chroma_from_luma.d.ts.map +0 -1
  863. package/src/avif/native/av1/predict/predict_chroma_from_luma.js +0 -153
  864. package/src/avif/native/av1/predict/predict_intra.d.ts.map +0 -1
  865. package/src/avif/native/av1/predict/predict_intra.js +0 -803
  866. package/src/avif/native/av1/predict/predict_palette.d.ts.map +0 -1
  867. package/src/avif/native/av1/tables/av1_symbols.d.ts.map +0 -1
  868. package/src/avif/native/av1/tables/av1_symbols.js +0 -419
  869. package/src/avif/native/av1/tables/block_tables.d.ts.map +0 -1
  870. package/src/avif/native/av1/tables/block_tables.js +0 -270
  871. package/src/avif/native/av1/tables/cdf_tables.d.ts.map +0 -1
  872. package/src/avif/native/av1/tables/cdf_tables.js +0 -1893
  873. package/src/avif/native/av1/tables/coefficient_tables.d.ts.map +0 -1
  874. package/src/avif/native/av1/tables/coefficient_tables.js +0 -82
  875. package/src/avif/native/av1/tables/derived_block_tables.d.ts.map +0 -1
  876. package/src/avif/native/av1/tables/filter_tables.d.ts.map +0 -1
  877. package/src/avif/native/av1/tables/filter_tables.js +0 -313
  878. package/src/avif/native/av1/tables/grain_tables.d.ts.map +0 -1
  879. package/src/avif/native/av1/tables/grain_tables.js +0 -190
  880. package/src/avif/native/av1/tables/prediction_tables.d.ts.map +0 -1
  881. package/src/avif/native/av1/tables/prediction_tables.js +0 -223
  882. package/src/avif/native/av1/tables/quantizer_matrix_tables.d.ts.map +0 -1
  883. package/src/avif/native/av1/tables/quantizer_matrix_tables.js +0 -38
  884. package/src/avif/native/av1/tables/quantizer_tables.d.ts.map +0 -1
  885. package/src/avif/native/av1/tables/quantizer_tables.js +0 -160
  886. package/src/avif/native/av1/tables/scan_tables.d.ts.map +0 -1
  887. package/src/avif/native/av1/tables/scan_tables.js +0 -727
  888. package/src/avif/native/av1/tables/segmentation_tables.d.ts.map +0 -1
  889. package/src/avif/native/av1/tables/segmentation_tables.js +0 -48
  890. package/src/avif/native/av1/tables/transform_tables.d.ts.map +0 -1
  891. package/src/avif/native/av1/tables/transform_tables.js +0 -140
  892. package/src/avif/native/av1/tables/unpack_table.d.ts.map +0 -1
  893. package/src/avif/native/av1/tables/unpack_table.js +0 -73
  894. package/src/avif/native/av1/transform/forward_transform_2d.d.ts.map +0 -1
  895. package/src/avif/native/av1/transform/inverse_transform_1d.d.ts.map +0 -1
  896. package/src/avif/native/av1/transform/inverse_transform_1d.js +0 -590
  897. package/src/avif/native/av1/transform/inverse_transform_2d.d.ts.map +0 -1
  898. package/src/avif/native/av1/transform/inverse_transform_2d.js +0 -180
  899. package/src/avif/native/av1/util/ceil_log2.d.ts.map +0 -1
  900. package/src/avif/native/av1/util/floor_log2.d.ts +0 -20
  901. package/src/avif/native/av1/util/floor_log2.d.ts.map +0 -1
  902. package/src/avif/native/av1/util/floor_log2.js +0 -20
  903. package/src/avif/native/av1/util/round2.d.ts.map +0 -1
  904. package/src/avif/native/av1/util/round2_signed.d.ts.map +0 -1
  905. package/src/avif/native/av1/util/tile_log2.d.ts.map +0 -1
  906. package/src/avif/native/bitstream/BitReader.d.ts.map +0 -1
  907. package/src/avif/native/bitstream/BitWriter.d.ts.map +0 -1
  908. package/src/avif/native/color/ColourTransform.d.ts.map +0 -1
  909. package/src/avif/native/color/YuvImage.d.ts.map +0 -1
  910. package/src/avif/native/color/clamp_sample.d.ts.map +0 -1
  911. package/src/avif/native/color/linear_to_transfer.d.ts.map +0 -1
  912. package/src/avif/native/color/linear_to_transfer.js +0 -126
  913. package/src/avif/native/color/primaries.d.ts.map +0 -1
  914. package/src/avif/native/color/rgb_row_to_ycbcr.d.ts.map +0 -1
  915. package/src/avif/native/color/transfer_to_linear.d.ts.map +0 -1
  916. package/src/avif/native/color/transfer_to_linear.js +0 -171
  917. package/src/avif/native/color/upsample_chroma_row.d.ts.map +0 -1
  918. package/src/avif/native/color/upsample_chroma_row.js +0 -89
  919. package/src/avif/native/color/ycbcr_row_to_rgb.d.ts.map +0 -1
  920. package/src/avif/native/color/ycbcr_row_to_rgb.js +0 -78
  921. package/src/avif/native/heif/AvifFile.d.ts.map +0 -1
  922. package/src/avif/native/heif/ItemProperty.d.ts.map +0 -1
  923. package/src/avif/native/heif/find_item_property.d.ts.map +0 -1
  924. package/src/avif/native/heif/find_item_references.d.ts.map +0 -1
  925. package/src/avif/native/heif/find_items_referencing.d.ts.map +0 -1
  926. package/src/avif/native/heif/parse_avif_file.d.ts.map +0 -1
  927. package/src/avif/native/heif/parse_avif_file.js +0 -383
  928. package/src/avif/native/heif/parse_image_grid.d.ts.map +0 -1
  929. package/src/avif/native/heif/parse_image_grid.js +0 -48
  930. package/src/avif/native/heif/parse_item_property.d.ts.map +0 -1
  931. package/src/avif/native/heif/read_item_data.d.ts.map +0 -1
  932. package/src/avif/native/heif/write_avif_file.d.ts.map +0 -1
  933. package/src/avif/native/heif/write_item_property.d.ts.map +0 -1
  934. package/src/avif/native/index.d.ts +0 -14
  935. package/src/avif/native/index.d.ts.map +0 -1
  936. package/src/avif/native/index.js +0 -56
  937. package/src/avif/native/isobmff/BoxHeader.d.ts.map +0 -1
  938. package/src/avif/native/isobmff/BoxWriter.d.ts +0 -118
  939. package/src/avif/native/isobmff/BoxWriter.d.ts.map +0 -1
  940. package/src/avif/native/isobmff/BoxWriter.js +0 -264
  941. package/src/avif/native/isobmff/ByteCursor.d.ts +0 -125
  942. package/src/avif/native/isobmff/ByteCursor.d.ts.map +0 -1
  943. package/src/avif/native/isobmff/ByteCursor.js +0 -298
  944. package/src/avif/native/isobmff/for_each_box.d.ts.map +0 -1
  945. package/src/avif/native/isobmff/read_box_header.d.ts.map +0 -1
  946. package/src/avif/native/isobmff/read_full_box_header.d.ts.map +0 -1
  947. package/src/avif/threaded_image_encoder.d.ts.map +0 -1
  948. package/src/engine/asset/loaders/gltf/computeObjectBoundingSphere.d.ts +0 -8
  949. package/src/engine/asset/loaders/gltf/computeObjectBoundingSphere.d.ts.map +0 -1
  950. package/src/engine/asset/loaders/gltf/computeObjectBoundingSphere.js +0 -70
  951. package/src/engine/asset/loaders/gltf/isMesh.d.ts +0 -7
  952. package/src/engine/asset/loaders/gltf/isMesh.d.ts.map +0 -1
  953. package/src/engine/asset/loaders/gltf/isMesh.js +0 -8
  954. package/src/engine/asset/loaders/image/codec/Codec.d.ts.map +0 -1
  955. package/src/engine/asset/loaders/image/codec/CodecWithFallback.d.ts.map +0 -1
  956. package/src/engine/asset/loaders/image/codec/CodecWithFallback.js +0 -105
  957. package/src/engine/asset/loaders/image/jpeg/JpegFrame.d.ts.map +0 -1
  958. package/src/engine/asset/loaders/image/jpeg/JpegFrameComponent.d.ts.map +0 -1
  959. package/src/engine/asset/loaders/image/jpeg/JpegImage.d.ts.map +0 -1
  960. package/src/engine/asset/loaders/image/jpeg/JpegImage.js +0 -664
  961. package/src/engine/asset/loaders/image/jpeg/buildComponentData.d.ts.map +0 -1
  962. package/src/engine/asset/loaders/image/jpeg/buildHuffmanTable.d.ts.map +0 -1
  963. package/src/engine/asset/loaders/image/jpeg/decodeScan.d.ts.map +0 -1
  964. package/src/engine/asset/loaders/image/jpeg/idct8x8_float.d.ts.map +0 -1
  965. package/src/engine/asset/loaders/image/jpeg/idct8x8_float.js +0 -31
  966. package/src/engine/asset/loaders/image/jpeg/jpeg_component_row.d.ts.map +0 -1
  967. package/src/engine/asset/loaders/image/jpeg/jpeg_decode.d.ts.map +0 -1
  968. package/src/engine/asset/loaders/image/png/PNG.d.ts.map +0 -1
  969. package/src/engine/asset/loaders/image/png/PNGReader.d.ts +0 -158
  970. package/src/engine/asset/loaders/image/png/PNGReader.d.ts.map +0 -1
  971. package/src/engine/asset/loaders/image/png/PNGReader.js +0 -656
  972. package/src/engine/asset/loaders/image/png/PNG_HEADER_BYTES.d.ts.map +0 -1
  973. package/src/engine/asset/loaders/image/png/chunk/png_chunk_decode_iTXt.d.ts.map +0 -1
  974. package/src/engine/asset/loaders/image/png/chunk/png_chunk_decode_iTXt.js +0 -53
  975. package/src/engine/asset/loaders/image/png/chunk/png_chunk_decode_zTXt.d.ts.map +0 -1
  976. package/src/engine/asset/loaders/image/png/chunk/png_chunk_decode_zTXt.js +0 -42
  977. package/src/engine/asset/loaders/image/png/crc32.d.ts +0 -2
  978. package/src/engine/asset/loaders/image/png/crc32.d.ts.map +0 -1
  979. package/src/engine/asset/loaders/image/png/crc32.js +0 -8
  980. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterAverage.d.ts.map +0 -1
  981. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterNone.d.ts.map +0 -1
  982. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterPaeth.d.ts.map +0 -1
  983. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterSub.d.ts.map +0 -1
  984. package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterUp.d.ts.map +0 -1
  985. package/src/engine/asset/loaders/image/png/filter/png_unfilter.d.ts.map +0 -1
  986. package/src/engine/asset/loaders/image/png/filter/png_unfilter.js +0 -68
  987. package/src/engine/asset/loaders/image/png/png_inflate.d.ts.map +0 -1
  988. package/src/engine/asset/loaders/image/png/png_unpack_samples.d.ts.map +0 -1
  989. package/src/engine/asset/loaders/image/png/prototypePNG.d.ts.map +0 -1
  990. package/src/engine/asset/loaders/image/png/prototypePNG.js +0 -37
  991. package/src/shade/renderer/geometry/bvh/record_blas_refit.d.ts +0 -25
  992. package/src/shade/renderer/geometry/bvh/record_blas_refit.d.ts.map +0 -1
  993. package/src/shade/renderer/geometry/bvh/record_blas_refit.js +0 -102
  994. package/src/shade/renderer/geometry/bvh/shader_blas_refit_leaf_bounds.d.ts +0 -30
  995. package/src/shade/renderer/geometry/bvh/shader_blas_refit_leaf_bounds.d.ts.map +0 -1
  996. package/src/shade/renderer/geometry/bvh/shader_blas_refit_leaf_bounds.js +0 -125
  997. package/src/shade/renderer/loader/gltf/GLTF_PRIMITIVE_MODE.d.ts.map +0 -1
  998. package/src/shade/renderer/loader/gltf/MESHOPT_COMPRESSION_PLAN.md +0 -793
  999. package/src/shade/renderer/loader/gltf/coalesce_array_duplicates.d.ts.map +0 -1
  1000. package/src/shade/renderer/loader/gltf/ext/GltfBufferViewExtension.d.ts.map +0 -1
  1001. package/src/shade/renderer/loader/gltf/ext/GltfBufferViewExtensionSet.d.ts.map +0 -1
  1002. package/src/shade/renderer/loader/gltf/ext/GltfBufferViewExtensionSet.js +0 -109
  1003. package/src/shade/renderer/loader/gltf/ext/gltf_apply_buffer_view_extensions.d.ts.map +0 -1
  1004. package/src/shade/renderer/loader/gltf/ext/gltf_buffer_view_extensions.d.ts.map +0 -1
  1005. package/src/shade/renderer/loader/gltf/ext/gltf_geometry_extensions.d.ts.map +0 -1
  1006. package/src/shade/renderer/loader/gltf/ext/meshopt/MeshoptBufferViewExtension.d.ts.map +0 -1
  1007. package/src/shade/renderer/loader/gltf/ext/meshopt/MeshoptBufferViewExtension.js +0 -301
  1008. package/src/shade/renderer/loader/gltf/gltf_component_type.d.ts.map +0 -1
  1009. package/src/shade/renderer/loader/gltf/gltf_node_world_matrices.d.ts.map +0 -1
  1010. package/src/shade/renderer/loader/gltf/gltf_node_world_matrices.js +0 -137
  1011. package/src/shade/renderer/loader/gltf/gltf_parse_container.d.ts.map +0 -1
  1012. package/src/shade/renderer/loader/gltf/gltf_read_accessor.d.ts.map +0 -1
  1013. package/src/shade/renderer/loader/gltf/gltf_read_accessor.js +0 -294
  1014. package/src/shade/renderer/loader/gltf/gltf_used_image_indices.d.ts +0 -25
  1015. package/src/shade/renderer/loader/gltf/gltf_used_image_indices.d.ts.map +0 -1
  1016. package/src/shade/renderer/loader/gltf/gltf_used_image_indices.js +0 -49
  1017. package/src/shade/renderer/loader/usd/UsdError.d.ts.map +0 -1
  1018. package/src/shade/renderer/loader/usd/parse_usda.d.ts.map +0 -1
  1019. package/src/shade/renderer/loader/usd/unpack_usdz.d.ts.map +0 -1
  1020. package/src/shade/renderer/loader/usd/unpack_usdz.js +0 -106
  1021. package/src/shade/renderer/loader/usd/usd_compose_transform.d.ts.map +0 -1
  1022. package/src/shade/renderer/loader/usd/usd_compose_transform.js +0 -258
  1023. package/src/shade/renderer/loader/usd/usd_lz4.d.ts.map +0 -1
  1024. package/src/shade/renderer/loader/usd/usd_lz4.js +0 -182
  1025. package/src/shade/renderer/loader/usd/usd_triangulate.d.ts.map +0 -1
  1026. package/src/shade/renderer/postprocess/taa/chunk_taa_sample_history_color.d.ts +0 -2
  1027. package/src/shade/renderer/postprocess/taa/chunk_taa_sample_history_color.d.ts.map +0 -1
  1028. package/src/shade/renderer/postprocess/taa/chunk_taa_sample_history_color.js +0 -43
  1029. package/src/shade/renderer/scene/optimization/sampler2d_compare.d.ts.map +0 -1
  1030. package/src/shade/renderer/scene/optimization/sampler2d_compare.js +0 -94
  1031. package/src/shade/util/compute_max_mip_count.d.ts +0 -8
  1032. package/src/shade/util/compute_max_mip_count.d.ts.map +0 -1
  1033. package/src/shade/util/compute_max_mip_count.js +0 -27
  1034. /package/src/engine/asset/{loaders/image/codec → codec}/Codec.d.ts +0 -0
  1035. /package/src/engine/asset/{loaders/image/codec → codec}/Codec.js +0 -0
  1036. /package/src/engine/asset/{loaders/image/codec → codec}/CodecWithFallback.d.ts +0 -0
  1037. /package/src/{avif → engine/asset/loaders/image/avif}/encoder_worker.d.ts +0 -0
  1038. /package/src/{avif → engine/asset/loaders/image/avif}/encoder_worker.js +0 -0
  1039. /package/src/{avif → engine/asset/loaders/image/avif}/threaded_image_encoder.d.ts +0 -0
  1040. /package/src/{avif → engine/asset/loaders/image/avif}/threaded_image_encoder.js +0 -0
  1041. /package/src/engine/asset/loaders/image/{png/prototypePNG.d.ts → prototypePNG.d.ts} +0 -0
  1042. /package/src/{shade/renderer/scene/optimization → engine/graphics/texture/sampler/compare}/sampler2d_compare.d.ts +0 -0
  1043. /package/src/{avif/native/api → engine/graphics/texture/sampler}/sampler2d_to_avif.d.ts +0 -0
  1044. /package/src/{avif/native → format/image/avif}/NOTICE.md +0 -0
  1045. /package/src/{avif/native → format/image/avif}/api/AvifDecoder.d.ts +0 -0
  1046. /package/src/{avif/native → format/image/avif}/api/AvifDecoder.js +0 -0
  1047. /package/src/{avif/native → format/image/avif}/api/apply_transformations.d.ts +0 -0
  1048. /package/src/{avif/native → format/image/avif}/api/apply_transformations.js +0 -0
  1049. /package/src/{avif/native → format/image/avif}/api/convert_to_rgba.d.ts +0 -0
  1050. /package/src/{avif/native → format/image/avif}/api/decode_avif.d.ts +0 -0
  1051. /package/src/{avif/native → format/image/avif}/api/decode_avif.js +0 -0
  1052. /package/src/{avif/native → format/image/avif}/api/decode_image_item.d.ts +0 -0
  1053. /package/src/{avif/native → format/image/avif}/api/decode_image_item.js +0 -0
  1054. /package/src/{avif/native → format/image/avif}/api/encode_avif.d.ts +0 -0
  1055. /package/src/{avif/native → format/image/avif}/api/encode_avif.js +0 -0
  1056. /package/src/{avif/native → format/image/avif}/av1/decode/Av1FrameContext.d.ts +0 -0
  1057. /package/src/{avif/native → format/image/avif}/av1/decode/Av1FrameContext.js +0 -0
  1058. /package/src/{avif/native → format/image/avif}/av1/decode/block_decoded.d.ts +0 -0
  1059. /package/src/{avif/native → format/image/avif}/av1/decode/block_decoded.js +0 -0
  1060. /package/src/{avif/native → format/image/avif}/av1/decode/decode_av1_still.d.ts +0 -0
  1061. /package/src/{avif/native → format/image/avif}/av1/decode/decode_av1_still.js +0 -0
  1062. /package/src/{avif/native → format/image/avif}/av1/decode/decode_coefficients.d.ts +0 -0
  1063. /package/src/{avif/native → format/image/avif}/av1/decode/decode_coefficients.js +0 -0
  1064. /package/src/{avif/native → format/image/avif}/av1/decode/decode_palette.d.ts +0 -0
  1065. /package/src/{avif/native → format/image/avif}/av1/decode/decode_tile.d.ts +0 -0
  1066. /package/src/{avif/native → format/image/avif}/av1/decode/get_scan.d.ts +0 -0
  1067. /package/src/{avif/native → format/image/avif}/av1/decode/get_scan.js +0 -0
  1068. /package/src/{avif/native → format/image/avif}/av1/decode/read_lr.d.ts +0 -0
  1069. /package/src/{avif/native → format/image/avif}/av1/decode/read_transform_type.d.ts +0 -0
  1070. /package/src/{avif/native → format/image/avif}/av1/decode/reconstruct.d.ts +0 -0
  1071. /package/src/{avif/native → format/image/avif}/av1/decode/transform_type.d.ts +0 -0
  1072. /package/src/{avif/native → format/image/avif}/av1/decode/transform_type.js +0 -0
  1073. /package/src/{avif/native → format/image/avif}/av1/encode/Av1BlockSnapshot.d.ts +0 -0
  1074. /package/src/{avif/native → format/image/avif}/av1/encode/Av1BlockSnapshot.js +0 -0
  1075. /package/src/{avif/native → format/image/avif}/av1/encode/Av1EncodeContext.d.ts +0 -0
  1076. /package/src/{avif/native → format/image/avif}/av1/encode/Av1EncodeContext.js +0 -0
  1077. /package/src/{avif/native → format/image/avif}/av1/encode/build_headers.d.ts +0 -0
  1078. /package/src/{avif/native → format/image/avif}/av1/encode/build_headers.js +0 -0
  1079. /package/src/{avif/native → format/image/avif}/av1/encode/choose_chroma_alpha.d.ts +0 -0
  1080. /package/src/{avif/native → format/image/avif}/av1/encode/choose_chroma_alpha.js +0 -0
  1081. /package/src/{avif/native → format/image/avif}/av1/encode/choose_filters.d.ts +0 -0
  1082. /package/src/{avif/native → format/image/avif}/av1/encode/choose_filters.js +0 -0
  1083. /package/src/{avif/native → format/image/avif}/av1/encode/choose_restoration.d.ts +0 -0
  1084. /package/src/{avif/native → format/image/avif}/av1/encode/decode_effort.d.ts +0 -0
  1085. /package/src/{avif/native → format/image/avif}/av1/encode/decode_effort.js +0 -0
  1086. /package/src/{avif/native → format/image/avif}/av1/encode/encode_av1_still.d.ts +0 -0
  1087. /package/src/{avif/native → format/image/avif}/av1/encode/encode_av1_still.js +0 -0
  1088. /package/src/{avif/native → format/image/avif}/av1/encode/encode_effort.d.ts +0 -0
  1089. /package/src/{avif/native → format/image/avif}/av1/encode/encode_effort.js +0 -0
  1090. /package/src/{avif/native → format/image/avif}/av1/encode/encode_tile.d.ts +0 -0
  1091. /package/src/{avif/native → format/image/avif}/av1/encode/quantise.d.ts +0 -0
  1092. /package/src/{avif/native → format/image/avif}/av1/encode/quantise.js +0 -0
  1093. /package/src/{avif/native → format/image/avif}/av1/encode/write_coefficients.d.ts +0 -0
  1094. /package/src/{avif/native → format/image/avif}/av1/encode/write_coefficients.js +0 -0
  1095. /package/src/{avif/native → format/image/avif}/av1/encode/write_lr.d.ts +0 -0
  1096. /package/src/{avif/native → format/image/avif}/av1/encode/write_lr.js +0 -0
  1097. /package/src/{avif/native → format/image/avif}/av1/encode/write_transform_type.d.ts +0 -0
  1098. /package/src/{avif/native → format/image/avif}/av1/encode/write_transform_type.js +0 -0
  1099. /package/src/{avif/native → format/image/avif}/av1/entropy/CdfContext.d.ts +0 -0
  1100. /package/src/{avif/native → format/image/avif}/av1/entropy/CdfContext.js +0 -0
  1101. /package/src/{avif/native → format/image/avif}/av1/entropy/SymbolReader.d.ts +0 -0
  1102. /package/src/{avif/native → format/image/avif}/av1/entropy/SymbolReader.js +0 -0
  1103. /package/src/{avif/native → format/image/avif}/av1/entropy/SymbolWriter.d.ts +0 -0
  1104. /package/src/{avif/native → format/image/avif}/av1/entropy/SymbolWriter.js +0 -0
  1105. /package/src/{avif/native → format/image/avif}/av1/entropy/coefficient_context.d.ts +0 -0
  1106. /package/src/{avif/native → format/image/avif}/av1/entropy/coefficient_context.js +0 -0
  1107. /package/src/{avif/native → format/image/avif}/av1/entropy/partition_cdf.d.ts +0 -0
  1108. /package/src/{avif/native → format/image/avif}/av1/entropy/partition_cdf.js +0 -0
  1109. /package/src/{avif/native → format/image/avif}/av1/entropy/symbol_cost.d.ts +0 -0
  1110. /package/src/{avif/native → format/image/avif}/av1/entropy/symbol_cost.js +0 -0
  1111. /package/src/{avif/native → format/image/avif}/av1/filter/cdef.d.ts +0 -0
  1112. /package/src/{avif/native → format/image/avif}/av1/filter/loop_filter.d.ts +0 -0
  1113. /package/src/{avif/native → format/image/avif}/av1/filter/loop_restoration.d.ts +0 -0
  1114. /package/src/{avif/native → format/image/avif}/av1/filter/superres.d.ts +0 -0
  1115. /package/src/{avif/native → format/image/avif}/av1/grain/FilmGrainState.d.ts +0 -0
  1116. /package/src/{avif/native → format/image/avif}/av1/grain/FilmGrainState.js +0 -0
  1117. /package/src/{avif/native → format/image/avif}/av1/grain/film_grain.d.ts +0 -0
  1118. /package/src/{avif/native → format/image/avif}/av1/obu/FrameHeader.d.ts +0 -0
  1119. /package/src/{avif/native → format/image/avif}/av1/obu/FrameHeader.js +0 -0
  1120. /package/src/{avif/native → format/image/avif}/av1/obu/ObuHeader.d.ts +0 -0
  1121. /package/src/{avif/native → format/image/avif}/av1/obu/ObuHeader.js +0 -0
  1122. /package/src/{avif/native → format/image/avif}/av1/obu/SequenceHeader.d.ts +0 -0
  1123. /package/src/{avif/native → format/image/avif}/av1/obu/SequenceHeader.js +0 -0
  1124. /package/src/{avif/native → format/image/avif}/av1/obu/for_each_obu.d.ts +0 -0
  1125. /package/src/{avif/native → format/image/avif}/av1/obu/for_each_obu.js +0 -0
  1126. /package/src/{avif/native → format/image/avif}/av1/obu/parse_frame_header.d.ts +0 -0
  1127. /package/src/{avif/native → format/image/avif}/av1/obu/parse_obu_header.d.ts +0 -0
  1128. /package/src/{avif/native → format/image/avif}/av1/obu/parse_obu_header.js +0 -0
  1129. /package/src/{avif/native → format/image/avif}/av1/obu/parse_sequence_header.d.ts +0 -0
  1130. /package/src/{avif/native → format/image/avif}/av1/obu/parse_sequence_header.js +0 -0
  1131. /package/src/{avif/native → format/image/avif}/av1/obu/write_frame_header.d.ts +0 -0
  1132. /package/src/{avif/native → format/image/avif}/av1/obu/write_frame_header.js +0 -0
  1133. /package/src/{avif/native → format/image/avif}/av1/obu/write_sequence_header.d.ts +0 -0
  1134. /package/src/{avif/native → format/image/avif}/av1/obu/write_sequence_header.js +0 -0
  1135. /package/src/{avif/native → format/image/avif}/av1/predict/IntraPredictionState.d.ts +0 -0
  1136. /package/src/{avif/native → format/image/avif}/av1/predict/IntraPredictionState.js +0 -0
  1137. /package/src/{avif/native → format/image/avif}/av1/predict/intra_filter_type.d.ts +0 -0
  1138. /package/src/{avif/native → format/image/avif}/av1/predict/intra_filter_type.js +0 -0
  1139. /package/src/{avif/native → format/image/avif}/av1/predict/predict_chroma_from_luma.d.ts +0 -0
  1140. /package/src/{avif/native → format/image/avif}/av1/predict/predict_intra.d.ts +0 -0
  1141. /package/src/{avif/native → format/image/avif}/av1/predict/predict_palette.d.ts +0 -0
  1142. /package/src/{avif/native → format/image/avif}/av1/predict/predict_palette.js +0 -0
  1143. /package/src/{avif/native → format/image/avif}/av1/tables/av1_symbols.d.ts +0 -0
  1144. /package/src/{avif/native → format/image/avif}/av1/tables/block_tables.d.ts +0 -0
  1145. /package/src/{avif/native → format/image/avif}/av1/tables/cdf_tables.d.ts +0 -0
  1146. /package/src/{avif/native → format/image/avif}/av1/tables/coefficient_tables.d.ts +0 -0
  1147. /package/src/{avif/native → format/image/avif}/av1/tables/derived_block_tables.d.ts +0 -0
  1148. /package/src/{avif/native → format/image/avif}/av1/tables/derived_block_tables.js +0 -0
  1149. /package/src/{avif/native → format/image/avif}/av1/tables/filter_tables.d.ts +0 -0
  1150. /package/src/{avif/native → format/image/avif}/av1/tables/grain_tables.d.ts +0 -0
  1151. /package/src/{avif/native → format/image/avif}/av1/tables/prediction_tables.d.ts +0 -0
  1152. /package/src/{avif/native → format/image/avif}/av1/tables/quantizer_matrix_tables.d.ts +0 -0
  1153. /package/src/{avif/native → format/image/avif}/av1/tables/quantizer_tables.d.ts +0 -0
  1154. /package/src/{avif/native → format/image/avif}/av1/tables/scan_tables.d.ts +0 -0
  1155. /package/src/{avif/native → format/image/avif}/av1/tables/segmentation_tables.d.ts +0 -0
  1156. /package/src/{avif/native → format/image/avif}/av1/tables/transform_tables.d.ts +0 -0
  1157. /package/src/{avif/native → format/image/avif}/av1/tables/unpack_table.d.ts +0 -0
  1158. /package/src/{avif/native → format/image/avif}/av1/transform/forward_transform_2d.d.ts +0 -0
  1159. /package/src/{avif/native → format/image/avif}/av1/transform/forward_transform_2d.js +0 -0
  1160. /package/src/{avif/native → format/image/avif}/av1/transform/inverse_transform_1d.d.ts +0 -0
  1161. /package/src/{avif/native → format/image/avif}/av1/transform/inverse_transform_2d.d.ts +0 -0
  1162. /package/src/{avif/native → format/image/avif}/av1/util/ceil_log2.d.ts +0 -0
  1163. /package/src/{avif/native → format/image/avif}/av1/util/ceil_log2.js +0 -0
  1164. /package/src/{avif/native → format/image/avif}/av1/util/round2.d.ts +0 -0
  1165. /package/src/{avif/native → format/image/avif}/av1/util/round2.js +0 -0
  1166. /package/src/{avif/native → format/image/avif}/av1/util/round2_signed.d.ts +0 -0
  1167. /package/src/{avif/native → format/image/avif}/av1/util/round2_signed.js +0 -0
  1168. /package/src/{avif/native → format/image/avif}/av1/util/tile_log2.d.ts +0 -0
  1169. /package/src/{avif/native → format/image/avif}/av1/util/tile_log2.js +0 -0
  1170. /package/src/{avif/native → format/image/avif}/bitstream/BitReader.d.ts +0 -0
  1171. /package/src/{avif/native → format/image/avif}/bitstream/BitReader.js +0 -0
  1172. /package/src/{avif/native → format/image/avif}/bitstream/BitWriter.d.ts +0 -0
  1173. /package/src/{avif/native → format/image/avif}/bitstream/BitWriter.js +0 -0
  1174. /package/src/{avif/native → format/image/avif}/color/ColourTransform.d.ts +0 -0
  1175. /package/src/{avif/native → format/image/avif}/color/ColourTransform.js +0 -0
  1176. /package/src/{avif/native → format/image/avif}/color/YuvImage.d.ts +0 -0
  1177. /package/src/{avif/native → format/image/avif}/color/YuvImage.js +0 -0
  1178. /package/src/{avif/native → format/image/avif}/color/clamp_sample.d.ts +0 -0
  1179. /package/src/{avif/native → format/image/avif}/color/clamp_sample.js +0 -0
  1180. /package/src/{avif/native → format/image/avif}/color/linear_to_transfer.d.ts +0 -0
  1181. /package/src/{avif/native → format/image/avif}/color/primaries.d.ts +0 -0
  1182. /package/src/{avif/native → format/image/avif}/color/primaries.js +0 -0
  1183. /package/src/{avif/native → format/image/avif}/color/rgb_row_to_ycbcr.d.ts +0 -0
  1184. /package/src/{avif/native → format/image/avif}/color/rgb_row_to_ycbcr.js +0 -0
  1185. /package/src/{avif/native → format/image/avif}/color/transfer_to_linear.d.ts +0 -0
  1186. /package/src/{avif/native → format/image/avif}/color/upsample_chroma_row.d.ts +0 -0
  1187. /package/src/{avif/native → format/image/avif}/color/ycbcr_row_to_rgb.d.ts +0 -0
  1188. /package/src/{avif/native → format/image/avif}/heif/AvifFile.d.ts +0 -0
  1189. /package/src/{avif/native → format/image/avif}/heif/AvifFile.js +0 -0
  1190. /package/src/{avif/native → format/image/avif}/heif/ItemProperty.d.ts +0 -0
  1191. /package/src/{avif/native → format/image/avif}/heif/ItemProperty.js +0 -0
  1192. /package/src/{avif/native → format/image/avif}/heif/find_item_property.d.ts +0 -0
  1193. /package/src/{avif/native → format/image/avif}/heif/find_item_property.js +0 -0
  1194. /package/src/{avif/native → format/image/avif}/heif/find_item_references.d.ts +0 -0
  1195. /package/src/{avif/native → format/image/avif}/heif/find_item_references.js +0 -0
  1196. /package/src/{avif/native → format/image/avif}/heif/find_items_referencing.d.ts +0 -0
  1197. /package/src/{avif/native → format/image/avif}/heif/find_items_referencing.js +0 -0
  1198. /package/src/{avif/native → format/image/avif}/heif/parse_avif_file.d.ts +0 -0
  1199. /package/src/{avif/native → format/image/avif}/heif/parse_image_grid.d.ts +0 -0
  1200. /package/src/{avif/native → format/image/avif}/heif/parse_item_property.d.ts +0 -0
  1201. /package/src/{avif/native → format/image/avif}/heif/parse_item_property.js +0 -0
  1202. /package/src/{avif/native → format/image/avif}/heif/read_item_data.d.ts +0 -0
  1203. /package/src/{avif/native → format/image/avif}/heif/read_item_data.js +0 -0
  1204. /package/src/{avif/native → format/image/avif}/heif/write_avif_file.d.ts +0 -0
  1205. /package/src/{avif/native → format/image/avif}/heif/write_avif_file.js +0 -0
  1206. /package/src/{avif/native → format/image/avif}/heif/write_item_property.d.ts +0 -0
  1207. /package/src/{avif/native → format/image/avif}/heif/write_item_property.js +0 -0
  1208. /package/src/{avif/native → format/image/avif}/isobmff/BoxHeader.d.ts +0 -0
  1209. /package/src/{avif/native → format/image/avif}/isobmff/BoxHeader.js +0 -0
  1210. /package/src/{avif/native → format/image/avif}/isobmff/for_each_box.d.ts +0 -0
  1211. /package/src/{avif/native → format/image/avif}/isobmff/for_each_box.js +0 -0
  1212. /package/src/{avif/native → format/image/avif}/isobmff/read_box_header.d.ts +0 -0
  1213. /package/src/{avif/native → format/image/avif}/isobmff/read_box_header.js +0 -0
  1214. /package/src/{avif/native → format/image/avif}/isobmff/read_full_box_header.d.ts +0 -0
  1215. /package/src/{avif/native → format/image/avif}/isobmff/read_full_box_header.js +0 -0
  1216. /package/src/{engine/asset/loaders → format}/image/jpeg/JpegFrame.d.ts +0 -0
  1217. /package/src/{engine/asset/loaders → format}/image/jpeg/JpegFrame.js +0 -0
  1218. /package/src/{engine/asset/loaders → format}/image/jpeg/JpegFrameComponent.d.ts +0 -0
  1219. /package/src/{engine/asset/loaders → format}/image/jpeg/JpegFrameComponent.js +0 -0
  1220. /package/src/{engine/asset/loaders → format}/image/jpeg/JpegImage.d.ts +0 -0
  1221. /package/src/{engine/asset/loaders → format}/image/jpeg/NOTES.md +0 -0
  1222. /package/src/{engine/asset/loaders → format}/image/jpeg/buildComponentData.d.ts +0 -0
  1223. /package/src/{engine/asset/loaders → format}/image/jpeg/buildComponentData.js +0 -0
  1224. /package/src/{engine/asset/loaders → format}/image/jpeg/buildHuffmanTable.d.ts +0 -0
  1225. /package/src/{engine/asset/loaders → format}/image/jpeg/buildHuffmanTable.js +0 -0
  1226. /package/src/{engine/asset/loaders → format}/image/jpeg/decodeScan.d.ts +0 -0
  1227. /package/src/{engine/asset/loaders → format}/image/jpeg/decodeScan.js +0 -0
  1228. /package/src/{engine/asset/loaders → format}/image/jpeg/idct8x8_float.d.ts +0 -0
  1229. /package/src/{engine/asset/loaders → format}/image/jpeg/jpeg_component_row.d.ts +0 -0
  1230. /package/src/{engine/asset/loaders → format}/image/jpeg/jpeg_component_row.js +0 -0
  1231. /package/src/{engine/asset/loaders → format}/image/jpeg/jpeg_decode.d.ts +0 -0
  1232. /package/src/{engine/asset/loaders → format}/image/jpeg/jpeg_decode.js +0 -0
  1233. /package/src/{engine/asset/loaders → format}/image/png/PNG.d.ts +0 -0
  1234. /package/src/{engine/asset/loaders → format}/image/png/PNG.js +0 -0
  1235. /package/src/{engine/asset/loaders → format}/image/png/PNG_HEADER_BYTES.d.ts +0 -0
  1236. /package/src/{engine/asset/loaders → format}/image/png/PNG_HEADER_BYTES.js +0 -0
  1237. /package/src/{engine/asset/loaders → format}/image/png/chunk/png_chunk_decode_iTXt.d.ts +0 -0
  1238. /package/src/{engine/asset/loaders → format}/image/png/chunk/png_chunk_decode_zTXt.d.ts +0 -0
  1239. /package/src/{engine/asset/loaders → format}/image/png/filter/png_filter_unFilterAverage.d.ts +0 -0
  1240. /package/src/{engine/asset/loaders → format}/image/png/filter/png_filter_unFilterAverage.js +0 -0
  1241. /package/src/{engine/asset/loaders → format}/image/png/filter/png_filter_unFilterNone.d.ts +0 -0
  1242. /package/src/{engine/asset/loaders → format}/image/png/filter/png_filter_unFilterNone.js +0 -0
  1243. /package/src/{engine/asset/loaders → format}/image/png/filter/png_filter_unFilterPaeth.d.ts +0 -0
  1244. /package/src/{engine/asset/loaders → format}/image/png/filter/png_filter_unFilterPaeth.js +0 -0
  1245. /package/src/{engine/asset/loaders → format}/image/png/filter/png_filter_unFilterSub.d.ts +0 -0
  1246. /package/src/{engine/asset/loaders → format}/image/png/filter/png_filter_unFilterSub.js +0 -0
  1247. /package/src/{engine/asset/loaders → format}/image/png/filter/png_filter_unFilterUp.d.ts +0 -0
  1248. /package/src/{engine/asset/loaders → format}/image/png/filter/png_filter_unFilterUp.js +0 -0
  1249. /package/src/{engine/asset/loaders → format}/image/png/filter/png_unfilter.d.ts +0 -0
  1250. /package/src/{engine/asset/loaders → format}/image/png/png_inflate.d.ts +0 -0
  1251. /package/src/{engine/asset/loaders → format}/image/png/png_inflate.js +0 -0
  1252. /package/src/{engine/asset/loaders → format}/image/png/png_unpack_samples.d.ts +0 -0
  1253. /package/src/{engine/asset/loaders → format}/image/png/png_unpack_samples.js +0 -0
  1254. /package/src/{shade/renderer/loader → format/scene}/gltf/GLTF_PRIMITIVE_MODE.d.ts +0 -0
  1255. /package/src/{shade/renderer/loader → format/scene}/gltf/GLTF_PRIMITIVE_MODE.js +0 -0
  1256. /package/src/{shade/renderer/loader → format/scene}/gltf/coalesce_array_duplicates.d.ts +0 -0
  1257. /package/src/{shade/renderer/loader → format/scene}/gltf/coalesce_array_duplicates.js +0 -0
  1258. /package/src/{shade/renderer/loader → format/scene}/gltf/ext/GltfBufferViewExtension.d.ts +0 -0
  1259. /package/src/{shade/renderer/loader → format/scene}/gltf/ext/GltfBufferViewExtension.js +0 -0
  1260. /package/src/{shade/renderer/loader → format/scene}/gltf/ext/GltfBufferViewExtensionSet.d.ts +0 -0
  1261. /package/src/{shade/renderer/loader → format/scene}/gltf/ext/gltf_apply_buffer_view_extensions.d.ts +0 -0
  1262. /package/src/{shade/renderer/loader → format/scene}/gltf/ext/gltf_apply_buffer_view_extensions.js +0 -0
  1263. /package/src/{shade/renderer/loader → format/scene}/gltf/ext/gltf_buffer_view_extensions.d.ts +0 -0
  1264. /package/src/{shade/renderer/loader → format/scene}/gltf/ext/gltf_buffer_view_extensions.js +0 -0
  1265. /package/src/{shade/renderer/loader → format/scene}/gltf/ext/gltf_geometry_extensions.d.ts +0 -0
  1266. /package/src/{shade/renderer/loader → format/scene}/gltf/ext/gltf_geometry_extensions.js +0 -0
  1267. /package/src/{shade/renderer/loader → format/scene}/gltf/ext/meshopt/MeshoptBufferViewExtension.d.ts +0 -0
  1268. /package/src/{shade/renderer/loader → format/scene}/gltf/gltf_component_type.d.ts +0 -0
  1269. /package/src/{shade/renderer/loader → format/scene}/gltf/gltf_component_type.js +0 -0
  1270. /package/src/{shade/renderer/loader → format/scene}/gltf/gltf_node_world_matrices.d.ts +0 -0
  1271. /package/src/{shade/renderer/loader → format/scene}/gltf/gltf_parse_container.d.ts +0 -0
  1272. /package/src/{shade/renderer/loader → format/scene}/gltf/gltf_parse_container.js +0 -0
  1273. /package/src/{shade/renderer/loader → format/scene}/gltf/gltf_read_accessor.d.ts +0 -0
  1274. /package/src/{shade/renderer/loader → format/scene}/usd/UsdError.d.ts +0 -0
  1275. /package/src/{shade/renderer/loader → format/scene}/usd/UsdError.js +0 -0
  1276. /package/src/{shade/renderer/loader → format/scene}/usd/parse_usda.d.ts +0 -0
  1277. /package/src/{shade/renderer/loader → format/scene}/usd/parse_usda.js +0 -0
  1278. /package/src/{shade/renderer/loader → format/scene}/usd/unpack_usdz.d.ts +0 -0
  1279. /package/src/{shade/renderer/loader → format/scene}/usd/usd_compose_transform.d.ts +0 -0
  1280. /package/src/{shade/renderer/loader → format/scene}/usd/usd_lz4.d.ts +0 -0
  1281. /package/src/{shade/renderer/loader → format/scene}/usd/usd_triangulate.d.ts +0 -0
  1282. /package/src/{shade/renderer/loader → format/scene}/usd/usd_triangulate.js +0 -0
@@ -1,2511 +1,2519 @@
1
- import { assert } from "../../core/assert.js";
2
- import Signal from "../../core/events/signal/Signal.js";
3
- import Vector2 from "../../core/geom/Vector2.js";
4
- import { clamp } from "../../core/math/clamp.js";
5
- import { remap } from "../../core/math/remap.js";
6
- import { MetricCollection } from "../../engine/development/performance/MetricCollection.js";
7
- import {
8
- MetricCollectionConsoleMonitor
9
- } from "../../engine/development/performance/monitor/MetricCollectionConsoleMonitor.js";
10
- import { FrameGraph } from "../../engine/graphics/render/frame_graph/FrameGraph.js";
11
- import { TextureDescriptor } from "../descriptor/texture/TextureDescriptor.js";
12
- import { WebGPUExtensionType } from "../descriptor/WebGPUExtensionType.js";
13
- import { ShadeDeviceFailure } from "../device/ShadeDeviceFailure.js";
14
- import { ShadeGPUCommandContext } from "../device/ShadeGPUCommandContext.js";
15
- import { CameraManager } from "./camera/CameraManager.js";
16
- import { shader_background } from "./deferred/shader_background.js";
17
- import { shader_composite_volumetrics } from "./deferred/shader_composite_volumetrics.js";
18
- import { shader_deferred_main, shader_deferred_main_restir } from "./deferred/shader_deferred_main.js";
19
- import { shader_tonemap_HDR } from "./deferred/shader_tonemap_HDR.js";
20
- import { shader_tonemap_LDR } from "./deferred/shader_tonemap_LDR.js";
21
- import { FrameContext } from "./extension/FrameContext.js";
22
- import { FramePhase } from "./extension/FramePhase.js";
23
- import { GBufferTextures } from "./extension/GBufferTextures.js";
24
- import { PresentTarget } from "./extension/PresentTarget.js";
25
- import { RenderExtensionRegistry } from "./extension/RenderExtensionRegistry.js";
26
- import { SceneColor } from "./extension/SceneColor.js";
27
- import { ViewTextures } from "./extension/ViewTextures.js";
28
- import { G_BUFFER_MIP_LEVELS } from "./gbuffer/G_BUFFER_MIP_LEVELS.js";
29
- import { shader_brick4_diffuse } from "./global_illumination/brick4/gpu/draw/shader_brick4_diffuse.js";
30
- import {
31
- shader_brick4_indirect_lighting
32
- } from "./global_illumination/brick4/gpu/draw/shader_brick4_indirect_lighting.js";
33
- import { shader_brick4_specular } from "./global_illumination/brick4/gpu/draw/shader_brick4_specular.js";
34
- import { shader_diffuse_IBL } from "./global_illumination/ibl/shader_diffuse_IBL.js";
35
- import { shader_specular_IBL } from "./global_illumination/ibl/shader_specular_IBL.js";
36
- import { GPULightProbeVolumeRenderer } from "./global_illumination/lpv/bake/GPULightProbeVolumeRenderer.js";
37
- import { shader_diffuse_LPV } from "./global_illumination/lpv/shader_diffuse_LPV.js";
38
- import { shader_resolve_indirect_lighting } from "./global_illumination/shader_resolve_indirect_lighting.js";
39
- import { GraphicsContext } from "./GraphicsContext.js";
40
- import { graph_build_light_clusters } from "./light/cluster/graph_build_light_clusters.js";
41
- import { AccumulatingPathTracer } from "./path_tracer/accumulating/AccumulatingPathTracer.js";
42
- import { graph_postprocess_bloom } from "./postprocess/bloom/graph_postprocess_bloom.js";
43
- import { shader_ffx_rcas } from "./postprocess/cas/shader_ffx_rcas.js";
44
- import { DepthOfFieldU } from "./postprocess/dof/gather/DepthOfFieldU.js";
45
- import { DepthOfField } from "./postprocess/dof/raymarch/DepthOfField.js";
46
- import { GPUCameraExposureManager } from "./postprocess/eye/GPUCameraExposureManager.js";
47
- import { MotionBlur } from "./postprocess/motion_blur/MotionBlur.js";
48
- import { NSS } from "./postprocess/nss/NSS.js";
49
- import { PostProcess } from "./postprocess/PostProcess.js";
50
- import { shader_depth_occlusion_clip } from "./postprocess/taa/shader_depth_occlusion_clip.js";
51
- import { TAA } from "./postprocess/taa/TAA.js";
52
- import { graph_add_per_object_velocity } from "./postprocess/velocity/graph_add_per_object_velocity.js";
53
- import { shader_debug_velocity } from "./postprocess/velocity/shader_debug_velocity.js";
54
- import {
55
- graph_rasterize_meshes_transparent_oit
56
- } from "./rasterize/native/oit/graph_rasterize_meshes_transparent_oit.js";
57
- import {
58
- viz_rasterization_alpha_tested_pass_descriptor
59
- } from "./rasterize/native/viz/viz_rasterization_alpha_tested_pass_descriptor.js";
60
- import {
61
- viz_rasterization_opaque_pass_descriptor
62
- } from "./rasterize/native/viz/viz_rasterization_opaque_pass_descriptor.js";
63
- import { RasterizationJob } from "./rasterize/RasterizationJob.js";
64
- import { graph_rasterize_scene } from "./rasterize/standard/graph_rasterize_scene.js";
65
- import { ReSTIRDI } from "./restir/di/ReSTIRDI.js";
66
- import { SceneManager } from "./scene/SceneManager.js";
67
- import { ShadeIndirectLightingMode } from "./ShadeIndirectLightingMode.js";
68
- import { graph_image_pass } from "./shader/graph/graph_image_pass.js";
69
- import { graph_import_buffer } from "./shader/graph/graph_import_buffer.js";
70
- import { graph_import_texture } from "./shader/graph/graph_import_texture.js";
71
- import { ShadeUpscalerType } from "./ShadeUpscalerType.js";
72
- import { CascadedSceneSDF } from "./shadow/sdf/cascade/CascadedSceneSDF.js";
73
- import { STATIC_GRAPHICS_ENGINE_ASSETS } from "./STATIC_GRAPHICS_ENGINE_ASSETS.js";
74
- import { GPUTextureContext } from "./texture/GPUTextureContext.js";
75
- import { RenderTarget } from "./texture/RenderTarget.js";
76
- import { View } from "./view/View.js";
77
- import { ViewManager } from "./view/ViewManager.js";
78
-
79
- const METRICS = new MetricCollection();
80
- METRICS.create({ name: 'frame_time' });
81
-
82
- /**
83
- * Depth and G-buffer textures carry {@link G_BUFFER_MIP_LEVELS} mip levels.
84
- * WebGPU's createTexture validation requires mipLevelCount <= floor(log2(max(w,h))) + 1,
85
- * so the internal resolution must never drop below 2^(G_BUFFER_MIP_LEVELS - 1)
86
- * or texture allocation will fail.
87
- * @type {number}
88
- */
89
- const INTERNAL_RESOLUTION_MIN = 1 << (G_BUFFER_MIP_LEVELS - 1);
90
-
91
- MetricCollectionConsoleMonitor.from(METRICS);
92
-
93
- export class Renderer {
94
- /**
95
- * Indexes current drawn frame
96
- * @type {number}
97
- */
98
- #frame_count = 0;
99
-
100
- get frame_count() {
101
- return this.#frame_count;
102
- }
103
-
104
- /**
105
- * @type {GPUCanvasContext}
106
- */
107
- context;
108
-
109
- /**
110
- * The HTMLCanvasElement (or OffscreenCanvas) bound to this renderer.
111
- * If `initialize()` was called without a `context`, this is the canvas
112
- * the renderer created — append it to the DOM to display the output.
113
- *
114
- * @returns {HTMLCanvasElement|OffscreenCanvas|undefined}
115
- */
116
- get canvas() {
117
- return this.context?.canvas;
118
- }
119
-
120
- /**
121
- * @type {GPUDevice}
122
- */
123
- device;
124
-
125
- /**
126
- * @type {GPUCameraExposureManager}
127
- */
128
- #autoexposure;
129
-
130
- /**
131
- * @type {SceneManager}
132
- */
133
- #scenes;
134
-
135
- /**
136
- * Only use for read-access
137
- * @returns {SceneManager}
138
- */
139
- get scenes() {
140
- return this.#scenes;
141
- }
142
-
143
- /**
144
- * @type {CameraManager}
145
- */
146
- #cameras
147
-
148
- /**
149
- * @type {ViewManager}
150
- */
151
- #views
152
-
153
-
154
- set feature_shadows_enabled(v) {
155
- assert.isBoolean(v, 'v');
156
- this.#feature_shadows_enabled = v;
157
- }
158
-
159
- get feature_shadows_enabled() {
160
- return this.#feature_shadows_enabled;
161
- }
162
-
163
- /**
164
- * Controls which indirect lighting technique is used for
165
- * both deferred resolve and forward transparency passes.
166
- * @type {ShadeIndirectLightingMode}
167
- */
168
- indirect_lighting_mode = ShadeIndirectLightingMode.IBL;
169
-
170
- feature_ssr_enabled = false;
171
- feature_ssao_enabled = true;
172
- /**
173
- * ReSTIR DI — stochastic screen-bounded direct shadowing of local
174
- * (point+spot) lights. When on, the deferred pass skips its froxel cluster
175
- * loop and consumes the ReSTIR-resolved radiance instead.
176
- */
177
- feature_restir_di_enabled = false;
178
- /**
179
- * Generate point-light shadows with the tetrahedral (4-face) path instead of the default
180
- * cube (6-face) path. Both produce the same octahedral atlas encoding, so this is safe to
181
- * flip at runtime and is meant for A/B comparison of the two generators. Pushed to the
182
- * scene's shadow context each frame; see
183
- * {@link GPUSceneShadowmapContext.use_tetrahedron_point_shadows}.
184
- * @type {boolean}
185
- */
186
- feature_tetrahedron_point_shadows = false;
187
- feature_bloom_enabled = true;
188
- feature_automatic_exposure_enabled = true;
189
-
190
- /**
191
- * Fixed exposure, in f-stops, used when {@link feature_automatic_exposure_enabled} is off.
192
- *
193
- * Turning adaptation off without being able to set this leaves the frame at 2 stops, which is
194
- * black for any scene the eye would otherwise have opened up for — so the flag alone is not
195
- * usable. Anything comparing two renders wants adaptation off and this pinned: eye adaptation
196
- * keeps drifting for seconds after a change, which makes two shots of the *same* setting differ
197
- * by more than the change being judged.
198
- *
199
- * @returns {number}
200
- */
201
- get exposure_compensation() {
202
- // the manager is built in initialize(); before that there is no value to report
203
- return this.#autoexposure === undefined ? 0 : this.#autoexposure.exposure_compensation;
204
- }
205
-
206
- set exposure_compensation(v) {
207
- assert.isNumber(v, 'exposure_compensation');
208
- assert.defined(this.#autoexposure, 'autoexposure (set exposure_compensation after initialize)');
209
-
210
- this.#autoexposure.exposure_compensation = v;
211
- }
212
-
213
- /**
214
- * Virtual texture streaming (opt-in per material via
215
- * {@link StandardShadeMaterial#vt_stack}). This flag is the system-wide
216
- * kill switch: when off, the feedback pass and residency maintenance
217
- * stop running — already-resident pages keep rendering, nothing new
218
- * streams in. Costs nothing while no stack is registered.
219
- * @type {boolean}
220
- */
221
- feature_virtual_textures = true;
222
-
223
- #feature_taa_enabled = true;
224
-
225
- get feature_taa_enabled() {
226
- return this.#feature_taa_enabled;
227
- }
228
-
229
- /**
230
- * While TAA is off nothing writes the history textures, but the frame counter that
231
- * indexes them keeps advancing — re-enabling would blend with arbitrarily stale
232
- * history of arbitrary parity. Reset temporal history on the transition.
233
- * @param {boolean} v
234
- */
235
- set feature_taa_enabled(v) {
236
- if (this.#feature_taa_enabled === v) {
237
- return;
238
- }
239
-
240
- this.#feature_taa_enabled = v;
241
- this.indicate_view_change();
242
- }
243
-
244
- /**
245
- * Jimenez 2014 reconstruction-filter motion blur, runs between
246
- * TAA and sharpening on the HDR colour. Reads the velocity buffer
247
- * the same way TAA does — per-pixel pixel-space deltas — and
248
- * scatter-gathers along the dilated tile velocity. Off by default
249
- * because the reconstruction pass is a few-ms-budget item and not
250
- * every scene needs it.
251
- *
252
- * @type {boolean}
253
- */
254
- feature_motion_blur_enabled = false;
255
-
256
- /**
257
- * Motion-blur subsystem (Jimenez 2014 reconstruction filter). A
258
- * self-contained manager — same pattern as {@link #autoexposure} /
259
- * {@link #depth_of_field} — that owns the motion-blur parameters
260
- * (currently just `strength`). Constructed in init.
261
- * @type {MotionBlur}
262
- */
263
- #motion_blur;
264
-
265
- /**
266
- * The motion-blur subsystem. Configure it via `renderer.motion_blur.*`
267
- * (currently `strength`); toggle the effect with
268
- * {@link feature_motion_blur_enabled}.
269
- * @returns {MotionBlur}
270
- */
271
- get motion_blur() { return this.#motion_blur; }
272
-
273
- /**
274
- * Debug-only override: when true, the per-object velocity texture
275
- * is drawn straight into the post-TAA color path so the screen
276
- * shows the velocity buffer instead of the rendered image. Wired
277
- * just before TAA — TAA then operates on the velocity texture,
278
- * which is nonsense but cheap to set up. Default false.
279
- *
280
- * @type {boolean}
281
- */
282
- feature_velocity_debug_view = false;
283
-
284
- /**
285
- * When true, {@link path_tracer} replaces the rasterized+shaded color for the frame. The
286
- * traced result still goes through TAA and tone mapping like any other color.
287
- *
288
- * The path tracer accumulates across frames itself, one tile per call, and resets whenever the
289
- * camera moves. TAA on top of that is two temporal filters fighting over the same image — turn
290
- * `feature_taa_enabled` off while this is on.
291
- *
292
- * This is the traversal-heaviest consumer of the TLAS — it binds `scene_ctx.tlas.buffer`
293
- * directly — which is what made it the check that the GPU TLAS build traces correctly, and what
294
- * makes it the first place a regression in that tree would show. Default false: it is a
295
- * prototype-grade path, not a shipping render mode.
296
- *
297
- * @type {boolean}
298
- */
299
- feature_path_tracing_enabled = false;
300
-
301
- /**
302
- * Screen-space ray-marched depth of field — the Tiny Glade model
303
- * (Stachowiak, GPC 2024; see {@link DepthOfField}): aperture sub-rays
304
- * marched through the half-res depth/CoC buffer with nearest-hit
305
- * occlusion, plus tilt-shift. Runs on the resolved HDR colour after TAA
306
- * (which resolves the march's sample noise) and before motion blur. Off
307
- * by default — a half-res march is a few-ms item, only worth it for a
308
- * deliberate shallow-focus / diorama look. Configure via `renderer.dof`.
309
- *
310
- * @type {boolean}
311
- */
312
- feature_dof_enabled = false;
313
-
314
- /**
315
- * Depth-of-field subsystem (screen-space ray-marched). A self-contained
316
- * manager — same pattern as {@link #autoexposure} — that owns all DoF
317
- * parameters, focus state, and GPU buffers. Constructed in init.
318
- * @type {DepthOfField}
319
- */
320
- #depth_of_field;
321
-
322
- /**
323
- * The depth-of-field subsystem. Configure it via `renderer.dof.*`
324
- * (`f_number`, `quality`, the `focus*` helpers, `applyPreset`, …);
325
- * toggle the effect with {@link feature_dof_enabled}.
326
- * @returns {DepthOfField}
327
- */
328
- get dof() { return this.#depth_of_field; }
329
-
330
- /**
331
- * Which depth-of-field implementation runs when {@link feature_dof_enabled}
332
- * is on. `"raymarch"` (default) is the screen-space ray-march
333
- * ({@link DepthOfField}); `"unreal"` is the gather-based Diaphragm /
334
- * Cinematic DoF ({@link DepthOfFieldU}) — half-res near/far gather with a
335
- * foreground coverage bleed. Mutually exclusive by construction (only one
336
- * runs at the single DoF call site).
337
- * @type {"raymarch"|"unreal"}
338
- */
339
- dof_algorithm = "raymarch";
340
-
341
- /**
342
- * Unreal-style (Diaphragm / Cinematic) gather depth of field — a drop-in
343
- * alternative to {@link #depth_of_field}, selected via {@link dof_algorithm}.
344
- * Constructed in init.
345
- * @type {DepthOfFieldU}
346
- */
347
- #depth_of_field_unreal;
348
-
349
- /**
350
- * The Unreal-style depth-of-field subsystem. Configure it via
351
- * `renderer.dof_unreal.*` and select it with `renderer.dof_algorithm = "unreal"`.
352
- * @returns {DepthOfFieldU}
353
- */
354
- get dof_unreal() { return this.#depth_of_field_unreal; }
355
-
356
- /**
357
- * When true and {@link indirect_lighting_mode} is Brick4, run a single fused
358
- * pass that produces the resolved indirect lighting directly (combining the
359
- * brick4 diffuse, brick4 specular and indirect resolve passes). Trades a
360
- * bit of cache pressure inside the pass for substantially less memory
361
- * bandwidth: no intermediate rgba16float diffuse/specular targets, the
362
- * g-buffer is read once, and a single brick4 probe pair is shared between
363
- * the diffuse and specular evaluations.
364
- *
365
- * SSR is mutually exclusive with the fused path (it needs the standalone
366
- * specular target as input), so when SSR is enabled the split path is used.
367
- * @type {boolean}
368
- */
369
- fused_indirect = true;
370
-
371
- /**
372
- * RCAS
373
- * @type {boolean}
374
- */
375
- feature_sharpening_enabled = true;
376
-
377
- #feature_shadows_enabled = true;
378
- #feature_enabled_transparencies = true;
379
-
380
- /**
381
- *
382
- * @return {ViewManager}
383
- */
384
- get views() {
385
- return this.#views;
386
- }
387
-
388
- /**
389
- * @type {GraphicsContext}
390
- */
391
- #graphics;
392
-
393
- /**
394
- *
395
- * @return {GraphicsContext}
396
- */
397
- get graphics() {
398
- return this.#graphics;
399
- }
400
-
401
-
402
- /**
403
- *
404
- * @type {Signal<number>}
405
- */
406
- /**
407
- * Extensions an outside caller has put into the frame, by phase.
408
- *
409
- * @type {RenderExtensionRegistry}
410
- */
411
- #extensions = new RenderExtensionRegistry();
412
-
413
- /**
414
- * Raised when there is no usable device — the browser has no WebGPU, the hardware is below the
415
- * floor, or a working device was lost while running. Carries a {@link ShadeDeviceFailure}.
416
- *
417
- * The floor is deliberate and there are no fallbacks (D6/I-8), so telling the player plainly is
418
- * the whole of what the engine owes here. Loss is not recovered from (R6): everything built on
419
- * the device went with it, and the honest response is a message and a reload.
420
- *
421
- * @type {Signal<ShadeDeviceFailure>}
422
- */
423
- onDeviceFailure = new Signal();
424
-
425
- onFrameFinished = new Signal();
426
-
427
- /**
428
- * Fraction of the output resolution.
429
- * Controls {@link #internal_resolution}.
430
- * If this is set to 0.5 for example - internal resolution will be 50% of the output resolution.
431
- * @type {number}
432
- */
433
- #internal_resolution_scale = 1;
434
-
435
- /**
436
- *
437
- * @type {boolean}
438
- */
439
- #internal_resolution_needs_update = true;
440
-
441
- /**
442
- *
443
- * @param {number} v
444
- */
445
- set internal_resolution_scale(v) {
446
- assert.isNumber(v, 'v');
447
- assert.notNaN(v, 'v');
448
- assert.greaterThan(v, 0);
449
- assert.isFinite(v, 'v');
450
-
451
- if (this.#internal_resolution_scale === v) {
452
- // no change
453
- return;
454
- }
455
-
456
- this.#internal_resolution_scale = v;
457
-
458
- // schedule resolution recalculation
459
- this.#internal_resolution_needs_update = true;
460
- }
461
-
462
- /**
463
- *
464
- * @returns {number}
465
- */
466
- get internal_resolution_scale() {
467
- return this.#internal_resolution_scale;
468
- }
469
-
470
- /**
471
- * This is the resolution that the rendering happens at before upscaling.
472
- * Derived from input resolution via {@link internal_resolution_scale}
473
- * @type {Vector2}
474
- */
475
- #internal_resolution = new Vector2(1, 1);
476
-
477
-
478
- /**
479
- * Output viewport size
480
- * @type {Vector2}
481
- */
482
- #size = new Vector2(1, 1);
483
-
484
- /**
485
- * Output resolution.
486
- * Equal to {@link size} * {@link pixel_ratio}
487
- * Don't write directly
488
- * @type {Vector2}
489
- * @see {#size}
490
- * @see {#pixel_ratio}
491
- */
492
- #output_resolution = new Vector2(1, 1);
493
-
494
- /**
495
- *
496
- * @returns {Vector2}
497
- */
498
- get output_resolution() {
499
- return this.#output_resolution.clone();
500
- }
501
-
502
- /**
503
- * width/height
504
- * Useful for camera projection setup
505
- * @return {number}
506
- */
507
- get aspect_ratio() {
508
- return this.#internal_resolution.x / this.#internal_resolution.y;
509
- }
510
-
511
- /**
512
- * TODO rework ping-ping buffer usage to release old buffer when no longer needed. Can reach much better resource utilization that way. Same for all other TAA-like techniques
513
- * @type {GPUTextureContext[]}
514
- */
515
- #textures_depth = new Array(2);
516
-
517
- /**
518
- *
519
- * @returns {GPUTextureContext}
520
- */
521
- get texture_depth_current() {
522
- const tx = this.#textures_depth;
523
-
524
- return tx[this.#frame_count % tx.length];
525
- }
526
-
527
- /**
528
- *
529
- * @returns {GPUTextureContext}
530
- */
531
- get texture_depth_previous() {
532
- const tx = this.#textures_depth;
533
-
534
- return tx[(this.#frame_count - 1 + tx.length) % tx.length];
535
- }
536
-
537
- /**
538
- *
539
- * @type {GPUTextureContext[]}
540
- */
541
- #textures_taa_history = new Array(2);
542
-
543
- /**
544
- *
545
- * @returns {GPUTextureContext}
546
- */
547
- #get_texture_taa_history(x) {
548
- const tx = this.#textures_taa_history;
549
-
550
- return tx[(this.#frame_count - x + tx.length) % tx.length];
551
- }
552
-
553
-
554
- /**
555
- * @type {GPUTextureFormat}
556
- */
557
- #presentation_format = "rgba8unorm";
558
-
559
- /**
560
- * How many pixels to draw per screen pixel.
561
- * Typically, this is used to match physical screen resolution to virtual resolution.
562
- * On the high pixel density displays, CSS pixels usually take up more than one screen pixel.
563
- * @type {number}
564
- */
565
- #pixel_ratio = window.devicePixelRatio;
566
-
567
- /**
568
- *
569
- * @return {number}
570
- */
571
- get pixel_ratio() {
572
- return this.#pixel_ratio;
573
- }
574
-
575
- /**
576
- *
577
- * @param {number} ratio
578
- */
579
- set pixel_ratio(ratio) {
580
- assert.isNumber(ratio, 'ratio');
581
- assert.notNaN(ratio, 'ratio');
582
- assert.greaterThan(ratio, 0);
583
- assert.isFinite(ratio, 'ratio');
584
-
585
- if (ratio === this.#pixel_ratio) {
586
- // no change
587
- return;
588
- }
589
-
590
- this.#pixel_ratio = ratio;
591
-
592
- this.#update_resolution();
593
- }
594
-
595
- /**
596
- * The profile recording to feed, or null.
597
- *
598
- * **Assign one; the renderer never makes one.** The profiler is a leaf nothing in the engine
599
- * imports, so an application that does not mention it does not carry it — see
600
- * {@link GPUProfileSession}. This field and the null checks around it are the whole
601
- * integration.
602
- *
603
- * ```js
604
- * const session = new GPUProfileSession({ level: GPUProfileLevel.TIMING });
605
- *
606
- * renderer.profile_session = session;
607
- * session.start();
608
- * // ... frames ...
609
- * const bytes = session.stop();
610
- * renderer.profile_session = null;
611
- * ```
612
- *
613
- * @type {GPUProfileSession|null}
614
- */
615
- profile_session = null;
616
-
617
- /**
618
- * Increase the number of future debug frames by X
619
- */
620
- /**
621
- * Record work into the frame at a named point in it.
622
- *
623
- * The extension is called once per frame, when its phase comes round, and is handed the
624
- * {@link FrameContext} — the frame's graph and the typed records holding the handles that exist
625
- * at that moment. It records with the `graph_*` helpers exactly as the built-in passes do, and
626
- * everything it produces reaches the rest of the frame by publishing a handle into a record.
627
- *
628
- * Handles come from the records rather than from the renderer on purpose: the graph is what
629
- * knows which resources a pass touched, and work recorded around it cannot be ordered or aliased
630
- * correctly against the rest of the frame.
631
- *
632
- * @param {RenderExtension} extension
633
- * @returns {RenderExtension} `extension`, for handing back to {@link remove_extension}
634
- */
635
- add_extension(extension) {
636
- return this.#extensions.add(extension);
637
- }
638
-
639
- /**
640
- * Take an extension back out of the frame.
641
- *
642
- * @param {RenderExtension} extension
643
- * @returns {boolean} whether it was registered
644
- */
645
- remove_extension(extension) {
646
- return this.#extensions.remove(extension);
647
- }
648
-
649
- /**
650
- * @param {FramePhase} phase
651
- * @returns {number} how many extensions are registered on `phase`
652
- */
653
- extension_count(phase) {
654
- return this.#extensions.count(phase);
655
- }
656
-
657
-
658
- /**
659
- *
660
- * @type {Map<Scene, GPULightProbeVolumeRenderer>}
661
- */
662
- #probe_bakers = new Map();
663
-
664
-
665
- /**
666
- *
667
- * @type {Map<Scene, CascadedSceneSDF>}
668
- */
669
- #scene_sdfs = new Map();
670
-
671
- /**
672
- *
673
- * @param {Scene} scene
674
- * @return {CascadedSceneSDF}
675
- */
676
- obtains_scene_sdf(scene) {
677
- let sdf = this.#scene_sdfs.get(scene);
678
-
679
- if (sdf === undefined) {
680
- sdf = new CascadedSceneSDF(this.device);
681
- this.#scene_sdfs.set(scene, sdf);
682
- }
683
-
684
- return sdf;
685
- }
686
-
687
- /**
688
- * Used to instruct renderer that either the scene or camera has changed significantly
689
- * Primarily instructs resetting history on temporal accumulation
690
- */
691
- indicate_view_change() {
692
- this.#postprocess.reset_history();
693
-
694
- if (this.#path_tracer !== undefined) {
695
- this.#path_tracer.clear_history = true;
696
- }
697
-
698
- this.#taa.reset_history = true;
699
-
700
- if (this.#nss !== undefined) {
701
- this.#nss.reset_history = true;
702
- }
703
- }
704
-
705
- /**
706
- * For internal and debug use only
707
- * @param {Scene} scene
708
- * @returns {GPULightProbeVolumeRenderer}
709
- */
710
- getProbeRendererForScene(scene) {
711
-
712
- const scene_ctx = this.#scenes.obtain(scene);
713
-
714
- let baker = this.#probe_bakers.get(scene);
715
-
716
- if (baker === undefined) {
717
- baker = new GPULightProbeVolumeRenderer(this.#graphics, scene_ctx);
718
- this.#probe_bakers.set(scene, baker);
719
- }
720
-
721
- return baker;
722
- }
723
-
724
-
725
- /**
726
- *
727
- * @param {Scene} scene
728
- */
729
- update_lpv(scene) {
730
-
731
- //
732
- // let baker = this.getProbeRendererForScene(scene);
733
- //
734
- // baker.autoSetRaysPerProbe(1);
735
- // baker.bake();
736
-
737
- const scene_ctx = this.#scenes.obtain(scene);
738
-
739
- const graph = new FrameGraph("LPV");
740
-
741
- const cmd = ShadeGPUCommandContext.create(this.graphics, 'LPV');
742
-
743
- scene_ctx.light_probe_volume.atlas.graph_update({
744
- graph,
745
- scene: scene_ctx,
746
- graphics: this.graphics,
747
- update_ray_count: 100_000
748
- });
749
-
750
- cmd.encodeGraph(graph);
751
- cmd.finish();
752
- }
753
-
754
- /**
755
- * Compute deferred indirect specular and diffuse contributions
756
- * based on the active indirect lighting mode.
757
- *
758
- * @param {object} params
759
- * @param {FrameGraph} params.graph
760
- * @param {GPUViewContext} params.view_ctx
761
- * @param {GPUSceneContext} params.scene_ctx
762
- * @param {number} params.bent_normals - graph resource ID
763
- * @param {number} params.current_color_out - graph resource ID (scene color, needed for SSR)
764
- * @param {number} params.gr_texture_depth_current
765
- * @param {number} params.gr_texture_hzb
766
- * @param {number} params.gr_texture_material_albedo_ao
767
- * @param {number} params.gr_texture_pbr
768
- * @param {number} params.gr_texture_normal
769
- * @param {number} params.gr_texture_environment
770
- * @param {number} params.gr_velocity
771
- * @param {number} params.gr_occlusion_clip
772
- * @param {number} params.gr_buffer_camera_current
773
- * @param {number} params.gr_buffer_camera_previous
774
- * @param {Vector2} params.resolution
775
- * @returns {{indirect_specular: number, indirect_diffuse: number}}
776
- */
777
- #graph_indirect_lighting({
778
- graph,
779
- view_ctx,
780
- scene_ctx,
781
- bent_normals,
782
- current_color_out,
783
- //
784
- gr_texture_depth_current,
785
- gr_texture_hzb,
786
- gr_texture_material_albedo_ao,
787
- gr_texture_pbr,
788
- gr_texture_normal,
789
- gr_texture_environment,
790
- gr_velocity,
791
- gr_occlusion_clip,
792
- gr_buffer_camera_current,
793
- gr_buffer_camera_previous,
794
- resolution,
795
- }) {
796
-
797
- const mode = this.indirect_lighting_mode;
798
-
799
- let indirect_specular = -1;
800
- let indirect_diffuse = -1;
801
-
802
- const lpv = scene_ctx.light_probe_volume;
803
-
804
- //
805
- // ── SPECULAR ────────────────────────────────────────────
806
- //
807
-
808
- // SSR replaces the specular IBL fallback when enabled.
809
- // NOTE: SSR is currently not supported in Brick4 mode — this is a known
810
- // limitation and will be addressed in a future update.
811
- if (this.feature_ssr_enabled && mode !== ShadeIndirectLightingMode.Brick4) {
812
-
813
- const ssr = this.#postprocess.ssr.graph_pass({
814
- graph,
815
- input_depth: gr_texture_depth_current,
816
- input_hzb: gr_texture_hzb,
817
- input_scene_color: current_color_out,
818
- input_albedo: gr_texture_material_albedo_ao,
819
- input_pbr: gr_texture_pbr,
820
- input_normal: gr_texture_normal,
821
- input_velocity: gr_velocity,
822
- input_occlusion: gr_occlusion_clip,
823
- input_environment: gr_texture_environment,
824
- camera_current: gr_buffer_camera_current,
825
- camera_previous: gr_buffer_camera_previous,
826
- lpv: mode === ShadeIndirectLightingMode.LPV ? lpv : undefined,
827
- resolution,
828
- });
829
-
830
- indirect_specular = ssr.denoised;
831
-
832
- } else if (mode === ShadeIndirectLightingMode.Brick4) {
833
-
834
- // Brick4 specular from volumetric lightmap
835
- [indirect_specular] = graph_image_pass({
836
- graph,
837
- shader: shader_brick4_specular,
838
- input_depth: gr_texture_depth_current,
839
- inputs: {
840
- tDepth: gr_texture_depth_current,
841
- tNormals: gr_texture_normal,
842
- tPBR: gr_texture_pbr,
843
- tSTBN_vec2: STATIC_GRAPHICS_ENGINE_ASSETS.stbn_vec2,
844
- camera: gr_buffer_camera_current,
845
- view: view_ctx.uniform_buffer.buffer,
846
- brick4: scene_ctx.volumetric_light_map.buffer,
847
- },
848
- output_resolution: view_ctx.resolution,
849
- });
850
-
851
- } else {
852
- // IBL / LPV fallback — environment map specular
853
- [indirect_specular] = graph_image_pass({
854
- graph,
855
- shader: shader_specular_IBL,
856
- input_depth: gr_texture_depth_current,
857
- inputs: {
858
- tBentNormals: bent_normals,
859
- tNormals: gr_texture_normal,
860
- tDepth: gr_texture_depth_current,
861
- tPBR: gr_texture_pbr,
862
- tEnvironment: gr_texture_environment,
863
- camera: gr_buffer_camera_current,
864
- },
865
- output_resolution: view_ctx.resolution,
866
- });
867
- }
868
-
869
- //
870
- // ── DIFFUSE ─────────────────────────────────────────────
871
- //
872
-
873
- switch (mode) {
874
-
875
- case ShadeIndirectLightingMode.IBL:
876
- // Environment map irradiance
877
- [indirect_diffuse] = graph_image_pass({
878
- graph,
879
- shader: shader_diffuse_IBL,
880
- input_depth: gr_texture_depth_current,
881
- inputs: {
882
- tBentNormals: bent_normals,
883
- tGBufferAlbedo: gr_texture_material_albedo_ao,
884
- tEnvironment: gr_texture_environment,
885
- },
886
- output_resolution: view_ctx.resolution,
887
- });
888
- break;
889
-
890
- case ShadeIndirectLightingMode.Brick4:
891
- // Brick4 diffuse from volumetric lightmap
892
- [indirect_diffuse] = graph_image_pass({
893
- graph,
894
- shader: shader_brick4_diffuse,
895
- input_depth: gr_texture_depth_current,
896
- inputs: {
897
- tDepth: gr_texture_depth_current,
898
- tBentNormals: bent_normals,
899
- tAlbedoAO: gr_texture_material_albedo_ao,
900
- tSTBN_vec2: STATIC_GRAPHICS_ENGINE_ASSETS.stbn_vec2,
901
- camera: gr_buffer_camera_current,
902
- view: view_ctx.uniform_buffer.buffer,
903
- brick4: scene_ctx.volumetric_light_map.buffer,
904
- },
905
- output_resolution: view_ctx.resolution,
906
- });
907
- break;
908
-
909
- case ShadeIndirectLightingMode.LPV:
910
- // Light Probe Volume diffuse
911
- [indirect_diffuse] = graph_image_pass({
912
- graph,
913
- shader: shader_diffuse_LPV,
914
- input_depth: gr_texture_depth_current,
915
- inputs: {
916
- camera: gr_buffer_camera_current,
917
- tDepth: gr_texture_depth_current,
918
- tBentNormals: bent_normals,
919
- tGBufferAlbedo: gr_texture_material_albedo_ao,
920
- //
921
- lpv_atlas_radiance: lpv.atlas.texture_radiance,
922
- lpv_atlas_depth: lpv.atlas.texture_depth,
923
- //
924
- lpv_lookup: lpv.buffer_mesh_bvh,
925
- lpv_metadata: lpv.buffer_metadata,
926
- lpv_mesh: lpv.buffer_mesh,
927
- lpv_probes: lpv.buffer_probes,
928
- },
929
- output_resolution: view_ctx.resolution,
930
- });
931
- break;
932
- }
933
-
934
- return { indirect_specular, indirect_diffuse };
935
- }
936
-
937
- /**
938
- * @type {PostProcess}
939
- */
940
- #postprocess
941
-
942
- /**
943
- * @type {ReSTIRDI}
944
- */
945
- #restir_di
946
-
947
- /**
948
- * ReSTIR DI subsystem — exposed for runtime tuning (e.g. GUI toggles like
949
- * `use_screen_space_shadow`, `m_initial`).
950
- * @returns {ReSTIRDI}
951
- */
952
- get restir_di() {
953
- return this.#restir_di;
954
- }
955
-
956
- /**
957
- *
958
- * @type {TAA}
959
- */
960
- #taa = new TAA();
961
-
962
- /**
963
- * Lazily constructed in {@link initialize} once a graphics context is
964
- * available — NSS owns persistent GPU textures, so it can't be a
965
- * field initializer like {@link #taa}.
966
- * @type {NSS | undefined}
967
- */
968
- #nss
969
-
970
- /**
971
- * Selects which temporal-AA / upscaler runs at the temporal-resolve
972
- * stage. Defaults to {@link ShadeUpscalerType.TAA}; assign
973
- * {@link ShadeUpscalerType.NSS} to use the bundled neural upscaler
974
- * (no extra setup — the NSS instance ships with placeholder weights).
975
- * @type {ShadeUpscalerType}
976
- */
977
- upscale_type = ShadeUpscalerType.TAA;
978
-
979
- /**
980
- * Public read access to the NSS instance. Lazily constructed on
981
- * first access, which is also when the bundled weights blob is
982
- * decoded — so the cost of selecting NSS is amortized to a single
983
- * frame.
984
- * @returns {NSS}
985
- */
986
- get nss() {
987
- if (this.#nss === undefined) {
988
- assert.defined(this.#graphics, 'graphics context not yet initialized — call Renderer.initialize() first');
989
- this.#nss = new NSS(this.#graphics);
990
-
991
- // First-time setup: align the jitter sequence size with the
992
- // current upscale ratio. Subsequent resolution changes are
993
- // picked up by #update_internal_resolution.
994
- const out_w = this.#output_resolution.x;
995
- const in_w = this.#internal_resolution.x;
996
- if (out_w > 0 && in_w > 0) {
997
- const upscale_ratio = out_w / in_w;
998
- this.#nss.jitter_sequence_size = NSS.recommended_jitter_sequence_size(upscale_ratio);
999
- }
1000
- }
1001
- return this.#nss;
1002
- }
1003
-
1004
- #device_lost = false;
1005
-
1006
- /**
1007
- * Handles event when GPUDevice is lost
1008
- * @param {GPUDeviceLostInfo} info
1009
- */
1010
- #handle_device_lost(info) {
1011
- this.#device_lost = true;
1012
-
1013
- if (info.reason === "destroyed") {
1014
- // most likely renderer was destroyed, this is expected behavior
1015
- // TODO check if renderer owns the device, if not, log a warning
1016
- return;
1017
- }
1018
-
1019
- console.error('GPUDevice lost', info);
1020
-
1021
- // Everything the renderer built lives on the device that just went away, so there is
1022
- // nothing to carry over and no attempt to (R6). Whoever is hosting this gets told, and a
1023
- // reload is the way back.
1024
- this.onDeviceFailure.send1(ShadeDeviceFailure.device_lost(info.message ?? info.reason ?? ""));
1025
- }
1026
-
1027
- #hdr_supported = false;
1028
-
1029
- /**
1030
- * What's the peak brightness of the display?
1031
- * Only valid for HDR.
1032
- *
1033
- * @type {number}
1034
- */
1035
- #display_peak_brightness_nits = 1000;
1036
-
1037
- #update_presentation_format() {
1038
-
1039
- const format8bit = navigator.gpu.getPreferredCanvasFormat();
1040
-
1041
- const format = this.#hdr_supported ? "rgba16float" : format8bit;
1042
-
1043
- if (format === this.#presentation_format) {
1044
- return;
1045
- }
1046
-
1047
- this.#presentation_format = format;
1048
-
1049
- this.#context_needs_update = true;
1050
- }
1051
-
1052
- /**
1053
- * Needs to be a lambda, because we use it as a listener.
1054
- */
1055
- #update_hdr_support = () => {
1056
- const isHDR = window.matchMedia("(dynamic-range: high)").matches;
1057
-
1058
- const previous_value = this.#hdr_supported;
1059
-
1060
-
1061
- this.#hdr_supported = isHDR;
1062
-
1063
- if (isHDR) {
1064
- // Currently, there is no way to interrogate this from the browser, so going with an assumption
1065
- this.#display_peak_brightness_nits = 1000;
1066
- } else {
1067
- // Assume SDR nits
1068
- this.#display_peak_brightness_nits = 80;
1069
- }
1070
-
1071
- if (isHDR === previous_value) {
1072
- // no change
1073
- return;
1074
- }
1075
-
1076
- console.log(`HDR support: ${isHDR ? 'enabled' : 'disabled'}`);
1077
-
1078
- this.#update_presentation_format();
1079
-
1080
- this.#context_needs_update = true;
1081
- }
1082
-
1083
- /**
1084
- *
1085
- * @param {GPUCanvasContext} [context] Optional, if not provided - one will be created.
1086
- * @param {GPUDevice} [device] Optional, if not provided - one will be created.
1087
- * @param {number} [pixelRatio] Optiona, if not provided - will be taken from browser context
1088
- */
1089
- async initialize({
1090
- context,
1091
- device,
1092
- pixelRatio = window.devicePixelRatio,
1093
- } = {}) {
1094
-
1095
- if (!('gpu' in navigator)) {
1096
- throw new Error('navigator.gpu not available — WebGPU disabled or unsupported');
1097
- }
1098
-
1099
- this.#update_presentation_format();
1100
- this.#update_hdr_support();
1101
-
1102
- if (context === undefined) {
1103
- const canvas = document.createElement('canvas');
1104
- canvas.width = window.innerWidth;
1105
- canvas.height = window.innerHeight;
1106
- // Sensible default styling so a freshly-appended canvas covers
1107
- // the viewport without depending on the host page's CSS reset.
1108
- // Override `style` after `initialize()` returns if the host
1109
- // page wants the canvas embedded somewhere else.
1110
- canvas.style.cssText = 'position:fixed;inset:0;width:100vw;height:100vh;display:block';
1111
-
1112
- context = canvas.getContext('webgpu');
1113
-
1114
- if (context === null) {
1115
- throw new Error('Failed to bind GPUCanvasContext');
1116
- }
1117
- }
1118
-
1119
- if (device === undefined) {
1120
- // no device present, let's create one
1121
-
1122
- const gpu = navigator.gpu;
1123
-
1124
- if (gpu === undefined) {
1125
- throw ShadeDeviceFailure.webgpu_unavailable();
1126
- }
1127
-
1128
- const adapter = await gpu.requestAdapter({
1129
- powerPreference: "high-performance",
1130
- });
1131
-
1132
- if (adapter === null) {
1133
- throw ShadeDeviceFailure.adapter_unavailable();
1134
- }
1135
-
1136
- if (adapter.isFallbackAdapter) {
1137
- // see https://www.w3.org/TR/webgpu/#dom-gpurequestadapteroptions-forcefallbackadapter
1138
- // fallback device is typically a software implementation and is going to be slow as sin
1139
- console.warn('GPU provided a fallback adapter (typically because no other appropriate adapter was available). Fallback adapter is typically a software implementation and will be slow.');
1140
- }
1141
-
1142
- // log details of the adapter
1143
- console.log(`GPU adapter is ${adapter.info.vendor}/${adapter.info.architecture}, device='${adapter.info.device}', description='${adapter.info.description}'`);
1144
-
1145
- // console.warn(`Buffer size limit: ${number_format_by_thousands(adapter.limits.maxBufferSize)}`);
1146
- //
1147
- // console.warn('adapter limits:', adapter.limits);
1148
-
1149
- const maxStorageBuffersPerShaderStage = adapter.limits.maxStorageBuffersPerShaderStage;
1150
-
1151
- if (maxStorageBuffersPerShaderStage < 10) {
1152
- throw ShadeDeviceFailure.below_floor(
1153
- `requires at least 10 storage buffers per shader stage, adapter offers ${maxStorageBuffersPerShaderStage}`
1154
- );
1155
- }
1156
-
1157
- const requiredFeatures = [
1158
- // required for indirect draw that's used extensively in Shade
1159
- WebGPUExtensionType.IndirectFirstInstance,
1160
- // required for OIT (might be unavailable)
1161
- WebGPUExtensionType.Float32Blendable,
1162
- ];
1163
-
1164
- // add features if they are available
1165
- const optional_desired = [
1166
- // Profiling only, and some browsers withhold it on hardware that is otherwise
1167
- // fine — so it is taken when offered and the timers go quiet when it is not
1168
- // (E7, sponsor 2026-08-16). Requiring it would refuse to start on those browsers
1169
- // for the sake of a feature the game does not need to run.
1170
- WebGPUExtensionType.TimestampQuery,
1171
- WebGPUExtensionType.Subgroups,
1172
- WebGPUExtensionType.TextureFormatsTier1,
1173
- ];
1174
-
1175
- // valid required features
1176
- for (const feature of requiredFeatures) {
1177
- if (!adapter.features.has(feature)) {
1178
- throw ShadeDeviceFailure.below_floor(`adapter does not support required feature '${feature}'`);
1179
- }
1180
- }
1181
-
1182
- for (const feature of optional_desired) {
1183
- if (adapter.features.has(feature)) {
1184
- requiredFeatures.push(feature);
1185
- }
1186
- }
1187
-
1188
-
1189
- device = await adapter.requestDevice({
1190
- requiredLimits: {
1191
- // required for large G-buffers
1192
- maxColorAttachmentBytesPerSample: 32,
1193
-
1194
- /*
1195
- grab the largest buffer limit we can get, default limits are super-low
1196
- */
1197
- maxBufferSize: adapter.limits.maxBufferSize,
1198
- maxStorageBufferBindingSize: adapter.limits.maxStorageBufferBindingSize,
1199
-
1200
- maxStorageBuffersPerShaderStage: 10,
1201
- },
1202
- requiredFeatures
1203
- });
1204
-
1205
- // NOTE: according to spec (as of 2025/09/19) - adapter can only be used to create one device, after which it becomes "consumed"
1206
- // see https://www.w3.org/TR/webgpu/#adapters
1207
-
1208
- // TODO obtained device might be "lost" if something goes wrong, would make sense to check for that
1209
- }
1210
-
1211
- device.lost.then(info => {
1212
- this.#handle_device_lost(info);
1213
- })
1214
-
1215
- if (context === undefined) {
1216
- const canvas = document.createElement('canvas');
1217
- canvas.width = window.innerWidth;
1218
- canvas.height = window.innerHeight;
1219
-
1220
- context = canvas.getContext('webgpu');
1221
-
1222
- if (context === null) {
1223
- throw new Error('Failed to bind GPUCanvasContext');
1224
- }
1225
- }
1226
-
1227
- assert.ok(device.features.has("indirect-first-instance"), '"indirect-first-instance" feature needs to be enabled for non-zero firstInstance values to be used.')
1228
- assert.isInstanceOf(context, GPUCanvasContext, 'context', 'GPUCanvasContext');
1229
-
1230
- this.context = context;
1231
- this.device = device;
1232
-
1233
- this.#pixel_ratio = pixelRatio;
1234
-
1235
- // clientWidth/clientHeight are 0 for a canvas that is not attached to the DOM,
1236
- // which is always the case for the renderer-owned canvas created above.
1237
- // Fall back to the backing-store size so that #configure_context doesn't
1238
- // overwrite the just-set canvas size with the 1x1 minimum resolution.
1239
- this.#size.set(
1240
- context.canvas.clientWidth || context.canvas.width,
1241
- context.canvas.clientHeight || context.canvas.height
1242
- );
1243
-
1244
- this.#update_output_resolution();
1245
-
1246
- this.#graphics = new GraphicsContext(device);
1247
-
1248
- const graphics = this.#graphics;
1249
-
1250
- await graphics.initialize();
1251
-
1252
-
1253
- this.#scenes = new SceneManager(graphics);
1254
-
1255
- this.#cameras = new CameraManager(this.device);
1256
- this.#views = new ViewManager(graphics, this.#cameras, this.#scenes);
1257
-
1258
- const resolution_internal = this.#internal_resolution.asArray();
1259
-
1260
- for (let i = 0; i < this.#textures_depth.length; i++) {
1261
-
1262
- this.#textures_depth[i] = graphics.textures.contextFromDescriptor(TextureDescriptor.from({
1263
- label: `Depth ${i}`,
1264
- size: resolution_internal,
1265
- format: 'depth32float',
1266
- mipLevelCount: G_BUFFER_MIP_LEVELS,
1267
- usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_SRC,
1268
- }));
1269
- }
1270
-
1271
-
1272
- const resolution_out = this.#output_resolution.asArray();
1273
-
1274
- for (let i = 0; i < this.#textures_taa_history.length; i++) {
1275
-
1276
- this.#textures_taa_history[i] = graphics.textures.contextFromDescriptor(TextureDescriptor.from({
1277
- label: `Color ${i}`,
1278
- size: resolution_out,
1279
- format: "rgba16float",
1280
- mipLevelCount: 1,
1281
- // STORAGE_BINDING is required for the NSS postprocess
1282
- // compute shader to write here. TAA continues to use
1283
- // RENDER_ATTACHMENT — the flags coexist on the same
1284
- // texture and the active upscaler picks its preferred
1285
- // write path each frame.
1286
- usage: GPUTextureUsage.RENDER_ATTACHMENT
1287
- | GPUTextureUsage.TEXTURE_BINDING
1288
- | GPUTextureUsage.STORAGE_BINDING
1289
- | GPUTextureUsage.COPY_SRC,
1290
- }));
1291
- }
1292
-
1293
- this.#autoexposure = new GPUCameraExposureManager(device);
1294
- this.#depth_of_field = new DepthOfField(device);
1295
- this.#depth_of_field_unreal = new DepthOfFieldU(device);
1296
- this.#motion_blur = new MotionBlur();
1297
-
1298
- this.#postprocess = new PostProcess(this.#graphics);
1299
-
1300
- this.#restir_di = new ReSTIRDI(this.#graphics);
1301
-
1302
- this.#configure_context();
1303
- this.init_render_targets();
1304
-
1305
- window.matchMedia("(dynamic-range: high)").addEventListener("change", this.#update_hdr_support);
1306
-
1307
- }
1308
-
1309
- /**
1310
- * Cleanup
1311
- */
1312
- destroy() {
1313
-
1314
- window.matchMedia("(dynamic-range: high)").removeEventListener("change", this.#update_hdr_support);
1315
- }
1316
-
1317
-
1318
- /**
1319
- * @type {RenderTarget}
1320
- */
1321
- #vis_render_target;
1322
-
1323
- init_render_targets() {
1324
- const vis_rt = new RenderTarget();
1325
- this.#vis_render_target = vis_rt;
1326
-
1327
- const textures = this.#graphics.textures;
1328
-
1329
- // TODO these can be moved to frame graph instead and managed in a transient manner
1330
- const internal_resolution_array = this.#internal_resolution.asArray();
1331
-
1332
- vis_rt.color_attachments = [
1333
- textures.contextFromDescriptor(TextureDescriptor.from({
1334
- size: internal_resolution_array,
1335
- format: "r32uint",
1336
- usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING
1337
- })),
1338
- textures.contextFromDescriptor(TextureDescriptor.from({
1339
- size: internal_resolution_array,
1340
- format: "r32uint",
1341
- usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING
1342
- })),
1343
- ];
1344
-
1345
- vis_rt.depth_attachment = this.#textures_depth[0];
1346
-
1347
- }
1348
-
1349
- /**
1350
- * If set to true, will force {@link #configure_context} on next render
1351
- * @type {boolean}
1352
- */
1353
- #context_needs_update = false;
1354
-
1355
- #configure_context() {
1356
- const context = this.context;
1357
-
1358
- const resolution = this.#output_resolution;
1359
-
1360
- context.canvas.width = resolution.x;
1361
- context.canvas.height = resolution.y;
1362
-
1363
- // canvas must be scaled on-screen differently from resolution to account for pixel ratio
1364
- const size = this.#size;
1365
- context.canvas.style.width = `${size.x}px`;
1366
- context.canvas.style.height = `${size.y}px`;
1367
-
1368
- const preferred_color_space = 'display-p3';
1369
-
1370
-
1371
- const config = {
1372
- device: this.device,
1373
- format: this.#presentation_format,
1374
- alphaMode: 'opaque',
1375
- colorSpace: preferred_color_space,
1376
- toneMapping: {
1377
- // see https://www.w3.org/TR/webgpu/#dom-gpucanvastonemappingmode-extended
1378
- mode: this.#hdr_supported ? "extended" : "standard"
1379
- }
1380
- };
1381
-
1382
-
1383
- try {
1384
- context.configure(config);
1385
- } catch (e) {
1386
- // try fall-back colorspace
1387
- context.configure({
1388
- ...config,
1389
- colorSpace: 'srgb'
1390
- });
1391
- }
1392
-
1393
- }
1394
-
1395
- #apply_size() {
1396
- const out_w = this.#output_resolution.x;
1397
- const out_h = this.#output_resolution.y;
1398
-
1399
- this.#textures_taa_history.forEach(t => t.resize(out_w, out_h));
1400
-
1401
-
1402
- this.#context_needs_update = true;
1403
- }
1404
-
1405
-
1406
- #update_internal_resolution() {
1407
- const out_w = this.#output_resolution.x;
1408
- const out_h = this.#output_resolution.y;
1409
-
1410
- const dimension_limit = this.device.limits.maxTextureDimension2D;
1411
-
1412
- const irs = this.#internal_resolution_scale;
1413
-
1414
- const _iw = clamp(Math.floor(out_w * irs), INTERNAL_RESOLUTION_MIN, dimension_limit);
1415
- const _ih = clamp(Math.floor(out_h * irs), INTERNAL_RESOLUTION_MIN, dimension_limit);
1416
-
1417
- this.#internal_resolution.set(_iw, _ih);
1418
-
1419
- // figure out exact x/y resolution scale
1420
- const irs_x_inv = out_w / _iw;
1421
- const irs_y_int = out_h / _ih;
1422
-
1423
- // we need to make TAA sequence long enough to provide full coverage over output resolution texels
1424
- const taa_sequence_scale = Math.max(1, irs_x_inv * irs_y_int);
1425
-
1426
- const upscale_factor = 1 / irs;
1427
-
1428
- // shrink the sequence as upscale factor increases
1429
- // we lose crispness of the edges, but we have to trade it to get faster convergence
1430
- const base_sequence_size = remap(
1431
- 1, 2,
1432
- 16, 4,
1433
- clamp(upscale_factor, 1, 2),
1434
- );
1435
-
1436
- this.#taa.jitter_sequence_size = Math.ceil(base_sequence_size * taa_sequence_scale);
1437
-
1438
- // ARM's NSS expects `8 * upscale_ratio^2` jitter phases. Apply the
1439
- // same coverage scaling as TAA so DPR-mismatch resolutions still
1440
- // get full coverage. Only applied if the NSS instance has been
1441
- // created — no point spinning it up just to set a number.
1442
- if (this.#nss !== undefined) {
1443
- const nss_base = NSS.recommended_jitter_sequence_size(upscale_factor);
1444
- this.#nss.jitter_sequence_size = Math.ceil(nss_base * taa_sequence_scale);
1445
- }
1446
-
1447
- const in_w = this.#internal_resolution.x;
1448
- const in_h = this.#internal_resolution.y;
1449
-
1450
- this.#textures_depth.forEach(t => {
1451
- t.resize(in_w, in_h)
1452
- });
1453
-
1454
- this.#vis_render_target.resize(in_w, in_h);
1455
-
1456
- // resizing destroys BOTH ping-pong depth textures, including the one holding last
1457
- // frame's depth — disocclusion/SSAO would read a zeroed "previous depth" this frame
1458
- // and silently corrupt temporal history. The external resize() path resets history
1459
- // via indicate_view_change(); internal-resolution changes (DRS steps) must too.
1460
- this.indicate_view_change();
1461
-
1462
- this.#internal_resolution_needs_update = false;
1463
- }
1464
-
1465
- #update_output_resolution() {
1466
- const size = this.#size;
1467
- const pixel_ratio = this.#pixel_ratio;
1468
-
1469
- const dimension_limit = this.device.limits.maxTextureDimension2D;
1470
-
1471
- // limits are there to prevent crashing out
1472
- const w = clamp(Math.ceil(size.x * pixel_ratio), 1, dimension_limit);
1473
- const h = clamp(Math.ceil(size.y * pixel_ratio), 1, dimension_limit);
1474
-
1475
- this.#output_resolution.set(w, h);
1476
-
1477
- this.#internal_resolution_needs_update = true;
1478
- }
1479
-
1480
- /**
1481
- * Make sure to resize at the start of the frame to avoid flicker
1482
- *
1483
- * @param {number} x
1484
- * @param {number} y
1485
- */
1486
- resize(x, y) {
1487
- assert.isNonNegativeInteger(x, 'x');
1488
- assert.isNonNegativeInteger(y, 'y');
1489
-
1490
- const size = this.#size;
1491
-
1492
- if (size.x === x && size.y === y) {
1493
- // no change
1494
- return;
1495
- }
1496
-
1497
- size.set(x, y);
1498
-
1499
- this.#update_resolution();
1500
- }
1501
-
1502
- /**
1503
- * Does not check for changes, so make sure to call this sparingly
1504
- */
1505
- #update_resolution() {
1506
-
1507
- this.#update_output_resolution();
1508
-
1509
- if (this.#internal_resolution_needs_update) {
1510
- this.#update_internal_resolution();
1511
- }
1512
-
1513
- this.#apply_size();
1514
-
1515
- // drop history buffers to prevent artifacts
1516
- this.indicate_view_change();
1517
- }
1518
-
1519
- /**
1520
- * Bring the canvas context up to date with the size the renderer is drawing at.
1521
- *
1522
- * **Only {@link render} calls this, and that is the point.** Configuring a context resizes the
1523
- * canvas and invalidates the texture it last handed out, so it has to happen before the frame
1524
- * asks for one — and a frame going somewhere other than the canvas must not do it at all, or
1525
- * every offscreen picture would resize the page's canvas to its own size and back.
1526
- */
1527
- #ensure_context_configured() {
1528
- this.#update_resolution_if_needed();
1529
-
1530
- if (this.#context_needs_update) {
1531
- this.#configure_context();
1532
- this.#context_needs_update = false;
1533
- }
1534
- }
1535
-
1536
- #update_resolution_if_needed() {
1537
- if (this.#internal_resolution_needs_update) {
1538
- this.#update_internal_resolution();
1539
- }
1540
- }
1541
-
1542
- #begin_frame() {
1543
-
1544
- this.#update_resolution_if_needed();
1545
-
1546
- this.#graphics.update();
1547
-
1548
- // Virtual texture maintenance: apply arrived pages (budgeted
1549
- // uploads), flush page-table dirty rects and stack info, issue
1550
- // streaming loads. Queue-ordered before this frame's submits, so
1551
- // the material pass samples a consistent table+cache snapshot.
1552
- if (this.feature_virtual_textures) {
1553
- this.#graphics.virtual_textures.update();
1554
- }
1555
-
1556
- // cycle depth attachment
1557
- this.#vis_render_target.depth_attachment = this.texture_depth_current;
1558
- this.#postprocess.update(this.#frame_count);
1559
-
1560
- // Advance whichever upscaler we're going to ask for jitter on this
1561
- // frame. Both share the same Halton(2, 3) sequence; we only tick
1562
- // the active one to avoid spinning up NSS just to drive a counter.
1563
- if (this.upscale_type === ShadeUpscalerType.NSS) {
1564
- const nss = this.nss;
1565
- nss.frame_count = this.#frame_count;
1566
- nss.frame_index = this.#frame_count;
1567
- } else {
1568
- this.#taa.frame_index = this.#frame_count;
1569
- }
1570
- }
1571
-
1572
- #end_frame() {
1573
- this.#frame_count++;
1574
-
1575
- // dispatch event
1576
- this.onFrameFinished.send1(this.#frame_count);
1577
- }
1578
-
1579
- /**
1580
- * @type {AccumulatingPathTracer}
1581
- */
1582
- #path_tracer;
1583
-
1584
- get path_tracer() {
1585
- if (this.#path_tracer === undefined) {
1586
- this.#path_tracer = new AccumulatingPathTracer(this.#graphics);
1587
- }
1588
-
1589
- return this.#path_tracer;
1590
- }
1591
-
1592
- /**
1593
- * Draw a frame onto the canvas this renderer is bound to.
1594
- *
1595
- * The canvas is one target among others: this is {@link render_to_target} with the canvas's
1596
- * current texture as the target, and nothing else.
1597
- *
1598
- * @param {PerspectiveCamera} camera
1599
- * @param {Scene} scene
1600
- * @param {number} [time_delta_seconds]
1601
- * @returns {boolean} whether frame was rendered, will return false if previous frame hasn't finished yet
1602
- */
1603
- render(
1604
- camera,
1605
- scene,
1606
- time_delta_seconds = 0.01666
1607
- ) {
1608
- if (this.#device_lost) {
1609
- // device is lost, can't render and asking the context for a texture would throw
1610
- return false;
1611
- }
1612
-
1613
- this.#ensure_context_configured();
1614
-
1615
- const canvas_texture = this.context.getCurrentTexture();
1616
-
1617
- return this.render_to_target(
1618
- camera,
1619
- scene,
1620
- time_delta_seconds,
1621
- GPUTextureContext.fromTexture(canvas_texture, this.device)
1622
- );
1623
- }
1624
-
1625
- /**
1626
- * Draw a frame into a texture of the caller's choosing.
1627
- *
1628
- * **The target says where the picture goes, not how big it is.** Everything the frame is built
1629
- * out of — the G-buffer, the visibility buffer, the depth ping-pong, the temporal history — is
1630
- * sized from {@link output_resolution}, so a target has to be that size; a caller wanting a
1631
- * different one calls {@link resize} first and puts the size back afterwards. Rendering into a
1632
- * texture the caller owns is what makes a frame readable: a canvas texture is configured by the
1633
- * presentation path and cannot carry `COPY_SRC`, and one of these can.
1634
- *
1635
- * @param {PerspectiveCamera} camera
1636
- * @param {Scene} scene
1637
- * @param {number} time_delta_seconds
1638
- * @param {GPUTextureContext} target must match {@link output_resolution}
1639
- * @returns {boolean} whether frame was rendered, will return false if previous frame hasn't finished yet
1640
- */
1641
- render_to_target(
1642
- camera,
1643
- scene,
1644
- time_delta_seconds,
1645
- target
1646
- ) {
1647
- assert.defined(target, 'target');
1648
- assert.equal(target.isGPUTextureContext, true, 'target.isGPUTextureContext !== true');
1649
-
1650
- if (this.#device_lost) {
1651
- // device is lost, can't render
1652
- return false;
1653
- }
1654
-
1655
- this.#begin_frame();
1656
-
1657
-
1658
- if (this.indirect_lighting_mode === ShadeIndirectLightingMode.LPV) {
1659
- this.update_lpv(scene);
1660
- }
1661
-
1662
- const view = View.from(camera, scene);
1663
- view.label = "Main View";
1664
- const view_ctx = this.#views.obtain(view);
1665
-
1666
- const graphics = this.#graphics;
1667
-
1668
- // Shadow allocation + per-light shadow_id assignment happens inside
1669
- // GPULightCollection.update (which view_ctx.update will trigger via
1670
- // GPUSceneContext.update below), so by the time we reach select_for_draw the
1671
- // light records on the GPU already carry their up-to-date shadow_id. Forward the
1672
- // feature flag so process_lights inside lights.update can evict everything when
1673
- // the renderer has shadows turned off — keeps CASTS_SHADOW_BIT cleared on every
1674
- // light record without further plumbing.
1675
- const sm = view_ctx.scene.lights.shadow_context;
1676
- sm.enabled = this.#feature_shadows_enabled;
1677
- // Which point-light shadow generator to use this frame; a flip triggers a rebuild of
1678
- // existing point maps inside process_lights (run via view_ctx.update above/below).
1679
- sm.use_tetrahedron_point_shadows = this.feature_tetrahedron_point_shadows;
1680
-
1681
- const taa = this.#taa;
1682
-
1683
- // Whichever upscaler is going to consume the temporal sequence
1684
- // also has to dictate the jitter applied to the camera projection.
1685
- // Both share Halton(2, 3); they just drive different jitter
1686
- // sequence sizes via #update_internal_resolution.
1687
- const jitter_source = this.upscale_type === ShadeUpscalerType.NSS
1688
- ? this.nss
1689
- : taa;
1690
-
1691
- const resolution_internal = this.#internal_resolution;
1692
- {
1693
- const jitter_x = jitter_source.Jitter[0];
1694
- const jitter_y = jitter_source.Jitter[1];
1695
-
1696
- view_ctx.setJitter(jitter_x, jitter_y);
1697
- view_ctx.setViewportSize(resolution_internal.x, resolution_internal.y);
1698
- view_ctx.setUpscaleRatio(
1699
- this.#output_resolution.x / resolution_internal.x,
1700
- this.#output_resolution.y / resolution_internal.y
1701
- );
1702
- // 2x offsets because the offsets are in NDC (-1, 1)
1703
- view_ctx.camera.setViewportOffset(
1704
- (2 * jitter_x) / resolution_internal.x,
1705
- (2 * jitter_y) / resolution_internal.y
1706
- );
1707
-
1708
- }
1709
-
1710
- view_ctx.update(graphics);
1711
-
1712
- const command_ctx = ShadeGPUCommandContext.create(
1713
- graphics,
1714
- "Renderer/main-0"
1715
- );
1716
-
1717
- /**
1718
- * The frame recorder for this frame, or null when nothing is profiling.
1719
- * @type {GPUFrameRecorder|null}
1720
- */
1721
- let profile_recorder = null;
1722
-
1723
- if (this.profile_session !== null) {
1724
- // The session hands out the recorder; nothing here imports the profiler, which is what
1725
- // keeps it out of a bundle that never asks for it. Null when the session is not running.
1726
- profile_recorder = this.profile_session.begin_frame(this.#frame_count, performance.now());
1727
-
1728
- if (profile_recorder !== null) {
1729
- command_ctx.enable_profiling(profile_recorder, 0);
1730
- }
1731
- }
1732
-
1733
- // Per-frame animation tick runs before shadow allocation so
1734
- // animated transforms (joint poses, mesh.global from animated
1735
- // parents) are in the scene database by the time shadow
1736
- // culling samples it. No-op when nothing's registered.
1737
- view_ctx.scene.tick(command_ctx, time_delta_seconds);
1738
-
1739
- const viz_rt = this.#vis_render_target;
1740
-
1741
- // prepare shadows (process_lights already ran inside lights.update via view_ctx.update,
1742
- // so the GPU light records already carry their up-to-date shadow_id)
1743
- if (this.#feature_shadows_enabled) {
1744
- // Two-stage: (1) score+select which maps refresh this frame and publish their metadata,
1745
- // (2) rasterize the selected maps. The context internally dispatches to the right
1746
- // raster path per light type — directional/spot go direct, point lights do a cube
1747
- // pass plus octahedral remap — so we don't have to juggle job arrays out here.
1748
- // draw() also writes per-shadow records into the scene's GPU light database
1749
- // (shadow_point/shadow_spot/shadow_directional tables) via its owner reference.
1750
- sm.select_for_draw(camera, view_ctx.scene, view_ctx.frame_index, view_ctx.resolution);
1751
- sm.draw(command_ctx);
1752
- }
1753
-
1754
-
1755
- const graph = new FrameGraph("Shading");
1756
-
1757
- /*
1758
- The view is updated and nothing has been rasterized, so an extension here is doing the
1759
- per-frame compute that later phases depend on. There are no records yet — the frame has
1760
- built nothing to hand out.
1761
- */
1762
- const frame = new FrameContext(graph, view_ctx);
1763
-
1764
- frame.phase = FramePhase.FrameStart;
1765
-
1766
- this.#extensions.run(frame);
1767
-
1768
- // build main view rasterization job
1769
- const raster_main = new RasterizationJob();
1770
- raster_main.view_ctx = view_ctx;
1771
- raster_main.render_target = viz_rt;
1772
- raster_main.opaque_pass = viz_rasterization_opaque_pass_descriptor;
1773
- raster_main.alpha_tested_pass = viz_rasterization_alpha_tested_pass_descriptor;
1774
-
1775
- const gr_render_buckets = graph_rasterize_scene({
1776
- job: raster_main,
1777
- graph,
1778
- limits: graphics.collection_limits,
1779
- });
1780
-
1781
- // `let` rather than `const` because an extension at `AfterGBuffer` may publish replacements
1782
- let gr_viz_buffer_triangle = graph_import_texture(graph, this.#vis_render_target.color_attachments[0], "viz_triangle");
1783
- let gr_viz_buffer_mesh = graph_import_texture(graph, this.#vis_render_target.color_attachments[1], "viz_mesh");
1784
-
1785
- // Virtual texture feedback: derive per-pixel page usage from the viz
1786
- // buffer (no extra geometry pass) into a unique-request hash set and
1787
- // kick its async readback. No-op unless VT stacks are registered.
1788
- if (this.feature_virtual_textures) {
1789
- graphics.virtual_textures.graph_feedback({
1790
- graph,
1791
- view: view_ctx,
1792
- texture_viz_mesh: gr_viz_buffer_mesh,
1793
- texture_viz_triangle: gr_viz_buffer_triangle,
1794
- material_metadata_buffer: graphics.materials.metadata_table.buffer,
1795
- });
1796
- }
1797
-
1798
- // run materials
1799
- const mat_g = graphics.materials.graph_viz_render({
1800
- graph,
1801
- view: view_ctx,
1802
- texture_viz_mesh: gr_viz_buffer_mesh,
1803
- texture_viz_triangle: gr_viz_buffer_triangle,
1804
- });
1805
-
1806
- // update texture references
1807
- // `let` rather than `const` because a pass injected at `AfterGBuffer` may replace any of
1808
- // them; see the read-back below.
1809
- let gr_texture_pbr = mat_g.g_pbr;
1810
- let gr_texture_normal = mat_g.g_normal;
1811
- let gr_texture_material_albedo_ao = mat_g.g_albedo;
1812
- let gr_texture_material_emissive = mat_g.g_emissive;
1813
-
1814
- // do mips for G-buffer
1815
- // mipmap_nearest(command_ctx, this.texture_depth_current);
1816
- // this.gBuffer.mipmap(command_ctx);
1817
-
1818
- // Update lights position
1819
- command_ctx.pushDebugGroup("Shade");
1820
-
1821
- const resolution = resolution_internal.asArray();
1822
-
1823
- const scene_ctx = view_ctx.scene;
1824
- const lights = scene_ctx.lights;
1825
-
1826
-
1827
- const gr_texture_canvas = graph_import_texture(graph, target, "canvas");
1828
- let gr_texture_depth_current = graph_import_texture(graph, this.texture_depth_current, "depth");
1829
- const gr_buffer_camera_current = graph_import_buffer(graph, view_ctx.camera.gpu_buffer, "camera/current");
1830
- const gr_buffer_camera_previous = graph_import_buffer(graph, view_ctx.gpu_previous_camera_state.gpu_buffer, "camera/previous");
1831
- const gr_texture_hzb = graph_import_texture(graph, view_ctx.hierarchical_z_buffer.texture, "HZB");
1832
- const gr_texture_environment = graph_import_texture(graph, view_ctx.scene.lights.environment);
1833
-
1834
- const taa_history_0 = this.#get_texture_taa_history(0);
1835
- const taa_history_1 = this.#get_texture_taa_history(-1);
1836
-
1837
- const gr_texture_taa_history = graph_import_texture(graph, taa_history_0, "taa history");
1838
- const gr_texture_taa_out = graph_import_texture(graph, taa_history_1, "taa out");
1839
- let gr_texture_depth_previous = graph_import_texture(graph, this.texture_depth_previous, "depth previous");
1840
-
1841
- const gr_shadowmap_atlas = graph_import_texture(graph, sm.texture);
1842
-
1843
- // The frame's surface handles exist now, so this is where the records that carry them are
1844
- // published. There is no colour yet, which is what makes this the phase for G-buffer work.
1845
- frame.phase = FramePhase.AfterGBuffer;
1846
-
1847
- const record_gbuffer = frame.create(GBufferTextures);
1848
- const record_view_textures = frame.create(ViewTextures);
1849
-
1850
- record_gbuffer.albedo = gr_texture_material_albedo_ao;
1851
- record_gbuffer.normal = gr_texture_normal;
1852
- record_gbuffer.pbr = gr_texture_pbr;
1853
- record_gbuffer.emissive = gr_texture_material_emissive;
1854
-
1855
- record_view_textures.depth = gr_texture_depth_current;
1856
- record_view_textures.depth_previous = gr_texture_depth_previous;
1857
- record_view_textures.visibility_mesh = gr_viz_buffer_mesh;
1858
- record_view_textures.visibility_triangle = gr_viz_buffer_triangle;
1859
-
1860
- this.#extensions.run(frame);
1861
-
1862
- /*
1863
- `GBufferTextures` is in/out at this phase, and frozen after it. An extension that wants to
1864
- *change* surface properties — decals are the reason this exists — cannot blend into these
1865
- targets: two of the four are integer formats, and one texture cannot be a render attachment
1866
- and a sampled source in the same pass. So it reads them, writes replacements, and publishes
1867
- the new handles. Everything downstream carries what it left.
1868
-
1869
- Writing the originals in place would work by accident rather than by contract: a written
1870
- handle is a *renamed* clone of the same physical resource, so the change would land in the
1871
- texture the shading pass reads only because the graph happens to execute in insertion
1872
- order, with no dependency edge saying so. Threading the handles makes the edge real.
1873
- */
1874
- gr_texture_pbr = record_gbuffer.pbr;
1875
- gr_texture_normal = record_gbuffer.normal;
1876
- gr_texture_material_albedo_ao = record_gbuffer.albedo;
1877
- gr_texture_material_emissive = record_gbuffer.emissive;
1878
-
1879
- gr_texture_depth_current = record_view_textures.depth;
1880
- gr_texture_depth_previous = record_view_textures.depth_previous;
1881
- gr_viz_buffer_mesh = record_view_textures.visibility_mesh;
1882
- gr_viz_buffer_triangle = record_view_textures.visibility_triangle;
1883
-
1884
- // Velocity pass with three branches: rotation-reprojection
1885
- // background, rigid per-object foreground (mesh.global delta),
1886
- // and skinned per-vertex foreground (barycentric interpolation
1887
- // of the triangle's mesh-local `position_prev` written by
1888
- // skinning into the side-buffer the skinning context owns).
1889
- // Per-vertex limb deformation lands in the final pixel-space
1890
- // velocity, so TAA reads correct history for character animation.
1891
- const gr_scene_database_for_velocity = graph_import_buffer(
1892
- graph, scene_ctx.scene_database_buffer, "scene_database/velocity"
1893
- );
1894
- const gr_meshlet_metadata_for_velocity = graph_import_buffer(
1895
- graph, scene_ctx.geometries.meshlets.buffer_metadata, "meshlet_metadata/velocity"
1896
- );
1897
- const gr_meshlet_data_for_velocity = graph_import_buffer(
1898
- graph, scene_ctx.geometries.meshlets.buffer_data, "meshlet_data/velocity"
1899
- );
1900
- // Skinning side-buffers — both null when no SkinnedMesh has
1901
- // been registered. The velocity shader still references these
1902
- // bindings (the dormant per-vertex branch), so the bind group
1903
- // must supply *something*; use the scene_database buffer as a
1904
- // placeholder when skinning is inactive. The shader is told via
1905
- // `skinning_active` whether the bindings are real — when false
1906
- // it never reads them and forces the rigid path, so the
1907
- // placeholder is never sampled. (Binding the placeholder
1908
- // without that guard was the source of phantom velocity on
1909
- // static meshes: `prev_position_offsets[meshlet_id]` read an
1910
- // unrelated scene_database word, and any non-0xFFFFFFFF value
1911
- // sent a static triangle down the skinned branch.)
1912
- const skinning_ctx = scene_ctx.skinning;
1913
- const skinning_active = skinning_ctx.prev_position_offsets_buffer !== null
1914
- && skinning_ctx.prev_positions_buffer !== null;
1915
- const gr_prev_position_offsets = graph_import_buffer(
1916
- graph,
1917
- skinning_ctx.prev_position_offsets_buffer ?? scene_ctx.scene_database_buffer,
1918
- "prev_position_offsets/velocity",
1919
- );
1920
- const gr_prev_positions = graph_import_buffer(
1921
- graph,
1922
- skinning_ctx.prev_positions_buffer ?? scene_ctx.scene_database_buffer,
1923
- "prev_positions/velocity",
1924
- );
1925
-
1926
- let gr_velocity = graph_add_per_object_velocity({
1927
- graph,
1928
- texture_depth: gr_texture_depth_current,
1929
- texture_viz_mesh: gr_viz_buffer_mesh,
1930
- texture_viz_triangle: gr_viz_buffer_triangle,
1931
- buffer_scene_database: gr_scene_database_for_velocity,
1932
- buffer_meshlet_metadata: gr_meshlet_metadata_for_velocity,
1933
- buffer_meshlet_data: gr_meshlet_data_for_velocity,
1934
- buffer_prev_position_offsets: gr_prev_position_offsets,
1935
- buffer_prev_positions: gr_prev_positions,
1936
- skinning_active,
1937
- resolution,
1938
- view: view_ctx,
1939
- enable_mipmap: true
1940
- });
1941
-
1942
- // gr_velocity = graph_mipmap_nearest(graph, gr_velocity, G_BUFFER_MIP_LEVELS);
1943
-
1944
- let [gr_occlusion_clip] = graph_image_pass({
1945
- graph,
1946
- shader: shader_depth_occlusion_clip,
1947
- output_resolution: view_ctx.resolution,
1948
- // mipmaps are going to be necessary for half-resolution post-process passes
1949
- output_mipmaps: true,
1950
- inputs: {
1951
- camera_current: gr_buffer_camera_current,
1952
- camera_previous: gr_buffer_camera_previous,
1953
- DepthBuffer: gr_texture_depth_current,
1954
- PrevDepthBuffer: gr_texture_depth_previous,
1955
- VelocityBuffer: gr_velocity
1956
- }
1957
- });
1958
-
1959
- const light_clusters = graph_build_light_clusters({
1960
- graph,
1961
- lights: lights,
1962
- camera: view_ctx.camera,
1963
- hzb: gr_texture_hzb,
1964
- resolution: view_ctx.resolution,
1965
- });
1966
-
1967
- // Build the view's volumetric fog LUTs (participating media -> per-froxel lighting ->
1968
- // ray-marched integration). Needs the light clusters and shadow atlas. Built every frame so
1969
- // the transparency (OIT) pass always has a valid LUT to sample — an empty scene integrates
1970
- // to a no-op (transmittance 1, in-scatter 0). The opaque composite below is still skipped
1971
- // when the scene has no fog.
1972
- const has_volumetrics = view_ctx.scene.volumetrics.source.volumes.length > 0;
1973
-
1974
- const volumetrics = view_ctx.volumetrics.graph_update({
1975
- graph,
1976
- light_cluster_data: light_clusters.data,
1977
- light_cluster_lookup: light_clusters.lookup,
1978
- light_cluster_parameters: light_clusters.parameters,
1979
- shadowmap_atlas: gr_shadowmap_atlas,
1980
- });
1981
-
1982
- /**
1983
- *
1984
- * @type {number}
1985
- */
1986
- let current_color_out = -1;
1987
-
1988
- // ReSTIR DI — stochastic direct lighting of local (point+spot) lights.
1989
- // When enabled, resolve per-pixel point+spot radiance and shade with the
1990
- // ReSTIR deferred variant (no brute-force cluster loop). The variant is a
1991
- // separate compiled shader, selected here at the JS level rather than via
1992
- // a runtime branch inside the shader.
1993
- let deferred_shader = shader_deferred_main;
1994
-
1995
- const deferred_inputs = {
1996
- gBufferDepth: gr_texture_depth_current,
1997
- gBufferPBR: gr_texture_pbr,
1998
- gBufferNormal: gr_texture_normal,
1999
- gBufferAlbedo: gr_texture_material_albedo_ao,
2000
- gBufferEmissive: gr_texture_material_emissive,
2001
-
2002
- //
2003
- light_data: lights.buffer_data,
2004
- tEnvironment: gr_texture_environment,
2005
-
2006
- // light clusters
2007
- cluster_parameters: light_clusters.parameters,
2008
- cluster_lookup: light_clusters.lookup,
2009
- cluster_data: light_clusters.data,
2010
-
2011
- // shadows
2012
- shadowmapAtlas: gr_shadowmap_atlas,
2013
-
2014
- //
2015
- camera: view_ctx.camera.buffer,
2016
- view: view_ctx.uniform_buffer.buffer,
2017
- };
2018
-
2019
- if (this.feature_restir_di_enabled) {
2020
- deferred_shader = shader_deferred_main_restir;
2021
-
2022
- deferred_inputs.tRestirRadiance = this.#restir_di.execute({
2023
- graph,
2024
- view: view_ctx,
2025
- depth: gr_texture_depth_current,
2026
- pbr: gr_texture_pbr,
2027
- normal: gr_texture_normal,
2028
- albedo: gr_texture_material_albedo_ao,
2029
- emissive: gr_texture_material_emissive,
2030
- velocity: gr_velocity,
2031
- occlusion_clip: gr_occlusion_clip,
2032
- hzb: gr_texture_hzb,
2033
- cluster_parameters: light_clusters.parameters,
2034
- cluster_lookup: light_clusters.lookup,
2035
- cluster_data: light_clusters.data,
2036
- });
2037
- }
2038
-
2039
- // Main shading pass
2040
- [current_color_out] = graph_image_pass({
2041
- graph,
2042
- shader: deferred_shader,
2043
- input_depth: gr_texture_depth_current,
2044
- inputs: deferred_inputs,
2045
- output_resolution: view_ctx.resolution,
2046
- });
2047
-
2048
-
2049
- let bent_normals = -1;
2050
-
2051
- if (this.feature_ssao_enabled) {
2052
-
2053
- const ssao = this.#postprocess.ssao.graph_pass({
2054
- graph: graph,
2055
- frame_index: this.#frame_count,
2056
- input_depth: gr_texture_depth_current,
2057
- input_color: current_color_out,
2058
- input_depth_previous: gr_texture_depth_previous,
2059
- input_velocity: gr_velocity,
2060
- input_normal: gr_texture_normal,
2061
- input_occlusion: gr_occlusion_clip,
2062
- // NOTE: AO is blended into the G-buffer
2063
- output: gr_texture_material_albedo_ao,
2064
- camera: gr_buffer_camera_current,
2065
- resolution: resolution,
2066
- });
2067
-
2068
- gr_texture_material_albedo_ao = ssao.occlusion;
2069
- bent_normals = ssao.bent_normals;
2070
-
2071
- } else {
2072
-
2073
- // default to shading normals
2074
- bent_normals = gr_texture_normal;
2075
-
2076
- }
2077
-
2078
-
2079
- // Shade background
2080
- [current_color_out] = graph_image_pass({
2081
- graph,
2082
- shader: shader_background,
2083
- inputs: {
2084
- camera: view_ctx.camera.buffer,
2085
- view: view_ctx.uniform_buffer.buffer,
2086
- tEnvironment: gr_texture_environment,
2087
- },
2088
- input_depth: gr_texture_depth_current,
2089
- load_op: "load",
2090
- output: [current_color_out],
2091
- });
2092
-
2093
- {
2094
- // Fused brick4 path: skip the intermediate diffuse/specular targets and the
2095
- // separate resolve, doing it all in a single shader. SSR isn't compatible
2096
- // since it consumes the standalone specular target.
2097
- const use_fused_indirect = this.fused_indirect
2098
- && this.indirect_lighting_mode === ShadeIndirectLightingMode.Brick4
2099
- && !this.feature_ssr_enabled;
2100
-
2101
- if (use_fused_indirect) {
2102
-
2103
- [current_color_out] = graph_image_pass({
2104
- graph,
2105
- shader: shader_brick4_indirect_lighting,
2106
- output: [current_color_out],
2107
- input_depth: gr_texture_depth_current,
2108
- load_op: "load",
2109
- inputs: {
2110
- tDepth: gr_texture_depth_current,
2111
- tGBufferNormals: gr_texture_normal,
2112
- tBentNormals: bent_normals,
2113
- tGBufferAlbedo: gr_texture_material_albedo_ao,
2114
- tGBufferPBR: gr_texture_pbr,
2115
- tSTBN_vec2: STATIC_GRAPHICS_ENGINE_ASSETS.stbn_vec2,
2116
- view: view_ctx.uniform_buffer.buffer,
2117
- camera: gr_buffer_camera_current,
2118
- //
2119
- brick4: scene_ctx.volumetric_light_map.buffer,
2120
- tSplitSum: STATIC_GRAPHICS_ENGINE_ASSETS.split_sum,
2121
- },
2122
- });
2123
-
2124
- } else {
2125
-
2126
- const { indirect_specular, indirect_diffuse } = this.#graph_indirect_lighting({
2127
- graph,
2128
- view_ctx,
2129
- scene_ctx,
2130
- bent_normals,
2131
- current_color_out,
2132
- //
2133
- gr_texture_depth_current,
2134
- gr_texture_hzb,
2135
- gr_texture_material_albedo_ao,
2136
- gr_texture_pbr,
2137
- gr_texture_normal,
2138
- gr_texture_environment,
2139
- gr_velocity,
2140
- gr_occlusion_clip,
2141
- gr_buffer_camera_current,
2142
- gr_buffer_camera_previous,
2143
- resolution,
2144
- });
2145
-
2146
- // resolve indirect lighting
2147
- [current_color_out] = graph_image_pass({
2148
- graph,
2149
- shader: shader_resolve_indirect_lighting,
2150
- output: [current_color_out],
2151
- input_depth: gr_texture_depth_current,
2152
- load_op: "load",
2153
- inputs: {
2154
- tIndirectDiffuse: indirect_diffuse,
2155
- tIndirectSpecular: indirect_specular,
2156
- //
2157
- tGBufferNormals: gr_texture_normal,
2158
- tBentNormals: bent_normals,
2159
- tGBufferAlbedo: gr_texture_material_albedo_ao,
2160
- tGBufferPBR: gr_texture_pbr,
2161
- tDepth: gr_texture_depth_current,
2162
- //
2163
- camera: gr_buffer_camera_current,
2164
- //
2165
- tSplitSum: STATIC_GRAPHICS_ENGINE_ASSETS.split_sum,
2166
- },
2167
- });
2168
-
2169
- }
2170
-
2171
- // current_color_out = indirect_diffuse
2172
- // current_color_out = indirect_specular
2173
-
2174
- }
2175
-
2176
- // current_color_out = graph_decode_rgbe9995_to_rgb16float({
2177
- // graph,
2178
- // input:indirect_diffuse_near_field,
2179
- // resolution: view_ctx.resolution,
2180
- // });
2181
- //
2182
- // const [norm] = graph_image_pass({
2183
- // shader: shader_decode_octahedral_normal,
2184
- // inputs:{
2185
- // tInput: bent_normals,
2186
- // },
2187
- // graph,
2188
- // output_resolution: view_ctx.resolution,
2189
- // });
2190
- //
2191
- // [current_color_out] = graph_image_pass({
2192
- // graph,
2193
- // shader: shader_draw_normals,
2194
- // inputs:{
2195
- // tInput: norm,
2196
- // },
2197
- // output_resolution: view_ctx.resolution,
2198
- // });
2199
-
2200
- // Composite volumetric fog over the finalized opaque + background + indirect colour.
2201
- // A dedicated pass (not inline in the shading shaders) because indirect lighting is added
2202
- // in a separate additively-blended pass, so the full surface radiance only exists here.
2203
- // Runs before transparency (transparent surfaces blend over the fog) and before the main
2204
- // TAA (which then smooths the fog's per-pixel sampling noise).
2205
- if (has_volumetrics) {
2206
- [current_color_out] = graph_image_pass({
2207
- graph,
2208
- shader: shader_composite_volumetrics,
2209
- output_resolution: view_ctx.resolution,
2210
- inputs: {
2211
- tColor: current_color_out,
2212
- gBufferDepth: gr_texture_depth_current,
2213
- tVolumetrics: volumetrics.resolved,
2214
- tSTBN_vec3: STATIC_GRAPHICS_ENGINE_ASSETS.stbn_vec3,
2215
- volumetrics_metadata: volumetrics.metadata,
2216
- camera: view_ctx.camera.buffer,
2217
- view: view_ctx.uniform_buffer.buffer,
2218
- },
2219
- });
2220
- }
2221
-
2222
- /*
2223
- The frame has a colour for the first time, so this is where `SceneColor` is published. It is
2224
- republished before each later phase because the built-in passes between them replace it —
2225
- the record names which handle currently *means* the scene colour, and the graph already
2226
- holds the dependency edge underneath.
2227
- */
2228
- frame.phase = FramePhase.AfterLighting;
2229
-
2230
- const record_scene_color = frame.create(SceneColor);
2231
-
2232
- record_scene_color.color = current_color_out;
2233
-
2234
- this.#extensions.run(frame);
2235
-
2236
- current_color_out = record_scene_color.color;
2237
- gr_texture_depth_current = record_view_textures.depth;
2238
-
2239
- if (this.#feature_enabled_transparencies) {
2240
- // do transparent alpha pass
2241
- graph.push_scope("transparencies");
2242
-
2243
- current_color_out = graph_rasterize_meshes_transparent_oit({
2244
- graph,
2245
- buckets: gr_render_buckets,
2246
- view_ctx,
2247
- viewport: [0, 0, resolution_internal.x, resolution_internal.y],
2248
- color_texture: current_color_out,
2249
- depth_texture: gr_texture_depth_current,
2250
-
2251
- limits: this.graphics.collection_limits,
2252
-
2253
- light_cluster_data: light_clusters.data,
2254
- light_cluster_lookup: light_clusters.lookup,
2255
- light_cluster_parameters: light_clusters.parameters,
2256
-
2257
- shadowmap_atlas: gr_shadowmap_atlas,
2258
-
2259
- volumetrics_lut: volumetrics.resolved,
2260
- volumetrics_metadata: volumetrics.metadata,
2261
-
2262
- indirect_lighting_mode: this.indirect_lighting_mode,
2263
- });
2264
-
2265
- graph.pop_scope();
2266
- }
2267
-
2268
- frame.phase = FramePhase.AfterTransparency;
2269
-
2270
- record_scene_color.color = current_color_out;
2271
-
2272
- this.#extensions.run(frame);
2273
-
2274
- current_color_out = record_scene_color.color;
2275
- gr_texture_depth_current = record_view_textures.depth;
2276
-
2277
- // current_color_out = gr_texture_material_albedo_ao;
2278
-
2279
- if (this.feature_path_tracing_enabled) {
2280
- current_color_out = this.path_tracer.render({
2281
- graph,
2282
- view: view_ctx
2283
- });
2284
- }
2285
-
2286
- // Debug override: replace the post-shading color with a
2287
- // visualization of the velocity buffer via shader_debug_velocity.
2288
- // Direction is encoded as hue (red = +X, cyan = -X, etc.) and
2289
- // magnitude as brightness; the AO channel of the albedo+AO
2290
- // G-buffer modulates the static base so geometry shape is
2291
- // still readable where motion is zero or near-zero. Done
2292
- // BEFORE TAA so the chain stays well-formed; TAA blending
2293
- // the debug view is meaningless, but it's debug.
2294
- if (this.feature_velocity_debug_view) {
2295
- [current_color_out] = graph_image_pass({
2296
- graph,
2297
- shader: shader_debug_velocity,
2298
- inputs: {
2299
- tInput: gr_velocity,
2300
- tAlbedoAO: gr_texture_material_albedo_ao,
2301
- },
2302
- output_resolution: resolution_internal.asArray(),
2303
- });
2304
- }
2305
-
2306
- if (this.feature_taa_enabled) {
2307
-
2308
- if (this.upscale_type === ShadeUpscalerType.NSS) {
2309
- current_color_out = this.nss.graph_pass({
2310
- graph,
2311
- texture_color_current: current_color_out,
2312
- texture_depth_current: gr_texture_depth_current,
2313
- texture_velocity: gr_velocity,
2314
- texture_disocclusion_confidence: gr_occlusion_clip,
2315
- texture_color_history: gr_texture_taa_history,
2316
- texture_output: gr_texture_taa_out,
2317
- render_resolution: resolution_internal.asArray(),
2318
- output_resolution: this.#output_resolution.asArray(),
2319
- });
2320
- } else {
2321
- current_color_out = taa.graph_pass({
2322
- graph,
2323
- texture_output: gr_texture_taa_out,
2324
- texture_color_current: current_color_out,
2325
- texture_color_history: gr_texture_taa_history,
2326
- texture_velocity: gr_velocity,
2327
- texture_occlusion: gr_occlusion_clip,
2328
- camera_current: gr_buffer_camera_current,
2329
- camera_previous: gr_buffer_camera_previous,
2330
- });
2331
- }
2332
- }
2333
-
2334
- // Bokeh depth of field on the resolved HDR colour. Runs after
2335
- // TAA (blurs a clean, converged image — TAA's neighbourhood
2336
- // clamp would otherwise fight the defocus) and before motion
2337
- // blur / bloom, so out-of-focus highlights bloom and the bokeh
2338
- // carries through the rest of the post chain. Perspective-only:
2339
- // the thin-lens CoC has no meaning under orthographic.
2340
- if (this.feature_dof_enabled && camera.isPerspectiveCamera === true) {
2341
- // Both implementations share the same render() signature, so the
2342
- // call site is identical only the subsystem differs.
2343
- const dof = this.dof_algorithm === "unreal"
2344
- ? this.#depth_of_field_unreal
2345
- : this.#depth_of_field;
2346
-
2347
- current_color_out = dof.render({
2348
- graph,
2349
- input_color: current_color_out,
2350
- depth: gr_texture_depth_current,
2351
- camera,
2352
- camera_buffer: view_ctx.camera.buffer,
2353
- resolution: this.#output_resolution.asArray(),
2354
- });
2355
- }
2356
-
2357
- // Jimenez 2014 motion blur runs on the resolved-but-not-
2358
- // sharpened HDR colour. TAA has already converged the
2359
- // jittered samples; sharpening, bloom, and tonemap operate
2360
- // on the blurred output after this. Skipped when the toggle
2361
- // is off so the rest of the chain stays bit-identical.
2362
- if (this.feature_motion_blur_enabled) {
2363
- current_color_out = this.#motion_blur.render({
2364
- graph,
2365
- input_color: current_color_out,
2366
- velocity: gr_velocity,
2367
- depth: gr_texture_depth_current,
2368
- resolution: this.#output_resolution.asArray(),
2369
- });
2370
- }
2371
-
2372
- // TODO if TAA is disabled, and internal resolution is < 100% - we need to do upscale
2373
-
2374
- if (this.feature_sharpening_enabled) {
2375
- [current_color_out] = graph_image_pass({
2376
- graph,
2377
- shader: shader_ffx_rcas,
2378
- output_resolution: this.#output_resolution.asArray(),
2379
- inputs: {
2380
- tInput: current_color_out,
2381
- uSharpness: {
2382
- value: 0.8
2383
- }
2384
- }
2385
- });
2386
- }
2387
-
2388
- let exposure = -1;
2389
-
2390
- if (this.feature_bloom_enabled || this.feature_automatic_exposure_enabled) {
2391
- const bloom = graph_postprocess_bloom({
2392
- graph,
2393
- input: current_color_out,
2394
- resolution: this.#output_resolution.asArray(),
2395
- });
2396
-
2397
- if (this.feature_bloom_enabled) {
2398
- current_color_out = bloom.composited;
2399
- }
2400
-
2401
- if (this.feature_automatic_exposure_enabled) {
2402
- // TODO force time_delta_second to a very high value on view transition
2403
-
2404
- exposure = this.#autoexposure.update({
2405
- graph,
2406
- input_color: bloom.downsampled,
2407
- time_delta_seconds,
2408
- });
2409
- }
2410
-
2411
- }
2412
-
2413
-
2414
- if (this.feature_automatic_exposure_enabled === false) {
2415
- exposure = this.#autoexposure.unadapted({ graph });
2416
- }
2417
-
2418
-
2419
- // current_color_out = graph_draw_texture_as_rgba({
2420
- // graph,
2421
- // source: gr_shadowmap_atlas,
2422
- // resolution: this.#output_resolution.asArray(),
2423
- // });
2424
-
2425
- /*
2426
- Past the upscale: the colour published here is output-sized while the G-buffer beside it is
2427
- still internal-sized, and `FrameContext.resolution` reads whichever of them the phase draws
2428
- into rather than a number anybody wrote down. With `feature_taa_enabled === false` no
2429
- upscale happened and the two agree — which a constant could not express.
2430
- */
2431
- frame.phase = FramePhase.BeforePresent;
2432
-
2433
- record_scene_color.color = current_color_out;
2434
-
2435
- this.#extensions.run(frame);
2436
-
2437
- current_color_out = record_scene_color.color;
2438
-
2439
- if (this.#hdr_supported) {
2440
- [current_color_out] = graph_image_pass({
2441
- graph,
2442
- shader: shader_tonemap_HDR,
2443
- inputs: {
2444
- input_color: current_color_out,
2445
- settings: {
2446
- peak_nits: this.#display_peak_brightness_nits,
2447
- paper_white_nits: 100, // SDR spec is 80, but 100 has been accepted as de-facto in recent years
2448
- },
2449
- exposure
2450
- },
2451
- output: [gr_texture_canvas]
2452
- });
2453
- } else {
2454
- [current_color_out] = graph_image_pass({
2455
- graph,
2456
- shader: shader_tonemap_LDR,
2457
- inputs: {
2458
- input_color: current_color_out,
2459
- exposure
2460
- },
2461
- output: [gr_texture_canvas]
2462
- });
2463
- }
2464
-
2465
- /*
2466
- The canvas is written here and cannot be read: a texture may not be a render attachment and
2467
- a sampled source in the same pass. So what this phase carries is a `PresentTarget` with one
2468
- field and no colour to be tempted by — an extension that wants the finished image as input
2469
- finds that out at `get` time and belongs at `BeforePresent`.
2470
- */
2471
- frame.phase = FramePhase.Overlay;
2472
-
2473
- frame.create(PresentTarget).canvas = current_color_out;
2474
-
2475
- this.#extensions.run(frame);
2476
-
2477
- frame.close();
2478
-
2479
- if (profile_recorder !== null) {
2480
- // Subscribed before the graph runs; the recorder drops the handlers when it closes.
2481
- // A frame graph is single-use, so this never outlives the frame either way.
2482
- profile_recorder.attach_graph(graph);
2483
- }
2484
-
2485
- command_ctx.encodeGraph(graph);
2486
-
2487
- command_ctx.popDebugGroup();
2488
-
2489
- view_ctx.finish_frame(command_ctx);
2490
-
2491
- command_ctx.finish();
2492
-
2493
- if (profile_recorder !== null) {
2494
- /*
2495
- Waits on `profiling_absorbed`, not on `done`. `done` resolves from `onFinished`, which
2496
- fires synchronously at submit — the timings have not been read back yet at that point,
2497
- and closing there would commit an empty frame every time.
2498
- */
2499
- const recorder = profile_recorder;
2500
- const session = this.profile_session;
2501
-
2502
- command_ctx.profiling_absorbed.then(() => {
2503
- session.end_frame(recorder, performance.now());
2504
- });
2505
- }
2506
-
2507
- this.#end_frame();
2508
-
2509
- return true;
2510
- }
2511
- }
1
+ import { assert } from "../../core/assert.js";
2
+ import Signal from "../../core/events/signal/Signal.js";
3
+ import Vector2 from "../../core/geom/Vector2.js";
4
+ import { clamp } from "../../core/math/clamp.js";
5
+ import { remap } from "../../core/math/remap.js";
6
+ import { MetricCollection } from "../../engine/development/performance/MetricCollection.js";
7
+ import {
8
+ MetricCollectionConsoleMonitor
9
+ } from "../../engine/development/performance/monitor/MetricCollectionConsoleMonitor.js";
10
+ import { FrameGraph } from "../../engine/graphics/render/frame_graph/FrameGraph.js";
11
+ import { TextureDescriptor } from "../descriptor/texture/TextureDescriptor.js";
12
+ import { WebGPUExtensionType } from "../descriptor/WebGPUExtensionType.js";
13
+ import { ShadeDeviceFailure } from "../device/ShadeDeviceFailure.js";
14
+ import { ShadeGPUCommandContext } from "../device/ShadeGPUCommandContext.js";
15
+ import { CameraManager } from "./camera/CameraManager.js";
16
+ import { shader_background } from "./deferred/shader_background.js";
17
+ import { shader_composite_volumetrics } from "./deferred/shader_composite_volumetrics.js";
18
+ import { shader_deferred_main, shader_deferred_main_restir } from "./deferred/shader_deferred_main.js";
19
+ import { shader_tonemap_HDR } from "./deferred/shader_tonemap_HDR.js";
20
+ import { shader_tonemap_LDR } from "./deferred/shader_tonemap_LDR.js";
21
+ import { FrameContext } from "./extension/FrameContext.js";
22
+ import { FramePhase } from "./extension/FramePhase.js";
23
+ import { GBufferTextures } from "./extension/GBufferTextures.js";
24
+ import { PresentTarget } from "./extension/PresentTarget.js";
25
+ import { RenderExtensionRegistry } from "./extension/RenderExtensionRegistry.js";
26
+ import { SceneColor } from "./extension/SceneColor.js";
27
+ import { ViewTextures } from "./extension/ViewTextures.js";
28
+ import { G_BUFFER_MIP_LEVELS } from "./gbuffer/G_BUFFER_MIP_LEVELS.js";
29
+ import { shader_brick4_diffuse } from "./global_illumination/brick4/gpu/draw/shader_brick4_diffuse.js";
30
+ import {
31
+ shader_brick4_indirect_lighting
32
+ } from "./global_illumination/brick4/gpu/draw/shader_brick4_indirect_lighting.js";
33
+ import { shader_brick4_specular } from "./global_illumination/brick4/gpu/draw/shader_brick4_specular.js";
34
+ import { shader_diffuse_IBL } from "./global_illumination/ibl/shader_diffuse_IBL.js";
35
+ import { shader_specular_IBL } from "./global_illumination/ibl/shader_specular_IBL.js";
36
+ import { GPULightProbeVolumeRenderer } from "./global_illumination/lpv/bake/GPULightProbeVolumeRenderer.js";
37
+ import { shader_diffuse_LPV } from "./global_illumination/lpv/shader_diffuse_LPV.js";
38
+ import { shader_resolve_indirect_lighting } from "./global_illumination/shader_resolve_indirect_lighting.js";
39
+ import { GraphicsContext } from "./GraphicsContext.js";
40
+ import { graph_build_light_clusters } from "./light/cluster/graph_build_light_clusters.js";
41
+ import { AccumulatingPathTracer } from "./path_tracer/accumulating/AccumulatingPathTracer.js";
42
+ import { graph_postprocess_bloom } from "./postprocess/bloom/graph_postprocess_bloom.js";
43
+ import { shader_ffx_rcas } from "./postprocess/cas/shader_ffx_rcas.js";
44
+ import { DepthOfFieldU } from "./postprocess/dof/gather/DepthOfFieldU.js";
45
+ import { DepthOfField } from "./postprocess/dof/raymarch/DepthOfField.js";
46
+ import { GPUCameraExposureManager } from "./postprocess/eye/GPUCameraExposureManager.js";
47
+ import { MotionBlur } from "./postprocess/motion_blur/MotionBlur.js";
48
+ import { NSS } from "./postprocess/nss/NSS.js";
49
+ import { PostProcess } from "./postprocess/PostProcess.js";
50
+ import { shader_depth_occlusion_clip } from "./postprocess/taa/shader_depth_occlusion_clip.js";
51
+ import { TAA } from "./postprocess/taa/TAA.js";
52
+ import { graph_add_per_object_velocity } from "./postprocess/velocity/graph_add_per_object_velocity.js";
53
+ import { shader_debug_velocity } from "./postprocess/velocity/shader_debug_velocity.js";
54
+ import {
55
+ graph_rasterize_meshes_transparent_oit
56
+ } from "./rasterize/native/oit/graph_rasterize_meshes_transparent_oit.js";
57
+ import {
58
+ viz_rasterization_alpha_tested_pass_descriptor
59
+ } from "./rasterize/native/viz/viz_rasterization_alpha_tested_pass_descriptor.js";
60
+ import {
61
+ viz_rasterization_opaque_pass_descriptor
62
+ } from "./rasterize/native/viz/viz_rasterization_opaque_pass_descriptor.js";
63
+ import { RasterizationJob } from "./rasterize/RasterizationJob.js";
64
+ import { graph_rasterize_scene } from "./rasterize/standard/graph_rasterize_scene.js";
65
+ import { ReSTIRDI } from "./restir/di/ReSTIRDI.js";
66
+ import { SceneManager } from "./scene/SceneManager.js";
67
+ import { ShadeIndirectLightingMode } from "./ShadeIndirectLightingMode.js";
68
+ import { graph_image_pass } from "./shader/graph/graph_image_pass.js";
69
+ import { graph_import_buffer } from "./shader/graph/graph_import_buffer.js";
70
+ import { graph_import_texture } from "./shader/graph/graph_import_texture.js";
71
+ import { ShadeUpscalerType } from "./ShadeUpscalerType.js";
72
+ import { CascadedSceneSDF } from "./shadow/sdf/cascade/CascadedSceneSDF.js";
73
+ import { STATIC_GRAPHICS_ENGINE_ASSETS } from "./STATIC_GRAPHICS_ENGINE_ASSETS.js";
74
+ import { GPUTextureContext } from "./texture/GPUTextureContext.js";
75
+ import { RenderTarget } from "./texture/RenderTarget.js";
76
+ import { View } from "./view/View.js";
77
+ import { ViewManager } from "./view/ViewManager.js";
78
+
79
+ const METRICS = new MetricCollection();
80
+ METRICS.create({ name: 'frame_time' });
81
+
82
+ /**
83
+ * Depth and G-buffer textures carry {@link G_BUFFER_MIP_LEVELS} mip levels.
84
+ * WebGPU's createTexture validation requires mipLevelCount <= floor(log2(max(w,h))) + 1,
85
+ * so the internal resolution must never drop below 2^(G_BUFFER_MIP_LEVELS - 1)
86
+ * or texture allocation will fail.
87
+ * @type {number}
88
+ */
89
+ const INTERNAL_RESOLUTION_MIN = 1 << (G_BUFFER_MIP_LEVELS - 1);
90
+
91
+ MetricCollectionConsoleMonitor.from(METRICS);
92
+
93
+ export class Renderer {
94
+ /**
95
+ * Indexes current drawn frame
96
+ * @type {number}
97
+ */
98
+ #frame_count = 0;
99
+
100
+ get frame_count() {
101
+ return this.#frame_count;
102
+ }
103
+
104
+ /**
105
+ * @type {GPUCanvasContext}
106
+ */
107
+ context;
108
+
109
+ /**
110
+ * The HTMLCanvasElement (or OffscreenCanvas) bound to this renderer.
111
+ * If `initialize()` was called without a `context`, this is the canvas
112
+ * the renderer created — append it to the DOM to display the output.
113
+ *
114
+ * @returns {HTMLCanvasElement|OffscreenCanvas|undefined}
115
+ */
116
+ get canvas() {
117
+ return this.context?.canvas;
118
+ }
119
+
120
+ /**
121
+ * @type {GPUDevice}
122
+ */
123
+ device;
124
+
125
+ /**
126
+ * @type {GPUCameraExposureManager}
127
+ */
128
+ #autoexposure;
129
+
130
+ /**
131
+ * @type {SceneManager}
132
+ */
133
+ #scenes;
134
+
135
+ /**
136
+ * Only use for read-access
137
+ * @returns {SceneManager}
138
+ */
139
+ get scenes() {
140
+ return this.#scenes;
141
+ }
142
+
143
+ /**
144
+ * @type {CameraManager}
145
+ */
146
+ #cameras
147
+
148
+ /**
149
+ * @type {ViewManager}
150
+ */
151
+ #views
152
+
153
+
154
+ set feature_shadows_enabled(v) {
155
+ assert.isBoolean(v, 'v');
156
+ this.#feature_shadows_enabled = v;
157
+ }
158
+
159
+ get feature_shadows_enabled() {
160
+ return this.#feature_shadows_enabled;
161
+ }
162
+
163
+ /**
164
+ * Controls which indirect lighting technique is used for
165
+ * both deferred resolve and forward transparency passes.
166
+ * @type {ShadeIndirectLightingMode}
167
+ */
168
+ indirect_lighting_mode = ShadeIndirectLightingMode.IBL;
169
+
170
+ feature_ssr_enabled = false;
171
+ feature_ssao_enabled = true;
172
+ /**
173
+ * ReSTIR DI — stochastic screen-bounded direct shadowing of local
174
+ * (point+spot) lights. When on, the deferred pass skips its froxel cluster
175
+ * loop and consumes the ReSTIR-resolved radiance instead.
176
+ */
177
+ feature_restir_di_enabled = false;
178
+ /**
179
+ * Generate point-light shadows with the tetrahedral (4-face) path instead of the default
180
+ * cube (6-face) path. Both produce the same octahedral atlas encoding, so this is safe to
181
+ * flip at runtime and is meant for A/B comparison of the two generators. Pushed to the
182
+ * scene's shadow context each frame; see
183
+ * {@link GPUSceneShadowmapContext.use_tetrahedron_point_shadows}.
184
+ * @type {boolean}
185
+ */
186
+ feature_tetrahedron_point_shadows = false;
187
+ feature_bloom_enabled = true;
188
+ feature_automatic_exposure_enabled = true;
189
+
190
+ /**
191
+ * Fixed exposure, in f-stops, used when {@link feature_automatic_exposure_enabled} is off.
192
+ *
193
+ * Turning adaptation off without being able to set this leaves the frame at 2 stops, which is
194
+ * black for any scene the eye would otherwise have opened up for — so the flag alone is not
195
+ * usable. Anything comparing two renders wants adaptation off and this pinned: eye adaptation
196
+ * keeps drifting for seconds after a change, which makes two shots of the *same* setting differ
197
+ * by more than the change being judged.
198
+ *
199
+ * @returns {number}
200
+ */
201
+ get exposure_compensation() {
202
+ // the manager is built in initialize(); before that there is no value to report
203
+ return this.#autoexposure === undefined ? 0 : this.#autoexposure.exposure_compensation;
204
+ }
205
+
206
+ set exposure_compensation(v) {
207
+ assert.isNumber(v, 'exposure_compensation');
208
+ assert.defined(this.#autoexposure, 'autoexposure (set exposure_compensation after initialize)');
209
+
210
+ this.#autoexposure.exposure_compensation = v;
211
+ }
212
+
213
+ /**
214
+ * Virtual texture streaming (opt-in per material via
215
+ * {@link StandardShadeMaterial#vt_stack}). This flag is the system-wide
216
+ * kill switch: when off, the feedback pass and residency maintenance
217
+ * stop running — already-resident pages keep rendering, nothing new
218
+ * streams in. Costs nothing while no stack is registered.
219
+ * @type {boolean}
220
+ */
221
+ feature_virtual_textures = true;
222
+
223
+ #feature_taa_enabled = true;
224
+
225
+ get feature_taa_enabled() {
226
+ return this.#feature_taa_enabled;
227
+ }
228
+
229
+ /**
230
+ * While TAA is off nothing writes the history textures, but the frame counter that
231
+ * indexes them keeps advancing — re-enabling would blend with arbitrarily stale
232
+ * history of arbitrary parity. Reset temporal history on the transition.
233
+ * @param {boolean} v
234
+ */
235
+ set feature_taa_enabled(v) {
236
+ if (this.#feature_taa_enabled === v) {
237
+ return;
238
+ }
239
+
240
+ this.#feature_taa_enabled = v;
241
+ this.indicate_view_change();
242
+ }
243
+
244
+ /**
245
+ * Jimenez 2014 reconstruction-filter motion blur, runs between
246
+ * TAA and sharpening on the HDR colour. Reads the velocity buffer
247
+ * the same way TAA does — per-pixel pixel-space deltas — and
248
+ * scatter-gathers along the dilated tile velocity. Off by default
249
+ * because the reconstruction pass is a few-ms-budget item and not
250
+ * every scene needs it.
251
+ *
252
+ * @type {boolean}
253
+ */
254
+ feature_motion_blur_enabled = false;
255
+
256
+ /**
257
+ * Motion-blur subsystem (Jimenez 2014 reconstruction filter). A
258
+ * self-contained manager — same pattern as {@link #autoexposure} /
259
+ * {@link #depth_of_field} — that owns the motion-blur parameters
260
+ * (currently just `strength`). Constructed in init.
261
+ * @type {MotionBlur}
262
+ */
263
+ #motion_blur;
264
+
265
+ /**
266
+ * The motion-blur subsystem. Configure it via `renderer.motion_blur.*`
267
+ * (currently `strength`); toggle the effect with
268
+ * {@link feature_motion_blur_enabled}.
269
+ * @returns {MotionBlur}
270
+ */
271
+ get motion_blur() { return this.#motion_blur; }
272
+
273
+ /**
274
+ * Debug-only override: when true, the per-object velocity texture
275
+ * is drawn straight into the post-TAA color path so the screen
276
+ * shows the velocity buffer instead of the rendered image. Wired
277
+ * just before TAA — TAA then operates on the velocity texture,
278
+ * which is nonsense but cheap to set up. Default false.
279
+ *
280
+ * @type {boolean}
281
+ */
282
+ feature_velocity_debug_view = false;
283
+
284
+ /**
285
+ * When true, {@link path_tracer} replaces the rasterized+shaded color for the frame. The
286
+ * traced result still goes through TAA and tone mapping like any other color.
287
+ *
288
+ * The path tracer accumulates across frames itself, one tile per call, and resets whenever the
289
+ * camera moves. TAA on top of that is two temporal filters fighting over the same image — turn
290
+ * `feature_taa_enabled` off while this is on.
291
+ *
292
+ * This is the traversal-heaviest consumer of the TLAS — it binds `scene_ctx.tlas.buffer`
293
+ * directly — which is what made it the check that the GPU TLAS build traces correctly, and what
294
+ * makes it the first place a regression in that tree would show. Default false: it is a
295
+ * prototype-grade path, not a shipping render mode.
296
+ *
297
+ * @type {boolean}
298
+ */
299
+ feature_path_tracing_enabled = false;
300
+
301
+ /**
302
+ * Screen-space ray-marched depth of field — the Tiny Glade model
303
+ * (Stachowiak, GPC 2024; see {@link DepthOfField}): aperture sub-rays
304
+ * marched through the half-res depth/CoC buffer with nearest-hit
305
+ * occlusion, plus tilt-shift. Runs on the resolved HDR colour after TAA
306
+ * (which resolves the march's sample noise) and before motion blur. Off
307
+ * by default — a half-res march is a few-ms item, only worth it for a
308
+ * deliberate shallow-focus / diorama look. Configure via `renderer.dof`.
309
+ *
310
+ * @type {boolean}
311
+ */
312
+ feature_dof_enabled = false;
313
+
314
+ /**
315
+ * Depth-of-field subsystem (screen-space ray-marched). A self-contained
316
+ * manager — same pattern as {@link #autoexposure} — that owns all DoF
317
+ * parameters, focus state, and GPU buffers. Constructed in init.
318
+ * @type {DepthOfField}
319
+ */
320
+ #depth_of_field;
321
+
322
+ /**
323
+ * The depth-of-field subsystem. Configure it via `renderer.dof.*`
324
+ * (`f_number`, `quality`, the `focus*` helpers, `applyPreset`, …);
325
+ * toggle the effect with {@link feature_dof_enabled}.
326
+ * @returns {DepthOfField}
327
+ */
328
+ get dof() { return this.#depth_of_field; }
329
+
330
+ /**
331
+ * Which depth-of-field implementation runs when {@link feature_dof_enabled}
332
+ * is on. `"raymarch"` (default) is the screen-space ray-march
333
+ * ({@link DepthOfField}); `"unreal"` is the gather-based Diaphragm /
334
+ * Cinematic DoF ({@link DepthOfFieldU}) — half-res near/far gather with a
335
+ * foreground coverage bleed. Mutually exclusive by construction (only one
336
+ * runs at the single DoF call site).
337
+ * @type {"raymarch"|"unreal"}
338
+ */
339
+ dof_algorithm = "raymarch";
340
+
341
+ /**
342
+ * Unreal-style (Diaphragm / Cinematic) gather depth of field — a drop-in
343
+ * alternative to {@link #depth_of_field}, selected via {@link dof_algorithm}.
344
+ * Constructed in init.
345
+ * @type {DepthOfFieldU}
346
+ */
347
+ #depth_of_field_unreal;
348
+
349
+ /**
350
+ * The Unreal-style depth-of-field subsystem. Configure it via
351
+ * `renderer.dof_unreal.*` and select it with `renderer.dof_algorithm = "unreal"`.
352
+ * @returns {DepthOfFieldU}
353
+ */
354
+ get dof_unreal() { return this.#depth_of_field_unreal; }
355
+
356
+ /**
357
+ * When true and {@link indirect_lighting_mode} is Brick4, run a single fused
358
+ * pass that produces the resolved indirect lighting directly (combining the
359
+ * brick4 diffuse, brick4 specular and indirect resolve passes). Trades a
360
+ * bit of cache pressure inside the pass for substantially less memory
361
+ * bandwidth: no intermediate rgba16float diffuse/specular targets, the
362
+ * g-buffer is read once, and a single brick4 probe pair is shared between
363
+ * the diffuse and specular evaluations.
364
+ *
365
+ * SSR is mutually exclusive with the fused path (it needs the standalone
366
+ * specular target as input), so when SSR is enabled the split path is used.
367
+ * @type {boolean}
368
+ */
369
+ fused_indirect = true;
370
+
371
+ /**
372
+ * RCAS
373
+ * @type {boolean}
374
+ */
375
+ feature_sharpening_enabled = true;
376
+
377
+ #feature_shadows_enabled = true;
378
+ #feature_enabled_transparencies = true;
379
+
380
+ /**
381
+ *
382
+ * @return {ViewManager}
383
+ */
384
+ get views() {
385
+ return this.#views;
386
+ }
387
+
388
+ /**
389
+ * @type {GraphicsContext}
390
+ */
391
+ #graphics;
392
+
393
+ /**
394
+ *
395
+ * @return {GraphicsContext}
396
+ */
397
+ get graphics() {
398
+ return this.#graphics;
399
+ }
400
+
401
+
402
+ /**
403
+ *
404
+ * @type {Signal<number>}
405
+ */
406
+ /**
407
+ * Extensions an outside caller has put into the frame, by phase.
408
+ *
409
+ * @type {RenderExtensionRegistry}
410
+ */
411
+ #extensions = new RenderExtensionRegistry();
412
+
413
+ /**
414
+ * Raised when there is no usable device — the browser has no WebGPU, the hardware is below the
415
+ * floor, or a working device was lost while running. Carries a {@link ShadeDeviceFailure}.
416
+ *
417
+ * The floor is deliberate and there are no fallbacks (D6/I-8), so telling the player plainly is
418
+ * the whole of what the engine owes here. Loss is not recovered from (R6): everything built on
419
+ * the device went with it, and the honest response is a message and a reload.
420
+ *
421
+ * @type {Signal<ShadeDeviceFailure>}
422
+ */
423
+ onDeviceFailure = new Signal();
424
+
425
+ onFrameFinished = new Signal();
426
+
427
+ /**
428
+ * Fraction of the output resolution.
429
+ * Controls {@link #internal_resolution}.
430
+ * If this is set to 0.5 for example - internal resolution will be 50% of the output resolution.
431
+ * @type {number}
432
+ */
433
+ #internal_resolution_scale = 1;
434
+
435
+ /**
436
+ *
437
+ * @type {boolean}
438
+ */
439
+ #internal_resolution_needs_update = true;
440
+
441
+ /**
442
+ *
443
+ * @param {number} v
444
+ */
445
+ set internal_resolution_scale(v) {
446
+ assert.isNumber(v, 'v');
447
+ assert.notNaN(v, 'v');
448
+ assert.greaterThan(v, 0);
449
+ assert.isFinite(v, 'v');
450
+
451
+ if (this.#internal_resolution_scale === v) {
452
+ // no change
453
+ return;
454
+ }
455
+
456
+ this.#internal_resolution_scale = v;
457
+
458
+ // schedule resolution recalculation
459
+ this.#internal_resolution_needs_update = true;
460
+ }
461
+
462
+ /**
463
+ *
464
+ * @returns {number}
465
+ */
466
+ get internal_resolution_scale() {
467
+ return this.#internal_resolution_scale;
468
+ }
469
+
470
+ /**
471
+ * This is the resolution that the rendering happens at before upscaling.
472
+ * Derived from input resolution via {@link internal_resolution_scale}
473
+ * @type {Vector2}
474
+ */
475
+ #internal_resolution = new Vector2(1, 1);
476
+
477
+
478
+ /**
479
+ * Output viewport size
480
+ * @type {Vector2}
481
+ */
482
+ #size = new Vector2(1, 1);
483
+
484
+ /**
485
+ * Output resolution.
486
+ * Equal to {@link size} * {@link pixel_ratio}
487
+ * Don't write directly
488
+ * @type {Vector2}
489
+ * @see {#size}
490
+ * @see {#pixel_ratio}
491
+ */
492
+ #output_resolution = new Vector2(1, 1);
493
+
494
+ /**
495
+ *
496
+ * @returns {Vector2}
497
+ */
498
+ get output_resolution() {
499
+ return this.#output_resolution.clone();
500
+ }
501
+
502
+ /**
503
+ * width/height
504
+ * Useful for camera projection setup
505
+ * @return {number}
506
+ */
507
+ get aspect_ratio() {
508
+ return this.#internal_resolution.x / this.#internal_resolution.y;
509
+ }
510
+
511
+ /**
512
+ * TODO rework ping-ping buffer usage to release old buffer when no longer needed. Can reach much better resource utilization that way. Same for all other TAA-like techniques
513
+ * @type {GPUTextureContext[]}
514
+ */
515
+ #textures_depth = new Array(2);
516
+
517
+ /**
518
+ *
519
+ * @returns {GPUTextureContext}
520
+ */
521
+ get texture_depth_current() {
522
+ const tx = this.#textures_depth;
523
+
524
+ return tx[this.#frame_count % tx.length];
525
+ }
526
+
527
+ /**
528
+ *
529
+ * @returns {GPUTextureContext}
530
+ */
531
+ get texture_depth_previous() {
532
+ const tx = this.#textures_depth;
533
+
534
+ return tx[(this.#frame_count - 1 + tx.length) % tx.length];
535
+ }
536
+
537
+ /**
538
+ *
539
+ * @type {GPUTextureContext[]}
540
+ */
541
+ #textures_taa_history = new Array(2);
542
+
543
+ /**
544
+ *
545
+ * @returns {GPUTextureContext}
546
+ */
547
+ #get_texture_taa_history(x) {
548
+ const tx = this.#textures_taa_history;
549
+
550
+ return tx[(this.#frame_count - x + tx.length) % tx.length];
551
+ }
552
+
553
+
554
+ /**
555
+ * @type {GPUTextureFormat}
556
+ */
557
+ #presentation_format = "rgba8unorm";
558
+
559
+ /**
560
+ * How many pixels to draw per screen pixel.
561
+ * Typically, this is used to match physical screen resolution to virtual resolution.
562
+ * On the high pixel density displays, CSS pixels usually take up more than one screen pixel.
563
+ * @type {number}
564
+ */
565
+ #pixel_ratio = window.devicePixelRatio;
566
+
567
+ /**
568
+ *
569
+ * @return {number}
570
+ */
571
+ get pixel_ratio() {
572
+ return this.#pixel_ratio;
573
+ }
574
+
575
+ /**
576
+ *
577
+ * @param {number} ratio
578
+ */
579
+ set pixel_ratio(ratio) {
580
+ assert.isNumber(ratio, 'ratio');
581
+ assert.notNaN(ratio, 'ratio');
582
+ assert.greaterThan(ratio, 0);
583
+ assert.isFinite(ratio, 'ratio');
584
+
585
+ if (ratio === this.#pixel_ratio) {
586
+ // no change
587
+ return;
588
+ }
589
+
590
+ this.#pixel_ratio = ratio;
591
+
592
+ this.#update_resolution();
593
+ }
594
+
595
+ /**
596
+ * The profile recording to feed, or null.
597
+ *
598
+ * **Assign one; the renderer never makes one.** The profiler is a leaf nothing in the engine
599
+ * imports, so an application that does not mention it does not carry it — see
600
+ * {@link GPUProfileSession}. This field and the null checks around it are the whole
601
+ * integration.
602
+ *
603
+ * ```js
604
+ * const session = new GPUProfileSession({ level: GPUProfileLevel.TIMING });
605
+ *
606
+ * renderer.profile_session = session;
607
+ * session.start();
608
+ * // ... frames ...
609
+ * const bytes = session.stop();
610
+ * renderer.profile_session = null;
611
+ * ```
612
+ *
613
+ * @type {GPUProfileSession|null}
614
+ */
615
+ profile_session = null;
616
+
617
+ /**
618
+ * Increase the number of future debug frames by X
619
+ */
620
+ /**
621
+ * Record work into the frame at a named point in it.
622
+ *
623
+ * The extension is called once per frame, when its phase comes round, and is handed the
624
+ * {@link FrameContext} — the frame's graph and the typed records holding the handles that exist
625
+ * at that moment. It records with the `graph_*` helpers exactly as the built-in passes do, and
626
+ * everything it produces reaches the rest of the frame by publishing a handle into a record.
627
+ *
628
+ * Handles come from the records rather than from the renderer on purpose: the graph is what
629
+ * knows which resources a pass touched, and work recorded around it cannot be ordered or aliased
630
+ * correctly against the rest of the frame.
631
+ *
632
+ * @param {RenderExtension} extension
633
+ * @returns {RenderExtension} `extension`, for handing back to {@link remove_extension}
634
+ */
635
+ add_extension(extension) {
636
+ return this.#extensions.add(extension);
637
+ }
638
+
639
+ /**
640
+ * Take an extension back out of the frame.
641
+ *
642
+ * @param {RenderExtension} extension
643
+ * @returns {boolean} whether it was registered
644
+ */
645
+ remove_extension(extension) {
646
+ return this.#extensions.remove(extension);
647
+ }
648
+
649
+ /**
650
+ * @param {FramePhase} phase
651
+ * @returns {number} how many extensions are registered on `phase`
652
+ */
653
+ extension_count(phase) {
654
+ return this.#extensions.count(phase);
655
+ }
656
+
657
+
658
+ /**
659
+ *
660
+ * @type {Map<Scene, GPULightProbeVolumeRenderer>}
661
+ */
662
+ #probe_bakers = new Map();
663
+
664
+
665
+ /**
666
+ *
667
+ * @type {Map<Scene, CascadedSceneSDF>}
668
+ */
669
+ #scene_sdfs = new Map();
670
+
671
+ /**
672
+ *
673
+ * @param {Scene} scene
674
+ * @return {CascadedSceneSDF}
675
+ */
676
+ obtains_scene_sdf(scene) {
677
+ let sdf = this.#scene_sdfs.get(scene);
678
+
679
+ if (sdf === undefined) {
680
+ sdf = new CascadedSceneSDF(this.device);
681
+ this.#scene_sdfs.set(scene, sdf);
682
+ }
683
+
684
+ return sdf;
685
+ }
686
+
687
+ /**
688
+ * Used to instruct renderer that either the scene or camera has changed significantly
689
+ * Primarily instructs resetting history on temporal accumulation
690
+ */
691
+ indicate_view_change() {
692
+ this.#postprocess.reset_history();
693
+
694
+ if (this.#path_tracer !== undefined) {
695
+ this.#path_tracer.clear_history = true;
696
+ }
697
+
698
+ this.#taa.reset_history = true;
699
+
700
+ if (this.#nss !== undefined) {
701
+ this.#nss.reset_history = true;
702
+ }
703
+ }
704
+
705
+ /**
706
+ * For internal and debug use only
707
+ * @param {Scene} scene
708
+ * @returns {GPULightProbeVolumeRenderer}
709
+ */
710
+ getProbeRendererForScene(scene) {
711
+
712
+ const scene_ctx = this.#scenes.obtain(scene);
713
+
714
+ let baker = this.#probe_bakers.get(scene);
715
+
716
+ if (baker === undefined) {
717
+ baker = new GPULightProbeVolumeRenderer(this.#graphics, scene_ctx);
718
+ this.#probe_bakers.set(scene, baker);
719
+ }
720
+
721
+ return baker;
722
+ }
723
+
724
+
725
+ /**
726
+ *
727
+ * @param {Scene} scene
728
+ */
729
+ update_lpv(scene) {
730
+
731
+ //
732
+ // let baker = this.getProbeRendererForScene(scene);
733
+ //
734
+ // baker.autoSetRaysPerProbe(1);
735
+ // baker.bake();
736
+
737
+ const scene_ctx = this.#scenes.obtain(scene);
738
+
739
+ const graph = new FrameGraph("LPV");
740
+
741
+ const cmd = ShadeGPUCommandContext.create(this.graphics, 'LPV');
742
+
743
+ scene_ctx.light_probe_volume.atlas.graph_update({
744
+ graph,
745
+ scene: scene_ctx,
746
+ graphics: this.graphics,
747
+ update_ray_count: 100_000
748
+ });
749
+
750
+ cmd.encodeGraph(graph);
751
+ cmd.finish();
752
+ }
753
+
754
+ /**
755
+ * Compute deferred indirect specular and diffuse contributions
756
+ * based on the active indirect lighting mode.
757
+ *
758
+ * @param {object} params
759
+ * @param {FrameGraph} params.graph
760
+ * @param {GPUViewContext} params.view_ctx
761
+ * @param {GPUSceneContext} params.scene_ctx
762
+ * @param {number} params.bent_normals - graph resource ID
763
+ * @param {number} params.current_color_out - graph resource ID (scene color, needed for SSR)
764
+ * @param {number} params.gr_texture_depth_current
765
+ * @param {number} params.gr_texture_hzb
766
+ * @param {number} params.gr_texture_material_albedo_ao
767
+ * @param {number} params.gr_texture_pbr
768
+ * @param {number} params.gr_texture_normal
769
+ * @param {number} params.gr_texture_environment
770
+ * @param {number} params.gr_velocity
771
+ * @param {number} params.gr_occlusion_clip
772
+ * @param {number} params.gr_buffer_camera_current
773
+ * @param {number} params.gr_buffer_camera_previous
774
+ * @param {Vector2} params.resolution
775
+ * @returns {{indirect_specular: number, indirect_diffuse: number}}
776
+ */
777
+ #graph_indirect_lighting({
778
+ graph,
779
+ view_ctx,
780
+ scene_ctx,
781
+ bent_normals,
782
+ current_color_out,
783
+ //
784
+ gr_texture_depth_current,
785
+ gr_texture_hzb,
786
+ gr_texture_material_albedo_ao,
787
+ gr_texture_pbr,
788
+ gr_texture_normal,
789
+ gr_texture_environment,
790
+ gr_velocity,
791
+ gr_occlusion_clip,
792
+ gr_buffer_camera_current,
793
+ gr_buffer_camera_previous,
794
+ resolution,
795
+ }) {
796
+
797
+ const mode = this.indirect_lighting_mode;
798
+
799
+ let indirect_specular = -1;
800
+ let indirect_diffuse = -1;
801
+
802
+ const lpv = scene_ctx.light_probe_volume;
803
+
804
+ //
805
+ // ── SPECULAR ────────────────────────────────────────────
806
+ //
807
+
808
+ // SSR replaces the specular IBL fallback when enabled.
809
+ // NOTE: SSR is currently not supported in Brick4 mode — this is a known
810
+ // limitation and will be addressed in a future update.
811
+ if (this.feature_ssr_enabled && mode !== ShadeIndirectLightingMode.Brick4) {
812
+
813
+ const ssr = this.#postprocess.ssr.graph_pass({
814
+ graph,
815
+ input_depth: gr_texture_depth_current,
816
+ input_hzb: gr_texture_hzb,
817
+ input_scene_color: current_color_out,
818
+ input_albedo: gr_texture_material_albedo_ao,
819
+ input_pbr: gr_texture_pbr,
820
+ input_normal: gr_texture_normal,
821
+ input_velocity: gr_velocity,
822
+ input_occlusion: gr_occlusion_clip,
823
+ input_environment: gr_texture_environment,
824
+ camera_current: gr_buffer_camera_current,
825
+ camera_previous: gr_buffer_camera_previous,
826
+ lpv: mode === ShadeIndirectLightingMode.LPV ? lpv : undefined,
827
+ resolution,
828
+ });
829
+
830
+ indirect_specular = ssr.denoised;
831
+
832
+ } else if (mode === ShadeIndirectLightingMode.Brick4) {
833
+
834
+ // Brick4 specular from volumetric lightmap
835
+ [indirect_specular] = graph_image_pass({
836
+ graph,
837
+ shader: shader_brick4_specular,
838
+ input_depth: gr_texture_depth_current,
839
+ inputs: {
840
+ tDepth: gr_texture_depth_current,
841
+ tNormals: gr_texture_normal,
842
+ tPBR: gr_texture_pbr,
843
+ tSTBN_vec2: STATIC_GRAPHICS_ENGINE_ASSETS.stbn_vec2,
844
+ camera: gr_buffer_camera_current,
845
+ view: view_ctx.uniform_buffer.buffer,
846
+ brick4: scene_ctx.volumetric_light_map.buffer,
847
+ },
848
+ output_resolution: view_ctx.resolution,
849
+ });
850
+
851
+ } else {
852
+ // IBL / LPV fallback — environment map specular
853
+ [indirect_specular] = graph_image_pass({
854
+ graph,
855
+ shader: shader_specular_IBL,
856
+ input_depth: gr_texture_depth_current,
857
+ inputs: {
858
+ tBentNormals: bent_normals,
859
+ tNormals: gr_texture_normal,
860
+ tDepth: gr_texture_depth_current,
861
+ tPBR: gr_texture_pbr,
862
+ tEnvironment: gr_texture_environment,
863
+ camera: gr_buffer_camera_current,
864
+ },
865
+ output_resolution: view_ctx.resolution,
866
+ });
867
+ }
868
+
869
+ //
870
+ // ── DIFFUSE ─────────────────────────────────────────────
871
+ //
872
+
873
+ switch (mode) {
874
+
875
+ case ShadeIndirectLightingMode.IBL:
876
+ // Environment map irradiance
877
+ [indirect_diffuse] = graph_image_pass({
878
+ graph,
879
+ shader: shader_diffuse_IBL,
880
+ input_depth: gr_texture_depth_current,
881
+ inputs: {
882
+ tBentNormals: bent_normals,
883
+ tGBufferAlbedo: gr_texture_material_albedo_ao,
884
+ tEnvironment: gr_texture_environment,
885
+ },
886
+ output_resolution: view_ctx.resolution,
887
+ });
888
+ break;
889
+
890
+ case ShadeIndirectLightingMode.Brick4:
891
+ // Brick4 diffuse from volumetric lightmap
892
+ [indirect_diffuse] = graph_image_pass({
893
+ graph,
894
+ shader: shader_brick4_diffuse,
895
+ input_depth: gr_texture_depth_current,
896
+ inputs: {
897
+ tDepth: gr_texture_depth_current,
898
+ tBentNormals: bent_normals,
899
+ tAlbedoAO: gr_texture_material_albedo_ao,
900
+ tSTBN_vec2: STATIC_GRAPHICS_ENGINE_ASSETS.stbn_vec2,
901
+ camera: gr_buffer_camera_current,
902
+ view: view_ctx.uniform_buffer.buffer,
903
+ brick4: scene_ctx.volumetric_light_map.buffer,
904
+ },
905
+ output_resolution: view_ctx.resolution,
906
+ });
907
+ break;
908
+
909
+ case ShadeIndirectLightingMode.LPV:
910
+ // Light Probe Volume diffuse
911
+ [indirect_diffuse] = graph_image_pass({
912
+ graph,
913
+ shader: shader_diffuse_LPV,
914
+ input_depth: gr_texture_depth_current,
915
+ inputs: {
916
+ camera: gr_buffer_camera_current,
917
+ tDepth: gr_texture_depth_current,
918
+ tBentNormals: bent_normals,
919
+ tGBufferAlbedo: gr_texture_material_albedo_ao,
920
+ //
921
+ lpv_atlas_radiance: lpv.atlas.texture_radiance,
922
+ lpv_atlas_depth: lpv.atlas.texture_depth,
923
+ //
924
+ lpv_lookup: lpv.buffer_mesh_bvh,
925
+ lpv_metadata: lpv.buffer_metadata,
926
+ lpv_mesh: lpv.buffer_mesh,
927
+ lpv_probes: lpv.buffer_probes,
928
+ },
929
+ output_resolution: view_ctx.resolution,
930
+ });
931
+ break;
932
+ }
933
+
934
+ return { indirect_specular, indirect_diffuse };
935
+ }
936
+
937
+ /**
938
+ * @type {PostProcess}
939
+ */
940
+ #postprocess
941
+
942
+ /**
943
+ * @type {ReSTIRDI}
944
+ */
945
+ #restir_di
946
+
947
+ /**
948
+ * ReSTIR DI subsystem — exposed for runtime tuning (e.g. GUI toggles like
949
+ * `use_screen_space_shadow`, `m_initial`).
950
+ * @returns {ReSTIRDI}
951
+ */
952
+ get restir_di() {
953
+ return this.#restir_di;
954
+ }
955
+
956
+ /**
957
+ *
958
+ * @type {TAA}
959
+ */
960
+ #taa = new TAA();
961
+
962
+ /**
963
+ * Lazily constructed in {@link initialize} once a graphics context is
964
+ * available — NSS owns persistent GPU textures, so it can't be a
965
+ * field initializer like {@link #taa}.
966
+ * @type {NSS | undefined}
967
+ */
968
+ #nss
969
+
970
+ /**
971
+ * Selects which temporal-AA / upscaler runs at the temporal-resolve
972
+ * stage. Defaults to {@link ShadeUpscalerType.TAA}; assign
973
+ * {@link ShadeUpscalerType.NSS} to use the bundled neural upscaler
974
+ * (no extra setup — the NSS instance ships with placeholder weights).
975
+ * @type {ShadeUpscalerType}
976
+ */
977
+ upscale_type = ShadeUpscalerType.TAA;
978
+
979
+ /**
980
+ * Public read access to the NSS instance. Lazily constructed on
981
+ * first access, which is also when the bundled weights blob is
982
+ * decoded — so the cost of selecting NSS is amortized to a single
983
+ * frame.
984
+ * @returns {NSS}
985
+ */
986
+ get nss() {
987
+ if (this.#nss === undefined) {
988
+ assert.defined(this.#graphics, 'graphics context not yet initialized — call Renderer.initialize() first');
989
+ this.#nss = new NSS(this.#graphics);
990
+
991
+ // First-time setup: align the jitter sequence size with the
992
+ // current upscale ratio. Subsequent resolution changes are
993
+ // picked up by #update_internal_resolution.
994
+ const out_w = this.#output_resolution.x;
995
+ const in_w = this.#internal_resolution.x;
996
+ if (out_w > 0 && in_w > 0) {
997
+ const upscale_ratio = out_w / in_w;
998
+ this.#nss.jitter_sequence_size = NSS.recommended_jitter_sequence_size(upscale_ratio);
999
+ }
1000
+ }
1001
+ return this.#nss;
1002
+ }
1003
+
1004
+ #device_lost = false;
1005
+
1006
+ /**
1007
+ * Handles event when GPUDevice is lost
1008
+ * @param {GPUDeviceLostInfo} info
1009
+ */
1010
+ #handle_device_lost(info) {
1011
+ this.#device_lost = true;
1012
+
1013
+ if (info.reason === "destroyed") {
1014
+ // most likely renderer was destroyed, this is expected behavior
1015
+ // TODO check if renderer owns the device, if not, log a warning
1016
+ return;
1017
+ }
1018
+
1019
+ console.error('GPUDevice lost', info);
1020
+
1021
+ // Everything the renderer built lives on the device that just went away, so there is
1022
+ // nothing to carry over and no attempt to (R6). Whoever is hosting this gets told, and a
1023
+ // reload is the way back.
1024
+ this.onDeviceFailure.send1(ShadeDeviceFailure.device_lost(info.message ?? info.reason ?? ""));
1025
+ }
1026
+
1027
+ #hdr_supported = false;
1028
+
1029
+ /**
1030
+ * What's the peak brightness of the display?
1031
+ * Only valid for HDR.
1032
+ *
1033
+ * @type {number}
1034
+ */
1035
+ #display_peak_brightness_nits = 1000;
1036
+
1037
+ #update_presentation_format() {
1038
+
1039
+ const format8bit = navigator.gpu.getPreferredCanvasFormat();
1040
+
1041
+ const format = this.#hdr_supported ? "rgba16float" : format8bit;
1042
+
1043
+ if (format === this.#presentation_format) {
1044
+ return;
1045
+ }
1046
+
1047
+ this.#presentation_format = format;
1048
+
1049
+ this.#context_needs_update = true;
1050
+ }
1051
+
1052
+ /**
1053
+ * Needs to be a lambda, because we use it as a listener.
1054
+ */
1055
+ #update_hdr_support = () => {
1056
+ const isHDR = window.matchMedia("(dynamic-range: high)").matches;
1057
+
1058
+ const previous_value = this.#hdr_supported;
1059
+
1060
+
1061
+ this.#hdr_supported = isHDR;
1062
+
1063
+ if (isHDR) {
1064
+ // Currently, there is no way to interrogate this from the browser, so going with an assumption
1065
+ this.#display_peak_brightness_nits = 1000;
1066
+ } else {
1067
+ // Assume SDR nits
1068
+ this.#display_peak_brightness_nits = 80;
1069
+ }
1070
+
1071
+ if (isHDR === previous_value) {
1072
+ // no change
1073
+ return;
1074
+ }
1075
+
1076
+ console.log(`HDR support: ${isHDR ? 'enabled' : 'disabled'}`);
1077
+
1078
+ this.#update_presentation_format();
1079
+
1080
+ this.#context_needs_update = true;
1081
+ }
1082
+
1083
+ /**
1084
+ *
1085
+ * @param {GPUCanvasContext} [context] Optional, if not provided - one will be created.
1086
+ * @param {GPUDevice} [device] Optional, if not provided - one will be created.
1087
+ * @param {number} [pixelRatio] Optiona, if not provided - will be taken from browser context
1088
+ */
1089
+ async initialize({
1090
+ context,
1091
+ device,
1092
+ pixelRatio = window.devicePixelRatio,
1093
+ } = {}) {
1094
+
1095
+ if (!('gpu' in navigator)) {
1096
+ throw new Error('navigator.gpu not available — WebGPU disabled or unsupported');
1097
+ }
1098
+
1099
+ this.#update_presentation_format();
1100
+ this.#update_hdr_support();
1101
+
1102
+ if (context === undefined) {
1103
+ const canvas = document.createElement('canvas');
1104
+ canvas.width = window.innerWidth;
1105
+ canvas.height = window.innerHeight;
1106
+ // Sensible default styling so a freshly-appended canvas covers
1107
+ // the viewport without depending on the host page's CSS reset.
1108
+ // Override `style` after `initialize()` returns if the host
1109
+ // page wants the canvas embedded somewhere else.
1110
+ canvas.style.cssText = 'position:fixed;inset:0;width:100vw;height:100vh;display:block';
1111
+
1112
+ context = canvas.getContext('webgpu');
1113
+
1114
+ if (context === null) {
1115
+ throw new Error('Failed to bind GPUCanvasContext');
1116
+ }
1117
+ }
1118
+
1119
+ if (device === undefined) {
1120
+ // no device present, let's create one
1121
+
1122
+ const gpu = navigator.gpu;
1123
+
1124
+ if (gpu === undefined) {
1125
+ throw ShadeDeviceFailure.webgpu_unavailable();
1126
+ }
1127
+
1128
+ const adapter = await gpu.requestAdapter({
1129
+ powerPreference: "high-performance",
1130
+ });
1131
+
1132
+ if (adapter === null) {
1133
+ throw ShadeDeviceFailure.adapter_unavailable();
1134
+ }
1135
+
1136
+ if (adapter.isFallbackAdapter) {
1137
+ // see https://www.w3.org/TR/webgpu/#dom-gpurequestadapteroptions-forcefallbackadapter
1138
+ // fallback device is typically a software implementation and is going to be slow as sin
1139
+ console.warn('GPU provided a fallback adapter (typically because no other appropriate adapter was available). Fallback adapter is typically a software implementation and will be slow.');
1140
+ }
1141
+
1142
+ // log details of the adapter
1143
+ console.log(`GPU adapter is ${adapter.info.vendor}/${adapter.info.architecture}, device='${adapter.info.device}', description='${adapter.info.description}'`);
1144
+
1145
+ // console.warn(`Buffer size limit: ${number_format_by_thousands(adapter.limits.maxBufferSize)}`);
1146
+ //
1147
+ // console.warn('adapter limits:', adapter.limits);
1148
+
1149
+ const maxStorageBuffersPerShaderStage = adapter.limits.maxStorageBuffersPerShaderStage;
1150
+
1151
+ if (maxStorageBuffersPerShaderStage < 10) {
1152
+ throw ShadeDeviceFailure.below_floor(
1153
+ `requires at least 10 storage buffers per shader stage, adapter offers ${maxStorageBuffersPerShaderStage}`
1154
+ );
1155
+ }
1156
+
1157
+ const requiredFeatures = [
1158
+ // required for indirect draw that's used extensively in Shade
1159
+ WebGPUExtensionType.IndirectFirstInstance,
1160
+ // required for OIT (might be unavailable)
1161
+ WebGPUExtensionType.Float32Blendable,
1162
+ ];
1163
+
1164
+ // add features if they are available
1165
+ const optional_desired = [
1166
+ // Profiling only, and some browsers withhold it on hardware that is otherwise
1167
+ // fine — so it is taken when offered and the timers go quiet when it is not
1168
+ // (E7, sponsor 2026-08-16). Requiring it would refuse to start on those browsers
1169
+ // for the sake of a feature the game does not need to run.
1170
+ WebGPUExtensionType.TimestampQuery,
1171
+ WebGPUExtensionType.Subgroups,
1172
+ WebGPUExtensionType.TextureFormatsTier1,
1173
+ /*
1174
+ Compressed textures. Taken when offered and never required: a device with none of
1175
+ them still loads every scene, because the asset layer asks what is supported before
1176
+ it asks for bytes and falls back to an uncompressed encoding.
1177
+ */
1178
+ WebGPUExtensionType.TextureCompressionBC,
1179
+ WebGPUExtensionType.TextureCompressionETC2,
1180
+ WebGPUExtensionType.TextureCompressionASTC,
1181
+ ];
1182
+
1183
+ // valid required features
1184
+ for (const feature of requiredFeatures) {
1185
+ if (!adapter.features.has(feature)) {
1186
+ throw ShadeDeviceFailure.below_floor(`adapter does not support required feature '${feature}'`);
1187
+ }
1188
+ }
1189
+
1190
+ for (const feature of optional_desired) {
1191
+ if (adapter.features.has(feature)) {
1192
+ requiredFeatures.push(feature);
1193
+ }
1194
+ }
1195
+
1196
+
1197
+ device = await adapter.requestDevice({
1198
+ requiredLimits: {
1199
+ // required for large G-buffers
1200
+ maxColorAttachmentBytesPerSample: 32,
1201
+
1202
+ /*
1203
+ grab the largest buffer limit we can get, default limits are super-low
1204
+ */
1205
+ maxBufferSize: adapter.limits.maxBufferSize,
1206
+ maxStorageBufferBindingSize: adapter.limits.maxStorageBufferBindingSize,
1207
+
1208
+ maxStorageBuffersPerShaderStage: 10,
1209
+ },
1210
+ requiredFeatures
1211
+ });
1212
+
1213
+ // NOTE: according to spec (as of 2025/09/19) - adapter can only be used to create one device, after which it becomes "consumed"
1214
+ // see https://www.w3.org/TR/webgpu/#adapters
1215
+
1216
+ // TODO obtained device might be "lost" if something goes wrong, would make sense to check for that
1217
+ }
1218
+
1219
+ device.lost.then(info => {
1220
+ this.#handle_device_lost(info);
1221
+ })
1222
+
1223
+ if (context === undefined) {
1224
+ const canvas = document.createElement('canvas');
1225
+ canvas.width = window.innerWidth;
1226
+ canvas.height = window.innerHeight;
1227
+
1228
+ context = canvas.getContext('webgpu');
1229
+
1230
+ if (context === null) {
1231
+ throw new Error('Failed to bind GPUCanvasContext');
1232
+ }
1233
+ }
1234
+
1235
+ assert.ok(device.features.has("indirect-first-instance"), '"indirect-first-instance" feature needs to be enabled for non-zero firstInstance values to be used.')
1236
+ assert.isInstanceOf(context, GPUCanvasContext, 'context', 'GPUCanvasContext');
1237
+
1238
+ this.context = context;
1239
+ this.device = device;
1240
+
1241
+ this.#pixel_ratio = pixelRatio;
1242
+
1243
+ // clientWidth/clientHeight are 0 for a canvas that is not attached to the DOM,
1244
+ // which is always the case for the renderer-owned canvas created above.
1245
+ // Fall back to the backing-store size so that #configure_context doesn't
1246
+ // overwrite the just-set canvas size with the 1x1 minimum resolution.
1247
+ this.#size.set(
1248
+ context.canvas.clientWidth || context.canvas.width,
1249
+ context.canvas.clientHeight || context.canvas.height
1250
+ );
1251
+
1252
+ this.#update_output_resolution();
1253
+
1254
+ this.#graphics = new GraphicsContext(device);
1255
+
1256
+ const graphics = this.#graphics;
1257
+
1258
+ await graphics.initialize();
1259
+
1260
+
1261
+ this.#scenes = new SceneManager(graphics);
1262
+
1263
+ this.#cameras = new CameraManager(this.device);
1264
+ this.#views = new ViewManager(graphics, this.#cameras, this.#scenes);
1265
+
1266
+ const resolution_internal = this.#internal_resolution.asArray();
1267
+
1268
+ for (let i = 0; i < this.#textures_depth.length; i++) {
1269
+
1270
+ this.#textures_depth[i] = graphics.textures.contextFromDescriptor(TextureDescriptor.from({
1271
+ label: `Depth ${i}`,
1272
+ size: resolution_internal,
1273
+ format: 'depth32float',
1274
+ mipLevelCount: G_BUFFER_MIP_LEVELS,
1275
+ usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_SRC,
1276
+ }));
1277
+ }
1278
+
1279
+
1280
+ const resolution_out = this.#output_resolution.asArray();
1281
+
1282
+ for (let i = 0; i < this.#textures_taa_history.length; i++) {
1283
+
1284
+ this.#textures_taa_history[i] = graphics.textures.contextFromDescriptor(TextureDescriptor.from({
1285
+ label: `Color ${i}`,
1286
+ size: resolution_out,
1287
+ format: "rgba16float",
1288
+ mipLevelCount: 1,
1289
+ // STORAGE_BINDING is required for the NSS postprocess
1290
+ // compute shader to write here. TAA continues to use
1291
+ // RENDER_ATTACHMENT — the flags coexist on the same
1292
+ // texture and the active upscaler picks its preferred
1293
+ // write path each frame.
1294
+ usage: GPUTextureUsage.RENDER_ATTACHMENT
1295
+ | GPUTextureUsage.TEXTURE_BINDING
1296
+ | GPUTextureUsage.STORAGE_BINDING
1297
+ | GPUTextureUsage.COPY_SRC,
1298
+ }));
1299
+ }
1300
+
1301
+ this.#autoexposure = new GPUCameraExposureManager(device);
1302
+ this.#depth_of_field = new DepthOfField(device);
1303
+ this.#depth_of_field_unreal = new DepthOfFieldU(device);
1304
+ this.#motion_blur = new MotionBlur();
1305
+
1306
+ this.#postprocess = new PostProcess(this.#graphics);
1307
+
1308
+ this.#restir_di = new ReSTIRDI(this.#graphics);
1309
+
1310
+ this.#configure_context();
1311
+ this.init_render_targets();
1312
+
1313
+ window.matchMedia("(dynamic-range: high)").addEventListener("change", this.#update_hdr_support);
1314
+
1315
+ }
1316
+
1317
+ /**
1318
+ * Cleanup
1319
+ */
1320
+ destroy() {
1321
+
1322
+ window.matchMedia("(dynamic-range: high)").removeEventListener("change", this.#update_hdr_support);
1323
+ }
1324
+
1325
+
1326
+ /**
1327
+ * @type {RenderTarget}
1328
+ */
1329
+ #vis_render_target;
1330
+
1331
+ init_render_targets() {
1332
+ const vis_rt = new RenderTarget();
1333
+ this.#vis_render_target = vis_rt;
1334
+
1335
+ const textures = this.#graphics.textures;
1336
+
1337
+ // TODO these can be moved to frame graph instead and managed in a transient manner
1338
+ const internal_resolution_array = this.#internal_resolution.asArray();
1339
+
1340
+ vis_rt.color_attachments = [
1341
+ textures.contextFromDescriptor(TextureDescriptor.from({
1342
+ size: internal_resolution_array,
1343
+ format: "r32uint",
1344
+ usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING
1345
+ })),
1346
+ textures.contextFromDescriptor(TextureDescriptor.from({
1347
+ size: internal_resolution_array,
1348
+ format: "r32uint",
1349
+ usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING
1350
+ })),
1351
+ ];
1352
+
1353
+ vis_rt.depth_attachment = this.#textures_depth[0];
1354
+
1355
+ }
1356
+
1357
+ /**
1358
+ * If set to true, will force {@link #configure_context} on next render
1359
+ * @type {boolean}
1360
+ */
1361
+ #context_needs_update = false;
1362
+
1363
+ #configure_context() {
1364
+ const context = this.context;
1365
+
1366
+ const resolution = this.#output_resolution;
1367
+
1368
+ context.canvas.width = resolution.x;
1369
+ context.canvas.height = resolution.y;
1370
+
1371
+ // canvas must be scaled on-screen differently from resolution to account for pixel ratio
1372
+ const size = this.#size;
1373
+ context.canvas.style.width = `${size.x}px`;
1374
+ context.canvas.style.height = `${size.y}px`;
1375
+
1376
+ const preferred_color_space = 'display-p3';
1377
+
1378
+
1379
+ const config = {
1380
+ device: this.device,
1381
+ format: this.#presentation_format,
1382
+ alphaMode: 'opaque',
1383
+ colorSpace: preferred_color_space,
1384
+ toneMapping: {
1385
+ // see https://www.w3.org/TR/webgpu/#dom-gpucanvastonemappingmode-extended
1386
+ mode: this.#hdr_supported ? "extended" : "standard"
1387
+ }
1388
+ };
1389
+
1390
+
1391
+ try {
1392
+ context.configure(config);
1393
+ } catch (e) {
1394
+ // try fall-back colorspace
1395
+ context.configure({
1396
+ ...config,
1397
+ colorSpace: 'srgb'
1398
+ });
1399
+ }
1400
+
1401
+ }
1402
+
1403
+ #apply_size() {
1404
+ const out_w = this.#output_resolution.x;
1405
+ const out_h = this.#output_resolution.y;
1406
+
1407
+ this.#textures_taa_history.forEach(t => t.resize(out_w, out_h));
1408
+
1409
+
1410
+ this.#context_needs_update = true;
1411
+ }
1412
+
1413
+
1414
+ #update_internal_resolution() {
1415
+ const out_w = this.#output_resolution.x;
1416
+ const out_h = this.#output_resolution.y;
1417
+
1418
+ const dimension_limit = this.device.limits.maxTextureDimension2D;
1419
+
1420
+ const irs = this.#internal_resolution_scale;
1421
+
1422
+ const _iw = clamp(Math.floor(out_w * irs), INTERNAL_RESOLUTION_MIN, dimension_limit);
1423
+ const _ih = clamp(Math.floor(out_h * irs), INTERNAL_RESOLUTION_MIN, dimension_limit);
1424
+
1425
+ this.#internal_resolution.set(_iw, _ih);
1426
+
1427
+ // figure out exact x/y resolution scale
1428
+ const irs_x_inv = out_w / _iw;
1429
+ const irs_y_int = out_h / _ih;
1430
+
1431
+ // we need to make TAA sequence long enough to provide full coverage over output resolution texels
1432
+ const taa_sequence_scale = Math.max(1, irs_x_inv * irs_y_int);
1433
+
1434
+ const upscale_factor = 1 / irs;
1435
+
1436
+ // shrink the sequence as upscale factor increases
1437
+ // we lose crispness of the edges, but we have to trade it to get faster convergence
1438
+ const base_sequence_size = remap(
1439
+ 1, 2,
1440
+ 16, 4,
1441
+ clamp(upscale_factor, 1, 2),
1442
+ );
1443
+
1444
+ this.#taa.jitter_sequence_size = Math.ceil(base_sequence_size * taa_sequence_scale);
1445
+
1446
+ // ARM's NSS expects `8 * upscale_ratio^2` jitter phases. Apply the
1447
+ // same coverage scaling as TAA so DPR-mismatch resolutions still
1448
+ // get full coverage. Only applied if the NSS instance has been
1449
+ // created — no point spinning it up just to set a number.
1450
+ if (this.#nss !== undefined) {
1451
+ const nss_base = NSS.recommended_jitter_sequence_size(upscale_factor);
1452
+ this.#nss.jitter_sequence_size = Math.ceil(nss_base * taa_sequence_scale);
1453
+ }
1454
+
1455
+ const in_w = this.#internal_resolution.x;
1456
+ const in_h = this.#internal_resolution.y;
1457
+
1458
+ this.#textures_depth.forEach(t => {
1459
+ t.resize(in_w, in_h)
1460
+ });
1461
+
1462
+ this.#vis_render_target.resize(in_w, in_h);
1463
+
1464
+ // resizing destroys BOTH ping-pong depth textures, including the one holding last
1465
+ // frame's depth — disocclusion/SSAO would read a zeroed "previous depth" this frame
1466
+ // and silently corrupt temporal history. The external resize() path resets history
1467
+ // via indicate_view_change(); internal-resolution changes (DRS steps) must too.
1468
+ this.indicate_view_change();
1469
+
1470
+ this.#internal_resolution_needs_update = false;
1471
+ }
1472
+
1473
+ #update_output_resolution() {
1474
+ const size = this.#size;
1475
+ const pixel_ratio = this.#pixel_ratio;
1476
+
1477
+ const dimension_limit = this.device.limits.maxTextureDimension2D;
1478
+
1479
+ // limits are there to prevent crashing out
1480
+ const w = clamp(Math.ceil(size.x * pixel_ratio), 1, dimension_limit);
1481
+ const h = clamp(Math.ceil(size.y * pixel_ratio), 1, dimension_limit);
1482
+
1483
+ this.#output_resolution.set(w, h);
1484
+
1485
+ this.#internal_resolution_needs_update = true;
1486
+ }
1487
+
1488
+ /**
1489
+ * Make sure to resize at the start of the frame to avoid flicker
1490
+ *
1491
+ * @param {number} x
1492
+ * @param {number} y
1493
+ */
1494
+ resize(x, y) {
1495
+ assert.isNonNegativeInteger(x, 'x');
1496
+ assert.isNonNegativeInteger(y, 'y');
1497
+
1498
+ const size = this.#size;
1499
+
1500
+ if (size.x === x && size.y === y) {
1501
+ // no change
1502
+ return;
1503
+ }
1504
+
1505
+ size.set(x, y);
1506
+
1507
+ this.#update_resolution();
1508
+ }
1509
+
1510
+ /**
1511
+ * Does not check for changes, so make sure to call this sparingly
1512
+ */
1513
+ #update_resolution() {
1514
+
1515
+ this.#update_output_resolution();
1516
+
1517
+ if (this.#internal_resolution_needs_update) {
1518
+ this.#update_internal_resolution();
1519
+ }
1520
+
1521
+ this.#apply_size();
1522
+
1523
+ // drop history buffers to prevent artifacts
1524
+ this.indicate_view_change();
1525
+ }
1526
+
1527
+ /**
1528
+ * Bring the canvas context up to date with the size the renderer is drawing at.
1529
+ *
1530
+ * **Only {@link render} calls this, and that is the point.** Configuring a context resizes the
1531
+ * canvas and invalidates the texture it last handed out, so it has to happen before the frame
1532
+ * asks for one — and a frame going somewhere other than the canvas must not do it at all, or
1533
+ * every offscreen picture would resize the page's canvas to its own size and back.
1534
+ */
1535
+ #ensure_context_configured() {
1536
+ this.#update_resolution_if_needed();
1537
+
1538
+ if (this.#context_needs_update) {
1539
+ this.#configure_context();
1540
+ this.#context_needs_update = false;
1541
+ }
1542
+ }
1543
+
1544
+ #update_resolution_if_needed() {
1545
+ if (this.#internal_resolution_needs_update) {
1546
+ this.#update_internal_resolution();
1547
+ }
1548
+ }
1549
+
1550
+ #begin_frame() {
1551
+
1552
+ this.#update_resolution_if_needed();
1553
+
1554
+ this.#graphics.update();
1555
+
1556
+ // Virtual texture maintenance: apply arrived pages (budgeted
1557
+ // uploads), flush page-table dirty rects and stack info, issue
1558
+ // streaming loads. Queue-ordered before this frame's submits, so
1559
+ // the material pass samples a consistent table+cache snapshot.
1560
+ if (this.feature_virtual_textures) {
1561
+ this.#graphics.virtual_textures.update();
1562
+ }
1563
+
1564
+ // cycle depth attachment
1565
+ this.#vis_render_target.depth_attachment = this.texture_depth_current;
1566
+ this.#postprocess.update(this.#frame_count);
1567
+
1568
+ // Advance whichever upscaler we're going to ask for jitter on this
1569
+ // frame. Both share the same Halton(2, 3) sequence; we only tick
1570
+ // the active one to avoid spinning up NSS just to drive a counter.
1571
+ if (this.upscale_type === ShadeUpscalerType.NSS) {
1572
+ const nss = this.nss;
1573
+ nss.frame_count = this.#frame_count;
1574
+ nss.frame_index = this.#frame_count;
1575
+ } else {
1576
+ this.#taa.frame_index = this.#frame_count;
1577
+ }
1578
+ }
1579
+
1580
+ #end_frame() {
1581
+ this.#frame_count++;
1582
+
1583
+ // dispatch event
1584
+ this.onFrameFinished.send1(this.#frame_count);
1585
+ }
1586
+
1587
+ /**
1588
+ * @type {AccumulatingPathTracer}
1589
+ */
1590
+ #path_tracer;
1591
+
1592
+ get path_tracer() {
1593
+ if (this.#path_tracer === undefined) {
1594
+ this.#path_tracer = new AccumulatingPathTracer(this.#graphics);
1595
+ }
1596
+
1597
+ return this.#path_tracer;
1598
+ }
1599
+
1600
+ /**
1601
+ * Draw a frame onto the canvas this renderer is bound to.
1602
+ *
1603
+ * The canvas is one target among others: this is {@link render_to_target} with the canvas's
1604
+ * current texture as the target, and nothing else.
1605
+ *
1606
+ * @param {PerspectiveCamera} camera
1607
+ * @param {Scene} scene
1608
+ * @param {number} [time_delta_seconds]
1609
+ * @returns {boolean} whether frame was rendered, will return false if previous frame hasn't finished yet
1610
+ */
1611
+ render(
1612
+ camera,
1613
+ scene,
1614
+ time_delta_seconds = 0.01666
1615
+ ) {
1616
+ if (this.#device_lost) {
1617
+ // device is lost, can't render — and asking the context for a texture would throw
1618
+ return false;
1619
+ }
1620
+
1621
+ this.#ensure_context_configured();
1622
+
1623
+ const canvas_texture = this.context.getCurrentTexture();
1624
+
1625
+ return this.render_to_target(
1626
+ camera,
1627
+ scene,
1628
+ time_delta_seconds,
1629
+ GPUTextureContext.fromTexture(canvas_texture, this.device)
1630
+ );
1631
+ }
1632
+
1633
+ /**
1634
+ * Draw a frame into a texture of the caller's choosing.
1635
+ *
1636
+ * **The target says where the picture goes, not how big it is.** Everything the frame is built
1637
+ * out of — the G-buffer, the visibility buffer, the depth ping-pong, the temporal history — is
1638
+ * sized from {@link output_resolution}, so a target has to be that size; a caller wanting a
1639
+ * different one calls {@link resize} first and puts the size back afterwards. Rendering into a
1640
+ * texture the caller owns is what makes a frame readable: a canvas texture is configured by the
1641
+ * presentation path and cannot carry `COPY_SRC`, and one of these can.
1642
+ *
1643
+ * @param {PerspectiveCamera} camera
1644
+ * @param {Scene} scene
1645
+ * @param {number} time_delta_seconds
1646
+ * @param {GPUTextureContext} target must match {@link output_resolution}
1647
+ * @returns {boolean} whether frame was rendered, will return false if previous frame hasn't finished yet
1648
+ */
1649
+ render_to_target(
1650
+ camera,
1651
+ scene,
1652
+ time_delta_seconds,
1653
+ target
1654
+ ) {
1655
+ assert.defined(target, 'target');
1656
+ assert.equal(target.isGPUTextureContext, true, 'target.isGPUTextureContext !== true');
1657
+
1658
+ if (this.#device_lost) {
1659
+ // device is lost, can't render
1660
+ return false;
1661
+ }
1662
+
1663
+ this.#begin_frame();
1664
+
1665
+
1666
+ if (this.indirect_lighting_mode === ShadeIndirectLightingMode.LPV) {
1667
+ this.update_lpv(scene);
1668
+ }
1669
+
1670
+ const view = View.from(camera, scene);
1671
+ view.label = "Main View";
1672
+ const view_ctx = this.#views.obtain(view);
1673
+
1674
+ const graphics = this.#graphics;
1675
+
1676
+ // Shadow allocation + per-light shadow_id assignment happens inside
1677
+ // GPULightCollection.update (which view_ctx.update will trigger via
1678
+ // GPUSceneContext.update below), so by the time we reach select_for_draw the
1679
+ // light records on the GPU already carry their up-to-date shadow_id. Forward the
1680
+ // feature flag so process_lights inside lights.update can evict everything when
1681
+ // the renderer has shadows turned off — keeps CASTS_SHADOW_BIT cleared on every
1682
+ // light record without further plumbing.
1683
+ const sm = view_ctx.scene.lights.shadow_context;
1684
+ sm.enabled = this.#feature_shadows_enabled;
1685
+ // Which point-light shadow generator to use this frame; a flip triggers a rebuild of
1686
+ // existing point maps inside process_lights (run via view_ctx.update above/below).
1687
+ sm.use_tetrahedron_point_shadows = this.feature_tetrahedron_point_shadows;
1688
+
1689
+ const taa = this.#taa;
1690
+
1691
+ // Whichever upscaler is going to consume the temporal sequence
1692
+ // also has to dictate the jitter applied to the camera projection.
1693
+ // Both share Halton(2, 3); they just drive different jitter
1694
+ // sequence sizes via #update_internal_resolution.
1695
+ const jitter_source = this.upscale_type === ShadeUpscalerType.NSS
1696
+ ? this.nss
1697
+ : taa;
1698
+
1699
+ const resolution_internal = this.#internal_resolution;
1700
+ {
1701
+ const jitter_x = jitter_source.Jitter[0];
1702
+ const jitter_y = jitter_source.Jitter[1];
1703
+
1704
+ view_ctx.setJitter(jitter_x, jitter_y);
1705
+ view_ctx.setViewportSize(resolution_internal.x, resolution_internal.y);
1706
+ view_ctx.setUpscaleRatio(
1707
+ this.#output_resolution.x / resolution_internal.x,
1708
+ this.#output_resolution.y / resolution_internal.y
1709
+ );
1710
+ // 2x offsets because the offsets are in NDC (-1, 1)
1711
+ view_ctx.camera.setViewportOffset(
1712
+ (2 * jitter_x) / resolution_internal.x,
1713
+ (2 * jitter_y) / resolution_internal.y
1714
+ );
1715
+
1716
+ }
1717
+
1718
+ view_ctx.update(graphics);
1719
+
1720
+ const command_ctx = ShadeGPUCommandContext.create(
1721
+ graphics,
1722
+ "Renderer/main-0"
1723
+ );
1724
+
1725
+ /**
1726
+ * The frame recorder for this frame, or null when nothing is profiling.
1727
+ * @type {GPUFrameRecorder|null}
1728
+ */
1729
+ let profile_recorder = null;
1730
+
1731
+ if (this.profile_session !== null) {
1732
+ // The session hands out the recorder; nothing here imports the profiler, which is what
1733
+ // keeps it out of a bundle that never asks for it. Null when the session is not running.
1734
+ profile_recorder = this.profile_session.begin_frame(this.#frame_count, performance.now());
1735
+
1736
+ if (profile_recorder !== null) {
1737
+ command_ctx.enable_profiling(profile_recorder, 0);
1738
+ }
1739
+ }
1740
+
1741
+ // Per-frame animation tick runs before shadow allocation so
1742
+ // animated transforms (joint poses, mesh.global from animated
1743
+ // parents) are in the scene database by the time shadow
1744
+ // culling samples it. No-op when nothing's registered.
1745
+ view_ctx.scene.tick(command_ctx, time_delta_seconds);
1746
+
1747
+ const viz_rt = this.#vis_render_target;
1748
+
1749
+ // prepare shadows (process_lights already ran inside lights.update via view_ctx.update,
1750
+ // so the GPU light records already carry their up-to-date shadow_id)
1751
+ if (this.#feature_shadows_enabled) {
1752
+ // Two-stage: (1) score+select which maps refresh this frame and publish their metadata,
1753
+ // (2) rasterize the selected maps. The context internally dispatches to the right
1754
+ // raster path per light type — directional/spot go direct, point lights do a cube
1755
+ // pass plus octahedral remap — so we don't have to juggle job arrays out here.
1756
+ // draw() also writes per-shadow records into the scene's GPU light database
1757
+ // (shadow_point/shadow_spot/shadow_directional tables) via its owner reference.
1758
+ sm.select_for_draw(camera, view_ctx.scene, view_ctx.frame_index, view_ctx.resolution);
1759
+ sm.draw(command_ctx);
1760
+ }
1761
+
1762
+
1763
+ const graph = new FrameGraph("Shading");
1764
+
1765
+ /*
1766
+ The view is updated and nothing has been rasterized, so an extension here is doing the
1767
+ per-frame compute that later phases depend on. There are no records yet — the frame has
1768
+ built nothing to hand out.
1769
+ */
1770
+ const frame = new FrameContext(graph, view_ctx);
1771
+
1772
+ frame.phase = FramePhase.FrameStart;
1773
+
1774
+ this.#extensions.run(frame);
1775
+
1776
+ // build main view rasterization job
1777
+ const raster_main = new RasterizationJob();
1778
+ raster_main.view_ctx = view_ctx;
1779
+ raster_main.render_target = viz_rt;
1780
+ raster_main.opaque_pass = viz_rasterization_opaque_pass_descriptor;
1781
+ raster_main.alpha_tested_pass = viz_rasterization_alpha_tested_pass_descriptor;
1782
+
1783
+ const gr_render_buckets = graph_rasterize_scene({
1784
+ job: raster_main,
1785
+ graph,
1786
+ limits: graphics.collection_limits,
1787
+ });
1788
+
1789
+ // `let` rather than `const` because an extension at `AfterGBuffer` may publish replacements
1790
+ let gr_viz_buffer_triangle = graph_import_texture(graph, this.#vis_render_target.color_attachments[0], "viz_triangle");
1791
+ let gr_viz_buffer_mesh = graph_import_texture(graph, this.#vis_render_target.color_attachments[1], "viz_mesh");
1792
+
1793
+ // Virtual texture feedback: derive per-pixel page usage from the viz
1794
+ // buffer (no extra geometry pass) into a unique-request hash set and
1795
+ // kick its async readback. No-op unless VT stacks are registered.
1796
+ if (this.feature_virtual_textures) {
1797
+ graphics.virtual_textures.graph_feedback({
1798
+ graph,
1799
+ view: view_ctx,
1800
+ texture_viz_mesh: gr_viz_buffer_mesh,
1801
+ texture_viz_triangle: gr_viz_buffer_triangle,
1802
+ material_metadata_buffer: graphics.materials.metadata_table.buffer,
1803
+ });
1804
+ }
1805
+
1806
+ // run materials
1807
+ const mat_g = graphics.materials.graph_viz_render({
1808
+ graph,
1809
+ view: view_ctx,
1810
+ texture_viz_mesh: gr_viz_buffer_mesh,
1811
+ texture_viz_triangle: gr_viz_buffer_triangle,
1812
+ });
1813
+
1814
+ // update texture references
1815
+ // `let` rather than `const` because a pass injected at `AfterGBuffer` may replace any of
1816
+ // them; see the read-back below.
1817
+ let gr_texture_pbr = mat_g.g_pbr;
1818
+ let gr_texture_normal = mat_g.g_normal;
1819
+ let gr_texture_material_albedo_ao = mat_g.g_albedo;
1820
+ let gr_texture_material_emissive = mat_g.g_emissive;
1821
+
1822
+ // do mips for G-buffer
1823
+ // mipmap_nearest(command_ctx, this.texture_depth_current);
1824
+ // this.gBuffer.mipmap(command_ctx);
1825
+
1826
+ // Update lights position
1827
+ command_ctx.pushDebugGroup("Shade");
1828
+
1829
+ const resolution = resolution_internal.asArray();
1830
+
1831
+ const scene_ctx = view_ctx.scene;
1832
+ const lights = scene_ctx.lights;
1833
+
1834
+
1835
+ const gr_texture_canvas = graph_import_texture(graph, target, "canvas");
1836
+ let gr_texture_depth_current = graph_import_texture(graph, this.texture_depth_current, "depth");
1837
+ const gr_buffer_camera_current = graph_import_buffer(graph, view_ctx.camera.gpu_buffer, "camera/current");
1838
+ const gr_buffer_camera_previous = graph_import_buffer(graph, view_ctx.gpu_previous_camera_state.gpu_buffer, "camera/previous");
1839
+ const gr_texture_hzb = graph_import_texture(graph, view_ctx.hierarchical_z_buffer.texture, "HZB");
1840
+ const gr_texture_environment = graph_import_texture(graph, view_ctx.scene.lights.environment);
1841
+
1842
+ const taa_history_0 = this.#get_texture_taa_history(0);
1843
+ const taa_history_1 = this.#get_texture_taa_history(-1);
1844
+
1845
+ const gr_texture_taa_history = graph_import_texture(graph, taa_history_0, "taa history");
1846
+ const gr_texture_taa_out = graph_import_texture(graph, taa_history_1, "taa out");
1847
+ let gr_texture_depth_previous = graph_import_texture(graph, this.texture_depth_previous, "depth previous");
1848
+
1849
+ const gr_shadowmap_atlas = graph_import_texture(graph, sm.texture);
1850
+
1851
+ // The frame's surface handles exist now, so this is where the records that carry them are
1852
+ // published. There is no colour yet, which is what makes this the phase for G-buffer work.
1853
+ frame.phase = FramePhase.AfterGBuffer;
1854
+
1855
+ const record_gbuffer = frame.create(GBufferTextures);
1856
+ const record_view_textures = frame.create(ViewTextures);
1857
+
1858
+ record_gbuffer.albedo = gr_texture_material_albedo_ao;
1859
+ record_gbuffer.normal = gr_texture_normal;
1860
+ record_gbuffer.pbr = gr_texture_pbr;
1861
+ record_gbuffer.emissive = gr_texture_material_emissive;
1862
+
1863
+ record_view_textures.depth = gr_texture_depth_current;
1864
+ record_view_textures.depth_previous = gr_texture_depth_previous;
1865
+ record_view_textures.visibility_mesh = gr_viz_buffer_mesh;
1866
+ record_view_textures.visibility_triangle = gr_viz_buffer_triangle;
1867
+
1868
+ this.#extensions.run(frame);
1869
+
1870
+ /*
1871
+ `GBufferTextures` is in/out at this phase, and frozen after it. An extension that wants to
1872
+ *change* surface properties decals are the reason this exists cannot blend into these
1873
+ targets: two of the four are integer formats, and one texture cannot be a render attachment
1874
+ and a sampled source in the same pass. So it reads them, writes replacements, and publishes
1875
+ the new handles. Everything downstream carries what it left.
1876
+
1877
+ Writing the originals in place would work by accident rather than by contract: a written
1878
+ handle is a *renamed* clone of the same physical resource, so the change would land in the
1879
+ texture the shading pass reads only because the graph happens to execute in insertion
1880
+ order, with no dependency edge saying so. Threading the handles makes the edge real.
1881
+ */
1882
+ gr_texture_pbr = record_gbuffer.pbr;
1883
+ gr_texture_normal = record_gbuffer.normal;
1884
+ gr_texture_material_albedo_ao = record_gbuffer.albedo;
1885
+ gr_texture_material_emissive = record_gbuffer.emissive;
1886
+
1887
+ gr_texture_depth_current = record_view_textures.depth;
1888
+ gr_texture_depth_previous = record_view_textures.depth_previous;
1889
+ gr_viz_buffer_mesh = record_view_textures.visibility_mesh;
1890
+ gr_viz_buffer_triangle = record_view_textures.visibility_triangle;
1891
+
1892
+ // Velocity pass with three branches: rotation-reprojection
1893
+ // background, rigid per-object foreground (mesh.global delta),
1894
+ // and skinned per-vertex foreground (barycentric interpolation
1895
+ // of the triangle's mesh-local `position_prev` written by
1896
+ // skinning into the side-buffer the skinning context owns).
1897
+ // Per-vertex limb deformation lands in the final pixel-space
1898
+ // velocity, so TAA reads correct history for character animation.
1899
+ const gr_scene_database_for_velocity = graph_import_buffer(
1900
+ graph, scene_ctx.scene_database_buffer, "scene_database/velocity"
1901
+ );
1902
+ const gr_meshlet_metadata_for_velocity = graph_import_buffer(
1903
+ graph, scene_ctx.geometries.meshlets.buffer_metadata, "meshlet_metadata/velocity"
1904
+ );
1905
+ const gr_meshlet_data_for_velocity = graph_import_buffer(
1906
+ graph, scene_ctx.geometries.meshlets.buffer_data, "meshlet_data/velocity"
1907
+ );
1908
+ // Skinning side-buffers both null when no SkinnedMesh has
1909
+ // been registered. The velocity shader still references these
1910
+ // bindings (the dormant per-vertex branch), so the bind group
1911
+ // must supply *something*; use the scene_database buffer as a
1912
+ // placeholder when skinning is inactive. The shader is told via
1913
+ // `skinning_active` whether the bindings are real — when false
1914
+ // it never reads them and forces the rigid path, so the
1915
+ // placeholder is never sampled. (Binding the placeholder
1916
+ // without that guard was the source of phantom velocity on
1917
+ // static meshes: `prev_position_offsets[meshlet_id]` read an
1918
+ // unrelated scene_database word, and any non-0xFFFFFFFF value
1919
+ // sent a static triangle down the skinned branch.)
1920
+ const skinning_ctx = scene_ctx.skinning;
1921
+ const skinning_active = skinning_ctx.prev_position_offsets_buffer !== null
1922
+ && skinning_ctx.prev_positions_buffer !== null;
1923
+ const gr_prev_position_offsets = graph_import_buffer(
1924
+ graph,
1925
+ skinning_ctx.prev_position_offsets_buffer ?? scene_ctx.scene_database_buffer,
1926
+ "prev_position_offsets/velocity",
1927
+ );
1928
+ const gr_prev_positions = graph_import_buffer(
1929
+ graph,
1930
+ skinning_ctx.prev_positions_buffer ?? scene_ctx.scene_database_buffer,
1931
+ "prev_positions/velocity",
1932
+ );
1933
+
1934
+ let gr_velocity = graph_add_per_object_velocity({
1935
+ graph,
1936
+ texture_depth: gr_texture_depth_current,
1937
+ texture_viz_mesh: gr_viz_buffer_mesh,
1938
+ texture_viz_triangle: gr_viz_buffer_triangle,
1939
+ buffer_scene_database: gr_scene_database_for_velocity,
1940
+ buffer_meshlet_metadata: gr_meshlet_metadata_for_velocity,
1941
+ buffer_meshlet_data: gr_meshlet_data_for_velocity,
1942
+ buffer_prev_position_offsets: gr_prev_position_offsets,
1943
+ buffer_prev_positions: gr_prev_positions,
1944
+ skinning_active,
1945
+ resolution,
1946
+ view: view_ctx,
1947
+ enable_mipmap: true
1948
+ });
1949
+
1950
+ // gr_velocity = graph_mipmap_nearest(graph, gr_velocity, G_BUFFER_MIP_LEVELS);
1951
+
1952
+ // rg8unorm: r is the history confidence, g records which texel won the nearest-depth search,
1953
+ // so the TAA resolve can reproject with exactly the velocity this pass validated.
1954
+ let [gr_occlusion_clip] = graph_image_pass({
1955
+ graph,
1956
+ shader: shader_depth_occlusion_clip,
1957
+ output_resolution: view_ctx.resolution,
1958
+ // mipmaps are going to be necessary for half-resolution post-process passes
1959
+ output_mipmaps: true,
1960
+ inputs: {
1961
+ camera_current: gr_buffer_camera_current,
1962
+ camera_previous: gr_buffer_camera_previous,
1963
+ DepthBuffer: gr_texture_depth_current,
1964
+ PrevDepthBuffer: gr_texture_depth_previous,
1965
+ VelocityBuffer: gr_velocity
1966
+ }
1967
+ });
1968
+
1969
+ const light_clusters = graph_build_light_clusters({
1970
+ graph,
1971
+ lights: lights,
1972
+ camera: view_ctx.camera,
1973
+ hzb: gr_texture_hzb,
1974
+ resolution: view_ctx.resolution,
1975
+ });
1976
+
1977
+ // Build the view's volumetric fog LUTs (participating media -> per-froxel lighting ->
1978
+ // ray-marched integration). Needs the light clusters and shadow atlas. Built every frame so
1979
+ // the transparency (OIT) pass always has a valid LUT to sample — an empty scene integrates
1980
+ // to a no-op (transmittance 1, in-scatter 0). The opaque composite below is still skipped
1981
+ // when the scene has no fog.
1982
+ const has_volumetrics = view_ctx.scene.volumetrics.source.volumes.length > 0;
1983
+
1984
+ const volumetrics = view_ctx.volumetrics.graph_update({
1985
+ graph,
1986
+ light_cluster_data: light_clusters.data,
1987
+ light_cluster_lookup: light_clusters.lookup,
1988
+ light_cluster_parameters: light_clusters.parameters,
1989
+ shadowmap_atlas: gr_shadowmap_atlas,
1990
+ });
1991
+
1992
+ /**
1993
+ *
1994
+ * @type {number}
1995
+ */
1996
+ let current_color_out = -1;
1997
+
1998
+ // ReSTIR DI — stochastic direct lighting of local (point+spot) lights.
1999
+ // When enabled, resolve per-pixel point+spot radiance and shade with the
2000
+ // ReSTIR deferred variant (no brute-force cluster loop). The variant is a
2001
+ // separate compiled shader, selected here at the JS level rather than via
2002
+ // a runtime branch inside the shader.
2003
+ let deferred_shader = shader_deferred_main;
2004
+
2005
+ const deferred_inputs = {
2006
+ gBufferDepth: gr_texture_depth_current,
2007
+ gBufferPBR: gr_texture_pbr,
2008
+ gBufferNormal: gr_texture_normal,
2009
+ gBufferAlbedo: gr_texture_material_albedo_ao,
2010
+ gBufferEmissive: gr_texture_material_emissive,
2011
+
2012
+ //
2013
+ light_data: lights.buffer_data,
2014
+ tEnvironment: gr_texture_environment,
2015
+
2016
+ // light clusters
2017
+ cluster_parameters: light_clusters.parameters,
2018
+ cluster_lookup: light_clusters.lookup,
2019
+ cluster_data: light_clusters.data,
2020
+
2021
+ // shadows
2022
+ shadowmapAtlas: gr_shadowmap_atlas,
2023
+
2024
+ //
2025
+ camera: view_ctx.camera.buffer,
2026
+ view: view_ctx.uniform_buffer.buffer,
2027
+ };
2028
+
2029
+ if (this.feature_restir_di_enabled) {
2030
+ deferred_shader = shader_deferred_main_restir;
2031
+
2032
+ deferred_inputs.tRestirRadiance = this.#restir_di.execute({
2033
+ graph,
2034
+ view: view_ctx,
2035
+ depth: gr_texture_depth_current,
2036
+ pbr: gr_texture_pbr,
2037
+ normal: gr_texture_normal,
2038
+ albedo: gr_texture_material_albedo_ao,
2039
+ emissive: gr_texture_material_emissive,
2040
+ velocity: gr_velocity,
2041
+ occlusion_clip: gr_occlusion_clip,
2042
+ hzb: gr_texture_hzb,
2043
+ cluster_parameters: light_clusters.parameters,
2044
+ cluster_lookup: light_clusters.lookup,
2045
+ cluster_data: light_clusters.data,
2046
+ });
2047
+ }
2048
+
2049
+ // Main shading pass
2050
+ [current_color_out] = graph_image_pass({
2051
+ graph,
2052
+ shader: deferred_shader,
2053
+ input_depth: gr_texture_depth_current,
2054
+ inputs: deferred_inputs,
2055
+ output_resolution: view_ctx.resolution,
2056
+ });
2057
+
2058
+
2059
+ let bent_normals = -1;
2060
+
2061
+ if (this.feature_ssao_enabled) {
2062
+
2063
+ const ssao = this.#postprocess.ssao.graph_pass({
2064
+ graph: graph,
2065
+ frame_index: this.#frame_count,
2066
+ input_depth: gr_texture_depth_current,
2067
+ input_color: current_color_out,
2068
+ input_depth_previous: gr_texture_depth_previous,
2069
+ input_velocity: gr_velocity,
2070
+ input_normal: gr_texture_normal,
2071
+ input_occlusion: gr_occlusion_clip,
2072
+ // NOTE: AO is blended into the G-buffer
2073
+ output: gr_texture_material_albedo_ao,
2074
+ camera: gr_buffer_camera_current,
2075
+ resolution: resolution,
2076
+ });
2077
+
2078
+ gr_texture_material_albedo_ao = ssao.occlusion;
2079
+ bent_normals = ssao.bent_normals;
2080
+
2081
+ } else {
2082
+
2083
+ // default to shading normals
2084
+ bent_normals = gr_texture_normal;
2085
+
2086
+ }
2087
+
2088
+
2089
+ // Shade background
2090
+ [current_color_out] = graph_image_pass({
2091
+ graph,
2092
+ shader: shader_background,
2093
+ inputs: {
2094
+ camera: view_ctx.camera.buffer,
2095
+ view: view_ctx.uniform_buffer.buffer,
2096
+ tEnvironment: gr_texture_environment,
2097
+ },
2098
+ input_depth: gr_texture_depth_current,
2099
+ load_op: "load",
2100
+ output: [current_color_out],
2101
+ });
2102
+
2103
+ {
2104
+ // Fused brick4 path: skip the intermediate diffuse/specular targets and the
2105
+ // separate resolve, doing it all in a single shader. SSR isn't compatible
2106
+ // since it consumes the standalone specular target.
2107
+ const use_fused_indirect = this.fused_indirect
2108
+ && this.indirect_lighting_mode === ShadeIndirectLightingMode.Brick4
2109
+ && !this.feature_ssr_enabled;
2110
+
2111
+ if (use_fused_indirect) {
2112
+
2113
+ [current_color_out] = graph_image_pass({
2114
+ graph,
2115
+ shader: shader_brick4_indirect_lighting,
2116
+ output: [current_color_out],
2117
+ input_depth: gr_texture_depth_current,
2118
+ load_op: "load",
2119
+ inputs: {
2120
+ tDepth: gr_texture_depth_current,
2121
+ tGBufferNormals: gr_texture_normal,
2122
+ tBentNormals: bent_normals,
2123
+ tGBufferAlbedo: gr_texture_material_albedo_ao,
2124
+ tGBufferPBR: gr_texture_pbr,
2125
+ tSTBN_vec2: STATIC_GRAPHICS_ENGINE_ASSETS.stbn_vec2,
2126
+ view: view_ctx.uniform_buffer.buffer,
2127
+ camera: gr_buffer_camera_current,
2128
+ //
2129
+ brick4: scene_ctx.volumetric_light_map.buffer,
2130
+ tSplitSum: STATIC_GRAPHICS_ENGINE_ASSETS.split_sum,
2131
+ },
2132
+ });
2133
+
2134
+ } else {
2135
+
2136
+ const { indirect_specular, indirect_diffuse } = this.#graph_indirect_lighting({
2137
+ graph,
2138
+ view_ctx,
2139
+ scene_ctx,
2140
+ bent_normals,
2141
+ current_color_out,
2142
+ //
2143
+ gr_texture_depth_current,
2144
+ gr_texture_hzb,
2145
+ gr_texture_material_albedo_ao,
2146
+ gr_texture_pbr,
2147
+ gr_texture_normal,
2148
+ gr_texture_environment,
2149
+ gr_velocity,
2150
+ gr_occlusion_clip,
2151
+ gr_buffer_camera_current,
2152
+ gr_buffer_camera_previous,
2153
+ resolution,
2154
+ });
2155
+
2156
+ // resolve indirect lighting
2157
+ [current_color_out] = graph_image_pass({
2158
+ graph,
2159
+ shader: shader_resolve_indirect_lighting,
2160
+ output: [current_color_out],
2161
+ input_depth: gr_texture_depth_current,
2162
+ load_op: "load",
2163
+ inputs: {
2164
+ tIndirectDiffuse: indirect_diffuse,
2165
+ tIndirectSpecular: indirect_specular,
2166
+ //
2167
+ tGBufferNormals: gr_texture_normal,
2168
+ tBentNormals: bent_normals,
2169
+ tGBufferAlbedo: gr_texture_material_albedo_ao,
2170
+ tGBufferPBR: gr_texture_pbr,
2171
+ tDepth: gr_texture_depth_current,
2172
+ //
2173
+ camera: gr_buffer_camera_current,
2174
+ //
2175
+ tSplitSum: STATIC_GRAPHICS_ENGINE_ASSETS.split_sum,
2176
+ },
2177
+ });
2178
+
2179
+ }
2180
+
2181
+ // current_color_out = indirect_diffuse
2182
+ // current_color_out = indirect_specular
2183
+
2184
+ }
2185
+
2186
+ // current_color_out = graph_decode_rgbe9995_to_rgb16float({
2187
+ // graph,
2188
+ // input:indirect_diffuse_near_field,
2189
+ // resolution: view_ctx.resolution,
2190
+ // });
2191
+ //
2192
+ // const [norm] = graph_image_pass({
2193
+ // shader: shader_decode_octahedral_normal,
2194
+ // inputs:{
2195
+ // tInput: bent_normals,
2196
+ // },
2197
+ // graph,
2198
+ // output_resolution: view_ctx.resolution,
2199
+ // });
2200
+ //
2201
+ // [current_color_out] = graph_image_pass({
2202
+ // graph,
2203
+ // shader: shader_draw_normals,
2204
+ // inputs:{
2205
+ // tInput: norm,
2206
+ // },
2207
+ // output_resolution: view_ctx.resolution,
2208
+ // });
2209
+
2210
+ // Composite volumetric fog over the finalized opaque + background + indirect colour.
2211
+ // A dedicated pass (not inline in the shading shaders) because indirect lighting is added
2212
+ // in a separate additively-blended pass, so the full surface radiance only exists here.
2213
+ // Runs before transparency (transparent surfaces blend over the fog) and before the main
2214
+ // TAA (which then smooths the fog's per-pixel sampling noise).
2215
+ if (has_volumetrics) {
2216
+ [current_color_out] = graph_image_pass({
2217
+ graph,
2218
+ shader: shader_composite_volumetrics,
2219
+ output_resolution: view_ctx.resolution,
2220
+ inputs: {
2221
+ tColor: current_color_out,
2222
+ gBufferDepth: gr_texture_depth_current,
2223
+ tVolumetrics: volumetrics.resolved,
2224
+ tSTBN_vec3: STATIC_GRAPHICS_ENGINE_ASSETS.stbn_vec3,
2225
+ volumetrics_metadata: volumetrics.metadata,
2226
+ camera: view_ctx.camera.buffer,
2227
+ view: view_ctx.uniform_buffer.buffer,
2228
+ },
2229
+ });
2230
+ }
2231
+
2232
+ /*
2233
+ The frame has a colour for the first time, so this is where `SceneColor` is published. It is
2234
+ republished before each later phase because the built-in passes between them replace it —
2235
+ the record names which handle currently *means* the scene colour, and the graph already
2236
+ holds the dependency edge underneath.
2237
+ */
2238
+ frame.phase = FramePhase.AfterLighting;
2239
+
2240
+ const record_scene_color = frame.create(SceneColor);
2241
+
2242
+ record_scene_color.color = current_color_out;
2243
+
2244
+ this.#extensions.run(frame);
2245
+
2246
+ current_color_out = record_scene_color.color;
2247
+ gr_texture_depth_current = record_view_textures.depth;
2248
+
2249
+ if (this.#feature_enabled_transparencies) {
2250
+ // do transparent alpha pass
2251
+ graph.push_scope("transparencies");
2252
+
2253
+ current_color_out = graph_rasterize_meshes_transparent_oit({
2254
+ graph,
2255
+ buckets: gr_render_buckets,
2256
+ view_ctx,
2257
+ viewport: [0, 0, resolution_internal.x, resolution_internal.y],
2258
+ color_texture: current_color_out,
2259
+ depth_texture: gr_texture_depth_current,
2260
+
2261
+ limits: this.graphics.collection_limits,
2262
+
2263
+ light_cluster_data: light_clusters.data,
2264
+ light_cluster_lookup: light_clusters.lookup,
2265
+ light_cluster_parameters: light_clusters.parameters,
2266
+
2267
+ shadowmap_atlas: gr_shadowmap_atlas,
2268
+
2269
+ volumetrics_lut: volumetrics.resolved,
2270
+ volumetrics_metadata: volumetrics.metadata,
2271
+
2272
+ indirect_lighting_mode: this.indirect_lighting_mode,
2273
+ });
2274
+
2275
+ graph.pop_scope();
2276
+ }
2277
+
2278
+ frame.phase = FramePhase.AfterTransparency;
2279
+
2280
+ record_scene_color.color = current_color_out;
2281
+
2282
+ this.#extensions.run(frame);
2283
+
2284
+ current_color_out = record_scene_color.color;
2285
+ gr_texture_depth_current = record_view_textures.depth;
2286
+
2287
+ // current_color_out = gr_texture_material_albedo_ao;
2288
+
2289
+ if (this.feature_path_tracing_enabled) {
2290
+ current_color_out = this.path_tracer.render({
2291
+ graph,
2292
+ view: view_ctx
2293
+ });
2294
+ }
2295
+
2296
+ // Debug override: replace the post-shading color with a
2297
+ // visualization of the velocity buffer via shader_debug_velocity.
2298
+ // Direction is encoded as hue (red = +X, cyan = -X, etc.) and
2299
+ // magnitude as brightness; the AO channel of the albedo+AO
2300
+ // G-buffer modulates the static base so geometry shape is
2301
+ // still readable where motion is zero or near-zero. Done
2302
+ // BEFORE TAA so the chain stays well-formed; TAA blending
2303
+ // the debug view is meaningless, but it's debug.
2304
+ if (this.feature_velocity_debug_view) {
2305
+ [current_color_out] = graph_image_pass({
2306
+ graph,
2307
+ shader: shader_debug_velocity,
2308
+ inputs: {
2309
+ tInput: gr_velocity,
2310
+ tAlbedoAO: gr_texture_material_albedo_ao,
2311
+ },
2312
+ output_resolution: resolution_internal.asArray(),
2313
+ });
2314
+ }
2315
+
2316
+ if (this.feature_taa_enabled) {
2317
+
2318
+ if (this.upscale_type === ShadeUpscalerType.NSS) {
2319
+ current_color_out = this.nss.graph_pass({
2320
+ graph,
2321
+ texture_color_current: current_color_out,
2322
+ texture_depth_current: gr_texture_depth_current,
2323
+ texture_velocity: gr_velocity,
2324
+ texture_disocclusion_confidence: gr_occlusion_clip,
2325
+ texture_color_history: gr_texture_taa_history,
2326
+ texture_output: gr_texture_taa_out,
2327
+ render_resolution: resolution_internal.asArray(),
2328
+ output_resolution: this.#output_resolution.asArray(),
2329
+ });
2330
+ } else {
2331
+ current_color_out = taa.graph_pass({
2332
+ graph,
2333
+ texture_output: gr_texture_taa_out,
2334
+ texture_color_current: current_color_out,
2335
+ texture_color_history: gr_texture_taa_history,
2336
+ texture_velocity: gr_velocity,
2337
+ texture_occlusion: gr_occlusion_clip,
2338
+ });
2339
+ }
2340
+ }
2341
+
2342
+ // Bokeh depth of field on the resolved HDR colour. Runs after
2343
+ // TAA (blurs a clean, converged image — TAA's neighbourhood
2344
+ // clamp would otherwise fight the defocus) and before motion
2345
+ // blur / bloom, so out-of-focus highlights bloom and the bokeh
2346
+ // carries through the rest of the post chain. Perspective-only:
2347
+ // the thin-lens CoC has no meaning under orthographic.
2348
+ if (this.feature_dof_enabled && camera.isPerspectiveCamera === true) {
2349
+ // Both implementations share the same render() signature, so the
2350
+ // call site is identical — only the subsystem differs.
2351
+ const dof = this.dof_algorithm === "unreal"
2352
+ ? this.#depth_of_field_unreal
2353
+ : this.#depth_of_field;
2354
+
2355
+ current_color_out = dof.render({
2356
+ graph,
2357
+ input_color: current_color_out,
2358
+ depth: gr_texture_depth_current,
2359
+ camera,
2360
+ camera_buffer: view_ctx.camera.buffer,
2361
+ resolution: this.#output_resolution.asArray(),
2362
+ });
2363
+ }
2364
+
2365
+ // Jimenez 2014 motion blur runs on the resolved-but-not-
2366
+ // sharpened HDR colour. TAA has already converged the
2367
+ // jittered samples; sharpening, bloom, and tonemap operate
2368
+ // on the blurred output after this. Skipped when the toggle
2369
+ // is off so the rest of the chain stays bit-identical.
2370
+ if (this.feature_motion_blur_enabled) {
2371
+ current_color_out = this.#motion_blur.render({
2372
+ graph,
2373
+ input_color: current_color_out,
2374
+ velocity: gr_velocity,
2375
+ depth: gr_texture_depth_current,
2376
+ resolution: this.#output_resolution.asArray(),
2377
+ });
2378
+ }
2379
+
2380
+ // TODO if TAA is disabled, and internal resolution is < 100% - we need to do upscale
2381
+
2382
+ if (this.feature_sharpening_enabled) {
2383
+ [current_color_out] = graph_image_pass({
2384
+ graph,
2385
+ shader: shader_ffx_rcas,
2386
+ output_resolution: this.#output_resolution.asArray(),
2387
+ inputs: {
2388
+ tInput: current_color_out,
2389
+ uSharpness: {
2390
+ value: 0.8
2391
+ }
2392
+ }
2393
+ });
2394
+ }
2395
+
2396
+ let exposure = -1;
2397
+
2398
+ if (this.feature_bloom_enabled || this.feature_automatic_exposure_enabled) {
2399
+ const bloom = graph_postprocess_bloom({
2400
+ graph,
2401
+ input: current_color_out,
2402
+ resolution: this.#output_resolution.asArray(),
2403
+ });
2404
+
2405
+ if (this.feature_bloom_enabled) {
2406
+ current_color_out = bloom.composited;
2407
+ }
2408
+
2409
+ if (this.feature_automatic_exposure_enabled) {
2410
+ // TODO force time_delta_second to a very high value on view transition
2411
+
2412
+ exposure = this.#autoexposure.update({
2413
+ graph,
2414
+ input_color: bloom.downsampled,
2415
+ time_delta_seconds,
2416
+ });
2417
+ }
2418
+
2419
+ }
2420
+
2421
+
2422
+ if (this.feature_automatic_exposure_enabled === false) {
2423
+ exposure = this.#autoexposure.unadapted({ graph });
2424
+ }
2425
+
2426
+
2427
+ // current_color_out = graph_draw_texture_as_rgba({
2428
+ // graph,
2429
+ // source: gr_shadowmap_atlas,
2430
+ // resolution: this.#output_resolution.asArray(),
2431
+ // });
2432
+
2433
+ /*
2434
+ Past the upscale: the colour published here is output-sized while the G-buffer beside it is
2435
+ still internal-sized, and `FrameContext.resolution` reads whichever of them the phase draws
2436
+ into rather than a number anybody wrote down. With `feature_taa_enabled === false` no
2437
+ upscale happened and the two agree — which a constant could not express.
2438
+ */
2439
+ frame.phase = FramePhase.BeforePresent;
2440
+
2441
+ record_scene_color.color = current_color_out;
2442
+
2443
+ this.#extensions.run(frame);
2444
+
2445
+ current_color_out = record_scene_color.color;
2446
+
2447
+ if (this.#hdr_supported) {
2448
+ [current_color_out] = graph_image_pass({
2449
+ graph,
2450
+ shader: shader_tonemap_HDR,
2451
+ inputs: {
2452
+ input_color: current_color_out,
2453
+ settings: {
2454
+ peak_nits: this.#display_peak_brightness_nits,
2455
+ paper_white_nits: 100, // SDR spec is 80, but 100 has been accepted as de-facto in recent years
2456
+ },
2457
+ exposure
2458
+ },
2459
+ output: [gr_texture_canvas]
2460
+ });
2461
+ } else {
2462
+ [current_color_out] = graph_image_pass({
2463
+ graph,
2464
+ shader: shader_tonemap_LDR,
2465
+ inputs: {
2466
+ input_color: current_color_out,
2467
+ exposure
2468
+ },
2469
+ output: [gr_texture_canvas]
2470
+ });
2471
+ }
2472
+
2473
+ /*
2474
+ The canvas is written here and cannot be read: a texture may not be a render attachment and
2475
+ a sampled source in the same pass. So what this phase carries is a `PresentTarget` with one
2476
+ field and no colour to be tempted by — an extension that wants the finished image as input
2477
+ finds that out at `get` time and belongs at `BeforePresent`.
2478
+ */
2479
+ frame.phase = FramePhase.Overlay;
2480
+
2481
+ frame.create(PresentTarget).canvas = current_color_out;
2482
+
2483
+ this.#extensions.run(frame);
2484
+
2485
+ frame.close();
2486
+
2487
+ if (profile_recorder !== null) {
2488
+ // Subscribed before the graph runs; the recorder drops the handlers when it closes.
2489
+ // A frame graph is single-use, so this never outlives the frame either way.
2490
+ profile_recorder.attach_graph(graph);
2491
+ }
2492
+
2493
+ command_ctx.encodeGraph(graph);
2494
+
2495
+ command_ctx.popDebugGroup();
2496
+
2497
+ view_ctx.finish_frame(command_ctx);
2498
+
2499
+ command_ctx.finish();
2500
+
2501
+ if (profile_recorder !== null) {
2502
+ /*
2503
+ Waits on `profiling_absorbed`, not on `done`. `done` resolves from `onFinished`, which
2504
+ fires synchronously at submit — the timings have not been read back yet at that point,
2505
+ and closing there would commit an empty frame every time.
2506
+ */
2507
+ const recorder = profile_recorder;
2508
+ const session = this.profile_session;
2509
+
2510
+ command_ctx.profiling_absorbed.then(() => {
2511
+ session.end_frame(recorder, performance.now());
2512
+ });
2513
+ }
2514
+
2515
+ this.#end_frame();
2516
+
2517
+ return true;
2518
+ }
2519
+ }