@driftengine/core 4.3.0 → 4.4.1

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 (218) hide show
  1. package/CHANGELOG.json +282 -0
  2. package/README.md +1 -1
  3. package/dist/cinematic/cameraPath.d.ts +53 -0
  4. package/dist/cinematic/cameraPath.js +118 -0
  5. package/dist/environment/daylight.d.ts +77 -0
  6. package/dist/environment/daylight.js +77 -0
  7. package/dist/geometry/meshConcat.d.ts +9 -0
  8. package/dist/geometry/meshConcat.js +101 -0
  9. package/dist/index.d.ts +12 -2
  10. package/dist/index.js +14 -1
  11. package/dist/render/ambientOcclusionPass.js +5 -1
  12. package/dist/render/backend/createRenderer.d.ts +13 -1
  13. package/dist/render/backend/createRenderer.js +6 -5
  14. package/dist/render/backend/webgl2/renderer.d.ts +147 -1
  15. package/dist/render/backend/webgl2/renderer.js +402 -23
  16. package/dist/render/backend/webgpu/buffers.js +46 -8
  17. package/dist/render/backend/webgpu/depthPass.d.ts +81 -3
  18. package/dist/render/backend/webgpu/depthPass.js +75 -14
  19. package/dist/render/backend/webgpu/exposurePass.d.ts +39 -0
  20. package/dist/render/backend/webgpu/exposurePass.js +190 -0
  21. package/dist/render/backend/webgpu/fieldCompose.d.ts +11 -0
  22. package/dist/render/backend/webgpu/fieldCompose.js +13 -0
  23. package/dist/render/backend/webgpu/flatPass.d.ts +3 -1
  24. package/dist/render/backend/webgpu/flatPass.js +12 -5
  25. package/dist/render/backend/webgpu/particlePass.d.ts +8 -0
  26. package/dist/render/backend/webgpu/particlePass.js +1 -0
  27. package/dist/render/backend/webgpu/postPass.d.ts +13 -3
  28. package/dist/render/backend/webgpu/probeBake.d.ts +59 -3
  29. package/dist/render/backend/webgpu/probeBake.js +97 -7
  30. package/dist/render/backend/webgpu/probeTargets.d.ts +65 -0
  31. package/dist/render/backend/webgpu/probeTargets.js +180 -0
  32. package/dist/render/backend/webgpu/renderer.d.ts +174 -11
  33. package/dist/render/backend/webgpu/renderer.js +682 -252
  34. package/dist/render/backend/webgpu/scatterPass.js +7 -7
  35. package/dist/render/backend/webgpu/shaders/clusterBin.wgsl.d.ts +1 -1
  36. package/dist/render/backend/webgpu/skinPaletteRing.d.ts +4 -0
  37. package/dist/render/backend/webgpu/skinPaletteRing.js +9 -0
  38. package/dist/render/backend/webgpu/skyPass.js +5 -1
  39. package/dist/render/backend/webgpu/uniformRing.d.ts +31 -1
  40. package/dist/render/backend/webgpu/uniformRing.js +53 -3
  41. package/dist/render/bloomChain.d.ts +6 -0
  42. package/dist/render/bloomChain.js +8 -0
  43. package/dist/render/clusteredLights.d.ts +19 -11
  44. package/dist/render/clusteredLights.js +96 -45
  45. package/dist/render/cutoutCaster.d.ts +23 -0
  46. package/dist/render/cutoutCaster.js +20 -0
  47. package/dist/render/driftLight/bake.d.ts +34 -0
  48. package/dist/render/driftLight/bake.js +95 -0
  49. package/dist/render/driftLight/falloff.d.ts +16 -0
  50. package/dist/render/driftLight/falloff.js +23 -0
  51. package/dist/render/driftLight/layout.d.ts +59 -0
  52. package/dist/render/driftLight/layout.js +138 -0
  53. package/dist/render/driftLight/lightField.d.ts +108 -0
  54. package/dist/render/driftLight/lightField.js +179 -0
  55. package/dist/render/driftLight/uniforms.d.ts +28 -0
  56. package/dist/render/driftLight/uniforms.js +41 -0
  57. package/dist/render/driftLight/visibility.d.ts +18 -0
  58. package/dist/render/driftLight/visibility.js +47 -0
  59. package/dist/render/emptyTexture.d.ts +6 -0
  60. package/dist/render/emptyTexture.js +19 -0
  61. package/dist/render/exposurePass.d.ts +48 -0
  62. package/dist/render/exposurePass.js +172 -0
  63. package/dist/render/flameLight.d.ts +71 -0
  64. package/dist/render/flameLight.js +63 -0
  65. package/dist/render/gi/bounceLights.d.ts +34 -0
  66. package/dist/render/gi/bounceLights.js +66 -0
  67. package/dist/render/gi/fieldReach.d.ts +12 -0
  68. package/dist/render/gi/fieldReach.js +62 -0
  69. package/dist/render/gi/globalField.d.ts +8 -0
  70. package/dist/render/gi/globalField.js +31 -0
  71. package/dist/render/gi/probeTrace.d.ts +3 -1
  72. package/dist/render/gi/probeTrace.js +3 -1
  73. package/dist/render/gpuCapability.js +19 -4
  74. package/dist/render/lightBudget.d.ts +11 -0
  75. package/dist/render/lightBudget.js +11 -0
  76. package/dist/render/pointLightSelection.d.ts +16 -0
  77. package/dist/render/pointLightSelection.js +178 -83
  78. package/dist/render/pointShadowBudget.d.ts +12 -2
  79. package/dist/render/pointShadowBudget.js +16 -10
  80. package/dist/render/probeGrid.d.ts +11 -1
  81. package/dist/render/probeGrid.js +5 -2
  82. package/dist/render/probeSweeps.d.ts +45 -0
  83. package/dist/render/probeSweeps.js +77 -0
  84. package/dist/render/reflectionProbe.d.ts +43 -1
  85. package/dist/render/reflectionProbe.js +17 -3
  86. package/dist/render/renderQuality.d.ts +3 -1
  87. package/dist/render/rendererHarness.d.ts +9 -0
  88. package/dist/render/rendererHarness.js +18 -3
  89. package/dist/render/sceneTarget.d.ts +20 -0
  90. package/dist/render/sceneTarget.js +62 -1
  91. package/dist/render/shaders/ambientOcclusion.d.ts +63 -6
  92. package/dist/render/shaders/ambientOcclusion.js +188 -71
  93. package/dist/render/shaders/cutoutCoverage.d.ts +31 -0
  94. package/dist/render/shaders/cutoutCoverage.js +40 -0
  95. package/dist/render/shaders/depth.d.ts +25 -0
  96. package/dist/render/shaders/depth.js +69 -3
  97. package/dist/render/shaders/exposure.d.ts +52 -0
  98. package/dist/render/shaders/exposure.js +124 -0
  99. package/dist/render/shaders/filmLook.d.ts +47 -0
  100. package/dist/render/shaders/filmLook.js +98 -0
  101. package/dist/render/shaders/flat/directionalShadow.js +35 -4
  102. package/dist/render/shaders/flat/driftLight.d.ts +29 -0
  103. package/dist/render/shaders/flat/driftLight.js +75 -0
  104. package/dist/render/shaders/flat/index.js +5 -0
  105. package/dist/render/shaders/flat/lobes.js +13 -0
  106. package/dist/render/shaders/flat/main.d.ts +1 -1
  107. package/dist/render/shaders/flat/main.js +68 -9
  108. package/dist/render/shaders/flat/preamble.js +23 -5
  109. package/dist/render/shaders/flat/probeGrid.js +46 -3
  110. package/dist/render/shaders/generated/ambientOcclusion.wgsl.d.ts +8 -3
  111. package/dist/render/shaders/generated/ambientOcclusion.wgsl.js +8 -3
  112. package/dist/render/shaders/generated/depth.wgsl.d.ts +100 -0
  113. package/dist/render/shaders/generated/depth.wgsl.js +100 -0
  114. package/dist/render/shaders/generated/exposure.wgsl.d.ts +42 -0
  115. package/dist/render/shaders/generated/exposure.wgsl.js +48 -0
  116. package/dist/render/shaders/generated/flat.wgsl.d.ts +1800 -1344
  117. package/dist/render/shaders/generated/flat.wgsl.js +1816 -1360
  118. package/dist/render/shaders/generated/localExposure.wgsl.d.ts +18 -0
  119. package/dist/render/shaders/generated/localExposure.wgsl.js +24 -0
  120. package/dist/render/shaders/generated/rush.wgsl.d.ts +40 -10
  121. package/dist/render/shaders/generated/rush.wgsl.js +40 -10
  122. package/dist/render/shaders/generated/temporalResolve.wgsl.d.ts +1 -1
  123. package/dist/render/shaders/generated/temporalResolve.wgsl.js +1 -1
  124. package/dist/render/shaders/gi/driftLight.wgsl.d.ts +16 -0
  125. package/dist/render/shaders/gi/driftLight.wgsl.js +49 -0
  126. package/dist/render/shaders/gi/probeBake.wgsl.d.ts +29 -4
  127. package/dist/render/shaders/gi/probeBake.wgsl.js +190 -20
  128. package/dist/render/shaders/globalMedium.js +4 -0
  129. package/dist/render/shaders/localExposure.d.ts +35 -0
  130. package/dist/render/shaders/localExposure.js +138 -0
  131. package/dist/render/shaders/prefilter.d.ts +1 -1
  132. package/dist/render/shaders/prefilter.js +6 -0
  133. package/dist/render/shaders/rush.js +33 -5
  134. package/dist/render/shaders/tangentFrame.d.ts +1 -1
  135. package/dist/render/shaders/tangentFrame.js +15 -3
  136. package/dist/render/shaders/temporalResolve.js +39 -1
  137. package/dist/render/shadowCasters.d.ts +5 -3
  138. package/dist/render/shadowMap.js +13 -0
  139. package/dist/render/surfaceTexture.d.ts +5 -0
  140. package/package.json +6 -6
  141. package/scripts/gpuCompute.mjs +24 -3
  142. package/scripts/png.mjs +23 -12
  143. package/src/cinematic/cameraPath.ts +178 -0
  144. package/src/environment/daylight.ts +152 -0
  145. package/src/geometry/meshConcat.ts +100 -0
  146. package/src/index.ts +32 -0
  147. package/src/render/ambientOcclusionPass.ts +5 -1
  148. package/src/render/backend/createRenderer.ts +22 -6
  149. package/src/render/backend/webgl2/renderer.ts +439 -20
  150. package/src/render/backend/webgpu/buffers.ts +51 -8
  151. package/src/render/backend/webgpu/depthPass.ts +78 -10
  152. package/src/render/backend/webgpu/exposurePass.ts +234 -0
  153. package/src/render/backend/webgpu/fieldCompose.ts +15 -0
  154. package/src/render/backend/webgpu/flatPass.ts +10 -2
  155. package/src/render/backend/webgpu/particlePass.ts +9 -0
  156. package/src/render/backend/webgpu/probeBake.ts +143 -9
  157. package/src/render/backend/webgpu/probeTargets.ts +211 -0
  158. package/src/render/backend/webgpu/renderer.ts +808 -273
  159. package/src/render/backend/webgpu/scatterPass.ts +7 -7
  160. package/src/render/backend/webgpu/skinPaletteRing.ts +10 -0
  161. package/src/render/backend/webgpu/skyPass.ts +5 -1
  162. package/src/render/backend/webgpu/uniformRing.ts +49 -3
  163. package/src/render/bloomChain.ts +9 -0
  164. package/src/render/clusteredLights.ts +108 -63
  165. package/src/render/cutoutCaster.ts +44 -0
  166. package/src/render/driftLight/bake.ts +125 -0
  167. package/src/render/driftLight/falloff.ts +26 -0
  168. package/src/render/driftLight/layout.ts +177 -0
  169. package/src/render/driftLight/lightField.ts +227 -0
  170. package/src/render/driftLight/uniforms.ts +61 -0
  171. package/src/render/driftLight/visibility.ts +58 -0
  172. package/src/render/emptyTexture.ts +41 -0
  173. package/src/render/exposurePass.ts +186 -0
  174. package/src/render/flameLight.ts +135 -0
  175. package/src/render/gi/bounceLights.ts +68 -0
  176. package/src/render/gi/fieldReach.ts +74 -0
  177. package/src/render/gi/globalField.ts +39 -0
  178. package/src/render/gi/probeTrace.ts +3 -1
  179. package/src/render/gpuCapability.ts +18 -5
  180. package/src/render/lightBudget.ts +12 -0
  181. package/src/render/pointLightSelection.ts +191 -79
  182. package/src/render/pointShadowBudget.ts +16 -8
  183. package/src/render/probeGrid.ts +13 -2
  184. package/src/render/probeSweeps.ts +80 -0
  185. package/src/render/reflectionProbe.ts +54 -2
  186. package/src/render/renderQuality.ts +3 -1
  187. package/src/render/rendererHarness.ts +25 -3
  188. package/src/render/sceneTarget.ts +75 -1
  189. package/src/render/shaders/ambientOcclusion.ts +205 -71
  190. package/src/render/shaders/cutoutCoverage.ts +43 -0
  191. package/src/render/shaders/depth.ts +80 -3
  192. package/src/render/shaders/exposure.ts +128 -0
  193. package/src/render/shaders/filmLook.ts +111 -0
  194. package/src/render/shaders/flat/directionalShadow.ts +35 -4
  195. package/src/render/shaders/flat/driftLight.ts +75 -0
  196. package/src/render/shaders/flat/index.ts +5 -0
  197. package/src/render/shaders/flat/lobes.ts +13 -0
  198. package/src/render/shaders/flat/main.ts +68 -9
  199. package/src/render/shaders/flat/preamble.ts +23 -5
  200. package/src/render/shaders/flat/probeGrid.ts +46 -3
  201. package/src/render/shaders/generated/ambientOcclusion.wgsl.ts +8 -3
  202. package/src/render/shaders/generated/depth.wgsl.ts +103 -0
  203. package/src/render/shaders/generated/exposure.wgsl.ts +51 -0
  204. package/src/render/shaders/generated/flat.wgsl.ts +1816 -1360
  205. package/src/render/shaders/generated/localExposure.wgsl.ts +26 -0
  206. package/src/render/shaders/generated/rush.wgsl.ts +40 -10
  207. package/src/render/shaders/generated/temporalResolve.wgsl.ts +1 -1
  208. package/src/render/shaders/gi/driftLight.wgsl.ts +49 -0
  209. package/src/render/shaders/gi/probeBake.wgsl.ts +191 -20
  210. package/src/render/shaders/globalMedium.ts +4 -0
  211. package/src/render/shaders/localExposure.ts +154 -0
  212. package/src/render/shaders/prefilter.ts +6 -0
  213. package/src/render/shaders/rush.ts +33 -5
  214. package/src/render/shaders/tangentFrame.ts +15 -3
  215. package/src/render/shaders/temporalResolve.ts +39 -1
  216. package/src/render/shadowCasters.ts +5 -3
  217. package/src/render/shadowMap.ts +14 -0
  218. package/src/render/surfaceTexture.ts +5 -0
@@ -0,0 +1,26 @@
1
+ /*
2
+ * Generated from ../localExposure.ts by `npm run wgsl`. Do not edit.
3
+ *
4
+ * The GLSL beside this file is the source of truth. A hand edit here is discarded by
5
+ * the next generation, and `npm run wgsl:check` fails the build when this is stale.
6
+ */
7
+
8
+ export const EXPOSURE_LOCAL_FRAG_WGSL = "var<private> vUv_1: vec2<f32>;\n@group(0) @binding(32) \nvar uScene_t: texture_2d<f32>;\n@group(0) @binding(33) \nvar uScene_s: sampler;\nvar<private> fragColor: vec2<f32>;\n\nfn main_1() {\n var uvBlock: f32;\n var band: f32;\n var corner: vec2<f32>;\n var sum: f32;\n var count: f32;\n var y: i32;\n var x: i32;\n var uv: vec2<f32>;\n var c: vec3<f32>;\n var level: f32;\n var tapBand: f32;\n var kept: f32;\n\n let _e39 = vUv_1[0u];\n uvBlock = (_e39 * 11f);\n let _e41 = uvBlock;\n band = floor(_e41);\n let _e43 = uvBlock;\n let _e46 = vUv_1[1u];\n corner = (vec2<f32>(fract(_e43), _e46) - vec2<f32>(0.015625f, 0.015625f));\n sum = 0f;\n count = 0f;\n y = 0i;\n loop {\n let _e49 = y;\n if (_e49 < 8i) {\n x = 0i;\n loop {\n let _e51 = x;\n if (_e51 < 8i) {\n let _e53 = corner;\n let _e54 = x;\n let _e56 = y;\n uv = (_e53 + ((vec2<f32>(f32(_e54), f32(_e56)) + vec2(0.5f)) / vec2(256f)));\n let _e64 = uv;\n let _e65 = textureSampleLevel(uScene_t, uScene_s, _e64, 0f);\n c = _e65.xyz;\n let _e67 = c;\n level = clamp(log2(max(dot(_e67, vec3<f32>(0.2126f, 0.7152f, 0.0722f)), 0.00000001f)), -12f, 8f);\n let _e72 = level;\n tapBand = floor(clamp(((_e72 - -12f) / 2f), 0f, 9f));\n let _e77 = band;\n let _e79 = tapBand;\n let _e80 = band;\n kept = select(0f, 1f, ((_e77 > 9f) || (_e79 == _e80)));\n let _e84 = level;\n let _e85 = kept;\n let _e87 = sum;\n sum = (_e87 + (_e84 * _e85));\n let _e89 = kept;\n let _e90 = count;\n count = (_e90 + _e89);\n continue;\n } else {\n break;\n }\n continuing {\n let _e92 = x;\n x = (_e92 + 1i);\n }\n }\n continue;\n } else {\n break;\n }\n continuing {\n let _e94 = y;\n y = (_e94 + 1i);\n }\n }\n let _e96 = sum;\n let _e97 = count;\n fragColor = (vec2<f32>(_e96, _e97) / vec2(64f));\n return;\n}\n\n@fragment \nfn main(@location(0) vUv: vec2<f32>) -> @location(0) vec2<f32> {\n vUv_1 = vUv;\n main_1();\n let _e3 = fragColor;\n return _e3;\n}\n";
9
+
10
+ /**
11
+ * What the transform assigned, so the renderer binds the same numbers.
12
+ *
13
+ * A permuted shader has one entry per variant, keyed as `FLAT_FRAG_WGSL` is.
14
+ */
15
+ export const LOCALEXPOSURE_BINDINGS = {
16
+ "EXPOSURE_LOCAL_FRAG": {
17
+ "uniforms": null,
18
+ "textures": {
19
+ "uScene": {
20
+ "texture": 32,
21
+ "sampler": 33,
22
+ "type": "sampler2D"
23
+ }
24
+ }
25
+ }
26
+ } as const;
@@ -5,7 +5,7 @@
5
5
  * the next generation, and `npm run wgsl:check` fails the build when this is stale.
6
6
  */
7
7
 
8
- export const RUSH_FRAG_WGSL = "struct Uniforms {\n uStrength: f32,\n uReach: f32,\n uOutputTransform: i32,\n uOutputExposure: f32,\n uReprojection: mat4x4<f32>,\n uMotionStrength: f32,\n uMotionMax: f32,\n uAoStrength: f32,\n uBloomStrength: f32,\n uVeilColor: vec3<f32>,\n uVeilAlpha: f32,\n uGradeStrength: f32,\n uGradeSize: f32,\n uFocusDistance: f32,\n uFocusRange: f32,\n uDofStrength: f32,\n uDofAspect: vec2<f32>,\n uDepthToView: vec4<f32>,\n}\n\n@group(0) @binding(34) \nvar uDepth_t: texture_2d<f32>;\n@group(0) @binding(35) \nvar uDepth_s: sampler;\n@group(0) @binding(1) \nvar<uniform> unnamed: Uniforms;\nvar<private> vUv_1: vec2<f32>;\n@group(0) @binding(32) \nvar uScene_t: texture_2d<f32>;\n@group(0) @binding(33) \nvar uScene_s: sampler;\n@group(0) @binding(38) \nvar uBloom_t: texture_2d<f32>;\n@group(0) @binding(39) \nvar uBloom_s: sampler;\n@group(0) @binding(40) \nvar uGradeLut_t: texture_3d<f32>;\n@group(0) @binding(41) \nvar uGradeLut_s: sampler;\n@group(0) @binding(36) \nvar uAo_t: texture_2d<f32>;\n@group(0) @binding(37) \nvar uAo_s: sampler;\nvar<private> fragColor: vec4<f32>;\n\nfn withVeil_u0028_vf3_u003b(c: ptr<function, vec3<f32>>) -> vec3<f32> {\n let _e113 = unnamed.uVeilAlpha;\n if (_e113 <= 0f) {\n let _e115 = (*c);\n return _e115;\n }\n let _e116 = (*c);\n let _e118 = unnamed.uVeilColor;\n let _e120 = unnamed.uVeilAlpha;\n return mix(_e116, _e118, vec3(_e120));\n}\n\nfn applyColourGrade_u0028_vf3_u003b(c_1: ptr<function, vec3<f32>>) -> vec3<f32> {\n var clamped: vec3<f32>;\n var uvw: vec3<f32>;\n\n let _e115 = unnamed.uGradeStrength;\n if (_e115 <= 0f) {\n let _e117 = (*c_1);\n return _e117;\n }\n let _e118 = (*c_1);\n clamped = clamp(_e118, vec3(0f), vec3(1f));\n let _e122 = clamped;\n let _e124 = unnamed.uGradeSize;\n let _e130 = unnamed.uGradeSize;\n uvw = (((_e122 * (_e124 - 1f)) + vec3(0.5f)) / vec3(_e130));\n let _e133 = (*c_1);\n let _e134 = uvw;\n let _e135 = textureSampleLevel(uGradeLut_t, uGradeLut_s, _e134, 0f);\n let _e138 = unnamed.uGradeStrength;\n return mix(_e133, _e135.xyz, vec3(_e138));\n}\n\nfn linearToSrgb_u0028_vf3_u003b(c_2: ptr<function, vec3<f32>>) -> vec3<f32> {\n var low: vec3<f32>;\n var high: vec3<f32>;\n\n let _e114 = (*c_2);\n low = (_e114 * 12.92f);\n let _e116 = (*c_2);\n high = ((pow(max(_e116, vec3<f32>(0f, 0f, 0f)), vec3<f32>(0.41666666f, 0.41666666f, 0.41666666f)) * 1.055f) - vec3(0.055f));\n let _e122 = low;\n let _e123 = high;\n let _e124 = (*c_2);\n return mix(_e122, _e123, step(vec3<f32>(0.0031308f, 0.0031308f, 0.0031308f), _e124));\n}\n\nfn acesFilmic_u0028_vf3_u003b(x: ptr<function, vec3<f32>>) -> vec3<f32> {\n var v: vec3<f32>;\n var a: vec3<f32>;\n var b: vec3<f32>;\n\n let _e116 = unnamed.uOutputExposure;\n let _e117 = (*x);\n (*x) = (_e117 * _e116);\n let _e119 = (*x);\n v = (mat3x3<f32>(vec3<f32>(0.59719f, 0.076f, 0.0284f), vec3<f32>(0.35458f, 0.90834f, 0.13383f), vec3<f32>(0.04823f, 0.01566f, 0.83777f)) * _e119);\n let _e121 = v;\n let _e122 = v;\n a = ((_e121 * (_e122 + vec3(0.0245786f))) - vec3(0.000090537f));\n let _e128 = v;\n let _e129 = v;\n b = ((_e128 * ((_e129 * 0.983729f) + vec3(0.432951f))) + vec3(0.238081f));\n let _e136 = a;\n let _e137 = b;\n return clamp((mat3x3<f32>(vec3<f32>(1.60475f, -0.10208f, -0.00327f), vec3<f32>(-0.53108f, 1.10813f, -0.07276f), vec3<f32>(-0.07367f, -0.00605f, 1.07602f)) * (_e136 / _e137)), vec3(0f), vec3(1f));\n}\n\nfn grade_u0028_vf3_u003b(c_3: ptr<function, vec3<f32>>) -> vec3<f32> {\n var param: vec3<f32>;\n var param_1: vec3<f32>;\n\n let _e115 = unnamed.uOutputTransform;\n if (_e115 == 0i) {\n let _e117 = (*c_3);\n return _e117;\n }\n let _e119 = unnamed.uOutputTransform;\n if (_e119 == 2i) {\n let _e121 = (*c_3);\n param = _e121;\n let _e122 = acesFilmic_u0028_vf3_u003b((&param));\n (*c_3) = _e122;\n }\n let _e123 = (*c_3);\n param_1 = _e123;\n let _e124 = linearToSrgb_u0028_vf3_u003b((&param_1));\n return _e124;\n}\n\nfn withBloom_u0028_vf3_u003b(c_4: ptr<function, vec3<f32>>) -> vec3<f32> {\n let _e113 = unnamed.uBloomStrength;\n if (_e113 <= 0f) {\n let _e115 = (*c_4);\n return _e115;\n }\n let _e116 = (*c_4);\n let _e117 = vUv_1;\n let _e118 = textureSampleLevel(uBloom_t, uBloom_s, _e117, 0f);\n let _e121 = unnamed.uBloomStrength;\n return (_e116 + (_e118.xyz * _e121));\n}\n\nfn circleOfConfusion_u0028_f1_u003b(viewDepth: ptr<function, f32>) -> f32 {\n var offPlane: f32;\n\n let _e113 = (*viewDepth);\n let _e115 = unnamed.uFocusDistance;\n let _e119 = unnamed.uFocusRange;\n offPlane = (abs((_e113 - _e115)) - _e119);\n let _e121 = offPlane;\n let _e123 = unnamed.uFocusRange;\n return clamp((_e121 / _e123), 0f, 1f);\n}\n\nfn viewDepthOf_u0028_vf2_u003b(uv: ptr<function, vec2<f32>>) -> f32 {\n var z: f32;\n\n let _e113 = (*uv);\n let _e114 = textureSampleLevel(uDepth_t, uDepth_s, _e113, 0f);\n z = (1f - (_e114.x * 2f));\n let _e120 = unnamed.uDepthToView[0u];\n let _e121 = z;\n let _e125 = unnamed.uDepthToView[1u];\n let _e130 = unnamed.uDepthToView[2u];\n let _e131 = z;\n let _e135 = unnamed.uDepthToView[3u];\n return (-(((_e120 * _e121) + _e125)) / ((_e130 * _e131) + _e135));\n}\n\nfn dofTap_u0028_vf2_u003b_f1_u003b_f1_u003b(direction: ptr<function, vec2<f32>>, radius: ptr<function, f32>, centreDepth: ptr<function, f32>) -> vec4<f32> {\n var uv_1: vec2<f32>;\n var depth: f32;\n var param_2: vec2<f32>;\n var weight: f32;\n var local: f32;\n var param_3: f32;\n\n let _e120 = vUv_1;\n let _e121 = (*direction);\n let _e122 = (*radius);\n let _e125 = unnamed.uDofAspect;\n uv_1 = (_e120 + ((_e121 * _e122) * _e125));\n let _e128 = uv_1;\n param_2 = _e128;\n let _e129 = viewDepthOf_u0028_vf2_u003b((&param_2));\n depth = _e129;\n let _e130 = depth;\n let _e131 = (*centreDepth);\n if (_e130 >= _e131) {\n local = 1f;\n } else {\n let _e133 = depth;\n param_3 = _e133;\n let _e134 = circleOfConfusion_u0028_f1_u003b((&param_3));\n local = _e134;\n }\n let _e135 = local;\n weight = _e135;\n let _e136 = uv_1;\n let _e137 = textureSampleLevel(uScene_t, uScene_s, _e136, 0f);\n let _e139 = weight;\n let _e140 = (_e137.xyz * _e139);\n let _e141 = weight;\n return vec4<f32>(_e140.x, _e140.y, _e140.z, _e141);\n}\n\nfn depthOfField_u0028_vf3_u003b(centre: ptr<function, vec3<f32>>) -> vec3<f32> {\n var depth_1: f32;\n var param_4: vec2<f32>;\n var coc: f32;\n var param_5: f32;\n var radius_1: f32;\n var sum: vec4<f32>;\n var param_6: vec2<f32>;\n var param_7: f32;\n var param_8: f32;\n var param_9: vec2<f32>;\n var param_10: f32;\n var param_11: f32;\n var param_12: vec2<f32>;\n var param_13: f32;\n var param_14: f32;\n var param_15: vec2<f32>;\n var param_16: f32;\n var param_17: f32;\n var param_18: vec2<f32>;\n var param_19: f32;\n var param_20: f32;\n var param_21: vec2<f32>;\n var param_22: f32;\n var param_23: f32;\n var param_24: vec2<f32>;\n var param_25: f32;\n var param_26: f32;\n var param_27: vec2<f32>;\n var param_28: f32;\n var param_29: f32;\n\n let _e142 = vUv_1;\n param_4 = _e142;\n let _e143 = viewDepthOf_u0028_vf2_u003b((&param_4));\n depth_1 = _e143;\n let _e144 = depth_1;\n param_5 = _e144;\n let _e145 = circleOfConfusion_u0028_f1_u003b((&param_5));\n coc = _e145;\n let _e146 = coc;\n if (_e146 <= 0f) {\n let _e148 = (*centre);\n return _e148;\n }\n let _e149 = coc;\n let _e151 = unnamed.uDofStrength;\n radius_1 = (_e149 * _e151);\n let _e153 = (*centre);\n sum = vec4<f32>(_e153.x, _e153.y, _e153.z, 1f);\n param_6 = vec2<f32>(0.25f, 0f);\n let _e158 = radius_1;\n param_7 = _e158;\n let _e159 = depth_1;\n param_8 = _e159;\n let _e160 = dofTap_u0028_vf2_u003b_f1_u003b_f1_u003b((&param_6), (&param_7), (&param_8));\n let _e161 = sum;\n sum = (_e161 + _e160);\n param_9 = vec2<f32>(-0.31929f, 0.292496f);\n let _e163 = radius_1;\n param_10 = _e163;\n let _e164 = depth_1;\n param_11 = _e164;\n let _e165 = dofTap_u0028_vf2_u003b_f1_u003b_f1_u003b((&param_9), (&param_10), (&param_11));\n let _e166 = sum;\n sum = (_e166 + _e165);\n param_12 = vec2<f32>(0.048872f, -0.556877f);\n let _e168 = radius_1;\n param_13 = _e168;\n let _e169 = depth_1;\n param_14 = _e169;\n let _e170 = dofTap_u0028_vf2_u003b_f1_u003b_f1_u003b((&param_12), (&param_13), (&param_14));\n let _e171 = sum;\n sum = (_e171 + _e170);\n param_15 = vec2<f32>(0.402444f, 0.524918f);\n let _e173 = radius_1;\n param_16 = _e173;\n let _e174 = depth_1;\n param_17 = _e174;\n let _e175 = dofTap_u0028_vf2_u003b_f1_u003b_f1_u003b((&param_15), (&param_16), (&param_17));\n let _e176 = sum;\n sum = (_e176 + _e175);\n param_18 = vec2<f32>(-0.738535f, -0.130636f);\n let _e178 = radius_1;\n param_19 = _e178;\n let _e179 = depth_1;\n param_20 = _e179;\n let _e180 = dofTap_u0028_vf2_u003b_f1_u003b_f1_u003b((&param_18), (&param_19), (&param_20));\n let _e181 = sum;\n sum = (_e181 + _e180);\n param_21 = vec2<f32>(0.699605f, -0.445031f);\n let _e183 = radius_1;\n param_22 = _e183;\n let _e184 = depth_1;\n param_23 = _e184;\n let _e185 = dofTap_u0028_vf2_u003b_f1_u003b_f1_u003b((&param_21), (&param_22), (&param_23));\n let _e186 = sum;\n sum = (_e186 + _e185);\n param_24 = vec2<f32>(-0.234004f, 0.870484f);\n let _e188 = radius_1;\n param_25 = _e188;\n let _e189 = depth_1;\n param_26 = _e189;\n let _e190 = dofTap_u0028_vf2_u003b_f1_u003b_f1_u003b((&param_24), (&param_25), (&param_26));\n let _e191 = sum;\n sum = (_e191 + _e190);\n param_27 = vec2<f32>(-0.446271f, -0.859268f);\n let _e193 = radius_1;\n param_28 = _e193;\n let _e194 = depth_1;\n param_29 = _e194;\n let _e195 = dofTap_u0028_vf2_u003b_f1_u003b_f1_u003b((&param_27), (&param_28), (&param_29));\n let _e196 = sum;\n sum = (_e196 + _e195);\n let _e198 = sum;\n let _e201 = sum[3u];\n return (_e198.xyz / vec3(_e201));\n}\n\nfn cameraBlur_u0028_vf3_u003b(scene: ptr<function, vec3<f32>>) -> vec3<f32> {\n var depth_2: f32;\n var clip: vec4<f32>;\n var previous: vec4<f32>;\n var wasUv: vec2<f32>;\n var velocity: vec2<f32>;\n var distance_: f32;\n var sum_1: vec3<f32>;\n var i: i32;\n var t: f32;\n\n let _e121 = vUv_1;\n let _e122 = textureSampleLevel(uDepth_t, uDepth_s, _e121, 0f);\n depth_2 = _e122.x;\n let _e124 = vUv_1;\n let _e127 = ((_e124 * 2f) - vec2(1f));\n let _e128 = depth_2;\n clip = vec4<f32>(_e127.x, _e127.y, (1f - (_e128 * 2f)), 1f);\n let _e135 = unnamed.uReprojection;\n let _e136 = clip;\n previous = (_e135 * _e136);\n let _e139 = previous[3u];\n if (_e139 <= 0f) {\n let _e141 = (*scene);\n return _e141;\n }\n let _e142 = previous;\n let _e145 = previous[3u];\n wasUv = (((_e142.xy / vec2(_e145)) * 0.5f) + vec2(0.5f));\n let _e151 = vUv_1;\n let _e152 = wasUv;\n let _e155 = unnamed.uMotionStrength;\n velocity = ((_e151 - _e152) * _e155);\n let _e157 = velocity;\n distance_ = length(_e157);\n let _e159 = distance_;\n if (_e159 < 0.0001f) {\n let _e161 = (*scene);\n return _e161;\n }\n let _e162 = distance_;\n let _e164 = unnamed.uMotionMax;\n if (_e162 > _e164) {\n let _e167 = unnamed.uMotionMax;\n let _e168 = distance_;\n let _e170 = velocity;\n velocity = (_e170 * (_e167 / _e168));\n }\n let _e172 = (*scene);\n sum_1 = _e172;\n i = 1i;\n loop {\n let _e173 = i;\n if (_e173 <= 4i) {\n let _e175 = i;\n t = ((f32(_e175) / 4f) * 0.5f);\n let _e179 = vUv_1;\n let _e180 = velocity;\n let _e181 = t;\n let _e184 = textureSampleLevel(uScene_t, uScene_s, (_e179 + (_e180 * _e181)), 0f);\n let _e186 = sum_1;\n sum_1 = (_e186 + _e184.xyz);\n let _e188 = vUv_1;\n let _e189 = velocity;\n let _e190 = t;\n let _e193 = textureSampleLevel(uScene_t, uScene_s, (_e188 - (_e189 * _e190)), 0f);\n let _e195 = sum_1;\n sum_1 = (_e195 + _e193.xyz);\n continue;\n } else {\n break;\n }\n continuing {\n let _e197 = i;\n i = (_e197 + 1i);\n }\n }\n let _e199 = sum_1;\n return (_e199 / vec3(9f));\n}\n\nfn main_1() {\n var scene_1: vec3<f32>;\n var param_30: vec3<f32>;\n var param_31: vec3<f32>;\n var ao: f32;\n var fromCentre: vec2<f32>;\n var radius_2: f32;\n var inner: f32;\n var edge: f32;\n var amount: f32;\n var param_32: vec3<f32>;\n var param_33: vec3<f32>;\n var param_34: vec3<f32>;\n var param_35: vec3<f32>;\n var step_: vec2<f32>;\n var sum_2: vec3<f32>;\n var i_1: i32;\n var blurred: vec3<f32>;\n var param_36: vec3<f32>;\n var param_37: vec3<f32>;\n var param_38: vec3<f32>;\n var param_39: vec3<f32>;\n\n let _e132 = vUv_1;\n let _e133 = textureSampleLevel(uScene_t, uScene_s, _e132, 0f);\n scene_1 = _e133.xyz;\n let _e136 = unnamed.uMotionStrength;\n if (_e136 > 0f) {\n let _e138 = scene_1;\n param_30 = _e138;\n let _e139 = cameraBlur_u0028_vf3_u003b((&param_30));\n scene_1 = _e139;\n }\n let _e141 = unnamed.uDofStrength;\n if (_e141 > 0f) {\n let _e143 = scene_1;\n param_31 = _e143;\n let _e144 = depthOfField_u0028_vf3_u003b((&param_31));\n scene_1 = _e144;\n }\n let _e145 = vUv_1;\n let _e146 = textureSampleLevel(uAo_t, uAo_s, _e145, 0f);\n let _e149 = unnamed.uAoStrength;\n ao = mix(1f, _e146.x, _e149);\n let _e151 = vUv_1;\n fromCentre = (_e151 - vec2(0.5f));\n let _e154 = fromCentre;\n radius_2 = (length((_e154 * vec2<f32>(1f, 0.62f))) * 2f);\n let _e159 = unnamed.uStrength;\n inner = mix(0.62f, 0.3f, _e159);\n let _e161 = inner;\n let _e162 = radius_2;\n edge = smoothstep(_e161, 1f, _e162);\n let _e164 = edge;\n let _e166 = unnamed.uStrength;\n amount = (_e164 * _e166);\n let _e168 = amount;\n if (_e168 <= 0f) {\n let _e170 = scene_1;\n let _e171 = ao;\n param_32 = (_e170 * _e171);\n let _e173 = withBloom_u0028_vf3_u003b((&param_32));\n param_33 = _e173;\n let _e174 = grade_u0028_vf3_u003b((&param_33));\n param_34 = _e174;\n let _e175 = applyColourGrade_u0028_vf3_u003b((&param_34));\n param_35 = _e175;\n let _e176 = withVeil_u0028_vf3_u003b((&param_35));\n fragColor = vec4<f32>(_e176.x, _e176.y, _e176.z, 1f);\n return;\n }\n let _e181 = fromCentre;\n let _e185 = unnamed.uReach;\n let _e187 = amount;\n step_ = ((normalize((_e181 + vec2<f32>(0.000001f, 0.000001f))) * _e185) * _e187);\n let _e189 = scene_1;\n sum_2 = _e189;\n i_1 = 1i;\n loop {\n let _e190 = i_1;\n if (_e190 <= 6i) {\n let _e192 = vUv_1;\n let _e193 = step_;\n let _e194 = i_1;\n let _e199 = textureSampleLevel(uScene_t, uScene_s, (_e192 + (_e193 * (f32(_e194) / 6f))), 0f);\n let _e201 = sum_2;\n sum_2 = (_e201 + _e199.xyz);\n continue;\n } else {\n break;\n }\n continuing {\n let _e203 = i_1;\n i_1 = (_e203 + 1i);\n }\n }\n let _e205 = sum_2;\n blurred = (_e205 / vec3(7f));\n let _e208 = scene_1;\n let _e209 = blurred;\n let _e210 = amount;\n let _e213 = ao;\n param_36 = (mix(_e208, _e209, vec3(_e210)) * _e213);\n let _e215 = withBloom_u0028_vf3_u003b((&param_36));\n param_37 = _e215;\n let _e216 = grade_u0028_vf3_u003b((&param_37));\n param_38 = _e216;\n let _e217 = applyColourGrade_u0028_vf3_u003b((&param_38));\n param_39 = _e217;\n let _e218 = withVeil_u0028_vf3_u003b((&param_39));\n fragColor = vec4<f32>(_e218.x, _e218.y, _e218.z, 1f);\n return;\n}\n\n@fragment \nfn main(@location(0) vUv: vec2<f32>) -> @location(0) vec4<f32> {\n vUv_1 = vUv;\n main_1();\n let _e3 = fragColor;\n return _e3;\n}\n";
8
+ export const RUSH_FRAG_WGSL = "struct Uniforms {\n uStrength: f32,\n uReach: f32,\n uOutputTransform: i32,\n uOutputExposure: f32,\n uReprojection: mat4x4<f32>,\n uMotionStrength: f32,\n uMotionMax: f32,\n uAoStrength: f32,\n uBloomStrength: f32,\n uVeilColor: vec3<f32>,\n uVeilAlpha: f32,\n uVignette: f32,\n uGrain: vec2<f32>,\n uAutoExposure: f32,\n uLocalExposure: f32,\n uGradeStrength: f32,\n uGradeSize: f32,\n uFocusDistance: f32,\n uFocusRange: f32,\n uDofStrength: f32,\n uDofAspect: vec2<f32>,\n uDepthToView: vec4<f32>,\n}\n\n@group(0) @binding(1) \nvar<uniform> unnamed: Uniforms;\n@group(0) @binding(40) \nvar uExposureHeld_t: texture_2d<f32>;\n@group(0) @binding(42) \nvar uExposureLocal_t: texture_2d<f32>;\n@group(0) @binding(43) \nvar uExposureLocal_s: sampler;\n@group(0) @binding(34) \nvar uDepth_t: texture_2d<f32>;\n@group(0) @binding(35) \nvar uDepth_s: sampler;\nvar<private> vUv_1: vec2<f32>;\n@group(0) @binding(32) \nvar uScene_t: texture_2d<f32>;\n@group(0) @binding(33) \nvar uScene_s: sampler;\n@group(0) @binding(38) \nvar uBloom_t: texture_2d<f32>;\n@group(0) @binding(39) \nvar uBloom_s: sampler;\n@group(0) @binding(44) \nvar uGradeLut_t: texture_3d<f32>;\n@group(0) @binding(45) \nvar uGradeLut_s: sampler;\nvar<private> gl_FragCoord_1: vec4<f32>;\n@group(0) @binding(36) \nvar uAo_t: texture_2d<f32>;\n@group(0) @binding(37) \nvar uAo_s: sampler;\nvar<private> fragColor: vec4<f32>;\n@group(0) @binding(41) \nvar uExposureHeld_s: sampler;\n\nfn grainNoise_u0028_vu2_u003b_u1_u003b(p: ptr<function, vec2<u32>>, seed: ptr<function, u32>) -> f32 {\n var h: u32;\n\n let _e152 = (*p)[0u];\n let _e155 = (*p)[1u];\n let _e158 = (*seed);\n h = (((_e152 * 1664525u) + (_e155 * 1013904223u)) + (_e158 * 2654435769u));\n let _e161 = h;\n let _e164 = h;\n h = (_e164 ^ (_e161 >> bitcast<u32>(16u)));\n let _e166 = h;\n h = (_e166 * 2246822519u);\n let _e168 = h;\n let _e171 = h;\n h = (_e171 ^ (_e168 >> bitcast<u32>(13u)));\n let _e173 = h;\n h = (_e173 * 3266489917u);\n let _e175 = h;\n let _e178 = h;\n h = (_e178 ^ (_e175 >> bitcast<u32>(16u)));\n let _e180 = h;\n return (f32(_e180) * 0.00000000023283064f);\n}\n\nfn withGrain_u0028_vf3_u003b_vf2_u003b(c: ptr<function, vec3<f32>>, fragCoord: ptr<function, vec2<f32>>) -> vec3<f32> {\n var luma: f32;\n var weight: f32;\n var n: f32;\n var param: vec2<u32>;\n var param_1: u32;\n\n let _e157 = unnamed.uGrain[0u];\n if (_e157 <= 0f) {\n let _e159 = (*c);\n return _e159;\n }\n let _e160 = (*c);\n luma = dot(clamp(_e160, vec3(0f), vec3(1f)), vec3<f32>(0.2126f, 0.7152f, 0.0722f));\n let _e165 = luma;\n let _e167 = luma;\n weight = (0.25f + ((3f * _e165) * (1f - _e167)));\n let _e171 = (*fragCoord);\n let _e175 = unnamed.uGrain[1u];\n param = vec2<u32>(_e171);\n param_1 = u32(_e175);\n let _e177 = grainNoise_u0028_vu2_u003b_u1_u003b((&param), (&param_1));\n n = (_e177 - 0.5f);\n let _e179 = (*c);\n let _e180 = n;\n let _e184 = unnamed.uGrain[0u];\n let _e186 = weight;\n return (_e179 + vec3((((2f * _e180) * _e184) * _e186)));\n}\n\nfn withVeil_u0028_vf3_u003b(c_1: ptr<function, vec3<f32>>) -> vec3<f32> {\n let _e150 = unnamed.uVeilAlpha;\n if (_e150 <= 0f) {\n let _e152 = (*c_1);\n return _e152;\n }\n let _e153 = (*c_1);\n let _e155 = unnamed.uVeilColor;\n let _e157 = unnamed.uVeilAlpha;\n return mix(_e153, _e155, vec3(_e157));\n}\n\nfn applyColourGrade_u0028_vf3_u003b(c_2: ptr<function, vec3<f32>>) -> vec3<f32> {\n var clamped: vec3<f32>;\n var uvw: vec3<f32>;\n\n let _e152 = unnamed.uGradeStrength;\n if (_e152 <= 0f) {\n let _e154 = (*c_2);\n return _e154;\n }\n let _e155 = (*c_2);\n clamped = clamp(_e155, vec3(0f), vec3(1f));\n let _e159 = clamped;\n let _e161 = unnamed.uGradeSize;\n let _e167 = unnamed.uGradeSize;\n uvw = (((_e159 * (_e161 - 1f)) + vec3(0.5f)) / vec3(_e167));\n let _e170 = (*c_2);\n let _e171 = uvw;\n let _e172 = textureSampleLevel(uGradeLut_t, uGradeLut_s, _e171, 0f);\n let _e175 = unnamed.uGradeStrength;\n return mix(_e170, _e172.xyz, vec3(_e175));\n}\n\nfn linearToSrgb_u0028_vf3_u003b(c_3: ptr<function, vec3<f32>>) -> vec3<f32> {\n var low: vec3<f32>;\n var high: vec3<f32>;\n\n let _e151 = (*c_3);\n low = (_e151 * 12.92f);\n let _e153 = (*c_3);\n high = ((pow(max(_e153, vec3<f32>(0f, 0f, 0f)), vec3<f32>(0.41666666f, 0.41666666f, 0.41666666f)) * 1.055f) - vec3(0.055f));\n let _e159 = low;\n let _e160 = high;\n let _e161 = (*c_3);\n return mix(_e159, _e160, step(vec3<f32>(0.0031308f, 0.0031308f, 0.0031308f), _e161));\n}\n\nfn acesFilmic_u0028_vf3_u003b(x: ptr<function, vec3<f32>>) -> vec3<f32> {\n var v: vec3<f32>;\n var a: vec3<f32>;\n var b: vec3<f32>;\n\n let _e153 = unnamed.uOutputExposure;\n let _e154 = (*x);\n (*x) = (_e154 * _e153);\n let _e156 = (*x);\n v = (mat3x3<f32>(vec3<f32>(0.59719f, 0.076f, 0.0284f), vec3<f32>(0.35458f, 0.90834f, 0.13383f), vec3<f32>(0.04823f, 0.01566f, 0.83777f)) * _e156);\n let _e158 = v;\n let _e159 = v;\n a = ((_e158 * (_e159 + vec3(0.0245786f))) - vec3(0.000090537f));\n let _e165 = v;\n let _e166 = v;\n b = ((_e165 * ((_e166 * 0.983729f) + vec3(0.432951f))) + vec3(0.238081f));\n let _e173 = a;\n let _e174 = b;\n return clamp((mat3x3<f32>(vec3<f32>(1.60475f, -0.10208f, -0.00327f), vec3<f32>(-0.53108f, 1.10813f, -0.07276f), vec3<f32>(-0.07367f, -0.00605f, 1.07602f)) * (_e173 / _e174)), vec3(0f), vec3(1f));\n}\n\nfn grade_u0028_vf3_u003b(c_4: ptr<function, vec3<f32>>) -> vec3<f32> {\n var param_2: vec3<f32>;\n var param_3: vec3<f32>;\n\n let _e152 = unnamed.uOutputTransform;\n if (_e152 == 0i) {\n let _e154 = (*c_4);\n return _e154;\n }\n let _e156 = unnamed.uOutputTransform;\n if (_e156 == 2i) {\n let _e158 = (*c_4);\n param_2 = _e158;\n let _e159 = acesFilmic_u0028_vf3_u003b((&param_2));\n (*c_4) = _e159;\n }\n let _e160 = (*c_4);\n param_3 = _e160;\n let _e161 = linearToSrgb_u0028_vf3_u003b((&param_3));\n return _e161;\n}\n\nfn withVignette_u0028_vf3_u003b_vf2_u003b_vf2_u003b(c_5: ptr<function, vec3<f32>>, uv: ptr<function, vec2<f32>>, size: ptr<function, vec2<f32>>) -> vec3<f32> {\n var d: vec2<f32>;\n var corner: vec2<f32>;\n var r2_: f32;\n var falloff: f32;\n\n let _e156 = unnamed.uVignette;\n if (_e156 <= 0f) {\n let _e158 = (*c_5);\n return _e158;\n }\n let _e159 = (*uv);\n let _e162 = (*size);\n d = ((_e159 - vec2(0.5f)) * _e162);\n let _e164 = (*size);\n corner = (_e164 * 0.5f);\n let _e166 = d;\n let _e167 = d;\n let _e169 = corner;\n let _e170 = corner;\n r2_ = (dot(_e166, _e167) / dot(_e169, _e170));\n let _e174 = unnamed.uVignette;\n let _e175 = r2_;\n falloff = (1f + (_e174 * _e175));\n let _e178 = (*c_5);\n let _e179 = falloff;\n let _e180 = falloff;\n return (_e178 / vec3((_e179 * _e180)));\n}\n\nfn autoExposureGain_u0028_() -> f32 {\n var held: f32;\n var stops: f32;\n\n let _e151 = unnamed.uAutoExposure;\n if (_e151 <= 0f) {\n return 1f;\n }\n let _e153 = textureLoad(uExposureHeld_t, vec2<i32>(0i, 0i), 0i);\n held = _e153.x;\n let _e156 = unnamed.uAutoExposure;\n let _e157 = held;\n stops = (_e156 * (-2.473931f - _e157));\n let _e160 = stops;\n return exp2(clamp(_e160, -6f, 6f));\n}\n\nfn localBlock_u0028_vf2_u003b_f1_u003b(uv_1: ptr<function, vec2<f32>>, block: ptr<function, f32>) -> vec2<f32> {\n var inside: vec2<f32>;\n\n let _e151 = (*uv_1);\n inside = clamp(_e151, vec2<f32>(0.015625f, 0.015625f), vec2<f32>(0.984375f, 0.984375f));\n let _e153 = (*block);\n let _e155 = inside[0u];\n let _e159 = inside[1u];\n let _e161 = textureSampleLevel(uExposureLocal_t, uExposureLocal_s, vec2<f32>(((_e153 + _e155) / 11f), _e159), 0f);\n return _e161.xy;\n}\n\nfn localExposureGain_u0028_vf2_u003b_vf3_u003b(uv_2: ptr<function, vec2<f32>>, light: ptr<function, vec3<f32>>) -> f32 {\n var held_1: f32;\n var pixel: f32;\n var b_1: f32;\n var lower: f32;\n var upper: f32;\n var banded: vec2<f32>;\n var param_4: vec2<f32>;\n var param_5: f32;\n var param_6: vec2<f32>;\n var param_7: f32;\n var tileMean: f32;\n var param_8: vec2<f32>;\n var param_9: f32;\n var bilateral: f32;\n var local: f32;\n var local_1: f32;\n var stops_1: f32;\n\n let _e168 = unnamed.uLocalExposure;\n if (_e168 <= 0f) {\n return 1f;\n }\n let _e170 = textureLoad(uExposureHeld_t, vec2<i32>(0i, 0i), 0i);\n held_1 = _e170.x;\n let _e172 = (*light);\n pixel = clamp(log2(max(dot(_e172, vec3<f32>(0.2126f, 0.7152f, 0.0722f)), 0.00000001f)), -12f, 8f);\n let _e177 = pixel;\n b_1 = (((_e177 - -12f) / 2f) - 0.5f);\n let _e181 = b_1;\n lower = clamp(floor(_e181), 0f, 9f);\n let _e184 = lower;\n upper = min((_e184 + 1f), 9f);\n let _e187 = (*uv_2);\n param_4 = _e187;\n let _e188 = lower;\n param_5 = _e188;\n let _e189 = localBlock_u0028_vf2_u003b_f1_u003b((&param_4), (&param_5));\n let _e190 = (*uv_2);\n param_6 = _e190;\n let _e191 = upper;\n param_7 = _e191;\n let _e192 = localBlock_u0028_vf2_u003b_f1_u003b((&param_6), (&param_7));\n let _e193 = b_1;\n let _e194 = lower;\n banded = mix(_e189, _e192, vec2(clamp((_e193 - _e194), 0f, 1f)));\n let _e199 = (*uv_2);\n param_8 = _e199;\n param_9 = 10f;\n let _e200 = localBlock_u0028_vf2_u003b_f1_u003b((&param_8), (&param_9));\n tileMean = _e200.x;\n let _e203 = banded[1u];\n if (_e203 > 0.001f) {\n let _e206 = banded[0u];\n let _e208 = banded[1u];\n local = (_e206 / _e208);\n } else {\n let _e210 = tileMean;\n local = _e210;\n }\n let _e211 = local;\n bilateral = _e211;\n let _e212 = bilateral;\n let _e213 = tileMean;\n local_1 = mix(_e212, _e213, 0.4f);\n let _e216 = unnamed.uLocalExposure;\n let _e217 = held_1;\n let _e218 = local_1;\n stops_1 = (_e216 * (_e217 - _e218));\n let _e221 = stops_1;\n return exp2(clamp(_e221, -3f, 3f));\n}\n\nfn finish_u0028_vf3_u003b(light_1: ptr<function, vec3<f32>>) -> vec3<f32> {\n var local_2: f32;\n var param_10: vec2<f32>;\n var param_11: vec3<f32>;\n var lensed: vec3<f32>;\n var param_12: vec3<f32>;\n var param_13: vec2<f32>;\n var param_14: vec2<f32>;\n var param_15: vec3<f32>;\n var param_16: vec3<f32>;\n var param_17: vec3<f32>;\n var param_18: vec3<f32>;\n var param_19: vec2<f32>;\n\n let _e161 = vUv_1;\n param_10 = _e161;\n let _e162 = (*light_1);\n param_11 = _e162;\n let _e163 = localExposureGain_u0028_vf2_u003b_vf3_u003b((&param_10), (&param_11));\n local_2 = _e163;\n let _e164 = autoExposureGain_u0028_();\n let _e165 = local_2;\n let _e167 = (*light_1);\n (*light_1) = (_e167 * (_e164 * _e165));\n let _e169 = textureDimensions(uScene_t, 0i);\n let _e172 = (*light_1);\n param_12 = _e172;\n let _e173 = vUv_1;\n param_13 = _e173;\n param_14 = vec2<f32>(vec2<i32>(_e169));\n let _e174 = withVignette_u0028_vf3_u003b_vf2_u003b_vf2_u003b((&param_12), (&param_13), (&param_14));\n lensed = _e174;\n let _e175 = lensed;\n param_15 = _e175;\n let _e176 = grade_u0028_vf3_u003b((&param_15));\n param_16 = _e176;\n let _e177 = applyColourGrade_u0028_vf3_u003b((&param_16));\n param_17 = _e177;\n let _e178 = withVeil_u0028_vf3_u003b((&param_17));\n param_18 = _e178;\n let _e179 = gl_FragCoord_1;\n param_19 = _e179.xy;\n let _e181 = withGrain_u0028_vf3_u003b_vf2_u003b((&param_18), (&param_19));\n return _e181;\n}\n\nfn withBloom_u0028_vf3_u003b(c_6: ptr<function, vec3<f32>>) -> vec3<f32> {\n let _e150 = unnamed.uBloomStrength;\n if (_e150 <= 0f) {\n let _e152 = (*c_6);\n return _e152;\n }\n let _e153 = (*c_6);\n let _e154 = vUv_1;\n let _e155 = textureSampleLevel(uBloom_t, uBloom_s, _e154, 0f);\n let _e158 = unnamed.uBloomStrength;\n return (_e153 + (_e155.xyz * _e158));\n}\n\nfn circleOfConfusion_u0028_f1_u003b(viewDepth: ptr<function, f32>) -> f32 {\n var offPlane: f32;\n\n let _e150 = (*viewDepth);\n let _e152 = unnamed.uFocusDistance;\n let _e156 = unnamed.uFocusRange;\n offPlane = (abs((_e150 - _e152)) - _e156);\n let _e158 = offPlane;\n let _e160 = unnamed.uFocusRange;\n return clamp((_e158 / _e160), 0f, 1f);\n}\n\nfn viewDepthOf_u0028_vf2_u003b(uv_3: ptr<function, vec2<f32>>) -> f32 {\n var z: f32;\n\n let _e150 = (*uv_3);\n let _e151 = textureSampleLevel(uDepth_t, uDepth_s, _e150, 0f);\n z = (1f - (_e151.x * 2f));\n let _e157 = unnamed.uDepthToView[0u];\n let _e158 = z;\n let _e162 = unnamed.uDepthToView[1u];\n let _e167 = unnamed.uDepthToView[2u];\n let _e168 = z;\n let _e172 = unnamed.uDepthToView[3u];\n return (-(((_e157 * _e158) + _e162)) / ((_e167 * _e168) + _e172));\n}\n\nfn dofTap_u0028_vf2_u003b_f1_u003b_f1_u003b(direction: ptr<function, vec2<f32>>, radius: ptr<function, f32>, centreDepth: ptr<function, f32>) -> vec4<f32> {\n var uv_4: vec2<f32>;\n var depth: f32;\n var param_20: vec2<f32>;\n var weight_1: f32;\n var local_3: f32;\n var param_21: f32;\n\n let _e157 = vUv_1;\n let _e158 = (*direction);\n let _e159 = (*radius);\n let _e162 = unnamed.uDofAspect;\n uv_4 = (_e157 + ((_e158 * _e159) * _e162));\n let _e165 = uv_4;\n param_20 = _e165;\n let _e166 = viewDepthOf_u0028_vf2_u003b((&param_20));\n depth = _e166;\n let _e167 = depth;\n let _e168 = (*centreDepth);\n if (_e167 >= _e168) {\n local_3 = 1f;\n } else {\n let _e170 = depth;\n param_21 = _e170;\n let _e171 = circleOfConfusion_u0028_f1_u003b((&param_21));\n local_3 = _e171;\n }\n let _e172 = local_3;\n weight_1 = _e172;\n let _e173 = uv_4;\n let _e174 = textureSampleLevel(uScene_t, uScene_s, _e173, 0f);\n let _e176 = weight_1;\n let _e177 = (_e174.xyz * _e176);\n let _e178 = weight_1;\n return vec4<f32>(_e177.x, _e177.y, _e177.z, _e178);\n}\n\nfn depthOfField_u0028_vf3_u003b(centre: ptr<function, vec3<f32>>) -> vec3<f32> {\n var depth_1: f32;\n var param_22: vec2<f32>;\n var coc: f32;\n var param_23: f32;\n var radius_1: f32;\n var sum: vec4<f32>;\n var param_24: vec2<f32>;\n var param_25: f32;\n var param_26: f32;\n var param_27: vec2<f32>;\n var param_28: f32;\n var param_29: f32;\n var param_30: vec2<f32>;\n var param_31: f32;\n var param_32: f32;\n var param_33: vec2<f32>;\n var param_34: f32;\n var param_35: f32;\n var param_36: vec2<f32>;\n var param_37: f32;\n var param_38: f32;\n var param_39: vec2<f32>;\n var param_40: f32;\n var param_41: f32;\n var param_42: vec2<f32>;\n var param_43: f32;\n var param_44: f32;\n var param_45: vec2<f32>;\n var param_46: f32;\n var param_47: f32;\n\n let _e179 = vUv_1;\n param_22 = _e179;\n let _e180 = viewDepthOf_u0028_vf2_u003b((&param_22));\n depth_1 = _e180;\n let _e181 = depth_1;\n param_23 = _e181;\n let _e182 = circleOfConfusion_u0028_f1_u003b((&param_23));\n coc = _e182;\n let _e183 = coc;\n if (_e183 <= 0f) {\n let _e185 = (*centre);\n return _e185;\n }\n let _e186 = coc;\n let _e188 = unnamed.uDofStrength;\n radius_1 = (_e186 * _e188);\n let _e190 = (*centre);\n sum = vec4<f32>(_e190.x, _e190.y, _e190.z, 1f);\n param_24 = vec2<f32>(0.25f, 0f);\n let _e195 = radius_1;\n param_25 = _e195;\n let _e196 = depth_1;\n param_26 = _e196;\n let _e197 = dofTap_u0028_vf2_u003b_f1_u003b_f1_u003b((&param_24), (&param_25), (&param_26));\n let _e198 = sum;\n sum = (_e198 + _e197);\n param_27 = vec2<f32>(-0.31929f, 0.292496f);\n let _e200 = radius_1;\n param_28 = _e200;\n let _e201 = depth_1;\n param_29 = _e201;\n let _e202 = dofTap_u0028_vf2_u003b_f1_u003b_f1_u003b((&param_27), (&param_28), (&param_29));\n let _e203 = sum;\n sum = (_e203 + _e202);\n param_30 = vec2<f32>(0.048872f, -0.556877f);\n let _e205 = radius_1;\n param_31 = _e205;\n let _e206 = depth_1;\n param_32 = _e206;\n let _e207 = dofTap_u0028_vf2_u003b_f1_u003b_f1_u003b((&param_30), (&param_31), (&param_32));\n let _e208 = sum;\n sum = (_e208 + _e207);\n param_33 = vec2<f32>(0.402444f, 0.524918f);\n let _e210 = radius_1;\n param_34 = _e210;\n let _e211 = depth_1;\n param_35 = _e211;\n let _e212 = dofTap_u0028_vf2_u003b_f1_u003b_f1_u003b((&param_33), (&param_34), (&param_35));\n let _e213 = sum;\n sum = (_e213 + _e212);\n param_36 = vec2<f32>(-0.738535f, -0.130636f);\n let _e215 = radius_1;\n param_37 = _e215;\n let _e216 = depth_1;\n param_38 = _e216;\n let _e217 = dofTap_u0028_vf2_u003b_f1_u003b_f1_u003b((&param_36), (&param_37), (&param_38));\n let _e218 = sum;\n sum = (_e218 + _e217);\n param_39 = vec2<f32>(0.699605f, -0.445031f);\n let _e220 = radius_1;\n param_40 = _e220;\n let _e221 = depth_1;\n param_41 = _e221;\n let _e222 = dofTap_u0028_vf2_u003b_f1_u003b_f1_u003b((&param_39), (&param_40), (&param_41));\n let _e223 = sum;\n sum = (_e223 + _e222);\n param_42 = vec2<f32>(-0.234004f, 0.870484f);\n let _e225 = radius_1;\n param_43 = _e225;\n let _e226 = depth_1;\n param_44 = _e226;\n let _e227 = dofTap_u0028_vf2_u003b_f1_u003b_f1_u003b((&param_42), (&param_43), (&param_44));\n let _e228 = sum;\n sum = (_e228 + _e227);\n param_45 = vec2<f32>(-0.446271f, -0.859268f);\n let _e230 = radius_1;\n param_46 = _e230;\n let _e231 = depth_1;\n param_47 = _e231;\n let _e232 = dofTap_u0028_vf2_u003b_f1_u003b_f1_u003b((&param_45), (&param_46), (&param_47));\n let _e233 = sum;\n sum = (_e233 + _e232);\n let _e235 = sum;\n let _e238 = sum[3u];\n return (_e235.xyz / vec3(_e238));\n}\n\nfn cameraBlur_u0028_vf3_u003b(scene: ptr<function, vec3<f32>>) -> vec3<f32> {\n var depth_2: f32;\n var clip: vec4<f32>;\n var previous: vec4<f32>;\n var wasUv: vec2<f32>;\n var velocity: vec2<f32>;\n var distance_: f32;\n var sum_1: vec3<f32>;\n var i: i32;\n var t: f32;\n\n let _e158 = vUv_1;\n let _e159 = textureSampleLevel(uDepth_t, uDepth_s, _e158, 0f);\n depth_2 = _e159.x;\n let _e161 = vUv_1;\n let _e164 = ((_e161 * 2f) - vec2(1f));\n let _e165 = depth_2;\n clip = vec4<f32>(_e164.x, _e164.y, (1f - (_e165 * 2f)), 1f);\n let _e172 = unnamed.uReprojection;\n let _e173 = clip;\n previous = (_e172 * _e173);\n let _e176 = previous[3u];\n if (_e176 <= 0f) {\n let _e178 = (*scene);\n return _e178;\n }\n let _e179 = previous;\n let _e182 = previous[3u];\n wasUv = (((_e179.xy / vec2(_e182)) * 0.5f) + vec2(0.5f));\n let _e188 = vUv_1;\n let _e189 = wasUv;\n let _e192 = unnamed.uMotionStrength;\n velocity = ((_e188 - _e189) * _e192);\n let _e194 = velocity;\n distance_ = length(_e194);\n let _e196 = distance_;\n if (_e196 < 0.0001f) {\n let _e198 = (*scene);\n return _e198;\n }\n let _e199 = distance_;\n let _e201 = unnamed.uMotionMax;\n if (_e199 > _e201) {\n let _e204 = unnamed.uMotionMax;\n let _e205 = distance_;\n let _e207 = velocity;\n velocity = (_e207 * (_e204 / _e205));\n }\n let _e209 = (*scene);\n sum_1 = _e209;\n i = 1i;\n loop {\n let _e210 = i;\n if (_e210 <= 4i) {\n let _e212 = i;\n t = ((f32(_e212) / 4f) * 0.5f);\n let _e216 = vUv_1;\n let _e217 = velocity;\n let _e218 = t;\n let _e221 = textureSampleLevel(uScene_t, uScene_s, (_e216 + (_e217 * _e218)), 0f);\n let _e223 = sum_1;\n sum_1 = (_e223 + _e221.xyz);\n let _e225 = vUv_1;\n let _e226 = velocity;\n let _e227 = t;\n let _e230 = textureSampleLevel(uScene_t, uScene_s, (_e225 - (_e226 * _e227)), 0f);\n let _e232 = sum_1;\n sum_1 = (_e232 + _e230.xyz);\n continue;\n } else {\n break;\n }\n continuing {\n let _e234 = i;\n i = (_e234 + 1i);\n }\n }\n let _e236 = sum_1;\n return (_e236 / vec3(9f));\n}\n\nfn main_1() {\n var scene_1: vec3<f32>;\n var param_48: vec3<f32>;\n var param_49: vec3<f32>;\n var ao: f32;\n var fromCentre: vec2<f32>;\n var radius_2: f32;\n var inner: f32;\n var edge: f32;\n var amount: f32;\n var param_50: vec3<f32>;\n var param_51: vec3<f32>;\n var step_: vec2<f32>;\n var sum_2: vec3<f32>;\n var i_1: i32;\n var blurred: vec3<f32>;\n var param_52: vec3<f32>;\n var param_53: vec3<f32>;\n\n let _e165 = vUv_1;\n let _e166 = textureSampleLevel(uScene_t, uScene_s, _e165, 0f);\n scene_1 = _e166.xyz;\n let _e169 = unnamed.uMotionStrength;\n if (_e169 > 0f) {\n let _e171 = scene_1;\n param_48 = _e171;\n let _e172 = cameraBlur_u0028_vf3_u003b((&param_48));\n scene_1 = _e172;\n }\n let _e174 = unnamed.uDofStrength;\n if (_e174 > 0f) {\n let _e176 = scene_1;\n param_49 = _e176;\n let _e177 = depthOfField_u0028_vf3_u003b((&param_49));\n scene_1 = _e177;\n }\n let _e178 = vUv_1;\n let _e179 = textureSampleLevel(uAo_t, uAo_s, _e178, 0f);\n let _e182 = unnamed.uAoStrength;\n ao = mix(1f, _e179.x, _e182);\n let _e184 = vUv_1;\n fromCentre = (_e184 - vec2(0.5f));\n let _e187 = fromCentre;\n radius_2 = (length((_e187 * vec2<f32>(1f, 0.62f))) * 2f);\n let _e192 = unnamed.uStrength;\n inner = mix(0.62f, 0.3f, _e192);\n let _e194 = inner;\n let _e195 = radius_2;\n edge = smoothstep(_e194, 1f, _e195);\n let _e197 = edge;\n let _e199 = unnamed.uStrength;\n amount = (_e197 * _e199);\n let _e201 = amount;\n if (_e201 <= 0f) {\n let _e203 = scene_1;\n let _e204 = ao;\n param_50 = (_e203 * _e204);\n let _e206 = withBloom_u0028_vf3_u003b((&param_50));\n param_51 = _e206;\n let _e207 = finish_u0028_vf3_u003b((&param_51));\n fragColor = vec4<f32>(_e207.x, _e207.y, _e207.z, 1f);\n return;\n }\n let _e212 = fromCentre;\n let _e216 = unnamed.uReach;\n let _e218 = amount;\n step_ = ((normalize((_e212 + vec2<f32>(0.000001f, 0.000001f))) * _e216) * _e218);\n let _e220 = scene_1;\n sum_2 = _e220;\n i_1 = 1i;\n loop {\n let _e221 = i_1;\n if (_e221 <= 6i) {\n let _e223 = vUv_1;\n let _e224 = step_;\n let _e225 = i_1;\n let _e230 = textureSampleLevel(uScene_t, uScene_s, (_e223 + (_e224 * (f32(_e225) / 6f))), 0f);\n let _e232 = sum_2;\n sum_2 = (_e232 + _e230.xyz);\n continue;\n } else {\n break;\n }\n continuing {\n let _e234 = i_1;\n i_1 = (_e234 + 1i);\n }\n }\n let _e236 = sum_2;\n blurred = (_e236 / vec3(7f));\n let _e239 = scene_1;\n let _e240 = blurred;\n let _e241 = amount;\n let _e244 = ao;\n param_52 = (mix(_e239, _e240, vec3(_e241)) * _e244);\n let _e246 = withBloom_u0028_vf3_u003b((&param_52));\n param_53 = _e246;\n let _e247 = finish_u0028_vf3_u003b((&param_53));\n fragColor = vec4<f32>(_e247.x, _e247.y, _e247.z, 1f);\n return;\n}\n\n@fragment \nfn main(@location(0) vUv: vec2<f32>, @builtin(position) gl_FragCoord: vec4<f32>) -> @location(0) vec4<f32> {\n vUv_1 = vUv;\n gl_FragCoord_1 = gl_FragCoord;\n main_1();\n let _e5 = fragColor;\n return _e5;\n}\n";
9
9
 
10
10
  /**
11
11
  * What the transform assigned, so the renderer binds the same numbers.
@@ -15,7 +15,7 @@ export const RUSH_FRAG_WGSL = "struct Uniforms {\n uStrength: f32,\n uReac
15
15
  export const RUSH_BINDINGS = {
16
16
  "RUSH_FRAG": {
17
17
  "uniforms": 1,
18
- "uniformSize": 160,
18
+ "uniformSize": 192,
19
19
  "fields": {
20
20
  "uStrength": {
21
21
  "offset": 0,
@@ -72,38 +72,58 @@ export const RUSH_BINDINGS = {
72
72
  "size": 4,
73
73
  "type": "float"
74
74
  },
75
- "uGradeStrength": {
75
+ "uVignette": {
76
76
  "offset": 112,
77
77
  "size": 4,
78
78
  "type": "float"
79
79
  },
80
+ "uGrain": {
81
+ "offset": 120,
82
+ "size": 8,
83
+ "type": "vec2"
84
+ },
85
+ "uAutoExposure": {
86
+ "offset": 128,
87
+ "size": 4,
88
+ "type": "float"
89
+ },
90
+ "uLocalExposure": {
91
+ "offset": 132,
92
+ "size": 4,
93
+ "type": "float"
94
+ },
95
+ "uGradeStrength": {
96
+ "offset": 136,
97
+ "size": 4,
98
+ "type": "float"
99
+ },
80
100
  "uGradeSize": {
81
- "offset": 116,
101
+ "offset": 140,
82
102
  "size": 4,
83
103
  "type": "float"
84
104
  },
85
105
  "uFocusDistance": {
86
- "offset": 120,
106
+ "offset": 144,
87
107
  "size": 4,
88
108
  "type": "float"
89
109
  },
90
110
  "uFocusRange": {
91
- "offset": 124,
111
+ "offset": 148,
92
112
  "size": 4,
93
113
  "type": "float"
94
114
  },
95
115
  "uDofStrength": {
96
- "offset": 128,
116
+ "offset": 152,
97
117
  "size": 4,
98
118
  "type": "float"
99
119
  },
100
120
  "uDofAspect": {
101
- "offset": 136,
121
+ "offset": 160,
102
122
  "size": 8,
103
123
  "type": "vec2"
104
124
  },
105
125
  "uDepthToView": {
106
- "offset": 144,
126
+ "offset": 176,
107
127
  "size": 16,
108
128
  "type": "vec4"
109
129
  }
@@ -129,9 +149,19 @@ export const RUSH_BINDINGS = {
129
149
  "sampler": 39,
130
150
  "type": "sampler2D"
131
151
  },
132
- "uGradeLut": {
152
+ "uExposureHeld": {
133
153
  "texture": 40,
134
154
  "sampler": 41,
155
+ "type": "sampler2D"
156
+ },
157
+ "uExposureLocal": {
158
+ "texture": 42,
159
+ "sampler": 43,
160
+ "type": "sampler2D"
161
+ },
162
+ "uGradeLut": {
163
+ "texture": 44,
164
+ "sampler": 45,
135
165
  "type": "sampler3D"
136
166
  }
137
167
  }
@@ -5,7 +5,7 @@
5
5
  * the next generation, and `npm run wgsl:check` fails the build when this is stale.
6
6
  */
7
7
 
8
- export const TEMPORAL_RESOLVE_FRAG_WGSL = "struct Uniforms {\n uReprojection: mat4x4<f32>,\n uTexel: vec2<f32>,\n uHistoryBlend: f32,\n}\n\n@group(0) @binding(32) \nvar uScene_t: texture_2d<f32>;\n@group(0) @binding(33) \nvar uScene_s: sampler;\nvar<private> vUv_1: vec2<f32>;\n@group(0) @binding(1) \nvar<uniform> unnamed: Uniforms;\nvar<private> fragColor: vec4<f32>;\n@group(0) @binding(36) \nvar uDepth_t: texture_2d<f32>;\n@group(0) @binding(37) \nvar uDepth_s: sampler;\n@group(0) @binding(34) \nvar uHistory_t: texture_2d<f32>;\n@group(0) @binding(35) \nvar uHistory_s: sampler;\n\nfn clipToNeighbourhood_u0028_vf3_u003b_vf3_u003b_vf3_u003b(history: ptr<function, vec3<f32>>, lo: ptr<function, vec3<f32>>, hi: ptr<function, vec3<f32>>) -> vec3<f32> {\n var centre: vec3<f32>;\n var extent: vec3<f32>;\n var offset: vec3<f32>;\n var ratios: vec3<f32>;\n var ratio: f32;\n\n let _e35 = (*lo);\n let _e36 = (*hi);\n centre = ((_e35 + _e36) * 0.5f);\n let _e39 = (*hi);\n let _e40 = (*lo);\n extent = ((_e39 - _e40) * 0.5f);\n let _e43 = (*history);\n let _e44 = centre;\n offset = (_e43 - _e44);\n let _e46 = offset;\n let _e48 = extent;\n ratios = (abs(_e46) / max(_e48, vec3<f32>(0.0000001f, 0.0000001f, 0.0000001f)));\n let _e52 = ratios[0u];\n let _e54 = ratios[1u];\n let _e56 = ratios[2u];\n ratio = max(_e52, max(_e54, _e56));\n let _e59 = ratio;\n if (_e59 <= 1f) {\n let _e61 = (*history);\n return _e61;\n }\n let _e62 = centre;\n let _e63 = offset;\n let _e64 = ratio;\n return (_e62 + (_e63 / vec3(_e64)));\n}\n\nfn neighbourhood_u0028_vf3_u003b_vf3_u003b(lo_1: ptr<function, vec3<f32>>, hi_1: ptr<function, vec3<f32>>) {\n var y: i32;\n var x: i32;\n var c: vec3<f32>;\n\n (*lo_1) = vec3<f32>(1000000000f, 1000000000f, 1000000000f);\n (*hi_1) = vec3<f32>(-1000000000f, -1000000000f, -1000000000f);\n y = -1i;\n loop {\n let _e32 = y;\n if (_e32 <= 1i) {\n x = -1i;\n loop {\n let _e34 = x;\n if (_e34 <= 1i) {\n let _e36 = vUv_1;\n let _e37 = x;\n let _e39 = y;\n let _e43 = unnamed.uTexel;\n let _e46 = textureSampleLevel(uScene_t, uScene_s, (_e36 + (vec2<f32>(f32(_e37), f32(_e39)) * _e43)), 0f);\n c = _e46.xyz;\n let _e48 = (*lo_1);\n let _e49 = c;\n (*lo_1) = min(_e48, _e49);\n let _e51 = (*hi_1);\n let _e52 = c;\n (*hi_1) = max(_e51, _e52);\n continue;\n } else {\n break;\n }\n continuing {\n let _e54 = x;\n x = (_e54 + 1i);\n }\n }\n continue;\n } else {\n break;\n }\n continuing {\n let _e56 = y;\n y = (_e56 + 1i);\n }\n }\n return;\n}\n\nfn main_1() {\n var current: vec3<f32>;\n var depth: f32;\n var clip: vec4<f32>;\n var previous: vec4<f32>;\n var wasUv: vec2<f32>;\n var lo_2: vec3<f32>;\n var hi_2: vec3<f32>;\n var param: vec3<f32>;\n var param_1: vec3<f32>;\n var history_1: vec3<f32>;\n var bounded: vec3<f32>;\n var param_2: vec3<f32>;\n var param_3: vec3<f32>;\n var param_4: vec3<f32>;\n var phi_223_: bool;\n var phi_230_: bool;\n var phi_237_: bool;\n\n let _e41 = vUv_1;\n let _e42 = textureSampleLevel(uScene_t, uScene_s, _e41, 0f);\n current = _e42.xyz;\n let _e45 = unnamed.uHistoryBlend;\n if (_e45 <= 0f) {\n let _e47 = current;\n fragColor = vec4<f32>(_e47.x, _e47.y, _e47.z, 1f);\n return;\n }\n let _e52 = vUv_1;\n let _e53 = textureSampleLevel(uDepth_t, uDepth_s, _e52, 0f);\n depth = _e53.x;\n let _e55 = vUv_1;\n let _e58 = ((_e55 * 2f) - vec2(1f));\n let _e59 = depth;\n clip = vec4<f32>(_e58.x, _e58.y, (1f - (_e59 * 2f)), 1f);\n let _e66 = unnamed.uReprojection;\n let _e67 = clip;\n previous = (_e66 * _e67);\n let _e70 = previous[3u];\n if (_e70 <= 0f) {\n let _e72 = current;\n fragColor = vec4<f32>(_e72.x, _e72.y, _e72.z, 1f);\n return;\n }\n let _e77 = previous;\n let _e80 = previous[3u];\n wasUv = (((_e77.xy / vec2(_e80)) * 0.5f) + vec2(0.5f));\n let _e87 = wasUv[0u];\n let _e88 = (_e87 < 0f);\n phi_223_ = _e88;\n if !(_e88) {\n let _e91 = wasUv[0u];\n phi_223_ = (_e91 > 1f);\n }\n let _e94 = phi_223_;\n phi_230_ = _e94;\n if !(_e94) {\n let _e97 = wasUv[1u];\n phi_230_ = (_e97 < 0f);\n }\n let _e100 = phi_230_;\n phi_237_ = _e100;\n if !(_e100) {\n let _e103 = wasUv[1u];\n phi_237_ = (_e103 > 1f);\n }\n let _e106 = phi_237_;\n if _e106 {\n let _e107 = current;\n fragColor = vec4<f32>(_e107.x, _e107.y, _e107.z, 1f);\n return;\n }\n neighbourhood_u0028_vf3_u003b_vf3_u003b((&param), (&param_1));\n let _e112 = param;\n lo_2 = _e112;\n let _e113 = param_1;\n hi_2 = _e113;\n let _e114 = wasUv;\n let _e115 = textureSampleLevel(uHistory_t, uHistory_s, _e114, 0f);\n history_1 = _e115.xyz;\n let _e117 = history_1;\n param_2 = _e117;\n let _e118 = lo_2;\n param_3 = _e118;\n let _e119 = hi_2;\n param_4 = _e119;\n let _e120 = clipToNeighbourhood_u0028_vf3_u003b_vf3_u003b_vf3_u003b((&param_2), (&param_3), (&param_4));\n bounded = _e120;\n let _e121 = current;\n let _e122 = bounded;\n let _e124 = unnamed.uHistoryBlend;\n let _e126 = mix(_e121, _e122, vec3(_e124));\n fragColor = vec4<f32>(_e126.x, _e126.y, _e126.z, 1f);\n return;\n}\n\n@fragment \nfn main(@location(0) vUv: vec2<f32>) -> @location(0) vec4<f32> {\n vUv_1 = vUv;\n main_1();\n let _e3 = fragColor;\n return _e3;\n}\n";
8
+ export const TEMPORAL_RESOLVE_FRAG_WGSL = "struct Uniforms {\n uReprojection: mat4x4<f32>,\n uTexel: vec2<f32>,\n uHistoryBlend: f32,\n}\n\n@group(0) @binding(32) \nvar uScene_t: texture_2d<f32>;\n@group(0) @binding(33) \nvar uScene_s: sampler;\nvar<private> vUv_1: vec2<f32>;\n@group(0) @binding(1) \nvar<uniform> unnamed: Uniforms;\n@group(0) @binding(34) \nvar uHistory_t: texture_2d<f32>;\n@group(0) @binding(35) \nvar uHistory_s: sampler;\nvar<private> fragColor: vec4<f32>;\n@group(0) @binding(36) \nvar uDepth_t: texture_2d<f32>;\n@group(0) @binding(37) \nvar uDepth_s: sampler;\n\nfn clipToNeighbourhood_u0028_vf3_u003b_vf3_u003b_vf3_u003b(history: ptr<function, vec3<f32>>, lo: ptr<function, vec3<f32>>, hi: ptr<function, vec3<f32>>) -> vec3<f32> {\n var centre: vec3<f32>;\n var extent: vec3<f32>;\n var offset: vec3<f32>;\n var ratios: vec3<f32>;\n var ratio: f32;\n\n let _e39 = (*lo);\n let _e40 = (*hi);\n centre = ((_e39 + _e40) * 0.5f);\n let _e43 = (*hi);\n let _e44 = (*lo);\n extent = ((_e43 - _e44) * 0.5f);\n let _e47 = (*history);\n let _e48 = centre;\n offset = (_e47 - _e48);\n let _e50 = offset;\n let _e52 = extent;\n ratios = (abs(_e50) / max(_e52, vec3<f32>(0.0000001f, 0.0000001f, 0.0000001f)));\n let _e56 = ratios[0u];\n let _e58 = ratios[1u];\n let _e60 = ratios[2u];\n ratio = max(_e56, max(_e58, _e60));\n let _e63 = ratio;\n if (_e63 <= 1f) {\n let _e65 = (*history);\n return _e65;\n }\n let _e66 = centre;\n let _e67 = offset;\n let _e68 = ratio;\n return (_e66 + (_e67 / vec3(_e68)));\n}\n\nfn historyCatmullRom_u0028_vf2_u003b(uv: ptr<function, vec2<f32>>) -> vec3<f32> {\n var size: vec2<f32>;\n var at: vec2<f32>;\n var base: vec2<f32>;\n var f: vec2<f32>;\n var w0_: vec2<f32>;\n var w1_: vec2<f32>;\n var w2_: vec2<f32>;\n var w3_: vec2<f32>;\n var w12_: vec2<f32>;\n var at0_: vec2<f32>;\n var at3_: vec2<f32>;\n var at12_: vec2<f32>;\n var sum: vec3<f32>;\n var weight: f32;\n\n let _e47 = unnamed.uTexel;\n size = (vec2(1f) / _e47);\n let _e50 = (*uv);\n let _e51 = size;\n at = (_e50 * _e51);\n let _e53 = at;\n base = (floor((_e53 - vec2(0.5f))) + vec2(0.5f));\n let _e59 = at;\n let _e60 = base;\n f = (_e59 - _e60);\n let _e62 = f;\n let _e63 = f;\n let _e64 = f;\n w0_ = (_e62 * (vec2(-0.5f) + (_e63 * (vec2(1f) - (_e64 * 0.5f)))));\n let _e72 = f;\n let _e73 = f;\n let _e75 = f;\n w1_ = (vec2(1f) + ((_e72 * _e73) * (vec2(-2.5f) + (_e75 * 1.5f))));\n let _e82 = f;\n let _e83 = f;\n let _e84 = f;\n w2_ = (_e82 * (vec2(0.5f) + (_e83 * (vec2(2f) - (_e84 * 1.5f)))));\n let _e92 = f;\n let _e93 = f;\n let _e95 = f;\n w3_ = ((_e92 * _e93) * (vec2(-0.5f) + (_e95 * 0.5f)));\n let _e100 = w1_;\n let _e101 = w2_;\n w12_ = (_e100 + _e101);\n let _e103 = base;\n let _e107 = unnamed.uTexel;\n at0_ = ((_e103 - vec2(1f)) * _e107);\n let _e109 = base;\n let _e113 = unnamed.uTexel;\n at3_ = ((_e109 + vec2(2f)) * _e113);\n let _e115 = base;\n let _e116 = w2_;\n let _e117 = w12_;\n let _e121 = unnamed.uTexel;\n at12_ = ((_e115 + (_e116 / _e117)) * _e121);\n let _e124 = at12_[0u];\n let _e126 = at0_[1u];\n let _e128 = textureSampleLevel(uHistory_t, uHistory_s, vec2<f32>(_e124, _e126), 0f);\n let _e131 = w12_[0u];\n let _e133 = w0_[1u];\n let _e137 = at0_[0u];\n let _e139 = at12_[1u];\n let _e141 = textureSampleLevel(uHistory_t, uHistory_s, vec2<f32>(_e137, _e139), 0f);\n let _e144 = w0_[0u];\n let _e146 = w12_[1u];\n let _e150 = at12_;\n let _e151 = textureSampleLevel(uHistory_t, uHistory_s, _e150, 0f);\n let _e154 = w12_[0u];\n let _e156 = w12_[1u];\n let _e161 = at3_[0u];\n let _e163 = at12_[1u];\n let _e165 = textureSampleLevel(uHistory_t, uHistory_s, vec2<f32>(_e161, _e163), 0f);\n let _e168 = w3_[0u];\n let _e170 = w12_[1u];\n let _e175 = at12_[0u];\n let _e177 = at3_[1u];\n let _e179 = textureSampleLevel(uHistory_t, uHistory_s, vec2<f32>(_e175, _e177), 0f);\n let _e182 = w12_[0u];\n let _e184 = w3_[1u];\n sum = (((((_e128.xyz * (_e131 * _e133)) + (_e141.xyz * (_e144 * _e146))) + (_e151.xyz * (_e154 * _e156))) + (_e165.xyz * (_e168 * _e170))) + (_e179.xyz * (_e182 * _e184)));\n let _e189 = w12_[0u];\n let _e191 = w0_[1u];\n let _e194 = w0_[0u];\n let _e196 = w12_[1u];\n let _e200 = w12_[0u];\n let _e202 = w12_[1u];\n let _e206 = w3_[0u];\n let _e208 = w12_[1u];\n let _e212 = w12_[0u];\n let _e214 = w3_[1u];\n weight = (((((_e189 * _e191) + (_e194 * _e196)) + (_e200 * _e202)) + (_e206 * _e208)) + (_e212 * _e214));\n let _e217 = sum;\n let _e218 = weight;\n return max((_e217 / vec3(_e218)), vec3<f32>(0f, 0f, 0f));\n}\n\nfn neighbourhood_u0028_vf3_u003b_vf3_u003b(lo_1: ptr<function, vec3<f32>>, hi_1: ptr<function, vec3<f32>>) {\n var y: i32;\n var x: i32;\n var c: vec3<f32>;\n\n (*lo_1) = vec3<f32>(1000000000f, 1000000000f, 1000000000f);\n (*hi_1) = vec3<f32>(-1000000000f, -1000000000f, -1000000000f);\n y = -1i;\n loop {\n let _e36 = y;\n if (_e36 <= 1i) {\n x = -1i;\n loop {\n let _e38 = x;\n if (_e38 <= 1i) {\n let _e40 = vUv_1;\n let _e41 = x;\n let _e43 = y;\n let _e47 = unnamed.uTexel;\n let _e50 = textureSampleLevel(uScene_t, uScene_s, (_e40 + (vec2<f32>(f32(_e41), f32(_e43)) * _e47)), 0f);\n c = _e50.xyz;\n let _e52 = (*lo_1);\n let _e53 = c;\n (*lo_1) = min(_e52, _e53);\n let _e55 = (*hi_1);\n let _e56 = c;\n (*hi_1) = max(_e55, _e56);\n continue;\n } else {\n break;\n }\n continuing {\n let _e58 = x;\n x = (_e58 + 1i);\n }\n }\n continue;\n } else {\n break;\n }\n continuing {\n let _e60 = y;\n y = (_e60 + 1i);\n }\n }\n return;\n}\n\nfn main_1() {\n var current: vec3<f32>;\n var depth: f32;\n var clip: vec4<f32>;\n var previous: vec4<f32>;\n var wasUv: vec2<f32>;\n var lo_2: vec3<f32>;\n var hi_2: vec3<f32>;\n var param: vec3<f32>;\n var param_1: vec3<f32>;\n var history_1: vec3<f32>;\n var param_2: vec2<f32>;\n var bounded: vec3<f32>;\n var param_3: vec3<f32>;\n var param_4: vec3<f32>;\n var param_5: vec3<f32>;\n var phi_440_: bool;\n var phi_447_: bool;\n var phi_454_: bool;\n\n let _e46 = vUv_1;\n let _e47 = textureSampleLevel(uScene_t, uScene_s, _e46, 0f);\n current = _e47.xyz;\n let _e50 = unnamed.uHistoryBlend;\n if (_e50 <= 0f) {\n let _e52 = current;\n fragColor = vec4<f32>(_e52.x, _e52.y, _e52.z, 1f);\n return;\n }\n let _e57 = vUv_1;\n let _e58 = textureSampleLevel(uDepth_t, uDepth_s, _e57, 0f);\n depth = _e58.x;\n let _e60 = vUv_1;\n let _e63 = ((_e60 * 2f) - vec2(1f));\n let _e64 = depth;\n clip = vec4<f32>(_e63.x, _e63.y, (1f - (_e64 * 2f)), 1f);\n let _e71 = unnamed.uReprojection;\n let _e72 = clip;\n previous = (_e71 * _e72);\n let _e75 = previous[3u];\n if (_e75 <= 0f) {\n let _e77 = current;\n fragColor = vec4<f32>(_e77.x, _e77.y, _e77.z, 1f);\n return;\n }\n let _e82 = previous;\n let _e85 = previous[3u];\n wasUv = (((_e82.xy / vec2(_e85)) * 0.5f) + vec2(0.5f));\n let _e92 = wasUv[0u];\n let _e93 = (_e92 < 0f);\n phi_440_ = _e93;\n if !(_e93) {\n let _e96 = wasUv[0u];\n phi_440_ = (_e96 > 1f);\n }\n let _e99 = phi_440_;\n phi_447_ = _e99;\n if !(_e99) {\n let _e102 = wasUv[1u];\n phi_447_ = (_e102 < 0f);\n }\n let _e105 = phi_447_;\n phi_454_ = _e105;\n if !(_e105) {\n let _e108 = wasUv[1u];\n phi_454_ = (_e108 > 1f);\n }\n let _e111 = phi_454_;\n if _e111 {\n let _e112 = current;\n fragColor = vec4<f32>(_e112.x, _e112.y, _e112.z, 1f);\n return;\n }\n neighbourhood_u0028_vf3_u003b_vf3_u003b((&param), (&param_1));\n let _e117 = param;\n lo_2 = _e117;\n let _e118 = param_1;\n hi_2 = _e118;\n let _e119 = wasUv;\n param_2 = _e119;\n let _e120 = historyCatmullRom_u0028_vf2_u003b((&param_2));\n history_1 = _e120;\n let _e121 = history_1;\n param_3 = _e121;\n let _e122 = lo_2;\n param_4 = _e122;\n let _e123 = hi_2;\n param_5 = _e123;\n let _e124 = clipToNeighbourhood_u0028_vf3_u003b_vf3_u003b_vf3_u003b((&param_3), (&param_4), (&param_5));\n bounded = _e124;\n let _e125 = current;\n let _e126 = bounded;\n let _e128 = unnamed.uHistoryBlend;\n let _e130 = mix(_e125, _e126, vec3(_e128));\n fragColor = vec4<f32>(_e130.x, _e130.y, _e130.z, 1f);\n return;\n}\n\n@fragment \nfn main(@location(0) vUv: vec2<f32>) -> @location(0) vec4<f32> {\n vUv_1 = vUv;\n main_1();\n let _e3 = fragColor;\n return _e3;\n}\n";
9
9
 
10
10
  /**
11
11
  * What the transform assigned, so the renderer binds the same numbers.
@@ -0,0 +1,49 @@
1
+ /**
2
+ * DriftLight's lookup in hand-written WGSL, for the traced probe bake: the summed light arriving on
3
+ * a surface a probe's ray struck, which is how candles past the frame's choice reach the bounce.
4
+ *
5
+ * **A transcription of `flat/driftLight.ts`, line for line**, because a compute shader cannot
6
+ * include the generated WGSL of a fragment stage. Two spellings of one lookup is the hazard the
7
+ * 2026-08-13 rule is about, and `driftLight.test.ts` beside this holds them together by reading
8
+ * both: change one and it names the line of the other.
9
+ *
10
+ * **Integer arithmetic for the brick's corner**, by the 2026-09-20 rule: a device divides a float by
11
+ * multiplying by its reciprocal, and a brick number off by one is a brick from somewhere else.
12
+ *
13
+ * The including module declares `driftIndex: texture_3d<u32>`, `driftAtlas: texture_3d<f32>` and a
14
+ * filtering `driftSampler`; `origin` is the field's first sample and, in `w`, the spacing.
15
+ */
16
+ export const DRIFT_LIGHT_WGSL = /* wgsl */ `
17
+ fn driftLightIrradiance(world: vec3<f32>, n: vec3<f32>, origin: vec4<f32>) -> vec3<f32> {
18
+ let spacing = origin.w;
19
+ let at = (world + n * (0.5 * spacing) - origin.xyz) / (3.0 * spacing);
20
+ let cell = vec3<i32>(floor(at));
21
+ if (any(cell < vec3<i32>(0)) || any(cell >= vec3<i32>(textureDimensions(driftIndex, 0)))) {
22
+ return vec3<f32>(0.0);
23
+ }
24
+ let id = textureLoad(driftIndex, cell, 0).r;
25
+ if (id == 0u) {
26
+ return vec3<f32>(0.0);
27
+ }
28
+ let size = vec3<i32>(textureDimensions(driftAtlas, 0));
29
+ let brick = i32(id) - 1;
30
+ let across = size.x / 8;
31
+ let down = size.y / 4;
32
+ let corner = vec3<f32>(
33
+ f32((brick % across) * 8),
34
+ f32(((brick / across) % down) * 4),
35
+ f32((brick / (across * down)) * 4)
36
+ );
37
+ let texel = 1.0 / vec3<f32>(size);
38
+ let inside = (at - vec3<f32>(cell)) * 3.0 + 0.5;
39
+ let light = textureSampleLevel(driftAtlas, driftSampler, (corner + inside) * texel, 0.0);
40
+ if (light.a < 1e-3) {
41
+ return vec3<f32>(0.0);
42
+ }
43
+ let toward = textureSampleLevel(driftAtlas, driftSampler, (corner + vec3<f32>(4.0, 0.0, 0.0) + inside) * texel, 0.0);
44
+ let arriving = light.rgb / light.a;
45
+ let towardLight = toward.xyz / light.a;
46
+ let facing = max(dot(n, towardLight), 0.0) + (1.0 - min(length(towardLight), 1.0)) * 0.25;
47
+ return arriving * facing;
48
+ }
49
+ `;
@@ -28,6 +28,8 @@ import { FRAME_TURN, GOLDEN_ANGLE, PROBE_DIRECTIONS } from '../../gi/probeTrace.
28
28
  import { PROBE_MARCH_WGSL, PROBE_TRACE_CORE_WGSL } from './probeTrace.wgsl.ts';
29
29
  import { PROBE_VOLUME_CORE_WGSL, PROBE_VOLUME_STRUCT_WGSL } from './probeVolume.wgsl.ts';
30
30
  import { SAMPLE_FIELD_WGSL } from './sampleField.wgsl.ts';
31
+ import { DRIFT_LIGHT_WGSL } from './driftLight.wgsl.ts';
32
+ import { BOUNCE_LIGHT_FLOATS, MAX_BOUNCE_LIGHTS } from '../../gi/bounceLights.ts';
31
33
 
32
34
  /**
33
35
  * Floats in the bake block, and where each field of it starts.
@@ -47,14 +49,40 @@ export const BAKE_COUNTS = 8;
47
49
  export const BAKE_EDGE = 11;
48
50
  export const BAKE_FRAME = 12;
49
51
  export const BAKE_SCHEDULED = 13;
52
+ /** How much of what a layer held a refresh keeps. See `PROBE_HISTORY` and `convolveMain`. */
53
+ export const BAKE_HISTORY = 14;
50
54
  /** The sun, which the trace evaluates itself so a light that moves changes the bounce. */
51
55
  export const BAKE_SUN_DIR = 16;
52
56
  export const BAKE_SUN_COLOUR = 20;
53
- /** What a ray that left the world finds. The frame's ambient, so nothing rasterised is read. */
57
+ /**
58
+ * What a ray that left the world finds: the sky's horizon colour where the frame drew a sky, and the
59
+ * whole of the sky, flat, where it drew none. The flag says which, in the fourth float of the row,
60
+ * which is where an f32 declared after a vec3 lands. The rest of the sky the frame drew follows.
61
+ */
54
62
  export const BAKE_SKY_COLOUR = 24;
63
+ export const BAKE_SKY_DRAWN = 27;
64
+ export const BAKE_SKY_TOP = 28;
65
+ export const BAKE_SKY_DEEP = 32;
66
+ /** The sky's own sun, which at night is not the key light: the moon is. The sunset reads this. */
67
+ export const BAKE_SKY_SUN = 36;
68
+ /**
69
+ * DriftLight's field, as `driftLight/uniforms.ts` resolves it for a probe: how much is in and its
70
+ * scale in `x` and `w`, and where its grid starts with the spacing in `w`. Zero switches it off.
71
+ */
72
+ export const BAKE_DRIFT_LIGHT = 40;
73
+ export const BAKE_DRIFT_ORIGIN = 44;
74
+ /**
75
+ * How many of the frame's exact lights `bounceLights` holds, and how the renderer shades a point
76
+ * light: 1 inverse-square, 0 the shaped falloff. See `gi/bounceLights.ts`.
77
+ */
78
+ export const BAKE_LIGHT_COUNT = 48;
79
+ export const BAKE_FALLOFF = 49;
80
+
81
+ /** Rounded up to the struct's own sixteen-byte alignment: the lattice, five vec3 rows, three vec4. */
82
+ export const PROBE_BAKE_FLOATS = 52;
55
83
 
56
- /** Rounded up to the struct's own sixteen-byte alignment, with two vec3 rows for the sun. */
57
- export const PROBE_BAKE_FLOATS = 28;
84
+ /** Rows of `bounceLights`: three a light. */
85
+ export const BOUNCE_LIGHT_ROWS = (MAX_BOUNCE_LIGHTS * BOUNCE_LIGHT_FLOATS) / 4;
58
86
 
59
87
  /** Invocations a workgroup, for both entry points. 64 is this backend's default everywhere. */
60
88
  export const PROBE_BAKE_WORKGROUP = 64;
@@ -74,17 +102,28 @@ struct ProbeBake {
74
102
  counts: vec3<f32>,
75
103
  /* Texels across one probe's map, gutter included. */
76
104
  edge: f32,
77
- /* Which frame this is, which turns the direction set so a probe converges rather than repeats. */
105
+ /* How far the direction set is turned. The bake holds it at 0; the parity check turns it. */
78
106
  frame: f32,
79
107
  /* How many probes this dispatch bakes. The schedule says which. */
80
108
  scheduled: f32,
81
- pad: f32,
109
+ /* How much of what a layer held each refresh keeps, 0 for a grid not yet traced whole. */
110
+ history: f32,
82
111
  /* Towards the sun, and what colour it is. The trace shades what it hits rather than reading a
83
112
  capture, which is what lets a bounce follow a light that moved. */
84
113
  sunDir: vec3<f32>,
85
114
  sunColour: vec3<f32>,
86
- /* And what is outside, for a ray that left. See probeDistantRadiance. */
115
+ /* And what is outside, for a ray that left. See probeDistantRadiance and probeSkyAlong. */
87
116
  skyColour: vec3<f32>,
117
+ skyDrawn: f32,
118
+ skyTop: vec3<f32>,
119
+ skyDeep: vec3<f32>,
120
+ skySun: vec3<f32>,
121
+ /* The summed light of a scene's many fixed lights. See driftLight.wgsl.ts. */
122
+ driftLight: vec4<f32>,
123
+ driftOrigin: vec4<f32>,
124
+ /* How many of the frame's exact lights bounceLights holds, and 1 for inverse-square falloff. */
125
+ lightCount: f32,
126
+ falloff: f32,
88
127
  }
89
128
  `;
90
129
 
@@ -237,11 +276,18 @@ fn convolveMain(@builtin(global_invocation_id) id: vec3<u32>) {
237
276
  zero rather than dividing is what keeps it from being a hole if it ever does. */
238
277
  let scale = select(0.0, 1.0 / weights, weights > 0.0);
239
278
  let value = max(vec3<f32>(0.0), sum * scale);
279
+ /*
280
+ * **Blended into what the layer held, because one refresh is one estimate.** 256 rays over a set
281
+ * that turns every frame put two refreshes of a probe a few per cent apart, and written as they
282
+ * landed they were a shimmer about nine times a second. "bake.history" is 0 until the grid has
283
+ * been traced whole, so a first fill lands at once.
284
+ */
285
+ let kept = mix(value, probeHistory(schedule[slot], u, v), bake.history);
240
286
 
241
287
  let out = id.x * ${String(PROBE_TEXEL_FLOATS)}u;
242
- irradiance[out] = value.x;
243
- irradiance[out + 1u] = value.y;
244
- irradiance[out + 2u] = value.z;
288
+ irradiance[out] = kept.x;
289
+ irradiance[out + 1u] = kept.y;
290
+ irradiance[out + 2u] = kept.z;
245
291
  }
246
292
  `;
247
293
 
@@ -291,6 +337,11 @@ fn probeLayerSample(layer: u32, uv: vec2<f32>) -> vec3<f32> {
291
337
  return vec3<f32>(probeValues[at], probeValues[at + 1u], probeValues[at + 2u]);
292
338
  }
293
339
 
340
+ /* No history: this module's refreshes are checked as single estimates, and "bake.history" is 0. */
341
+ fn probeHistory(layer: u32, u: u32, v: u32) -> vec3<f32> {
342
+ return vec3<f32>(0.0);
343
+ }
344
+
294
345
  /* The same flat value: this module checks the blend, and what a production texture holds at its
295
346
  two levels is what makes them different. */
296
347
  fn probeLayerIrradiance(layer: u32, uv: vec2<f32>) -> vec3<f32> {
@@ -374,6 +425,10 @@ fn echoMain(@builtin(global_invocation_id) id: vec3<u32>) {
374
425
  irradiance[9] = bake.edge;
375
426
  irradiance[10] = bake.frame;
376
427
  irradiance[11] = bake.scheduled;
428
+ irradiance[12] = bake.skyDrawn;
429
+ irradiance[13] = bake.skyTop.x;
430
+ irradiance[14] = bake.skyDeep.x;
431
+ irradiance[15] = bake.skySun.x;
377
432
  }
378
433
 
379
434
  /* The encode, which is a different function from the fold "texelMain" checks and needs its own. */
@@ -451,7 +506,19 @@ ${PROBE_VOLUME_STRUCT_WGSL}
451
506
  @group(0) @binding(9) var probeSampler: sampler;
452
507
  /* The colour of whatever won the union at each sample, three floats, same layout as the field. */
453
508
  @group(0) @binding(10) var<storage, read> albedoField: array<f32>;
509
+ /* DriftLight's brick index and atlas, or one-texel stand-ins while driftLight.x is zero. */
510
+ @group(0) @binding(11) var driftIndex: texture_3d<u32>;
511
+ @group(0) @binding(12) var driftAtlas: texture_3d<f32>;
512
+ @group(0) @binding(13) var driftSampler: sampler;
513
+ /* The frame's exact lights, three rows each: see gi/bounceLights.ts for what each row holds. */
514
+ @group(0) @binding(14) var<uniform> bounceLights: array<vec4<f32>, ${String(BOUNCE_LIGHT_ROWS)}>;
454
515
  ${SAMPLE_FIELD_WGSL}
516
+ ${DRIFT_LIGHT_WGSL}
517
+
518
+ /* What a layer's irradiance level holds at a texel, which the convolution blends into. */
519
+ fn probeHistory(layer: u32, u: u32, v: u32) -> vec3<f32> {
520
+ return textureLoad(probeArray, vec2<i32>(i32(u), i32(v)), i32(layer), i32(volume.level)).rgb;
521
+ }
455
522
 
456
523
  /*
457
524
  * The albedo at a world point, from the finest cascade that holds it, by nearest sample.
@@ -564,13 +631,111 @@ fn probeSurfaceRadiance(p: vec3<f32>, towards: vec3<f32>) -> vec3<f32> {
564
631
  /*
565
632
  * And what has already bounced, which is the level this bake writes — so the loop closes.
566
633
  *
567
- * **Divided by pi once and not twice.** "convolveProbe" normalises by the cosine weights it
568
- * actually used, so what a probe stores is the cosine-weighted *mean radiance*, which is already
569
- * the irradiance over pi — the convention a Lambertian's outgoing radiance multiplies directly
570
- * by its albedo. Only the sun's own irradiance needs the division.
634
+ * **Neither term is divided by pi, because the frame divides neither.** "convolveProbe"
635
+ * normalises by the cosine weights it actually used, so a probe stores the cosine-weighted
636
+ * *mean radiance*, which a Lambertian's outgoing radiance multiplies directly by its albedo. And
637
+ * the flat shader lights a surface with "albedo * (ambient + directionalColor * cosine)", so
638
+ * "directionalColor" is the radiance a white surface facing the sun sends back rather than an
639
+ * irradiance. This divided the sun by pi until 2026-09-27, and every sunlit wall a probe struck
640
+ * came back a third as bright as the frame drew it: a room lit through its one open side read
641
+ * 66 of 255 on its far wall against a path-traced 200 ("scripts/bounce-check.mjs"). What would
642
+ * make it wrong is a flat shader that divides its own sun by pi; "probeBake.test.ts" reads both.
571
643
  */
572
644
  let bounced = probeVolumeIrradianceAt(p, n);
573
- return albedo * (direct * ${String(1 / Math.PI)} + bounced);
645
+ /*
646
+ * And the summed light of the scene's many fixed lights, which is how a candle nobody is near
647
+ * reaches the bounce: the trace shades a hit with the sun alone otherwise. At the presence and
648
+ * scale the frame reads it with, and with no share, because a probe sees every fixed light through
649
+ * the volume (driftLight/uniforms.ts).
650
+ */
651
+ let summed = driftLightIrradiance(p, n, bake.driftOrigin) * (bake.driftLight.x * bake.driftLight.w);
652
+ return albedo * (direct + bounced + summed + probeLampsAt(p, n));
653
+ }
654
+
655
+ /*
656
+ * Whether a lamp reaches a point, by marching the field towards it and stopping short.
657
+ *
658
+ * **Short of the lamp by its fixture.** A flame stands inside a lantern and a bulb inside a shade,
659
+ * and a field a quarter of a metre fine draws those as solid: a march that ran all the way would
660
+ * find the lantern round every lantern and shade every one of them out. So it stops a fixture's
661
+ * width away, the larger of 30 cm and two of the finest voxels, and what it gives up is an occluder
662
+ * that close to a lamp.
663
+ */
664
+ fn probeLampVisible(p: vec3<f32>, n: vec3<f32>, toward: vec3<f32>, span: f32) -> f32 {
665
+ let lifted = p + n * (PROBE_FIELD_START_VOXELS * march.finestStep);
666
+ var travelled = 0.0;
667
+ for (var step = 0u; step < march.steps; step = step + 1u) {
668
+ if (travelled >= span) { return 1.0; }
669
+ let at = lifted + toward * travelled;
670
+ if (probeFieldInside(at) <= 0.0) { return 1.0; }
671
+ let distance = probeFieldAt(at);
672
+ if (distance <= march.hitEpsilonM) { return 0.0; }
673
+ travelled = travelled + max(distance, march.finestStep * 0.25);
674
+ }
675
+ return 1.0;
676
+ }
677
+
678
+ /*
679
+ * The frame's exact lights on a surface a ray struck: the lit shader's lamp term, line for line
680
+ * (probeBake.test.ts holds the two together), with the field's own shadow in place of a lamp's
681
+ * shadow map. Not a photometric profile or a cookie, which the bounce reads as a plain cone.
682
+ */
683
+ fn probeLampsAt(p: vec3<f32>, n: vec3<f32>) -> vec3<f32> {
684
+ var sum = vec3<f32>(0.0);
685
+ let count = u32(bake.lightCount);
686
+ for (var i = 0u; i < count; i = i + 1u) {
687
+ let at = bounceLights[i * 3u];
688
+ let colour = bounceLights[i * 3u + 1u];
689
+ let aim = bounceLights[i * 3u + 2u];
690
+ let lightRadius = at.w;
691
+ let toLight = at.xyz - p;
692
+ let dist = length(toLight);
693
+ let coneFalloff = smoothstep(aim.w, colour.w, dot(-toLight / max(dist, 1e-4), aim.xyz));
694
+ var falloff: f32;
695
+ if (bake.falloff == 1.0) {
696
+ let window = clamp(1.0 - pow(dist / max(lightRadius, 1e-4), 4.0), 0.0, 1.0);
697
+ falloff = window * window / max(dist * dist, 0.01);
698
+ } else {
699
+ falloff = clamp(1.0 - dist / lightRadius, 0.0, 1.0);
700
+ }
701
+ if (falloff <= 0.0) { continue; }
702
+ let ndl = max(dot(n, toLight / max(dist, 1e-4)), 0.0);
703
+ if (ndl <= 0.0) { continue; }
704
+ let shape = select(falloff * falloff, falloff, bake.falloff == 1.0) * coneFalloff;
705
+ if (shape <= 0.0) { continue; }
706
+ let fixture = max(0.3, 2.0 * march.finestStep);
707
+ let seen = probeLampVisible(p, n, toLight / max(dist, 1e-4), dist - fixture);
708
+ sum = sum + colour.rgb * ndl * shape * seen;
709
+ }
710
+ return sum;
711
+ }
712
+
713
+ /*
714
+ * The sky the frame drew, along a direction: the sky shader's gradient and its two sunset bands,
715
+ * transcribed line for line (probeBake.test.ts holds the two together). Not its sun, moon, stars or
716
+ * clouds: the sun reaches a probe as direct light at what the ray strikes, and the rest is a few
717
+ * per cent of a sky's light. Where the frame drew no sky, the environment's ambient, flat.
718
+ */
719
+ fn probeSkyAlong(d: vec3<f32>) -> vec3<f32> {
720
+ if (bake.skyDrawn < 0.5) { return bake.skyColour; }
721
+ let t = d.y;
722
+ var col: vec3<f32>;
723
+ if (t >= 0.0) {
724
+ col = mix(bake.skyColour, bake.skyTop, pow(min(t, 1.0), 0.55));
725
+ } else {
726
+ col = mix(bake.skyColour, bake.skyDeep, min(-t * 1.8, 1.0));
727
+ }
728
+ let sunset = (1.0 - smoothstep(-0.03, 0.30, bake.skySun.y)) * smoothstep(-0.35, -0.05, bake.skySun.y);
729
+ let ember = vec3<f32>(1.0, 0.36, 0.13);
730
+ let sunBearing = normalize(bake.skySun.xz + vec2<f32>(1e-5));
731
+ let viewBearing = normalize(d.xz + vec2<f32>(1e-5));
732
+ let toward = max(dot(viewBearing, sunBearing), 0.0);
733
+ let fromHorizon = select(-t * 3.0, t, t >= 0.0);
734
+ let band = pow(1.0 - min(fromHorizon * 2.2, 1.0), 2.6);
735
+ col += ember * sunset * band * (0.18 + 0.75 * pow(toward, 2.2));
736
+ let away = max(-dot(viewBearing, sunBearing), 0.0);
737
+ col += vec3<f32>(0.42, 0.28, 0.45) * sunset * band * away * 0.22;
738
+ return col;
574
739
  }
575
740
 
576
741
  /*
@@ -578,15 +743,21 @@ fn probeSurfaceRadiance(p: vec3<f32>, towards: vec3<f32>) -> vec3<f32> {
578
743
  *
579
744
  * **Not the probe array's own level 0, and that was measured rather than reasoned.** Level 0 is a
580
745
  * *rasterised* capture taken once, so a ray reading it gathers the light the room had when the
581
- * capture was made — and a room whose red wall was repainted blue went on bouncing red, because
582
- * most of its rays escaped through the opening and read the capture. With the sky here instead,
583
- * **nothing in the trace reads anything rasterised**, which is what lets the whole solution follow
584
- * a scene that changes and is the sentence Wave 4's criterion asks for.
746
+ * capture was made, and a room whose red wall was repainted blue went on bouncing red, because
747
+ * most of its rays escaped through the opening and read the capture. The sky is the frame's own
748
+ * numbers, so **nothing in the trace reads anything rasterised** and the solution follows a scene
749
+ * that changes.
750
+ *
751
+ * **The sky drawn, and not the environment's ambient, since 2026-09-27.** The ambient is a grade's
752
+ * fill for surfaces the probes do not reach, and a palette sets it apart from the sky: at ten
753
+ * degrees of sun a courtyard's was five times dimmer than its horizon, and blue where the horizon
754
+ * was amber, so traced shade at dusk came out cool against the rasterised grid that saw the sky.
585
755
  *
586
- * No albedo and no sun: nothing was struck, so there is no surface to shade.
756
+ * No albedo and no sun: nothing was struck, so there is no surface to shade. "towards" points back
757
+ * down the ray, so the sky is read along its opposite.
587
758
  */
588
759
  fn probeDistantRadiance(p: vec3<f32>, towards: vec3<f32>) -> vec3<f32> {
589
- return bake.skyColour;
760
+ return probeSkyAlong(-towards);
590
761
  }
591
762
  ${PROBE_TRACE_CORE_WGSL}
592
763
  ${PROBE_BAKE_CORE_WGSL}
@@ -293,6 +293,10 @@ void main() {
293
293
  */
294
294
  export const MEDIUM_UPSAMPLE_FRAG = `#version 300 es
295
295
  precision highp float;
296
+ /* highp int, by the rule every fragment stage doing bit arithmetic keeps: the footprint below is
297
+ picked with a mask and a shift. At four values it would survive sixteen bits, and a gate that
298
+ has to judge which masks are small is a gate nobody can hold. */
299
+ precision highp int;
296
300
 
297
301
  in vec2 vUv;
298
302