@driftengine/core 4.8.5 → 4.8.7

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 (214) hide show
  1. package/CHANGELOG.json +4392 -4250
  2. package/README.md +1 -1
  3. package/dist/index.d.ts +12 -4
  4. package/dist/index.js +12 -2
  5. package/dist/render/ambientHarmonics.d.ts +46 -0
  6. package/dist/render/ambientHarmonics.js +80 -0
  7. package/dist/render/anisotropicLobe.d.ts +10 -0
  8. package/dist/render/anisotropicLobe.js +19 -0
  9. package/dist/render/areaLights.d.ts +54 -0
  10. package/dist/render/areaLights.js +55 -0
  11. package/dist/render/backend/api.d.ts +43 -2
  12. package/dist/render/backend/webgl2/instanced.d.ts +2 -0
  13. package/dist/render/backend/webgl2/instanced.js +11 -2
  14. package/dist/render/backend/webgl2/renderer.d.ts +120 -11
  15. package/dist/render/backend/webgl2/renderer.js +356 -53
  16. package/dist/render/backend/webgl2/sceneCaptureTarget.d.ts +29 -0
  17. package/dist/render/backend/webgl2/sceneCaptureTarget.js +96 -0
  18. package/dist/render/backend/webgl2/skinScatter.d.ts +14 -0
  19. package/dist/render/backend/webgl2/skinScatter.js +88 -26
  20. package/dist/render/backend/webgpu/buffers.js +2 -1
  21. package/dist/render/backend/webgpu/clusterBinner.js +3 -2
  22. package/dist/render/backend/webgpu/flatPass.d.ts +7 -5
  23. package/dist/render/backend/webgpu/flatPass.js +15 -13
  24. package/dist/render/backend/webgpu/particlePass.d.ts +37 -4
  25. package/dist/render/backend/webgpu/particlePass.js +81 -12
  26. package/dist/render/backend/webgpu/postPass.d.ts +6 -1
  27. package/dist/render/backend/webgpu/postPass.js +7 -2
  28. package/dist/render/backend/webgpu/renderer.d.ts +93 -8
  29. package/dist/render/backend/webgpu/renderer.js +483 -93
  30. package/dist/render/backend/webgpu/sceneCaptureTarget.d.ts +24 -0
  31. package/dist/render/backend/webgpu/sceneCaptureTarget.js +59 -0
  32. package/dist/render/backend/webgpu/shaders/clusterBin.wgsl.d.ts +1 -1
  33. package/dist/render/backend/webgpu/shaders/clusterBin.wgsl.js +41 -1
  34. package/dist/render/backend/webgpu/skinPaletteRing.d.ts +40 -28
  35. package/dist/render/backend/webgpu/skinPaletteRing.js +69 -32
  36. package/dist/render/backend/webgpu/skinScatterPass.d.ts +10 -2
  37. package/dist/render/backend/webgpu/skinScatterPass.js +59 -9
  38. package/dist/render/backend/webgpu/surfaceTexturePass.d.ts +5 -1
  39. package/dist/render/backend/webgpu/surfaceTexturePass.js +45 -5
  40. package/dist/render/backend/webgpu/waterPass.d.ts +1 -1
  41. package/dist/render/bloomChain.d.ts +44 -0
  42. package/dist/render/bloomChain.js +28 -0
  43. package/dist/render/bloomPass.d.ts +3 -1
  44. package/dist/render/bloomPass.js +16 -2
  45. package/dist/render/clusteredLights.d.ts +78 -6
  46. package/dist/render/clusteredLights.js +214 -13
  47. package/dist/render/driftLight/bake.d.ts +2 -0
  48. package/dist/render/driftLight/bake.js +1 -1
  49. package/dist/render/driftLight/falloff.d.ts +4 -2
  50. package/dist/render/driftLight/falloff.js +8 -2
  51. package/dist/render/fixtureAtlas.js +1 -1
  52. package/dist/render/gi/bounceLights.d.ts +3 -2
  53. package/dist/render/gi/bounceLights.js +8 -3
  54. package/dist/render/instanceCull.js +12 -0
  55. package/dist/render/instances.d.ts +47 -11
  56. package/dist/render/instances.js +24 -9
  57. package/dist/render/lightBudget.d.ts +38 -2
  58. package/dist/render/lightBudget.js +48 -5
  59. package/dist/render/lightmap.d.ts +116 -0
  60. package/dist/render/lightmap.js +140 -0
  61. package/dist/render/mesh.js +2 -1
  62. package/dist/render/particleBatch.d.ts +59 -3
  63. package/dist/render/particleBatch.js +53 -2
  64. package/dist/render/particleMaterial.d.ts +6 -1
  65. package/dist/render/particleMaterial.js +10 -2
  66. package/dist/render/particlePool.d.ts +32 -0
  67. package/dist/render/particlePool.js +9 -0
  68. package/dist/render/particleSort.d.ts +34 -0
  69. package/dist/render/particleSort.js +96 -0
  70. package/dist/render/pointLightSelection.d.ts +13 -0
  71. package/dist/render/pointLightSelection.js +3 -1
  72. package/dist/render/renderQuality.d.ts +8 -7
  73. package/dist/render/rendererHarness.js +3 -0
  74. package/dist/render/rgb9e5.d.ts +22 -0
  75. package/dist/render/rgb9e5.js +47 -0
  76. package/dist/render/sceneCapture.d.ts +29 -0
  77. package/dist/render/sceneCapture.js +36 -0
  78. package/dist/render/sceneTarget.d.ts +5 -0
  79. package/dist/render/sceneTarget.js +8 -1
  80. package/dist/render/screenSpaceReflection.d.ts +27 -1
  81. package/dist/render/screenSpaceReflection.js +9 -0
  82. package/dist/render/shaders/bloom.d.ts +8 -4
  83. package/dist/render/shaders/bloom.js +20 -3
  84. package/dist/render/shaders/bolt.d.ts +1 -1
  85. package/dist/render/shaders/bolt.js +7 -1
  86. package/dist/render/shaders/depth.js +11 -0
  87. package/dist/render/shaders/flat/anisotropic.d.ts +1 -1
  88. package/dist/render/shaders/flat/anisotropic.js +37 -3
  89. package/dist/render/shaders/flat/areaLight.d.ts +10 -0
  90. package/dist/render/shaders/flat/areaLight.js +142 -0
  91. package/dist/render/shaders/flat/glassTint.d.ts +3 -2
  92. package/dist/render/shaders/flat/glassTint.js +3 -1
  93. package/dist/render/shaders/flat/index.d.ts +5 -0
  94. package/dist/render/shaders/flat/index.js +46 -6
  95. package/dist/render/shaders/flat/lobes.d.ts +6 -0
  96. package/dist/render/shaders/flat/lobes.js +49 -43
  97. package/dist/render/shaders/flat/main.d.ts +1 -1
  98. package/dist/render/shaders/flat/main.js +158 -121
  99. package/dist/render/shaders/flat/models.d.ts +21 -6
  100. package/dist/render/shaders/flat/models.js +161 -17
  101. package/dist/render/shaders/flat/normalMap.d.ts +10 -0
  102. package/dist/render/shaders/flat/normalMap.js +25 -0
  103. package/dist/render/shaders/flat/preamble.js +84 -40
  104. package/dist/render/shaders/flat/skin.js +6 -5
  105. package/dist/render/shaders/generated/bloom.wgsl.d.ts +13 -3
  106. package/dist/render/shaders/generated/bloom.wgsl.js +13 -3
  107. package/dist/render/shaders/generated/bolt.wgsl.d.ts +1 -1
  108. package/dist/render/shaders/generated/bolt.wgsl.js +1 -1
  109. package/dist/render/shaders/generated/depth.wgsl.d.ts +4 -4
  110. package/dist/render/shaders/generated/depth.wgsl.js +4 -4
  111. package/dist/render/shaders/generated/flat.wgsl.d.ts +1647 -2044
  112. package/dist/render/shaders/generated/flat.wgsl.js +1685 -2082
  113. package/dist/render/shaders/generated/particle.wgsl.d.ts +115 -1
  114. package/dist/render/shaders/generated/particle.wgsl.js +115 -1
  115. package/dist/render/shaders/generated/skinBlur.wgsl.d.ts +12 -2
  116. package/dist/render/shaders/generated/skinBlur.wgsl.js +12 -2
  117. package/dist/render/shaders/generated/ssrTrace.wgsl.d.ts +11 -6
  118. package/dist/render/shaders/generated/ssrTrace.wgsl.js +11 -6
  119. package/dist/render/shaders/generated/water.wgsl.d.ts +23 -16
  120. package/dist/render/shaders/generated/water.wgsl.js +23 -16
  121. package/dist/render/shaders/gi/probeBake.wgsl.js +9 -5
  122. package/dist/render/shaders/particle.d.ts +17 -1
  123. package/dist/render/shaders/particle.js +133 -1
  124. package/dist/render/shaders/recon/motion.wgsl.d.ts +1 -1
  125. package/dist/render/shaders/recon/motion.wgsl.js +13 -2
  126. package/dist/render/shaders/skinBlur.js +25 -3
  127. package/dist/render/shaders/ssrTrace.js +20 -1
  128. package/dist/render/shaders/water.d.ts +1 -1
  129. package/dist/render/shaders/water.js +12 -3
  130. package/dist/render/skinBlur.d.ts +8 -5
  131. package/dist/render/skinBlur.js +8 -5
  132. package/dist/render/skinScatter.d.ts +3 -1
  133. package/dist/render/skinScatter.js +3 -1
  134. package/dist/render/ssrPass.js +1 -0
  135. package/dist/render/surfaceModel.d.ts +49 -8
  136. package/dist/render/surfaceModel.js +54 -8
  137. package/dist/render/surfaceTexture.d.ts +38 -1
  138. package/dist/render/surfaceTexture.js +37 -2
  139. package/package.json +6 -6
  140. package/src/index.ts +26 -3
  141. package/src/render/ambientHarmonics.ts +92 -0
  142. package/src/render/anisotropicLobe.ts +29 -0
  143. package/src/render/areaLights.ts +97 -0
  144. package/src/render/backend/api.ts +61 -1
  145. package/src/render/backend/webgl2/instanced.ts +12 -2
  146. package/src/render/backend/webgl2/renderer.ts +470 -59
  147. package/src/render/backend/webgl2/sceneCaptureTarget.ts +130 -0
  148. package/src/render/backend/webgl2/skinScatter.ts +120 -43
  149. package/src/render/backend/webgpu/buffers.ts +2 -1
  150. package/src/render/backend/webgpu/clusterBinner.ts +3 -1
  151. package/src/render/backend/webgpu/flatPass.ts +18 -13
  152. package/src/render/backend/webgpu/particlePass.ts +119 -12
  153. package/src/render/backend/webgpu/postPass.ts +7 -2
  154. package/src/render/backend/webgpu/renderer.ts +589 -113
  155. package/src/render/backend/webgpu/sceneCaptureTarget.ts +63 -0
  156. package/src/render/backend/webgpu/shaders/clusterBin.wgsl.ts +41 -1
  157. package/src/render/backend/webgpu/skinPaletteRing.ts +65 -33
  158. package/src/render/backend/webgpu/skinScatterPass.ts +59 -9
  159. package/src/render/backend/webgpu/surfaceTexturePass.ts +57 -6
  160. package/src/render/bloomChain.ts +69 -0
  161. package/src/render/bloomPass.ts +26 -2
  162. package/src/render/clusteredLights.ts +259 -12
  163. package/src/render/driftLight/bake.ts +3 -1
  164. package/src/render/driftLight/falloff.ts +13 -2
  165. package/src/render/fixtureAtlas.ts +1 -1
  166. package/src/render/gi/bounceLights.ts +12 -3
  167. package/src/render/instanceCull.ts +9 -0
  168. package/src/render/instances.ts +61 -12
  169. package/src/render/lightBudget.ts +88 -4
  170. package/src/render/lightmap.ts +243 -0
  171. package/src/render/mesh.ts +2 -1
  172. package/src/render/particleBatch.ts +95 -4
  173. package/src/render/particleMaterial.ts +11 -1
  174. package/src/render/particlePool.ts +36 -0
  175. package/src/render/particleSort.ts +133 -0
  176. package/src/render/pointLightSelection.ts +20 -1
  177. package/src/render/renderQuality.ts +8 -7
  178. package/src/render/rendererHarness.ts +3 -0
  179. package/src/render/rgb9e5.ts +52 -0
  180. package/src/render/sceneCapture.ts +56 -0
  181. package/src/render/sceneTarget.ts +18 -1
  182. package/src/render/screenSpaceReflection.ts +33 -1
  183. package/src/render/shaders/bloom.ts +20 -3
  184. package/src/render/shaders/bolt.ts +7 -1
  185. package/src/render/shaders/depth.ts +11 -0
  186. package/src/render/shaders/flat/anisotropic.ts +37 -3
  187. package/src/render/shaders/flat/areaLight.ts +142 -0
  188. package/src/render/shaders/flat/glassTint.ts +9 -2
  189. package/src/render/shaders/flat/index.ts +51 -6
  190. package/src/render/shaders/flat/lobes.ts +50 -43
  191. package/src/render/shaders/flat/main.ts +158 -121
  192. package/src/render/shaders/flat/models.ts +170 -21
  193. package/src/render/shaders/flat/normalMap.ts +25 -0
  194. package/src/render/shaders/flat/preamble.ts +84 -40
  195. package/src/render/shaders/flat/skin.ts +6 -5
  196. package/src/render/shaders/generated/bloom.wgsl.ts +13 -3
  197. package/src/render/shaders/generated/bolt.wgsl.ts +1 -1
  198. package/src/render/shaders/generated/depth.wgsl.ts +4 -4
  199. package/src/render/shaders/generated/flat.wgsl.ts +1685 -2082
  200. package/src/render/shaders/generated/particle.wgsl.ts +116 -1
  201. package/src/render/shaders/generated/skinBlur.wgsl.ts +12 -2
  202. package/src/render/shaders/generated/ssrTrace.wgsl.ts +11 -6
  203. package/src/render/shaders/generated/water.wgsl.ts +23 -16
  204. package/src/render/shaders/gi/probeBake.wgsl.ts +9 -5
  205. package/src/render/shaders/particle.ts +134 -1
  206. package/src/render/shaders/recon/motion.wgsl.ts +13 -2
  207. package/src/render/shaders/skinBlur.ts +25 -3
  208. package/src/render/shaders/ssrTrace.ts +20 -1
  209. package/src/render/shaders/water.ts +12 -3
  210. package/src/render/skinBlur.ts +8 -5
  211. package/src/render/skinScatter.ts +3 -1
  212. package/src/render/ssrPass.ts +1 -0
  213. package/src/render/surfaceModel.ts +82 -10
  214. package/src/render/surfaceTexture.ts +101 -3
@@ -148,6 +148,12 @@ export const MAIN_GLSL = `void main() {
148
148
  float glassTransmission = uSeeThrough.z;
149
149
  float glassFrost = uSeeThrough.w;
150
150
 
151
+ /*
152
+ * The normal a refracting draw bends by: the shading normal, a normal map's tilt and every relief
153
+ * in it, as the lit block leaves it before turning a back face — the geometric normal where
154
+ * nothing tilts it, which is what refraction bent by before 4.8.6. See the refraction below.
155
+ */
156
+ vec3 shadingNormal = normalize(vNormal);
151
157
  if (uLightingEnabled != 0) {
152
158
  vec3 n = normalize(vNormal);
153
159
  /*
@@ -181,20 +187,7 @@ export const MAIN_GLSL = `void main() {
181
187
  * right: a mipped colour image, sampled under uniform control flow, exactly as uAlbedo is
182
188
  * below. The rule is about non-uniform branches, and this branch is on a uniform.
183
189
  */
184
- if (uNormalStrength > 0.0) {
185
- vec3 mapped = texture(uNormalMap, surfaceAt).xyz * 2.0 - 1.0;
186
- /*
187
- * z rebuilt where none is stored. A tangent-space normal points out of its surface, so a
188
- * stored z at or below zero is never a real one: it is a two-channel map, BC5, whose blue a
189
- * device samples as zero and which arrives here as -1. Every map baked from BC5 to PNG before
190
- * 4.8.4 carried the same zero. A select rather than a flag: no uniform to bind, no material
191
- * that has to say what format it holds, and continuous at the boundary, since a unit texel
192
- * lying flat has its z near zero either way. A texel with z above zero is left as it was.
193
- */
194
- mapped.z = mapped.z > 0.0 ? mapped.z : sqrt(max(0.0, 1.0 - dot(mapped.xy, mapped.xy)));
195
- mat3 tbn = tangentFrame(n, vWorldPos, vUv.xy, vTangent, vHasTangents);
196
- n = normalize(mix(n, normalize(tbn * mapped), uNormalStrength));
197
- }
190
+ if (uNormalStrength > 0.0) n = normalMapped(n, surfaceAt);
198
191
 
199
192
  /*
200
193
  * Microscopic relief: the surface's own texture, as a turn of the normal rather than a change
@@ -218,7 +211,8 @@ export const MAIN_GLSL = `void main() {
218
211
  * widening driven by fwidth was measured making that artefact three times worse, because that
219
212
  * derivative spikes at every hard crease. See docs/IMPROVEMENTS.md.
220
213
  */
221
- float reliefAmount = uRelief * vRelief;
214
+ /* Never below zero: a lightmapped mesh's coordinates ride this lane below it. See lightmap.ts. */
215
+ float reliefAmount = uRelief.x * max(vRelief, 0.0);
222
216
  /* Grown with the relief, before anything reads it. See the comment above: a normal that
223
217
  wanders cannot hold a highlight narrower than the wander. */
224
218
  /*
@@ -259,11 +253,11 @@ export const MAIN_GLSL = `void main() {
259
253
  * variance is still roughness — a road that faded to smooth at distance would go glossy
260
254
  * instead of noisy, which is a worse artefact wearing better clothes.
261
255
  */
262
- vec3 reliefPixel = fwidth(vWorldPos) * uReliefCycles;
256
+ vec3 reliefPixel = fwidth(vWorldPos) * uRelief.y;
263
257
  float reliefFootprint = max(max(reliefPixel.x, reliefPixel.y), reliefPixel.z);
264
258
  float reliefResolved = reliefAmount * (1.0 - smoothstep(0.5, 1.5, reliefFootprint));
265
259
  if (reliefResolved > 0.0) {
266
- vec3 at = vWorldPos * uReliefCycles;
260
+ vec3 at = vWorldPos * uRelief.y;
267
261
  /* One cell of the noise, which is one bump: the gradient over any smaller step is the
268
262
  interpolant's own slope rather than the shape's. */
269
263
  float here = grain(at);
@@ -360,6 +354,7 @@ export const MAIN_GLSL = `void main() {
360
354
  * Turning only the interpolated normal would leave a normal map's tilt pointing the wrong way
361
355
  * across the fold of every curtain.
362
356
  */
357
+ shadingNormal = n;
363
358
  if (backFace) n = -n;
364
359
  /*
365
360
  * A model's surface, gathered once, on a branch on the switches alone (models.ts) — and whether
@@ -369,6 +364,14 @@ export const MAIN_GLSL = `void main() {
369
364
  bool modelled = modelOn();
370
365
  bool modelledBehind = modelSeesBehind();
371
366
  if (modelled) modelSurface(n, albedo, surfaceRoughness, metal, surfaceAt);
367
+ /*
368
+ * Skin's colour half leaves here, with the colour its spread light is multiplied by, and a whole
369
+ * alpha a multisampled edge resolves to its coverage. A branch on the switches alone, so uniform.
370
+ */
371
+ if (modelAlbedoAlone()) {
372
+ outColor = vec4(albedo, 1.0);
373
+ return;
374
+ }
372
375
 
373
376
  /*
374
377
  * One dot product, used twice: ndl is the lit side and its negative is the night side below.
@@ -468,6 +471,8 @@ export const MAIN_GLSL = `void main() {
468
471
  irradiance = mix(irradiance, ambient, probeGridOutside(surfaceN, vWorldPos));
469
472
  ambient = mix(ambient, irradiance, uProbeGridAmbient * uEnvironmentEnabled);
470
473
  #endif
474
+ /* A draw's own ambient, where one is set, in place of the frame's: \`setAmbientSH\`. */
475
+ if (uAmbientSH[6].w > 0.5) ambient = ambientHarmonics(n);
471
476
  /*
472
477
  * A metal keeps its ambient and loses its direct diffuse.
473
478
  *
@@ -495,6 +500,8 @@ export const MAIN_GLSL = `void main() {
495
500
  } else {
496
501
  lit = albedo * (ambient + sunColor * direct * (1.0 - metal));
497
502
  }
503
+ /* A baked page's light, beside the sky's and the sun's: nothing but where a material has one. */
504
+ lit += modelBaked(n, albedo, metal);
498
505
 
499
506
  /*
500
507
  * A sun highlight, for the few surfaces that ask for one.
@@ -536,7 +543,7 @@ export const MAIN_GLSL = `void main() {
536
543
  * specularLobe's header argues for at length.
537
544
  */
538
545
  float sunVoH = max(dot(normalize(uCameraPos - vWorldPos), halfway), 0.0);
539
- vec3 sunSpec = mix(specColor, vec3(1.0), pow(1.0 - sunVoH, 5.0) * metal);
546
+ vec3 sunSpec = highlightTint(specColor, sunVoH, metal);
540
547
  /*
541
548
  * **Held back until after the environment blend, because that blend is a mix and would
542
549
  * otherwise erase this.**
@@ -555,8 +562,12 @@ export const MAIN_GLSL = `void main() {
555
562
  * Zero for the whole world that carries no specular attribute and no metalness, exactly as
556
563
  * before: \`sunSpec\` is \`vec3(vSpecular)\` at metal 0 and \`vSpecular\` defaults to 0.
557
564
  */
558
- vec3 sunHighlight =
559
- sunColor * specularLobe(max(dot(n, halfway), 0.0), surfaceRoughness) * sunSpec * sunShade * sunFacing;
565
+ /* GGX's own where the surface asks (\`physicalSpecular\`): the sun is a point, so nothing widens it. */
566
+ float sunNdh = max(dot(n, halfway), 0.0);
567
+ float sunLobe = physicalSpecular()
568
+ ? physicalLobe(sunNdh, ndl, dot(n, normalize(uCameraPos - vWorldPos)), surfaceRoughness, 0.0, 1.0)
569
+ : specularLobe(sunNdh, surfaceRoughness);
570
+ vec3 sunHighlight = sunColor * sunLobe * sunSpec * sunShade * sunFacing;
560
571
  if (modelled) sunHighlight = sunModelSpecular;
561
572
  /*
562
573
  * The dielectric's share goes in here, where it has always gone, so the environment blend
@@ -640,7 +651,7 @@ export const MAIN_GLSL = `void main() {
640
651
  */
641
652
  /* A model reflects its environment whatever the pass asked of the standard model: see
642
653
  modelReflectance. On the switches alone, so the derivatives below stay in uniform flow. */
643
- if (uReflectivity > 0.0 || uMaterialFlags.y != 0 || modelled) {
654
+ if (uEnvironmentDials.y > 0.0 || uMaterialFlags.y != 0 || modelled) {
644
655
  vec3 toEye = normalize(uCameraPos - vWorldPos);
645
656
  vec3 mirrored = reflect(-toEye, modelled ? modelReflectNormal(n) : n);
646
657
  vec3 environment = mix(uAmbientGround, uAmbient, mirrored.y * 0.5 + 0.5);
@@ -741,7 +752,7 @@ export const MAIN_GLSL = `void main() {
741
752
  float footprintRough = 0.5 * sqrt(min(swingRad, 1.0));
742
753
  float lobeRough = min(1.0, sqrt(surfaceRoughness * surfaceRoughness + footprintRough * footprintRough));
743
754
  float envLod = clamp(
744
- mix(boxLod, lobeRough * uEnvironmentMaxLod, uEnvironmentPrefiltered),
755
+ mix(boxLod, lobeRough * uEnvironmentMaxLod, uEnvironmentDials.x),
745
756
  0.0,
746
757
  uEnvironmentMaxLod
747
758
  );
@@ -777,7 +788,7 @@ export const MAIN_GLSL = `void main() {
777
788
  * \`mix(1, gain, 0)\` is exactly 1, so a dielectric is arithmetically untouched however the
778
789
  * caller sets this.
779
790
  */
780
- environment *= mix(1.0, uEnvironmentGain, metal);
791
+ environment *= mix(1.0, uEnvironmentDials.z, metal);
781
792
  float facing = 1.0 - max(dot(n, toEye), 0.0);
782
793
  /*
783
794
  * **A metal's Fresnel base is close to its albedo, not a dielectric's four percent.** Schlick
@@ -811,7 +822,7 @@ export const MAIN_GLSL = `void main() {
811
822
  * which is what the old \`max(uReflectivity, metal) * (1 - r)\` came to, and both renderers
812
823
  * clamp that uniform non-negative on upload.
813
824
  */
814
- float reflectAmount = max(uReflectivity * (1.0 - surfaceRoughness), metal);
825
+ float reflectAmount = max(uEnvironmentDials.y * (1.0 - surfaceRoughness), metal);
815
826
  /*
816
827
  * **With a prefiltered environment, how much a surface returns is an integral rather than a
817
828
  * curve somebody chose**, and this is where the comment above said the thinning should go
@@ -881,7 +892,7 @@ export const MAIN_GLSL = `void main() {
881
892
  */
882
893
  #if ENVIRONMENT_PROBE
883
894
  vec2 dfg = envBrdfApprox(ndv, surfaceRoughness);
884
- float integrated = clamp(envSpecularEnergy(f0, dfg) * max(uReflectivity, metal), 0.0, 1.0);
895
+ float integrated = clamp(envSpecularEnergy(f0, dfg) * max(uEnvironmentDials.y, metal), 0.0, 1.0);
885
896
  /*
886
897
  * **The split sum only where a prefiltered chain is what is being sampled.** It is the
887
898
  * correct share of a *prefiltered* environment; over a box chain it asserts an integral that
@@ -893,7 +904,7 @@ export const MAIN_GLSL = `void main() {
893
904
  float weight = mix(
894
905
  clamp(fresnel * reflectAmount, 0.0, 1.0),
895
906
  integrated,
896
- uEnvironmentEnabled * uEnvironmentPrefiltered
907
+ uEnvironmentEnabled * uEnvironmentDials.x
897
908
  );
898
909
  #else
899
910
  float weight = clamp(fresnel * reflectAmount, 0.0, 1.0);
@@ -1030,8 +1041,8 @@ export const MAIN_GLSL = `void main() {
1030
1041
  bool fixtureProfiles = false;
1031
1042
  bool fixtureShapes = false;
1032
1043
  if (LIGHT_FIXTURES) {
1033
- fixtureProfiles = uIesAtlasRows > 1.0;
1034
- fixtureShapes = uIesPlaneCount > 1.0 || uCookieTiles > 0.0;
1044
+ fixtureProfiles = uFixtureShape.x > 1.0;
1045
+ fixtureShapes = uFixtureShape.y > 1.0 || uFixtureShape.z > 0.0;
1035
1046
  }
1036
1047
 
1037
1048
  // Point lights. Inverse-square-ish falloff clipped to a finite radius, so a
@@ -1058,6 +1069,19 @@ export const MAIN_GLSL = `void main() {
1058
1069
  float iesProfile;
1059
1070
  vec3 iesAxis;
1060
1071
  float cookie;
1072
+ /* The light's lighting channels, a mask: 1 unless it names others. See \`uLightIesAxis\`. */
1073
+ float lightChannels = 1.0;
1074
+ /* The light's own falloff exponent, or 0 for the frame's falloff. See \`uLightCone\`. */
1075
+ float lightExponent = 0.0;
1076
+ /* A clustered rectangle's barn doors: their cosine and length, none at 0. See \`areaBarnDoors\`. */
1077
+ vec2 areaDoors = vec2(0.0);
1078
+ /*
1079
+ * **A rectangle in the froxel table** — one past the fixed arm's \`maxAreaLights\` — which
1080
+ * its record says with a negative radius, its reach negated. Its fields come out of the
1081
+ * fixture texels: sidedness, the right axis, the half extents and the up axis.
1082
+ */
1083
+ bool clusteredArea = false;
1084
+ float areaTwoSided = 0.0;
1061
1085
  if (clusteredArm) {
1062
1086
  if (slot >= clusterLights) break;
1063
1087
  /*
@@ -1076,6 +1100,8 @@ export const MAIN_GLSL = `void main() {
1076
1100
  lightPos = vec3(
1077
1101
  uintBitsToFloat(rec0.x), uintBitsToFloat(rec0.y), uintBitsToFloat(rec0.z));
1078
1102
  lightRadius = uintBitsToFloat(rec0.w);
1103
+ clusteredArea = lightRadius < 0.0;
1104
+ lightRadius = abs(lightRadius);
1079
1105
  /*
1080
1106
  * **Out of reach is decided on the first texel, before the rest of the record is read.**
1081
1107
  * A froxel holds every light whose sphere touches its box, so most of the lights a fragment
@@ -1099,8 +1125,8 @@ export const MAIN_GLSL = `void main() {
1099
1125
  lightWeight = sizeAndWeight.y;
1100
1126
  /*
1101
1127
  * **The fixture, read only for a light that has one.** What a plain light's record holds in
1102
- * the last three texels is exactly these values, so a light carrying no shadow slot, cone,
1103
- * profile or cookie shades the same whether they are read or assumed, and at heavy overlap
1128
+ * the last four texels is exactly these values, so a light carrying no shadow slot, cone,
1129
+ * profile, cookie, channels or falloff of its own shades the same whether they are read or assumed, and at heavy overlap
1104
1130
  * reading them was a third of the pass. A branch on a value from a texture around
1105
1131
  * \`texelFetch\` is not the 2026-08-07 case: an integer fetch takes no derivative.
1106
1132
  *
@@ -1120,7 +1146,9 @@ export const MAIN_GLSL = `void main() {
1120
1146
  uvec4 rec2 = clusterTexel(record + 2);
1121
1147
  uvec4 rec3 = clusterTexel(record + 3);
1122
1148
  uvec4 rec4 = clusterTexel(record + 4);
1123
- shadowSlot = int(uintBitsToFloat(rec2.x));
1149
+ uvec4 rec5 = clusterTexel(record + 5);
1150
+ shadowSlot = clusteredArea ? -1 : int(uintBitsToFloat(rec2.x));
1151
+ areaTwoSided = uintBitsToFloat(rec2.x);
1124
1152
  lightDir = vec3(
1125
1153
  uintBitsToFloat(rec2.y), uintBitsToFloat(rec2.z), uintBitsToFloat(rec2.w));
1126
1154
  lightCone = vec2(uintBitsToFloat(rec3.x), uintBitsToFloat(rec3.y));
@@ -1130,6 +1158,9 @@ export const MAIN_GLSL = `void main() {
1130
1158
  texel rather than being derived from the direction. */
1131
1159
  iesAxis = vec3(
1132
1160
  uintBitsToFloat(rec4.x), uintBitsToFloat(rec4.y), uintBitsToFloat(rec4.z));
1161
+ lightChannels = uintBitsToFloat(rec4.w);
1162
+ lightExponent = uintBitsToFloat(rec5.x);
1163
+ areaDoors = vec2(uintBitsToFloat(rec5.y), uintBitsToFloat(rec5.z));
1133
1164
  }
1134
1165
  }
1135
1166
  } else {
@@ -1142,11 +1173,48 @@ export const MAIN_GLSL = `void main() {
1142
1173
  lightWeight = uLightWeight[i];
1143
1174
  shadowSlot = i;
1144
1175
  lightDir = uLightDir[i];
1145
- lightCone = uLightCone[i];
1176
+ lightCone = uLightCone[i].xy;
1177
+ lightExponent = uLightCone[i].z;
1146
1178
  iesProfile = uLightIesProfile[i];
1147
- iesAxis = uLightIesAxis[i];
1179
+ iesAxis = uLightIesAxis[i].xyz;
1180
+ lightChannels = uLightIesAxis[i].w;
1148
1181
  cookie = uLightCookie[i];
1149
1182
  }
1183
+ /*
1184
+ * **A light shades a surface only where their channels meet**: the light's mask against the
1185
+ * material's. Both default to channel 1, so a scene naming none takes every light as before
1186
+ * — and **zero reads as that default on both sides**, so a pass that never writes the lane
1187
+ * loses no light: an unwritten uniform is zero, and zero here would be every lamp switched
1188
+ * off. A branch on a value read from a texture in the clustered arm, as the reach test above
1189
+ * is, and it skips only what the light would add; no derivative is taken past it.
1190
+ */
1191
+ int litChannels = int(lightChannels);
1192
+ int surfaceChannels = int(uCutout.w);
1193
+ if (((litChannels == 0 ? 1 : litChannels) & (surfaceChannels == 0 ? 1 : surfaceChannels)) == 0) {
1194
+ continue;
1195
+ }
1196
+ /*
1197
+ * **A clustered rectangle is shaded here and goes no further**: by the fixed loop's own body
1198
+ * (\`areaLight.ts\`), unshadowed — its occlusion is the fixed arm's, which is why the first
1199
+ * \`maxAreaLights\` stay there — and windowed to nothing at its reach, as a lamp is, so the
1200
+ * froxel it is binned into has no edge in the picture.
1201
+ */
1202
+ if (clusteredArea) {
1203
+ vec3 seenCentre = lightPos;
1204
+ vec2 seenHalf = lightCone;
1205
+ if (!areaBarnDoors(seenCentre, lightDir, iesAxis, seenHalf, areaDoors)) continue;
1206
+ float areaForm = areaSignedForm(n, seenCentre, lightDir, iesAxis, seenHalf);
1207
+ float areaWindow = clamp(1.0 - pow(length(lightPos - vWorldPos) / max(lightRadius, 1e-4), 4.0), 0.0, 1.0);
1208
+ areaForm = mix(max(0.0, areaForm), abs(areaForm), areaTwoSided);
1209
+ if (areaForm > 0.0) {
1210
+ areaLightAdd(
1211
+ seenCentre, lightDir, iesAxis, seenHalf, lightColor * (areaWindow * areaWindow), areaForm,
1212
+ 1.0, vec3(1.0), n, albedo, metal, specColor, surfaceRoughness, modelled,
1213
+ lampOpen, lampShadowed
1214
+ );
1215
+ }
1216
+ continue;
1217
+ }
1150
1218
  /* A DriftLight field's own light carries a negative weight, and is shaded exactly only for the
1151
1219
  share of this pixel the field does not stand in for. See \`driftLight.ts\`. */
1152
1220
  if (lightWeight < 0.0) lightWeight = -lightWeight * (1.0 - driftShare);
@@ -1191,7 +1259,16 @@ export const MAIN_GLSL = `void main() {
1191
1259
  * same way three.js windows its own, so the light still ends where it says it does.
1192
1260
  */
1193
1261
  float falloff;
1194
- if (uLightFalloff == 1) {
1262
+ /*
1263
+ * **A light may name its own falloff, and then it is Unreal's for a light without
1264
+ * inverse-square falloff**: \`(1 - (d/R)^2)^n\` with no distance term, so a fill authored to
1265
+ * light a whole hall across a hundred metres does, where the inverse square would have it
1266
+ * gone a few metres out. Zero is the frame's own rule below, which every light was before.
1267
+ */
1268
+ if (lightExponent > 0.0) {
1269
+ float reach = dist / max(lightRadius, 1e-4);
1270
+ falloff = pow(clamp(1.0 - reach * reach, 0.0, 1.0), lightExponent);
1271
+ } else if (uLightFalloff == 1) {
1195
1272
  float window = clamp(1.0 - pow(dist / max(lightRadius, 1e-4), 4.0), 0.0, 1.0);
1196
1273
  falloff = window * window / max(dist * dist, 0.01);
1197
1274
  } else {
@@ -1351,7 +1428,7 @@ export const MAIN_GLSL = `void main() {
1351
1428
  * and the result is selected afterwards with a \`mix\` on a compare — which is arithmetic
1352
1429
  * rather than control flow.
1353
1430
  *
1354
- * **And skipped outright where nothing loaded a profile**, behind \`uIesAtlasRows\`, which is
1431
+ * **And skipped outright where nothing loaded a profile**, behind \`uFixtureShape.x\`, which is
1355
1432
  * one while the atlas holds only its row of ones. A uniform is provably uniform control
1356
1433
  * flow, so this branch is not the one the rule forbids. It was paid on every scene until a
1357
1434
  * 4K frame of 320 lamps and no shadows measured it at 0.7 ms of the main pass, rising to
@@ -1394,12 +1471,12 @@ export const MAIN_GLSL = `void main() {
1394
1471
  if (iesRefLen > 1e-5) {
1395
1472
  iesRef /= iesRefLen;
1396
1473
  vec3 iesBinormal = cross(lightDir, iesRef);
1397
- if (uIesPlaneCount > 1.0) {
1474
+ if (uFixtureShape.y > 1.0) {
1398
1475
  /* \`atan\` answers -PI..PI and \`fract\` of a negative wraps forward, so this is 0..1
1399
1476
  across the whole turn without a branch on the sign. */
1400
1477
  iesTurns = fract(atan(dot(iesRay, iesBinormal), dot(iesRay, iesRef)) / TAU_IES);
1401
1478
  }
1402
- if (uCookieTiles > 0.0) {
1479
+ if (uFixtureShape.z > 0.0) {
1403
1480
  /*
1404
1481
  * **A perspective projection onto the plane one unit down the aim**, which is what a
1405
1482
  * fixture actually throws: the mask grows with distance rather than being pasted on
@@ -1446,15 +1523,19 @@ export const MAIN_GLSL = `void main() {
1446
1523
  */
1447
1524
  float photometric = 1.0;
1448
1525
  if (fixtureProfiles) {
1449
- float iesBase = iesRow * (uIesPlaneCount + 1.0);
1526
+ float iesBase = iesRow * (uFixtureShape.y + 1.0);
1450
1527
  /* The profiles are the atlas's bottom rows, below any cookies. */
1451
- float iesTop = fixtureSize.y - uIesAtlasRows;
1452
- float iesV = (iesTop + iesBase + iesTurns * uIesPlaneCount + 0.5) / fixtureSize.y;
1528
+ float iesTop = fixtureSize.y - uFixtureShape.x;
1529
+ float iesV = (iesTop + iesBase + iesTurns * uFixtureShape.y + 0.5) / fixtureSize.y;
1453
1530
  float iesGain = textureLod(uFixtureAtlas, vec2(iesU, iesV), 0.0).r;
1454
1531
  photometric = mix(1.0, iesGain, step(0.0, iesProfile));
1455
1532
  }
1456
1533
 
1457
- float shape = (uLightFalloff == 1 ? falloff : falloff * falloff) * coneFalloff * photometric;
1534
+ /* A light's own exponent already is its whole curve; the frame's smooth rule squares its own. */
1535
+ float shape =
1536
+ (lightExponent > 0.0 || uLightFalloff == 1 ? falloff : falloff * falloff) *
1537
+ coneFalloff *
1538
+ photometric;
1458
1539
  glassGlow += lightColor * backNdl * shape * lightWeight * shaded * lampGlass;
1459
1540
  if (ndl <= 0.0 && !modelledBehind) continue;
1460
1541
  /*
@@ -1531,16 +1612,15 @@ export const MAIN_GLSL = `void main() {
1531
1612
  if (vSpecular > 0.0 || metal > 0.0) {
1532
1613
  vec3 toEyeLamp = normalize(uCameraPos - vWorldPos);
1533
1614
  vec3 lampHalfway = normalize(toLight / max(dist, 1e-4) + toEyeLamp);
1534
- /* The same grazing whitening the sun's highlight takes, and zero at metal 0. */
1535
- vec3 lampSpec = mix(
1536
- specColor,
1537
- vec3(1.0),
1538
- pow(1.0 - max(dot(toEyeLamp, lampHalfway), 0.0), 5.0) * metal
1539
- );
1615
+ /* The same grazing whitening the sun's highlight takes, and zero at metal 0 for the look. */
1616
+ vec3 lampSpec = highlightTint(specColor, max(dot(toEyeLamp, lampHalfway), 0.0), metal);
1617
+ /* The look's lobe, or GGX's own where the surface asks for it: see \`physicalLobe\`. */
1618
+ float lampNdh = max(dot(n, lampHalfway), 0.0);
1619
+ float lampLobe = physicalSpecular()
1620
+ ? physicalLobe(lampNdh, ndl, dot(n, toEyeLamp), surfaceRoughness, lightSourceRadius, dist)
1621
+ : sphereLobe(lampNdh, surfaceRoughness, lightSourceRadius, dist);
1540
1622
  /* Held back with the diffuse half, and shadowed by the same term it always was. */
1541
- vec3 lampHighlight =
1542
- lightColor * sphereLobe(max(dot(n, lampHalfway), 0.0), surfaceRoughness, lightSourceRadius, dist)
1543
- * lampSpec * shape * lightWeight;
1623
+ vec3 lampHighlight = lightColor * lampLobe * lampSpec * shape * lightWeight;
1544
1624
  lampOpen += lampHighlight;
1545
1625
  lampShadowed += lampHighlight * shaded * lampGlass;
1546
1626
  }
@@ -1584,24 +1664,18 @@ export const MAIN_GLSL = `void main() {
1584
1664
  vec3 centre = uAreaLightPos[a];
1585
1665
  vec3 right = uAreaLightRight[a];
1586
1666
  vec3 up = uAreaLightUp[a];
1587
- vec2 halfSize = uAreaLightSize[a];
1588
-
1667
+ vec2 halfSize = uAreaLightSize[a].xy;
1589
1668
  /*
1590
- * **Wound so a surface on the emitting side sees them counter-clockwise**, which is what
1591
- * makes the form factor positive there. The natural order — minus, plus, plus, minus — winds
1592
- * the other way, and every one-sided light then clamped to zero and the frame was black.
1669
+ * **The part of the rectangle this fragment sees past its barn doors** (\`areaBarnDoors\`),
1670
+ * which its light and highlight come from. Its shadow keeps the whole rectangle's centre and
1671
+ * size below, because that is what its map was baked from.
1593
1672
  */
1594
- vec3 c0 = centre - right * halfSize.x + up * halfSize.y;
1595
- vec3 c1 = centre + right * halfSize.x + up * halfSize.y;
1596
- vec3 c2 = centre + right * halfSize.x - up * halfSize.y;
1597
- vec3 c3 = centre - right * halfSize.x - up * halfSize.y;
1673
+ vec3 seenCentre = centre;
1674
+ vec2 seenHalf = halfSize;
1675
+ if (!areaBarnDoors(seenCentre, right, up, seenHalf, uAreaLightSize[a].zw)) continue;
1598
1676
 
1599
- /*
1600
- * **The sign is the sidedness.** A one-sided rectangle takes the positive part and a
1601
- * two-sided one the magnitude — no facing test, because the sign already answers it exactly
1602
- * per fragment rather than once for the rectangle's centre.
1603
- */
1604
- float signedForm = quadFormFactor(n, vWorldPos, c0, c1, c2, c3);
1677
+ /* The form factor and its sign, which is the sidedness: see \`areaSignedForm\`. */
1678
+ float signedForm = areaSignedForm(n, seenCentre, right, up, seenHalf);
1605
1679
  float form = mix(max(0.0, signedForm), abs(signedForm), uAreaLightTwoSided[a]);
1606
1680
  /* The form factor is linear in the normal, so the one seen from behind is its negation. */
1607
1681
  float backForm = glassTransmission > 0.0
@@ -1716,55 +1790,11 @@ export const MAIN_GLSL = `void main() {
1716
1790
 
1717
1791
  glassGlow += uAreaLightColor[a] * backForm * areaOccl * areaGlass;
1718
1792
  if (form <= 0.0) continue;
1719
- /*
1720
- * A model answers a rectangle as it answers a lamp at its centre, carried at the rectangle's
1721
- * own energy: the diffuse by the exact form factor over the centre's cosine, the specular by
1722
- * the form factor. **An approximation, stated**: a model's lobe is not integrated over the
1723
- * rectangle as the standard lobe is, so a glossy model under a large softbox shows a lobe
1724
- * from its centre rather than its shape.
1725
- */
1726
- if (modelled) {
1727
- vec3 areaL = normalize(centre - vWorldPos);
1728
- modelLight(areaL, 0.0, 0.0);
1729
- vec3 areaModel = (mDiffuse * (form / max(dot(n, areaL), 1e-3)) + mSpecular * form)
1730
- * uAreaLightColor[a];
1731
- lampOpen += areaModel;
1732
- lampShadowed += areaModel * areaOccl * areaGlass;
1733
- continue;
1734
- }
1735
- /* Held back with the point lamps', and shadowed by the same term it always was. */
1736
- vec3 areaDiffuse = albedo * uAreaLightColor[a] * form * (1.0 - metal);
1737
- lampOpen += areaDiffuse;
1738
- lampShadowed += areaDiffuse * areaOccl * areaGlass;
1739
-
1740
- if (vSpecular > 0.0 || metal > 0.0) {
1741
- /*
1742
- * **The lobe integrated over the rectangle, rather than sampled at one point on it.**
1743
- *
1744
- * What stood here handed the closest point on the rectangle to \`sphereLobe\` and scaled it
1745
- * by \`form\`, the *diffuse* form factor. Measured against a brute-force integral by
1746
- * \`scripts/areaSpecular.mjs\`, that lost the reflection rather than blurring it: on
1747
- * polished metal facing a softbox it returned 0.000233 where the integral is 0.9207, and
1748
- * head-on on a rough surface it was 3.7 times too bright. Worst 287% either way; this is
1749
- * 40.1% where the light is what the surface reflects and 79.0% for one overhead.
1750
- *
1751
- * \`quadCoverage\` says what fraction of the specular lobe the rectangle covers and the
1752
- * environment BRDF says how much the surface returns, which is the same split the probe
1753
- * path uses. **\`dfg.x + dfg.y\` and not \`envSpecularEnergy\`**, deliberately and against
1754
- * the obvious argument: the compensation returns the multiply-scattered share, and every
1755
- * direct lobe in this shader is single-scattering, so adding it here returns energy the
1756
- * light never had. Measured at 211% against 40.1%.
1757
- */
1758
- vec3 toEyeArea = normalize(uCameraPos - vWorldPos);
1759
- float coverage = quadCoverage(n, vWorldPos, toEyeArea, surfaceRoughness, c0, c1, c2, c3);
1760
- if (coverage > 0.0) {
1761
- vec2 areaDfg = envBrdfApprox(max(dot(n, toEyeArea), 0.0), surfaceRoughness);
1762
- vec3 areaSpec = specColor * areaDfg.x + vec3(areaDfg.y);
1763
- vec3 areaHighlight = areaSpec * uAreaLightColor[a] * coverage;
1764
- lampOpen += areaHighlight;
1765
- lampShadowed += areaHighlight * areaOccl * areaGlass;
1766
- }
1767
- }
1793
+ /* The diffuse, the model's answer or the lobe integrated over the rectangle: see areaLight.ts. */
1794
+ areaLightAdd(
1795
+ seenCentre, right, up, seenHalf, uAreaLightColor[a], form, areaOccl, areaGlass,
1796
+ n, albedo, metal, specColor, surfaceRoughness, modelled, lampOpen, lampShadowed
1797
+ );
1768
1798
  }
1769
1799
 
1770
1800
  /*
@@ -1906,10 +1936,10 @@ export const MAIN_GLSL = `void main() {
1906
1936
  }
1907
1937
  /* Pulse, flicker and fade from the layer's effects; exactly 1 where it names none. */
1908
1938
  float fxGlow = fx4.z + fx5.x + fx5.w > 0.0 ? fxEmission(surfaceAt.z) : 1.0;
1909
- lit += emissiveTint * emissiveMapped * uEmissiveGain * vEmissive * uNightFactor
1939
+ lit += emissiveTint * emissiveMapped * uEmission.x * vEmissive * uEmission.y
1910
1940
  * mix(1.0, min(lightShade, sunShade), EMISSIVE_SHADOW_SHARE) * fxGlow;
1911
1941
  /* And a lit window's glow, which the scene's lit share already times: not gated on night. */
1912
- lit += windowGlow * uEmissiveGain;
1942
+ lit += windowGlow * uEmission.x;
1913
1943
 
1914
1944
  #if NIGHT_EMISSIVE
1915
1945
  /*
@@ -1942,9 +1972,9 @@ export const MAIN_GLSL = `void main() {
1942
1972
  // Arrival glow: a world-space box lit independently of the clock, so
1943
1973
  // finishing a run reads the same at noon and at midnight. Costs one compare
1944
1974
  // per fragment and no extra draw call — the box is a uniform, not geometry.
1945
- if (uHighlightGain > 0.0) {
1946
- vec3 inside = step(uHighlightMin, vWorldPos) * step(vWorldPos, uHighlightMax);
1947
- lit += albedo * uHighlightGain * inside.x * inside.y * inside.z;
1975
+ if (uHighlightMax.w > 0.0) {
1976
+ vec3 inside = step(uHighlightMin, vWorldPos) * step(vWorldPos, uHighlightMax.xyz);
1977
+ lit += albedo * uHighlightMax.w * inside.x * inside.y * inside.z;
1948
1978
  }
1949
1979
  }
1950
1980
 
@@ -2001,7 +2031,7 @@ export const MAIN_GLSL = `void main() {
2001
2031
  /*
2002
2032
  * **Refraction: the scene behind this surface, bent and absorbed.**
2003
2033
  *
2004
- * The offset is along the surface normal in screen space, which is the cheap approximation every
2034
+ * The offset is along the shading normal in screen space, which is the cheap approximation every
2005
2035
  * real-time renderer ships rather than a ray traced through two interfaces of a solid. What it
2006
2036
  * cannot do is show anything the frame had not already drawn, so a pane at the edge of the frame
2007
2037
  * refracts what is beside it -- and the clamp below is what keeps that from being worse than
@@ -2036,7 +2066,14 @@ export const MAIN_GLSL = `void main() {
2036
2066
  * draw uses.
2037
2067
  */
2038
2068
  if (uSeeThrough.x > 0.0 || glassTransmission > 0.0) {
2039
- vec3 refractN = normalize(vNormal);
2069
+ /*
2070
+ * **Bent by the shading normal, so a normal map shimmers what is seen through it** — a heat
2071
+ * haze, a distortion sphere, a rippled pane. Until 4.8.6 this was the geometric normal and a
2072
+ * mapped surface refracted as a smooth lens. An unlit draw shaded no normal, so it reads the
2073
+ * map here, on a branch on uniforms alone, which keeps its derivatives legal.
2074
+ */
2075
+ vec3 refractN = shadingNormal;
2076
+ if (uLightingEnabled == 0 && uNormalStrength > 0.0) refractN = normalMapped(refractN, surfaceAt);
2040
2077
  vec3 refractV = normalize(uCameraPos - vWorldPos);
2041
2078
  ivec2 snapSize = textureSize(uRefractScene, 0);
2042
2079
  vec2 screenUv = gl_FragCoord.xy / vec2(snapSize);