@driftengine/core 4.8.2 → 4.8.4

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 (259) hide show
  1. package/CHANGELOG.json +127 -0
  2. package/README.md +1 -1
  3. package/dist/geometry/meshConcat.js +2 -0
  4. package/dist/index.d.ts +11 -4
  5. package/dist/index.js +22 -1
  6. package/dist/math/scalar.js +1 -1
  7. package/dist/render/anisotropicLobe.d.ts +7 -0
  8. package/dist/render/anisotropicLobe.js +33 -0
  9. package/dist/render/backend/api.d.ts +41 -4
  10. package/dist/render/backend/materialChanges.d.ts +7 -2
  11. package/dist/render/backend/materialChanges.js +8 -3
  12. package/dist/render/backend/select.js +8 -0
  13. package/dist/render/backend/webgl2/clothTextures.d.ts +27 -0
  14. package/dist/render/backend/webgl2/clothTextures.js +93 -0
  15. package/dist/render/backend/webgl2/renderer.d.ts +159 -3
  16. package/dist/render/backend/webgl2/renderer.js +662 -80
  17. package/dist/render/backend/webgl2/skinScatter.d.ts +50 -0
  18. package/dist/render/backend/webgl2/skinScatter.js +256 -0
  19. package/dist/render/backend/webgpu/buffers.d.ts +25 -11
  20. package/dist/render/backend/webgpu/buffers.js +98 -49
  21. package/dist/render/backend/webgpu/causticsPass.js +2 -1
  22. package/dist/render/backend/webgpu/clothSolvePack.d.ts +27 -0
  23. package/dist/render/backend/webgpu/clothSolvePack.js +129 -0
  24. package/dist/render/backend/webgpu/clothTextures.d.ts +68 -0
  25. package/dist/render/backend/webgpu/clothTextures.js +145 -0
  26. package/dist/render/backend/webgpu/compressedUpload.d.ts +18 -0
  27. package/dist/render/backend/webgpu/compressedUpload.js +38 -0
  28. package/dist/render/backend/webgpu/computeHost.d.ts +21 -0
  29. package/dist/render/backend/webgpu/computeHost.js +5 -0
  30. package/dist/render/backend/webgpu/depthPass.d.ts +29 -9
  31. package/dist/render/backend/webgpu/depthPass.js +43 -12
  32. package/dist/render/backend/webgpu/drawCommand.js +6 -2
  33. package/dist/render/backend/webgpu/filmPass.js +2 -1
  34. package/dist/render/backend/webgpu/flatPass.d.ts +43 -4
  35. package/dist/render/backend/webgpu/flatPass.js +111 -13
  36. package/dist/render/backend/webgpu/gpuSkinnedCloth.d.ts +74 -0
  37. package/dist/render/backend/webgpu/gpuSkinnedCloth.js +452 -0
  38. package/dist/render/backend/webgpu/linePass.js +2 -1
  39. package/dist/render/backend/webgpu/motionPass.d.ts +20 -0
  40. package/dist/render/backend/webgpu/motionPass.js +106 -9
  41. package/dist/render/backend/webgpu/panelPass.js +2 -1
  42. package/dist/render/backend/webgpu/particlePass.js +2 -1
  43. package/dist/render/backend/webgpu/plumePass.js +2 -1
  44. package/dist/render/backend/webgpu/postPass.d.ts +15 -3
  45. package/dist/render/backend/webgpu/postPass.js +25 -8
  46. package/dist/render/backend/webgpu/renderer.d.ts +123 -6
  47. package/dist/render/backend/webgpu/renderer.js +534 -58
  48. package/dist/render/backend/webgpu/sdfTextPass.js +2 -1
  49. package/dist/render/backend/webgpu/shaders/clothSolve.wgsl.d.ts +33 -0
  50. package/dist/render/backend/webgpu/shaders/clothSolve.wgsl.js +469 -0
  51. package/dist/render/backend/webgpu/skinScatterPass.d.ts +51 -0
  52. package/dist/render/backend/webgpu/skinScatterPass.js +253 -0
  53. package/dist/render/backend/webgpu/surfaceTexturePass.d.ts +4 -1
  54. package/dist/render/backend/webgpu/surfaceTexturePass.js +37 -12
  55. package/dist/render/backend/webgpu/textPass.js +2 -1
  56. package/dist/render/backend/webgpu/waterPass.js +2 -1
  57. package/dist/render/backend/webgpu/windStreakPass.js +2 -1
  58. package/dist/render/boltBatch.js +2 -1
  59. package/dist/render/causticsRenderer.js +2 -1
  60. package/dist/render/clothBindingData.d.ts +41 -0
  61. package/dist/render/clothBindingData.js +72 -0
  62. package/dist/render/clothPlacement.d.ts +25 -0
  63. package/dist/render/clothPlacement.js +85 -0
  64. package/dist/render/compressedSource.d.ts +66 -0
  65. package/dist/render/compressedSource.js +138 -0
  66. package/dist/render/cutoutCaster.d.ts +5 -1
  67. package/dist/render/cutoutCaster.js +6 -0
  68. package/dist/render/cutoutDither.d.ts +51 -0
  69. package/dist/render/cutoutDither.js +90 -0
  70. package/dist/render/decalPass.js +2 -1
  71. package/dist/render/eyeRefraction.d.ts +35 -0
  72. package/dist/render/eyeRefraction.js +40 -0
  73. package/dist/render/glCompressed.d.ts +27 -0
  74. package/dist/render/glCompressed.js +53 -0
  75. package/dist/render/globalMediumPass.js +3 -2
  76. package/dist/render/hairLobes.d.ts +70 -0
  77. package/dist/render/hairLobes.js +120 -0
  78. package/dist/render/lightBudget.d.ts +22 -0
  79. package/dist/render/lightBudget.js +22 -0
  80. package/dist/render/lineBatch.js +5 -1
  81. package/dist/render/mesh.d.ts +7 -0
  82. package/dist/render/mesh.js +24 -0
  83. package/dist/render/oitPass.js +2 -1
  84. package/dist/render/particleBatch.js +3 -2
  85. package/dist/render/particlePool.d.ts +6 -2
  86. package/dist/render/plumeRenderer.js +3 -2
  87. package/dist/render/recon/motionVectors.d.ts +4 -2
  88. package/dist/render/recon/motionVectors.js +6 -3
  89. package/dist/render/renderQuality.d.ts +29 -2
  90. package/dist/render/renderQuality.js +5 -0
  91. package/dist/render/rendererHarness.js +4 -0
  92. package/dist/render/sceneCoverage.d.ts +54 -0
  93. package/dist/render/sceneCoverage.js +72 -0
  94. package/dist/render/sceneTarget.d.ts +12 -0
  95. package/dist/render/sceneTarget.js +14 -0
  96. package/dist/render/sdfTextRenderer.js +2 -1
  97. package/dist/render/shaders/clothBinding.d.ts +22 -0
  98. package/dist/render/shaders/clothBinding.js +80 -0
  99. package/dist/render/shaders/depth.js +45 -8
  100. package/dist/render/shaders/flat/anisotropic.d.ts +15 -0
  101. package/dist/render/shaders/flat/anisotropic.js +68 -0
  102. package/dist/render/shaders/flat/eye.d.ts +1 -0
  103. package/dist/render/shaders/flat/eye.js +81 -0
  104. package/dist/render/shaders/flat/hair.d.ts +1 -0
  105. package/dist/render/shaders/flat/hair.js +101 -0
  106. package/dist/render/shaders/flat/index.js +42 -3
  107. package/dist/render/shaders/flat/main.d.ts +1 -1
  108. package/dist/render/shaders/flat/main.js +113 -17
  109. package/dist/render/shaders/flat/models.d.ts +14 -0
  110. package/dist/render/shaders/flat/models.js +273 -0
  111. package/dist/render/shaders/flat/preamble.js +26 -24
  112. package/dist/render/shaders/flat/skin.d.ts +1 -0
  113. package/dist/render/shaders/flat/skin.js +114 -0
  114. package/dist/render/shaders/generated/depth.wgsl.d.ts +66 -24
  115. package/dist/render/shaders/generated/depth.wgsl.js +66 -24
  116. package/dist/render/shaders/generated/flat.wgsl.d.ts +1815 -1704
  117. package/dist/render/shaders/generated/flat.wgsl.js +1853 -1742
  118. package/dist/render/shaders/generated/line.wgsl.d.ts +1 -1
  119. package/dist/render/shaders/generated/line.wgsl.js +1 -1
  120. package/dist/render/shaders/generated/particle.wgsl.d.ts +3 -3
  121. package/dist/render/shaders/generated/particle.wgsl.js +3 -3
  122. package/dist/render/shaders/generated/rush.wgsl.d.ts +1 -1
  123. package/dist/render/shaders/generated/rush.wgsl.js +1 -1
  124. package/dist/render/shaders/generated/sdfText.wgsl.d.ts +1 -1
  125. package/dist/render/shaders/generated/sdfText.wgsl.js +1 -1
  126. package/dist/render/shaders/generated/skinBlur.wgsl.d.ts +48 -0
  127. package/dist/render/shaders/generated/skinBlur.wgsl.js +54 -0
  128. package/dist/render/shaders/generated/temporalResolve.wgsl.d.ts +1 -1
  129. package/dist/render/shaders/generated/temporalResolve.wgsl.js +1 -1
  130. package/dist/render/shaders/line.d.ts +1 -1
  131. package/dist/render/shaders/outputTransform.d.ts +14 -1
  132. package/dist/render/shaders/outputTransform.js +23 -1
  133. package/dist/render/shaders/particle.d.ts +3 -3
  134. package/dist/render/shaders/recon/motion.wgsl.d.ts +1 -1
  135. package/dist/render/shaders/recon/motion.wgsl.js +102 -0
  136. package/dist/render/shaders/recon/resolve.wgsl.js +15 -1
  137. package/dist/render/shaders/rush.js +13 -2
  138. package/dist/render/shaders/sdfText.d.ts +1 -1
  139. package/dist/render/shaders/skinBlur.d.ts +1 -0
  140. package/dist/render/shaders/skinBlur.js +103 -0
  141. package/dist/render/shaders/skinning.d.ts +3 -1
  142. package/dist/render/shaders/skinning.js +31 -4
  143. package/dist/render/shaders/temporalResolve.js +12 -5
  144. package/dist/render/shadowCasters.d.ts +13 -1
  145. package/dist/render/skinBlur.d.ts +41 -0
  146. package/dist/render/skinBlur.js +49 -0
  147. package/dist/render/skinScatter.d.ts +67 -0
  148. package/dist/render/skinScatter.js +80 -0
  149. package/dist/render/skinnedClothRun.d.ts +26 -0
  150. package/dist/render/skinnedClothRun.js +84 -0
  151. package/dist/render/ssrPass.js +2 -1
  152. package/dist/render/surfaceModel.d.ts +129 -0
  153. package/dist/render/surfaceModel.js +152 -0
  154. package/dist/render/surfaceTexture.d.ts +55 -4
  155. package/dist/render/surfaceTexture.js +60 -46
  156. package/dist/render/textRenderer.js +2 -1
  157. package/dist/render/vertexDefaults.js +8 -0
  158. package/dist/render/waterRenderer.js +2 -1
  159. package/dist/render/windStreakRenderer.js +2 -1
  160. package/package.json +6 -6
  161. package/src/geometry/meshConcat.ts +2 -0
  162. package/src/index.ts +53 -1
  163. package/src/math/scalar.ts +1 -1
  164. package/src/render/anisotropicLobe.ts +41 -0
  165. package/src/render/backend/api.ts +52 -3
  166. package/src/render/backend/materialChanges.ts +8 -3
  167. package/src/render/backend/select.ts +8 -0
  168. package/src/render/backend/webgl2/clothTextures.ts +120 -0
  169. package/src/render/backend/webgl2/renderer.ts +750 -80
  170. package/src/render/backend/webgl2/skinScatter.ts +309 -0
  171. package/src/render/backend/webgpu/buffers.ts +137 -63
  172. package/src/render/backend/webgpu/causticsPass.ts +2 -1
  173. package/src/render/backend/webgpu/clothSolvePack.ts +161 -0
  174. package/src/render/backend/webgpu/clothTextures.ts +194 -0
  175. package/src/render/backend/webgpu/compressedUpload.ts +65 -0
  176. package/src/render/backend/webgpu/computeHost.ts +25 -0
  177. package/src/render/backend/webgpu/depthPass.ts +43 -10
  178. package/src/render/backend/webgpu/drawCommand.ts +6 -2
  179. package/src/render/backend/webgpu/filmPass.ts +2 -1
  180. package/src/render/backend/webgpu/flatPass.ts +147 -8
  181. package/src/render/backend/webgpu/gpuSkinnedCloth.ts +502 -0
  182. package/src/render/backend/webgpu/linePass.ts +2 -1
  183. package/src/render/backend/webgpu/motionPass.ts +128 -9
  184. package/src/render/backend/webgpu/panelPass.ts +2 -1
  185. package/src/render/backend/webgpu/particlePass.ts +2 -1
  186. package/src/render/backend/webgpu/plumePass.ts +2 -1
  187. package/src/render/backend/webgpu/postPass.ts +25 -6
  188. package/src/render/backend/webgpu/renderer.ts +701 -52
  189. package/src/render/backend/webgpu/sdfTextPass.ts +2 -1
  190. package/src/render/backend/webgpu/shaders/clothSolve.wgsl.ts +470 -0
  191. package/src/render/backend/webgpu/skinScatterPass.ts +309 -0
  192. package/src/render/backend/webgpu/surfaceTexturePass.ts +42 -12
  193. package/src/render/backend/webgpu/textPass.ts +2 -1
  194. package/src/render/backend/webgpu/waterPass.ts +2 -1
  195. package/src/render/backend/webgpu/windStreakPass.ts +2 -1
  196. package/src/render/boltBatch.ts +2 -1
  197. package/src/render/causticsRenderer.ts +2 -1
  198. package/src/render/clothBindingData.ts +89 -0
  199. package/src/render/clothPlacement.ts +114 -0
  200. package/src/render/compressedSource.ts +198 -0
  201. package/src/render/cutoutCaster.ts +20 -2
  202. package/src/render/cutoutDither.ts +99 -0
  203. package/src/render/decalPass.ts +2 -1
  204. package/src/render/eyeRefraction.ts +72 -0
  205. package/src/render/glCompressed.ts +86 -0
  206. package/src/render/globalMediumPass.ts +3 -2
  207. package/src/render/hairLobes.ts +188 -0
  208. package/src/render/lightBudget.ts +25 -0
  209. package/src/render/lineBatch.ts +3 -1
  210. package/src/render/mesh.ts +23 -0
  211. package/src/render/oitPass.ts +2 -1
  212. package/src/render/particleBatch.ts +3 -2
  213. package/src/render/particlePool.ts +6 -2
  214. package/src/render/plumeRenderer.ts +3 -2
  215. package/src/render/recon/motionVectors.ts +6 -3
  216. package/src/render/renderQuality.ts +37 -2
  217. package/src/render/rendererHarness.ts +4 -0
  218. package/src/render/sceneCoverage.ts +78 -0
  219. package/src/render/sceneTarget.ts +21 -0
  220. package/src/render/sdfTextRenderer.ts +2 -1
  221. package/src/render/shaders/clothBinding.ts +81 -0
  222. package/src/render/shaders/depth.ts +45 -8
  223. package/src/render/shaders/flat/anisotropic.ts +68 -0
  224. package/src/render/shaders/flat/eye.ts +82 -0
  225. package/src/render/shaders/flat/hair.ts +102 -0
  226. package/src/render/shaders/flat/index.ts +42 -3
  227. package/src/render/shaders/flat/main.ts +113 -17
  228. package/src/render/shaders/flat/models.ts +286 -0
  229. package/src/render/shaders/flat/preamble.ts +26 -24
  230. package/src/render/shaders/flat/skin.ts +116 -0
  231. package/src/render/shaders/generated/depth.wgsl.ts +66 -24
  232. package/src/render/shaders/generated/flat.wgsl.ts +1853 -1742
  233. package/src/render/shaders/generated/line.wgsl.ts +1 -1
  234. package/src/render/shaders/generated/particle.wgsl.ts +3 -3
  235. package/src/render/shaders/generated/rush.wgsl.ts +1 -1
  236. package/src/render/shaders/generated/sdfText.wgsl.ts +1 -1
  237. package/src/render/shaders/generated/skinBlur.wgsl.ts +56 -0
  238. package/src/render/shaders/generated/temporalResolve.wgsl.ts +1 -1
  239. package/src/render/shaders/outputTransform.ts +24 -1
  240. package/src/render/shaders/recon/motion.wgsl.ts +102 -0
  241. package/src/render/shaders/recon/resolve.wgsl.ts +15 -1
  242. package/src/render/shaders/rush.ts +13 -2
  243. package/src/render/shaders/skinBlur.ts +105 -0
  244. package/src/render/shaders/skinning.ts +31 -4
  245. package/src/render/shaders/temporalResolve.ts +12 -5
  246. package/src/render/shadowCasters.ts +13 -0
  247. package/src/render/skinBlur.ts +53 -0
  248. package/src/render/skinScatter.ts +92 -0
  249. package/src/render/skinnedClothRun.ts +128 -0
  250. package/src/render/ssrPass.ts +2 -1
  251. package/src/render/surfaceModel.ts +274 -0
  252. package/src/render/surfaceTexture.ts +134 -63
  253. package/src/render/textRenderer.ts +2 -1
  254. package/src/render/vertexDefaults.ts +8 -0
  255. package/src/render/waterRenderer.ts +2 -1
  256. package/src/render/windStreakRenderer.ts +2 -1
  257. package/dist/math/exact.d.ts +0 -76
  258. package/dist/math/exact.js +0 -327
  259. package/src/math/exact.ts +0 -340
@@ -4,7 +4,7 @@
4
4
  * The GLSL beside this file is the source of truth. A hand edit here is discarded by
5
5
  * the next generation, and `npm run wgsl:check` fails the build when this is stale.
6
6
  */
7
- export const TEMPORAL_RESOLVE_FRAG_WGSL = "struct Uniforms {\n uDepthToViewZ: vec4<f32>,\n uAntiFlicker: f32,\n uReprojection: mat4x4<f32>,\n uTexel: vec2<f32>,\n uPeriodStart: f32,\n uHistoryBlend: f32,\n}\n\nstruct FragmentOutput {\n @location(0) member: vec4<f32>,\n @location(1) member_1: vec4<f32>,\n @location(2) member_2: vec4<f32>,\n}\n\n@group(0) @binding(1) \nvar<uniform> unnamed: Uniforms;\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(34) \nvar uHistory_t: texture_2d<f32>;\n@group(0) @binding(35) \nvar uHistory_s: sampler;\nvar<private> fragColor: vec4<f32>;\nvar<private> flickerOut: vec4<f32>;\nvar<private> flickerMotionOut: vec4<f32>;\n@group(0) @binding(40) \nvar uDepth_t: texture_2d<f32>;\n@group(0) @binding(41) \nvar uDepth_s: sampler;\n@group(0) @binding(36) \nvar uFlicker_t: texture_2d<f32>;\n@group(0) @binding(38) \nvar uFlickerMotion_t: texture_2d<f32>;\n@group(0) @binding(37) \nvar uFlicker_s: sampler;\n@group(0) @binding(39) \nvar uFlickerMotion_s: sampler;\n\nfn repeats_u0028_f1_u003b_f1_u003b(mean: ptr<function, f32>, previous: ptr<function, f32>) -> f32 {\n var apart: f32;\n\n let _e63 = (*mean);\n let _e64 = (*previous);\n let _e67 = (*mean);\n let _e68 = (*previous);\n apart = (abs((_e63 - _e64)) / max(max(_e67, _e68), 0.003921569f));\n let _e72 = apart;\n return (1f - smoothstep(0.05f, 0.1f, _e72));\n}\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 _e68 = (*lo);\n let _e69 = (*hi);\n centre = ((_e68 + _e69) * 0.5f);\n let _e72 = (*hi);\n let _e73 = (*lo);\n extent = ((_e72 - _e73) * 0.5f);\n let _e76 = (*history);\n let _e77 = centre;\n offset = (_e76 - _e77);\n let _e79 = offset;\n let _e81 = extent;\n ratios = (abs(_e79) / max(_e81, vec3<f32>(0.0000001f, 0.0000001f, 0.0000001f)));\n let _e85 = ratios[0u];\n let _e87 = ratios[1u];\n let _e89 = ratios[2u];\n ratio = max(_e85, max(_e87, _e89));\n let _e92 = ratio;\n if (_e92 <= 1f) {\n let _e94 = (*history);\n return _e94;\n }\n let _e95 = centre;\n let _e96 = offset;\n let _e97 = ratio;\n return (_e95 + (_e96 / vec3(_e97)));\n}\n\nfn luma_u0028_vf3_u003b(c: ptr<function, vec3<f32>>) -> f32 {\n let _e61 = (*c);\n return dot(_e61, vec3<f32>(0.2126f, 0.7152f, 0.0722f));\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 _e76 = unnamed.uTexel;\n size = (vec2(1f) / _e76);\n let _e79 = (*uv);\n let _e80 = size;\n at = (_e79 * _e80);\n let _e82 = at;\n base = (floor((_e82 - vec2(0.5f))) + vec2(0.5f));\n let _e88 = at;\n let _e89 = base;\n f = (_e88 - _e89);\n let _e91 = f;\n let _e92 = f;\n let _e93 = f;\n w0_ = (_e91 * (vec2(-0.5f) + (_e92 * (vec2(1f) - (_e93 * 0.5f)))));\n let _e101 = f;\n let _e102 = f;\n let _e104 = f;\n w1_ = (vec2(1f) + ((_e101 * _e102) * (vec2(-2.5f) + (_e104 * 1.5f))));\n let _e111 = f;\n let _e112 = f;\n let _e113 = f;\n w2_ = (_e111 * (vec2(0.5f) + (_e112 * (vec2(2f) - (_e113 * 1.5f)))));\n let _e121 = f;\n let _e122 = f;\n let _e124 = f;\n w3_ = ((_e121 * _e122) * (vec2(-0.5f) + (_e124 * 0.5f)));\n let _e129 = w1_;\n let _e130 = w2_;\n w12_ = (_e129 + _e130);\n let _e132 = base;\n let _e136 = unnamed.uTexel;\n at0_ = ((_e132 - vec2(1f)) * _e136);\n let _e138 = base;\n let _e142 = unnamed.uTexel;\n at3_ = ((_e138 + vec2(2f)) * _e142);\n let _e144 = base;\n let _e145 = w2_;\n let _e146 = w12_;\n let _e150 = unnamed.uTexel;\n at12_ = ((_e144 + (_e145 / _e146)) * _e150);\n let _e153 = at12_[0u];\n let _e155 = at0_[1u];\n let _e157 = textureSampleLevel(uHistory_t, uHistory_s, vec2<f32>(_e153, _e155), 0f);\n let _e160 = w12_[0u];\n let _e162 = w0_[1u];\n let _e166 = at0_[0u];\n let _e168 = at12_[1u];\n let _e170 = textureSampleLevel(uHistory_t, uHistory_s, vec2<f32>(_e166, _e168), 0f);\n let _e173 = w0_[0u];\n let _e175 = w12_[1u];\n let _e179 = at12_;\n let _e180 = textureSampleLevel(uHistory_t, uHistory_s, _e179, 0f);\n let _e183 = w12_[0u];\n let _e185 = w12_[1u];\n let _e190 = at3_[0u];\n let _e192 = at12_[1u];\n let _e194 = textureSampleLevel(uHistory_t, uHistory_s, vec2<f32>(_e190, _e192), 0f);\n let _e197 = w3_[0u];\n let _e199 = w12_[1u];\n let _e204 = at12_[0u];\n let _e206 = at3_[1u];\n let _e208 = textureSampleLevel(uHistory_t, uHistory_s, vec2<f32>(_e204, _e206), 0f);\n let _e211 = w12_[0u];\n let _e213 = w3_[1u];\n sum = (((((_e157.xyz * (_e160 * _e162)) + (_e170.xyz * (_e173 * _e175))) + (_e180.xyz * (_e183 * _e185))) + (_e194.xyz * (_e197 * _e199))) + (_e208.xyz * (_e211 * _e213)));\n let _e218 = w12_[0u];\n let _e220 = w0_[1u];\n let _e223 = w0_[0u];\n let _e225 = w12_[1u];\n let _e229 = w12_[0u];\n let _e231 = w12_[1u];\n let _e235 = w3_[0u];\n let _e237 = w12_[1u];\n let _e241 = w12_[0u];\n let _e243 = w3_[1u];\n weight = (((((_e218 * _e220) + (_e223 * _e225)) + (_e229 * _e231)) + (_e235 * _e237)) + (_e241 * _e243));\n let _e246 = sum;\n let _e247 = weight;\n return max((_e246 / vec3(_e247)), 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_1: 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 _e65 = y;\n if (_e65 <= 1i) {\n x = -1i;\n loop {\n let _e67 = x;\n if (_e67 <= 1i) {\n let _e69 = vUv_1;\n let _e70 = x;\n let _e72 = y;\n let _e76 = unnamed.uTexel;\n let _e79 = textureSampleLevel(uScene_t, uScene_s, (_e69 + (vec2<f32>(f32(_e70), f32(_e72)) * _e76)), 0f);\n c_1 = _e79.xyz;\n let _e81 = (*lo_1);\n let _e82 = c_1;\n (*lo_1) = min(_e81, _e82);\n let _e84 = (*hi_1);\n let _e85 = c_1;\n (*hi_1) = max(_e84, _e85);\n continue;\n } else {\n break;\n }\n continuing {\n let _e87 = x;\n x = (_e87 + 1i);\n }\n }\n continue;\n } else {\n break;\n }\n continuing {\n let _e89 = y;\n y = (_e89 + 1i);\n }\n }\n return;\n}\n\nfn viewDepthOf_u0028_f1_u003b(depth: ptr<function, f32>) -> f32 {\n var z: f32;\n\n let _e62 = (*depth);\n z = (1f - (_e62 * 2f));\n let _e67 = unnamed.uDepthToViewZ[0u];\n let _e68 = z;\n let _e72 = unnamed.uDepthToViewZ[1u];\n let _e77 = unnamed.uDepthToViewZ[2u];\n let _e78 = z;\n let _e82 = unnamed.uDepthToViewZ[3u];\n return (-(((_e67 * _e68) + _e72)) / ((_e77 * _e78) + _e82));\n}\n\nfn freshRecord_u0028_vf3_u003b(current: ptr<function, vec3<f32>>) -> vec4<f32> {\n var seen: f32;\n var param: vec3<f32>;\n\n let _e63 = (*current);\n param = _e63;\n let _e64 = luma_u0028_vf3_u003b((&param));\n seen = _e64;\n let _e65 = seen;\n let _e67 = seen;\n return vec4<f32>(0f, (_e65 * 0.125f), _e67, 0f);\n}\n\nfn main_1() {\n var current_1: vec3<f32>;\n var param_1: vec3<f32>;\n var nearestAt: vec2<f32>;\n var depth_1: f32;\n var metres: f32;\n var param_2: f32;\n var y_1: i32;\n var x_1: i32;\n var at_1: vec2<f32>;\n var tap: f32;\n var tapMetres: f32;\n var param_3: f32;\n var clip: vec4<f32>;\n var previous_1: vec4<f32>;\n var param_4: vec3<f32>;\n var wasUv: vec2<f32>;\n var param_5: vec3<f32>;\n var lo_2: vec3<f32>;\n var hi_2: vec3<f32>;\n var param_6: vec3<f32>;\n var param_7: vec3<f32>;\n var history_1: vec3<f32>;\n var param_8: vec2<f32>;\n var size_1: vec2<i32>;\n var was: vec2<i32>;\n var nearest: f32;\n var n: i32;\n var at_2: vec2<i32>;\n var local: vec2<i32>;\n var local_1: vec2<i32>;\n var local_2: vec2<i32>;\n var stood: f32;\n var motionThere: vec4<f32>;\n var missedAll: bool;\n var same: bool;\n var swingOut: f32;\n var local_3: f32;\n var seen_1: f32;\n var param_9: vec3<f32>;\n var held: vec4<f32>;\n var local_4: vec4<f32>;\n var param_10: vec3<f32>;\n var still: f32;\n var apart_1: f32;\n var reach: f32;\n var within: bool;\n var proven: bool;\n var widen: f32;\n var local_5: f32;\n var blend: f32;\n var local_6: f32;\n var bounded: vec3<f32>;\n var param_11: vec3<f32>;\n var param_12: vec3<f32>;\n var param_13: vec3<f32>;\n var sum_1: f32;\n var mean_1: f32;\n var repeated: f32;\n var local_7: f32;\n var param_14: f32;\n var param_15: f32;\n var local_8: f32;\n var phi_589_: bool;\n var phi_596_: bool;\n var phi_603_: bool;\n var phi_740_: bool;\n\n let _e122 = vUv_1;\n let _e123 = textureSampleLevel(uScene_t, uScene_s, _e122, 0f);\n current_1 = _e123.xyz;\n let _e126 = unnamed.uHistoryBlend;\n if (_e126 <= 0f) {\n let _e128 = current_1;\n fragColor = vec4<f32>(_e128.x, _e128.y, _e128.z, 1f);\n let _e133 = current_1;\n param_1 = _e133;\n let _e134 = freshRecord_u0028_vf3_u003b((&param_1));\n flickerOut = _e134;\n flickerMotionOut = vec4<f32>(0f, 0f, 0f, 0f);\n return;\n }\n let _e135 = vUv_1;\n nearestAt = _e135;\n let _e136 = vUv_1;\n let _e137 = textureSampleLevel(uDepth_t, uDepth_s, _e136, 0f);\n depth_1 = _e137.x;\n let _e139 = depth_1;\n param_2 = _e139;\n let _e140 = viewDepthOf_u0028_f1_u003b((&param_2));\n metres = _e140;\n y_1 = -1i;\n loop {\n let _e141 = y_1;\n if (_e141 <= 1i) {\n x_1 = -1i;\n loop {\n let _e143 = x_1;\n if (_e143 <= 1i) {\n let _e145 = vUv_1;\n let _e146 = x_1;\n let _e148 = y_1;\n let _e152 = unnamed.uTexel;\n at_1 = (_e145 + (vec2<f32>(f32(_e146), f32(_e148)) * _e152));\n let _e155 = at_1;\n let _e156 = textureSampleLevel(uDepth_t, uDepth_s, _e155, 0f);\n tap = _e156.x;\n let _e158 = tap;\n param_3 = _e158;\n let _e159 = viewDepthOf_u0028_f1_u003b((&param_3));\n tapMetres = _e159;\n let _e160 = tapMetres;\n let _e161 = metres;\n if (_e160 < _e161) {\n let _e163 = tapMetres;\n metres = _e163;\n let _e164 = tap;\n depth_1 = _e164;\n let _e165 = at_1;\n nearestAt = _e165;\n }\n continue;\n } else {\n break;\n }\n continuing {\n let _e166 = x_1;\n x_1 = (_e166 + 1i);\n }\n }\n continue;\n } else {\n break;\n }\n continuing {\n let _e168 = y_1;\n y_1 = (_e168 + 1i);\n }\n }\n let _e170 = nearestAt;\n let _e173 = ((_e170 * 2f) - vec2(1f));\n let _e174 = depth_1;\n clip = vec4<f32>(_e173.x, _e173.y, (1f - (_e174 * 2f)), 1f);\n let _e181 = unnamed.uReprojection;\n let _e182 = clip;\n previous_1 = (_e181 * _e182);\n let _e185 = previous_1[3u];\n if (_e185 <= 0f) {\n let _e187 = current_1;\n fragColor = vec4<f32>(_e187.x, _e187.y, _e187.z, 1f);\n let _e192 = current_1;\n param_4 = _e192;\n let _e193 = freshRecord_u0028_vf3_u003b((&param_4));\n flickerOut = _e193;\n let _e194 = metres;\n flickerMotionOut = vec4<f32>(_e194, 0f, 0f, 0f);\n return;\n }\n let _e196 = vUv_1;\n let _e197 = previous_1;\n let _e200 = previous_1[3u];\n let _e206 = nearestAt;\n wasUv = (_e196 + ((((_e197.xy / vec2(_e200)) * 0.5f) + vec2(0.5f)) - _e206));\n let _e210 = wasUv[0u];\n let _e211 = (_e210 < 0f);\n phi_589_ = _e211;\n if !(_e211) {\n let _e214 = wasUv[0u];\n phi_589_ = (_e214 > 1f);\n }\n let _e217 = phi_589_;\n phi_596_ = _e217;\n if !(_e217) {\n let _e220 = wasUv[1u];\n phi_596_ = (_e220 < 0f);\n }\n let _e223 = phi_596_;\n phi_603_ = _e223;\n if !(_e223) {\n let _e226 = wasUv[1u];\n phi_603_ = (_e226 > 1f);\n }\n let _e229 = phi_603_;\n if _e229 {\n let _e230 = current_1;\n fragColor = vec4<f32>(_e230.x, _e230.y, _e230.z, 1f);\n let _e235 = current_1;\n param_5 = _e235;\n let _e236 = freshRecord_u0028_vf3_u003b((&param_5));\n flickerOut = _e236;\n let _e237 = metres;\n flickerMotionOut = vec4<f32>(_e237, 0f, 0f, 0f);\n return;\n }\n neighbourhood_u0028_vf3_u003b_vf3_u003b((&param_6), (&param_7));\n let _e239 = param_6;\n lo_2 = _e239;\n let _e240 = param_7;\n hi_2 = _e240;\n let _e241 = wasUv;\n param_8 = _e241;\n let _e242 = historyCatmullRom_u0028_vf2_u003b((&param_8));\n history_1 = _e242;\n let _e243 = textureDimensions(uFlicker_t, 0i);\n size_1 = vec2<i32>(_e243);\n let _e245 = wasUv;\n let _e246 = size_1;\n let _e250 = size_1;\n was = clamp(vec2<i32>((_e245 * vec2<f32>(_e246))), vec2<i32>(0i, 0i), (_e250 - vec2(1i)));\n nearest = 1000000000f;\n n = 0i;\n loop {\n let _e254 = n;\n if (_e254 < 5i) {\n let _e256 = was;\n let _e257 = n;\n if (_e257 == 1i) {\n local = vec2<i32>(1i, 0i);\n } else {\n let _e259 = n;\n if (_e259 == 2i) {\n local_1 = vec2<i32>(-1i, 0i);\n } else {\n let _e261 = n;\n if (_e261 == 3i) {\n local_2 = vec2<i32>(0i, 1i);\n } else {\n let _e263 = n;\n local_2 = select(vec2<i32>(0i, 0i), vec2<i32>(0i, -1i), vec2((_e263 == 4i)));\n }\n let _e267 = local_2;\n local_1 = _e267;\n }\n let _e268 = local_1;\n local = _e268;\n }\n let _e269 = local;\n at_2 = (_e256 + _e269);\n let _e271 = at_2;\n let _e272 = size_1;\n let _e276 = textureLoad(uFlickerMotion_t, clamp(_e271, vec2<i32>(0i, 0i), (_e272 - vec2(1i))), 0i);\n stood = _e276.x;\n let _e278 = stood;\n if (_e278 > 0f) {\n let _e280 = nearest;\n let _e281 = stood;\n let _e283 = previous_1[3u];\n nearest = min(_e280, abs((_e281 - _e283)));\n }\n continue;\n } else {\n break;\n }\n continuing {\n let _e287 = n;\n n = (_e287 + 1i);\n }\n }\n let _e289 = was;\n let _e290 = textureLoad(uFlickerMotion_t, _e289, 0i);\n motionThere = _e290;\n let _e291 = nearest;\n missedAll = (_e291 > 100000000f);\n let _e294 = unnamed.uAntiFlicker;\n let _e296 = missedAll;\n let _e298 = ((_e294 > 0.5f) && !(_e296));\n phi_740_ = _e298;\n if _e298 {\n let _e299 = nearest;\n let _e301 = motionThere[1u];\n let _e304 = previous_1[3u];\n phi_740_ = (_e299 <= ((6f * _e301) + (0.02f * _e304)));\n }\n let _e309 = phi_740_;\n same = _e309;\n let _e310 = missedAll;\n if _e310 {\n local_3 = 0f;\n } else {\n let _e312 = motionThere[1u];\n let _e313 = nearest;\n let _e315 = motionThere[1u];\n local_3 = (_e312 + ((_e313 - _e315) * 0.125f));\n }\n let _e319 = local_3;\n swingOut = _e319;\n let _e320 = current_1;\n param_9 = _e320;\n let _e321 = luma_u0028_vf3_u003b((&param_9));\n seen_1 = _e321;\n let _e322 = same;\n if _e322 {\n let _e323 = was;\n let _e324 = textureLoad(uFlicker_t, _e323, 0i);\n local_4 = _e324;\n } else {\n let _e325 = current_1;\n param_10 = _e325;\n let _e326 = freshRecord_u0028_vf3_u003b((&param_10));\n local_4 = _e326;\n }\n let _e327 = local_4;\n held = _e327;\n let _e328 = wasUv;\n let _e329 = vUv_1;\n let _e332 = unnamed.uTexel;\n still = (1f - smoothstep(0.01f, 0.05f, length(((_e328 - _e329) / _e332))));\n let _e337 = seen_1;\n let _e339 = held[2u];\n apart_1 = abs((_e337 - _e339));\n let _e343 = held[0u];\n reach = ((6f * _e343) + 0.003921569f);\n let _e346 = apart_1;\n let _e347 = reach;\n within = (_e346 <= _e347);\n let _e350 = held[3u];\n let _e352 = within;\n proven = ((_e350 > 0.75f) && _e352);\n let _e354 = proven;\n if _e354 {\n let _e356 = held[0u];\n let _e358 = still;\n local_5 = ((6f * _e356) * _e358);\n } else {\n local_5 = 0f;\n }\n let _e360 = local_5;\n widen = _e360;\n let _e361 = proven;\n if _e361 {\n let _e363 = unnamed.uHistoryBlend;\n let _e364 = still;\n local_6 = mix(_e363, 0.97f, _e364);\n } else {\n let _e367 = unnamed.uHistoryBlend;\n local_6 = _e367;\n }\n let _e368 = local_6;\n blend = _e368;\n let _e369 = lo_2;\n let _e370 = widen;\n let _e373 = hi_2;\n let _e374 = widen;\n let _e377 = history_1;\n param_11 = _e377;\n param_12 = (_e369 - vec3(_e370));\n param_13 = (_e373 + vec3(_e374));\n let _e378 = clipToNeighbourhood_u0028_vf3_u003b_vf3_u003b_vf3_u003b((&param_11), (&param_12), (&param_13));\n bounded = _e378;\n let _e380 = held[1u];\n sum_1 = _e380;\n let _e382 = held[2u];\n mean_1 = _e382;\n let _e383 = within;\n if _e383 {\n let _e385 = held[3u];\n local_7 = _e385;\n } else {\n local_7 = 0f;\n }\n let _e386 = local_7;\n repeated = _e386;\n let _e388 = unnamed.uPeriodStart;\n if (_e388 > 0.5f) {\n let _e390 = sum_1;\n param_14 = _e390;\n let _e391 = mean_1;\n param_15 = _e391;\n let _e392 = repeats_u0028_f1_u003b_f1_u003b((&param_14), (&param_15));\n if (_e392 > 0.5f) {\n let _e394 = repeated;\n local_8 = min(1f, (_e394 + 0.5f));\n } else {\n local_8 = 0f;\n }\n let _e397 = local_8;\n repeated = _e397;\n let _e398 = sum_1;\n mean_1 = _e398;\n sum_1 = 0f;\n }\n let _e400 = held[0u];\n let _e401 = apart_1;\n let _e403 = held[0u];\n let _e407 = sum_1;\n let _e408 = seen_1;\n let _e411 = mean_1;\n let _e412 = repeated;\n let _e413 = still;\n flickerOut = vec4<f32>((_e400 + ((_e401 - _e403) * 0.125f)), (_e407 + (_e408 * 0.125f)), _e411, (_e412 * _e413));\n let _e416 = metres;\n let _e417 = swingOut;\n flickerMotionOut = vec4<f32>(_e416, _e417, 0f, 0f);\n let _e419 = current_1;\n let _e420 = bounded;\n let _e421 = blend;\n let _e423 = mix(_e419, _e420, vec3(_e421));\n fragColor = vec4<f32>(_e423.x, _e423.y, _e423.z, 1f);\n return;\n}\n\n@fragment \nfn main(@location(0) vUv: vec2<f32>) -> FragmentOutput {\n vUv_1 = vUv;\n main_1();\n let _e5 = fragColor;\n let _e6 = flickerOut;\n let _e7 = flickerMotionOut;\n return FragmentOutput(_e5, _e6, _e7);\n}\n";
7
+ export const TEMPORAL_RESOLVE_FRAG_WGSL = "struct Uniforms {\n uDepthToViewZ: vec4<f32>,\n uAntiFlicker: f32,\n uReprojection: mat4x4<f32>,\n uTexel: vec2<f32>,\n uPeriodStart: f32,\n uHistoryBlend: f32,\n}\n\nstruct FragmentOutput {\n @location(0) member: vec4<f32>,\n @location(1) member_1: vec4<f32>,\n @location(2) member_2: vec4<f32>,\n}\n\n@group(0) @binding(1) \nvar<uniform> unnamed: Uniforms;\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(34) \nvar uHistory_t: texture_2d<f32>;\n@group(0) @binding(35) \nvar uHistory_s: sampler;\nvar<private> fragColor: vec4<f32>;\nvar<private> flickerOut: vec4<f32>;\nvar<private> flickerMotionOut: vec4<f32>;\n@group(0) @binding(40) \nvar uDepth_t: texture_2d<f32>;\n@group(0) @binding(41) \nvar uDepth_s: sampler;\n@group(0) @binding(36) \nvar uFlicker_t: texture_2d<f32>;\n@group(0) @binding(38) \nvar uFlickerMotion_t: texture_2d<f32>;\n@group(0) @binding(37) \nvar uFlicker_s: sampler;\n@group(0) @binding(39) \nvar uFlickerMotion_s: sampler;\n\nfn repeats_u0028_f1_u003b_f1_u003b(mean: ptr<function, f32>, previous: ptr<function, f32>) -> f32 {\n var apart: f32;\n\n let _e63 = (*mean);\n let _e64 = (*previous);\n let _e67 = (*mean);\n let _e68 = (*previous);\n apart = (abs((_e63 - _e64)) / max(max(_e67, _e68), 0.003921569f));\n let _e72 = apart;\n return (1f - smoothstep(0.05f, 0.1f, _e72));\n}\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 _e68 = (*lo);\n let _e69 = (*hi);\n centre = ((_e68 + _e69) * 0.5f);\n let _e72 = (*hi);\n let _e73 = (*lo);\n extent = ((_e72 - _e73) * 0.5f);\n let _e76 = (*history);\n let _e77 = centre;\n offset = (_e76 - _e77);\n let _e79 = offset;\n let _e81 = extent;\n ratios = (abs(_e79) / max(_e81, vec3<f32>(0.0000001f, 0.0000001f, 0.0000001f)));\n let _e85 = ratios[0u];\n let _e87 = ratios[1u];\n let _e89 = ratios[2u];\n ratio = max(_e85, max(_e87, _e89));\n let _e92 = ratio;\n if (_e92 <= 1f) {\n let _e94 = (*history);\n return _e94;\n }\n let _e95 = centre;\n let _e96 = offset;\n let _e97 = ratio;\n return (_e95 + (_e96 / vec3(_e97)));\n}\n\nfn luma_u0028_vf3_u003b(c: ptr<function, vec3<f32>>) -> f32 {\n let _e61 = (*c);\n return dot(_e61, vec3<f32>(0.2126f, 0.7152f, 0.0722f));\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 _e76 = unnamed.uTexel;\n size = (vec2(1f) / _e76);\n let _e79 = (*uv);\n let _e80 = size;\n at = (_e79 * _e80);\n let _e82 = at;\n base = (floor((_e82 - vec2(0.5f))) + vec2(0.5f));\n let _e88 = at;\n let _e89 = base;\n f = (_e88 - _e89);\n let _e91 = f;\n let _e92 = f;\n let _e93 = f;\n w0_ = (_e91 * (vec2(-0.5f) + (_e92 * (vec2(1f) - (_e93 * 0.5f)))));\n let _e101 = f;\n let _e102 = f;\n let _e104 = f;\n w1_ = (vec2(1f) + ((_e101 * _e102) * (vec2(-2.5f) + (_e104 * 1.5f))));\n let _e111 = f;\n let _e112 = f;\n let _e113 = f;\n w2_ = (_e111 * (vec2(0.5f) + (_e112 * (vec2(2f) - (_e113 * 1.5f)))));\n let _e121 = f;\n let _e122 = f;\n let _e124 = f;\n w3_ = ((_e121 * _e122) * (vec2(-0.5f) + (_e124 * 0.5f)));\n let _e129 = w1_;\n let _e130 = w2_;\n w12_ = (_e129 + _e130);\n let _e132 = base;\n let _e136 = unnamed.uTexel;\n at0_ = ((_e132 - vec2(1f)) * _e136);\n let _e138 = base;\n let _e142 = unnamed.uTexel;\n at3_ = ((_e138 + vec2(2f)) * _e142);\n let _e144 = base;\n let _e145 = w2_;\n let _e146 = w12_;\n let _e150 = unnamed.uTexel;\n at12_ = ((_e144 + (_e145 / _e146)) * _e150);\n let _e153 = at12_[0u];\n let _e155 = at0_[1u];\n let _e157 = textureSampleLevel(uHistory_t, uHistory_s, vec2<f32>(_e153, _e155), 0f);\n let _e160 = w12_[0u];\n let _e162 = w0_[1u];\n let _e166 = at0_[0u];\n let _e168 = at12_[1u];\n let _e170 = textureSampleLevel(uHistory_t, uHistory_s, vec2<f32>(_e166, _e168), 0f);\n let _e173 = w0_[0u];\n let _e175 = w12_[1u];\n let _e179 = at12_;\n let _e180 = textureSampleLevel(uHistory_t, uHistory_s, _e179, 0f);\n let _e183 = w12_[0u];\n let _e185 = w12_[1u];\n let _e190 = at3_[0u];\n let _e192 = at12_[1u];\n let _e194 = textureSampleLevel(uHistory_t, uHistory_s, vec2<f32>(_e190, _e192), 0f);\n let _e197 = w3_[0u];\n let _e199 = w12_[1u];\n let _e204 = at12_[0u];\n let _e206 = at3_[1u];\n let _e208 = textureSampleLevel(uHistory_t, uHistory_s, vec2<f32>(_e204, _e206), 0f);\n let _e211 = w12_[0u];\n let _e213 = w3_[1u];\n sum = (((((_e157.xyz * (_e160 * _e162)) + (_e170.xyz * (_e173 * _e175))) + (_e180.xyz * (_e183 * _e185))) + (_e194.xyz * (_e197 * _e199))) + (_e208.xyz * (_e211 * _e213)));\n let _e218 = w12_[0u];\n let _e220 = w0_[1u];\n let _e223 = w0_[0u];\n let _e225 = w12_[1u];\n let _e229 = w12_[0u];\n let _e231 = w12_[1u];\n let _e235 = w3_[0u];\n let _e237 = w12_[1u];\n let _e241 = w12_[0u];\n let _e243 = w3_[1u];\n weight = (((((_e218 * _e220) + (_e223 * _e225)) + (_e229 * _e231)) + (_e235 * _e237)) + (_e241 * _e243));\n let _e246 = sum;\n let _e247 = weight;\n return max((_e246 / vec3(_e247)), 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_1: 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 _e65 = y;\n if (_e65 <= 1i) {\n x = -1i;\n loop {\n let _e67 = x;\n if (_e67 <= 1i) {\n let _e69 = vUv_1;\n let _e70 = x;\n let _e72 = y;\n let _e76 = unnamed.uTexel;\n let _e79 = textureSampleLevel(uScene_t, uScene_s, (_e69 + (vec2<f32>(f32(_e70), f32(_e72)) * _e76)), 0f);\n c_1 = _e79.xyz;\n let _e81 = (*lo_1);\n let _e82 = c_1;\n (*lo_1) = min(_e81, _e82);\n let _e84 = (*hi_1);\n let _e85 = c_1;\n (*hi_1) = max(_e84, _e85);\n continue;\n } else {\n break;\n }\n continuing {\n let _e87 = x;\n x = (_e87 + 1i);\n }\n }\n continue;\n } else {\n break;\n }\n continuing {\n let _e89 = y;\n y = (_e89 + 1i);\n }\n }\n return;\n}\n\nfn viewDepthOf_u0028_f1_u003b(depth: ptr<function, f32>) -> f32 {\n var z: f32;\n\n let _e62 = (*depth);\n z = (1f - (_e62 * 2f));\n let _e67 = unnamed.uDepthToViewZ[0u];\n let _e68 = z;\n let _e72 = unnamed.uDepthToViewZ[1u];\n let _e77 = unnamed.uDepthToViewZ[2u];\n let _e78 = z;\n let _e82 = unnamed.uDepthToViewZ[3u];\n return (-(((_e67 * _e68) + _e72)) / ((_e77 * _e78) + _e82));\n}\n\nfn freshRecord_u0028_vf3_u003b(current: ptr<function, vec3<f32>>) -> vec4<f32> {\n var seen: f32;\n var param: vec3<f32>;\n\n let _e63 = (*current);\n param = _e63;\n let _e64 = luma_u0028_vf3_u003b((&param));\n seen = _e64;\n let _e65 = seen;\n let _e67 = seen;\n return vec4<f32>(0f, (_e65 * 0.125f), _e67, 0f);\n}\n\nfn main_1() {\n var sampled: vec4<f32>;\n var current_1: vec3<f32>;\n var share: f32;\n var param_1: vec3<f32>;\n var nearestAt: vec2<f32>;\n var depth_1: f32;\n var metres: f32;\n var param_2: f32;\n var y_1: i32;\n var x_1: i32;\n var at_1: vec2<f32>;\n var tap: f32;\n var tapMetres: f32;\n var param_3: f32;\n var clip: vec4<f32>;\n var previous_1: vec4<f32>;\n var param_4: vec3<f32>;\n var wasUv: vec2<f32>;\n var param_5: vec3<f32>;\n var lo_2: vec3<f32>;\n var hi_2: vec3<f32>;\n var param_6: vec3<f32>;\n var param_7: vec3<f32>;\n var history_1: vec3<f32>;\n var param_8: vec2<f32>;\n var size_1: vec2<i32>;\n var was: vec2<i32>;\n var nearest: f32;\n var n: i32;\n var at_2: vec2<i32>;\n var local: vec2<i32>;\n var local_1: vec2<i32>;\n var local_2: vec2<i32>;\n var stood: f32;\n var motionThere: vec4<f32>;\n var missedAll: bool;\n var same: bool;\n var swingOut: f32;\n var local_3: f32;\n var seen_1: f32;\n var param_9: vec3<f32>;\n var held: vec4<f32>;\n var local_4: vec4<f32>;\n var param_10: vec3<f32>;\n var still: f32;\n var apart_1: f32;\n var reach: f32;\n var within: bool;\n var proven: bool;\n var widen: f32;\n var local_5: f32;\n var blend: f32;\n var local_6: f32;\n var bounded: vec3<f32>;\n var param_11: vec3<f32>;\n var param_12: vec3<f32>;\n var param_13: vec3<f32>;\n var sum_1: f32;\n var mean_1: f32;\n var repeated: f32;\n var local_7: f32;\n var param_14: f32;\n var param_15: f32;\n var local_8: f32;\n var phi_596_: bool;\n var phi_603_: bool;\n var phi_610_: bool;\n var phi_748_: bool;\n\n let _e124 = vUv_1;\n let _e125 = textureSampleLevel(uScene_t, uScene_s, _e124, 0f);\n sampled = _e125;\n let _e126 = sampled;\n current_1 = _e126.xyz;\n let _e129 = sampled[3u];\n share = _e129;\n let _e131 = unnamed.uHistoryBlend;\n if (_e131 <= 0f) {\n let _e133 = current_1;\n let _e134 = share;\n fragColor = vec4<f32>(_e133.x, _e133.y, _e133.z, _e134);\n let _e139 = current_1;\n param_1 = _e139;\n let _e140 = freshRecord_u0028_vf3_u003b((&param_1));\n flickerOut = _e140;\n flickerMotionOut = vec4<f32>(0f, 0f, 0f, 0f);\n return;\n }\n let _e141 = vUv_1;\n nearestAt = _e141;\n let _e142 = vUv_1;\n let _e143 = textureSampleLevel(uDepth_t, uDepth_s, _e142, 0f);\n depth_1 = _e143.x;\n let _e145 = depth_1;\n param_2 = _e145;\n let _e146 = viewDepthOf_u0028_f1_u003b((&param_2));\n metres = _e146;\n y_1 = -1i;\n loop {\n let _e147 = y_1;\n if (_e147 <= 1i) {\n x_1 = -1i;\n loop {\n let _e149 = x_1;\n if (_e149 <= 1i) {\n let _e151 = vUv_1;\n let _e152 = x_1;\n let _e154 = y_1;\n let _e158 = unnamed.uTexel;\n at_1 = (_e151 + (vec2<f32>(f32(_e152), f32(_e154)) * _e158));\n let _e161 = at_1;\n let _e162 = textureSampleLevel(uDepth_t, uDepth_s, _e161, 0f);\n tap = _e162.x;\n let _e164 = tap;\n param_3 = _e164;\n let _e165 = viewDepthOf_u0028_f1_u003b((&param_3));\n tapMetres = _e165;\n let _e166 = tapMetres;\n let _e167 = metres;\n if (_e166 < _e167) {\n let _e169 = tapMetres;\n metres = _e169;\n let _e170 = tap;\n depth_1 = _e170;\n let _e171 = at_1;\n nearestAt = _e171;\n }\n continue;\n } else {\n break;\n }\n continuing {\n let _e172 = x_1;\n x_1 = (_e172 + 1i);\n }\n }\n continue;\n } else {\n break;\n }\n continuing {\n let _e174 = y_1;\n y_1 = (_e174 + 1i);\n }\n }\n let _e176 = nearestAt;\n let _e179 = ((_e176 * 2f) - vec2(1f));\n let _e180 = depth_1;\n clip = vec4<f32>(_e179.x, _e179.y, (1f - (_e180 * 2f)), 1f);\n let _e187 = unnamed.uReprojection;\n let _e188 = clip;\n previous_1 = (_e187 * _e188);\n let _e191 = previous_1[3u];\n if (_e191 <= 0f) {\n let _e193 = current_1;\n let _e194 = share;\n fragColor = vec4<f32>(_e193.x, _e193.y, _e193.z, _e194);\n let _e199 = current_1;\n param_4 = _e199;\n let _e200 = freshRecord_u0028_vf3_u003b((&param_4));\n flickerOut = _e200;\n let _e201 = metres;\n flickerMotionOut = vec4<f32>(_e201, 0f, 0f, 0f);\n return;\n }\n let _e203 = vUv_1;\n let _e204 = previous_1;\n let _e207 = previous_1[3u];\n let _e213 = nearestAt;\n wasUv = (_e203 + ((((_e204.xy / vec2(_e207)) * 0.5f) + vec2(0.5f)) - _e213));\n let _e217 = wasUv[0u];\n let _e218 = (_e217 < 0f);\n phi_596_ = _e218;\n if !(_e218) {\n let _e221 = wasUv[0u];\n phi_596_ = (_e221 > 1f);\n }\n let _e224 = phi_596_;\n phi_603_ = _e224;\n if !(_e224) {\n let _e227 = wasUv[1u];\n phi_603_ = (_e227 < 0f);\n }\n let _e230 = phi_603_;\n phi_610_ = _e230;\n if !(_e230) {\n let _e233 = wasUv[1u];\n phi_610_ = (_e233 > 1f);\n }\n let _e236 = phi_610_;\n if _e236 {\n let _e237 = current_1;\n let _e238 = share;\n fragColor = vec4<f32>(_e237.x, _e237.y, _e237.z, _e238);\n let _e243 = current_1;\n param_5 = _e243;\n let _e244 = freshRecord_u0028_vf3_u003b((&param_5));\n flickerOut = _e244;\n let _e245 = metres;\n flickerMotionOut = vec4<f32>(_e245, 0f, 0f, 0f);\n return;\n }\n neighbourhood_u0028_vf3_u003b_vf3_u003b((&param_6), (&param_7));\n let _e247 = param_6;\n lo_2 = _e247;\n let _e248 = param_7;\n hi_2 = _e248;\n let _e249 = wasUv;\n param_8 = _e249;\n let _e250 = historyCatmullRom_u0028_vf2_u003b((&param_8));\n history_1 = _e250;\n let _e251 = textureDimensions(uFlicker_t, 0i);\n size_1 = vec2<i32>(_e251);\n let _e253 = wasUv;\n let _e254 = size_1;\n let _e258 = size_1;\n was = clamp(vec2<i32>((_e253 * vec2<f32>(_e254))), vec2<i32>(0i, 0i), (_e258 - vec2(1i)));\n nearest = 1000000000f;\n n = 0i;\n loop {\n let _e262 = n;\n if (_e262 < 5i) {\n let _e264 = was;\n let _e265 = n;\n if (_e265 == 1i) {\n local = vec2<i32>(1i, 0i);\n } else {\n let _e267 = n;\n if (_e267 == 2i) {\n local_1 = vec2<i32>(-1i, 0i);\n } else {\n let _e269 = n;\n if (_e269 == 3i) {\n local_2 = vec2<i32>(0i, 1i);\n } else {\n let _e271 = n;\n local_2 = select(vec2<i32>(0i, 0i), vec2<i32>(0i, -1i), vec2((_e271 == 4i)));\n }\n let _e275 = local_2;\n local_1 = _e275;\n }\n let _e276 = local_1;\n local = _e276;\n }\n let _e277 = local;\n at_2 = (_e264 + _e277);\n let _e279 = at_2;\n let _e280 = size_1;\n let _e284 = textureLoad(uFlickerMotion_t, clamp(_e279, vec2<i32>(0i, 0i), (_e280 - vec2(1i))), 0i);\n stood = _e284.x;\n let _e286 = stood;\n if (_e286 > 0f) {\n let _e288 = nearest;\n let _e289 = stood;\n let _e291 = previous_1[3u];\n nearest = min(_e288, abs((_e289 - _e291)));\n }\n continue;\n } else {\n break;\n }\n continuing {\n let _e295 = n;\n n = (_e295 + 1i);\n }\n }\n let _e297 = was;\n let _e298 = textureLoad(uFlickerMotion_t, _e297, 0i);\n motionThere = _e298;\n let _e299 = nearest;\n missedAll = (_e299 > 100000000f);\n let _e302 = unnamed.uAntiFlicker;\n let _e304 = missedAll;\n let _e306 = ((_e302 > 0.5f) && !(_e304));\n phi_748_ = _e306;\n if _e306 {\n let _e307 = nearest;\n let _e309 = motionThere[1u];\n let _e312 = previous_1[3u];\n phi_748_ = (_e307 <= ((6f * _e309) + (0.02f * _e312)));\n }\n let _e317 = phi_748_;\n same = _e317;\n let _e318 = missedAll;\n if _e318 {\n local_3 = 0f;\n } else {\n let _e320 = motionThere[1u];\n let _e321 = nearest;\n let _e323 = motionThere[1u];\n local_3 = (_e320 + ((_e321 - _e323) * 0.125f));\n }\n let _e327 = local_3;\n swingOut = _e327;\n let _e328 = current_1;\n param_9 = _e328;\n let _e329 = luma_u0028_vf3_u003b((&param_9));\n seen_1 = _e329;\n let _e330 = same;\n if _e330 {\n let _e331 = was;\n let _e332 = textureLoad(uFlicker_t, _e331, 0i);\n local_4 = _e332;\n } else {\n let _e333 = current_1;\n param_10 = _e333;\n let _e334 = freshRecord_u0028_vf3_u003b((&param_10));\n local_4 = _e334;\n }\n let _e335 = local_4;\n held = _e335;\n let _e336 = wasUv;\n let _e337 = vUv_1;\n let _e340 = unnamed.uTexel;\n still = (1f - smoothstep(0.01f, 0.05f, length(((_e336 - _e337) / _e340))));\n let _e345 = seen_1;\n let _e347 = held[2u];\n apart_1 = abs((_e345 - _e347));\n let _e351 = held[0u];\n reach = ((6f * _e351) + 0.003921569f);\n let _e354 = apart_1;\n let _e355 = reach;\n within = (_e354 <= _e355);\n let _e358 = held[3u];\n let _e360 = within;\n proven = ((_e358 > 0.75f) && _e360);\n let _e362 = proven;\n if _e362 {\n let _e364 = held[0u];\n let _e366 = still;\n local_5 = ((6f * _e364) * _e366);\n } else {\n local_5 = 0f;\n }\n let _e368 = local_5;\n widen = _e368;\n let _e369 = proven;\n if _e369 {\n let _e371 = unnamed.uHistoryBlend;\n let _e372 = still;\n local_6 = mix(_e371, 0.97f, _e372);\n } else {\n let _e375 = unnamed.uHistoryBlend;\n local_6 = _e375;\n }\n let _e376 = local_6;\n blend = _e376;\n let _e377 = lo_2;\n let _e378 = widen;\n let _e381 = hi_2;\n let _e382 = widen;\n let _e385 = history_1;\n param_11 = _e385;\n param_12 = (_e377 - vec3(_e378));\n param_13 = (_e381 + vec3(_e382));\n let _e386 = clipToNeighbourhood_u0028_vf3_u003b_vf3_u003b_vf3_u003b((&param_11), (&param_12), (&param_13));\n bounded = _e386;\n let _e388 = held[1u];\n sum_1 = _e388;\n let _e390 = held[2u];\n mean_1 = _e390;\n let _e391 = within;\n if _e391 {\n let _e393 = held[3u];\n local_7 = _e393;\n } else {\n local_7 = 0f;\n }\n let _e394 = local_7;\n repeated = _e394;\n let _e396 = unnamed.uPeriodStart;\n if (_e396 > 0.5f) {\n let _e398 = sum_1;\n param_14 = _e398;\n let _e399 = mean_1;\n param_15 = _e399;\n let _e400 = repeats_u0028_f1_u003b_f1_u003b((&param_14), (&param_15));\n if (_e400 > 0.5f) {\n let _e402 = repeated;\n local_8 = min(1f, (_e402 + 0.5f));\n } else {\n local_8 = 0f;\n }\n let _e405 = local_8;\n repeated = _e405;\n let _e406 = sum_1;\n mean_1 = _e406;\n sum_1 = 0f;\n }\n let _e408 = held[0u];\n let _e409 = apart_1;\n let _e411 = held[0u];\n let _e415 = sum_1;\n let _e416 = seen_1;\n let _e419 = mean_1;\n let _e420 = repeated;\n let _e421 = still;\n flickerOut = vec4<f32>((_e408 + ((_e409 - _e411) * 0.125f)), (_e415 + (_e416 * 0.125f)), _e419, (_e420 * _e421));\n let _e424 = metres;\n let _e425 = swingOut;\n flickerMotionOut = vec4<f32>(_e424, _e425, 0f, 0f);\n let _e427 = current_1;\n let _e428 = bounded;\n let _e429 = blend;\n let _e431 = mix(_e427, _e428, vec3(_e429));\n let _e432 = share;\n fragColor = vec4<f32>(_e431.x, _e431.y, _e431.z, _e432);\n return;\n}\n\n@fragment \nfn main(@location(0) vUv: vec2<f32>) -> FragmentOutput {\n vUv_1 = vUv;\n main_1();\n let _e5 = fragColor;\n let _e6 = flickerOut;\n let _e7 = flickerMotionOut;\n return FragmentOutput(_e5, _e6, _e7);\n}\n";
8
8
  /**
9
9
  * What the transform assigned, so the renderer binds the same numbers.
10
10
  *
@@ -15,4 +15,4 @@
15
15
  * draws.
16
16
  */
17
17
  export declare const LINE_VERT = "#version 300 es\nlayout(location = 0) in vec3 aFrom;\nlayout(location = 1) in vec3 aTo;\n/** Along the segment (0 or 1), and which side of it (-1 or +1). */\nlayout(location = 2) in vec2 aCorner;\n\nuniform mat4 uViewProj;\nuniform mat4 uModel;\nuniform vec3 uCameraPos;\n/** Half-width in metres, and how much of a pixel a far line must still cover. */\nuniform float uWidth;\nuniform float uMinWidthPerMetre;\n\nout float vSide;\nout vec3 vWorldPos;\n\nvoid main() {\n /*\n * Through the model matrix before anything else, unlike an arc, whose endpoints are\n * world-space by nature. A line is usually attached to something that moves, and the\n * alternative is making every caller transform its own points on the CPU each frame.\n *\n * The width is deliberately *not* scaled by the model. A stroke's weight is a property\n * of how it is drawn rather than of the geometry it follows, so a card that shrinks\n * keeps the same line weight, which is what a reader expects and what a designer means.\n */\n vec3 from = (uModel * vec4(aFrom, 1.0)).xyz;\n vec3 to = (uModel * vec4(aTo, 1.0)).xyz;\n\n vec3 mid = mix(from, to, aCorner.x);\n vec3 dir = to - from;\n float len = length(dir);\n dir = len > 1e-6 ? dir / len : vec3(0.0, 1.0, 0.0);\n\n vec3 view = mid - uCameraPos;\n float dist = length(view);\n view = dist > 1e-6 ? view / dist : vec3(0.0, 0.0, 1.0);\n\n /*\n * Across the segment and across the line of sight. Degenerate exactly when the segment\n * points at the viewer, where any perpendicular is as good as another, and where the\n * segment covers almost no screen anyway.\n */\n vec3 across = cross(dir, view);\n float span = length(across);\n across = span > 1e-4 ? across / span : normalize(cross(dir, vec3(0.0, 1.0, 0.0)) + vec3(1e-3));\n\n /*\n * A floor on the world-space width that grows with distance, so a stroke never thins\n * below a pixel. Under a pixel a thin line does not get fainter, it *flickers*, because\n * the rasteriser catches it on some frames and not others.\n */\n float halfWidth = max(uWidth, dist * uMinWidthPerMetre);\n vec3 world = mid + across * aCorner.y * halfWidth;\n\n vSide = aCorner.y;\n vWorldPos = world;\n gl_Position = uViewProj * vec4(world, 1.0);\n}\n";
18
- export declare const LINE_FRAG = "#version 300 es\nprecision highp float;\n\nin float vSide;\nin vec3 vWorldPos;\n\nuniform vec3 uColor;\nuniform float uOpacity;\nuniform vec3 uCameraPos;\n/**\n * How far in from the edge the stroke fades, as a fraction of its half-width. Zero is a\n * clean edge, one is a stroke that is soft all the way to its middle.\n */\nuniform float uSoftness;\n\n\nuniform vec3 uFogColor;\n/** Extinction per metre **at the camera's own height**, not at the base. */\nuniform float uFogDensity;\n/** Reciprocal scale height of the haze, per metre. 0 is a uniform medium. */\nuniform float uFogHeightFalloff;\n/** The camera's height, so a fragment's own height is one subtraction away. */\nuniform float uFogEyeY;\nuniform vec3 uUnderwaterColor;\nuniform float uUnderwaterFogDensity;\nuniform float uUnderwaterFactor;\n/** 0 integrates a medium (Beer-Lambert); 1 ramps linearly between near and far. */\nuniform int uFogMode;\n/** Linear mode only: where haze begins, and where it is total. */\nuniform float uFogNear;\nuniform float uFogFar;\n\n/** What distance converges toward: the day's haze, or the water column. */\nvec3 mediumColor() {\n return mix(uFogColor, uUnderwaterColor, uUnderwaterFactor);\n}\n\n/**\n * How much of a surface standing at height pointY, dist metres away, is lost to\n * the medium in between. 0 is perfectly clear, 1 is the medium's own colour.\n */\nfloat mediumFog(float dist, float pointY) {\n /*\n * A depth ramp rather than a medium, for worlds authored against one.\n *\n * Beer-Lambert is the honest model and stays the default: it integrates something\n * physically there, so extinction begins at the eye and never stops. A linear near/far\n * fog is not that \u2014 it is a *look*, with a hard start distance before which the air is\n * perfectly clear, and it is what the fixed-function pipeline offered and what several\n * renderers still expose. Approximating one with the other is not a matter of tuning:\n * matched at half occlusion, the exponential curve still lays haze over everything\n * inside near, where the ramp lays none, and near-field colour desaturates toward the\n * fog colour with nothing to show for it.\n *\n * Height falloff has no meaning here and is ignored: a ramp is defined on distance\n * alone.\n */\n if (uFogMode == 1) {\n float span = max(uFogFar - uFogNear, 1e-4);\n float ramp = clamp((dist - uFogNear) / span, 0.0, 1.0);\n if (uUnderwaterFactor <= 0.0) return ramp;\n float wetLinear = uUnderwaterFogDensity * dist;\n return mix(ramp, 1.0 - exp2(-wetLinear * wetLinear * 1.442695), uUnderwaterFactor);\n }\n\n float t = (pointY - uFogEyeY) * uFogHeightFalloff;\n // (1 - e^-t)/t, which tends to 1 as the ray levels out. Guarded rather than\n // branched: at t = 0 the quotient is 0/0, and 1e-4 of a scale height is 8 mm.\n float denom = abs(t) < 1e-4 ? 1e-4 : t;\n float air = 1.0 - exp(-uFogDensity * dist * (1.0 - exp(-denom)) / denom);\n if (uUnderwaterFactor <= 0.0) return air;\n // Water is its own medium and keeps its own curve, so crossing the surface\n // changes nothing about how the water column reads.\n float wet = uUnderwaterFogDensity * dist;\n return mix(air, 1.0 - exp2(-wet * wet * 1.442695), uUnderwaterFactor);\n}\n\n\nout vec4 outColor;\n\n/** 0 none, 1 sRGB, 2 ACES then sRGB. See renderQuality.ts. */\nuniform int uOutputTransform;\n/** Scales the scene into the tone curve. 1 is the reference grade. See renderQuality.ts. */\nuniform float uOutputExposure;\n\n/*\n * ACES: the reference fit, not the cheap one.\n *\n * This was Narkowicz's single rational function, on the argument that the difference from\n * the reference curve is invisible next to the gain. That argument holds for a look and\n * fails for a *match*, which is what this option is for \u2014 aces exists so a world ported\n * from three.js reads the same, and three.js applies the full fit: into AP1 through\n * ACESInputMat, the RRT and ODT together, then back out through ACESOutputMat.\n *\n * The two curves are not a shade apart. Narkowicz is markedly brighter through the\n * midtones, which is exactly where an interior scene lives, and it is a large part of a\n * measured ~1.7x that survived correcting the colour space and the missing Lambert pi.\n * An approximation of a standard is the wrong thing to hold when the standard is the\n * specification.\n */\nvec3 rrtAndOdtFit(vec3 v) {\n vec3 a = v * (v + 0.0245786) - 0.000090537;\n vec3 b = v * (0.983729 * v + 0.4329510) + 0.238081;\n return a / b;\n}\n\nvec3 acesFilmic(vec3 x) {\n /*\n * Exposure first, because a tone curve is only defined relative to one.\n *\n * The reference RRT and ODT are graded for a dark cinema. Every renderer that ships ACES\n * scales its input to suit whatever it is actually shown on, and the factor each one\n * picks is a *look*, not a standard - so this engine takes no position and reads it from\n * the caller. Neutral by default, which is the reference grade unmodified. three.js's own\n * pick is 1 / 0.6, for a consumer matching one.\n */\n x *= uOutputExposure;\n // Columns, as GLSL reads them: sRGB -> XYZ -> D65_2_D60 -> AP1 -> RRT_SAT.\n const mat3 ACES_INPUT = mat3(\n 0.59719, 0.07600, 0.02840,\n 0.35458, 0.90834, 0.13383,\n 0.04823, 0.01566, 0.83777\n );\n // ODT_SAT -> XYZ -> D60_2_D65 -> sRGB.\n const mat3 ACES_OUTPUT = mat3(\n 1.60475, -0.10208, -0.00327,\n -0.53108, 1.10813, -0.07276,\n -0.07367, -0.00605, 1.07602\n );\n return clamp(ACES_OUTPUT * rrtAndOdtFit(ACES_INPUT * x), 0.0, 1.0);\n}\n\n/*\n * Linear to sRGB. The piecewise form rather than a plain pow: the linear toe near black\n * is where banding lives in an 8-bit buffer, and the cheap approximation puts it in the\n * wrong place.\n */\nvec3 linearToSrgb(vec3 c) {\n vec3 low = c * 12.92;\n vec3 high = 1.055 * pow(max(c, vec3(0.0)), vec3(1.0 / 2.4)) - 0.055;\n return mix(high, low, step(c, vec3(0.0031308)));\n}\n\nvec3 applyOutputTransform(vec3 c) {\n if (uOutputTransform == 0) return c;\n if (uOutputTransform == 2) c = acesFilmic(c);\n return linearToSrgb(c);\n}\n\n\nvoid main() {\n /*\n * Coverage across the ribbon: one down the middle, falling to zero at both edges.\n *\n * The band is at least one pixel wide *in screen space*, which is what lets one shader\n * draw a stroke of any width at any distance without either aliasing into a staircase or\n * blurring into a smear. A constant band is tuned for one width and is wrong at the rest,\n * which is the same argument `SDF_TEXT_FRAG` makes for the same reason.\n */\n float edge = 1.0 - abs(vSide);\n float band = max(fwidth(vSide), uSoftness);\n float coverage = smoothstep(0.0, band, edge);\n\n /*\n * Fogged like geometry, which is where this parts company with `bolt.ts`. That shader\n * includes the same helpers and never calls them, because an arc is light arriving\n * rather than a surface losing some of itself to the air on the way over. A drawn line\n * is a thing in the world and recedes like one.\n */\n float fog = mediumFog(distance(vWorldPos, uCameraPos), vWorldPos.y);\n vec3 color = mix(uColor, mediumColor(), fog);\n outColor = vec4(applyOutputTransform(color), coverage * uOpacity);\n}\n";
18
+ export declare const LINE_FRAG = "#version 300 es\nprecision highp float;\n\nin float vSide;\nin vec3 vWorldPos;\n\nuniform vec3 uColor;\nuniform float uOpacity;\nuniform vec3 uCameraPos;\n/**\n * How far in from the edge the stroke fades, as a fraction of its half-width. Zero is a\n * clean edge, one is a stroke that is soft all the way to its middle.\n */\nuniform float uSoftness;\n\n\nuniform vec3 uFogColor;\n/** Extinction per metre **at the camera's own height**, not at the base. */\nuniform float uFogDensity;\n/** Reciprocal scale height of the haze, per metre. 0 is a uniform medium. */\nuniform float uFogHeightFalloff;\n/** The camera's height, so a fragment's own height is one subtraction away. */\nuniform float uFogEyeY;\nuniform vec3 uUnderwaterColor;\nuniform float uUnderwaterFogDensity;\nuniform float uUnderwaterFactor;\n/** 0 integrates a medium (Beer-Lambert); 1 ramps linearly between near and far. */\nuniform int uFogMode;\n/** Linear mode only: where haze begins, and where it is total. */\nuniform float uFogNear;\nuniform float uFogFar;\n\n/** What distance converges toward: the day's haze, or the water column. */\nvec3 mediumColor() {\n return mix(uFogColor, uUnderwaterColor, uUnderwaterFactor);\n}\n\n/**\n * How much of a surface standing at height pointY, dist metres away, is lost to\n * the medium in between. 0 is perfectly clear, 1 is the medium's own colour.\n */\nfloat mediumFog(float dist, float pointY) {\n /*\n * A depth ramp rather than a medium, for worlds authored against one.\n *\n * Beer-Lambert is the honest model and stays the default: it integrates something\n * physically there, so extinction begins at the eye and never stops. A linear near/far\n * fog is not that \u2014 it is a *look*, with a hard start distance before which the air is\n * perfectly clear, and it is what the fixed-function pipeline offered and what several\n * renderers still expose. Approximating one with the other is not a matter of tuning:\n * matched at half occlusion, the exponential curve still lays haze over everything\n * inside near, where the ramp lays none, and near-field colour desaturates toward the\n * fog colour with nothing to show for it.\n *\n * Height falloff has no meaning here and is ignored: a ramp is defined on distance\n * alone.\n */\n if (uFogMode == 1) {\n float span = max(uFogFar - uFogNear, 1e-4);\n float ramp = clamp((dist - uFogNear) / span, 0.0, 1.0);\n if (uUnderwaterFactor <= 0.0) return ramp;\n float wetLinear = uUnderwaterFogDensity * dist;\n return mix(ramp, 1.0 - exp2(-wetLinear * wetLinear * 1.442695), uUnderwaterFactor);\n }\n\n float t = (pointY - uFogEyeY) * uFogHeightFalloff;\n // (1 - e^-t)/t, which tends to 1 as the ray levels out. Guarded rather than\n // branched: at t = 0 the quotient is 0/0, and 1e-4 of a scale height is 8 mm.\n float denom = abs(t) < 1e-4 ? 1e-4 : t;\n float air = 1.0 - exp(-uFogDensity * dist * (1.0 - exp(-denom)) / denom);\n if (uUnderwaterFactor <= 0.0) return air;\n // Water is its own medium and keeps its own curve, so crossing the surface\n // changes nothing about how the water column reads.\n float wet = uUnderwaterFogDensity * dist;\n return mix(air, 1.0 - exp2(-wet * wet * 1.442695), uUnderwaterFactor);\n}\n\n\nout vec4 outColor;\n\n/** 0 none, 1 sRGB, 2 ACES then sRGB, 3 the highlight shoulder then sRGB. See renderQuality.ts. */\nuniform int uOutputTransform;\n/** Scales the scene into the tone curve. 1 is the reference grade. See renderQuality.ts. */\nuniform float uOutputExposure;\n\n/*\n * ACES: the reference fit, not the cheap one.\n *\n * This was Narkowicz's single rational function, on the argument that the difference from\n * the reference curve is invisible next to the gain. That argument holds for a look and\n * fails for a *match*, which is what this option is for \u2014 aces exists so a world ported\n * from three.js reads the same, and three.js applies the full fit: into AP1 through\n * ACESInputMat, the RRT and ODT together, then back out through ACESOutputMat.\n *\n * The two curves are not a shade apart. Narkowicz is markedly brighter through the\n * midtones, which is exactly where an interior scene lives, and it is a large part of a\n * measured ~1.7x that survived correcting the colour space and the missing Lambert pi.\n * An approximation of a standard is the wrong thing to hold when the standard is the\n * specification.\n */\nvec3 rrtAndOdtFit(vec3 v) {\n vec3 a = v * (v + 0.0245786) - 0.000090537;\n vec3 b = v * (0.983729 * v + 0.4329510) + 0.238081;\n return a / b;\n}\n\nvec3 acesFilmic(vec3 x) {\n /*\n * Exposure first, because a tone curve is only defined relative to one.\n *\n * The reference RRT and ODT are graded for a dark cinema. Every renderer that ships ACES\n * scales its input to suit whatever it is actually shown on, and the factor each one\n * picks is a *look*, not a standard - so this engine takes no position and reads it from\n * the caller. Neutral by default, which is the reference grade unmodified. three.js's own\n * pick is 1 / 0.6, for a consumer matching one.\n */\n x *= uOutputExposure;\n // Columns, as GLSL reads them: sRGB -> XYZ -> D65_2_D60 -> AP1 -> RRT_SAT.\n const mat3 ACES_INPUT = mat3(\n 0.59719, 0.07600, 0.02840,\n 0.35458, 0.90834, 0.13383,\n 0.04823, 0.01566, 0.83777\n );\n // ODT_SAT -> XYZ -> D60_2_D65 -> sRGB.\n const mat3 ACES_OUTPUT = mat3(\n 1.60475, -0.10208, -0.00327,\n -0.53108, 1.10813, -0.07276,\n -0.07367, -0.00605, 1.07602\n );\n return clamp(ACES_OUTPUT * rrtAndOdtFit(ACES_INPUT * x), 0.0, 1.0);\n}\n\n/*\n * Linear to sRGB. The piecewise form rather than a plain pow: the linear toe near black\n * is where banding lives in an 8-bit buffer, and the cheap approximation puts it in the\n * wrong place.\n */\nvec3 linearToSrgb(vec3 c) {\n vec3 low = c * 12.92;\n vec3 high = 1.055 * pow(max(c, vec3(0.0)), vec3(1.0 / 2.4)) - 0.055;\n return mix(high, low, step(c, vec3(0.0031308)));\n}\n\n\nvec3 highlightShoulder(vec3 c) {\n float m = max(c.r, max(c.g, c.b));\n if (m <= 0.8) return c;\n float e = m - 0.8;\n return c * ((0.8 + 0.2 * e / (e + 0.2)) / m);\n}\n\nvec3 applyOutputTransform(vec3 c) {\n if (uOutputTransform == 0) return c;\n if (uOutputTransform == 2) c = acesFilmic(c);\n if (uOutputTransform == 3) c = highlightShoulder(c * uOutputExposure);\n return linearToSrgb(c);\n}\n\n\nvoid main() {\n /*\n * Coverage across the ribbon: one down the middle, falling to zero at both edges.\n *\n * The band is at least one pixel wide *in screen space*, which is what lets one shader\n * draw a stroke of any width at any distance without either aliasing into a staircase or\n * blurring into a smear. A constant band is tuned for one width and is wrong at the rest,\n * which is the same argument `SDF_TEXT_FRAG` makes for the same reason.\n */\n float edge = 1.0 - abs(vSide);\n float band = max(fwidth(vSide), uSoftness);\n float coverage = smoothstep(0.0, band, edge);\n\n /*\n * Fogged like geometry, which is where this parts company with `bolt.ts`. That shader\n * includes the same helpers and never calls them, because an arc is light arriving\n * rather than a surface losing some of itself to the air on the way over. A drawn line\n * is a thing in the world and recedes like one.\n */\n float fog = mediumFog(distance(vWorldPos, uCameraPos), vWorldPos.y);\n vec3 color = mix(uColor, mediumColor(), fog);\n outColor = vec4(applyOutputTransform(color), coverage * uOpacity);\n}\n";
@@ -26,6 +26,19 @@
26
26
  * grades, so a pass that also graded would apply a curve to its own output; every upload site
27
27
  * gates on the same `gradeHere` the mesh pass uses.
28
28
  */
29
+ /**
30
+ * A highlight shoulder that keeps a colour's hue: past 0.8 the brightest channel eases toward 1 —
31
+ * `0.8 + 0.2·e / (e + 0.2)` of an excess `e` — and the other two are scaled by the same factor, so
32
+ * an overbright red stays red rather than clipping channel by channel toward white.
33
+ *
34
+ * **Per channel is what sRGB alone does, and it is a hue shift**: `(1.6, 0.4, 0.2)` clips to
35
+ * `(1, 0.4, 0.2)`, a pinker colour and a wider core, where this gives `(0.96, 0.24, 0.12)`. The
36
+ * curve is the one a ported game's own resolve applies, read out of its build, so a port matching
37
+ * it reads the same. **What it gives up** is ACES's filmic toe and saturation roll-off: it touches
38
+ * nothing below 0.8 and never desaturates, so a scene that wants a film's look still wants ACES.
39
+ * Shared by the forward passes and the resolve, so the two cannot disagree about it.
40
+ */
41
+ export declare const HIGHLIGHT_SHOULDER_GLSL = "\nvec3 highlightShoulder(vec3 c) {\n float m = max(c.r, max(c.g, c.b));\n if (m <= 0.8) return c;\n float e = m - 0.8;\n return c * ((0.8 + 0.2 * e / (e + 0.2)) / m);\n}\n";
29
42
  /**
30
43
  * `uOutputTransform` and `uOutputExposure`, the fit, and `applyOutputTransform`.
31
44
  *
@@ -34,4 +47,4 @@
34
47
  * caller's, per draw, and a permutation per output transform would double a pipeline count for
35
48
  * a branch that costs one compare.
36
49
  */
37
- export declare const OUTPUT_TRANSFORM_GLSL = "\n/** 0 none, 1 sRGB, 2 ACES then sRGB. See renderQuality.ts. */\nuniform int uOutputTransform;\n/** Scales the scene into the tone curve. 1 is the reference grade. See renderQuality.ts. */\nuniform float uOutputExposure;\n\n/*\n * ACES: the reference fit, not the cheap one.\n *\n * This was Narkowicz's single rational function, on the argument that the difference from\n * the reference curve is invisible next to the gain. That argument holds for a look and\n * fails for a *match*, which is what this option is for \u2014 aces exists so a world ported\n * from three.js reads the same, and three.js applies the full fit: into AP1 through\n * ACESInputMat, the RRT and ODT together, then back out through ACESOutputMat.\n *\n * The two curves are not a shade apart. Narkowicz is markedly brighter through the\n * midtones, which is exactly where an interior scene lives, and it is a large part of a\n * measured ~1.7x that survived correcting the colour space and the missing Lambert pi.\n * An approximation of a standard is the wrong thing to hold when the standard is the\n * specification.\n */\nvec3 rrtAndOdtFit(vec3 v) {\n vec3 a = v * (v + 0.0245786) - 0.000090537;\n vec3 b = v * (0.983729 * v + 0.4329510) + 0.238081;\n return a / b;\n}\n\nvec3 acesFilmic(vec3 x) {\n /*\n * Exposure first, because a tone curve is only defined relative to one.\n *\n * The reference RRT and ODT are graded for a dark cinema. Every renderer that ships ACES\n * scales its input to suit whatever it is actually shown on, and the factor each one\n * picks is a *look*, not a standard - so this engine takes no position and reads it from\n * the caller. Neutral by default, which is the reference grade unmodified. three.js's own\n * pick is 1 / 0.6, for a consumer matching one.\n */\n x *= uOutputExposure;\n // Columns, as GLSL reads them: sRGB -> XYZ -> D65_2_D60 -> AP1 -> RRT_SAT.\n const mat3 ACES_INPUT = mat3(\n 0.59719, 0.07600, 0.02840,\n 0.35458, 0.90834, 0.13383,\n 0.04823, 0.01566, 0.83777\n );\n // ODT_SAT -> XYZ -> D60_2_D65 -> sRGB.\n const mat3 ACES_OUTPUT = mat3(\n 1.60475, -0.10208, -0.00327,\n -0.53108, 1.10813, -0.07276,\n -0.07367, -0.00605, 1.07602\n );\n return clamp(ACES_OUTPUT * rrtAndOdtFit(ACES_INPUT * x), 0.0, 1.0);\n}\n\n/*\n * Linear to sRGB. The piecewise form rather than a plain pow: the linear toe near black\n * is where banding lives in an 8-bit buffer, and the cheap approximation puts it in the\n * wrong place.\n */\nvec3 linearToSrgb(vec3 c) {\n vec3 low = c * 12.92;\n vec3 high = 1.055 * pow(max(c, vec3(0.0)), vec3(1.0 / 2.4)) - 0.055;\n return mix(high, low, step(c, vec3(0.0031308)));\n}\n\nvec3 applyOutputTransform(vec3 c) {\n if (uOutputTransform == 0) return c;\n if (uOutputTransform == 2) c = acesFilmic(c);\n return linearToSrgb(c);\n}\n";
50
+ export declare const OUTPUT_TRANSFORM_GLSL = "\n/** 0 none, 1 sRGB, 2 ACES then sRGB, 3 the highlight shoulder then sRGB. See renderQuality.ts. */\nuniform int uOutputTransform;\n/** Scales the scene into the tone curve. 1 is the reference grade. See renderQuality.ts. */\nuniform float uOutputExposure;\n\n/*\n * ACES: the reference fit, not the cheap one.\n *\n * This was Narkowicz's single rational function, on the argument that the difference from\n * the reference curve is invisible next to the gain. That argument holds for a look and\n * fails for a *match*, which is what this option is for \u2014 aces exists so a world ported\n * from three.js reads the same, and three.js applies the full fit: into AP1 through\n * ACESInputMat, the RRT and ODT together, then back out through ACESOutputMat.\n *\n * The two curves are not a shade apart. Narkowicz is markedly brighter through the\n * midtones, which is exactly where an interior scene lives, and it is a large part of a\n * measured ~1.7x that survived correcting the colour space and the missing Lambert pi.\n * An approximation of a standard is the wrong thing to hold when the standard is the\n * specification.\n */\nvec3 rrtAndOdtFit(vec3 v) {\n vec3 a = v * (v + 0.0245786) - 0.000090537;\n vec3 b = v * (0.983729 * v + 0.4329510) + 0.238081;\n return a / b;\n}\n\nvec3 acesFilmic(vec3 x) {\n /*\n * Exposure first, because a tone curve is only defined relative to one.\n *\n * The reference RRT and ODT are graded for a dark cinema. Every renderer that ships ACES\n * scales its input to suit whatever it is actually shown on, and the factor each one\n * picks is a *look*, not a standard - so this engine takes no position and reads it from\n * the caller. Neutral by default, which is the reference grade unmodified. three.js's own\n * pick is 1 / 0.6, for a consumer matching one.\n */\n x *= uOutputExposure;\n // Columns, as GLSL reads them: sRGB -> XYZ -> D65_2_D60 -> AP1 -> RRT_SAT.\n const mat3 ACES_INPUT = mat3(\n 0.59719, 0.07600, 0.02840,\n 0.35458, 0.90834, 0.13383,\n 0.04823, 0.01566, 0.83777\n );\n // ODT_SAT -> XYZ -> D60_2_D65 -> sRGB.\n const mat3 ACES_OUTPUT = mat3(\n 1.60475, -0.10208, -0.00327,\n -0.53108, 1.10813, -0.07276,\n -0.07367, -0.00605, 1.07602\n );\n return clamp(ACES_OUTPUT * rrtAndOdtFit(ACES_INPUT * x), 0.0, 1.0);\n}\n\n/*\n * Linear to sRGB. The piecewise form rather than a plain pow: the linear toe near black\n * is where banding lives in an 8-bit buffer, and the cheap approximation puts it in the\n * wrong place.\n */\nvec3 linearToSrgb(vec3 c) {\n vec3 low = c * 12.92;\n vec3 high = 1.055 * pow(max(c, vec3(0.0)), vec3(1.0 / 2.4)) - 0.055;\n return mix(high, low, step(c, vec3(0.0031308)));\n}\n\n\nvec3 highlightShoulder(vec3 c) {\n float m = max(c.r, max(c.g, c.b));\n if (m <= 0.8) return c;\n float e = m - 0.8;\n return c * ((0.8 + 0.2 * e / (e + 0.2)) / m);\n}\n\nvec3 applyOutputTransform(vec3 c) {\n if (uOutputTransform == 0) return c;\n if (uOutputTransform == 2) c = acesFilmic(c);\n if (uOutputTransform == 3) c = highlightShoulder(c * uOutputExposure);\n return linearToSrgb(c);\n}\n";
@@ -26,6 +26,26 @@
26
26
  * grades, so a pass that also graded would apply a curve to its own output; every upload site
27
27
  * gates on the same `gradeHere` the mesh pass uses.
28
28
  */
29
+ /**
30
+ * A highlight shoulder that keeps a colour's hue: past 0.8 the brightest channel eases toward 1 —
31
+ * `0.8 + 0.2·e / (e + 0.2)` of an excess `e` — and the other two are scaled by the same factor, so
32
+ * an overbright red stays red rather than clipping channel by channel toward white.
33
+ *
34
+ * **Per channel is what sRGB alone does, and it is a hue shift**: `(1.6, 0.4, 0.2)` clips to
35
+ * `(1, 0.4, 0.2)`, a pinker colour and a wider core, where this gives `(0.96, 0.24, 0.12)`. The
36
+ * curve is the one a ported game's own resolve applies, read out of its build, so a port matching
37
+ * it reads the same. **What it gives up** is ACES's filmic toe and saturation roll-off: it touches
38
+ * nothing below 0.8 and never desaturates, so a scene that wants a film's look still wants ACES.
39
+ * Shared by the forward passes and the resolve, so the two cannot disagree about it.
40
+ */
41
+ export const HIGHLIGHT_SHOULDER_GLSL = `
42
+ vec3 highlightShoulder(vec3 c) {
43
+ float m = max(c.r, max(c.g, c.b));
44
+ if (m <= 0.8) return c;
45
+ float e = m - 0.8;
46
+ return c * ((0.8 + 0.2 * e / (e + 0.2)) / m);
47
+ }
48
+ `;
29
49
  /**
30
50
  * `uOutputTransform` and `uOutputExposure`, the fit, and `applyOutputTransform`.
31
51
  *
@@ -35,7 +55,7 @@
35
55
  * a branch that costs one compare.
36
56
  */
37
57
  export const OUTPUT_TRANSFORM_GLSL = `
38
- /** 0 none, 1 sRGB, 2 ACES then sRGB. See renderQuality.ts. */
58
+ /** 0 none, 1 sRGB, 2 ACES then sRGB, 3 the highlight shoulder then sRGB. See renderQuality.ts. */
39
59
  uniform int uOutputTransform;
40
60
  /** Scales the scene into the tone curve. 1 is the reference grade. See renderQuality.ts. */
41
61
  uniform float uOutputExposure;
@@ -98,9 +118,11 @@ vec3 linearToSrgb(vec3 c) {
98
118
  return mix(high, low, step(c, vec3(0.0031308)));
99
119
  }
100
120
 
121
+ ${HIGHLIGHT_SHOULDER_GLSL}
101
122
  vec3 applyOutputTransform(vec3 c) {
102
123
  if (uOutputTransform == 0) return c;
103
124
  if (uOutputTransform == 2) c = acesFilmic(c);
125
+ if (uOutputTransform == 3) c = highlightShoulder(c * uOutputExposure);
104
126
  return linearToSrgb(c);
105
127
  }
106
128
  `;
@@ -47,7 +47,7 @@ export declare const PARTICLE_VERT = "#version 300 es\n/** Per-vertex: the quad
47
47
  * and unlit smoke in a world lit by fires is the tell that gives an effect away
48
48
  * fastest. A puff catching a flame's colour is most of what makes it belong.
49
49
  */
50
- export declare const PARTICLE_SMOKE_FRAG = "#version 300 es\nprecision highp float;\n\nin vec2 vUv;\nin vec3 vColor;\nin float vAlpha;\nin float vAge;\nin float vSeed;\nin vec3 vWorldPos;\nin vec3 vNormal;\n\nuniform float uTime;\nuniform vec3 uDirectionalDir;\nuniform vec3 uDirectionalColor;\nuniform vec3 uAmbient;\nuniform vec3 uCameraPos;\nuniform int uNoiseOctaves;\n/** How strongly the noise eats into the puff. 0 is a plain soft ball. */\nuniform float uErosion;\n\n#define MAX_LIGHTS 16\nuniform int uLightCount;\nuniform vec3 uLightPos[MAX_LIGHTS];\nuniform vec3 uLightColor[MAX_LIGHTS];\nuniform float uLightRadius[MAX_LIGHTS];\n// How present each light is, 0 to 1. See pointLightSelection.ts.\nuniform float uLightWeight[MAX_LIGHTS];\n\n\nuniform vec3 uFogColor;\n/** Extinction per metre **at the camera's own height**, not at the base. */\nuniform float uFogDensity;\n/** Reciprocal scale height of the haze, per metre. 0 is a uniform medium. */\nuniform float uFogHeightFalloff;\n/** The camera's height, so a fragment's own height is one subtraction away. */\nuniform float uFogEyeY;\nuniform vec3 uUnderwaterColor;\nuniform float uUnderwaterFogDensity;\nuniform float uUnderwaterFactor;\n/** 0 integrates a medium (Beer-Lambert); 1 ramps linearly between near and far. */\nuniform int uFogMode;\n/** Linear mode only: where haze begins, and where it is total. */\nuniform float uFogNear;\nuniform float uFogFar;\n\n/** What distance converges toward: the day's haze, or the water column. */\nvec3 mediumColor() {\n return mix(uFogColor, uUnderwaterColor, uUnderwaterFactor);\n}\n\n/**\n * How much of a surface standing at height pointY, dist metres away, is lost to\n * the medium in between. 0 is perfectly clear, 1 is the medium's own colour.\n */\nfloat mediumFog(float dist, float pointY) {\n /*\n * A depth ramp rather than a medium, for worlds authored against one.\n *\n * Beer-Lambert is the honest model and stays the default: it integrates something\n * physically there, so extinction begins at the eye and never stops. A linear near/far\n * fog is not that \u2014 it is a *look*, with a hard start distance before which the air is\n * perfectly clear, and it is what the fixed-function pipeline offered and what several\n * renderers still expose. Approximating one with the other is not a matter of tuning:\n * matched at half occlusion, the exponential curve still lays haze over everything\n * inside near, where the ramp lays none, and near-field colour desaturates toward the\n * fog colour with nothing to show for it.\n *\n * Height falloff has no meaning here and is ignored: a ramp is defined on distance\n * alone.\n */\n if (uFogMode == 1) {\n float span = max(uFogFar - uFogNear, 1e-4);\n float ramp = clamp((dist - uFogNear) / span, 0.0, 1.0);\n if (uUnderwaterFactor <= 0.0) return ramp;\n float wetLinear = uUnderwaterFogDensity * dist;\n return mix(ramp, 1.0 - exp2(-wetLinear * wetLinear * 1.442695), uUnderwaterFactor);\n }\n\n float t = (pointY - uFogEyeY) * uFogHeightFalloff;\n // (1 - e^-t)/t, which tends to 1 as the ray levels out. Guarded rather than\n // branched: at t = 0 the quotient is 0/0, and 1e-4 of a scale height is 8 mm.\n float denom = abs(t) < 1e-4 ? 1e-4 : t;\n float air = 1.0 - exp(-uFogDensity * dist * (1.0 - exp(-denom)) / denom);\n if (uUnderwaterFactor <= 0.0) return air;\n // Water is its own medium and keeps its own curve, so crossing the surface\n // changes nothing about how the water column reads.\n float wet = uUnderwaterFogDensity * dist;\n return mix(air, 1.0 - exp2(-wet * wet * 1.442695), uUnderwaterFactor);\n}\n\n\nfloat hash21(vec2 p) {\n return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453123);\n}\n\nfloat valueNoise(vec2 p) {\n vec2 i = floor(p);\n vec2 f = fract(p);\n vec2 u = f * f * (3.0 - 2.0 * f);\n return mix(\n mix(hash21(i), hash21(i + vec2(1.0, 0.0)), u.x),\n mix(hash21(i + vec2(0.0, 1.0)), hash21(i + vec2(1.0, 1.0)), u.x),\n u.y\n );\n}\n\nfloat billow(vec2 p, float t, int octaves) {\n float v = valueNoise(p * 2.4 + vec2(0.0, -t * 0.5)) * 0.62;\n if (octaves == 1) return v / 0.62;\n v += valueNoise(p * 5.1 + vec2(t * 0.15, -t * 0.8)) * 0.38;\n return v / 1.0;\n}\n\n\nout vec4 outColor;\n\n/** 0 none, 1 sRGB, 2 ACES then sRGB. See renderQuality.ts. */\nuniform int uOutputTransform;\n/** Scales the scene into the tone curve. 1 is the reference grade. See renderQuality.ts. */\nuniform float uOutputExposure;\n\n/*\n * ACES: the reference fit, not the cheap one.\n *\n * This was Narkowicz's single rational function, on the argument that the difference from\n * the reference curve is invisible next to the gain. That argument holds for a look and\n * fails for a *match*, which is what this option is for \u2014 aces exists so a world ported\n * from three.js reads the same, and three.js applies the full fit: into AP1 through\n * ACESInputMat, the RRT and ODT together, then back out through ACESOutputMat.\n *\n * The two curves are not a shade apart. Narkowicz is markedly brighter through the\n * midtones, which is exactly where an interior scene lives, and it is a large part of a\n * measured ~1.7x that survived correcting the colour space and the missing Lambert pi.\n * An approximation of a standard is the wrong thing to hold when the standard is the\n * specification.\n */\nvec3 rrtAndOdtFit(vec3 v) {\n vec3 a = v * (v + 0.0245786) - 0.000090537;\n vec3 b = v * (0.983729 * v + 0.4329510) + 0.238081;\n return a / b;\n}\n\nvec3 acesFilmic(vec3 x) {\n /*\n * Exposure first, because a tone curve is only defined relative to one.\n *\n * The reference RRT and ODT are graded for a dark cinema. Every renderer that ships ACES\n * scales its input to suit whatever it is actually shown on, and the factor each one\n * picks is a *look*, not a standard - so this engine takes no position and reads it from\n * the caller. Neutral by default, which is the reference grade unmodified. three.js's own\n * pick is 1 / 0.6, for a consumer matching one.\n */\n x *= uOutputExposure;\n // Columns, as GLSL reads them: sRGB -> XYZ -> D65_2_D60 -> AP1 -> RRT_SAT.\n const mat3 ACES_INPUT = mat3(\n 0.59719, 0.07600, 0.02840,\n 0.35458, 0.90834, 0.13383,\n 0.04823, 0.01566, 0.83777\n );\n // ODT_SAT -> XYZ -> D60_2_D65 -> sRGB.\n const mat3 ACES_OUTPUT = mat3(\n 1.60475, -0.10208, -0.00327,\n -0.53108, 1.10813, -0.07276,\n -0.07367, -0.00605, 1.07602\n );\n return clamp(ACES_OUTPUT * rrtAndOdtFit(ACES_INPUT * x), 0.0, 1.0);\n}\n\n/*\n * Linear to sRGB. The piecewise form rather than a plain pow: the linear toe near black\n * is where banding lives in an 8-bit buffer, and the cheap approximation puts it in the\n * wrong place.\n */\nvec3 linearToSrgb(vec3 c) {\n vec3 low = c * 12.92;\n vec3 high = 1.055 * pow(max(c, vec3(0.0)), vec3(1.0 / 2.4)) - 0.055;\n return mix(high, low, step(c, vec3(0.0031308)));\n}\n\nvec3 applyOutputTransform(vec3 c) {\n if (uOutputTransform == 0) return c;\n if (uOutputTransform == 2) c = acesFilmic(c);\n return linearToSrgb(c);\n}\n\n\nvoid main() {\n /*\n * A round, soft body first. 'smoothstep' rather than a hard disc: the edge is\n * the entire difference between a puff and a sprite, and a cut-off circle reads\n * as a decal however good the noise inside it is.\n */\n float r = length(vUv);\n float body = 1.0 - smoothstep(0.35, 1.0, r);\n if (body <= 0.0) discard;\n\n /*\n * Then eaten into by noise that drifts and coarsens as the puff ages, so it\n * dissipates by *breaking up* rather than by uniformly thinning. Uniform\n * thinning is what a fading sprite does, and it is what the old cube did.\n */\n float t = uTime * 0.55 + vSeed * 7.31;\n float n = billow(vUv * (0.9 + vAge * 1.4) + vec2(vSeed * 3.7, 0.0), t, uNoiseOctaves);\n float erode = mix(1.0, n, uErosion * (0.35 + vAge * 0.65));\n float mask = clamp(body * erode, 0.0, 1.0);\n // Feather the last of it out rather than letting a noise threshold flicker.\n mask *= smoothstep(0.0, 0.25, mask);\n if (mask <= 0.002) discard;\n\n vec3 n3 = normalize(vNormal);\n /*\n * Wrapped diffuse. Smoke transmits as well as reflects, so the terminator on a\n * puff sits well past 90\u00B0 \u2014 a hard 'max(dot, 0)' gives a lump with a black side,\n * which is exactly the \"coloured box\" failure the fidelity rules name.\n */\n float ndl = dot(n3, uDirectionalDir) * 0.5 + 0.5;\n vec3 lit = uAmbient + uDirectionalColor * ndl;\n\n for (int i = 0; i < MAX_LIGHTS; i++) {\n if (i >= uLightCount) break;\n vec3 toLight = uLightPos[i] - vWorldPos;\n float dist = length(toLight);\n float radius = uLightRadius[i];\n if (radius <= 0.0 || dist >= radius) continue;\n float falloff = 1.0 - dist / radius;\n float wrapped = dot(n3, toLight / max(dist, 1e-4)) * 0.5 + 0.5;\n lit += uLightColor[i] * falloff * falloff * wrapped * uLightWeight[i];\n }\n\n vec3 shaded = vColor * lit;\n float fog = mediumFog(distance(vWorldPos, uCameraPos), vWorldPos.y);\n outColor = vec4(applyOutputTransform(mix(shaded, mediumColor(), fog)), mask * vAlpha);\n}\n";
50
+ export declare const PARTICLE_SMOKE_FRAG = "#version 300 es\nprecision highp float;\n\nin vec2 vUv;\nin vec3 vColor;\nin float vAlpha;\nin float vAge;\nin float vSeed;\nin vec3 vWorldPos;\nin vec3 vNormal;\n\nuniform float uTime;\nuniform vec3 uDirectionalDir;\nuniform vec3 uDirectionalColor;\nuniform vec3 uAmbient;\nuniform vec3 uCameraPos;\nuniform int uNoiseOctaves;\n/** How strongly the noise eats into the puff. 0 is a plain soft ball. */\nuniform float uErosion;\n\n#define MAX_LIGHTS 16\nuniform int uLightCount;\nuniform vec3 uLightPos[MAX_LIGHTS];\nuniform vec3 uLightColor[MAX_LIGHTS];\nuniform float uLightRadius[MAX_LIGHTS];\n// How present each light is, 0 to 1. See pointLightSelection.ts.\nuniform float uLightWeight[MAX_LIGHTS];\n\n\nuniform vec3 uFogColor;\n/** Extinction per metre **at the camera's own height**, not at the base. */\nuniform float uFogDensity;\n/** Reciprocal scale height of the haze, per metre. 0 is a uniform medium. */\nuniform float uFogHeightFalloff;\n/** The camera's height, so a fragment's own height is one subtraction away. */\nuniform float uFogEyeY;\nuniform vec3 uUnderwaterColor;\nuniform float uUnderwaterFogDensity;\nuniform float uUnderwaterFactor;\n/** 0 integrates a medium (Beer-Lambert); 1 ramps linearly between near and far. */\nuniform int uFogMode;\n/** Linear mode only: where haze begins, and where it is total. */\nuniform float uFogNear;\nuniform float uFogFar;\n\n/** What distance converges toward: the day's haze, or the water column. */\nvec3 mediumColor() {\n return mix(uFogColor, uUnderwaterColor, uUnderwaterFactor);\n}\n\n/**\n * How much of a surface standing at height pointY, dist metres away, is lost to\n * the medium in between. 0 is perfectly clear, 1 is the medium's own colour.\n */\nfloat mediumFog(float dist, float pointY) {\n /*\n * A depth ramp rather than a medium, for worlds authored against one.\n *\n * Beer-Lambert is the honest model and stays the default: it integrates something\n * physically there, so extinction begins at the eye and never stops. A linear near/far\n * fog is not that \u2014 it is a *look*, with a hard start distance before which the air is\n * perfectly clear, and it is what the fixed-function pipeline offered and what several\n * renderers still expose. Approximating one with the other is not a matter of tuning:\n * matched at half occlusion, the exponential curve still lays haze over everything\n * inside near, where the ramp lays none, and near-field colour desaturates toward the\n * fog colour with nothing to show for it.\n *\n * Height falloff has no meaning here and is ignored: a ramp is defined on distance\n * alone.\n */\n if (uFogMode == 1) {\n float span = max(uFogFar - uFogNear, 1e-4);\n float ramp = clamp((dist - uFogNear) / span, 0.0, 1.0);\n if (uUnderwaterFactor <= 0.0) return ramp;\n float wetLinear = uUnderwaterFogDensity * dist;\n return mix(ramp, 1.0 - exp2(-wetLinear * wetLinear * 1.442695), uUnderwaterFactor);\n }\n\n float t = (pointY - uFogEyeY) * uFogHeightFalloff;\n // (1 - e^-t)/t, which tends to 1 as the ray levels out. Guarded rather than\n // branched: at t = 0 the quotient is 0/0, and 1e-4 of a scale height is 8 mm.\n float denom = abs(t) < 1e-4 ? 1e-4 : t;\n float air = 1.0 - exp(-uFogDensity * dist * (1.0 - exp(-denom)) / denom);\n if (uUnderwaterFactor <= 0.0) return air;\n // Water is its own medium and keeps its own curve, so crossing the surface\n // changes nothing about how the water column reads.\n float wet = uUnderwaterFogDensity * dist;\n return mix(air, 1.0 - exp2(-wet * wet * 1.442695), uUnderwaterFactor);\n}\n\n\nfloat hash21(vec2 p) {\n return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453123);\n}\n\nfloat valueNoise(vec2 p) {\n vec2 i = floor(p);\n vec2 f = fract(p);\n vec2 u = f * f * (3.0 - 2.0 * f);\n return mix(\n mix(hash21(i), hash21(i + vec2(1.0, 0.0)), u.x),\n mix(hash21(i + vec2(0.0, 1.0)), hash21(i + vec2(1.0, 1.0)), u.x),\n u.y\n );\n}\n\nfloat billow(vec2 p, float t, int octaves) {\n float v = valueNoise(p * 2.4 + vec2(0.0, -t * 0.5)) * 0.62;\n if (octaves == 1) return v / 0.62;\n v += valueNoise(p * 5.1 + vec2(t * 0.15, -t * 0.8)) * 0.38;\n return v / 1.0;\n}\n\n\nout vec4 outColor;\n\n/** 0 none, 1 sRGB, 2 ACES then sRGB, 3 the highlight shoulder then sRGB. See renderQuality.ts. */\nuniform int uOutputTransform;\n/** Scales the scene into the tone curve. 1 is the reference grade. See renderQuality.ts. */\nuniform float uOutputExposure;\n\n/*\n * ACES: the reference fit, not the cheap one.\n *\n * This was Narkowicz's single rational function, on the argument that the difference from\n * the reference curve is invisible next to the gain. That argument holds for a look and\n * fails for a *match*, which is what this option is for \u2014 aces exists so a world ported\n * from three.js reads the same, and three.js applies the full fit: into AP1 through\n * ACESInputMat, the RRT and ODT together, then back out through ACESOutputMat.\n *\n * The two curves are not a shade apart. Narkowicz is markedly brighter through the\n * midtones, which is exactly where an interior scene lives, and it is a large part of a\n * measured ~1.7x that survived correcting the colour space and the missing Lambert pi.\n * An approximation of a standard is the wrong thing to hold when the standard is the\n * specification.\n */\nvec3 rrtAndOdtFit(vec3 v) {\n vec3 a = v * (v + 0.0245786) - 0.000090537;\n vec3 b = v * (0.983729 * v + 0.4329510) + 0.238081;\n return a / b;\n}\n\nvec3 acesFilmic(vec3 x) {\n /*\n * Exposure first, because a tone curve is only defined relative to one.\n *\n * The reference RRT and ODT are graded for a dark cinema. Every renderer that ships ACES\n * scales its input to suit whatever it is actually shown on, and the factor each one\n * picks is a *look*, not a standard - so this engine takes no position and reads it from\n * the caller. Neutral by default, which is the reference grade unmodified. three.js's own\n * pick is 1 / 0.6, for a consumer matching one.\n */\n x *= uOutputExposure;\n // Columns, as GLSL reads them: sRGB -> XYZ -> D65_2_D60 -> AP1 -> RRT_SAT.\n const mat3 ACES_INPUT = mat3(\n 0.59719, 0.07600, 0.02840,\n 0.35458, 0.90834, 0.13383,\n 0.04823, 0.01566, 0.83777\n );\n // ODT_SAT -> XYZ -> D60_2_D65 -> sRGB.\n const mat3 ACES_OUTPUT = mat3(\n 1.60475, -0.10208, -0.00327,\n -0.53108, 1.10813, -0.07276,\n -0.07367, -0.00605, 1.07602\n );\n return clamp(ACES_OUTPUT * rrtAndOdtFit(ACES_INPUT * x), 0.0, 1.0);\n}\n\n/*\n * Linear to sRGB. The piecewise form rather than a plain pow: the linear toe near black\n * is where banding lives in an 8-bit buffer, and the cheap approximation puts it in the\n * wrong place.\n */\nvec3 linearToSrgb(vec3 c) {\n vec3 low = c * 12.92;\n vec3 high = 1.055 * pow(max(c, vec3(0.0)), vec3(1.0 / 2.4)) - 0.055;\n return mix(high, low, step(c, vec3(0.0031308)));\n}\n\n\nvec3 highlightShoulder(vec3 c) {\n float m = max(c.r, max(c.g, c.b));\n if (m <= 0.8) return c;\n float e = m - 0.8;\n return c * ((0.8 + 0.2 * e / (e + 0.2)) / m);\n}\n\nvec3 applyOutputTransform(vec3 c) {\n if (uOutputTransform == 0) return c;\n if (uOutputTransform == 2) c = acesFilmic(c);\n if (uOutputTransform == 3) c = highlightShoulder(c * uOutputExposure);\n return linearToSrgb(c);\n}\n\n\nvoid main() {\n /*\n * A round, soft body first. 'smoothstep' rather than a hard disc: the edge is\n * the entire difference between a puff and a sprite, and a cut-off circle reads\n * as a decal however good the noise inside it is.\n */\n float r = length(vUv);\n float body = 1.0 - smoothstep(0.35, 1.0, r);\n if (body <= 0.0) discard;\n\n /*\n * Then eaten into by noise that drifts and coarsens as the puff ages, so it\n * dissipates by *breaking up* rather than by uniformly thinning. Uniform\n * thinning is what a fading sprite does, and it is what the old cube did.\n */\n float t = uTime * 0.55 + vSeed * 7.31;\n float n = billow(vUv * (0.9 + vAge * 1.4) + vec2(vSeed * 3.7, 0.0), t, uNoiseOctaves);\n float erode = mix(1.0, n, uErosion * (0.35 + vAge * 0.65));\n float mask = clamp(body * erode, 0.0, 1.0);\n // Feather the last of it out rather than letting a noise threshold flicker.\n mask *= smoothstep(0.0, 0.25, mask);\n if (mask <= 0.002) discard;\n\n vec3 n3 = normalize(vNormal);\n /*\n * Wrapped diffuse. Smoke transmits as well as reflects, so the terminator on a\n * puff sits well past 90\u00B0 \u2014 a hard 'max(dot, 0)' gives a lump with a black side,\n * which is exactly the \"coloured box\" failure the fidelity rules name.\n */\n float ndl = dot(n3, uDirectionalDir) * 0.5 + 0.5;\n vec3 lit = uAmbient + uDirectionalColor * ndl;\n\n for (int i = 0; i < MAX_LIGHTS; i++) {\n if (i >= uLightCount) break;\n vec3 toLight = uLightPos[i] - vWorldPos;\n float dist = length(toLight);\n float radius = uLightRadius[i];\n if (radius <= 0.0 || dist >= radius) continue;\n float falloff = 1.0 - dist / radius;\n float wrapped = dot(n3, toLight / max(dist, 1e-4)) * 0.5 + 0.5;\n lit += uLightColor[i] * falloff * falloff * wrapped * uLightWeight[i];\n }\n\n vec3 shaded = vColor * lit;\n float fog = mediumFog(distance(vWorldPos, uCameraPos), vWorldPos.y);\n outColor = vec4(applyOutputTransform(mix(shaded, mediumColor(), fog)), mask * vAlpha);\n}\n";
51
51
  /**
52
52
  * Sparks and embers: additive, hot in the middle, and stretched along travel.
53
53
  *
@@ -55,7 +55,7 @@ export declare const PARTICLE_SMOKE_FRAG = "#version 300 es\nprecision highp flo
55
55
  * is what turned the first version into a grey cube at night. The core is allowed
56
56
  * past white so it reads as incandescent rather than as a pale dot.
57
57
  */
58
- export declare const PARTICLE_SPARK_FRAG = "#version 300 es\nprecision highp float;\n\nin vec2 vUv;\nin vec3 vColor;\nin float vAlpha;\nin float vAge;\nin float vSeed;\nin vec3 vWorldPos;\nin vec3 vNormal;\n\nuniform float uTime;\nuniform vec3 uCameraPos;\n/** How far past white the centre may go. */\nuniform float uCoreGain;\n\nuniform vec3 uFogColor;\n/** Extinction per metre **at the camera's own height**, not at the base. */\nuniform float uFogDensity;\n/** Reciprocal scale height of the haze, per metre. 0 is a uniform medium. */\nuniform float uFogHeightFalloff;\n/** The camera's height, so a fragment's own height is one subtraction away. */\nuniform float uFogEyeY;\nuniform vec3 uUnderwaterColor;\nuniform float uUnderwaterFogDensity;\nuniform float uUnderwaterFactor;\n/** 0 integrates a medium (Beer-Lambert); 1 ramps linearly between near and far. */\nuniform int uFogMode;\n/** Linear mode only: where haze begins, and where it is total. */\nuniform float uFogNear;\nuniform float uFogFar;\n\n/** What distance converges toward: the day's haze, or the water column. */\nvec3 mediumColor() {\n return mix(uFogColor, uUnderwaterColor, uUnderwaterFactor);\n}\n\n/**\n * How much of a surface standing at height pointY, dist metres away, is lost to\n * the medium in between. 0 is perfectly clear, 1 is the medium's own colour.\n */\nfloat mediumFog(float dist, float pointY) {\n /*\n * A depth ramp rather than a medium, for worlds authored against one.\n *\n * Beer-Lambert is the honest model and stays the default: it integrates something\n * physically there, so extinction begins at the eye and never stops. A linear near/far\n * fog is not that \u2014 it is a *look*, with a hard start distance before which the air is\n * perfectly clear, and it is what the fixed-function pipeline offered and what several\n * renderers still expose. Approximating one with the other is not a matter of tuning:\n * matched at half occlusion, the exponential curve still lays haze over everything\n * inside near, where the ramp lays none, and near-field colour desaturates toward the\n * fog colour with nothing to show for it.\n *\n * Height falloff has no meaning here and is ignored: a ramp is defined on distance\n * alone.\n */\n if (uFogMode == 1) {\n float span = max(uFogFar - uFogNear, 1e-4);\n float ramp = clamp((dist - uFogNear) / span, 0.0, 1.0);\n if (uUnderwaterFactor <= 0.0) return ramp;\n float wetLinear = uUnderwaterFogDensity * dist;\n return mix(ramp, 1.0 - exp2(-wetLinear * wetLinear * 1.442695), uUnderwaterFactor);\n }\n\n float t = (pointY - uFogEyeY) * uFogHeightFalloff;\n // (1 - e^-t)/t, which tends to 1 as the ray levels out. Guarded rather than\n // branched: at t = 0 the quotient is 0/0, and 1e-4 of a scale height is 8 mm.\n float denom = abs(t) < 1e-4 ? 1e-4 : t;\n float air = 1.0 - exp(-uFogDensity * dist * (1.0 - exp(-denom)) / denom);\n if (uUnderwaterFactor <= 0.0) return air;\n // Water is its own medium and keeps its own curve, so crossing the surface\n // changes nothing about how the water column reads.\n float wet = uUnderwaterFogDensity * dist;\n return mix(air, 1.0 - exp2(-wet * wet * 1.442695), uUnderwaterFactor);\n}\n\n\nfloat hash21(vec2 p) {\n return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453123);\n}\n\nfloat valueNoise(vec2 p) {\n vec2 i = floor(p);\n vec2 f = fract(p);\n vec2 u = f * f * (3.0 - 2.0 * f);\n return mix(\n mix(hash21(i), hash21(i + vec2(1.0, 0.0)), u.x),\n mix(hash21(i + vec2(0.0, 1.0)), hash21(i + vec2(1.0, 1.0)), u.x),\n u.y\n );\n}\n\nfloat billow(vec2 p, float t, int octaves) {\n float v = valueNoise(p * 2.4 + vec2(0.0, -t * 0.5)) * 0.62;\n if (octaves == 1) return v / 0.62;\n v += valueNoise(p * 5.1 + vec2(t * 0.15, -t * 0.8)) * 0.38;\n return v / 1.0;\n}\n\n\nout vec4 outColor;\n\n/** 0 none, 1 sRGB, 2 ACES then sRGB. See renderQuality.ts. */\nuniform int uOutputTransform;\n/** Scales the scene into the tone curve. 1 is the reference grade. See renderQuality.ts. */\nuniform float uOutputExposure;\n\n/*\n * ACES: the reference fit, not the cheap one.\n *\n * This was Narkowicz's single rational function, on the argument that the difference from\n * the reference curve is invisible next to the gain. That argument holds for a look and\n * fails for a *match*, which is what this option is for \u2014 aces exists so a world ported\n * from three.js reads the same, and three.js applies the full fit: into AP1 through\n * ACESInputMat, the RRT and ODT together, then back out through ACESOutputMat.\n *\n * The two curves are not a shade apart. Narkowicz is markedly brighter through the\n * midtones, which is exactly where an interior scene lives, and it is a large part of a\n * measured ~1.7x that survived correcting the colour space and the missing Lambert pi.\n * An approximation of a standard is the wrong thing to hold when the standard is the\n * specification.\n */\nvec3 rrtAndOdtFit(vec3 v) {\n vec3 a = v * (v + 0.0245786) - 0.000090537;\n vec3 b = v * (0.983729 * v + 0.4329510) + 0.238081;\n return a / b;\n}\n\nvec3 acesFilmic(vec3 x) {\n /*\n * Exposure first, because a tone curve is only defined relative to one.\n *\n * The reference RRT and ODT are graded for a dark cinema. Every renderer that ships ACES\n * scales its input to suit whatever it is actually shown on, and the factor each one\n * picks is a *look*, not a standard - so this engine takes no position and reads it from\n * the caller. Neutral by default, which is the reference grade unmodified. three.js's own\n * pick is 1 / 0.6, for a consumer matching one.\n */\n x *= uOutputExposure;\n // Columns, as GLSL reads them: sRGB -> XYZ -> D65_2_D60 -> AP1 -> RRT_SAT.\n const mat3 ACES_INPUT = mat3(\n 0.59719, 0.07600, 0.02840,\n 0.35458, 0.90834, 0.13383,\n 0.04823, 0.01566, 0.83777\n );\n // ODT_SAT -> XYZ -> D60_2_D65 -> sRGB.\n const mat3 ACES_OUTPUT = mat3(\n 1.60475, -0.10208, -0.00327,\n -0.53108, 1.10813, -0.07276,\n -0.07367, -0.00605, 1.07602\n );\n return clamp(ACES_OUTPUT * rrtAndOdtFit(ACES_INPUT * x), 0.0, 1.0);\n}\n\n/*\n * Linear to sRGB. The piecewise form rather than a plain pow: the linear toe near black\n * is where banding lives in an 8-bit buffer, and the cheap approximation puts it in the\n * wrong place.\n */\nvec3 linearToSrgb(vec3 c) {\n vec3 low = c * 12.92;\n vec3 high = 1.055 * pow(max(c, vec3(0.0)), vec3(1.0 / 2.4)) - 0.055;\n return mix(high, low, step(c, vec3(0.0031308)));\n}\n\nvec3 applyOutputTransform(vec3 c) {\n if (uOutputTransform == 0) return c;\n if (uOutputTransform == 2) c = acesFilmic(c);\n return linearToSrgb(c);\n}\n\n\nvoid main() {\n float r = length(vUv);\n if (r > 1.0) discard;\n\n /*\n * Two falloffs again \u2014 a tight core and a broad halo \u2014 because one gives either\n * a hard dot or a soft smudge. The halo is what makes a shower of embers read\n * as glowing air rather than as a scatter of points.\n */\n float core = pow(1.0 - clamp(r, 0.0, 1.0), 6.0);\n float halo = pow(1.0 - clamp(r, 0.0, 1.0), 1.6);\n\n /*\n * Embers flicker as they tumble and cool. Per-particle phase from the seed, so\n * a shower crackles instead of pulsing as one body.\n */\n float flick = 0.7 + 0.3 * valueNoise(vec2(uTime * 9.0 + vSeed * 13.0, vSeed));\n\n // Cooling: the last of a spark's life is dimmer as well as smaller.\n float cool = 1.0 - vAge * vAge;\n float energy = (halo * 0.55 + core * uCoreGain) * flick * cool * vAlpha;\n\n float fog = mediumFog(distance(vWorldPos, uCameraPos), vWorldPos.y);\n energy *= 1.0 - fog;\n /*\n * Alpha 1, energy in the colour \u2014 see the note in 'bolt.ts'. Additive blending is\n * 'rgb * a', so carrying the energy in both channels squares it and quietly halves\n * every emissive effect in the game.\n */\n outColor = vec4(applyOutputTransform(vColor * energy), 1.0);\n}\n";
58
+ export declare const PARTICLE_SPARK_FRAG = "#version 300 es\nprecision highp float;\n\nin vec2 vUv;\nin vec3 vColor;\nin float vAlpha;\nin float vAge;\nin float vSeed;\nin vec3 vWorldPos;\nin vec3 vNormal;\n\nuniform float uTime;\nuniform vec3 uCameraPos;\n/** How far past white the centre may go. */\nuniform float uCoreGain;\n\nuniform vec3 uFogColor;\n/** Extinction per metre **at the camera's own height**, not at the base. */\nuniform float uFogDensity;\n/** Reciprocal scale height of the haze, per metre. 0 is a uniform medium. */\nuniform float uFogHeightFalloff;\n/** The camera's height, so a fragment's own height is one subtraction away. */\nuniform float uFogEyeY;\nuniform vec3 uUnderwaterColor;\nuniform float uUnderwaterFogDensity;\nuniform float uUnderwaterFactor;\n/** 0 integrates a medium (Beer-Lambert); 1 ramps linearly between near and far. */\nuniform int uFogMode;\n/** Linear mode only: where haze begins, and where it is total. */\nuniform float uFogNear;\nuniform float uFogFar;\n\n/** What distance converges toward: the day's haze, or the water column. */\nvec3 mediumColor() {\n return mix(uFogColor, uUnderwaterColor, uUnderwaterFactor);\n}\n\n/**\n * How much of a surface standing at height pointY, dist metres away, is lost to\n * the medium in between. 0 is perfectly clear, 1 is the medium's own colour.\n */\nfloat mediumFog(float dist, float pointY) {\n /*\n * A depth ramp rather than a medium, for worlds authored against one.\n *\n * Beer-Lambert is the honest model and stays the default: it integrates something\n * physically there, so extinction begins at the eye and never stops. A linear near/far\n * fog is not that \u2014 it is a *look*, with a hard start distance before which the air is\n * perfectly clear, and it is what the fixed-function pipeline offered and what several\n * renderers still expose. Approximating one with the other is not a matter of tuning:\n * matched at half occlusion, the exponential curve still lays haze over everything\n * inside near, where the ramp lays none, and near-field colour desaturates toward the\n * fog colour with nothing to show for it.\n *\n * Height falloff has no meaning here and is ignored: a ramp is defined on distance\n * alone.\n */\n if (uFogMode == 1) {\n float span = max(uFogFar - uFogNear, 1e-4);\n float ramp = clamp((dist - uFogNear) / span, 0.0, 1.0);\n if (uUnderwaterFactor <= 0.0) return ramp;\n float wetLinear = uUnderwaterFogDensity * dist;\n return mix(ramp, 1.0 - exp2(-wetLinear * wetLinear * 1.442695), uUnderwaterFactor);\n }\n\n float t = (pointY - uFogEyeY) * uFogHeightFalloff;\n // (1 - e^-t)/t, which tends to 1 as the ray levels out. Guarded rather than\n // branched: at t = 0 the quotient is 0/0, and 1e-4 of a scale height is 8 mm.\n float denom = abs(t) < 1e-4 ? 1e-4 : t;\n float air = 1.0 - exp(-uFogDensity * dist * (1.0 - exp(-denom)) / denom);\n if (uUnderwaterFactor <= 0.0) return air;\n // Water is its own medium and keeps its own curve, so crossing the surface\n // changes nothing about how the water column reads.\n float wet = uUnderwaterFogDensity * dist;\n return mix(air, 1.0 - exp2(-wet * wet * 1.442695), uUnderwaterFactor);\n}\n\n\nfloat hash21(vec2 p) {\n return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453123);\n}\n\nfloat valueNoise(vec2 p) {\n vec2 i = floor(p);\n vec2 f = fract(p);\n vec2 u = f * f * (3.0 - 2.0 * f);\n return mix(\n mix(hash21(i), hash21(i + vec2(1.0, 0.0)), u.x),\n mix(hash21(i + vec2(0.0, 1.0)), hash21(i + vec2(1.0, 1.0)), u.x),\n u.y\n );\n}\n\nfloat billow(vec2 p, float t, int octaves) {\n float v = valueNoise(p * 2.4 + vec2(0.0, -t * 0.5)) * 0.62;\n if (octaves == 1) return v / 0.62;\n v += valueNoise(p * 5.1 + vec2(t * 0.15, -t * 0.8)) * 0.38;\n return v / 1.0;\n}\n\n\nout vec4 outColor;\n\n/** 0 none, 1 sRGB, 2 ACES then sRGB, 3 the highlight shoulder then sRGB. See renderQuality.ts. */\nuniform int uOutputTransform;\n/** Scales the scene into the tone curve. 1 is the reference grade. See renderQuality.ts. */\nuniform float uOutputExposure;\n\n/*\n * ACES: the reference fit, not the cheap one.\n *\n * This was Narkowicz's single rational function, on the argument that the difference from\n * the reference curve is invisible next to the gain. That argument holds for a look and\n * fails for a *match*, which is what this option is for \u2014 aces exists so a world ported\n * from three.js reads the same, and three.js applies the full fit: into AP1 through\n * ACESInputMat, the RRT and ODT together, then back out through ACESOutputMat.\n *\n * The two curves are not a shade apart. Narkowicz is markedly brighter through the\n * midtones, which is exactly where an interior scene lives, and it is a large part of a\n * measured ~1.7x that survived correcting the colour space and the missing Lambert pi.\n * An approximation of a standard is the wrong thing to hold when the standard is the\n * specification.\n */\nvec3 rrtAndOdtFit(vec3 v) {\n vec3 a = v * (v + 0.0245786) - 0.000090537;\n vec3 b = v * (0.983729 * v + 0.4329510) + 0.238081;\n return a / b;\n}\n\nvec3 acesFilmic(vec3 x) {\n /*\n * Exposure first, because a tone curve is only defined relative to one.\n *\n * The reference RRT and ODT are graded for a dark cinema. Every renderer that ships ACES\n * scales its input to suit whatever it is actually shown on, and the factor each one\n * picks is a *look*, not a standard - so this engine takes no position and reads it from\n * the caller. Neutral by default, which is the reference grade unmodified. three.js's own\n * pick is 1 / 0.6, for a consumer matching one.\n */\n x *= uOutputExposure;\n // Columns, as GLSL reads them: sRGB -> XYZ -> D65_2_D60 -> AP1 -> RRT_SAT.\n const mat3 ACES_INPUT = mat3(\n 0.59719, 0.07600, 0.02840,\n 0.35458, 0.90834, 0.13383,\n 0.04823, 0.01566, 0.83777\n );\n // ODT_SAT -> XYZ -> D60_2_D65 -> sRGB.\n const mat3 ACES_OUTPUT = mat3(\n 1.60475, -0.10208, -0.00327,\n -0.53108, 1.10813, -0.07276,\n -0.07367, -0.00605, 1.07602\n );\n return clamp(ACES_OUTPUT * rrtAndOdtFit(ACES_INPUT * x), 0.0, 1.0);\n}\n\n/*\n * Linear to sRGB. The piecewise form rather than a plain pow: the linear toe near black\n * is where banding lives in an 8-bit buffer, and the cheap approximation puts it in the\n * wrong place.\n */\nvec3 linearToSrgb(vec3 c) {\n vec3 low = c * 12.92;\n vec3 high = 1.055 * pow(max(c, vec3(0.0)), vec3(1.0 / 2.4)) - 0.055;\n return mix(high, low, step(c, vec3(0.0031308)));\n}\n\n\nvec3 highlightShoulder(vec3 c) {\n float m = max(c.r, max(c.g, c.b));\n if (m <= 0.8) return c;\n float e = m - 0.8;\n return c * ((0.8 + 0.2 * e / (e + 0.2)) / m);\n}\n\nvec3 applyOutputTransform(vec3 c) {\n if (uOutputTransform == 0) return c;\n if (uOutputTransform == 2) c = acesFilmic(c);\n if (uOutputTransform == 3) c = highlightShoulder(c * uOutputExposure);\n return linearToSrgb(c);\n}\n\n\nvoid main() {\n float r = length(vUv);\n if (r > 1.0) discard;\n\n /*\n * Two falloffs again \u2014 a tight core and a broad halo \u2014 because one gives either\n * a hard dot or a soft smudge. The halo is what makes a shower of embers read\n * as glowing air rather than as a scatter of points.\n */\n float core = pow(1.0 - clamp(r, 0.0, 1.0), 6.0);\n float halo = pow(1.0 - clamp(r, 0.0, 1.0), 1.6);\n\n /*\n * Embers flicker as they tumble and cool. Per-particle phase from the seed, so\n * a shower crackles instead of pulsing as one body.\n */\n float flick = 0.7 + 0.3 * valueNoise(vec2(uTime * 9.0 + vSeed * 13.0, vSeed));\n\n // Cooling: the last of a spark's life is dimmer as well as smaller.\n float cool = 1.0 - vAge * vAge;\n float energy = (halo * 0.55 + core * uCoreGain) * flick * cool * vAlpha;\n\n float fog = mediumFog(distance(vWorldPos, uCameraPos), vWorldPos.y);\n energy *= 1.0 - fog;\n /*\n * Alpha 1, energy in the colour \u2014 see the note in 'bolt.ts'. Additive blending is\n * 'rgb * a', so carrying the energy in both channels squares it and quietly halves\n * every emissive effect in the game.\n */\n outColor = vec4(applyOutputTransform(vColor * energy), 1.0);\n}\n";
59
59
  /**
60
60
  * Dust motes and drifting glints: unlit, alpha blended, and fogged only when the caller asks.
61
61
  *
@@ -79,4 +79,4 @@ export declare const PARTICLE_SPARK_FRAG = "#version 300 es\nprecision highp flo
79
79
  * option and stay unconditionally fogged, matching every particle drawn before this material
80
80
  * existed; see `ParticleBatchOptions.fog`.
81
81
  */
82
- export declare const PARTICLE_MOTE_FRAG = "#version 300 es\nprecision highp float;\n\nin vec2 vUv;\nin vec3 vColor;\nin float vAlpha;\nin float vAge;\nin float vSeed;\nin vec3 vWorldPos;\nin vec3 vNormal;\n\nuniform vec3 uCameraPos;\n/**\n * Whether the fragment stage mixes toward the medium's own colour at all. 0 \u2014 what a batch\n * gets by leaving ParticleBatchOptions.fog unset \u2014 leaves vColor untouched by distance, which\n * is what a caller reaching for this material over 'spark'/'smoke' is usually asking for: an\n * unlit point drawn exactly as its own colour says. 1 mixes toward mediumColor() by\n * mediumFog(), the same medium every other pass in the frame recedes into.\n */\nuniform int uFogEnabled;\n\nuniform vec3 uFogColor;\n/** Extinction per metre **at the camera's own height**, not at the base. */\nuniform float uFogDensity;\n/** Reciprocal scale height of the haze, per metre. 0 is a uniform medium. */\nuniform float uFogHeightFalloff;\n/** The camera's height, so a fragment's own height is one subtraction away. */\nuniform float uFogEyeY;\nuniform vec3 uUnderwaterColor;\nuniform float uUnderwaterFogDensity;\nuniform float uUnderwaterFactor;\n/** 0 integrates a medium (Beer-Lambert); 1 ramps linearly between near and far. */\nuniform int uFogMode;\n/** Linear mode only: where haze begins, and where it is total. */\nuniform float uFogNear;\nuniform float uFogFar;\n\n/** What distance converges toward: the day's haze, or the water column. */\nvec3 mediumColor() {\n return mix(uFogColor, uUnderwaterColor, uUnderwaterFactor);\n}\n\n/**\n * How much of a surface standing at height pointY, dist metres away, is lost to\n * the medium in between. 0 is perfectly clear, 1 is the medium's own colour.\n */\nfloat mediumFog(float dist, float pointY) {\n /*\n * A depth ramp rather than a medium, for worlds authored against one.\n *\n * Beer-Lambert is the honest model and stays the default: it integrates something\n * physically there, so extinction begins at the eye and never stops. A linear near/far\n * fog is not that \u2014 it is a *look*, with a hard start distance before which the air is\n * perfectly clear, and it is what the fixed-function pipeline offered and what several\n * renderers still expose. Approximating one with the other is not a matter of tuning:\n * matched at half occlusion, the exponential curve still lays haze over everything\n * inside near, where the ramp lays none, and near-field colour desaturates toward the\n * fog colour with nothing to show for it.\n *\n * Height falloff has no meaning here and is ignored: a ramp is defined on distance\n * alone.\n */\n if (uFogMode == 1) {\n float span = max(uFogFar - uFogNear, 1e-4);\n float ramp = clamp((dist - uFogNear) / span, 0.0, 1.0);\n if (uUnderwaterFactor <= 0.0) return ramp;\n float wetLinear = uUnderwaterFogDensity * dist;\n return mix(ramp, 1.0 - exp2(-wetLinear * wetLinear * 1.442695), uUnderwaterFactor);\n }\n\n float t = (pointY - uFogEyeY) * uFogHeightFalloff;\n // (1 - e^-t)/t, which tends to 1 as the ray levels out. Guarded rather than\n // branched: at t = 0 the quotient is 0/0, and 1e-4 of a scale height is 8 mm.\n float denom = abs(t) < 1e-4 ? 1e-4 : t;\n float air = 1.0 - exp(-uFogDensity * dist * (1.0 - exp(-denom)) / denom);\n if (uUnderwaterFactor <= 0.0) return air;\n // Water is its own medium and keeps its own curve, so crossing the surface\n // changes nothing about how the water column reads.\n float wet = uUnderwaterFogDensity * dist;\n return mix(air, 1.0 - exp2(-wet * wet * 1.442695), uUnderwaterFactor);\n}\n\n\nout vec4 outColor;\n\n/** 0 none, 1 sRGB, 2 ACES then sRGB. See renderQuality.ts. */\nuniform int uOutputTransform;\n/** Scales the scene into the tone curve. 1 is the reference grade. See renderQuality.ts. */\nuniform float uOutputExposure;\n\n/*\n * ACES: the reference fit, not the cheap one.\n *\n * This was Narkowicz's single rational function, on the argument that the difference from\n * the reference curve is invisible next to the gain. That argument holds for a look and\n * fails for a *match*, which is what this option is for \u2014 aces exists so a world ported\n * from three.js reads the same, and three.js applies the full fit: into AP1 through\n * ACESInputMat, the RRT and ODT together, then back out through ACESOutputMat.\n *\n * The two curves are not a shade apart. Narkowicz is markedly brighter through the\n * midtones, which is exactly where an interior scene lives, and it is a large part of a\n * measured ~1.7x that survived correcting the colour space and the missing Lambert pi.\n * An approximation of a standard is the wrong thing to hold when the standard is the\n * specification.\n */\nvec3 rrtAndOdtFit(vec3 v) {\n vec3 a = v * (v + 0.0245786) - 0.000090537;\n vec3 b = v * (0.983729 * v + 0.4329510) + 0.238081;\n return a / b;\n}\n\nvec3 acesFilmic(vec3 x) {\n /*\n * Exposure first, because a tone curve is only defined relative to one.\n *\n * The reference RRT and ODT are graded for a dark cinema. Every renderer that ships ACES\n * scales its input to suit whatever it is actually shown on, and the factor each one\n * picks is a *look*, not a standard - so this engine takes no position and reads it from\n * the caller. Neutral by default, which is the reference grade unmodified. three.js's own\n * pick is 1 / 0.6, for a consumer matching one.\n */\n x *= uOutputExposure;\n // Columns, as GLSL reads them: sRGB -> XYZ -> D65_2_D60 -> AP1 -> RRT_SAT.\n const mat3 ACES_INPUT = mat3(\n 0.59719, 0.07600, 0.02840,\n 0.35458, 0.90834, 0.13383,\n 0.04823, 0.01566, 0.83777\n );\n // ODT_SAT -> XYZ -> D60_2_D65 -> sRGB.\n const mat3 ACES_OUTPUT = mat3(\n 1.60475, -0.10208, -0.00327,\n -0.53108, 1.10813, -0.07276,\n -0.07367, -0.00605, 1.07602\n );\n return clamp(ACES_OUTPUT * rrtAndOdtFit(ACES_INPUT * x), 0.0, 1.0);\n}\n\n/*\n * Linear to sRGB. The piecewise form rather than a plain pow: the linear toe near black\n * is where banding lives in an 8-bit buffer, and the cheap approximation puts it in the\n * wrong place.\n */\nvec3 linearToSrgb(vec3 c) {\n vec3 low = c * 12.92;\n vec3 high = 1.055 * pow(max(c, vec3(0.0)), vec3(1.0 / 2.4)) - 0.055;\n return mix(high, low, step(c, vec3(0.0031308)));\n}\n\nvec3 applyOutputTransform(vec3 c) {\n if (uOutputTransform == 0) return c;\n if (uOutputTransform == 2) c = acesFilmic(c);\n return linearToSrgb(c);\n}\n\n\nvoid main() {\n /*\n * One soft, round falloff \u2014 no erosion, no core past white, because this material draws\n * neither a body being eaten by noise nor a light source. Squared rather than linear so the\n * edge feathers instead of ramping, which is what keeps a field of these reading as dust\n * rather than as a scatter of hard-edged discs.\n */\n float r = length(vUv);\n float body = 1.0 - smoothstep(0.4, 1.0, r);\n if (body <= 0.0) discard;\n float alpha = body * body * vAlpha;\n if (alpha <= 0.002) discard;\n\n vec3 color = vColor;\n if (uFogEnabled != 0) {\n float fog = mediumFog(distance(vWorldPos, uCameraPos), vWorldPos.y);\n color = mix(color, mediumColor(), fog);\n }\n /*\n * A real alpha blend (SRC_ALPHA, ONE_MINUS_SRC_ALPHA) rather than spark's energy-in-colour\n * trick: this point genuinely occludes what little is behind it instead of adding light to it.\n */\n outColor = vec4(applyOutputTransform(color), alpha);\n}\n";
82
+ export declare const PARTICLE_MOTE_FRAG = "#version 300 es\nprecision highp float;\n\nin vec2 vUv;\nin vec3 vColor;\nin float vAlpha;\nin float vAge;\nin float vSeed;\nin vec3 vWorldPos;\nin vec3 vNormal;\n\nuniform vec3 uCameraPos;\n/**\n * Whether the fragment stage mixes toward the medium's own colour at all. 0 \u2014 what a batch\n * gets by leaving ParticleBatchOptions.fog unset \u2014 leaves vColor untouched by distance, which\n * is what a caller reaching for this material over 'spark'/'smoke' is usually asking for: an\n * unlit point drawn exactly as its own colour says. 1 mixes toward mediumColor() by\n * mediumFog(), the same medium every other pass in the frame recedes into.\n */\nuniform int uFogEnabled;\n\nuniform vec3 uFogColor;\n/** Extinction per metre **at the camera's own height**, not at the base. */\nuniform float uFogDensity;\n/** Reciprocal scale height of the haze, per metre. 0 is a uniform medium. */\nuniform float uFogHeightFalloff;\n/** The camera's height, so a fragment's own height is one subtraction away. */\nuniform float uFogEyeY;\nuniform vec3 uUnderwaterColor;\nuniform float uUnderwaterFogDensity;\nuniform float uUnderwaterFactor;\n/** 0 integrates a medium (Beer-Lambert); 1 ramps linearly between near and far. */\nuniform int uFogMode;\n/** Linear mode only: where haze begins, and where it is total. */\nuniform float uFogNear;\nuniform float uFogFar;\n\n/** What distance converges toward: the day's haze, or the water column. */\nvec3 mediumColor() {\n return mix(uFogColor, uUnderwaterColor, uUnderwaterFactor);\n}\n\n/**\n * How much of a surface standing at height pointY, dist metres away, is lost to\n * the medium in between. 0 is perfectly clear, 1 is the medium's own colour.\n */\nfloat mediumFog(float dist, float pointY) {\n /*\n * A depth ramp rather than a medium, for worlds authored against one.\n *\n * Beer-Lambert is the honest model and stays the default: it integrates something\n * physically there, so extinction begins at the eye and never stops. A linear near/far\n * fog is not that \u2014 it is a *look*, with a hard start distance before which the air is\n * perfectly clear, and it is what the fixed-function pipeline offered and what several\n * renderers still expose. Approximating one with the other is not a matter of tuning:\n * matched at half occlusion, the exponential curve still lays haze over everything\n * inside near, where the ramp lays none, and near-field colour desaturates toward the\n * fog colour with nothing to show for it.\n *\n * Height falloff has no meaning here and is ignored: a ramp is defined on distance\n * alone.\n */\n if (uFogMode == 1) {\n float span = max(uFogFar - uFogNear, 1e-4);\n float ramp = clamp((dist - uFogNear) / span, 0.0, 1.0);\n if (uUnderwaterFactor <= 0.0) return ramp;\n float wetLinear = uUnderwaterFogDensity * dist;\n return mix(ramp, 1.0 - exp2(-wetLinear * wetLinear * 1.442695), uUnderwaterFactor);\n }\n\n float t = (pointY - uFogEyeY) * uFogHeightFalloff;\n // (1 - e^-t)/t, which tends to 1 as the ray levels out. Guarded rather than\n // branched: at t = 0 the quotient is 0/0, and 1e-4 of a scale height is 8 mm.\n float denom = abs(t) < 1e-4 ? 1e-4 : t;\n float air = 1.0 - exp(-uFogDensity * dist * (1.0 - exp(-denom)) / denom);\n if (uUnderwaterFactor <= 0.0) return air;\n // Water is its own medium and keeps its own curve, so crossing the surface\n // changes nothing about how the water column reads.\n float wet = uUnderwaterFogDensity * dist;\n return mix(air, 1.0 - exp2(-wet * wet * 1.442695), uUnderwaterFactor);\n}\n\n\nout vec4 outColor;\n\n/** 0 none, 1 sRGB, 2 ACES then sRGB, 3 the highlight shoulder then sRGB. See renderQuality.ts. */\nuniform int uOutputTransform;\n/** Scales the scene into the tone curve. 1 is the reference grade. See renderQuality.ts. */\nuniform float uOutputExposure;\n\n/*\n * ACES: the reference fit, not the cheap one.\n *\n * This was Narkowicz's single rational function, on the argument that the difference from\n * the reference curve is invisible next to the gain. That argument holds for a look and\n * fails for a *match*, which is what this option is for \u2014 aces exists so a world ported\n * from three.js reads the same, and three.js applies the full fit: into AP1 through\n * ACESInputMat, the RRT and ODT together, then back out through ACESOutputMat.\n *\n * The two curves are not a shade apart. Narkowicz is markedly brighter through the\n * midtones, which is exactly where an interior scene lives, and it is a large part of a\n * measured ~1.7x that survived correcting the colour space and the missing Lambert pi.\n * An approximation of a standard is the wrong thing to hold when the standard is the\n * specification.\n */\nvec3 rrtAndOdtFit(vec3 v) {\n vec3 a = v * (v + 0.0245786) - 0.000090537;\n vec3 b = v * (0.983729 * v + 0.4329510) + 0.238081;\n return a / b;\n}\n\nvec3 acesFilmic(vec3 x) {\n /*\n * Exposure first, because a tone curve is only defined relative to one.\n *\n * The reference RRT and ODT are graded for a dark cinema. Every renderer that ships ACES\n * scales its input to suit whatever it is actually shown on, and the factor each one\n * picks is a *look*, not a standard - so this engine takes no position and reads it from\n * the caller. Neutral by default, which is the reference grade unmodified. three.js's own\n * pick is 1 / 0.6, for a consumer matching one.\n */\n x *= uOutputExposure;\n // Columns, as GLSL reads them: sRGB -> XYZ -> D65_2_D60 -> AP1 -> RRT_SAT.\n const mat3 ACES_INPUT = mat3(\n 0.59719, 0.07600, 0.02840,\n 0.35458, 0.90834, 0.13383,\n 0.04823, 0.01566, 0.83777\n );\n // ODT_SAT -> XYZ -> D60_2_D65 -> sRGB.\n const mat3 ACES_OUTPUT = mat3(\n 1.60475, -0.10208, -0.00327,\n -0.53108, 1.10813, -0.07276,\n -0.07367, -0.00605, 1.07602\n );\n return clamp(ACES_OUTPUT * rrtAndOdtFit(ACES_INPUT * x), 0.0, 1.0);\n}\n\n/*\n * Linear to sRGB. The piecewise form rather than a plain pow: the linear toe near black\n * is where banding lives in an 8-bit buffer, and the cheap approximation puts it in the\n * wrong place.\n */\nvec3 linearToSrgb(vec3 c) {\n vec3 low = c * 12.92;\n vec3 high = 1.055 * pow(max(c, vec3(0.0)), vec3(1.0 / 2.4)) - 0.055;\n return mix(high, low, step(c, vec3(0.0031308)));\n}\n\n\nvec3 highlightShoulder(vec3 c) {\n float m = max(c.r, max(c.g, c.b));\n if (m <= 0.8) return c;\n float e = m - 0.8;\n return c * ((0.8 + 0.2 * e / (e + 0.2)) / m);\n}\n\nvec3 applyOutputTransform(vec3 c) {\n if (uOutputTransform == 0) return c;\n if (uOutputTransform == 2) c = acesFilmic(c);\n if (uOutputTransform == 3) c = highlightShoulder(c * uOutputExposure);\n return linearToSrgb(c);\n}\n\n\nvoid main() {\n /*\n * One soft, round falloff \u2014 no erosion, no core past white, because this material draws\n * neither a body being eaten by noise nor a light source. Squared rather than linear so the\n * edge feathers instead of ramping, which is what keeps a field of these reading as dust\n * rather than as a scatter of hard-edged discs.\n */\n float r = length(vUv);\n float body = 1.0 - smoothstep(0.4, 1.0, r);\n if (body <= 0.0) discard;\n float alpha = body * body * vAlpha;\n if (alpha <= 0.002) discard;\n\n vec3 color = vColor;\n if (uFogEnabled != 0) {\n float fog = mediumFog(distance(vWorldPos, uCameraPos), vWorldPos.y);\n color = mix(color, mediumColor(), fog);\n }\n /*\n * A real alpha blend (SRC_ALPHA, ONE_MINUS_SRC_ALPHA) rather than spark's energy-in-colour\n * trick: this point genuinely occludes what little is behind it instead of adding light to it.\n */\n outColor = vec4(applyOutputTransform(color), alpha);\n}\n";
@@ -41,4 +41,4 @@ export declare const MOTION_DRAW_STRIDE = 256;
41
41
  export declare const MOTION_DRAW_FLOATS = 32;
42
42
  /** The motion target's format. Half float holds a uv to a hundredth of a pixel and a view depth. */
43
43
  export declare const MOTION_TARGET_FORMAT: GPUTextureFormat;
44
- export declare const RECON_MOTION_WGSL = "\nstruct MotionFrame {\n /* The scene's own clip transform, with the generated shaders' y negation already folded in. */\n raster: mat4x4<f32>,\n /* This frame's and last frame's view-projections, unjittered, in the matrices' own convention. */\n viewProj: mat4x4<f32>,\n previousViewProj: mat4x4<f32>,\n}\n\nstruct MotionDraw {\n model: mat4x4<f32>,\n previousModel: mat4x4<f32>,\n}\n\n@group(0) @binding(0) var<uniform> frame: MotionFrame;\n@group(0) @binding(1) var<uniform> draw: MotionDraw;\n\nstruct Varyings {\n @builtin(position) clip: vec4<f32>,\n /* Clip positions rather than uv: an interpolator divides by w for us, so dividing these by their\n own interpolated w in the fragment stage is the perspective-correct answer at every pixel. */\n @location(0) now: vec4<f32>,\n @location(1) was: vec4<f32>,\n}\n\n@vertex\nfn motionVert(@location(0) position: vec3<f32>) -> Varyings {\n let world = draw.model * vec4<f32>(position, 1.0);\n let wasWorld = draw.previousModel * vec4<f32>(position, 1.0);\n var out: Varyings;\n out.clip = frame.raster * world;\n out.now = frame.viewProj * world;\n out.was = frame.previousViewProj * wasWorld;\n return out;\n}\n\n/* Normalised device coordinates to the uv the resolve measures in: v increases upward, as the\n references' images do, and the accessor that reads this target is what flips the texture's rows. */\nfn motionUv(clip: vec4<f32>) -> vec2<f32> {\n return clip.xy / clip.w * 0.5 + vec2<f32>(0.5);\n}\n\n/*\n * The skinned stage: the joints this frame and last frame, read from two palette textures of the\n * frame's ring. The same four weighted products in the same order as the scene's own skinning, so\n * the depth this stage produces is the depth the scene wrote.\n */\n@group(1) @binding(0) var palette: texture_2d<f32>;\n@group(1) @binding(1) var previousPalette: texture_2d<f32>;\n\nfn jointOf(source: texture_2d<f32>, index: i32) -> mat4x4<f32> {\n let x = index * 4;\n return mat4x4<f32>(\n textureLoad(source, vec2<i32>(x, 0), 0),\n textureLoad(source, vec2<i32>(x + 1, 0), 0),\n textureLoad(source, vec2<i32>(x + 2, 0), 0),\n textureLoad(source, vec2<i32>(x + 3, 0), 0));\n}\n\nfn skinOf(source: texture_2d<f32>, joints: vec4<f32>, weights: vec4<f32>) -> mat4x4<f32> {\n return jointOf(source, i32(joints.x)) * weights.x\n + jointOf(source, i32(joints.y)) * weights.y\n + jointOf(source, i32(joints.z)) * weights.z\n + jointOf(source, i32(joints.w)) * weights.w;\n}\n\n@vertex\nfn motionSkinnedVert(\n @location(0) position: vec3<f32>,\n @location(11) joints: vec4<f32>,\n @location(12) weights: vec4<f32>,\n) -> Varyings {\n let world = draw.model * (skinOf(palette, joints, weights) * vec4<f32>(position, 1.0));\n let wasWorld =\n draw.previousModel * (skinOf(previousPalette, joints, weights) * vec4<f32>(position, 1.0));\n var out: Varyings;\n out.clip = frame.raster * world;\n out.now = frame.viewProj * world;\n out.was = frame.previousViewProj * wasWorld;\n return out;\n}\n\n/*\n * The rewritten stage: a mesh whose vertices were rewritten this frame reads last frame's rows from\n * a second buffer of the same stride, so each vertex carries both of its positions.\n */\n@vertex\nfn motionDynamicVert(\n @location(0) position: vec3<f32>,\n @location(1) previousPosition: vec3<f32>,\n) -> Varyings {\n let world = draw.model * vec4<f32>(position, 1.0);\n let wasWorld = draw.previousModel * vec4<f32>(previousPosition, 1.0);\n var out: Varyings;\n out.clip = frame.raster * world;\n out.now = frame.viewProj * world;\n out.was = frame.previousViewProj * wasWorld;\n return out;\n}\n\n/*\n * The instanced stage: each instance's matrix this frame and last frame, read from the batch's\n * placement and the copy of last frame's it kept. Slot for slot, so an instance is paired with\n * itself; the per-draw matrices are not read.\n */\n@vertex\nfn motionInstancedVert(\n @location(0) position: vec3<f32>,\n @location(2) m0: vec4<f32>,\n @location(3) m1: vec4<f32>,\n @location(4) m2: vec4<f32>,\n @location(5) m3: vec4<f32>,\n @location(6) p0: vec4<f32>,\n @location(7) p1: vec4<f32>,\n @location(8) p2: vec4<f32>,\n @location(9) p3: vec4<f32>,\n) -> Varyings {\n let world = mat4x4<f32>(m0, m1, m2, m3) * vec4<f32>(position, 1.0);\n let wasWorld = mat4x4<f32>(p0, p1, p2, p3) * vec4<f32>(position, 1.0);\n var out: Varyings;\n out.clip = frame.raster * world;\n out.now = frame.viewProj * world;\n out.was = frame.previousViewProj * wasWorld;\n return out;\n}\n\n@fragment\nfn motionFrag(in: Varyings) -> @location(0) vec4<f32> {\n /*\n * A surface behind last frame's eye has a w that is not positive, and there is no uv for it. The\n * flag stays set: the disocclusion refuses a depth that is not positive, so the resolve drops the\n * history rather than reading it from wherever a divide by a negative w would have pointed.\n */\n let offset = select(vec2<f32>(0.0), motionUv(in.was) - motionUv(in.now), in.was.w > 0.0);\n return vec4<f32>(offset, in.was.w, 1.0);\n}\n";
44
+ export declare const RECON_MOTION_WGSL = "\nstruct MotionFrame {\n /* The scene's own clip transform, with the generated shaders' y negation already folded in. */\n raster: mat4x4<f32>,\n /* This frame's and last frame's view-projections, unjittered, in the matrices' own convention. */\n viewProj: mat4x4<f32>,\n previousViewProj: mat4x4<f32>,\n}\n\nstruct MotionDraw {\n model: mat4x4<f32>,\n previousModel: mat4x4<f32>,\n}\n\n@group(0) @binding(0) var<uniform> frame: MotionFrame;\n@group(0) @binding(1) var<uniform> draw: MotionDraw;\n\nstruct Varyings {\n @builtin(position) clip: vec4<f32>,\n /* Clip positions rather than uv: an interpolator divides by w for us, so dividing these by their\n own interpolated w in the fragment stage is the perspective-correct answer at every pixel. */\n @location(0) now: vec4<f32>,\n @location(1) was: vec4<f32>,\n}\n\n@vertex\nfn motionVert(@location(0) position: vec3<f32>) -> Varyings {\n let world = draw.model * vec4<f32>(position, 1.0);\n let wasWorld = draw.previousModel * vec4<f32>(position, 1.0);\n var out: Varyings;\n out.clip = frame.raster * world;\n out.now = frame.viewProj * world;\n out.was = frame.previousViewProj * wasWorld;\n return out;\n}\n\n/* Normalised device coordinates to the uv the resolve measures in: v increases upward, as the\n references' images do, and the accessor that reads this target is what flips the texture's rows. */\nfn motionUv(clip: vec4<f32>) -> vec2<f32> {\n return clip.xy / clip.w * 0.5 + vec2<f32>(0.5);\n}\n\n/*\n * The skinned stage: the joints this frame and last frame, read from two palette textures of the\n * frame's ring. The same four weighted products in the same order as the scene's own skinning, so\n * the depth this stage produces is the depth the scene wrote.\n */\n@group(1) @binding(0) var palette: texture_2d<f32>;\n@group(1) @binding(1) var previousPalette: texture_2d<f32>;\n\nfn jointOf(source: texture_2d<f32>, index: i32) -> mat4x4<f32> {\n let x = index * 4;\n return mat4x4<f32>(\n textureLoad(source, vec2<i32>(x, 0), 0),\n textureLoad(source, vec2<i32>(x + 1, 0), 0),\n textureLoad(source, vec2<i32>(x + 2, 0), 0),\n textureLoad(source, vec2<i32>(x + 3, 0), 0));\n}\n\nfn skinOf(source: texture_2d<f32>, joints: vec4<f32>, weights: vec4<f32>) -> mat4x4<f32> {\n return jointOf(source, i32(joints.x)) * weights.x\n + jointOf(source, i32(joints.y)) * weights.y\n + jointOf(source, i32(joints.z)) * weights.z\n + jointOf(source, i32(joints.w)) * weights.w;\n}\n\n@vertex\nfn motionSkinnedVert(\n @location(0) position: vec3<f32>,\n @location(11) joints: vec4<f32>,\n @location(12) weights: vec4<f32>,\n) -> Varyings {\n let world = draw.model * (skinOf(palette, joints, weights) * vec4<f32>(position, 1.0));\n let wasWorld =\n draw.previousModel * (skinOf(previousPalette, joints, weights) * vec4<f32>(position, 1.0));\n var out: Varyings;\n out.clip = frame.raster * world;\n out.now = frame.viewProj * world;\n out.was = frame.previousViewProj * wasWorld;\n return out;\n}\n\n/*\n * The same for a rig with eight influences a vertex, the second four at the scene's own locations\n * 14 and 15 and summed after the first, as `skinMatrix()` sums them with `SKIN_EIGHT` on \u2014 or the\n * motion of a face or a shoulder would be the four heaviest joints' alone.\n */\n@vertex\nfn motionSkinnedEightVert(\n @location(0) position: vec3<f32>,\n @location(11) joints: vec4<f32>,\n @location(12) weights: vec4<f32>,\n @location(14) joints2: vec4<f32>,\n @location(15) weights2: vec4<f32>,\n) -> Varyings {\n let skin = skinOf(palette, joints, weights) + skinOf(palette, joints2, weights2);\n let wasSkin =\n skinOf(previousPalette, joints, weights) + skinOf(previousPalette, joints2, weights2);\n let world = draw.model * (skin * vec4<f32>(position, 1.0));\n let wasWorld = draw.previousModel * (wasSkin * vec4<f32>(position, 1.0));\n var out: Varyings;\n out.clip = frame.raster * world;\n out.now = frame.viewProj * world;\n out.was = frame.previousViewProj * wasWorld;\n return out;\n}\n\n/*\n * The cloth-bound stage: a skinned vertex moved toward its simulation triangle by its painted\n * weight, as shaders/clothBinding.ts moves it in the scene, once with this frame's particles and\n * once with last frame's. **The same arithmetic in the same order**, or the depth this stage writes\n * is not the scene's and the equal test admits none of the garment. The binding's turn is not\n * needed: a motion is where a point went, not which way it faces.\n */\n@group(2) @binding(0) var clothBinding: texture_2d<f32>;\n@group(2) @binding(1) var clothParticles: texture_2d<f32>;\n@group(2) @binding(2) var previousClothParticles: texture_2d<f32>;\n\nfn clothTexel(i: i32, width: i32) -> vec2<i32> {\n return vec2<i32>(i % width, i / width);\n}\n\nfn clothPoint(particles: texture_2d<f32>, indices: vec4<f32>, at: vec4<f32>) -> vec3<f32> {\n let width = i32(textureDimensions(particles, 0).x);\n let a = i32(indices.x);\n let b = i32(indices.y);\n let c = i32(indices.z);\n let pa = textureLoad(particles, clothTexel(a, width), 0).xyz;\n if (a == b && b == c) {\n return pa;\n }\n let pb = textureLoad(particles, clothTexel(b, width), 0).xyz;\n let pc = textureLoad(particles, clothTexel(c, width), 0).xyz;\n let n = normalize(cross(pb - pa, pc - pa));\n return pa * (1.0 - at.x - at.y) + pb * at.x + pc * at.y + n * at.z;\n}\n\n/* A skinned point now and last frame, carried to the cloth by the vertex's own weight. */\nfn clothVaryings(vertex: u32, world: vec4<f32>, wasWorld: vec4<f32>) -> Varyings {\n let width = i32(textureDimensions(clothBinding, 0).x);\n let indices = textureLoad(clothBinding, clothTexel(i32(vertex) * 2, width), 0);\n let at = textureLoad(clothBinding, clothTexel(i32(vertex) * 2 + 1, width), 0);\n let follow = indices.w;\n let placed = vec4<f32>(mix(world.xyz, clothPoint(clothParticles, indices, at), follow), world.w);\n let wasPlaced = vec4<f32>(\n mix(wasWorld.xyz, clothPoint(previousClothParticles, indices, at), follow),\n wasWorld.w);\n var out: Varyings;\n out.clip = frame.raster * placed;\n out.now = frame.viewProj * placed;\n out.was = frame.previousViewProj * wasPlaced;\n return out;\n}\n\n@vertex\nfn motionClothVert(\n @builtin(vertex_index) vertex: u32,\n @location(0) position: vec3<f32>,\n @location(11) joints: vec4<f32>,\n @location(12) weights: vec4<f32>,\n) -> Varyings {\n let world = draw.model * (skinOf(palette, joints, weights) * vec4<f32>(position, 1.0));\n let wasWorld =\n draw.previousModel * (skinOf(previousPalette, joints, weights) * vec4<f32>(position, 1.0));\n return clothVaryings(vertex, world, wasWorld);\n}\n\n@vertex\nfn motionClothEightVert(\n @builtin(vertex_index) vertex: u32,\n @location(0) position: vec3<f32>,\n @location(11) joints: vec4<f32>,\n @location(12) weights: vec4<f32>,\n @location(14) joints2: vec4<f32>,\n @location(15) weights2: vec4<f32>,\n) -> Varyings {\n let skin = skinOf(palette, joints, weights) + skinOf(palette, joints2, weights2);\n let wasSkin =\n skinOf(previousPalette, joints, weights) + skinOf(previousPalette, joints2, weights2);\n let world = draw.model * (skin * vec4<f32>(position, 1.0));\n let wasWorld = draw.previousModel * (wasSkin * vec4<f32>(position, 1.0));\n return clothVaryings(vertex, world, wasWorld);\n}\n\n/*\n * The rewritten stage: a mesh whose vertices were rewritten this frame reads last frame's rows from\n * a second buffer of the same stride, so each vertex carries both of its positions.\n */\n@vertex\nfn motionDynamicVert(\n @location(0) position: vec3<f32>,\n @location(1) previousPosition: vec3<f32>,\n) -> Varyings {\n let world = draw.model * vec4<f32>(position, 1.0);\n let wasWorld = draw.previousModel * vec4<f32>(previousPosition, 1.0);\n var out: Varyings;\n out.clip = frame.raster * world;\n out.now = frame.viewProj * world;\n out.was = frame.previousViewProj * wasWorld;\n return out;\n}\n\n/*\n * The instanced stage: each instance's matrix this frame and last frame, read from the batch's\n * placement and the copy of last frame's it kept. Slot for slot, so an instance is paired with\n * itself; the per-draw matrices are not read.\n */\n@vertex\nfn motionInstancedVert(\n @location(0) position: vec3<f32>,\n @location(2) m0: vec4<f32>,\n @location(3) m1: vec4<f32>,\n @location(4) m2: vec4<f32>,\n @location(5) m3: vec4<f32>,\n @location(6) p0: vec4<f32>,\n @location(7) p1: vec4<f32>,\n @location(8) p2: vec4<f32>,\n @location(9) p3: vec4<f32>,\n) -> Varyings {\n let world = mat4x4<f32>(m0, m1, m2, m3) * vec4<f32>(position, 1.0);\n let wasWorld = mat4x4<f32>(p0, p1, p2, p3) * vec4<f32>(position, 1.0);\n var out: Varyings;\n out.clip = frame.raster * world;\n out.now = frame.viewProj * world;\n out.was = frame.previousViewProj * wasWorld;\n return out;\n}\n\n@fragment\nfn motionFrag(in: Varyings) -> @location(0) vec4<f32> {\n /*\n * A surface behind last frame's eye has a w that is not positive, and there is no uv for it. The\n * flag stays set: the disocclusion refuses a depth that is not positive, so the resolve drops the\n * history rather than reading it from wherever a divide by a negative w would have pointed.\n */\n let offset = select(vec2<f32>(0.0), motionUv(in.was) - motionUv(in.now), in.was.w > 0.0);\n return vec4<f32>(offset, in.was.w, 1.0);\n}\n";
@@ -123,6 +123,108 @@ fn motionSkinnedVert(
123
123
  return out;
124
124
  }
125
125
 
126
+ /*
127
+ * The same for a rig with eight influences a vertex, the second four at the scene's own locations
128
+ * 14 and 15 and summed after the first, as \`skinMatrix()\` sums them with \`SKIN_EIGHT\` on — or the
129
+ * motion of a face or a shoulder would be the four heaviest joints' alone.
130
+ */
131
+ @vertex
132
+ fn motionSkinnedEightVert(
133
+ @location(0) position: vec3<f32>,
134
+ @location(11) joints: vec4<f32>,
135
+ @location(12) weights: vec4<f32>,
136
+ @location(14) joints2: vec4<f32>,
137
+ @location(15) weights2: vec4<f32>,
138
+ ) -> Varyings {
139
+ let skin = skinOf(palette, joints, weights) + skinOf(palette, joints2, weights2);
140
+ let wasSkin =
141
+ skinOf(previousPalette, joints, weights) + skinOf(previousPalette, joints2, weights2);
142
+ let world = draw.model * (skin * vec4<f32>(position, 1.0));
143
+ let wasWorld = draw.previousModel * (wasSkin * vec4<f32>(position, 1.0));
144
+ var out: Varyings;
145
+ out.clip = frame.raster * world;
146
+ out.now = frame.viewProj * world;
147
+ out.was = frame.previousViewProj * wasWorld;
148
+ return out;
149
+ }
150
+
151
+ /*
152
+ * The cloth-bound stage: a skinned vertex moved toward its simulation triangle by its painted
153
+ * weight, as shaders/clothBinding.ts moves it in the scene, once with this frame's particles and
154
+ * once with last frame's. **The same arithmetic in the same order**, or the depth this stage writes
155
+ * is not the scene's and the equal test admits none of the garment. The binding's turn is not
156
+ * needed: a motion is where a point went, not which way it faces.
157
+ */
158
+ @group(2) @binding(0) var clothBinding: texture_2d<f32>;
159
+ @group(2) @binding(1) var clothParticles: texture_2d<f32>;
160
+ @group(2) @binding(2) var previousClothParticles: texture_2d<f32>;
161
+
162
+ fn clothTexel(i: i32, width: i32) -> vec2<i32> {
163
+ return vec2<i32>(i % width, i / width);
164
+ }
165
+
166
+ fn clothPoint(particles: texture_2d<f32>, indices: vec4<f32>, at: vec4<f32>) -> vec3<f32> {
167
+ let width = i32(textureDimensions(particles, 0).x);
168
+ let a = i32(indices.x);
169
+ let b = i32(indices.y);
170
+ let c = i32(indices.z);
171
+ let pa = textureLoad(particles, clothTexel(a, width), 0).xyz;
172
+ if (a == b && b == c) {
173
+ return pa;
174
+ }
175
+ let pb = textureLoad(particles, clothTexel(b, width), 0).xyz;
176
+ let pc = textureLoad(particles, clothTexel(c, width), 0).xyz;
177
+ let n = normalize(cross(pb - pa, pc - pa));
178
+ return pa * (1.0 - at.x - at.y) + pb * at.x + pc * at.y + n * at.z;
179
+ }
180
+
181
+ /* A skinned point now and last frame, carried to the cloth by the vertex's own weight. */
182
+ fn clothVaryings(vertex: u32, world: vec4<f32>, wasWorld: vec4<f32>) -> Varyings {
183
+ let width = i32(textureDimensions(clothBinding, 0).x);
184
+ let indices = textureLoad(clothBinding, clothTexel(i32(vertex) * 2, width), 0);
185
+ let at = textureLoad(clothBinding, clothTexel(i32(vertex) * 2 + 1, width), 0);
186
+ let follow = indices.w;
187
+ let placed = vec4<f32>(mix(world.xyz, clothPoint(clothParticles, indices, at), follow), world.w);
188
+ let wasPlaced = vec4<f32>(
189
+ mix(wasWorld.xyz, clothPoint(previousClothParticles, indices, at), follow),
190
+ wasWorld.w);
191
+ var out: Varyings;
192
+ out.clip = frame.raster * placed;
193
+ out.now = frame.viewProj * placed;
194
+ out.was = frame.previousViewProj * wasPlaced;
195
+ return out;
196
+ }
197
+
198
+ @vertex
199
+ fn motionClothVert(
200
+ @builtin(vertex_index) vertex: u32,
201
+ @location(0) position: vec3<f32>,
202
+ @location(11) joints: vec4<f32>,
203
+ @location(12) weights: vec4<f32>,
204
+ ) -> Varyings {
205
+ let world = draw.model * (skinOf(palette, joints, weights) * vec4<f32>(position, 1.0));
206
+ let wasWorld =
207
+ draw.previousModel * (skinOf(previousPalette, joints, weights) * vec4<f32>(position, 1.0));
208
+ return clothVaryings(vertex, world, wasWorld);
209
+ }
210
+
211
+ @vertex
212
+ fn motionClothEightVert(
213
+ @builtin(vertex_index) vertex: u32,
214
+ @location(0) position: vec3<f32>,
215
+ @location(11) joints: vec4<f32>,
216
+ @location(12) weights: vec4<f32>,
217
+ @location(14) joints2: vec4<f32>,
218
+ @location(15) weights2: vec4<f32>,
219
+ ) -> Varyings {
220
+ let skin = skinOf(palette, joints, weights) + skinOf(palette, joints2, weights2);
221
+ let wasSkin =
222
+ skinOf(previousPalette, joints, weights) + skinOf(previousPalette, joints2, weights2);
223
+ let world = draw.model * (skin * vec4<f32>(position, 1.0));
224
+ let wasWorld = draw.previousModel * (wasSkin * vec4<f32>(position, 1.0));
225
+ return clothVaryings(vertex, world, wasWorld);
226
+ }
227
+
126
228
  /*
127
229
  * The rewritten stage: a mesh whose vertices were rewritten this frame reads last frame's rows from
128
230
  * a second buffer of the same stride, so each vertex carries both of its positions.
@@ -943,6 +943,19 @@ fn reconSceneBilinear(p: vec2<f32>) -> vec3<f32> {
943
943
  return textureSampleLevel(sceneTexture, linearSampler, uv, 0.0).xyz;
944
944
  }
945
945
 
946
+ /*
947
+ * The surface's share of an output pixel, read from the jittered scene it was rebuilt from
948
+ * (sceneCoverage.ts): what the blended draws that landed before the reconstruction left of it.
949
+ * The late ones then cover the picture this is stored in, so the composite's occlusion reads both.
950
+ * Bilinear and at the unjittered position, which is where the colour beside it stands.
951
+ */
952
+ fn reconSceneShare(ox: i32, oy: i32) -> f32 {
953
+ let output = vec2<f32>(f32(recon.outputSize.x), f32(recon.outputSize.y));
954
+ let render = vec2<f32>(f32(recon.renderSize.x), f32(recon.renderSize.y));
955
+ let at = (vec2<f32>(f32(ox), f32(oy)) + 0.5) / output + recon.jitter / render;
956
+ return textureSampleLevel(sceneTexture, linearSampler, vec2<f32>(at.x, 1.0 - at.y), 0.0).w;
957
+ }
958
+
946
959
  fn reconHistoryBilinear(p: vec2<f32>) -> vec4<f32> {
947
960
  let size = vec2<f32>(f32(recon.outputSize.x), f32(recon.outputSize.y));
948
961
  let uv = vec2<f32>(p.x + 0.5, size.y - 0.5 - p.y) / size;
@@ -965,7 +978,8 @@ fn sharpenMain(@builtin(global_invocation_id) id: vec3<u32>) {
965
978
  if (id.x >= recon.outputSize.x || id.y >= recon.outputSize.y) { return; }
966
979
  let y = i32(recon.outputSize.y) - 1 - i32(id.y);
967
980
  let value = reconSharpenAt(i32(id.x), y);
968
- textureStore(resolved, vec2<i32>(i32(id.x), i32(id.y)), vec4<f32>(value, 1.0));
981
+ let share = reconSceneShare(i32(id.x), y);
982
+ textureStore(resolved, vec2<i32>(i32(id.x), i32(id.y)), vec4<f32>(value, share));
969
983
  }
970
984
  `;
971
985
  }
@@ -24,6 +24,7 @@ import { DEPTH_OF_FIELD_GLSL } from './depthOfField.js';
24
24
  import { AUTO_EXPOSURE_GLSL } from './exposure.js';
25
25
  import { LOCAL_EXPOSURE_GLSL } from './localExposure.js';
26
26
  import { FILM_LOOK_GLSL } from './filmLook.js';
27
+ import { HIGHLIGHT_SHOULDER_GLSL } from './outputTransform.js';
27
28
  export const RUSH_FRAG = `#version 300 es
28
29
  precision highp float;
29
30
  /*
@@ -240,9 +241,11 @@ vec3 acesFilmic(vec3 x) {
240
241
  return clamp(ACES_OUTPUT * (a / b), 0.0, 1.0);
241
242
  }
242
243
 
244
+ ${HIGHLIGHT_SHOULDER_GLSL}
243
245
  vec3 grade(vec3 c) {
244
246
  if (uOutputTransform == 0) return c;
245
247
  if (uOutputTransform == 2) c = acesFilmic(c);
248
+ if (uOutputTransform == 3) c = highlightShoulder(c * uOutputExposure);
246
249
  return linearToSrgb(c);
247
250
  }
248
251
 
@@ -333,7 +336,8 @@ vec3 finish(vec3 light) {
333
336
  }
334
337
 
335
338
  void main() {
336
- vec3 scene = textureLod(uScene, vUv, 0.0).rgb;
339
+ vec4 sampled = textureLod(uScene, vUv, 0.0);
340
+ vec3 scene = sampled.rgb;
337
341
  if (uMotionStrength > 0.0) scene = cameraBlur(scene);
338
342
  /*
339
343
  * Defocus after the camera smear and before everything else, because a lens is the last thing
@@ -348,8 +352,15 @@ void main() {
348
352
  * not then darkened again along its own trail. mix from 1 rather than a multiply by the
349
353
  * strength, so the parameter reads as "how much of this occlusion", and 0 is exactly the
350
354
  * frame that existed before the effect did.
355
+ *
356
+ * **Scaled by the surface's share of the pixel**, which the scene carries in its alpha
357
+ * (sceneCoverage.ts): the occlusion was measured from the depth the opaque world left, and a
358
+ * pane, a puff of smoke or a caption in front of a corner wrote no depth, so darkening all of the
359
+ * pixel darkened them by a corner they hide. Where nothing blended landed the share is 1 and
360
+ * this is the frame it was.
351
361
  */
352
- float ao = mix(1.0, textureLod(uAo, vUv + uAoOffset, 0.0).r, uAoStrength);
362
+ float share = clamp(sampled.a, 0.0, 1.0);
363
+ float ao = mix(1.0, textureLod(uAo, vUv + uAoOffset, 0.0).r, uAoStrength * share);
353
364
 
354
365
  /*
355
366
  * Distance from the centre, corrected so the falloff is a circle on screen rather than