@ifc-lite/renderer 6.4.0 → 6.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (223) hide show
  1. package/dist/camera-animation.d.ts +7 -1
  2. package/dist/camera-animation.d.ts.map +1 -1
  3. package/dist/camera-animation.js +19 -3
  4. package/dist/camera-animation.js.map +1 -1
  5. package/dist/camera-fit-geometry.d.ts +47 -0
  6. package/dist/camera-fit-geometry.d.ts.map +1 -0
  7. package/dist/camera-fit-geometry.js +44 -0
  8. package/dist/camera-fit-geometry.js.map +1 -0
  9. package/dist/camera-framing.d.ts +27 -21
  10. package/dist/camera-framing.d.ts.map +1 -1
  11. package/dist/camera-framing.js +47 -44
  12. package/dist/camera-framing.js.map +1 -1
  13. package/dist/camera-preset-view.d.ts +18 -0
  14. package/dist/camera-preset-view.d.ts.map +1 -1
  15. package/dist/camera-preset-view.js +42 -0
  16. package/dist/camera-preset-view.js.map +1 -1
  17. package/dist/camera.d.ts +14 -1
  18. package/dist/camera.d.ts.map +1 -1
  19. package/dist/camera.js +14 -2
  20. package/dist/camera.js.map +1 -1
  21. package/dist/clip-types.d.ts +35 -0
  22. package/dist/clip-types.d.ts.map +1 -0
  23. package/dist/clip-types.js +5 -0
  24. package/dist/clip-types.js.map +1 -0
  25. package/dist/device-recovery.js +11 -1
  26. package/dist/device-recovery.js.map +1 -1
  27. package/dist/device.d.ts +4 -4
  28. package/dist/device.js +9 -9
  29. package/dist/device.js.map +1 -1
  30. package/dist/extra-clip-planes.d.ts +57 -0
  31. package/dist/extra-clip-planes.d.ts.map +1 -0
  32. package/dist/extra-clip-planes.js +161 -0
  33. package/dist/extra-clip-planes.js.map +1 -0
  34. package/dist/gpu-counters.d.ts +4 -2
  35. package/dist/gpu-counters.d.ts.map +1 -1
  36. package/dist/gpu-counters.js +9 -6
  37. package/dist/gpu-counters.js.map +1 -1
  38. package/dist/index.d.ts +18 -5
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +68 -90
  41. package/dist/index.js.map +1 -1
  42. package/dist/mesh-rte-uniforms.d.ts +7 -3
  43. package/dist/mesh-rte-uniforms.d.ts.map +1 -1
  44. package/dist/mesh-rte-uniforms.js +16 -2
  45. package/dist/mesh-rte-uniforms.js.map +1 -1
  46. package/dist/opaque-visibility-commands.d.ts +3 -0
  47. package/dist/opaque-visibility-commands.d.ts.map +1 -0
  48. package/dist/opaque-visibility-commands.js +11 -0
  49. package/dist/opaque-visibility-commands.js.map +1 -0
  50. package/dist/opaque-visibility-pass.d.ts +37 -0
  51. package/dist/opaque-visibility-pass.d.ts.map +1 -0
  52. package/dist/opaque-visibility-pass.js +230 -0
  53. package/dist/opaque-visibility-pass.js.map +1 -0
  54. package/dist/pick-types.d.ts +5 -1
  55. package/dist/pick-types.d.ts.map +1 -1
  56. package/dist/picker-rte-uniforms.d.ts +1 -1
  57. package/dist/picker-rte-uniforms.d.ts.map +1 -1
  58. package/dist/picker-rte-uniforms.js +4 -2
  59. package/dist/picker-rte-uniforms.js.map +1 -1
  60. package/dist/picker-shaders.d.ts +5 -0
  61. package/dist/picker-shaders.d.ts.map +1 -0
  62. package/dist/picker-shaders.js +157 -0
  63. package/dist/picker-shaders.js.map +1 -0
  64. package/dist/picker.d.ts +3 -0
  65. package/dist/picker.d.ts.map +1 -1
  66. package/dist/picker.js +43 -133
  67. package/dist/picker.js.map +1 -1
  68. package/dist/pipeline.d.ts +5 -9
  69. package/dist/pipeline.d.ts.map +1 -1
  70. package/dist/pipeline.js +34 -29
  71. package/dist/pipeline.js.map +1 -1
  72. package/dist/point-picker.d.ts +2 -1
  73. package/dist/point-picker.d.ts.map +1 -1
  74. package/dist/point-picker.js +12 -4
  75. package/dist/point-picker.js.map +1 -1
  76. package/dist/pointcloud/point-cloud-renderer.d.ts +4 -4
  77. package/dist/pointcloud/point-cloud-renderer.d.ts.map +1 -1
  78. package/dist/pointcloud/point-cloud-renderer.js +1 -1
  79. package/dist/pointcloud/point-cloud-renderer.js.map +1 -1
  80. package/dist/pointcloud/point-cloud-uniforms.d.ts +3 -1
  81. package/dist/pointcloud/point-cloud-uniforms.d.ts.map +1 -1
  82. package/dist/pointcloud/point-cloud-uniforms.js +3 -1
  83. package/dist/pointcloud/point-cloud-uniforms.js.map +1 -1
  84. package/dist/pointcloud/point-pipeline.d.ts +3 -1
  85. package/dist/pointcloud/point-pipeline.d.ts.map +1 -1
  86. package/dist/pointcloud/point-pipeline.js +4 -1
  87. package/dist/pointcloud/point-pipeline.js.map +1 -1
  88. package/dist/pointcloud/point-shader.wgsl.d.ts +1 -1
  89. package/dist/pointcloud/point-shader.wgsl.d.ts.map +1 -1
  90. package/dist/pointcloud/point-shader.wgsl.js +8 -0
  91. package/dist/pointcloud/point-shader.wgsl.js.map +1 -1
  92. package/dist/post-pass-chain.d.ts +1 -0
  93. package/dist/post-pass-chain.d.ts.map +1 -1
  94. package/dist/post-pass-chain.js +1 -0
  95. package/dist/post-pass-chain.js.map +1 -1
  96. package/dist/quantized-lifecycle.d.ts +6 -0
  97. package/dist/quantized-lifecycle.d.ts.map +1 -0
  98. package/dist/quantized-lifecycle.js +19 -0
  99. package/dist/quantized-lifecycle.js.map +1 -0
  100. package/dist/raycast-engine.d.ts.map +1 -1
  101. package/dist/raycast-engine.js +3 -2
  102. package/dist/raycast-engine.js.map +1 -1
  103. package/dist/render-section-draw.d.ts +5 -0
  104. package/dist/render-section-draw.d.ts.map +1 -1
  105. package/dist/render-section-draw.js +59 -25
  106. package/dist/render-section-draw.js.map +1 -1
  107. package/dist/render-section-plane.d.ts +5 -33
  108. package/dist/render-section-plane.d.ts.map +1 -1
  109. package/dist/render-section-plane.js +8 -175
  110. package/dist/render-section-plane.js.map +1 -1
  111. package/dist/renderer-frame-timing.d.ts +1 -0
  112. package/dist/renderer-frame-timing.d.ts.map +1 -1
  113. package/dist/renderer-frame-timing.js +8 -1
  114. package/dist/renderer-frame-timing.js.map +1 -1
  115. package/dist/renderer-overlays.d.ts +8 -2
  116. package/dist/renderer-overlays.d.ts.map +1 -1
  117. package/dist/renderer-overlays.js +22 -45
  118. package/dist/renderer-overlays.js.map +1 -1
  119. package/dist/scene-raycaster.d.ts +1 -1
  120. package/dist/scene-raycaster.d.ts.map +1 -1
  121. package/dist/scene-raycaster.js +18 -44
  122. package/dist/scene-raycaster.js.map +1 -1
  123. package/dist/scene-rect-select.d.ts.map +1 -1
  124. package/dist/scene-rect-select.js +2 -1
  125. package/dist/scene-rect-select.js.map +1 -1
  126. package/dist/section-2d-lift.d.ts +25 -0
  127. package/dist/section-2d-lift.d.ts.map +1 -1
  128. package/dist/section-2d-lift.js +35 -0
  129. package/dist/section-2d-lift.js.map +1 -1
  130. package/dist/section-2d-overlay.d.ts +41 -12
  131. package/dist/section-2d-overlay.d.ts.map +1 -1
  132. package/dist/section-2d-overlay.js +121 -179
  133. package/dist/section-2d-overlay.js.map +1 -1
  134. package/dist/section-2d-types.d.ts +2 -0
  135. package/dist/section-2d-types.d.ts.map +1 -1
  136. package/dist/section-cap-geometry.d.ts +33 -0
  137. package/dist/section-cap-geometry.d.ts.map +1 -0
  138. package/dist/section-cap-geometry.js +137 -0
  139. package/dist/section-cap-geometry.js.map +1 -0
  140. package/dist/section-cap-set.d.ts +60 -0
  141. package/dist/section-cap-set.d.ts.map +1 -0
  142. package/dist/section-cap-set.js +212 -0
  143. package/dist/section-cap-set.js.map +1 -0
  144. package/dist/section-cap-style.d.ts +3 -0
  145. package/dist/section-cap-style.d.ts.map +1 -1
  146. package/dist/section-cap-style.js.map +1 -1
  147. package/dist/section-cap-upload.d.ts +16 -0
  148. package/dist/section-cap-upload.d.ts.map +1 -0
  149. package/dist/section-cap-upload.js +52 -0
  150. package/dist/section-cap-upload.js.map +1 -0
  151. package/dist/section-exclusions.d.ts +26 -0
  152. package/dist/section-exclusions.d.ts.map +1 -0
  153. package/dist/section-exclusions.js +95 -0
  154. package/dist/section-exclusions.js.map +1 -0
  155. package/dist/section-plane-frames.d.ts +48 -0
  156. package/dist/section-plane-frames.d.ts.map +1 -0
  157. package/dist/section-plane-frames.js +49 -0
  158. package/dist/section-plane-frames.js.map +1 -0
  159. package/dist/section-plane-resolve.d.ts +63 -0
  160. package/dist/section-plane-resolve.d.ts.map +1 -0
  161. package/dist/section-plane-resolve.js +200 -0
  162. package/dist/section-plane-resolve.js.map +1 -0
  163. package/dist/selection-mask-pass.d.ts +2 -0
  164. package/dist/selection-mask-pass.d.ts.map +1 -1
  165. package/dist/selection-mask-pass.js +16 -4
  166. package/dist/selection-mask-pass.js.map +1 -1
  167. package/dist/selection-mask-pipelines.d.ts +5 -1
  168. package/dist/selection-mask-pipelines.d.ts.map +1 -1
  169. package/dist/selection-mask-pipelines.js +27 -3
  170. package/dist/selection-mask-pipelines.js.map +1 -1
  171. package/dist/selection-outline-frame.d.ts +3 -1
  172. package/dist/selection-outline-frame.d.ts.map +1 -1
  173. package/dist/selection-outline-frame.js +2 -1
  174. package/dist/selection-outline-frame.js.map +1 -1
  175. package/dist/shaders/depth-nudge.wgsl.d.ts +2 -2
  176. package/dist/shaders/depth-nudge.wgsl.d.ts.map +1 -1
  177. package/dist/shaders/depth-nudge.wgsl.js +1 -18
  178. package/dist/shaders/depth-nudge.wgsl.js.map +1 -1
  179. package/dist/shaders/main.wgsl.d.ts +1 -1
  180. package/dist/shaders/main.wgsl.d.ts.map +1 -1
  181. package/dist/shaders/main.wgsl.js +9 -1
  182. package/dist/shaders/main.wgsl.js.map +1 -1
  183. package/dist/shaders/mesh-uniforms.wgsl.d.ts +1 -1
  184. package/dist/shaders/mesh-uniforms.wgsl.d.ts.map +1 -1
  185. package/dist/shaders/mesh-uniforms.wgsl.js +11 -3
  186. package/dist/shaders/mesh-uniforms.wgsl.js.map +1 -1
  187. package/dist/shaders/opaque-visibility.wgsl.d.ts +11 -0
  188. package/dist/shaders/opaque-visibility.wgsl.d.ts.map +1 -0
  189. package/dist/shaders/opaque-visibility.wgsl.js +55 -0
  190. package/dist/shaders/opaque-visibility.wgsl.js.map +1 -0
  191. package/dist/shaders/section-2d-overlay.wgsl.d.ts +11 -5
  192. package/dist/shaders/section-2d-overlay.wgsl.d.ts.map +1 -1
  193. package/dist/shaders/section-2d-overlay.wgsl.js +31 -5
  194. package/dist/shaders/section-2d-overlay.wgsl.js.map +1 -1
  195. package/dist/shaders/selection-mask.wgsl.d.ts +1 -1
  196. package/dist/shaders/selection-mask.wgsl.d.ts.map +1 -1
  197. package/dist/shaders/selection-mask.wgsl.js +10 -4
  198. package/dist/shaders/selection-mask.wgsl.js.map +1 -1
  199. package/dist/shaders/shadow.wgsl.d.ts +1 -1
  200. package/dist/shaders/shadow.wgsl.d.ts.map +1 -1
  201. package/dist/shaders/shadow.wgsl.js +22 -7
  202. package/dist/shaders/shadow.wgsl.js.map +1 -1
  203. package/dist/shaders/symbolic-overlay.wgsl.d.ts +1 -1
  204. package/dist/shaders/symbolic-overlay.wgsl.d.ts.map +1 -1
  205. package/dist/shadow-occluders.d.ts.map +1 -1
  206. package/dist/shadow-occluders.js +4 -0
  207. package/dist/shadow-occluders.js.map +1 -1
  208. package/dist/shadow-pass.d.ts +2 -5
  209. package/dist/shadow-pass.d.ts.map +1 -1
  210. package/dist/shadow-pass.js +17 -17
  211. package/dist/shadow-pass.js.map +1 -1
  212. package/dist/shadow-types.d.ts +7 -0
  213. package/dist/shadow-types.d.ts.map +1 -1
  214. package/dist/shadow-types.js.map +1 -1
  215. package/dist/source-curve-clipping.d.ts.map +1 -1
  216. package/dist/source-curve-clipping.js +7 -1
  217. package/dist/source-curve-clipping.js.map +1 -1
  218. package/dist/source-curve-snap.d.ts.map +1 -1
  219. package/dist/source-curve-snap.js +2 -1
  220. package/dist/source-curve-snap.js.map +1 -1
  221. package/dist/types.d.ts +12 -16
  222. package/dist/types.d.ts.map +1 -1
  223. package/package.json +3 -3
@@ -4,7 +4,7 @@ import type { IndividualMeshGpu } from './individual-mesh-upload.js';
4
4
  import type { HoveredMesh, SelectableMesh } from './selection-mask-pass.js';
5
5
  import type { InstancedMaskFrame, InstancedMaskTemplate } from './selection-mask-pipelines.js';
6
6
  import type { InstancedTemplateGPU } from './scene-instance-types.js';
7
- import type { ClipBox, Mesh } from './types.js';
7
+ import type { ClipBox, ExtraClipPlane, Mesh } from './types.js';
8
8
  export interface SelectionOutlineSource {
9
9
  uniformBufferSize: number;
10
10
  viewProj: Float32Array | number[];
@@ -19,6 +19,8 @@ export interface SelectionOutlineSource {
19
19
  section: Parameters<typeof packRteFragmentSpace>[1];
20
20
  sectionFlipped: boolean | undefined;
21
21
  clipBox: ClipBox | null | undefined;
22
+ /** Cutting planes beyond `section` (#7545), world-space. */
23
+ extraPlanes?: readonly ExtraClipPlane[] | null;
22
24
  /** This frame's live instanced templates; those with a selected occurrence are outlined (#5745). */
23
25
  instancedTemplates?: readonly InstancedTemplateGPU[];
24
26
  /** Instanced templates holding an occurrence of `hoveredId` (#5745). */
@@ -1 +1 @@
1
- {"version":3,"file":"selection-outline-frame.d.ts","sourceRoot":"","sources":["../src/selection-outline-frame.ts"],"names":[],"mappings":"AAsCA,OAAO,EAAuE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACnI,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC5E,OAAO,KAAK,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAC/F,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEhD,MAAM,WAAW,sBAAsB;IACrC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,QAAQ,EAAE,YAAY,GAAG,MAAM,EAAE,CAAC;IAClC,kBAAkB,EAAE,kBAAkB,C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E,SAAS,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAEjH;AA6BD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,sBAAsB,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,WAAW,GAAG,WAAW,CAAC,GAAG,YAAY,CAO3H;AAED,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,EAAE,cAAc,EAAE,CAAC;IAC3B,yEAAyE;IACzE,OAAO,EAAE,WAAW,EAAE,CAAC;IACvB,mFAAmF;IACnF,SAAS,EAAE,kBAAkB,GAAG,IAAI,CAAC;CACtC;AAeD,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,sBAAsB,GAAG,2BAA2B,CAwBtG"}
@@ -61,7 +61,7 @@ function packMaskFrameUniforms(source) {
61
61
  scratch.set(IDENTITY_TRANSFORM.m, MESH_UNIFORM_OFFSET.model);
62
62
  source.relativeToEyeFrame.packUniforms(scratch, MESH_UNIFORM_OFFSET.rteViewProj);
63
63
  const clipBit = packClipBox(source.clipBox, scratch, MESH_UNIFORM_OFFSET.clipBoxMin);
64
- packRteFragmentSpace(source.relativeToEyeFrame, source.section, source.clipBox, scratch);
64
+ packRteFragmentSpace(source.relativeToEyeFrame, source.section, source.clipBox, scratch, source.extraPlanes);
65
65
  const flags = new Uint32Array(scratch.buffer, MESH_FLAGS_BYTE_OFFSET, 2);
66
66
  flags[0] = MESH_FLAG_RTE_DRAWABLE;
67
67
  // flags.y: bit 0 = section enabled, bit 1 = flipped, bit 2 = clip box (as index.ts packs it).
@@ -76,6 +76,7 @@ function packMaskFrameUniforms(source) {
76
76
  export function packHoverUniforms(source, mesh) {
77
77
  const scratch = packMaskFrameUniforms(source);
78
78
  scratch.set(mesh.transform.m, MESH_UNIFORM_OFFSET.model);
79
+ new Uint32Array(scratch.buffer)[MESH_UNIFORM_OFFSET.overrideParams] = source.hoveredId ?? 0;
79
80
  const origin = mesh.rteOrigin ?? [mesh.transform.m[12], mesh.transform.m[13], mesh.transform.m[14]];
80
81
  source.relativeToEyeFrame.packDrawableOrigin(origin, scratch, MESH_UNIFORM_OFFSET.drawableDelta);
81
82
  return scratch;
@@ -1 +1 @@
1
- {"version":3,"file":"selection-outline-frame.js","sourceRoot":"","sources":["../src/selection-outline-frame.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AA4BnI;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAU,EAAE,SAAiB,EAAE,kBAAsC;IACtG,OAAO,IAAI,CAAC,SAAS,KAAK,SAAS,IAAI,CAAC,kBAAkB,KAAK,SAAS,IAAI,IAAI,CAAC,UAAU,KAAK,kBAAkB,CAAC,CAAC;AACtH,CAAC;AAED,SAAS,YAAY,CAAC,IAAU;IAC9B,IAAI,CAAC,IAAI,CAAC,SAAS;QAAE,OAAO,IAAI,CAAC;IACjC,OAAO,EAAE,YAAY,EAAE,IAAI,CAAC,YAAY,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC;AACpI,CAAC;AAED,MAAM,kBAAkB,GAAsB,EAAE,CAAC,EAAE,IAAI,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AAExH;;;;;GAKG;AACH,SAAS,qB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ACnC,MAAM,OAAO,GAAG,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC;QACjH,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACvB,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;gBAC3B,MAAM,CAAC,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;gBAC7B,IAAI,CAAC;oBAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YACzB,CAAC;QACH,CAAC;aAAM,CAAC;YACN,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;gBACvC,OAAO,CAAC,IAAI,CAAC,EAAE,YAAY,EAAE,KAAK,CAAC,YAAY,EAAE,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE,UAAU,EAAE,KAAK,CAAC,UAAU,EAAE,QAAQ,EAAE,iBAAiB,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC;YAC/J,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,uBAAuB,CAAC,MAAM,CAAC,EAAE,CAAC;AAC3E,CAAC"}
@@ -62,6 +62,6 @@ export declare const ORTHOGRAPHIC_MAX_DEPTH_NUDGE_METRES = 0.025;
62
62
  export declare const MAX_DEPTH_NUDGE_HASH = 255;
63
63
  /** Perspective: NDC lift for annotation lines and text; also the orthographic minimum. */
64
64
  export declare const PERSPECTIVE_OVERLAY_DEPTH_LIFT = 0.00005;
65
- export declare const depthNudgeWgsl = "\n \n const ORTHOGRAPHIC_DEPTH_NUDGE_PER_LEVEL: f32 = 4.76837158203125e-7;\n const ORTHOGRAPHIC_MAX_DEPTH_NUDGE_METRES: f32 = 0.025;\n const MAX_DEPTH_NUDGE_HASH: f32 = 255.0;\n\n // An orthographic view-projection leaves w at 1: its bottom row is exactly\n // (0, 0, 0, 1), because the projection's and the view's bottom rows are\n // both (0, 0, 0, 1). A perspective one copies the forward axis into that\n // row, a unit vector, so it is never zero. Every caller passes the\n // camera's world view-projection, which each draw packs whether or not\n // it renders camera-relative.\n fn isOrthographicProjection(viewProj: mat4x4<f32>) -> bool {\n return viewProj[0][3] == 0.0 && viewProj[1][3] == 0.0 && viewProj[2][3] == 0.0 && viewProj[3][3] == 1.0;\n }\n\n // Orthographic only: how many hash levels fit the metre bound. The z row\n // of the view-projection has length 1 / (far - near).\n fn orthographicNudgeLevels(viewProj: mat4x4<f32>) -> u32 {\n let depthRange = 1.0 / length(vec3<f32>(viewProj[0][2], viewProj[1][2], viewProj[2][2]));\n let steps = ORTHOGRAPHIC_MAX_DEPTH_NUDGE_METRES / (depthRange * ORTHOGRAPHIC_DEPTH_NUDGE_PER_LEVEL);\n return u32(clamp(floor(steps), 0.0, MAX_DEPTH_NUDGE_HASH)) + 1u;\n }\n\n // Orthographic only: clip z moved `ndcOffset` toward the camera without\n // changing which side of a clip plane the vertex is on. A vertex beyond\n // either plane, or exactly on the far plane, stays where it is.\n fn orthographicOffsetInsideDepthRange(clip: vec4<f32>, ndcOffset: f32) -> f32 {\n if (!(clip.z > 0.0 && clip.z < clip.w)) { return clip.z; }\n return min(clip.z + ndcOffset * clip.w, clip.w);\n }\n\n const PERSPECTIVE_DEPTH_NUDGE_PER_STEP: f32 = 0.000001;\n\n // Clip-space z with the entity's depth nudge applied (depth-nudge.wgsl.ts).\n fn nudgedClipZ(clip: vec4<f32>, zHash: u32, viewProj: mat4x4<f32>) -> f32 {\n if (isOrthographicProjection(viewProj)) {\n let level = (zHash * orthographicNudgeLevels(viewProj)) >> 8u;\n return orthographicOffsetInsideDepthRange(clip, f32(level) * ORTHOGRAPHIC_DEPTH_NUDGE_PER_LEVEL);\n }\n return clip.z * (1.0 + f32(zHash) * PERSPECTIVE_DEPTH_NUDGE_PER_STEP);\n }\n";
66
- export declare const overlayDepthLiftWgsl = "\n \n const ORTHOGRAPHIC_DEPTH_NUDGE_PER_LEVEL: f32 = 4.76837158203125e-7;\n const ORTHOGRAPHIC_MAX_DEPTH_NUDGE_METRES: f32 = 0.025;\n const MAX_DEPTH_NUDGE_HASH: f32 = 255.0;\n\n // An orthographic view-projection leaves w at 1: its bottom row is exactly\n // (0, 0, 0, 1), because the projection's and the view's bottom rows are\n // both (0, 0, 0, 1). A perspective one copies the forward axis into that\n // row, a unit vector, so it is never zero. Every caller passes the\n // camera's world view-projection, which each draw packs whether or not\n // it renders camera-relative.\n fn isOrthographicProjection(viewProj: mat4x4<f32>) -> bool {\n return viewProj[0][3] == 0.0 && viewProj[1][3] == 0.0 && viewProj[2][3] == 0.0 && viewProj[3][3] == 1.0;\n }\n\n // Orthographic only: how many hash levels fit the metre bound. The z row\n // of the view-projection has length 1 / (far - near).\n fn orthographicNudgeLevels(viewProj: mat4x4<f32>) -> u32 {\n let depthRange = 1.0 / length(vec3<f32>(viewProj[0][2], viewProj[1][2], viewProj[2][2]));\n let steps = ORTHOGRAPHIC_MAX_DEPTH_NUDGE_METRES / (depthRange * ORTHOGRAPHIC_DEPTH_NUDGE_PER_LEVEL);\n return u32(clamp(floor(steps), 0.0, MAX_DEPTH_NUDGE_HASH)) + 1u;\n }\n\n // Orthographic only: clip z moved `ndcOffset` toward the camera without\n // changing which side of a clip plane the vertex is on. A vertex beyond\n // either plane, or exactly on the far plane, stays where it is.\n fn orthographicOffsetInsideDepthRange(clip: vec4<f32>, ndcOffset: f32) -> f32 {\n if (!(clip.z > 0.0 && clip.z < clip.w)) { return clip.z; }\n return min(clip.z + ndcOffset * clip.w, clip.w);\n }\n\n const PERSPECTIVE_OVERLAY_DEPTH_LIFT: f32 = 0.00005;\n\n // Clip-space z raised above any nudged mesh face (depth-nudge.wgsl.ts).\n // A multiple of clip.w is a constant NDC offset after the w-divide, which\n // under reverse-Z reads as \"slightly closer\". Orthographic keeps at least\n // the perspective lift, and two levels above the highest nudge level\n // when that is more (all 256 levels in use), so the text pipeline's\n // constant depthBias of -4 units is covered too.\n fn overlayLiftedClipZ(clip: vec4<f32>, viewProj: mat4x4<f32>) -> f32 {\n if (isOrthographicProjection(viewProj)) {\n let levelsLift = f32(orthographicNudgeLevels(viewProj) + 1u) * ORTHOGRAPHIC_DEPTH_NUDGE_PER_LEVEL;\n return orthographicOffsetInsideDepthRange(clip, max(PERSPECTIVE_OVERLAY_DEPTH_LIFT, levelsLift));\n }\n return clip.z + PERSPECTIVE_OVERLAY_DEPTH_LIFT * clip.w;\n }\n";
65
+ export declare const depthNudgeWgsl = "\n \n const ORTHOGRAPHIC_DEPTH_NUDGE_PER_LEVEL: f32 = 4.76837158203125e-7;\n const ORTHOGRAPHIC_MAX_DEPTH_NUDGE_METRES: f32 = 0.025;\n const MAX_DEPTH_NUDGE_HASH: f32 = 255.0;\n\n fn isOrthographicProjection(viewProj: mat4x4<f32>) -> bool {\n return viewProj[0][3] == 0.0 && viewProj[1][3] == 0.0 && viewProj[2][3] == 0.0 && viewProj[3][3] == 1.0;\n }\n\n fn orthographicNudgeLevels(viewProj: mat4x4<f32>) -> u32 {\n let depthRange = 1.0 / length(vec3<f32>(viewProj[0][2], viewProj[1][2], viewProj[2][2]));\n let steps = ORTHOGRAPHIC_MAX_DEPTH_NUDGE_METRES / (depthRange * ORTHOGRAPHIC_DEPTH_NUDGE_PER_LEVEL);\n return u32(clamp(floor(steps), 0.0, MAX_DEPTH_NUDGE_HASH)) + 1u;\n }\n\n fn orthographicOffsetInsideDepthRange(clip: vec4<f32>, ndcOffset: f32) -> f32 {\n if (!(clip.z > 0.0 && clip.z < clip.w)) { return clip.z; }\n return min(clip.z + ndcOffset * clip.w, clip.w);\n }\n\n const PERSPECTIVE_DEPTH_NUDGE_PER_STEP: f32 = 0.000001;\n\n fn nudgedClipZ(clip: vec4<f32>, zHash: u32, viewProj: mat4x4<f32>) -> f32 {\n if (isOrthographicProjection(viewProj)) {\n let level = (zHash * orthographicNudgeLevels(viewProj)) >> 8u;\n return orthographicOffsetInsideDepthRange(clip, f32(level) * ORTHOGRAPHIC_DEPTH_NUDGE_PER_LEVEL);\n }\n return clip.z * (1.0 + f32(zHash) * PERSPECTIVE_DEPTH_NUDGE_PER_STEP);\n }\n";
66
+ export declare const overlayDepthLiftWgsl = "\n \n const ORTHOGRAPHIC_DEPTH_NUDGE_PER_LEVEL: f32 = 4.76837158203125e-7;\n const ORTHOGRAPHIC_MAX_DEPTH_NUDGE_METRES: f32 = 0.025;\n const MAX_DEPTH_NUDGE_HASH: f32 = 255.0;\n\n fn isOrthographicProjection(viewProj: mat4x4<f32>) -> bool {\n return viewProj[0][3] == 0.0 && viewProj[1][3] == 0.0 && viewProj[2][3] == 0.0 && viewProj[3][3] == 1.0;\n }\n\n fn orthographicNudgeLevels(viewProj: mat4x4<f32>) -> u32 {\n let depthRange = 1.0 / length(vec3<f32>(viewProj[0][2], viewProj[1][2], viewProj[2][2]));\n let steps = ORTHOGRAPHIC_MAX_DEPTH_NUDGE_METRES / (depthRange * ORTHOGRAPHIC_DEPTH_NUDGE_PER_LEVEL);\n return u32(clamp(floor(steps), 0.0, MAX_DEPTH_NUDGE_HASH)) + 1u;\n }\n\n fn orthographicOffsetInsideDepthRange(clip: vec4<f32>, ndcOffset: f32) -> f32 {\n if (!(clip.z > 0.0 && clip.z < clip.w)) { return clip.z; }\n return min(clip.z + ndcOffset * clip.w, clip.w);\n }\n\n const PERSPECTIVE_OVERLAY_DEPTH_LIFT: f32 = 0.00005;\n\n fn overlayLiftedClipZ(clip: vec4<f32>, viewProj: mat4x4<f32>) -> f32 {\n if (isOrthographicProjection(viewProj)) {\n let levelsLift = f32(orthographicNudgeLevels(viewProj) + 1u) * ORTHOGRAPHIC_DEPTH_NUDGE_PER_LEVEL;\n return orthographicOffsetInsideDepthRange(clip, max(PERSPECTIVE_OVERLAY_DEPTH_LIFT, levelsLift));\n }\n return clip.z + PERSPECTIVE_OVERLAY_DEPTH_LIFT * clip.w;\n }\n";
67
67
  //# sourceMappingURL=depth-nudge.wgsl.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"depth-nudge.wgsl.d.ts","sourceRoot":"","sources":["../../src/shaders/depth-nudge.wgsl.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AAEH,0DAA0D;AAC1D,eAAO,MAAM,gCAAgC,WAAO,CAAC;AAErD,kGAAkG;AAClG,eAAO,MAAM,kCAAkC,QAAe,CAAC;AAE/D,iFAAiF;AACjF,eAAO,MAAM,mCAAmC,QAAQ,CAAC;AAEzD,uDAAuD;AACvD,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAExC,0FAA0F;AAC1F,eAAO,MAAM,8BAA8B,UAAO,CAAC;AAkCnD,eAAO,MAAM,cAAc,83EAY1B,CAAC;AAEF,eAAO,MAAM,oBAAoB,0wFAiBhC,CAAC"}
1
+ {"version":3,"file":"depth-nudge.wgsl.d.ts","sourceRoot":"","sources":["../../src/shaders/depth-nudge.wgsl.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AAEH,0DAA0D;AAC1D,eAAO,MAAM,gCAAgC,WAAO,CAAC;AAErD,kGAAkG;AAClG,eAAO,MAAM,kCAAkC,QAAe,CAAC;AAE/D,iFAAiF;AACjF,eAAO,MAAM,mCAAmC,QAAQ,CAAC;AAEzD,uDAAuD;AACvD,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAExC,0FAA0F;AAC1F,eAAO,MAAM,8BAA8B,UAAO,CAAC;AAwBnD,eAAO,MAAM,cAAc,u+CAW1B,CAAC;AAEF,eAAO,MAAM,oBAAoB,q/CAWhC,CAAC"}
@@ -65,32 +65,22 @@ export const ORTHOGRAPHIC_MAX_DEPTH_NUDGE_METRES = 0.025;
65
65
  export const MAX_DEPTH_NUDGE_HASH = 255;
66
66
  /** Perspective: NDC lift for annotation lines and text; also the orthographic minimum. */
67
67
  export const PERSPECTIVE_OVERLAY_DEPTH_LIFT = 5e-5;
68
+ /** Keep explanations above, outside the shipped WGSL literals (#7918). */
68
69
  const projectionWgsl = `
69
70
  const ORTHOGRAPHIC_DEPTH_NUDGE_PER_LEVEL: f32 = ${ORTHOGRAPHIC_DEPTH_NUDGE_PER_LEVEL};
70
71
  const ORTHOGRAPHIC_MAX_DEPTH_NUDGE_METRES: f32 = ${ORTHOGRAPHIC_MAX_DEPTH_NUDGE_METRES};
71
72
  const MAX_DEPTH_NUDGE_HASH: f32 = ${MAX_DEPTH_NUDGE_HASH}.0;
72
73
 
73
- // An orthographic view-projection leaves w at 1: its bottom row is exactly
74
- // (0, 0, 0, 1), because the projection's and the view's bottom rows are
75
- // both (0, 0, 0, 1). A perspective one copies the forward axis into that
76
- // row, a unit vector, so it is never zero. Every caller passes the
77
- // camera's world view-projection, which each draw packs whether or not
78
- // it renders camera-relative.
79
74
  fn isOrthographicProjection(viewProj: mat4x4<f32>) -> bool {
80
75
  return viewProj[0][3] == 0.0 && viewProj[1][3] == 0.0 && viewProj[2][3] == 0.0 && viewProj[3][3] == 1.0;
81
76
  }
82
77
 
83
- // Orthographic only: how many hash levels fit the metre bound. The z row
84
- // of the view-projection has length 1 / (far - near).
85
78
  fn orthographicNudgeLevels(viewProj: mat4x4<f32>) -> u32 {
86
79
  let depthRange = 1.0 / length(vec3<f32>(viewProj[0][2], viewProj[1][2], viewProj[2][2]));
87
80
  let steps = ORTHOGRAPHIC_MAX_DEPTH_NUDGE_METRES / (depthRange * ORTHOGRAPHIC_DEPTH_NUDGE_PER_LEVEL);
88
81
  return u32(clamp(floor(steps), 0.0, MAX_DEPTH_NUDGE_HASH)) + 1u;
89
82
  }
90
83
 
91
- // Orthographic only: clip z moved \`ndcOffset\` toward the camera without
92
- // changing which side of a clip plane the vertex is on. A vertex beyond
93
- // either plane, or exactly on the far plane, stays where it is.
94
84
  fn orthographicOffsetInsideDepthRange(clip: vec4<f32>, ndcOffset: f32) -> f32 {
95
85
  if (!(clip.z > 0.0 && clip.z < clip.w)) { return clip.z; }
96
86
  return min(clip.z + ndcOffset * clip.w, clip.w);
@@ -100,7 +90,6 @@ export const depthNudgeWgsl = `
100
90
  ${projectionWgsl}
101
91
  const PERSPECTIVE_DEPTH_NUDGE_PER_STEP: f32 = ${PERSPECTIVE_DEPTH_NUDGE_PER_STEP};
102
92
 
103
- // Clip-space z with the entity's depth nudge applied (depth-nudge.wgsl.ts).
104
93
  fn nudgedClipZ(clip: vec4<f32>, zHash: u32, viewProj: mat4x4<f32>) -> f32 {
105
94
  if (isOrthographicProjection(viewProj)) {
106
95
  let level = (zHash * orthographicNudgeLevels(viewProj)) >> 8u;
@@ -113,12 +102,6 @@ export const overlayDepthLiftWgsl = `
113
102
  ${projectionWgsl}
114
103
  const PERSPECTIVE_OVERLAY_DEPTH_LIFT: f32 = ${PERSPECTIVE_OVERLAY_DEPTH_LIFT};
115
104
 
116
- // Clip-space z raised above any nudged mesh face (depth-nudge.wgsl.ts).
117
- // A multiple of clip.w is a constant NDC offset after the w-divide, which
118
- // under reverse-Z reads as "slightly closer". Orthographic keeps at least
119
- // the perspective lift, and two levels above the highest nudge level
120
- // when that is more (all 256 levels in use), so the text pipeline's
121
- // constant depthBias of -4 units is covered too.
122
105
  fn overlayLiftedClipZ(clip: vec4<f32>, viewProj: mat4x4<f32>) -> f32 {
123
106
  if (isOrthographicProjection(viewProj)) {
124
107
  let levelsLift = f32(orthographicNudgeLevels(viewProj) + 1u) * ORTHOGRAPHIC_DEPTH_NUDGE_PER_LEVEL;
@@ -1 +1 @@
1
- {"version":3,"file":"depth-nudge.wgsl.js","sourceRoot":"","sources":["../../src/shaders/depth-nudge.wgsl.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AAEH,0D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Ac,GAAG;0DACmC,kCAAkC;2DACjC,mCAAmC;4CAClD,oBAAoB;;;;;;;;;;;;;;;;CAgB/D,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG;UACpB,cAAc;wDACgC,gCAAgC;;;;;;;;;CASvF,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG;UAC1B,cAAc;sDAC8B,8BAA8B;;;;;;;;;CASnF,CAAC"}
@@ -1,2 +1,2 @@
1
- export declare const mainShaderSource = "\n \n struct Uniforms {\n viewProj: mat4x4<f32>,\n model: mat4x4<f32>,\n baseColor: vec4<f32>,\n metallicRoughness: vec2<f32>, // x = metallic, y = roughness (mesh-material.ts)\n transmission: vec2<f32>, // x = 1: authored translucent, drawn as glass; y = pad\n sectionPlane: vec4<f32>, // xyz = plane normal, w = plane distance\n flags: vec4<u32>, // x = isSelected, y = section/clip bits; z, w unused (0) since #5746 dropped the derivative edges\n clipBoxMin: vec4<f32>, // xyz = clip-box min corner (world), w = pad\n clipBoxMax: vec4<f32>, // xyz = clip-box max corner (world), w = pad\n quantParams: vec4<f32>, // local min xyz, lattice step w\n rteViewProj: mat4x4<f32>, // appended frame; bit 16 selects it\n drawableDeltaHigh: vec4<f32>,\n drawableDeltaLow: vec4<f32>,\n rteCameraHigh: vec4<f32>,\n rteCameraLow: vec4<f32>,\n overrideParams: vec4<u32>, // x = draw's id anchor, y = OVERRIDE_* bits (entity-color-table.ts, #6076)\n }\n @binding(0) @group(0) var<uniform> uniforms: Uniforms;\n const RTE_DRAWABLE_FLAG: u32 = 65536u;\n\n // The fragment position the section/crop tests run in: camera-relative\n // for RTE drawables (the packer writes plane and box in that frame),\n // world space otherwise.\n fn clipSpacePos(worldPos: vec3<f32>, eyePos: vec3<f32>) -> vec3<f32> {\n return select(worldPos, eyePos, (uniforms.flags.x & RTE_DRAWABLE_FLAG) != 0u);\n }\n\n // True when p is cut away: ABOVE the section plane (flags.y bit 0 =\n // enabled, bit 1 = flipped) or OUTSIDE the clip box (bit 2).\n fn sectionClipped(p: vec3<f32>) -> bool {\n if ((uniforms.flags.y & 1u) == 1u) {\n let side = select(1.0, -1.0, (uniforms.flags.y & 2u) == 2u);\n if ((dot(p, uniforms.sectionPlane.xyz) - uniforms.sectionPlane.w) * side > 0.0) { return true; }\n }\n if ((uniforms.flags.y & 4u) != 0u) {\n if (any(p < uniforms.clipBoxMin.xyz) || any(p > uniforms.clipBoxMax.xyz)) { return true; }\n }\n return false;\n }\n\n \n \n const ORTHOGRAPHIC_DEPTH_NUDGE_PER_LEVEL: f32 = 4.76837158203125e-7;\n const ORTHOGRAPHIC_MAX_DEPTH_NUDGE_METRES: f32 = 0.025;\n const MAX_DEPTH_NUDGE_HASH: f32 = 255.0;\n\n // An orthographic view-projection leaves w at 1: its bottom row is exactly\n // (0, 0, 0, 1), because the projection's and the view's bottom rows are\n // both (0, 0, 0, 1). A perspective one copies the forward axis into that\n // row, a unit vector, so it is never zero. Every caller passes the\n // camera's world view-projection, which each draw packs whether or not\n // it renders camera-relative.\n fn isOrthographicProjection(viewProj: mat4x4<f32>) -> bool {\n return viewProj[0][3] == 0.0 && viewProj[1][3] == 0.0 && viewProj[2][3] == 0.0 && viewProj[3][3] == 1.0;\n }\n\n // Orthographic only: how many hash levels fit the metre bound. The z row\n // of the view-projection has length 1 / (far - near).\n fn orthographicNudgeLevels(viewProj: mat4x4<f32>) -> u32 {\n let depthRange = 1.0 / length(vec3<f32>(viewProj[0][2], viewProj[1][2], viewProj[2][2]));\n let steps = ORTHOGRAPHIC_MAX_DEPTH_NUDGE_METRES / (depthRange * ORTHOGRAPHIC_DEPTH_NUDGE_PER_LEVEL);\n return u32(clamp(floor(steps), 0.0, MAX_DEPTH_NUDGE_HASH)) + 1u;\n }\n\n // Orthographic only: clip z moved `ndcOffset` toward the camera without\n // changing which side of a clip plane the vertex is on. A vertex beyond\n // either plane, or exactly on the far plane, stays where it is.\n fn orthographicOffsetInsideDepthRange(clip: vec4<f32>, ndcOffset: f32) -> f32 {\n if (!(clip.z > 0.0 && clip.z < clip.w)) { return clip.z; }\n return min(clip.z + ndcOffset * clip.w, clip.w);\n }\n\n const PERSPECTIVE_DEPTH_NUDGE_PER_STEP: f32 = 0.000001;\n\n // Clip-space z with the entity's depth nudge applied (depth-nudge.wgsl.ts).\n fn nudgedClipZ(clip: vec4<f32>, zHash: u32, viewProj: mat4x4<f32>) -> f32 {\n if (isOrthographicProjection(viewProj)) {\n let level = (zHash * orthographicNudgeLevels(viewProj)) >> 8u;\n return orthographicOffsetInsideDepthRange(clip, f32(level) * ORTHOGRAPHIC_DEPTH_NUDGE_PER_LEVEL);\n }\n return clip.z * (1.0 + f32(zHash) * PERSPECTIVE_DEPTH_NUDGE_PER_STEP);\n }\n\n \nstruct RteFrameUniform {\n // Camera translation is intentionally absent. This projects positions\n // returned by rteWorldPosition, which are already relative to the eye.\n viewProj: mat4x4<f32>,\n}\n\nstruct RteDrawableUniform {\n // CPU computes (drawable origin - camera origin) in f64 and splits it.\n // This data must be refreshed whenever the RTE camera frame changes.\n drawableDeltaHigh: vec4<f32>,\n drawableDeltaLow: vec4<f32>,\n}\n\nfn rteWorldPosition(\n local: vec3<f32>,\n drawable: RteDrawableUniform,\n) -> vec4<f32> {\n // Do not subtract a camera origin here: this delta was formed in CPU f64.\n let highDelta = drawable.drawableDeltaHigh.xyz;\n let lowDelta = drawable.drawableDeltaLow.xyz;\n // A drawable template can span kilometres. Keep local with high first;\n // The local-plus-(high-plus-low) association is not equivalent in f32.\n return vec4<f32>((local + highDelta) + lowDelta, 1.0);\n}\n\n \n fn rtePosition(local: vec3<f32>) -> vec4<f32> {\n let linear = (uniforms.model * vec4<f32>(local, 0.0)).xyz;\n return rteWorldPosition(linear, RteDrawableUniform(\n uniforms.drawableDeltaHigh,\n uniforms.drawableDeltaLow,\n ));\n }\n fn rteInstancePosition(local: vec3<f32>, anchorHigh: vec3<f32>, anchorLow: vec3<f32>) -> vec4<f32> {\n return rteWorldPosition(local, RteDrawableUniform(\n vec4<f32>(anchorHigh, 0.0),\n vec4<f32>(anchorLow, 0.0),\n ));\n }\n // Shared group(1) lighting; packing matches packEnvironmentUniforms().\n struct Environment {\n sunDirection: vec3<f32>, // unit vector TOWARD the sun\n sunIntensity: f32,\n sunColor: vec3<f32>,\n ambientIntensity: f32,\n skyColor: vec3<f32>, // hemisphere-ambient sky tint\n exposure: f32,\n groundColor: vec3<f32>, // hemisphere-ambient ground tint\n fillIntensity: f32,\n rimIntensity: f32,\n sunSoftness: f32,\n _pad1: f32,\n _pad2: f32,\n }\n @binding(0) @group(1) var<uniform> env: Environment;\n // Selection highlight tint (#5484), set by Renderer.setOverlayTheme via\n // updateSelectionColor \u2014 written only on theme change, never per frame.\n // TRUE LINEAR-LIGHT RGB: re-lit by lightTerm below exactly like the WGSL\n // constant it replaces, then ACES-tonemapped + gamma-encoded on output.\n @binding(4) @group(1) var<uniform> selectionColor: vec4<f32>;\n const IRRADIANCE_CALIBRATION: f32 = 1.82;\n const TRANSLUCENT_OPACITY_SCALE: f32 = 0.7;\n \n fn srgbToLinear(c: vec3<f32>) -> vec3<f32> {\n let lo = c / 12.92;\n let hi = pow((max(c, vec3<f32>(0.0)) + 0.055) / 1.055, vec3<f32>(2.4));\n return select(hi, lo, c <= vec3<f32>(0.04045));\n }\n\n fn linearToSrgb(c: vec3<f32>) -> vec3<f32> {\n let lo = c * 12.92;\n let hi = 1.055 * pow(max(c, vec3<f32>(0.0)), vec3<f32>(1.0 / 2.4)) - 0.055;\n return select(hi, lo, c <= vec3<f32>(0.0031308));\n }\n\n fn neutralCompress(cIn: vec3<f32>) -> vec3<f32> {\n let startCompression = 0.76;\n let desaturation = 0.15;\n let c = max(cIn, vec3<f32>(0.0));\n let peak = max(c.r, max(c.g, c.b));\n if (peak < startCompression) { return c; }\n let d = 1.0 - startCompression;\n let newPeak = 1.0 - d * d / (peak + d - startCompression);\n let g = 1.0 - 1.0 / (desaturation * (peak - newPeak) + 1.0);\n return mix(c * (newPeak / peak), vec3<f32>(newPeak), g);\n }\n\n \n const MIN_SPECULAR_ROUGHNESS: f32 = 0.045;\n const DIELECTRIC_F0: f32 = 0.04;\n const PI: f32 = 3.14159265;\n\n fn fresnelSchlick(cosTheta: f32, F0: vec3<f32>) -> vec3<f32> {\n return F0 + (1.0 - F0) * pow(clamp(1.0 - cosTheta, 0.0, 1.0), 5.0);\n }\n\n fn distributionGGX(NdotH: f32, roughness: f32) -> f32 {\n let a = roughness * roughness;\n let a2 = a * a;\n let NdotH2 = NdotH * NdotH;\n let denomBase = (NdotH2 * (a2 - 1.0) + 1.0);\n return a2 / max(PI * denomBase * denomBase, 0.0000001);\n }\n\n fn geometrySchlickGGX(NdotV: f32, roughness: f32) -> f32 {\n let r = (roughness + 1.0);\n let k = (r * r) / 8.0;\n return NdotV / max(NdotV * (1.0 - k) + k, 0.0000001);\n }\n\n fn geometrySmith(NdotV: f32, NdotL: f32, roughness: f32) -> f32 {\n return geometrySchlickGGX(NdotL, roughness) * geometrySchlickGGX(NdotV, roughness);\n }\n\n // Split-sum environment BRDF, analytic fit (Karis 2014).\n fn envBrdfApprox(F0: vec3<f32>, roughness: f32, NdotV: f32) -> vec3<f32> {\n let r = roughness * vec4<f32>(-1.0, -0.0275, -0.572, 0.022) + vec4<f32>(1.0, 0.0425, 1.04, -0.04);\n let a004 = min(r.x * r.x, exp2(-9.28 * NdotV)) * r.x + r.y;\n let ab = vec2<f32>(-1.04, 1.04) * a004 + r.zw;\n return F0 * ab.x + ab.y;\n }\n\n struct SurfaceSpecular {\n // Reflected light, in lightTerm units (unexposed, uncalibrated).\n light: vec3<f32>,\n // Directional albedo of the specular lobe for this view.\n reflectance: vec3<f32>,\n }\n\n // N and V are unit vectors; V points from the surface to the eye.\n // sunLight is the sun's diffuse-equivalent intensity: sunColor *\n // sunIntensity * sunShadow, exactly what scales the diffuse sun term.\n fn surfaceSpecular(\n N: vec3<f32>,\n V: vec3<f32>,\n albedo: vec3<f32>,\n metallic: f32,\n roughnessIn: f32,\n sunLight: vec3<f32>,\n ) -> SurfaceSpecular {\n var out: SurfaceSpecular;\n let NdotV = dot(N, V);\n // A face turned away from the eye is its back side: nothing it\n // reflects can reach the eye, and its diffuse keeps full weight.\n if (NdotV <= 0.0) {\n out.light = vec3<f32>(0.0);\n out.reflectance = vec3<f32>(0.0);\n return out;\n }\n let roughness = clamp(roughnessIn, MIN_SPECULAR_ROUGHNESS, 1.0);\n let F0 = mix(vec3<f32>(DIELECTRIC_F0), albedo, metallic);\n\n let L = env.sunDirection;\n let rawNdotL = dot(N, L);\n let NdotL = max(rawNdotL, 0.0);\n // A face the sun is behind (rawNdotL <= 0) contributes nothing to\n // the direct lobe anyway (NdotL clamps it to 0 below), but V + L\n // can be exactly zero there \u2014 the sun exactly opposite the eye\n // reflection, e.g. N = V = (0,-1,0), sun = (0,1,0), both satisfy\n // NdotV > 0 above. normalize(vec3(0)) is NaN in WGSL, and NaN * 0\n // is NaN, not 0, so it would poison sun and everything summed with\n // it instead of being multiplied away. Skip the half-vector\n // entirely in that case rather than relying on the NdotL factor.\n var sun = vec3<f32>(0.0);\n if (rawNdotL > 0.0) {\n let H = normalize(V + L);\n let D = distributionGGX(max(dot(N, H), 0.0), roughness);\n let G = geometrySmith(NdotV, NdotL, roughness);\n let F = fresnelSchlick(max(dot(V, H), 0.0), F0);\n // BRDF * NdotL * (pi * intensity); the NdotL cancels the BRDF's.\n sun = F * (D * G * PI / (4.0 * NdotV)) * sunLight;\n }\n\n // The hemisphere ambient, looked up along the reflection. A rough\n // lobe gathers from around the normal, so lean the lookup toward N.\n let R = reflect(-V, N);\n let Rd = normalize(mix(R, N, roughness * roughness));\n let sky = mix(env.groundColor, env.skyColor, Rd.y * 0.5 + 0.5) * env.ambientIntensity;\n let reflectance = envBrdfApprox(F0, roughness, NdotV);\n\n out.light = sun + sky * reflectance;\n out.reflectance = reflectance;\n return out;\n }\n\n \n @binding(5) @group(1) var<storage, read> entityColorTable: array<u32>;\n const ENTITY_COLOR_EMPTY: u32 = 4294967295u;\n const ENTITY_COLOR_HEADER: u32 = 4u;\n const OVERRIDE_PAINT: u32 = 1u;\n const OVERRIDE_EMPHASIZE: u32 = 2u;\n\n fn entityColorSlotHash(key: u32) -> u32 {\n var h = key;\n h = h ^ (h >> 16u);\n h = h * 0x85ebca6bu;\n h = h ^ (h >> 13u);\n h = h * 0xc2b2ae35u;\n h = h ^ (h >> 16u);\n return h;\n }\n\n // Full scene id behind a 24-bit lane, given the draw's smallest id.\n fn resolveLaneEntityId(anchor: u32, lane: u32) -> u32 {\n return anchor + ((lane - anchor) & 0x00FFFFFFu);\n }\n\n // The override colour for this fragment's entity; alpha < 0 = none.\n fn entityOverrideColor(lane: u32) -> vec4<f32> {\n let none = vec4<f32>(0.0, 0.0, 0.0, -1.0);\n if ((uniforms.overrideParams.y & OVERRIDE_PAINT) == 0u || entityColorTable[2] == 0u) {\n return none;\n }\n let capacity = entityColorTable[0];\n let maxProbe = entityColorTable[1];\n let colorBase = entityColorTable[3];\n let id = resolveLaneEntityId(uniforms.overrideParams.x, lane);\n let mask = capacity - 1u;\n var slot = entityColorSlotHash(id) & mask;\n for (var i = 0u; i <= maxProbe && i < capacity; i = i + 1u) {\n let key = entityColorTable[ENTITY_COLOR_HEADER + slot];\n if (key == id) {\n let c = colorBase + slot * 4u;\n return vec4<f32>(\n bitcast<f32>(entityColorTable[c]),\n bitcast<f32>(entityColorTable[c + 1u]),\n bitcast<f32>(entityColorTable[c + 2u]),\n bitcast<f32>(entityColorTable[c + 3u])\n );\n }\n if (key == ENTITY_COLOR_EMPTY) {\n break;\n }\n slot = (slot + 1u) & mask;\n }\n return none;\n }\n\n // Composite an override over the fragment's own encoded colour exactly\n // as the retired equal-depth overlay pass blended it (src-alpha over\n // the base draw): the override albedo lit by the same irradiance, no\n // specular, the same roll-off and edge darkening, mixed by its alpha.\n // Emphasized overrides are unlit, faintly faceted and opaque (#1277).\n fn paintEntityOverride(base: vec4<f32>, ov: vec4<f32>, irradiance: vec3<f32>, N: vec3<f32>) -> vec4<f32> {\n let albedo = srgbToLinear(ov.rgb);\n var lit = albedo * irradiance;\n var a = ov.a;\n if ((uniforms.overrideParams.y & OVERRIDE_EMPHASIZE) != 0u) {\n lit = albedo * (0.85 + 0.15 * abs(dot(N, normalize(vec3<f32>(0.3, 1.0, 0.2)))));\n a = 1.0;\n }\n let encoded = linearToSrgb(clamp(neutralCompress(lit), vec3<f32>(0.0), vec3<f32>(1.0)));\n return vec4<f32>(mix(base.rgb, encoded, a), a + (1.0 - a) * base.a);\n }\n\n\n \n @binding(1) @group(1) var shadowMap: texture_depth_2d;\n @binding(2) @group(1) var shadowCmp: sampler_comparison;\n struct Shadow { lightViewProj: mat4x4<f32>, params: vec4<f32>, params2: vec4<f32>, }\n @binding(3) @group(1) var<uniform> shadowU: Shadow;\n const SHADOW_POISSON = array<vec2<f32>, 12>(\n vec2<f32>(-0.326, -0.406), vec2<f32>(-0.840, -0.074), vec2<f32>(-0.696, 0.457),\n vec2<f32>(-0.203, 0.621), vec2<f32>( 0.962, -0.195), vec2<f32>( 0.473, -0.480),\n vec2<f32>( 0.519, 0.767), vec2<f32>( 0.185, -0.893), vec2<f32>( 0.507, 0.064),\n vec2<f32>( 0.896, 0.412), vec2<f32>(-0.322, -0.933), vec2<f32>(-0.792, -0.598),\n );\n fn sunShadowFactor(eyePos: vec3<f32>, N: vec3<f32>, fragCoord: vec2<f32>) -> f32 {\n if (shadowU.params.y < 0.5) { return 1.0; }\n let L = normalize(env.sunDirection);\n let Ns = N * select(-1.0, 1.0, dot(N, L) >= 0.0);\n let biased = eyePos + Ns * shadowU.params.z;\n let clip = shadowU.lightViewProj * vec4<f32>(biased, 1.0);\n let ndc = clip.xyz / clip.w;\n let uv = vec2<f32>(ndc.x * 0.5 + 0.5, ndc.y * -0.5 + 0.5);\n let inBounds = uv.x >= 0.0 && uv.x <= 1.0 && uv.y >= 0.0 && uv.y <= 1.0 && ndc.z > 0.0;\n if (!inBounds) { return 1.0; }\n let NdotL = max(dot(Ns, L), 0.0);\n let slope = clamp(sqrt(max(1.0 - NdotL * NdotL, 0.0)) / max(NdotL, 0.1), 1.0, 12.0);\n let refDepth = ndc.z + shadowU.params2.x * slope * (1.0 + shadowU.params.w);\n let radius = shadowU.params.x * shadowU.params.w;\n let ign = fract(52.9829189 * fract(dot(fragCoord, vec2<f32>(0.06711056, 0.00583715))));\n let ang = ign * 6.2831853;\n let cr = cos(ang); let sr = sin(ang); var sum = 0.0;\n for (var i = 0; i < 12; i = i + 1) {\n let p = SHADOW_POISSON[i];\n let off = vec2<f32>(p.x * cr - p.y * sr, p.x * sr + p.y * cr) * radius;\n sum = sum + textureSampleCompareLevel(shadowMap, shadowCmp, uv + off, refDepth);\n }\n return mix(1.0, sum / 12.0, smoothstep(0.0, 0.3, NdotL));\n }\n\n struct VertexInput {\n @location(0) position: vec3<f32>,\n @location(1) normal: vec3<f32>,\n @location(2) entityId: u32,\n }\n\n struct VertexOutput {\n @builtin(position) position: vec4<f32>,\n @location(0) worldPos: vec3<f32>,\n @location(1) normal: vec3<f32>,\n @location(2) @interpolate(flat) entityId: u32,\n // Per-draw albedo carried from the vertex stage so the fragment shader\n // is shared by the flat path (vs_main writes uniforms.baseColor \u2014 the\n // per-batch colour) AND the instanced path\n // (vs_instanced writes the per-occurrence colour from the instance\n // buffer). For the flat path this is identical to reading\n // uniforms.baseColor directly (the value is constant across the draw).\n @location(4) color: vec4<f32>,\n // Per-occurrence selection flag for the instanced path (bit 0 = selected).\n // vs_main writes 0 (the flat path selects via uniforms.flags.x instead);\n // vs_instanced writes the per-instance flag from the instance buffer, so a\n // single selected occurrence highlights without re-drawing.\n @location(5) @interpolate(flat) instSelected: u32,\n // Camera-relative position for fragment operations that compare\n // geometry to section/crop boundaries or take derivatives. This is\n // intentionally separate from worldPos: shadow maps still consume\n // their established world-space light matrix until their depth pass\n // is migrated as one transaction.\n @location(6) eyePos: vec3<f32>,\n }\n\n // Per-instance vertex-buffer inputs (slot 1, stepMode 'instance') used by\n // vs_instanced. The mat4 arrives as four COLUMN vec4s (WGSL mat4x4 is\n // column-major), matching composeInstanceMatrix's column-major output +\n // the pipeline's slot-1 attribute offsets (0/16/32/48).\n //\n // Location namespaces: vertex-INPUT @location (this struct + VertexInput)\n // and inter-stage @location (VertexOutput) are INDEPENDENT in WGSL, so\n // InstanceInput.m1 @location(4) does NOT collide with VertexOutput.color\n // @location(4) \u2014 exactly as VertexInput.entityId and VertexOutput.entityId\n // already BOTH use @location(2). Within the INPUT namespace the per-vertex\n // inputs (0..2) and per-instance inputs (3..8) stay distinct.\n struct InstanceInput {\n @location(3) m0: vec4<f32>,\n @location(4) m1: vec4<f32>,\n @location(5) m2: vec4<f32>,\n @location(6) m3: vec4<f32>,\n @location(7) instEntityId: u32,\n @location(8) instColor: vec4<f32>,\n @location(9) instSelected: u32,\n @location(10) anchorHigh: vec4<f32>,\n @location(11) anchorLow: vec4<f32>,\n }\n\n // 12-byte quantized vertex (issue #1682 phase 6): uint16x4 (lattice\n // position xyz + packed octahedral normal in w as (u8x << 8 | u8y))\n // followed by the u32 entityId lane. Dequantization is BIT-EXACT for\n // the 2^-10 lattice: quantMin and q*step are both (integer)\u00B72^-10,\n // so coincident points across batches stay coincident (the shared-\n // origin z-fight guarantee survives quantization).\n struct QuantizedVertexInput {\n @location(0) q: vec4<u32>, // uint16x4: x, y, z, packedOct\n @location(2) entityId: u32,\n }\n\n fn octDecodeN(packed: u32) -> vec3<f32> {\n let ox = (f32((packed >> 8u) & 255u) / 255.0) * 2.0 - 1.0;\n let oy = (f32(packed & 255u) / 255.0) * 2.0 - 1.0;\n var n = vec3<f32>(ox, oy, 1.0 - abs(ox) - abs(oy));\n if (n.z < 0.0) {\n let tx = (1.0 - abs(oy)) * select(-1.0, 1.0, ox >= 0.0);\n let ty = (1.0 - abs(ox)) * select(-1.0, 1.0, oy >= 0.0);\n n = vec3<f32>(tx, ty, n.z);\n }\n return normalize(n);\n }\n\n // Shared flat-path vertex shading \u2014 vs_main and vs_main_quantized\n // differ ONLY in how position/normal are sourced.\n fn shadeFlatVertex(localPos: vec3<f32>, localNormal: vec3<f32>, entityId: u32) -> VertexOutput {\n var output: VertexOutput;\n let worldPos = uniforms.model * vec4<f32>(localPos, 1.0);\n let eyePos = rtePosition(localPos).xyz;\n let rte = (uniforms.flags.x & RTE_DRAWABLE_FLAG) != 0u;\n output.position = select(uniforms.viewProj * worldPos, uniforms.rteViewProj * vec4<f32>(eyePos, 1.0), rte);\n // Anti z-fighting depth nudge \u2014 see vs_main's comment.\n let colorSalt = (entityId >> 24u) * 2654435761u;\n let zHash = (((entityId & 0x00FFFFFFu) ^ colorSalt) * 2654435761u) & 255u;\n output.position.z = nudgedClipZ(output.position, zHash, uniforms.viewProj);\n output.worldPos = worldPos.xyz;\n output.normal = normalize((uniforms.model * vec4<f32>(localNormal, 0.0)).xyz);\n output.entityId = entityId;\n output.color = uniforms.baseColor;\n output.instSelected = 0u;\n output.eyePos = eyePos;\n return output;\n }\n\n @vertex\n fn vs_main_quantized(input: QuantizedVertexInput) -> VertexOutput {\n let p = uniforms.quantParams.xyz\n + vec3<f32>(f32(input.q.x), f32(input.q.y), f32(input.q.z)) * uniforms.quantParams.w;\n return shadeFlatVertex(p, octDecodeN(input.q.w), input.entityId);\n }\n\n @vertex\n fn vs_main(input: VertexInput, @builtin(instance_index) instanceIndex: u32) -> VertexOutput {\n var output: VertexOutput;\n let worldPos = uniforms.model * vec4<f32>(input.position, 1.0);\n let eyePos = rtePosition(input.position).xyz;\n let rte = (uniforms.flags.x & RTE_DRAWABLE_FLAG) != 0u;\n output.position = select(uniforms.viewProj * worldPos, uniforms.rteViewProj * vec4<f32>(eyePos, 1.0), rte);\n // Anti z-fighting: deterministic depth nudge.\n // Knuth multiplicative hash spreads sequential IDs across 0-255 so\n // coplanar faces from different entities always get distinct depths.\n // Material-layer walls slice into one closed solid per layer, all\n // sharing the PARENT wall's expressId, so adjacent layers' coincident\n // interface caps would get the same entity nudge and z-fight into a\n // flickering comb (\"see inside the wall\"). To separate them we fold in\n // an 8-bit MATERIAL-COLOUR salt that mergeGeometry/interleaveTextured\n // baked into the HIGH 8 bits of the entityId lane (low 24 = picking id,\n // masked off by encodeId24). Crucially the salt comes from the mesh's\n // OWN colour, NOT the per-draw baseColor uniform \u2014 so every redraw of\n // the same geometry with a different draw colour (the selection\n // highlight's greater-equal pass) computes the SAME nudge as its\n // batch. The step size per projection is in depth-nudge.wgsl.ts.\n let colorSalt = (input.entityId >> 24u) * 2654435761u;\n let zHash = (((input.entityId & 0x00FFFFFFu) ^ colorSalt) * 2654435761u) & 255u;\n output.position.z = nudgedClipZ(output.position, zHash, uniforms.viewProj);\n output.worldPos = worldPos.xyz;\n output.normal = normalize((uniforms.model * vec4<f32>(input.normal, 0.0)).xyz);\n output.entityId = input.entityId;\n output.color = uniforms.baseColor;\n output.instSelected = 0u; // flat path selects via uniforms.flags.x\n output.eyePos = eyePos;\n return output;\n }\n\n // Instanced vertex entry \u2014 one template's geometry drawn once per\n // occurrence. The per-instance mat4 already folds SWAP * rel_k * T(origin)\n // (composed CPU-side, see instanced-render.ts), so it maps the template's\n // LOCAL vertex straight to WebGL Y-up world space \u2014 no uniforms.model.\n // rel_k and SWAP are rigid (no scale), so the same matrix transforms\n // normals. entityId + colour come per-occurrence from the instance buffer.\n @vertex\n fn vs_instanced(input: VertexInput, inst: InstanceInput) -> VertexOutput {\n var output: VertexOutput;\n let instMat = mat4x4<f32>(inst.m0, inst.m1, inst.m2, inst.m3);\n let worldPos = instMat * vec4<f32>(input.position, 1.0);\n let linearLocal = (instMat * vec4<f32>(input.position, 0.0)).xyz;\n let eyePos = rteInstancePosition(linearLocal, inst.anchorHigh.xyz, inst.anchorLow.xyz).xyz;\n output.position = uniforms.rteViewProj * vec4<f32>(eyePos, 1.0);\n // Same per-entity depth nudge as vs_main. No colour salt here: the\n // instanced path never redraws an occurrence with a second draw\n // colour, so the raw picking id is enough to separate coplanar entities.\n let zHash = ((inst.instEntityId & 0x00FFFFFFu) * 2654435761u) & 255u;\n output.position.z = nudgedClipZ(output.position, zHash, uniforms.viewProj);\n output.worldPos = worldPos.xyz;\n output.normal = normalize((instMat * vec4<f32>(input.normal, 0.0)).xyz);\n output.entityId = inst.instEntityId;\n output.color = inst.instColor;\n output.instSelected = inst.instSelected;\n output.eyePos = eyePos;\n return output;\n }\n\n fn encodeId24(id: u32) -> vec4<f32> {\n let r = f32((id >> 16u) & 255u) / 255.0;\n let g = f32((id >> 8u) & 255u) / 255.0;\n let b = f32(id & 255u) / 255.0;\n return vec4<f32>(r, g, b, 1.0);\n }\n\n struct FragmentOutput {\n @location(0) color: vec4<f32>,\n @location(1) objectIdEncoded: vec4<f32>,\n }\n\n @fragment\n fn fs_main(input: VertexOutput) -> FragmentOutput {\n // The flat/quantized/textured mesh paths submit this in one\n // camera-relative frame. Do all camera-local fragment arithmetic in\n // that frame; otherwise the RTE vertex precision is thrown away at\n // section/crop/derivative ingress. Instanced geometry is not yet\n // anchored, so its worldPos remains the authoritative input.\n let fragmentPos = clipSpacePos(input.worldPos, input.eyePos);\n // Per-instance hide/isolate: bit 1 of the instance flags lane marks a hidden\n // occurrence. Discard it so it neither draws nor writes depth (and the pick\n // pass applies the same discard, so it isn't pickable). vs_main writes\n // instSelected=0u for flat geometry, so this never affects the flat path.\n if ((input.instSelected & 2u) != 0u) {\n discard;\n }\n // Per-instance opacity routing (instanced passes only \u2014 flags.x bit 2). The\n // opaque instanced pass draws fully-opaque (or selected) occurrences; the\n // transparent instanced sub-pass (bit 3, alpha-blended) draws the rest. Discard\n // the occurrences belonging to the OTHER pass so each is drawn exactly once.\n // Lens-ghost / x-ray / compare write a low per-instance alpha into input.color.a.\n if ((uniforms.flags.x & 4u) != 0u) {\n let occOpaque = input.color.a >= 0.99 || (input.instSelected & 1u) != 0u;\n let transparentPass = (uniforms.flags.x & 8u) != 0u;\n if (transparentPass) {\n if (occOpaque) { discard; }\n } else {\n if (!occOpaque) { discard; }\n }\n }\n // Section plane / clip box (mesh-uniforms.wgsl.ts, shared with the\n // selection mask so an outline is cut where its surface is).\n if (sectionClipped(fragmentPos)) { discard; }\n\n // Compute normal via derivative-based flat shading.\n //\n // Industry-standard solution for BIM/CAD viewers \u2014 what\n // Three.js (material.flatShading = true), Autodesk Forge,\n // Speckle, and xeokit all do for opaque surfaces. Rationale:\n //\n // * BIM geometry is overwhelmingly flat surfaces (walls,\n // slabs, roofs, beams), and CSG operations (opening\n // subtraction, layer slicing) emit those surfaces as\n // dense strips of coplanar triangles. Per-vertex normal\n // averaging gives a SLIGHTLY-different normal at each\n // vertex due to f32 noise from boolean output; the\n // boundary between strips then reads as a visible darker/\n // brighter scar line \u2014 the horizontal striations on\n // walls, stripes on roofs, visible triangulation reports\n // across every CSG kernel we have tried (legacy BSP,\n // Manifold).\n // * cross(dpdx, dpdy) of world position evaluates to the\n // EXACT face normal in the fragment shader. Every\n // fragment on a flat face \u2014 across an arbitrarily-fine\n // triangulation \u2014 gets the IDENTICAL normal, so coplanar\n // splits become invisible by construction. No CPU-side\n // welding, smooth-grouping, or coplanar-face merging\n // fixes the symptom as cleanly.\n //\n // Trade-off: genuinely curved surfaces (cylinder tessellations,\n // BSpline approximations) shade with visible facets. For BIM\n // that's acceptable \u2014 curved surfaces are < 5 % of typical\n // model triangle count and the faceting matches CAD-tool\n // (Revit, ArchiCAD) on-screen behaviour at default quality.\n //\n // We still fall back to the vertex normal when derivatives\n // are unavailable (extreme polygon degeneracy where dpdx /\n // dpdy collapse to zero \u2014 practically never on real geometry).\n let faceN = cross(dpdx(fragmentPos), dpdy(fragmentPos));\n let fLen2 = dot(faceN, faceN);\n var N: vec3<f32>;\n if (fLen2 > 1e-10) {\n N = faceN * inverseSqrt(fLen2);\n } else {\n // Degenerate derivative \u2014 fall back to the vertex normal\n // if it's populated, else +Y.\n N = input.normal;\n let nLen2 = dot(N, N);\n if (nLen2 > 1e-6) {\n N = N * inverseSqrt(nLen2);\n } else {\n N = vec3<f32>(0.0, 1.0, 0.0);\n }\n }\n\n // Stabilize the SIGN of the derivative face normal with the vertex\n // normal. The screen-space cross product gives the exact face\n // normal DIRECTION for coplanar strips (the scar-line fix), but at\n // grazing angles its SIGN becomes numerically unstable per quad \u2014\n // hemisphere/rim lighting then band-flips across large regions of\n // flat walls/slabs (diagonal lighter/darker bands). The interpolated\n // vertex normal is quad-noise-free, so use it only to orient N.\n // Guard: skip when the vertex normal is missing or nearly\n // perpendicular to the face normal (unreliable witness).\n let vN = input.normal;\n let alignDot = dot(N, vN);\n if (alignDot * alignDot > 0.03 * dot(vN, vN)) {\n N = N * sign(alignDot);\n }\n\n // Lighting environment \u2014 sun/hemisphere/exposure come from the\n // global env uniform. The fill follows the sun (it bounces in from\n // the opposite side); the rim stays fixed in world space as a\n // stylistic shaping light.\n let sunLight = env.sunDirection;\n // Horizontal mirror of the sun, lifted slightly. An overhead sun\n // leaves (0, 0.25, 0), which normalizes to straight up.\n let fillLight = normalize(vec3<f32>(-sunLight.x, 0.25, -sunLight.z));\n let rimLight = normalize(vec3<f32>(0.0, 0.2, -1.0)); // Rim light for edge definition\n\n // Hemisphere ambient. This, not the sun, keeps faces turned away\n // from the sun readable (I-beam webs and flange undersides, #5382).\n let hemisphereFactor = N.y * 0.5 + 0.5;\n let ambient = mix(env.groundColor, env.skyColor, hemisphereFactor) * env.ambientIntensity;\n\n // One-sided sun, so a building has a lit side and a shaded side.\n // sunSoftness is the diffuse wrap (env uniform): 0 = crisp\n // terminator (hard shadows), larger = softer wrap-around (overcast).\n let NdotL = dot(N, sunLight);\n let wrap = env.sunSoftness;\n let diffuseSun = max((NdotL + wrap) / (1.0 + wrap), 0.0) * env.sunIntensity;\n\n // Fill light, one-sided like the sun.\n let NdotFill = max(dot(N, fillLight), 0.0);\n let diffuseFill = NdotFill * env.fillIntensity;\n\n // Rim light for edge definition\n let NdotRim = max(dot(N, rimLight), 0.0);\n let rim = pow(NdotRim, 4.0) * env.rimIntensity;\n\n // The authored colour is display-referred sRGB; light it in linear.\n // (textured.wgsl.ts anchors on the first line to multiply in the texel.)\n var baseColor = input.color.rgb;\n baseColor = srgbToLinear(baseColor);\n\n // Combine all lighting. Only the DIRECT sun term is occluded by cast\n // shadows (#2670); ambient/fill/rim are indirect and stay unshadowed.\n // Exposure scales the light, so the selection shade below and every\n // later stage see one exposed irradiance.\n let sunShadow = sunShadowFactor(input.eyePos, N, input.position.xy);\n let lightTerm = ambient + env.sunColor * (diffuseSun * sunShadow) + vec3<f32>(diffuseFill + rim);\n let irradiance = lightTerm * (env.exposure * IRRADIANCE_CALIBRATION);\n var color = baseColor * irradiance;\n\n // flags.x bit 0 (value 1) = isSelected \u2192 selection highlight, forced opaque.\n // bit 1 (value 2) = isOverlay \u2192 legacy overlay pipeline callers;\n // preserve alpha and skip specular for their blended draw.\n // Selected via the per-draw flag (flat path) OR the per-occurrence flag\n // (instanced path \u2014 vs_instanced reads it from the instance buffer).\n let isSelected = ((uniforms.flags.x & 1u) == 1u) || ((input.instSelected & 1u) == 1u);\n let isOverlay = (uniforms.flags.x & 2u) == 2u;\n\n // Selection highlight \u2014 a blue albedo RE-LIT by the scene lighting.\n //\n // We override the material albedo with selection-blue and re-light\n // it with the SAME lightTerm used for unselected surfaces, then\n // skip the view-dependent (specular) term below. Two requirements\n // are in tension and this satisfies both:\n //\n // * No base-material bleed-through. The old fresnel-glow mix left\n // ~80 % of the lit object colour visible at face centres (the\n // green-site / red-roof wash-out). Here the base colour never\n // enters the result \u2014 only lightTerm (geometry/light, colour-\n // independent) modulates the constant blue albedo.\n // * Facet/crease structure must survive. A single FLAT colour\n // (the previous fix) collapsed every face to the same blue, so\n // internal edges \u2014 which read as the per-face shading STEP, not\n // just the faint screen-space edge line \u2014 disappeared on\n // selection. Re-lighting keeps that per-face brightness step, so\n // creases read on the highlight exactly as they do unselected.\n //\n // The luminance of the exposed irradiance is used as a multiplicative\n // gain (which preserves the per-face brightness RATIOS, so creases\n // read as strongly as on the unselected surface). The calibration\n // puts a sunlit face at 1.0, i.e. full selection-blue, and the\n // floor/ceiling clamp keeps shadowed faces only dimmed and bright\n // scenes from washing out.\n if (isSelected) {\n let shadeLum = dot(irradiance, vec3<f32>(0.299, 0.587, 0.114));\n let shade = clamp(shadeLum, 0.45, 1.2);\n // selectionColor is already linear-light (set by Renderer.setOverlayTheme\n // from the app theme, #5484) \u2014 no srgbToLinear here, unlike the constant\n // it replaces.\n color = selectionColor.rgb * shade;\n }\n\n // Public getOverlayPipeline() callers can still use the emphasized\n // overlay bit even though internal colour overrides now use a table.\n let emphasizedOverlay = isOverlay && (uniforms.flags.x & 32u) != 0u;\n if (emphasizedOverlay) {\n let facet = 0.85 + 0.15 * abs(dot(N, normalize(vec3<f32>(0.3, 1.0, 0.2))));\n color = baseColor * facet;\n }\n\n // Selected objects and emphasized overlays draw fully opaque.\n var finalAlpha = select(input.color.a, 1.0, isSelected || emphasizedOverlay);\n\n // Specular (#5386; specular.wgsl.ts), after the diffuse above. Not\n // on the selection highlight or legacy overlay (it would wash out\n // their colours); a table override is composited without it below. The\n // sun lobe is scaled exactly like the diffuse sun term, and both\n // terms like irradiance, so a preset's highlights and diffuse move together.\n if (!isSelected && !isOverlay) {\n // Glass is an authored translucent material (mesh-material.ts\n // also gives it its smooth roughness). An X-Ray or compare fade\n // only lowers the alpha and stays a fade. Instanced occurrences\n // are never authored translucent: prepareInstancedRender routes\n // those to the flat path, so the per-pass lane is ignored there.\n let instancedPass = (uniforms.flags.x & 4u) != 0u;\n let translucent = finalAlpha < 0.99;\n let glass = translucent && uniforms.transmission.x > 0.5 && !instancedPass;\n // #5984: an instanced occurrence's own authored finish rides its\n // flags lane (instanced-render.ts packInstanceFinish); the pass's\n // uniform row is the shared default.\n var metallicRoughness = vec2<f32>(uniforms.metallicRoughness.x, uniforms.metallicRoughness.y);\n if (instancedPass && (input.instSelected & 4u) != 0u) {\n metallicRoughness.x = f32((input.instSelected >> 16u) & 255u) / 255.0;\n }\n if (instancedPass && (input.instSelected & 8u) != 0u) {\n metallicRoughness.y = f32((input.instSelected >> 24u) & 255u) / 255.0;\n }\n let metallic = clamp(metallicRoughness.x, 0.0, 1.0);\n let spec = surfaceSpecular(\n N,\n normalize(-input.eyePos),\n baseColor,\n metallic,\n metallicRoughness.y,\n env.sunColor * (env.sunIntensity * sunShadow),\n );\n // What the lobe reflects is not there to diffuse; a metal has no\n // diffuse at all.\n let diffuse = color * (1.0 - spec.reflectance) * (1.0 - metallic);\n let reflected = spec.light * (env.exposure * IRRADIANCE_CALIBRATION);\n if (translucent) {\n finalAlpha = finalAlpha * TRANSLUCENT_OPACITY_SCALE;\n }\n if (glass) {\n // The transparent pipelines blend straight alpha:\n // out = c * a + behind * (1 - a). A pane passes what is behind\n // it except what its body absorbs and its surface reflects, and\n // its reflection is not dimmed by the body's opacity, so solve\n // for (c, a). The reflectance rising at grazing angles is what\n // makes glass more opaque there; a bright sun glint raises the\n // alpha further so it is not clipped to the body's opacity.\n let body = finalAlpha;\n let reflectance = dot(spec.reflectance, vec3<f32>(0.299, 0.587, 0.114));\n let premultiplied = diffuse * body + reflected;\n let peak = max(premultiplied.r, max(premultiplied.g, premultiplied.b));\n finalAlpha = clamp(max(body + reflectance * (1.0 - body), peak), 0.0, 1.0);\n color = premultiplied / max(finalAlpha, 0.0001);\n } else {\n color = diffuse + reflected;\n }\n }\n\n // Hue-preserving highlight roll-off (color-transfer.wgsl.ts). No\n // contrast curve and no saturation boost: an authored colour lit at\n // unit irradiance leaves here unchanged unless it is brighter than\n // the roll-off threshold.\n color = neutralCompress(color);\n\n color = linearToSrgb(clamp(color, vec3<f32>(0.0), vec3<f32>(1.0)));\n\n var out: FragmentOutput;\n out.color = vec4<f32>(color, finalAlpha);\n // Colour override from the per-entity table (#6076): only draws the\n // renderer marks (overrideParams.y), i.e. depth-writing opaque ones.\n let entityOverride = entityOverrideColor(input.entityId);\n if (entityOverride.a >= 0.0 && !isSelected) {\n out.color = paintEntityOverride(out.color, entityOverride, irradiance, N);\n }\n out.objectIdEncoded = encodeId24(input.entityId);\n return out;\n }\n ";
1
+ export declare const mainShaderSource = "\n \n \n struct ExtraClip {\n planeInfo: vec4<u32>, // x = plane count, y = flipped bit mask\n planes: array<vec4<f32>, 7>, // xyz = normal, w = distance\n }\n\n // True when p is on the removed side of ANY extra plane.\n fn extraClipClipped(clip: ExtraClip, p: vec3<f32>) -> bool {\n for (var i = 0u; i < clip.planeInfo.x; i = i + 1u) {\n let side = select(1.0, -1.0, ((clip.planeInfo.y >> i) & 1u) == 1u);\n if ((dot(p, clip.planes[i].xyz) - clip.planes[i].w) * side > 0.0) { return true; }\n }\n return false;\n }\n\n \n@group(3) @binding(0) var<storage, read> sectionExcludedIds: array<u32>;\n// Scene colour buckets are partitioned by 2^24 ID page. Reject an invalid anchor.\nfn sectionEntityFromLane(anchor: u32, lane: u32) -> u32 {\n return select(anchor + ((lane - anchor) & 0x00FFFFFFu), 0xFFFFFFFFu, anchor == 0xFFFFFFFFu);\n}\nfn sectionExcluded(id: u32) -> bool {\n var lo = 0u;\n var hi = sectionExcludedIds[0];\n while (lo < hi) {\n let mid = lo + (hi - lo) / 2u;\n let key = sectionExcludedIds[mid + 1u];\n if (key == id) { return true; }\n if (key < id) { lo = mid + 1u; } else { hi = mid; }\n }\n return false;\n}\n\n struct Uniforms {\n viewProj: mat4x4<f32>,\n model: mat4x4<f32>,\n baseColor: vec4<f32>,\n metallicRoughness: vec2<f32>, // x = metallic, y = roughness (mesh-material.ts)\n transmission: vec2<f32>, // x = 1: authored translucent, drawn as glass; y = pad\n sectionPlane: vec4<f32>, // xyz = plane normal, w = plane distance\n flags: vec4<u32>, // x = isSelected, y = section/clip bits; z, w unused (0) since #5746 dropped the derivative edges\n clipBoxMin: vec4<f32>, // xyz = clip-box min corner (world), w = pad\n clipBoxMax: vec4<f32>, // xyz = clip-box max corner (world), w = pad\n quantParams: vec4<f32>, // local min xyz, lattice step w\n rteViewProj: mat4x4<f32>, // appended frame; bit 16 selects it\n drawableDeltaHigh: vec4<f32>,\n drawableDeltaLow: vec4<f32>,\n rteCameraHigh: vec4<f32>,\n rteCameraLow: vec4<f32>,\n overrideParams: vec4<u32>, // x = draw's id anchor, y = OVERRIDE_* bits (entity-color-table.ts, #6076)\n extraClip: ExtraClip, // cutting planes beyond sectionPlane (#7545); count 0 = none\n }\n @binding(0) @group(0) var<uniform> uniforms: Uniforms;\n const RTE_DRAWABLE_FLAG: u32 = 65536u;\n\n // The fragment position the section/crop tests run in: camera-relative\n // for RTE drawables (the packer writes plane and box in that frame),\n // world space otherwise.\n fn clipSpacePos(worldPos: vec3<f32>, eyePos: vec3<f32>) -> vec3<f32> {\n return select(worldPos, eyePos, (uniforms.flags.x & RTE_DRAWABLE_FLAG) != 0u);\n }\n\n // True when p is cut away: ABOVE the section plane (flags.y bit 0 =\n // enabled, bit 1 = flipped), on the removed side of any extra plane\n // (extraClip, #7545) or OUTSIDE the clip box (bit 2).\n fn sectionClipped(p: vec3<f32>, id: u32) -> bool {\n let excluded = sectionExcluded(id);\n if (!excluded && (uniforms.flags.y & 1u) == 1u) {\n let side = select(1.0, -1.0, (uniforms.flags.y & 2u) == 2u);\n if ((dot(p, uniforms.sectionPlane.xyz) - uniforms.sectionPlane.w) * side > 0.0) { return true; }\n }\n if (!excluded && extraClipClipped(uniforms.extraClip, p)) { return true; }\n if ((uniforms.flags.y & 4u) != 0u) {\n if (any(p < uniforms.clipBoxMin.xyz) || any(p > uniforms.clipBoxMax.xyz)) { return true; }\n }\n return false;\n }\n\n \n \n const ORTHOGRAPHIC_DEPTH_NUDGE_PER_LEVEL: f32 = 4.76837158203125e-7;\n const ORTHOGRAPHIC_MAX_DEPTH_NUDGE_METRES: f32 = 0.025;\n const MAX_DEPTH_NUDGE_HASH: f32 = 255.0;\n\n fn isOrthographicProjection(viewProj: mat4x4<f32>) -> bool {\n return viewProj[0][3] == 0.0 && viewProj[1][3] == 0.0 && viewProj[2][3] == 0.0 && viewProj[3][3] == 1.0;\n }\n\n fn orthographicNudgeLevels(viewProj: mat4x4<f32>) -> u32 {\n let depthRange = 1.0 / length(vec3<f32>(viewProj[0][2], viewProj[1][2], viewProj[2][2]));\n let steps = ORTHOGRAPHIC_MAX_DEPTH_NUDGE_METRES / (depthRange * ORTHOGRAPHIC_DEPTH_NUDGE_PER_LEVEL);\n return u32(clamp(floor(steps), 0.0, MAX_DEPTH_NUDGE_HASH)) + 1u;\n }\n\n fn orthographicOffsetInsideDepthRange(clip: vec4<f32>, ndcOffset: f32) -> f32 {\n if (!(clip.z > 0.0 && clip.z < clip.w)) { return clip.z; }\n return min(clip.z + ndcOffset * clip.w, clip.w);\n }\n\n const PERSPECTIVE_DEPTH_NUDGE_PER_STEP: f32 = 0.000001;\n\n fn nudgedClipZ(clip: vec4<f32>, zHash: u32, viewProj: mat4x4<f32>) -> f32 {\n if (isOrthographicProjection(viewProj)) {\n let level = (zHash * orthographicNudgeLevels(viewProj)) >> 8u;\n return orthographicOffsetInsideDepthRange(clip, f32(level) * ORTHOGRAPHIC_DEPTH_NUDGE_PER_LEVEL);\n }\n return clip.z * (1.0 + f32(zHash) * PERSPECTIVE_DEPTH_NUDGE_PER_STEP);\n }\n\n \nstruct RteFrameUniform {\n // Camera translation is intentionally absent. This projects positions\n // returned by rteWorldPosition, which are already relative to the eye.\n viewProj: mat4x4<f32>,\n}\n\nstruct RteDrawableUniform {\n // CPU computes (drawable origin - camera origin) in f64 and splits it.\n // This data must be refreshed whenever the RTE camera frame changes.\n drawableDeltaHigh: vec4<f32>,\n drawableDeltaLow: vec4<f32>,\n}\n\nfn rteWorldPosition(\n local: vec3<f32>,\n drawable: RteDrawableUniform,\n) -> vec4<f32> {\n // Do not subtract a camera origin here: this delta was formed in CPU f64.\n let highDelta = drawable.drawableDeltaHigh.xyz;\n let lowDelta = drawable.drawableDeltaLow.xyz;\n // A drawable template can span kilometres. Keep local with high first;\n // The local-plus-(high-plus-low) association is not equivalent in f32.\n return vec4<f32>((local + highDelta) + lowDelta, 1.0);\n}\n\n \n fn rtePosition(local: vec3<f32>) -> vec4<f32> {\n let linear = (uniforms.model * vec4<f32>(local, 0.0)).xyz;\n return rteWorldPosition(linear, RteDrawableUniform(\n uniforms.drawableDeltaHigh,\n uniforms.drawableDeltaLow,\n ));\n }\n fn rteInstancePosition(local: vec3<f32>, anchorHigh: vec3<f32>, anchorLow: vec3<f32>) -> vec4<f32> {\n return rteWorldPosition(local, RteDrawableUniform(\n vec4<f32>(anchorHigh, 0.0),\n vec4<f32>(anchorLow, 0.0),\n ));\n }\n // Shared group(1) lighting; packing matches packEnvironmentUniforms().\n struct Environment {\n sunDirection: vec3<f32>, // unit vector TOWARD the sun\n sunIntensity: f32,\n sunColor: vec3<f32>,\n ambientIntensity: f32,\n skyColor: vec3<f32>, // hemisphere-ambient sky tint\n exposure: f32,\n groundColor: vec3<f32>, // hemisphere-ambient ground tint\n fillIntensity: f32,\n rimIntensity: f32,\n sunSoftness: f32,\n _pad1: f32,\n _pad2: f32,\n }\n @binding(0) @group(1) var<uniform> env: Environment;\n // Selection highlight tint (#5484), set by Renderer.setOverlayTheme via\n // updateSelectionColor \u2014 written only on theme change, never per frame.\n // TRUE LINEAR-LIGHT RGB: re-lit by lightTerm below exactly like the WGSL\n // constant it replaces, then ACES-tonemapped + gamma-encoded on output.\n @binding(4) @group(1) var<uniform> selectionColor: vec4<f32>;\n const IRRADIANCE_CALIBRATION: f32 = 1.82;\n const TRANSLUCENT_OPACITY_SCALE: f32 = 0.7;\n \n fn srgbToLinear(c: vec3<f32>) -> vec3<f32> {\n let lo = c / 12.92;\n let hi = pow((max(c, vec3<f32>(0.0)) + 0.055) / 1.055, vec3<f32>(2.4));\n return select(hi, lo, c <= vec3<f32>(0.04045));\n }\n\n fn linearToSrgb(c: vec3<f32>) -> vec3<f32> {\n let lo = c * 12.92;\n let hi = 1.055 * pow(max(c, vec3<f32>(0.0)), vec3<f32>(1.0 / 2.4)) - 0.055;\n return select(hi, lo, c <= vec3<f32>(0.0031308));\n }\n\n fn neutralCompress(cIn: vec3<f32>) -> vec3<f32> {\n let startCompression = 0.76;\n let desaturation = 0.15;\n let c = max(cIn, vec3<f32>(0.0));\n let peak = max(c.r, max(c.g, c.b));\n if (peak < startCompression) { return c; }\n let d = 1.0 - startCompression;\n let newPeak = 1.0 - d * d / (peak + d - startCompression);\n let g = 1.0 - 1.0 / (desaturation * (peak - newPeak) + 1.0);\n return mix(c * (newPeak / peak), vec3<f32>(newPeak), g);\n }\n\n \n const MIN_SPECULAR_ROUGHNESS: f32 = 0.045;\n const DIELECTRIC_F0: f32 = 0.04;\n const PI: f32 = 3.14159265;\n\n fn fresnelSchlick(cosTheta: f32, F0: vec3<f32>) -> vec3<f32> {\n return F0 + (1.0 - F0) * pow(clamp(1.0 - cosTheta, 0.0, 1.0), 5.0);\n }\n\n fn distributionGGX(NdotH: f32, roughness: f32) -> f32 {\n let a = roughness * roughness;\n let a2 = a * a;\n let NdotH2 = NdotH * NdotH;\n let denomBase = (NdotH2 * (a2 - 1.0) + 1.0);\n return a2 / max(PI * denomBase * denomBase, 0.0000001);\n }\n\n fn geometrySchlickGGX(NdotV: f32, roughness: f32) -> f32 {\n let r = (roughness + 1.0);\n let k = (r * r) / 8.0;\n return NdotV / max(NdotV * (1.0 - k) + k, 0.0000001);\n }\n\n fn geometrySmith(NdotV: f32, NdotL: f32, roughness: f32) -> f32 {\n return geometrySchlickGGX(NdotL, roughness) * geometrySchlickGGX(NdotV, roughness);\n }\n\n // Split-sum environment BRDF, analytic fit (Karis 2014).\n fn envBrdfApprox(F0: vec3<f32>, roughness: f32, NdotV: f32) -> vec3<f32> {\n let r = roughness * vec4<f32>(-1.0, -0.0275, -0.572, 0.022) + vec4<f32>(1.0, 0.0425, 1.04, -0.04);\n let a004 = min(r.x * r.x, exp2(-9.28 * NdotV)) * r.x + r.y;\n let ab = vec2<f32>(-1.04, 1.04) * a004 + r.zw;\n return F0 * ab.x + ab.y;\n }\n\n struct SurfaceSpecular {\n // Reflected light, in lightTerm units (unexposed, uncalibrated).\n light: vec3<f32>,\n // Directional albedo of the specular lobe for this view.\n reflectance: vec3<f32>,\n }\n\n // N and V are unit vectors; V points from the surface to the eye.\n // sunLight is the sun's diffuse-equivalent intensity: sunColor *\n // sunIntensity * sunShadow, exactly what scales the diffuse sun term.\n fn surfaceSpecular(\n N: vec3<f32>,\n V: vec3<f32>,\n albedo: vec3<f32>,\n metallic: f32,\n roughnessIn: f32,\n sunLight: vec3<f32>,\n ) -> SurfaceSpecular {\n var out: SurfaceSpecular;\n let NdotV = dot(N, V);\n // A face turned away from the eye is its back side: nothing it\n // reflects can reach the eye, and its diffuse keeps full weight.\n if (NdotV <= 0.0) {\n out.light = vec3<f32>(0.0);\n out.reflectance = vec3<f32>(0.0);\n return out;\n }\n let roughness = clamp(roughnessIn, MIN_SPECULAR_ROUGHNESS, 1.0);\n let F0 = mix(vec3<f32>(DIELECTRIC_F0), albedo, metallic);\n\n let L = env.sunDirection;\n let rawNdotL = dot(N, L);\n let NdotL = max(rawNdotL, 0.0);\n // A face the sun is behind (rawNdotL <= 0) contributes nothing to\n // the direct lobe anyway (NdotL clamps it to 0 below), but V + L\n // can be exactly zero there \u2014 the sun exactly opposite the eye\n // reflection, e.g. N = V = (0,-1,0), sun = (0,1,0), both satisfy\n // NdotV > 0 above. normalize(vec3(0)) is NaN in WGSL, and NaN * 0\n // is NaN, not 0, so it would poison sun and everything summed with\n // it instead of being multiplied away. Skip the half-vector\n // entirely in that case rather than relying on the NdotL factor.\n var sun = vec3<f32>(0.0);\n if (rawNdotL > 0.0) {\n let H = normalize(V + L);\n let D = distributionGGX(max(dot(N, H), 0.0), roughness);\n let G = geometrySmith(NdotV, NdotL, roughness);\n let F = fresnelSchlick(max(dot(V, H), 0.0), F0);\n // BRDF * NdotL * (pi * intensity); the NdotL cancels the BRDF's.\n sun = F * (D * G * PI / (4.0 * NdotV)) * sunLight;\n }\n\n // The hemisphere ambient, looked up along the reflection. A rough\n // lobe gathers from around the normal, so lean the lookup toward N.\n let R = reflect(-V, N);\n let Rd = normalize(mix(R, N, roughness * roughness));\n let sky = mix(env.groundColor, env.skyColor, Rd.y * 0.5 + 0.5) * env.ambientIntensity;\n let reflectance = envBrdfApprox(F0, roughness, NdotV);\n\n out.light = sun + sky * reflectance;\n out.reflectance = reflectance;\n return out;\n }\n\n \n @binding(5) @group(1) var<storage, read> entityColorTable: array<u32>;\n const ENTITY_COLOR_EMPTY: u32 = 4294967295u;\n const ENTITY_COLOR_HEADER: u32 = 4u;\n const OVERRIDE_PAINT: u32 = 1u;\n const OVERRIDE_EMPHASIZE: u32 = 2u;\n\n fn entityColorSlotHash(key: u32) -> u32 {\n var h = key;\n h = h ^ (h >> 16u);\n h = h * 0x85ebca6bu;\n h = h ^ (h >> 13u);\n h = h * 0xc2b2ae35u;\n h = h ^ (h >> 16u);\n return h;\n }\n\n // Full scene id behind a 24-bit lane, given the draw's smallest id.\n fn resolveLaneEntityId(anchor: u32, lane: u32) -> u32 {\n return anchor + ((lane - anchor) & 0x00FFFFFFu);\n }\n\n // The override colour for this fragment's entity; alpha < 0 = none.\n fn entityOverrideColor(lane: u32) -> vec4<f32> {\n let none = vec4<f32>(0.0, 0.0, 0.0, -1.0);\n if ((uniforms.overrideParams.y & OVERRIDE_PAINT) == 0u || entityColorTable[2] == 0u) {\n return none;\n }\n let capacity = entityColorTable[0];\n let maxProbe = entityColorTable[1];\n let colorBase = entityColorTable[3];\n let id = resolveLaneEntityId(uniforms.overrideParams.x, lane);\n let mask = capacity - 1u;\n var slot = entityColorSlotHash(id) & mask;\n for (var i = 0u; i <= maxProbe && i < capacity; i = i + 1u) {\n let key = entityColorTable[ENTITY_COLOR_HEADER + slot];\n if (key == id) {\n let c = colorBase + slot * 4u;\n return vec4<f32>(\n bitcast<f32>(entityColorTable[c]),\n bitcast<f32>(entityColorTable[c + 1u]),\n bitcast<f32>(entityColorTable[c + 2u]),\n bitcast<f32>(entityColorTable[c + 3u])\n );\n }\n if (key == ENTITY_COLOR_EMPTY) {\n break;\n }\n slot = (slot + 1u) & mask;\n }\n return none;\n }\n\n // Composite an override over the fragment's own encoded colour exactly\n // as the retired equal-depth overlay pass blended it (src-alpha over\n // the base draw): the override albedo lit by the same irradiance, no\n // specular, the same roll-off and edge darkening, mixed by its alpha.\n // Emphasized overrides are unlit, faintly faceted and opaque (#1277).\n fn paintEntityOverride(base: vec4<f32>, ov: vec4<f32>, irradiance: vec3<f32>, N: vec3<f32>) -> vec4<f32> {\n let albedo = srgbToLinear(ov.rgb);\n var lit = albedo * irradiance;\n var a = ov.a;\n if ((uniforms.overrideParams.y & OVERRIDE_EMPHASIZE) != 0u) {\n lit = albedo * (0.85 + 0.15 * abs(dot(N, normalize(vec3<f32>(0.3, 1.0, 0.2)))));\n a = 1.0;\n }\n let encoded = linearToSrgb(clamp(neutralCompress(lit), vec3<f32>(0.0), vec3<f32>(1.0)));\n return vec4<f32>(mix(base.rgb, encoded, a), a + (1.0 - a) * base.a);\n }\n\n\n \n @binding(1) @group(1) var shadowMap: texture_depth_2d;\n @binding(2) @group(1) var shadowCmp: sampler_comparison;\n struct Shadow { lightViewProj: mat4x4<f32>, params: vec4<f32>, params2: vec4<f32>, }\n @binding(3) @group(1) var<uniform> shadowU: Shadow;\n const SHADOW_POISSON = array<vec2<f32>, 12>(\n vec2<f32>(-0.326, -0.406), vec2<f32>(-0.840, -0.074), vec2<f32>(-0.696, 0.457),\n vec2<f32>(-0.203, 0.621), vec2<f32>( 0.962, -0.195), vec2<f32>( 0.473, -0.480),\n vec2<f32>( 0.519, 0.767), vec2<f32>( 0.185, -0.893), vec2<f32>( 0.507, 0.064),\n vec2<f32>( 0.896, 0.412), vec2<f32>(-0.322, -0.933), vec2<f32>(-0.792, -0.598),\n );\n fn sunShadowFactor(eyePos: vec3<f32>, N: vec3<f32>, fragCoord: vec2<f32>) -> f32 {\n if (shadowU.params.y < 0.5) { return 1.0; }\n let L = normalize(env.sunDirection);\n let Ns = N * select(-1.0, 1.0, dot(N, L) >= 0.0);\n let biased = eyePos + Ns * shadowU.params.z;\n let clip = shadowU.lightViewProj * vec4<f32>(biased, 1.0);\n let ndc = clip.xyz / clip.w;\n let uv = vec2<f32>(ndc.x * 0.5 + 0.5, ndc.y * -0.5 + 0.5);\n let inBounds = uv.x >= 0.0 && uv.x <= 1.0 && uv.y >= 0.0 && uv.y <= 1.0 && ndc.z > 0.0;\n if (!inBounds) { return 1.0; }\n let NdotL = max(dot(Ns, L), 0.0);\n let slope = clamp(sqrt(max(1.0 - NdotL * NdotL, 0.0)) / max(NdotL, 0.1), 1.0, 12.0);\n let refDepth = ndc.z + shadowU.params2.x * slope * (1.0 + shadowU.params.w);\n let radius = shadowU.params.x * shadowU.params.w;\n let ign = fract(52.9829189 * fract(dot(fragCoord, vec2<f32>(0.06711056, 0.00583715))));\n let ang = ign * 6.2831853;\n let cr = cos(ang); let sr = sin(ang); var sum = 0.0;\n for (var i = 0; i < 12; i = i + 1) {\n let p = SHADOW_POISSON[i];\n let off = vec2<f32>(p.x * cr - p.y * sr, p.x * sr + p.y * cr) * radius;\n sum = sum + textureSampleCompareLevel(shadowMap, shadowCmp, uv + off, refDepth);\n }\n return mix(1.0, sum / 12.0, smoothstep(0.0, 0.3, NdotL));\n }\n\n struct VertexInput {\n @location(0) position: vec3<f32>,\n @location(1) normal: vec3<f32>,\n @location(2) entityId: u32,\n }\n\n struct VertexOutput {\n @builtin(position) position: vec4<f32>,\n @location(0) worldPos: vec3<f32>,\n @location(1) normal: vec3<f32>,\n @location(2) @interpolate(flat) entityId: u32,\n @location(9) @interpolate(flat) sectionEntityId: u32,\n // Per-draw albedo carried from the vertex stage so the fragment shader\n // is shared by the flat path (vs_main writes uniforms.baseColor \u2014 the\n // per-batch colour) AND the instanced path\n // (vs_instanced writes the per-occurrence colour from the instance\n // buffer). For the flat path this is identical to reading\n // uniforms.baseColor directly (the value is constant across the draw).\n @location(4) color: vec4<f32>,\n // Per-occurrence selection flag for the instanced path (bit 0 = selected).\n // vs_main writes 0 (the flat path selects via uniforms.flags.x instead);\n // vs_instanced writes the per-instance flag from the instance buffer, so a\n // single selected occurrence highlights without re-drawing.\n @location(5) @interpolate(flat) instSelected: u32,\n // Camera-relative position for fragment operations that compare\n // geometry to section/crop boundaries or take derivatives. This is\n // intentionally separate from worldPos: shadow maps still consume\n // their established world-space light matrix until their depth pass\n // is migrated as one transaction.\n @location(8) @interpolate(linear) geometricDepth: f32,\n @location(6) eyePos: vec3<f32>,\n }\n\n // Per-instance vertex-buffer inputs (slot 1, stepMode 'instance') used by\n // vs_instanced. The mat4 arrives as four COLUMN vec4s (WGSL mat4x4 is\n // column-major), matching composeInstanceMatrix's column-major output +\n // the pipeline's slot-1 attribute offsets (0/16/32/48).\n //\n // Location namespaces: vertex-INPUT @location (this struct + VertexInput)\n // and inter-stage @location (VertexOutput) are INDEPENDENT in WGSL, so\n // InstanceInput.m1 @location(4) does NOT collide with VertexOutput.color\n // @location(4) \u2014 exactly as VertexInput.entityId and VertexOutput.entityId\n // already BOTH use @location(2). Within the INPUT namespace the per-vertex\n // inputs (0..2) and per-instance inputs (3..8) stay distinct.\n struct InstanceInput {\n @location(3) m0: vec4<f32>,\n @location(4) m1: vec4<f32>,\n @location(5) m2: vec4<f32>,\n @location(6) m3: vec4<f32>,\n @location(7) instEntityId: u32,\n @location(8) instColor: vec4<f32>,\n @location(9) instSelected: u32,\n @location(10) anchorHigh: vec4<f32>,\n @location(11) anchorLow: vec4<f32>,\n }\n\n // 12-byte quantized vertex (issue #1682 phase 6): uint16x4 (lattice\n // position xyz + packed octahedral normal in w as (u8x << 8 | u8y))\n // followed by the u32 entityId lane. Dequantization is BIT-EXACT for\n // the 2^-10 lattice: quantMin and q*step are both (integer)\u00B72^-10,\n // so coincident points across batches stay coincident (the shared-\n // origin z-fight guarantee survives quantization).\n struct QuantizedVertexInput {\n @location(0) q: vec4<u32>, // uint16x4: x, y, z, packedOct\n @location(2) entityId: u32,\n }\n\n fn octDecodeN(packed: u32) -> vec3<f32> {\n let ox = (f32((packed >> 8u) & 255u) / 255.0) * 2.0 - 1.0;\n let oy = (f32(packed & 255u) / 255.0) * 2.0 - 1.0;\n var n = vec3<f32>(ox, oy, 1.0 - abs(ox) - abs(oy));\n if (n.z < 0.0) {\n let tx = (1.0 - abs(oy)) * select(-1.0, 1.0, ox >= 0.0);\n let ty = (1.0 - abs(ox)) * select(-1.0, 1.0, oy >= 0.0);\n n = vec3<f32>(tx, ty, n.z);\n }\n return normalize(n);\n }\n\n // Shared flat-path vertex shading \u2014 vs_main and vs_main_quantized\n // differ ONLY in how position/normal are sourced.\n fn shadeFlatVertex(localPos: vec3<f32>, localNormal: vec3<f32>, entityId: u32) -> VertexOutput {\n var output: VertexOutput;\n let worldPos = uniforms.model * vec4<f32>(localPos, 1.0);\n let eyePos = rtePosition(localPos).xyz;\n let rte = (uniforms.flags.x & RTE_DRAWABLE_FLAG) != 0u;\n output.position = select(uniforms.viewProj * worldPos, uniforms.rteViewProj * vec4<f32>(eyePos, 1.0), rte);\n // Anti z-fighting depth nudge \u2014 see vs_main's comment.\n let colorSalt = (entityId >> 24u) * 2654435761u;\n let zHash = (((entityId & 0x00FFFFFFu) ^ colorSalt) * 2654435761u) & 255u;\n output.geometricDepth = output.position.z / output.position.w;\n output.position.z = nudgedClipZ(output.position, zHash, uniforms.viewProj);\n output.worldPos = worldPos.xyz;\n output.normal = normalize((uniforms.model * vec4<f32>(localNormal, 0.0)).xyz);\n output.entityId = entityId;\n output.sectionEntityId = sectionEntityFromLane(uniforms.overrideParams.x, entityId);\n output.color = uniforms.baseColor;\n output.instSelected = 0u;\n output.eyePos = eyePos;\n return output;\n }\n\n @vertex\n fn vs_main_quantized(input: QuantizedVertexInput) -> VertexOutput {\n let p = uniforms.quantParams.xyz\n + vec3<f32>(f32(input.q.x), f32(input.q.y), f32(input.q.z)) * uniforms.quantParams.w;\n return shadeFlatVertex(p, octDecodeN(input.q.w), input.entityId);\n }\n\n @vertex\n fn vs_main(input: VertexInput, @builtin(instance_index) instanceIndex: u32) -> VertexOutput {\n var output: VertexOutput;\n let worldPos = uniforms.model * vec4<f32>(input.position, 1.0);\n let eyePos = rtePosition(input.position).xyz;\n let rte = (uniforms.flags.x & RTE_DRAWABLE_FLAG) != 0u;\n output.position = select(uniforms.viewProj * worldPos, uniforms.rteViewProj * vec4<f32>(eyePos, 1.0), rte);\n // Anti z-fighting: deterministic depth nudge.\n // Knuth multiplicative hash spreads sequential IDs across 0-255 so\n // coplanar faces from different entities always get distinct depths.\n // Material-layer walls slice into one closed solid per layer, all\n // sharing the PARENT wall's expressId, so adjacent layers' coincident\n // interface caps would get the same entity nudge and z-fight into a\n // flickering comb (\"see inside the wall\"). To separate them we fold in\n // an 8-bit MATERIAL-COLOUR salt that mergeGeometry/interleaveTextured\n // baked into the HIGH 8 bits of the entityId lane (low 24 = picking id,\n // masked off by encodeId24). Crucially the salt comes from the mesh's\n // OWN colour, NOT the per-draw baseColor uniform \u2014 so every redraw of\n // the same geometry with a different draw colour (the selection\n // highlight's greater-equal pass) computes the SAME nudge as its\n // batch. The step size per projection is in depth-nudge.wgsl.ts.\n let colorSalt = (input.entityId >> 24u) * 2654435761u;\n let zHash = (((input.entityId & 0x00FFFFFFu) ^ colorSalt) * 2654435761u) & 255u;\n output.geometricDepth = output.position.z / output.position.w;\n output.position.z = nudgedClipZ(output.position, zHash, uniforms.viewProj);\n output.worldPos = worldPos.xyz;\n output.normal = normalize((uniforms.model * vec4<f32>(input.normal, 0.0)).xyz);\n output.entityId = input.entityId;\n output.sectionEntityId = sectionEntityFromLane(uniforms.overrideParams.x, input.entityId);\n output.color = uniforms.baseColor;\n output.instSelected = 0u; // flat path selects via uniforms.flags.x\n output.eyePos = eyePos;\n return output;\n }\n\n // Instanced vertex entry \u2014 one template's geometry drawn once per\n // occurrence. The per-instance mat4 already folds SWAP * rel_k * T(origin)\n // (composed CPU-side, see instanced-render.ts), so it maps the template's\n // LOCAL vertex straight to WebGL Y-up world space \u2014 no uniforms.model.\n // rel_k and SWAP are rigid (no scale), so the same matrix transforms\n // normals. entityId + colour come per-occurrence from the instance buffer.\n @vertex\n fn vs_instanced(input: VertexInput, inst: InstanceInput) -> VertexOutput {\n var output: VertexOutput;\n let instMat = mat4x4<f32>(inst.m0, inst.m1, inst.m2, inst.m3);\n let worldPos = instMat * vec4<f32>(input.position, 1.0);\n let linearLocal = (instMat * vec4<f32>(input.position, 0.0)).xyz;\n let eyePos = rteInstancePosition(linearLocal, inst.anchorHigh.xyz, inst.anchorLow.xyz).xyz;\n output.position = uniforms.rteViewProj * vec4<f32>(eyePos, 1.0);\n // Same per-entity depth nudge as vs_main. No colour salt here: the\n // instanced path never redraws an occurrence with a second draw\n // colour, so the raw picking id is enough to separate coplanar entities.\n let zHash = ((inst.instEntityId & 0x00FFFFFFu) * 2654435761u) & 255u;\n output.geometricDepth = output.position.z / output.position.w;\n output.position.z = nudgedClipZ(output.position, zHash, uniforms.viewProj);\n output.worldPos = worldPos.xyz;\n output.normal = normalize((instMat * vec4<f32>(input.normal, 0.0)).xyz);\n output.entityId = inst.instEntityId;\n output.sectionEntityId = inst.instEntityId;\n output.color = inst.instColor;\n output.instSelected = inst.instSelected;\n output.eyePos = eyePos;\n return output;\n }\n\n fn encodeId24(id: u32) -> vec4<f32> {\n let r = f32((id >> 16u) & 255u) / 255.0;\n let g = f32((id >> 8u) & 255u) / 255.0;\n let b = f32(id & 255u) / 255.0;\n return vec4<f32>(r, g, b, 1.0);\n }\n\n struct FragmentOutput {\n @location(0) color: vec4<f32>,\n @location(1) objectIdEncoded: vec4<f32>,\n }\n\n @fragment\n fn fs_main(input: VertexOutput) -> FragmentOutput {\n // The flat/quantized/textured mesh paths submit this in one\n // camera-relative frame. Do all camera-local fragment arithmetic in\n // that frame; otherwise the RTE vertex precision is thrown away at\n // section/crop/derivative ingress. Instanced geometry is not yet\n // anchored, so its worldPos remains the authoritative input.\n let fragmentPos = clipSpacePos(input.worldPos, input.eyePos);\n // Per-instance hide/isolate: bit 1 of the instance flags lane marks a hidden\n // occurrence. Discard it so it neither draws nor writes depth (and the pick\n // pass applies the same discard, so it isn't pickable). vs_main writes\n // instSelected=0u for flat geometry, so this never affects the flat path.\n if ((input.instSelected & 2u) != 0u) {\n discard;\n }\n // Per-instance opacity routing (instanced passes only \u2014 flags.x bit 2). The\n // opaque instanced pass draws fully-opaque (or selected) occurrences; the\n // transparent instanced sub-pass (bit 3, alpha-blended) draws the rest. Discard\n // the occurrences belonging to the OTHER pass so each is drawn exactly once.\n // Lens-ghost / x-ray / compare write a low per-instance alpha into input.color.a.\n if ((uniforms.flags.x & 4u) != 0u) {\n let occOpaque = input.color.a >= 0.99 || (input.instSelected & 1u) != 0u;\n let transparentPass = (uniforms.flags.x & 8u) != 0u;\n if (transparentPass) {\n if (occOpaque) { discard; }\n } else {\n if (!occOpaque) { discard; }\n }\n }\n // Section plane / clip box (mesh-uniforms.wgsl.ts, shared with the\n // selection mask so an outline is cut where its surface is).\n if (sectionClipped(fragmentPos, input.sectionEntityId)) { discard; }\n\n // Compute normal via derivative-based flat shading.\n //\n // Industry-standard solution for BIM/CAD viewers \u2014 what\n // Three.js (material.flatShading = true), Autodesk Forge,\n // Speckle, and xeokit all do for opaque surfaces. Rationale:\n //\n // * BIM geometry is overwhelmingly flat surfaces (walls,\n // slabs, roofs, beams), and CSG operations (opening\n // subtraction, layer slicing) emit those surfaces as\n // dense strips of coplanar triangles. Per-vertex normal\n // averaging gives a SLIGHTLY-different normal at each\n // vertex due to f32 noise from boolean output; the\n // boundary between strips then reads as a visible darker/\n // brighter scar line \u2014 the horizontal striations on\n // walls, stripes on roofs, visible triangulation reports\n // across every CSG kernel we have tried (legacy BSP,\n // Manifold).\n // * cross(dpdx, dpdy) of world position evaluates to the\n // EXACT face normal in the fragment shader. Every\n // fragment on a flat face \u2014 across an arbitrarily-fine\n // triangulation \u2014 gets the IDENTICAL normal, so coplanar\n // splits become invisible by construction. No CPU-side\n // welding, smooth-grouping, or coplanar-face merging\n // fixes the symptom as cleanly.\n //\n // Trade-off: genuinely curved surfaces (cylinder tessellations,\n // BSpline approximations) shade with visible facets. For BIM\n // that's acceptable \u2014 curved surfaces are < 5 % of typical\n // model triangle count and the faceting matches CAD-tool\n // (Revit, ArchiCAD) on-screen behaviour at default quality.\n //\n // We still fall back to the vertex normal when derivatives\n // are unavailable (extreme polygon degeneracy where dpdx /\n // dpdy collapse to zero \u2014 practically never on real geometry).\n let faceN = cross(dpdx(fragmentPos), dpdy(fragmentPos));\n let fLen2 = dot(faceN, faceN);\n var N: vec3<f32>;\n if (fLen2 > 1e-10) {\n N = faceN * inverseSqrt(fLen2);\n } else {\n // Degenerate derivative \u2014 fall back to the vertex normal\n // if it's populated, else +Y.\n N = input.normal;\n let nLen2 = dot(N, N);\n if (nLen2 > 1e-6) {\n N = N * inverseSqrt(nLen2);\n } else {\n N = vec3<f32>(0.0, 1.0, 0.0);\n }\n }\n\n // Stabilize the SIGN of the derivative face normal with the vertex\n // normal. The screen-space cross product gives the exact face\n // normal DIRECTION for coplanar strips (the scar-line fix), but at\n // grazing angles its SIGN becomes numerically unstable per quad \u2014\n // hemisphere/rim lighting then band-flips across large regions of\n // flat walls/slabs (diagonal lighter/darker bands). The interpolated\n // vertex normal is quad-noise-free, so use it only to orient N.\n // Guard: skip when the vertex normal is missing or nearly\n // perpendicular to the face normal (unreliable witness).\n let vN = input.normal;\n let alignDot = dot(N, vN);\n if (alignDot * alignDot > 0.03 * dot(vN, vN)) {\n N = N * sign(alignDot);\n }\n\n // Lighting environment \u2014 sun/hemisphere/exposure come from the\n // global env uniform. The fill follows the sun (it bounces in from\n // the opposite side); the rim stays fixed in world space as a\n // stylistic shaping light.\n let sunLight = env.sunDirection;\n // Horizontal mirror of the sun, lifted slightly. An overhead sun\n // leaves (0, 0.25, 0), which normalizes to straight up.\n let fillLight = normalize(vec3<f32>(-sunLight.x, 0.25, -sunLight.z));\n let rimLight = normalize(vec3<f32>(0.0, 0.2, -1.0)); // Rim light for edge definition\n\n // Hemisphere ambient. This, not the sun, keeps faces turned away\n // from the sun readable (I-beam webs and flange undersides, #5382).\n let hemisphereFactor = N.y * 0.5 + 0.5;\n let ambient = mix(env.groundColor, env.skyColor, hemisphereFactor) * env.ambientIntensity;\n\n // One-sided sun, so a building has a lit side and a shaded side.\n // sunSoftness is the diffuse wrap (env uniform): 0 = crisp\n // terminator (hard shadows), larger = softer wrap-around (overcast).\n let NdotL = dot(N, sunLight);\n let wrap = env.sunSoftness;\n let diffuseSun = max((NdotL + wrap) / (1.0 + wrap), 0.0) * env.sunIntensity;\n\n // Fill light, one-sided like the sun.\n let NdotFill = max(dot(N, fillLight), 0.0);\n let diffuseFill = NdotFill * env.fillIntensity;\n\n // Rim light for edge definition\n let NdotRim = max(dot(N, rimLight), 0.0);\n let rim = pow(NdotRim, 4.0) * env.rimIntensity;\n\n // The authored colour is display-referred sRGB; light it in linear.\n // (textured.wgsl.ts anchors on the first line to multiply in the texel.)\n var baseColor = input.color.rgb;\n baseColor = srgbToLinear(baseColor);\n\n // Combine all lighting. Only the DIRECT sun term is occluded by cast\n // shadows (#2670); ambient/fill/rim are indirect and stay unshadowed.\n // Exposure scales the light, so the selection shade below and every\n // later stage see one exposed irradiance.\n let sunShadow = sunShadowFactor(input.eyePos, N, input.position.xy);\n let lightTerm = ambient + env.sunColor * (diffuseSun * sunShadow) + vec3<f32>(diffuseFill + rim);\n let irradiance = lightTerm * (env.exposure * IRRADIANCE_CALIBRATION);\n var color = baseColor * irradiance;\n\n // flags.x bit 0 (value 1) = isSelected \u2192 selection highlight, forced opaque.\n // bit 1 (value 2) = isOverlay \u2192 legacy overlay pipeline callers;\n // preserve alpha and skip specular for their blended draw.\n // Selected via the per-draw flag (flat path) OR the per-occurrence flag\n // (instanced path \u2014 vs_instanced reads it from the instance buffer).\n let isSelected = ((uniforms.flags.x & 1u) == 1u) || ((input.instSelected & 1u) == 1u);\n let isOverlay = (uniforms.flags.x & 2u) == 2u;\n\n // Selection highlight \u2014 a blue albedo RE-LIT by the scene lighting.\n //\n // We override the material albedo with selection-blue and re-light\n // it with the SAME lightTerm used for unselected surfaces, then\n // skip the view-dependent (specular) term below. Two requirements\n // are in tension and this satisfies both:\n //\n // * No base-material bleed-through. The old fresnel-glow mix left\n // ~80 % of the lit object colour visible at face centres (the\n // green-site / red-roof wash-out). Here the base colour never\n // enters the result \u2014 only lightTerm (geometry/light, colour-\n // independent) modulates the constant blue albedo.\n // * Facet/crease structure must survive. A single FLAT colour\n // (the previous fix) collapsed every face to the same blue, so\n // internal edges \u2014 which read as the per-face shading STEP, not\n // just the faint screen-space edge line \u2014 disappeared on\n // selection. Re-lighting keeps that per-face brightness step, so\n // creases read on the highlight exactly as they do unselected.\n //\n // The luminance of the exposed irradiance is used as a multiplicative\n // gain (which preserves the per-face brightness RATIOS, so creases\n // read as strongly as on the unselected surface). The calibration\n // puts a sunlit face at 1.0, i.e. full selection-blue, and the\n // floor/ceiling clamp keeps shadowed faces only dimmed and bright\n // scenes from washing out.\n if (isSelected) {\n let shadeLum = dot(irradiance, vec3<f32>(0.299, 0.587, 0.114));\n let shade = clamp(shadeLum, 0.45, 1.2);\n // selectionColor is already linear-light (set by Renderer.setOverlayTheme\n // from the app theme, #5484) \u2014 no srgbToLinear here, unlike the constant\n // it replaces.\n color = selectionColor.rgb * shade;\n }\n\n // Public getOverlayPipeline() callers can still use the emphasized\n // overlay bit even though internal colour overrides now use a table.\n let emphasizedOverlay = isOverlay && (uniforms.flags.x & 32u) != 0u;\n if (emphasizedOverlay) {\n let facet = 0.85 + 0.15 * abs(dot(N, normalize(vec3<f32>(0.3, 1.0, 0.2))));\n color = baseColor * facet;\n }\n\n // Selected objects and emphasized overlays draw fully opaque.\n var finalAlpha = select(input.color.a, 1.0, isSelected || emphasizedOverlay);\n\n // Specular (#5386; specular.wgsl.ts), after the diffuse above. Not\n // on the selection highlight or legacy overlay (it would wash out\n // their colours); a table override is composited without it below. The\n // sun lobe is scaled exactly like the diffuse sun term, and both\n // terms like irradiance, so a preset's highlights and diffuse move together.\n if (!isSelected && !isOverlay) {\n // Glass is an authored translucent material (mesh-material.ts\n // also gives it its smooth roughness). An X-Ray or compare fade\n // only lowers the alpha and stays a fade. Instanced occurrences\n // are never authored translucent: prepareInstancedRender routes\n // those to the flat path, so the per-pass lane is ignored there.\n let instancedPass = (uniforms.flags.x & 4u) != 0u;\n let translucent = finalAlpha < 0.99;\n let glass = translucent && uniforms.transmission.x > 0.5 && !instancedPass;\n // #5984: an instanced occurrence's own authored finish rides its\n // flags lane (instanced-render.ts packInstanceFinish); the pass's\n // uniform row is the shared default.\n var metallicRoughness = vec2<f32>(uniforms.metallicRoughness.x, uniforms.metallicRoughness.y);\n if (instancedPass && (input.instSelected & 4u) != 0u) {\n metallicRoughness.x = f32((input.instSelected >> 16u) & 255u) / 255.0;\n }\n if (instancedPass && (input.instSelected & 8u) != 0u) {\n metallicRoughness.y = f32((input.instSelected >> 24u) & 255u) / 255.0;\n }\n let metallic = clamp(metallicRoughness.x, 0.0, 1.0);\n let spec = surfaceSpecular(\n N,\n normalize(-input.eyePos),\n baseColor,\n metallic,\n metallicRoughness.y,\n env.sunColor * (env.sunIntensity * sunShadow),\n );\n // What the lobe reflects is not there to diffuse; a metal has no\n // diffuse at all.\n let diffuse = color * (1.0 - spec.reflectance) * (1.0 - metallic);\n let reflected = spec.light * (env.exposure * IRRADIANCE_CALIBRATION);\n if (translucent) {\n finalAlpha = finalAlpha * TRANSLUCENT_OPACITY_SCALE;\n }\n if (glass) {\n // The transparent pipelines blend straight alpha:\n // out = c * a + behind * (1 - a). A pane passes what is behind\n // it except what its body absorbs and its surface reflects, and\n // its reflection is not dimmed by the body's opacity, so solve\n // for (c, a). The reflectance rising at grazing angles is what\n // makes glass more opaque there; a bright sun glint raises the\n // alpha further so it is not clipped to the body's opacity.\n let body = finalAlpha;\n let reflectance = dot(spec.reflectance, vec3<f32>(0.299, 0.587, 0.114));\n let premultiplied = diffuse * body + reflected;\n let peak = max(premultiplied.r, max(premultiplied.g, premultiplied.b));\n finalAlpha = clamp(max(body + reflectance * (1.0 - body), peak), 0.0, 1.0);\n color = premultiplied / max(finalAlpha, 0.0001);\n } else {\n color = diffuse + reflected;\n }\n }\n\n // Hue-preserving highlight roll-off (color-transfer.wgsl.ts). No\n // contrast curve and no saturation boost: an authored colour lit at\n // unit irradiance leaves here unchanged unless it is brighter than\n // the roll-off threshold.\n color = neutralCompress(color);\n\n color = linearToSrgb(clamp(color, vec3<f32>(0.0), vec3<f32>(1.0)));\n\n var out: FragmentOutput;\n out.color = vec4<f32>(color, finalAlpha);\n // Colour override from the per-entity table (#6076): only draws the\n // renderer marks (overrideParams.y), i.e. depth-writing opaque ones.\n let entityOverride = entityOverrideColor(input.entityId);\n if (entityOverride.a >= 0.0 && !isSelected) {\n out.color = paintEntityOverride(out.color, entityOverride, irradiance, N);\n }\n out.objectIdEncoded = encodeId24(input.entityId);\n return out;\n }\n ";
2
2
  //# sourceMappingURL=main.wgsl.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"main.wgsl.d.ts","sourceRoot":"","sources":["../../src/shaders/main.wgsl.ts"],"names":[],"mappings":"AA4CA,eAAO,MAAM,gBAAgB,qq2CAsetB,CAAC"}
1
+ {"version":3,"file":"main.wgsl.d.ts","sourceRoot":"","sources":["../../src/shaders/main.wgsl.ts"],"names":[],"mappings":"AA4CA,eAAO,MAAM,gBAAgB,m84CA8etB,CAAC"}
@@ -83,6 +83,7 @@ export const mainShaderSource = `
83
83
  @location(0) worldPos: vec3<f32>,
84
84
  @location(1) normal: vec3<f32>,
85
85
  @location(2) @interpolate(flat) entityId: u32,
86
+ @location(9) @interpolate(flat) sectionEntityId: u32,
86
87
  // Per-draw albedo carried from the vertex stage so the fragment shader
87
88
  // is shared by the flat path (vs_main writes uniforms.baseColor — the
88
89
  // per-batch colour) AND the instanced path
@@ -100,6 +101,7 @@ export const mainShaderSource = `
100
101
  // intentionally separate from worldPos: shadow maps still consume
101
102
  // their established world-space light matrix until their depth pass
102
103
  // is migrated as one transaction.
104
+ @location(8) @interpolate(linear) geometricDepth: f32,
103
105
  @location(6) eyePos: vec3<f32>,
104
106
  }
105
107
 
@@ -160,10 +162,12 @@ export const mainShaderSource = `
160
162
  // Anti z-fighting depth nudge — see vs_main's comment.
161
163
  let colorSalt = (entityId >> 24u) * 2654435761u;
162
164
  let zHash = (((entityId & 0x00FFFFFFu) ^ colorSalt) * 2654435761u) & 255u;
165
+ output.geometricDepth = output.position.z / output.position.w;
163
166
  output.position.z = nudgedClipZ(output.position, zHash, uniforms.viewProj);
164
167
  output.worldPos = worldPos.xyz;
165
168
  output.normal = normalize((uniforms.model * vec4<f32>(localNormal, 0.0)).xyz);
166
169
  output.entityId = entityId;
170
+ output.sectionEntityId = sectionEntityFromLane(uniforms.overrideParams.x, entityId);
167
171
  output.color = uniforms.baseColor;
168
172
  output.instSelected = 0u;
169
173
  output.eyePos = eyePos;
@@ -200,10 +204,12 @@ export const mainShaderSource = `
200
204
  // batch. The step size per projection is in depth-nudge.wgsl.ts.
201
205
  let colorSalt = (input.entityId >> 24u) * 2654435761u;
202
206
  let zHash = (((input.entityId & 0x00FFFFFFu) ^ colorSalt) * 2654435761u) & 255u;
207
+ output.geometricDepth = output.position.z / output.position.w;
203
208
  output.position.z = nudgedClipZ(output.position, zHash, uniforms.viewProj);
204
209
  output.worldPos = worldPos.xyz;
205
210
  output.normal = normalize((uniforms.model * vec4<f32>(input.normal, 0.0)).xyz);
206
211
  output.entityId = input.entityId;
212
+ output.sectionEntityId = sectionEntityFromLane(uniforms.overrideParams.x, input.entityId);
207
213
  output.color = uniforms.baseColor;
208
214
  output.instSelected = 0u; // flat path selects via uniforms.flags.x
209
215
  output.eyePos = eyePos;
@@ -228,10 +234,12 @@ export const mainShaderSource = `
228
234
  // instanced path never redraws an occurrence with a second draw
229
235
  // colour, so the raw picking id is enough to separate coplanar entities.
230
236
  let zHash = ((inst.instEntityId & 0x00FFFFFFu) * 2654435761u) & 255u;
237
+ output.geometricDepth = output.position.z / output.position.w;
231
238
  output.position.z = nudgedClipZ(output.position, zHash, uniforms.viewProj);
232
239
  output.worldPos = worldPos.xyz;
233
240
  output.normal = normalize((instMat * vec4<f32>(input.normal, 0.0)).xyz);
234
241
  output.entityId = inst.instEntityId;
242
+ output.sectionEntityId = inst.instEntityId;
235
243
  output.color = inst.instColor;
236
244
  output.instSelected = inst.instSelected;
237
245
  output.eyePos = eyePos;
@@ -281,7 +289,7 @@ export const mainShaderSource = `
281
289
  }
282
290
  // Section plane / clip box (mesh-uniforms.wgsl.ts, shared with the
283
291
  // selection mask so an outline is cut where its surface is).
284
- if (sectionClipped(fragmentPos)) { discard; }
292
+ if (sectionClipped(fragmentPos, input.sectionEntityId)) { discard; }
285
293
 
286
294
  // Compute normal via derivative-based flat shading.
287
295
  //
@@ -1 +1 @@
1
- {"version":3,"file":"main.wgsl.js","sourceRoot":"","sources":["../../src/shaders/main.wgsl.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAE/D;;;;;;GAMG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD;;;;GAIG;AACH,MAAM,yBAAyB,GAAG,GAAG,CAAC;AAEtC;;;;;;;;;;;;;;;GAeG;AACH,MAAM,sBAAsB,GAAG,IAAI,CAAC;AAEpC,MAAM,CAAC,MAAM,gBAAgB,GAAG;UACtB,gBAAgB;UAChB,cAAc;UACd,iBAAiB;UACjB,WAAW;;;;;;;;;;;;;;;;;;;;;;8CAsByB,sBAAsB;iDACnB,yBAAyB;UAChE,iBAAiB;UACjB,YAAY;UACZ,oBAA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UACtB,gBAAgB;UAChB,cAAc;UACd,iBAAiB;UACjB,WAAW;;;;;;;;;;;;;;;;;;;;;;8CAsByB,sBAAsB;iDACnB,yBAAyB;UAChE,iBAAiB;UACjB,YAAY;UACZ,oBAAoB;;UAEpB,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8cjB,CAAC"}
@@ -1,2 +1,2 @@
1
- export declare const meshUniformsWgsl = "\n struct Uniforms {\n viewProj: mat4x4<f32>,\n model: mat4x4<f32>,\n baseColor: vec4<f32>,\n metallicRoughness: vec2<f32>, // x = metallic, y = roughness (mesh-material.ts)\n transmission: vec2<f32>, // x = 1: authored translucent, drawn as glass; y = pad\n sectionPlane: vec4<f32>, // xyz = plane normal, w = plane distance\n flags: vec4<u32>, // x = isSelected, y = section/clip bits; z, w unused (0) since #5746 dropped the derivative edges\n clipBoxMin: vec4<f32>, // xyz = clip-box min corner (world), w = pad\n clipBoxMax: vec4<f32>, // xyz = clip-box max corner (world), w = pad\n quantParams: vec4<f32>, // local min xyz, lattice step w\n rteViewProj: mat4x4<f32>, // appended frame; bit 16 selects it\n drawableDeltaHigh: vec4<f32>,\n drawableDeltaLow: vec4<f32>,\n rteCameraHigh: vec4<f32>,\n rteCameraLow: vec4<f32>,\n overrideParams: vec4<u32>, // x = draw's id anchor, y = OVERRIDE_* bits (entity-color-table.ts, #6076)\n }\n @binding(0) @group(0) var<uniform> uniforms: Uniforms;\n const RTE_DRAWABLE_FLAG: u32 = 65536u;\n\n // The fragment position the section/crop tests run in: camera-relative\n // for RTE drawables (the packer writes plane and box in that frame),\n // world space otherwise.\n fn clipSpacePos(worldPos: vec3<f32>, eyePos: vec3<f32>) -> vec3<f32> {\n return select(worldPos, eyePos, (uniforms.flags.x & RTE_DRAWABLE_FLAG) != 0u);\n }\n\n // True when p is cut away: ABOVE the section plane (flags.y bit 0 =\n // enabled, bit 1 = flipped) or OUTSIDE the clip box (bit 2).\n fn sectionClipped(p: vec3<f32>) -> bool {\n if ((uniforms.flags.y & 1u) == 1u) {\n let side = select(1.0, -1.0, (uniforms.flags.y & 2u) == 2u);\n if ((dot(p, uniforms.sectionPlane.xyz) - uniforms.sectionPlane.w) * side > 0.0) { return true; }\n }\n if ((uniforms.flags.y & 4u) != 0u) {\n if (any(p < uniforms.clipBoxMin.xyz) || any(p > uniforms.clipBoxMax.xyz)) { return true; }\n }\n return false;\n }\n";
1
+ export declare const meshUniformsWgsl = "\n \n struct ExtraClip {\n planeInfo: vec4<u32>, // x = plane count, y = flipped bit mask\n planes: array<vec4<f32>, 7>, // xyz = normal, w = distance\n }\n\n // True when p is on the removed side of ANY extra plane.\n fn extraClipClipped(clip: ExtraClip, p: vec3<f32>) -> bool {\n for (var i = 0u; i < clip.planeInfo.x; i = i + 1u) {\n let side = select(1.0, -1.0, ((clip.planeInfo.y >> i) & 1u) == 1u);\n if ((dot(p, clip.planes[i].xyz) - clip.planes[i].w) * side > 0.0) { return true; }\n }\n return false;\n }\n\n \n@group(3) @binding(0) var<storage, read> sectionExcludedIds: array<u32>;\n// Scene colour buckets are partitioned by 2^24 ID page. Reject an invalid anchor.\nfn sectionEntityFromLane(anchor: u32, lane: u32) -> u32 {\n return select(anchor + ((lane - anchor) & 0x00FFFFFFu), 0xFFFFFFFFu, anchor == 0xFFFFFFFFu);\n}\nfn sectionExcluded(id: u32) -> bool {\n var lo = 0u;\n var hi = sectionExcludedIds[0];\n while (lo < hi) {\n let mid = lo + (hi - lo) / 2u;\n let key = sectionExcludedIds[mid + 1u];\n if (key == id) { return true; }\n if (key < id) { lo = mid + 1u; } else { hi = mid; }\n }\n return false;\n}\n\n struct Uniforms {\n viewProj: mat4x4<f32>,\n model: mat4x4<f32>,\n baseColor: vec4<f32>,\n metallicRoughness: vec2<f32>, // x = metallic, y = roughness (mesh-material.ts)\n transmission: vec2<f32>, // x = 1: authored translucent, drawn as glass; y = pad\n sectionPlane: vec4<f32>, // xyz = plane normal, w = plane distance\n flags: vec4<u32>, // x = isSelected, y = section/clip bits; z, w unused (0) since #5746 dropped the derivative edges\n clipBoxMin: vec4<f32>, // xyz = clip-box min corner (world), w = pad\n clipBoxMax: vec4<f32>, // xyz = clip-box max corner (world), w = pad\n quantParams: vec4<f32>, // local min xyz, lattice step w\n rteViewProj: mat4x4<f32>, // appended frame; bit 16 selects it\n drawableDeltaHigh: vec4<f32>,\n drawableDeltaLow: vec4<f32>,\n rteCameraHigh: vec4<f32>,\n rteCameraLow: vec4<f32>,\n overrideParams: vec4<u32>, // x = draw's id anchor, y = OVERRIDE_* bits (entity-color-table.ts, #6076)\n extraClip: ExtraClip, // cutting planes beyond sectionPlane (#7545); count 0 = none\n }\n @binding(0) @group(0) var<uniform> uniforms: Uniforms;\n const RTE_DRAWABLE_FLAG: u32 = 65536u;\n\n // The fragment position the section/crop tests run in: camera-relative\n // for RTE drawables (the packer writes plane and box in that frame),\n // world space otherwise.\n fn clipSpacePos(worldPos: vec3<f32>, eyePos: vec3<f32>) -> vec3<f32> {\n return select(worldPos, eyePos, (uniforms.flags.x & RTE_DRAWABLE_FLAG) != 0u);\n }\n\n // True when p is cut away: ABOVE the section plane (flags.y bit 0 =\n // enabled, bit 1 = flipped), on the removed side of any extra plane\n // (extraClip, #7545) or OUTSIDE the clip box (bit 2).\n fn sectionClipped(p: vec3<f32>, id: u32) -> bool {\n let excluded = sectionExcluded(id);\n if (!excluded && (uniforms.flags.y & 1u) == 1u) {\n let side = select(1.0, -1.0, (uniforms.flags.y & 2u) == 2u);\n if ((dot(p, uniforms.sectionPlane.xyz) - uniforms.sectionPlane.w) * side > 0.0) { return true; }\n }\n if (!excluded && extraClipClipped(uniforms.extraClip, p)) { return true; }\n if ((uniforms.flags.y & 4u) != 0u) {\n if (any(p < uniforms.clipBoxMin.xyz) || any(p > uniforms.clipBoxMax.xyz)) { return true; }\n }\n return false;\n }\n";
2
2
  //# sourceMappingURL=mesh-uniforms.wgsl.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mesh-uniforms.wgsl.d.ts","sourceRoot":"","sources":["../../src/shaders/mesh-uniforms.wgsl.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,gBAAgB,ouEAyC5B,CAAC"}
1
+ {"version":3,"file":"mesh-uniforms.wgsl.d.ts","sourceRoot":"","sources":["../../src/shaders/mesh-uniforms.wgsl.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,gBAAgB,oyHA+C5B,CAAC"}
@@ -8,7 +8,11 @@
8
8
  * surface it traces is. Packing: `mesh-rte-uniforms.ts` / `index.ts`.
9
9
  */
10
10
  import { MESH_FLAG_RTE_DRAWABLE } from '../mesh-rte-uniforms.js';
11
+ import { sectionExclusionsWgsl } from '../section-exclusions.js';
12
+ import { extraClipWgsl } from '../extra-clip-planes.js';
11
13
  export const meshUniformsWgsl = `
14
+ ${extraClipWgsl}
15
+ ${sectionExclusionsWgsl}
12
16
  struct Uniforms {
13
17
  viewProj: mat4x4<f32>,
14
18
  model: mat4x4<f32>,
@@ -26,6 +30,7 @@ export const meshUniformsWgsl = `
26
30
  rteCameraHigh: vec4<f32>,
27
31
  rteCameraLow: vec4<f32>,
28
32
  overrideParams: vec4<u32>, // x = draw's id anchor, y = OVERRIDE_* bits (entity-color-table.ts, #6076)
33
+ extraClip: ExtraClip, // cutting planes beyond sectionPlane (#7545); count 0 = none
29
34
  }
30
35
  @binding(0) @group(0) var<uniform> uniforms: Uniforms;
31
36
  const RTE_DRAWABLE_FLAG: u32 = ${MESH_FLAG_RTE_DRAWABLE}u;
@@ -38,12 +43,15 @@ export const meshUniformsWgsl = `
38
43
  }
39
44
 
40
45
  // True when p is cut away: ABOVE the section plane (flags.y bit 0 =
41
- // enabled, bit 1 = flipped) or OUTSIDE the clip box (bit 2).
42
- fn sectionClipped(p: vec3<f32>) -> bool {
43
- if ((uniforms.flags.y & 1u) == 1u) {
46
+ // enabled, bit 1 = flipped), on the removed side of any extra plane
47
+ // (extraClip, #7545) or OUTSIDE the clip box (bit 2).
48
+ fn sectionClipped(p: vec3<f32>, id: u32) -> bool {
49
+ let excluded = sectionExcluded(id);
50
+ if (!excluded && (uniforms.flags.y & 1u) == 1u) {
44
51
  let side = select(1.0, -1.0, (uniforms.flags.y & 2u) == 2u);
45
52
  if ((dot(p, uniforms.sectionPlane.xyz) - uniforms.sectionPlane.w) * side > 0.0) { return true; }
46
53
  }
54
+ if (!excluded && extraClipClipped(uniforms.extraClip, p)) { return true; }
47
55
  if ((uniforms.flags.y & 4u) != 0u) {
48
56
  if (any(p < uniforms.clipBoxMin.xyz) || any(p > uniforms.clipBoxMax.xyz)) { return true; }
49
57
  }
@@ -1 +1 @@
1
- {"version":3,"file":"mesh-uniforms.wgsl.js","sourceRoot":"","sources":["../../src/shaders/mesh-uniforms.wgsl.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAE/D;;;;;GAKG;AACH,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAEjE,MAAM,CAAC,MAAM,gBAAgB,GAAG;;;;;;;;;;;;;;;;;;;;yCAoBS,sBAAsB;;;;;;;;;;;;;;;;;;;;;CAqB9D,CAAC"}
1
+ {"version":3,"file":"mesh-uniforms.wgsl.js","sourceRoot":"","sources":["../../src/shaders/mesh-uniforms.wgsl.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAE/D;;;;;GAKG;AACH,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,MAAM,CAAC,MAAM,gBAAgB,GAAG;UACtB,aAAa;UACb,qBAAqB;;;;;;;;;;;;;;;;;;;;;yCAqBU,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;CAwB9D,CAAC"}
@@ -0,0 +1,11 @@
1
+ /** Bind after mesh and environment/hover groups. Shared by colour and masks. */
2
+ export declare const OPAQUE_VISIBILITY_GROUP = 2;
3
+ /** Numerical coincidence allowance, independent of the entity's hash rank. */
4
+ export declare const OPAQUE_VISIBILITY_ULPS = 4;
5
+ /** depth32float permits interpolation roundoff, independent of the hash rank. */
6
+ export declare function opaqueVisibilityWgsl(samples: number): string;
7
+ /** Same transformations and fragment discards, without entity displacement. */
8
+ export declare function unbiasedMeshShader(source: string, samples: number, entryPoint?: string): string;
9
+ /** Guard an actual colour fragment; keep its clipping, texture and opacity rules. */
10
+ export declare function guardedMeshShader(source: string, samples: number, entryPoint?: string): string;
11
+ //# sourceMappingURL=opaque-visibility.wgsl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opaque-visibility.wgsl.d.ts","sourceRoot":"","sources":["../../src/shaders/opaque-visibility.wgsl.ts"],"names":[],"mappings":"AAKA,gFAAgF;AAChF,eAAO,MAAM,uBAAuB,IAAI,CAAC;AAEzC,8EAA8E;AAC9E,eAAO,MAAM,sBAAsB,IAAI,CAAC;AAExC,iFAAiF;AACjF,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAU5D;AAED,+EAA+E;AAC/E,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,SAAY,GAAG,MAAM,CAoBlG;AAED,qFAAqF;AACrF,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,SAAY,GAAG,MAAM,CAQjG"}