@woosh/meep-engine 3.14.0 → 3.14.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (220) hide show
  1. package/README.md +33 -64
  2. package/package.json +1 -1
  3. package/src/avif/native/DECISIONS.md +544 -536
  4. package/src/avif/native/heif/parse_avif_file.d.ts.map +1 -1
  5. package/src/avif/native/heif/parse_avif_file.js +384 -383
  6. package/src/avif/native/heif/parse_image_grid.d.ts.map +1 -1
  7. package/src/avif/native/heif/parse_image_grid.js +49 -48
  8. package/src/basis/BasisBitReader.d.ts +77 -0
  9. package/src/basis/BasisBitReader.d.ts.map +1 -0
  10. package/src/basis/BasisBitReader.js +231 -0
  11. package/src/basis/BasisHuffmanTable.d.ts +53 -0
  12. package/src/basis/BasisHuffmanTable.d.ts.map +1 -0
  13. package/src/basis/BasisHuffmanTable.js +263 -0
  14. package/src/basis/basis_read_huffman_table.d.ts +20 -0
  15. package/src/basis/basis_read_huffman_table.d.ts.map +1 -0
  16. package/src/basis/basis_read_huffman_table.js +187 -0
  17. package/src/basis/etc1s/Etc1sSelectorHistory.d.ts +50 -0
  18. package/src/basis/etc1s/Etc1sSelectorHistory.d.ts.map +1 -0
  19. package/src/basis/etc1s/Etc1sSelectorHistory.js +89 -0
  20. package/src/basis/etc1s/etc1s_block_colors.d.ts +14 -0
  21. package/src/basis/etc1s/etc1s_block_colors.d.ts.map +1 -0
  22. package/src/basis/etc1s/etc1s_block_colors.js +75 -0
  23. package/src/basis/etc1s/etc1s_decode_slice.d.ts +57 -0
  24. package/src/basis/etc1s/etc1s_decode_slice.d.ts.map +1 -0
  25. package/src/basis/etc1s/etc1s_decode_slice.js +258 -0
  26. package/src/basis/etc1s/etc1s_read_endpoint_codebook.d.ts +48 -0
  27. package/src/basis/etc1s/etc1s_read_endpoint_codebook.d.ts.map +1 -0
  28. package/src/basis/etc1s/etc1s_read_endpoint_codebook.js +111 -0
  29. package/src/basis/etc1s/etc1s_read_selector_codebook.d.ts +42 -0
  30. package/src/basis/etc1s/etc1s_read_selector_codebook.d.ts.map +1 -0
  31. package/src/basis/etc1s/etc1s_read_selector_codebook.js +127 -0
  32. package/src/basis/etc1s/etc1s_read_slice_tables.d.ts +54 -0
  33. package/src/basis/etc1s/etc1s_read_slice_tables.d.ts.map +1 -0
  34. package/src/basis/etc1s/etc1s_read_slice_tables.js +47 -0
  35. package/src/basis/transcode/build_range_plan.js +54 -0
  36. package/src/basis/transcode/etc1s_to_bc1.d.ts +24 -0
  37. package/src/basis/transcode/etc1s_to_bc1.d.ts.map +1 -0
  38. package/src/basis/transcode/etc1s_to_bc1.js +205 -0
  39. package/src/basis/transcode/etc1s_to_bc7.d.ts +30 -0
  40. package/src/basis/transcode/etc1s_to_bc7.d.ts.map +1 -0
  41. package/src/basis/transcode/etc1s_to_bc7.js +496 -0
  42. package/src/basis/transcode/fit_endpoints.d.ts +59 -0
  43. package/src/basis/transcode/fit_endpoints.d.ts.map +1 -0
  44. package/src/basis/transcode/fit_endpoints.js +226 -0
  45. package/src/{avif/native/isobmff → core/binary}/ByteCursor.d.ts +19 -6
  46. package/src/core/binary/ByteCursor.d.ts.map +1 -0
  47. package/src/{avif/native/isobmff → core/binary}/ByteCursor.js +41 -14
  48. package/src/engine/EngineHarness.js +1 -1
  49. package/src/engine/asset/codec/Codec.d.ts.map +1 -0
  50. package/src/engine/asset/codec/CodecWithFallback.d.ts.map +1 -0
  51. package/src/engine/asset/{loaders/image/codec → codec}/CodecWithFallback.js +2 -2
  52. package/src/engine/asset/loaders/image/IMAGE_CODEC_REVIEW_2026_08_28.md +4 -4
  53. package/src/engine/asset/loaders/image/ImageRGBADataLoader.d.ts +1 -1
  54. package/src/engine/asset/loaders/image/ImageRGBADataLoader.d.ts.map +1 -1
  55. package/src/engine/asset/loaders/image/ImageRGBADataLoader.js +1 -1
  56. package/src/engine/asset/loaders/image/codec/NativeImageDecoder.d.ts +1 -1
  57. package/src/engine/asset/loaders/image/codec/NativeImageDecoder.d.ts.map +1 -1
  58. package/src/engine/asset/loaders/image/codec/NativeImageDecoder.js +1 -1
  59. package/src/engine/asset/loaders/image/codec/ThreadedImageDecoder.d.ts +1 -1
  60. package/src/engine/asset/loaders/image/codec/ThreadedImageDecoder.d.ts.map +1 -1
  61. package/src/engine/asset/loaders/image/codec/ThreadedImageDecoder.js +1 -1
  62. package/src/engine/graphics/texture/atlas/TextureAtlas.d.ts.map +1 -1
  63. package/src/engine/graphics/texture/atlas/TextureAtlas.js +13 -0
  64. package/src/engine/physics/broadphase/generate_pairs.d.ts.map +1 -1
  65. package/src/engine/physics/broadphase/generate_pairs.js +7 -1
  66. package/src/engine/physics/fluid/ecs/FluidObstacleSystem.d.ts +4 -4
  67. package/src/ktx2/KTX2_IDENTIFIER.d.ts +14 -0
  68. package/src/ktx2/KTX2_IDENTIFIER.d.ts.map +1 -0
  69. package/src/ktx2/KTX2_IDENTIFIER.js +15 -0
  70. package/src/ktx2/KhrDfModel.d.ts +35 -0
  71. package/src/ktx2/KhrDfModel.d.ts.map +1 -0
  72. package/src/ktx2/KhrDfModel.js +49 -0
  73. package/src/ktx2/SupercompressionScheme.d.ts +16 -0
  74. package/src/ktx2/SupercompressionScheme.d.ts.map +1 -0
  75. package/src/ktx2/SupercompressionScheme.js +23 -0
  76. package/src/ktx2/ktx2_read.d.ts +71 -0
  77. package/src/ktx2/ktx2_read.d.ts.map +1 -0
  78. package/src/ktx2/ktx2_read.js +581 -0
  79. package/src/ktx2/ktx2_read_basis_lz_global_data.d.ts +27 -0
  80. package/src/ktx2/ktx2_read_basis_lz_global_data.d.ts.map +1 -0
  81. package/src/ktx2/ktx2_read_basis_lz_global_data.js +189 -0
  82. package/src/ktx2/vk_format_to_texture_format.d.ts +55 -0
  83. package/src/ktx2/vk_format_to_texture_format.d.ts.map +1 -0
  84. package/src/ktx2/vk_format_to_texture_format.js +290 -0
  85. package/src/shade/descriptor/GPUTextureUsage.d.ts +23 -0
  86. package/src/shade/descriptor/GPUTextureUsage.d.ts.map +1 -0
  87. package/src/shade/descriptor/GPUTextureUsage.js +24 -0
  88. package/src/shade/descriptor/WebGPUExtensionType.d.ts +3 -0
  89. package/src/shade/descriptor/WebGPUExtensionType.js +26 -0
  90. package/src/shade/descriptor/texture/TextureDescriptor.d.ts +2 -6
  91. package/src/shade/descriptor/texture/TextureDescriptor.d.ts.map +1 -1
  92. package/src/shade/descriptor/texture/TextureDescriptor.js +24 -40
  93. package/src/shade/descriptor/texture/format/TextureFormat.d.ts +125 -0
  94. package/src/shade/descriptor/texture/format/TextureFormat.d.ts.map +1 -0
  95. package/src/shade/descriptor/texture/format/TextureFormat.js +146 -0
  96. package/src/shade/descriptor/texture/format/gpu_texture_format_info.d.ts +60 -0
  97. package/src/shade/descriptor/texture/format/gpu_texture_format_info.d.ts.map +1 -1
  98. package/src/shade/descriptor/texture/format/gpu_texture_format_info.js +102 -0
  99. package/src/shade/device/graph/TextureResourceDescriptor.d.ts.map +1 -1
  100. package/src/shade/device/graph/TextureResourceDescriptor.js +160 -155
  101. package/src/shade/device/mock/SoftwareGPUQueue.d.ts +11 -4
  102. package/src/shade/device/mock/SoftwareGPUQueue.d.ts.map +1 -1
  103. package/src/shade/device/mock/SoftwareGPUQueue.js +31 -37
  104. package/src/shade/device/mock/SoftwareGPUTexture.d.ts.map +1 -1
  105. package/src/shade/device/mock/SoftwareGPUTexture.js +8 -4
  106. package/src/shade/device/timing/profile/frame_graph_extract_topology.d.ts.map +1 -1
  107. package/src/shade/device/timing/profile/frame_graph_extract_topology.js +164 -174
  108. package/src/shade/playground/ground_seam/README.md +235 -0
  109. package/src/shade/playground/ground_seam/capture_scene_color.d.ts +45 -0
  110. package/src/shade/playground/ground_seam/capture_scene_color.d.ts.map +1 -0
  111. package/src/shade/playground/ground_seam/capture_scene_color.js +242 -0
  112. package/src/shade/playground/ground_seam/depth_step_across_seam.d.ts +11 -0
  113. package/src/shade/playground/ground_seam/depth_step_across_seam.d.ts.map +1 -0
  114. package/src/shade/playground/ground_seam/depth_step_across_seam.js +185 -0
  115. package/src/shade/playground/ground_seam/index.html +195 -0
  116. package/src/shade/playground/ground_seam/main.d.ts +2 -0
  117. package/src/shade/playground/ground_seam/main.d.ts.map +1 -0
  118. package/src/shade/playground/ground_seam/main.js +879 -0
  119. package/src/shade/playground/ground_seam/make_grid_texture.d.ts +29 -0
  120. package/src/shade/playground/ground_seam/make_grid_texture.d.ts.map +1 -0
  121. package/src/shade/playground/ground_seam/make_grid_texture.js +105 -0
  122. package/src/shade/playground/ground_seam/make_ground.d.ts +70 -0
  123. package/src/shade/playground/ground_seam/make_ground.d.ts.map +1 -0
  124. package/src/shade/playground/ground_seam/make_ground.js +161 -0
  125. package/src/shade/playground/ground_seam/measure_flicker.d.ts +71 -0
  126. package/src/shade/playground/ground_seam/measure_flicker.d.ts.map +1 -0
  127. package/src/shade/playground/ground_seam/measure_flicker.js +531 -0
  128. package/src/shade/renderer/Renderer.d.ts.map +1 -1
  129. package/src/shade/renderer/Renderer.js +2519 -2511
  130. package/src/shade/renderer/hiz/HierarchicalZBuffer.d.ts.map +1 -1
  131. package/src/shade/renderer/hiz/HierarchicalZBuffer.js +275 -274
  132. package/src/shade/renderer/light/GPULightCollection.d.ts.map +1 -1
  133. package/src/shade/renderer/light/GPULightCollection.js +323 -314
  134. package/src/shade/renderer/lightmap/GPULightMap.js +336 -336
  135. package/src/shade/renderer/material/resident/GPUResidentMaterialContext.d.ts.map +1 -1
  136. package/src/shade/renderer/material/resident/GPUResidentMaterialContext.js +12 -2
  137. package/src/shade/renderer/material/standard/fragment_gbuffer.d.ts.map +1 -1
  138. package/src/shade/renderer/material/standard/fragment_gbuffer.js +3 -1
  139. package/src/shade/renderer/material/standard/fragment_gbuffer_vt.js +169 -169
  140. package/src/shade/renderer/path_tracer/shader/chunk_sample_material_data.d.ts.map +1 -1
  141. package/src/shade/renderer/path_tracer/shader/chunk_sample_material_data.js +3 -1
  142. package/src/shade/renderer/postprocess/nss/NSS.d.ts +1 -1
  143. package/src/shade/renderer/rasterize/native/oit/chunk_forward_shade_standard_fragment_brick4.d.ts.map +1 -1
  144. package/src/shade/renderer/rasterize/native/oit/chunk_forward_shade_standard_fragment_brick4.js +3 -1
  145. package/src/shade/renderer/rasterize/native/oit/chunk_forward_shade_standard_fragment_ibl.d.ts.map +1 -1
  146. package/src/shade/renderer/rasterize/native/oit/chunk_forward_shade_standard_fragment_ibl.js +3 -1
  147. package/src/shade/renderer/shader/chunk/geometry/normal/chunk_decode_tangent_normal.d.ts +28 -0
  148. package/src/shade/renderer/shader/chunk/geometry/normal/chunk_decode_tangent_normal.d.ts.map +1 -0
  149. package/src/shade/renderer/shader/chunk/geometry/normal/chunk_decode_tangent_normal.js +39 -0
  150. package/src/shade/renderer/shader/chunk/geometry/triangle/chunk_barycentric_full.d.ts +45 -0
  151. package/src/shade/renderer/shader/chunk/geometry/triangle/chunk_barycentric_full.d.ts.map +1 -1
  152. package/src/shade/renderer/shader/chunk/geometry/triangle/chunk_barycentric_full.js +94 -61
  153. package/src/shade/renderer/shader/chunk/geometry/triangle/chunk_barycentric_solve.d.ts +24 -0
  154. package/src/shade/renderer/shader/chunk/geometry/triangle/chunk_barycentric_solve.d.ts.map +1 -0
  155. package/src/shade/renderer/shader/chunk/geometry/triangle/chunk_barycentric_solve.js +43 -0
  156. package/src/shade/renderer/texture/COMPRESSED_TEXTURE_PLAN_2026_09_01.md +1462 -0
  157. package/src/shade/renderer/texture/TextureManager.d.ts.map +1 -1
  158. package/src/shade/renderer/texture/TextureManager.js +20 -8
  159. package/src/shade/renderer/texture/TextureRole.d.ts +19 -0
  160. package/src/shade/renderer/texture/TextureRole.d.ts.map +1 -0
  161. package/src/shade/renderer/texture/TextureRole.js +26 -0
  162. package/src/shade/renderer/texture/TextureVariantSet.d.ts +71 -0
  163. package/src/shade/renderer/texture/TextureVariantSet.d.ts.map +1 -0
  164. package/src/shade/renderer/texture/TextureVariantSet.js +105 -0
  165. package/src/shade/renderer/texture/download_texture_data.d.ts.map +1 -1
  166. package/src/shade/renderer/texture/download_texture_data.js +22 -0
  167. package/src/shade/renderer/texture/format/gpu_texture_compression_support.d.ts +15 -0
  168. package/src/shade/renderer/texture/format/gpu_texture_compression_support.d.ts.map +1 -0
  169. package/src/shade/renderer/texture/format/gpu_texture_compression_support.js +50 -0
  170. package/src/shade/renderer/texture/format/gpu_texture_format_can_generate_mipmaps.d.ts +27 -0
  171. package/src/shade/renderer/texture/format/gpu_texture_format_can_generate_mipmaps.d.ts.map +1 -0
  172. package/src/shade/renderer/texture/format/gpu_texture_format_can_generate_mipmaps.js +65 -0
  173. package/src/shade/renderer/texture/format/infer_format_from_parameters.d.ts +11 -0
  174. package/src/shade/renderer/texture/format/infer_format_from_parameters.d.ts.map +1 -0
  175. package/src/shade/renderer/texture/format/infer_format_from_parameters.js +88 -0
  176. package/src/shade/renderer/texture/format/texture_format_from_shade_image.d.ts +24 -0
  177. package/src/shade/renderer/texture/format/texture_format_from_shade_image.d.ts.map +1 -0
  178. package/src/shade/renderer/texture/format/texture_format_from_shade_image.js +71 -0
  179. package/src/shade/renderer/texture/format/texture_format_preference.d.ts +22 -0
  180. package/src/shade/renderer/texture/format/texture_format_preference.d.ts.map +1 -0
  181. package/src/shade/renderer/texture/format/texture_format_preference.js +89 -0
  182. package/src/shade/renderer/texture/format/texture_variant_select.d.ts +24 -0
  183. package/src/shade/renderer/texture/format/texture_variant_select.d.ts.map +1 -0
  184. package/src/shade/renderer/texture/format/texture_variant_select.js +38 -0
  185. package/src/shade/renderer/texture/shade_texture_might_have_alpha.d.ts +9 -1
  186. package/src/shade/renderer/texture/shade_texture_might_have_alpha.d.ts.map +1 -1
  187. package/src/shade/renderer/texture/shade_texture_might_have_alpha.js +73 -8
  188. package/src/shade/renderer/texture/source/AlphaMode.d.ts +27 -0
  189. package/src/shade/renderer/texture/source/AlphaMode.d.ts.map +1 -0
  190. package/src/shade/renderer/texture/source/AlphaMode.js +52 -0
  191. package/src/shade/renderer/texture/source/ShadeImage.d.ts +33 -0
  192. package/src/shade/renderer/texture/source/ShadeImage.d.ts.map +1 -1
  193. package/src/shade/renderer/texture/source/ShadeImage.js +74 -0
  194. package/src/shade/renderer/texture/source/ShadeTexelData.d.ts +78 -0
  195. package/src/shade/renderer/texture/source/ShadeTexelData.d.ts.map +1 -0
  196. package/src/shade/renderer/texture/source/ShadeTexelData.js +158 -0
  197. package/src/shade/renderer/texture/texture_descriptor_from_texture_shade.d.ts +0 -10
  198. package/src/shade/renderer/texture/texture_descriptor_from_texture_shade.d.ts.map +1 -1
  199. package/src/shade/renderer/texture/texture_descriptor_from_texture_shade.js +73 -175
  200. package/src/shade/renderer/texture/texture_write_level.d.ts +32 -0
  201. package/src/shade/renderer/texture/texture_write_level.d.ts.map +1 -0
  202. package/src/shade/renderer/texture/texture_write_level.js +77 -0
  203. package/src/shade/renderer/texture/texture_write_to_gpu.d.ts +8 -1
  204. package/src/shade/renderer/texture/texture_write_to_gpu.d.ts.map +1 -1
  205. package/src/shade/renderer/texture/texture_write_to_gpu.js +62 -37
  206. package/src/shade/renderer/texture/virtual/source/VTSourceImage.d.ts +8 -0
  207. package/src/shade/renderer/texture/virtual/source/VTSourceImage.d.ts.map +1 -1
  208. package/src/shade/renderer/texture/virtual/source/VTSourceImage.js +8 -0
  209. package/src/shade/util/texture_mip_extent.d.ts +49 -0
  210. package/src/shade/util/texture_mip_extent.d.ts.map +1 -0
  211. package/src/shade/util/texture_mip_extent.js +87 -0
  212. package/src/avif/native/isobmff/ByteCursor.d.ts.map +0 -1
  213. package/src/engine/asset/loaders/image/codec/Codec.d.ts.map +0 -1
  214. package/src/engine/asset/loaders/image/codec/CodecWithFallback.d.ts.map +0 -1
  215. package/src/shade/util/compute_max_mip_count.d.ts +0 -8
  216. package/src/shade/util/compute_max_mip_count.d.ts.map +0 -1
  217. package/src/shade/util/compute_max_mip_count.js +0 -27
  218. /package/src/engine/asset/{loaders/image/codec → codec}/Codec.d.ts +0 -0
  219. /package/src/engine/asset/{loaders/image/codec → codec}/Codec.js +0 -0
  220. /package/src/engine/asset/{loaders/image/codec → codec}/CodecWithFallback.d.ts +0 -0
@@ -1,61 +1,94 @@
1
- import { BARYCENTRIC_STRUCT } from "./BARYCENTRIC_STRUCT.js";
2
- import { CodeChunk } from "../../../compiler/CodeChunk.js";
3
-
4
- /*
5
- references:
6
- http://filmicworlds.com/blog/visibility-buffer-rendering-with-material-graphs/
7
- https://github.com/ssloy/tinyrenderer/wiki/Lesson-2:-Triangle-rasterization-and-back-face-culling
8
-
9
- */
10
-
11
-
12
- export const chunk_barycentric_full = CodeChunk.from(
13
- // language=WGSL
14
- `
15
- fn barycentric_full(
16
- pt0: vec4<f32>,
17
- pt1: vec4<f32>,
18
- pt2: vec4<f32>,
19
- pixel: vec2<f32>
20
- ) -> ${BARYCENTRIC_STRUCT.wgsl_ref} {
21
- let invW:vec3<f32> = 1.0 / vec3<f32>(pt0.w, pt1.w, pt2.w);
22
-
23
- let ndc0:vec2<f32> = pt0.xy * invW.x;
24
- let ndc1:vec2<f32> = pt1.xy * invW.y;
25
- let ndc2:vec2<f32> = pt2.xy * invW.z;
26
-
27
- let det_multiplier:vec3<f32> = invW / (determinant(mat2x2(ndc2 - ndc1, ndc0 - ndc1)));
28
-
29
- let m_ddx = vec3<f32>(ndc1.y - ndc2.y, ndc2.y - ndc0.y, ndc0.y - ndc1.y) * det_multiplier;
30
- let m_ddy = vec3<f32>(ndc2.x - ndc1.x, ndc0.x - ndc2.x, ndc1.x - ndc0.x) * det_multiplier;
31
-
32
- let ddxSum:f32 = dot(m_ddx, vec3<f32>(1,1,1));
33
- let ddySum:f32 = dot(m_ddy, vec3<f32>(1,1,1));
34
-
35
- let deltaVec:vec2<f32> = pixel - ndc0;
36
-
37
- let interpInvW:f32 = invW.x + deltaVec.x * ddxSum + deltaVec.y * ddySum;
38
- let interpW:f32 = 1.0 / interpInvW;
39
-
40
- let m_lambda = vec3<f32>(
41
- interpW * (invW.x + deltaVec.x * m_ddx.x + deltaVec.y * m_ddy.x),
42
- interpW * (0.0f + deltaVec.x * m_ddx.y + deltaVec.y * m_ddy.y),
43
- interpW * (0.0f + deltaVec.x * m_ddx.z + deltaVec.y * m_ddy.z)
44
- );
45
-
46
- let interpW_ddx:f32 = 1.0f / (interpInvW + ddxSum);
47
- let interpW_ddy:f32 = 1.0f / (interpInvW + ddySum);
48
-
49
- let liw = m_lambda * interpInvW;
50
-
51
- return ${BARYCENTRIC_STRUCT.wgsl_ref}(
52
- m_lambda,
53
- interpW_ddx * (liw + m_ddx) - m_lambda,
54
- interpW_ddy * (liw + m_ddy) - m_lambda
55
- );
56
- }
57
- `,
58
- [
59
- BARYCENTRIC_STRUCT.declaration_chunk
60
- ]
61
- );
1
+ import { BARYCENTRIC_STRUCT } from "./BARYCENTRIC_STRUCT.js";
2
+ import { CodeChunk } from "../../../compiler/CodeChunk.js";
3
+ import { chunk_barycentric_solve } from "./chunk_barycentric_solve.js";
4
+
5
+ /*
6
+ references:
7
+ http://filmicworlds.com/blog/visibility-buffer-rendering-with-material-graphs/
8
+ https://github.com/ssloy/tinyrenderer/wiki/Lesson-2:-Triangle-rasterization-and-back-face-culling
9
+ Olano & Greer 1997, "Triangle Scan Conversion using 2D Homogeneous Coordinates"
10
+ */
11
+
12
+ /**
13
+ * Perspective-correct barycentric coordinates for a pixel inside a triangle, with the per-pixel
14
+ * derivatives the texture gradients are built from.
15
+ *
16
+ * ## What it solves
17
+ *
18
+ * A point of the triangle with barycentric `l` sits at clip position `sum(l_i * P_i)` and therefore
19
+ * at screen position `sum(l_i * P_i.xy) / sum(l_i * P_i.w)`. Asking for the `l` whose screen
20
+ * position is this pixel gives two linear equations, and `sum(l) == 1` gives the third:
21
+ *
22
+ * ```
23
+ * sum_i l_i * (x_i - pixel.x * w_i) = 0
24
+ * sum_i l_i * (y_i - pixel.y * w_i) = 0
25
+ * sum_i l_i = 1
26
+ * ```
27
+ *
28
+ * This function forms the two pixel-relative coordinate vectors that system is written in;
29
+ * {@link chunk_barycentric_solve} solves it.
30
+ *
31
+ * ## Why it is written this way
32
+ *
33
+ * **It never divides by w.** A vertex on the eye plane has `w == 0` and one behind it has `w < 0`;
34
+ * projecting either to NDC first yields an infinity or a sign-flipped coordinate hundreds of
35
+ * thousands of pixels outside the viewport, and every later term then has to cancel that magnitude
36
+ * back down. Here `w` only ever multiplies, so a triangle straddling the eye plane is an ordinary
37
+ * case rather than a near-singular one.
38
+ *
39
+ * **It has no anchor, and that is the point.** The previous formulation measured every pixel from
40
+ * `pixel - ndc0` and scaled by a determinant taken about vertex 1, so vertex 0 was the origin of
41
+ * the whole reconstruction and the three corners were not interchangeable. In exact arithmetic that
42
+ * is irrelevant. In f32, on a triangle whose corners project far outside the viewport, it is not:
43
+ * the rounding depended on which corner was first, so two coplanar triangles meeting along an edge
44
+ * reconstructed measurably different UVs on either side of it — and the difference moved with the
45
+ * TAA jitter, which turned it into a temporally unstable seam along the shared edge. Invisible in a
46
+ * still frame, plainly visible in a multi-frame difference. `src/shade/playground/ground_seam`
47
+ * measures it, and measured this rewrite: the seam goes from a 2.1x step in per-pixel temporal
48
+ * spread to none, and a two-triangle quad now behaves like the same quad subdivided 8x8.
49
+ *
50
+ * **The derivatives are evaluations, not a differentiation.** `ddx` is defined as
51
+ * `lambda(pixel + (1,0)) - lambda(pixel)`, a whole-pixel forward difference, which is what mip
52
+ * selection wants; it is computed by solving the same system one pixel over. Stepping the pixel by
53
+ * one in x subtracts `w` from `u`, so the second and third solves share every input with the first.
54
+ *
55
+ * @type {CodeChunk}
56
+ */
57
+ export const chunk_barycentric_full = CodeChunk.from(
58
+ // language=WGSL
59
+ `
60
+ fn barycentric_full(
61
+ pt0: vec4<f32>,
62
+ pt1: vec4<f32>,
63
+ pt2: vec4<f32>,
64
+ pixel: vec2<f32>
65
+ ) -> ${BARYCENTRIC_STRUCT.wgsl_ref} {
66
+ let w = vec3<f32>(pt0.w, pt1.w, pt2.w);
67
+
68
+ /*
69
+ Each vertex's offset from the pixel's ray, in homogeneous coordinates. This is where the
70
+ triangle's size is cancelled against the pixel's position, and it is deliberately the only
71
+ place that happens: one multiply-subtract per component, which a driver may contract into a
72
+ single fused operation, rather than a chain of large intermediates left to cancel each other
73
+ several steps later.
74
+ */
75
+ let u = fma(vec3<f32>(-pixel.x), w, vec3<f32>(pt0.x, pt1.x, pt2.x));
76
+ let v = fma(vec3<f32>(-pixel.y), w, vec3<f32>(pt0.y, pt1.y, pt2.y));
77
+
78
+ // one pixel along x subtracts w from u; one along y subtracts w from v
79
+ let lambda = barycentric_solve(u, v);
80
+ let lambda_x = barycentric_solve(u - w, v);
81
+ let lambda_y = barycentric_solve(u, v - w);
82
+
83
+ return ${BARYCENTRIC_STRUCT.wgsl_ref}(
84
+ lambda,
85
+ lambda_x - lambda,
86
+ lambda_y - lambda
87
+ );
88
+ }
89
+ `,
90
+ [
91
+ BARYCENTRIC_STRUCT.declaration_chunk,
92
+ chunk_barycentric_solve
93
+ ]
94
+ );
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Barycentric weights of a point inside a triangle, by Cramer's rule, from coordinates already
3
+ * expressed relative to that point.
4
+ *
5
+ * The caller supplies `u` and `v`: for each corner `i`, `u[i] = x_i - point.x * w_i` and
6
+ * `v[i] = y_i - point.y * w_i`, in homogeneous clip coordinates. Those are the two equations that
7
+ * say "the corners, weighted, project to this point"; together with the weights summing to one they
8
+ * make a 3x3 system, and the three 2x2 determinants below are its Cramer solution.
9
+ *
10
+ * Separated from {@link chunk_barycentric_full} because it is the whole of the arithmetic and none
11
+ * of the setup, so it can be read, tested and reused on its own — {@link chunk_barycentric_full}
12
+ * calls it three times per pixel, once for the pixel and once for each of its two neighbours.
13
+ *
14
+ * **Cyclically symmetric, deliberately.** Each weight is the same expression in the other two
15
+ * corners, so rotating which corner is first permutes the result and changes nothing else. That is
16
+ * not an aesthetic property: a formulation that measures from one distinguished corner rounds
17
+ * differently depending on which corner that is, and two coplanar triangles then disagree about the
18
+ * surface they share. See `src/shade/playground/ground_seam`.
19
+ *
20
+ * @type {CodeChunk}
21
+ */
22
+ export const chunk_barycentric_solve: CodeChunk;
23
+ import { CodeChunk } from "../../../compiler/CodeChunk.js";
24
+ //# sourceMappingURL=chunk_barycentric_solve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chunk_barycentric_solve.d.ts","sourceRoot":"","sources":["../../../../../../../../src/shade/renderer/shader/chunk/geometry/triangle/chunk_barycentric_solve.js"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,sCAFU,SAAS,CAqBjB;0BA1CwB,gCAAgC"}
@@ -0,0 +1,43 @@
1
+ import { CodeChunk } from "../../../compiler/CodeChunk.js";
2
+
3
+ /**
4
+ * Barycentric weights of a point inside a triangle, by Cramer's rule, from coordinates already
5
+ * expressed relative to that point.
6
+ *
7
+ * The caller supplies `u` and `v`: for each corner `i`, `u[i] = x_i - point.x * w_i` and
8
+ * `v[i] = y_i - point.y * w_i`, in homogeneous clip coordinates. Those are the two equations that
9
+ * say "the corners, weighted, project to this point"; together with the weights summing to one they
10
+ * make a 3x3 system, and the three 2x2 determinants below are its Cramer solution.
11
+ *
12
+ * Separated from {@link chunk_barycentric_full} because it is the whole of the arithmetic and none
13
+ * of the setup, so it can be read, tested and reused on its own — {@link chunk_barycentric_full}
14
+ * calls it three times per pixel, once for the pixel and once for each of its two neighbours.
15
+ *
16
+ * **Cyclically symmetric, deliberately.** Each weight is the same expression in the other two
17
+ * corners, so rotating which corner is first permutes the result and changes nothing else. That is
18
+ * not an aesthetic property: a formulation that measures from one distinguished corner rounds
19
+ * differently depending on which corner that is, and two coplanar triangles then disagree about the
20
+ * surface they share. See `src/shade/playground/ground_seam`.
21
+ *
22
+ * @type {CodeChunk}
23
+ */
24
+ export const chunk_barycentric_solve = CodeChunk.from(
25
+ // language=WGSL
26
+ `
27
+ fn barycentric_solve(u: vec3<f32>, v: vec3<f32>) -> vec3<f32> {
28
+ let cofactor = vec3<f32>(
29
+ u.y * v.z - u.z * v.y,
30
+ u.z * v.x - u.x * v.z,
31
+ u.x * v.y - u.y * v.x,
32
+ );
33
+
34
+ /*
35
+ The cofactors carry a common factor of the triangle's homogeneous area, which this divides out
36
+ — so it is never formed, and a sliver divides by its own signed area rather than by anything
37
+ larger. For a point inside the triangle all three share a sign, making this sum the one place
38
+ in the function where nothing cancels.
39
+ */
40
+ return cofactor / (cofactor.x + cofactor.y + cofactor.z);
41
+ }
42
+ `
43
+ );