@meimu/mutracer 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (304) hide show
  1. package/CHANGELOG.md +222 -0
  2. package/LICENSES/FidelityFX-FSR.txt +19 -0
  3. package/LICENSES/pbrt-v4-Apache-2.0.txt +202 -0
  4. package/THIRD_PARTY_NOTICES.md +18 -4
  5. package/dist/assets/bvh.worker.js +1 -1
  6. package/dist/mutracer.umd.js +6260 -5580
  7. package/docs/api.md +45 -18
  8. package/docs/materials.md +4 -2
  9. package/docs/performance.md +7 -0
  10. package/docs/post-processing.md +62 -9
  11. package/docs/progressive-rendering.md +3 -0
  12. package/docs/sampling.md +4 -0
  13. package/docs/technical/acceleration.md +52 -0
  14. package/docs/technical/aovs.md +79 -0
  15. package/docs/technical/caustics.md +109 -0
  16. package/docs/technical/continuous-spectrum.md +29 -0
  17. package/docs/technical/display-upscale.md +82 -0
  18. package/docs/technical/openpbr.md +99 -0
  19. package/docs/technical/pbrt-import.md +168 -0
  20. package/docs/technical/tiling.md +74 -0
  21. package/docs/technical/webgl.md +53 -0
  22. package/docs/viewer.md +11 -1
  23. package/lib/Display.d.ts +19 -5
  24. package/lib/Display.js +10 -7
  25. package/lib/Display.js.map +1 -1
  26. package/lib/Engine.d.ts +2 -1
  27. package/lib/Engine.js +30 -2
  28. package/lib/Engine.js.map +1 -1
  29. package/lib/Render.d.ts +20 -11
  30. package/lib/Render.js +32 -7
  31. package/lib/Render.js.map +1 -1
  32. package/lib/main.d.ts +3 -1
  33. package/lib/main.js +1 -0
  34. package/lib/main.js.map +1 -1
  35. package/lib/oidn.d.ts +1 -1
  36. package/lib/renderer/AovPrimitiveCache.js +39 -8
  37. package/lib/renderer/AovPrimitiveCache.js.map +1 -1
  38. package/lib/renderer/DisplayPostProcess.d.ts +8 -3
  39. package/lib/renderer/DisplayPostProcess.js +51 -18
  40. package/lib/renderer/DisplayPostProcess.js.map +1 -1
  41. package/lib/renderer/MaterialData.js +7 -2
  42. package/lib/renderer/MaterialData.js.map +1 -1
  43. package/lib/renderer/RenderingPipeline.d.ts +7 -1
  44. package/lib/renderer/RenderingPipeline.js.map +1 -1
  45. package/lib/renderer/TileRender.d.ts +2 -2
  46. package/lib/renderer/TileRender.js +128 -7
  47. package/lib/renderer/TileRender.js.map +1 -1
  48. package/lib/renderer/WGPUAov.d.ts +6 -1
  49. package/lib/renderer/WGPUAov.js +108 -14
  50. package/lib/renderer/WGPUAov.js.map +1 -1
  51. package/lib/renderer/WGPUCanvasSurface.js +12 -1
  52. package/lib/renderer/WGPUCanvasSurface.js.map +1 -1
  53. package/lib/renderer/WGPUEnvMapDistribution.js +19 -19
  54. package/lib/renderer/WGPUFullQuadPass.js +3 -3
  55. package/lib/renderer/WGPURayTraceOutput.js +12 -12
  56. package/lib/renderer/WGPURayTracePass.d.ts +17 -4
  57. package/lib/renderer/WGPURayTracePass.js +194 -71
  58. package/lib/renderer/WGPURayTracePass.js.map +1 -1
  59. package/lib/renderer/WGPURenderingPipeline.js +46 -40
  60. package/lib/renderer/WGPURenderingPipeline.js.map +1 -1
  61. package/lib/renderer/WebGLAov.js +3 -3
  62. package/lib/renderer/WebGLAov.js.map +1 -1
  63. package/lib/renderer/WebGLFullQuadPass.d.ts +1 -1
  64. package/lib/renderer/WebGLFullQuadPass.js +8 -2
  65. package/lib/renderer/WebGLFullQuadPass.js.map +1 -1
  66. package/lib/renderer/WebGLJNLMDenoiser.js +66 -66
  67. package/lib/renderer/WebGLJNLMDenoiser.js.map +1 -1
  68. package/lib/renderer/WebGLRayTraceOutputPass.js +4 -4
  69. package/lib/renderer/WebGLRayTracePass.d.ts +14 -10
  70. package/lib/renderer/WebGLRayTracePass.js +115 -111
  71. package/lib/renderer/WebGLRayTracePass.js.map +1 -1
  72. package/lib/renderer/WebGLRenderingPipeline.js +10 -3
  73. package/lib/renderer/WebGLRenderingPipeline.js.map +1 -1
  74. package/lib/renderer/WebGLSkyBaker.js +57 -57
  75. package/lib/renderer/aov.d.ts +13 -1
  76. package/lib/renderer/aov.js +21 -2
  77. package/lib/renderer/aov.js.map +1 -1
  78. package/lib/renderer/aovDisplay.js +2 -2
  79. package/lib/renderer/aovDisplay.js.map +1 -1
  80. package/lib/renderer/binnedSahBvh.d.ts +2 -1
  81. package/lib/renderer/binnedSahBvh.js +24 -17
  82. package/lib/renderer/binnedSahBvh.js.map +1 -1
  83. package/lib/renderer/bvhAccel.d.ts +3 -1
  84. package/lib/renderer/bvhAccel.js +36 -6
  85. package/lib/renderer/bvhAccel.js.map +1 -1
  86. package/lib/renderer/cameraUniform.d.ts +1 -1
  87. package/lib/renderer/cameraUniform.js +6 -2
  88. package/lib/renderer/cameraUniform.js.map +1 -1
  89. package/lib/renderer/compactVertices.d.ts +14 -0
  90. package/lib/renderer/compactVertices.js +124 -0
  91. package/lib/renderer/compactVertices.js.map +1 -0
  92. package/lib/renderer/easu.d.ts +11 -0
  93. package/lib/renderer/easu.js +156 -0
  94. package/lib/renderer/easu.js.map +1 -0
  95. package/lib/renderer/geometryUpdateState.d.ts +1 -0
  96. package/lib/renderer/geometryUpdateState.js.map +1 -1
  97. package/lib/renderer/geometryUpdates.js +3 -2
  98. package/lib/renderer/geometryUpdates.js.map +1 -1
  99. package/lib/renderer/glsl/aovDisplay.frag.js +5 -5
  100. package/lib/renderer/glsl/aovReflectance.glsl.js +35 -35
  101. package/lib/renderer/glsl/aovReflectanceSamples.glsl.js +1 -1
  102. package/lib/renderer/glsl/aovTrace.frag.js +44 -36
  103. package/lib/renderer/glsl/aovTrace.frag.js.map +1 -1
  104. package/lib/renderer/glsl/chunks/cameraProjection.glsl.d.ts +2 -0
  105. package/lib/renderer/glsl/chunks/cameraProjection.glsl.js +16 -0
  106. package/lib/renderer/glsl/chunks/cameraProjection.glsl.js.map +1 -0
  107. package/lib/renderer/glsl/chunks/cameraRay.glsl.d.ts +1 -1
  108. package/lib/renderer/glsl/chunks/cameraRay.glsl.js +9 -16
  109. package/lib/renderer/glsl/chunks/cameraRay.glsl.js.map +1 -1
  110. package/lib/renderer/glsl/chunks/emissiveLight.glsl.js +8 -8
  111. package/lib/renderer/glsl/chunks/envMap.glsl.js +67 -67
  112. package/lib/renderer/glsl/chunks/intersect.glsl.js +390 -375
  113. package/lib/renderer/glsl/chunks/intersect.glsl.js.map +1 -1
  114. package/lib/renderer/glsl/chunks/materialBuffer.glsl.js +120 -120
  115. package/lib/renderer/glsl/chunks/openPbrBsdf.glsl.js +562 -562
  116. package/lib/renderer/glsl/chunks/rand.glsl.js +3 -3
  117. package/lib/renderer/glsl/chunks/random.glsl.js +4 -4
  118. package/lib/renderer/glsl/chunks/rayTraceCore.glsl.js +37 -35
  119. package/lib/renderer/glsl/chunks/rayTraceCore.glsl.js.map +1 -1
  120. package/lib/renderer/glsl/chunks/sampleLight.glsl.js +70 -74
  121. package/lib/renderer/glsl/chunks/sampleLight.glsl.js.map +1 -1
  122. package/lib/renderer/glsl/chunks/sampleMaterial.glsl.d.ts +1 -1
  123. package/lib/renderer/glsl/chunks/sampleMaterial.glsl.js +107 -88
  124. package/lib/renderer/glsl/chunks/sampleMaterial.glsl.js.map +1 -1
  125. package/lib/renderer/glsl/chunks/sampleShadowCatcher.glsl.js +11 -11
  126. package/lib/renderer/glsl/chunks/sampling.glsl.js +77 -77
  127. package/lib/renderer/glsl/chunks/sobol.glsl.js +70 -70
  128. package/lib/renderer/glsl/chunks/spectralPrefix.glsl.d.ts +6 -0
  129. package/lib/renderer/glsl/chunks/spectralPrefix.glsl.js +47 -0
  130. package/lib/renderer/glsl/chunks/spectralPrefix.glsl.js.map +1 -0
  131. package/lib/renderer/glsl/chunks/textureLinear.glsl.js +5 -5
  132. package/lib/renderer/glsl/chunks/uvProjection.glsl.js +11 -11
  133. package/lib/renderer/glsl/depthQuery.frag.js +12 -6
  134. package/lib/renderer/glsl/depthQuery.frag.js.map +1 -1
  135. package/lib/renderer/glsl/normalizeRayTraceOutput.frag.js +10 -10
  136. package/lib/renderer/glsl/rayTrace.frag.js +233 -170
  137. package/lib/renderer/glsl/rayTrace.frag.js.map +1 -1
  138. package/lib/renderer/glsl/shadowCatcher.frag.js +10 -9
  139. package/lib/renderer/glsl/shadowCatcher.frag.js.map +1 -1
  140. package/lib/renderer/glsl/webglPipeline.frag.js +58 -58
  141. package/lib/renderer/gpuMemory.js +1 -1
  142. package/lib/renderer/gpuMemory.js.map +1 -1
  143. package/lib/renderer/openPbrEnergyLut.d.ts +2 -1
  144. package/lib/renderer/openPbrEnergyLut.js +18 -1
  145. package/lib/renderer/openPbrEnergyLut.js.map +1 -1
  146. package/lib/renderer/pathLimits.d.ts +5 -4
  147. package/lib/renderer/pathLimits.js +6 -5
  148. package/lib/renderer/pathLimits.js.map +1 -1
  149. package/lib/renderer/prepareMeshBVH.d.ts +2 -0
  150. package/lib/renderer/prepareMeshBVH.js +5 -3
  151. package/lib/renderer/prepareMeshBVH.js.map +1 -1
  152. package/lib/renderer/progressiveScheduler.js +1 -1
  153. package/lib/renderer/progressiveScheduler.js.map +1 -1
  154. package/lib/renderer/renderPipeline.d.ts +4 -0
  155. package/lib/renderer/renderPipeline.js +1 -0
  156. package/lib/renderer/renderPipeline.js.map +1 -1
  157. package/lib/renderer/researchTransport.d.ts +1 -1
  158. package/lib/renderer/researchTransport.js.map +1 -1
  159. package/lib/renderer/sceneAssembly.d.ts +1 -1
  160. package/lib/renderer/sceneAssembly.js +4 -3
  161. package/lib/renderer/sceneAssembly.js.map +1 -1
  162. package/lib/renderer/sceneChangeDetector.d.ts +1 -1
  163. package/lib/renderer/sceneChangeDetector.js +3 -1
  164. package/lib/renderer/sceneChangeDetector.js.map +1 -1
  165. package/lib/renderer/sceneLayoutSchema.d.ts +1 -0
  166. package/lib/renderer/sceneLayoutSchema.js +2 -2
  167. package/lib/renderer/sceneLayoutSchema.js.map +1 -1
  168. package/lib/renderer/scenePreparation.d.ts +3 -2
  169. package/lib/renderer/scenePreparation.js +18 -2
  170. package/lib/renderer/scenePreparation.js.map +1 -1
  171. package/lib/renderer/scratchSampling.js +6 -6
  172. package/lib/renderer/spectrum.js +2 -2
  173. package/lib/renderer/staticBvhPreparation.d.ts +9 -0
  174. package/lib/renderer/staticBvhPreparation.js +8 -2
  175. package/lib/renderer/staticBvhPreparation.js.map +1 -1
  176. package/lib/renderer/surfaceHit.d.ts +10 -0
  177. package/lib/renderer/surfaceHit.js +22 -0
  178. package/lib/renderer/surfaceHit.js.map +1 -0
  179. package/lib/renderer/tangentRequirements.d.ts +2 -0
  180. package/lib/renderer/tangentRequirements.js +7 -0
  181. package/lib/renderer/tangentRequirements.js.map +1 -0
  182. package/lib/renderer/textureAtlas.d.ts +4 -0
  183. package/lib/renderer/textureAtlas.js +48 -2
  184. package/lib/renderer/textureAtlas.js.map +1 -1
  185. package/lib/renderer/webgl.js +4 -0
  186. package/lib/renderer/webgl.js.map +1 -1
  187. package/lib/renderer/webglVertexAttributes.d.ts +17 -0
  188. package/lib/renderer/webglVertexAttributes.js +44 -0
  189. package/lib/renderer/webglVertexAttributes.js.map +1 -0
  190. package/lib/renderer/wgpuBindlessSource.js +2 -2
  191. package/lib/renderer/wgpuMaterialConstants.js +4 -3
  192. package/lib/renderer/wgpuMaterialConstants.js.map +1 -1
  193. package/lib/renderer/wgpuSceneUniform.js +2 -2
  194. package/lib/renderer/wgpuSceneUniform.js.map +1 -1
  195. package/lib/renderer/wgpuShaderSource.d.ts +15 -0
  196. package/lib/renderer/wgpuShaderSource.js +1 -1
  197. package/lib/renderer/wgpuShaderSource.js.map +1 -1
  198. package/lib/renderer/wgsl/aovCompact.wgsl.d.ts +4 -0
  199. package/lib/renderer/wgsl/aovCompact.wgsl.js +26 -0
  200. package/lib/renderer/wgsl/aovCompact.wgsl.js.map +1 -0
  201. package/lib/renderer/wgsl/aovDisplay.wgsl.js +9 -9
  202. package/lib/renderer/wgsl/aovReflectance.wgsl.js +39 -39
  203. package/lib/renderer/wgsl/aovReflectanceSamples.wgsl.js +1 -1
  204. package/lib/renderer/wgsl/aovResolve.wgsl.d.ts +4 -0
  205. package/lib/renderer/wgsl/aovResolve.wgsl.js +21 -2
  206. package/lib/renderer/wgsl/aovResolve.wgsl.js.map +1 -1
  207. package/lib/renderer/wgsl/aovSnapshot.wgsl.js +2 -2
  208. package/lib/renderer/wgsl/aovSnapshot.wgsl.js.map +1 -1
  209. package/lib/renderer/wgsl/aovTrace.wgsl.js +31 -31
  210. package/lib/renderer/wgsl/aovTraceDisplay.wgsl.d.ts +2 -0
  211. package/lib/renderer/wgsl/aovTraceDisplay.wgsl.js +56 -0
  212. package/lib/renderer/wgsl/aovTraceDisplay.wgsl.js.map +1 -0
  213. package/lib/renderer/wgsl/bloom.wgsl.js +18 -18
  214. package/lib/renderer/wgsl/causticLight.compute.d.ts +1 -1
  215. package/lib/renderer/wgsl/causticLight.compute.js +121 -119
  216. package/lib/renderer/wgsl/causticLight.compute.js.map +1 -1
  217. package/lib/renderer/wgsl/chunks/background.wgsl.js +46 -46
  218. package/lib/renderer/wgsl/chunks/causticAdjoint.wgsl.js +4 -4
  219. package/lib/renderer/wgsl/chunks/causticAtomic.wgsl.js +3 -3
  220. package/lib/renderer/wgsl/chunks/caustics.wgsl.js +3 -3
  221. package/lib/renderer/wgsl/chunks/common.wgsl.js +4 -4
  222. package/lib/renderer/wgsl/chunks/envMap.wgsl.js +30 -30
  223. package/lib/renderer/wgsl/chunks/intersect.wgsl.d.ts +6 -2
  224. package/lib/renderer/wgsl/chunks/intersect.wgsl.js +550 -542
  225. package/lib/renderer/wgsl/chunks/intersect.wgsl.js.map +1 -1
  226. package/lib/renderer/wgsl/chunks/intersectionAlpha.wgsl.d.ts +1 -1
  227. package/lib/renderer/wgsl/chunks/intersectionAlpha.wgsl.js +18 -16
  228. package/lib/renderer/wgsl/chunks/intersectionAlpha.wgsl.js.map +1 -1
  229. package/lib/renderer/wgsl/chunks/materialBuffer.wgsl.d.ts +2 -1
  230. package/lib/renderer/wgsl/chunks/materialBuffer.wgsl.js +70 -69
  231. package/lib/renderer/wgsl/chunks/materialBuffer.wgsl.js.map +1 -1
  232. package/lib/renderer/wgsl/chunks/openPbrBsdf.wgsl.js +593 -593
  233. package/lib/renderer/wgsl/chunks/pdm_displacement.wgsl.js +118 -118
  234. package/lib/renderer/wgsl/chunks/rand.wgsl.js +3 -3
  235. package/lib/renderer/wgsl/chunks/rayTraceCore.wgsl.d.ts +4 -1
  236. package/lib/renderer/wgsl/chunks/rayTraceCore.wgsl.js +32 -26
  237. package/lib/renderer/wgsl/chunks/rayTraceCore.wgsl.js.map +1 -1
  238. package/lib/renderer/wgsl/chunks/sampleLight.wgsl.js +114 -114
  239. package/lib/renderer/wgsl/chunks/sampleMaterial.wgsl.d.ts +1 -1
  240. package/lib/renderer/wgsl/chunks/sampleMaterial.wgsl.js +159 -137
  241. package/lib/renderer/wgsl/chunks/sampleMaterial.wgsl.js.map +1 -1
  242. package/lib/renderer/wgsl/chunks/sampleShadowCatcher.wgsl.js +8 -8
  243. package/lib/renderer/wgsl/chunks/sampling.wgsl.js +74 -74
  244. package/lib/renderer/wgsl/chunks/sobol.wgsl.js +74 -74
  245. package/lib/renderer/wgsl/chunks/spectralPrefix.wgsl.d.ts +6 -0
  246. package/lib/renderer/wgsl/chunks/spectralPrefix.wgsl.js +66 -0
  247. package/lib/renderer/wgsl/chunks/spectralPrefix.wgsl.js.map +1 -0
  248. package/lib/renderer/wgsl/chunks/uvProjection.wgsl.js +11 -11
  249. package/lib/renderer/wgsl/chunks/vertexAttributes.wgsl.d.ts +2 -0
  250. package/lib/renderer/wgsl/chunks/vertexAttributes.wgsl.js +61 -0
  251. package/lib/renderer/wgsl/chunks/vertexAttributes.wgsl.js.map +1 -0
  252. package/lib/renderer/wgsl/compose.frag.wgsl.d.ts +2 -0
  253. package/lib/renderer/wgsl/compose.frag.wgsl.js +99 -97
  254. package/lib/renderer/wgsl/compose.frag.wgsl.js.map +1 -1
  255. package/lib/renderer/wgsl/customDenoise.wgsl.js +10 -10
  256. package/lib/renderer/wgsl/depthQuery.wgsl.d.ts +1 -1
  257. package/lib/renderer/wgsl/depthQuery.wgsl.js +11 -2
  258. package/lib/renderer/wgsl/depthQuery.wgsl.js.map +1 -1
  259. package/lib/renderer/wgsl/easu.wgsl.d.ts +2 -0
  260. package/lib/renderer/wgsl/easu.wgsl.js +80 -0
  261. package/lib/renderer/wgsl/easu.wgsl.js.map +1 -0
  262. package/lib/renderer/wgsl/easuDetail.wgsl.d.ts +21 -0
  263. package/lib/renderer/wgsl/easuDetail.wgsl.js +230 -0
  264. package/lib/renderer/wgsl/easuDetail.wgsl.js.map +1 -0
  265. package/lib/renderer/wgsl/jnlm.compute.js +74 -74
  266. package/lib/renderer/wgsl/jnlm.compute.js.map +1 -1
  267. package/lib/renderer/wgsl/offlineAdaptive.compute.js +26 -26
  268. package/lib/renderer/wgsl/oidnAuxiliary.wgsl.js +3 -3
  269. package/lib/renderer/wgsl/photonMap.compute.js +89 -89
  270. package/lib/renderer/wgsl/proceduralSky.compute.js +61 -61
  271. package/lib/renderer/wgsl/rayTrace.compute.d.ts +14 -0
  272. package/lib/renderer/wgsl/rayTrace.compute.js +395 -333
  273. package/lib/renderer/wgsl/rayTrace.compute.js.map +1 -1
  274. package/lib/scene/Scene.js.map +1 -1
  275. package/lib/settings/render.d.ts +11 -0
  276. package/lib/settings/render.js +1 -0
  277. package/lib/settings/render.js.map +1 -1
  278. package/lib/util/fromTHREE.js +21 -14
  279. package/lib/util/fromTHREE.js.map +1 -1
  280. package/lib/version.d.ts +1 -1
  281. package/lib/version.js +1 -1
  282. package/lib/version.js.map +1 -1
  283. package/package.json +5 -2
  284. package/lib/oidnBundledWeights.cdn.d.ts +0 -2
  285. package/lib/oidnBundledWeights.cdn.js +0 -5
  286. package/lib/oidnBundledWeights.cdn.js.map +0 -1
  287. package/lib/renderer/bvh.worker.d.ts +0 -1
  288. package/lib/renderer/bvh.worker.js +0 -16
  289. package/lib/renderer/bvh.worker.js.map +0 -1
  290. package/lib/renderer/bvhWorkerBuild.d.ts +0 -13
  291. package/lib/renderer/bvhWorkerBuild.js +0 -17
  292. package/lib/renderer/bvhWorkerBuild.js.map +0 -1
  293. package/lib/renderer/lightCore.d.ts +0 -12
  294. package/lib/renderer/lightCore.js +0 -13
  295. package/lib/renderer/lightCore.js.map +0 -1
  296. package/lib/renderer/materialCore.d.ts +0 -8
  297. package/lib/renderer/materialCore.js +0 -9
  298. package/lib/renderer/materialCore.js.map +0 -1
  299. package/lib/scene/PixelTexture.d.ts +0 -6
  300. package/lib/scene/PixelTexture.js +0 -10
  301. package/lib/scene/PixelTexture.js.map +0 -1
  302. package/lib/util/studioLighting.d.ts +0 -18
  303. package/lib/util/studioLighting.js +0 -36
  304. package/lib/util/studioLighting.js.map +0 -1
@@ -1,5 +1,6 @@
1
+ import { spectralPrefixGlsl, prefixCheckpoint, prefixSave, prefixRestore, prefixRandomBindings } from './chunks/spectralPrefix.glsl.js';
1
2
  import { researchTransport } from '../researchTransport.js';
2
- import { MAX_PATH_EVENTS } from '../pathLimits.js';
3
+ import { MAX_PATH_EVENTS_WEBGL } from '../pathLimits.js';
3
4
  import cameraRayGlsl from './chunks/cameraRay.glsl.js';
4
5
  // Portions adapted from ray-tracing-renderer@0.10.15
5
6
  // (https://github.com/hoverinc/ray-tracing-renderer).
@@ -34,7 +35,7 @@ return;
34
35
  // So here the code are injected separately.
35
36
  const bounceCodeOnIntelMac = glsl `
36
37
 
37
- for(int yl = 0; yl < BOUNCES; yl++) {{
38
+ for(int Aj = 0; Aj < BOUNCES; Aj++) {{
38
39
  if (path.abort) {
39
40
  return vec4(path.li, path.alpha);
40
41
  }
@@ -42,10 +43,10 @@ bounce(path, depth, si, mat, outAux);
42
43
  }}
43
44
  `;
44
45
  const bounceCodeOnOther = glsl `
45
- bool xB = !si.isTransparency;
46
- int rQ = min(BOUNCES, bounceLimit);
47
- for(int idx = 0; idx < min(BOUNCES * 3, ${MAX_PATH_EVENTS}); idx++) {
48
- if (xB && idx > rQ) {
46
+ bool isOpaque = !si.isTransparency;
47
+ int activeBounceLimit = min(BOUNCES, bounceLimit);
48
+ for(int idx = 0; idx < min(BOUNCES * 3, ${MAX_PATH_EVENTS_WEBGL}); idx++) {
49
+ if (isOpaque && idx > activeBounceLimit) {
49
50
  path.abort = true;
50
51
  }
51
52
  if (path.abort) {
@@ -55,12 +56,19 @@ bounce(path, depth, si, mat, outAux);
55
56
  }
56
57
  `;
57
58
  export default function createRayTraceFragmentShader(...options) {
58
- const research = researchTransport()?.fragment(options);
59
+ const channelIndependentLight = options[0]?.channelIndependentLight ?? false;
60
+ const sharePrefix = options[0]?.shareSpectralPrefix ?? false;
61
+ const surfacePrefix = {
62
+ path: ['Path', 'path'], si: ['SurfaceInteraction', 'si'], mat: ['OpenPbrResolvedMaterial', 'mat'],
63
+ aux: ['RayTraceAuxiliary', 'outAux'], depth: ['int', 'depth'], event: ['int', 'idx'],
64
+ ignored: ['bool', 'sampleIgnored'], opaque: ['bool', 'isOpaque'], ...prefixRandomBindings
65
+ };
66
+ const research = researchTransport()?.fragment(typeof options[0] === 'object' ? [] : options);
59
67
  const enabled = research?.enabled ?? false;
60
68
  const fragments = research?.fragments;
61
69
  const materialBufferGlsl = createMaterialBufferGlsl(fragments);
62
70
  const rayTraceCore = createRayTraceCoreGlsl(fragments);
63
- const sampleMaterialGlsl = createSampleMaterialGlsl(fragments);
71
+ const sampleMaterialGlsl = createSampleMaterialGlsl(fragments, channelIndependentLight);
64
72
  const intelMac = isIntelMac();
65
73
  return new FragmentShader({
66
74
  name: 'rayTraceFrag',
@@ -75,6 +83,7 @@ export default function createRayTraceFragmentShader(...options) {
75
83
  cameraApertureRadius: Shader.uniform('float', 0),
76
84
  cameraFocusDistance: Shader.uniform('float', 10),
77
85
  viewProjectionInv: Shader.uniform('mat4'),
86
+ projectionInv: Shader.uniform('mat4'),
78
87
  viewInv: Shader.uniform('mat4'),
79
88
  transmissiveOutputAlphaMin: Shader.uniform('float'),
80
89
  openPbrEnergyLut: Shader.uniform('sampler2D'),
@@ -105,9 +114,9 @@ ${samplingGlsl}
105
114
  ${spectrumGlsl}
106
115
  ${openPbrBsdfGlsl}
107
116
 
108
- float qh;
117
+ float rq;
109
118
  float pathWavelength;
110
- int qg;
119
+ int rp;
111
120
  int pathChannel;
112
121
 
113
122
  ${sampleLightGlsl}
@@ -123,7 +132,7 @@ bool isBlank;
123
132
  bool isShadowCatcher;
124
133
  };
125
134
 
126
- void bounce(inout Path path, inout int depth, inout SurfaceInteraction si, inout OpenPbrResolvedMaterial mat, inout RayTraceAuxiliary outAux) {
135
+ ${sharePrefix ? spectralPrefixGlsl + prefixCheckpoint('spSurface', surfacePrefix) : ''}void ${sharePrefix ? 'shadeSurfaceVertex' : 'bounce'}(inout Path path, inout int depth, inout SurfaceInteraction si, inout OpenPbrResolvedMaterial mat, inout RayTraceAuxiliary outAux${sharePrefix ? ', out bool sampleIgnored' : ''}) {${sharePrefix ? '\n sampleIgnored = false;' : ''}
127
136
  samplingBounce = uint(max(depth, 0));
128
137
 
129
138
 
@@ -149,26 +158,26 @@ if (path.isNextRefraction) {
149
158
 
150
159
 
151
160
 
152
- vec4 bg = cn(path.ray.o, path.ray.d);
161
+ vec4 bg = cq(path.ray.o, path.ray.d);
153
162
  bg.rgb = sampling_spectral_rgb_filter(bg.rgb, pathChannel);
154
- float cM = path.scatteringIsDelta ? 1.0
155
- : aF(path.scatteringPdf,
156
- envMapPdf(cT(path.ray.d)) * envLightSelectionPmf);
157
- path.li += cM * path.beta * bg.rgb * bg.a;
163
+ float cP = path.scatteringIsDelta ? 1.0
164
+ : aG(path.scatteringPdf,
165
+ envMapPdf(cU(path.ray.d)) * envLightSelectionPmf);
166
+ path.li += cP * path.beta * bg.rgb * bg.a;
158
167
  path.alpha = max(path.alpha, bg.a);
159
168
  }
160
169
  else {
161
- vec2 vC = cT(path.ray.d);
162
- vec3 emission = textureLinear(envMap, vC).rgb;
170
+ vec2 xp = cU(path.ray.d);
171
+ vec3 emission = textureLinear(envMap, xp).rgb;
163
172
  emission = sampling_spectral_rgb_filter(emission, pathChannel);
164
173
  path.li += path.beta * emission *
165
- aF(
174
+ aG(
166
175
  path.scatteringPdf,
167
- envMapPdf(vC) * envLightSelectionPmf
176
+ envMapPdf(xp) * envLightSelectionPmf
168
177
  );
169
178
  }
170
179
  #else
171
- vec4 bg = cn(path.ray.o, path.ray.d);
180
+ vec4 bg = cq(path.ray.o, path.ray.d);
172
181
  bg.rgb = sampling_spectral_rgb_filter(bg.rgb, pathChannel);
173
182
  path.li += path.beta * bg.rgb * bg.a;
174
183
  #endif
@@ -179,7 +188,7 @@ return;
179
188
 
180
189
  if (!si.hit) {
181
190
 
182
- vec4 bg = cn(path.ray.o, path.ray.d);
191
+ vec4 bg = cq(path.ray.o, path.ray.d);
183
192
 
184
193
 
185
194
 
@@ -191,10 +200,10 @@ path.alpha = bg.a;
191
200
  outAux.isBlank = bg.a < 0.01;
192
201
  }
193
202
  else {
194
- Ray cam = eT(v_Texcoord + te());
195
- bool nt = dot(cam.d, path.ray.d) > 0.0;
203
+ Ray cam = cV(v_Texcoord + uH());
204
+ bool ou = dot(cam.d, path.ray.d) > 0.0;
196
205
  if (transmissiveOutputAlphaMin < 1.0) {
197
- if (nt) {
206
+ if (ou) {
198
207
  path.alpha = max(path.alpha, bg.a);
199
208
  } else {
200
209
  path.alpha = 1.0;
@@ -202,8 +211,8 @@ path.alpha = 1.0;
202
211
  }
203
212
  #if !defined(USE_ENVMAP)
204
213
 
205
- if (nt) {
206
- path.li += path.beta * aF(path.scatteringPdf, 1.0) * bg.rgb;
214
+ if (ou) {
215
+ path.li += path.beta * aG(path.scatteringPdf, 1.0) * bg.rgb;
207
216
  }
208
217
  #endif
209
218
  }
@@ -211,7 +220,7 @@ path.abort = true;
211
220
  return;
212
221
  }
213
222
 
214
- bool aJ = false;
223
+ ${sharePrefix ? ' sampleIgnored = false;' : ' bool sampleIgnored = false;'}
215
224
  if ((mat.materialType == STANDARD || mat.materialType == UNLIT)) {
216
225
  if (transmissiveOutputAlphaMin < 1.0) {
217
226
 
@@ -223,19 +232,19 @@ if (alpha < 1.0) {
223
232
 
224
233
 
225
234
  path.alpha = max(path.alpha, alpha);
226
- if (ek(3u) > alpha) {
227
- aJ = true;
235
+ if (cm(3u) > alpha) {
236
+ sampleIgnored = true;
228
237
  }
229
238
  }
230
- if (!aJ) {
231
- mx(si, mat, path);
239
+ if (!sampleIgnored) {
240
+ nB(si, mat, path);
232
241
  }
233
242
  else {
234
243
  path.ray.o = si.position + path.ray.d * EPS;
235
244
  }
236
245
  }
237
246
 
238
- if (!si.albedoSampled && !aJ) {
247
+ if (!si.albedoSampled && !sampleIgnored) {
239
248
 
240
249
  if ((mat.materialType == STANDARD || mat.materialType == UNLIT) &&
241
250
  !(mat.transmissionWeight > 0.5 ||
@@ -257,11 +266,12 @@ si.albedoSampled = true;
257
266
 
258
267
 
259
268
  #ifdef USE_RR
260
- if (depth >= RR_MAX && !aJ) {
269
+ int wj = path.scatteringMediumEntered ? RR_MAX : 2;
270
+ if (depth >= wj && !sampleIgnored) {
261
271
 
262
- float pc = max(max(path.beta.x, path.beta.y), path.beta.z);
263
- float q = max(0.0, 1.0 - pc);
264
- if (sample1D(bE(RUSSIAN_ROULETTE)) < q) {
272
+ float ql = max(max(path.beta.x, path.beta.y), path.beta.z);
273
+ float q = max(0.0, 1.0 - ql);
274
+ if (sample1D(aX(RUSSIAN_ROULETTE)) < q) {
265
275
 
266
276
 
267
277
  path.alpha = 1.0;
@@ -277,17 +287,20 @@ if (path.abort) {
277
287
  return;
278
288
  }
279
289
 
280
-
281
- intersectScene(path.ray, si, true);
290
+ ${sharePrefix ? /* glsl */ ` return;
291
+ }
292
+ void qU(inout Path path, inout int depth, inout SurfaceInteraction si, inout OpenPbrResolvedMaterial mat, bool sampleIgnored) {
293
+ ` : ''}
294
+ ${sharePrefix ? '' : /* glsl */ ` intersectScene(path.ray, si, true);
282
295
  getMaterial(mat, si.materialIndex, si.uv, si.uv1, si.instanceIndex, si.vertexColor);
283
296
  si.isTransparency = mat.transmissionWeight > 0.001 || mat.subsurfaceWeight > 0.001 || mat.alpha < 0.999;
284
-
297
+ `}
285
298
 
286
299
 
287
300
 
288
301
  if (dispersionWavelengths == 1 && si.hit && mat.transmissionWeight > 0.001 && mat.transmissionDispersionScale > 0.001) {
289
- pathWavelength = qh;
290
- pathChannel = qg;
302
+ pathWavelength = rq;
303
+ pathChannel = rp;
291
304
  }
292
305
  if (mat.transmissionWeight > 0.001 && pathWavelength > 0.0) {
293
306
  mat.specularIor = sampling_cauchy_ior(
@@ -298,22 +311,22 @@ mat.dispersionAbbeNumber
298
311
  );
299
312
  }
300
313
 
301
- if (aJ) {
314
+ if (sampleIgnored) {
302
315
  return;
303
316
  }
304
317
 
305
- bool ht = ek(3u) < mat.alpha;
318
+ bool hN = cm(3u) < mat.alpha;
306
319
  #ifdef NUM_LIGHTS
307
320
 
308
321
  LightSampleRec lightSample;
309
322
  for (int i = 0; i < NUM_LIGHTS; i++) {
310
323
 
311
324
  Light light = fetchLight(i);
312
- float d = mX(path.ray, light, lightSample);
313
- bool lH = si.hit && d > distance(si.position, path.ray.o);
314
- if (d != INF && !(lH && ht)) {
325
+ float d = iB(path.ray, light, lightSample);
326
+ bool mz = si.hit && d > distance(si.position, path.ray.o);
327
+ if (d != INF && !(mz && hN)) {
315
328
  lightSample.pdf *= light.selectionPmf;
316
- float misWeight = aF(path.scatteringPdf, lightSample.pdf);
329
+ float misWeight = aG(path.scatteringPdf, lightSample.pdf);
317
330
  lightSample.emission = sampling_spectral_rgb_filter(lightSample.emission, pathChannel);
318
331
  ${enabled ? 'if (!causticHitOwned(path)) { ' : ''}path.li += misWeight * path.beta * lightSample.emission;${enabled ? ' }' : ''}
319
332
 
@@ -324,23 +337,23 @@ path.abort = true;
324
337
  #endif
325
338
 
326
339
  #ifdef USE_ENVMAP
327
- if (!(si.hit && ht)) {
340
+ if (!(si.hit && hN)) {
328
341
  if (path.isNextRefraction) {
329
342
 
330
343
 
331
- vec4 bg = cn(path.ray.o, path.ray.d);
344
+ vec4 bg = cq(path.ray.o, path.ray.d);
332
345
  bg.rgb = sampling_spectral_rgb_filter(bg.rgb, pathChannel);
333
- float cM = path.scatteringIsDelta ? 1.0
334
- : aF(path.scatteringPdf,
335
- envMapPdf(cT(path.ray.d)) * envLightSelectionPmf);
336
- path.li += cM * path.beta * bg.rgb * bg.a;
346
+ float cP = path.scatteringIsDelta ? 1.0
347
+ : aG(path.scatteringPdf,
348
+ envMapPdf(cU(path.ray.d)) * envLightSelectionPmf);
349
+ path.li += cP * path.beta * bg.rgb * bg.a;
337
350
  path.alpha = max(path.alpha, bg.a);
338
351
  path.abort = true;
339
352
  return;
340
353
  }
341
- vec2 uv = cT(path.ray.d);
354
+ vec2 uv = cU(path.ray.d);
342
355
  vec3 emission = textureLinear(envMap, uv).rgb;
343
- float misWeight = aF(
356
+ float misWeight = aG(
344
357
  path.scatteringPdf,
345
358
  envMapPdf(uv) * envLightSelectionPmf
346
359
  );
@@ -360,110 +373,110 @@ depth++;
360
373
  }
361
374
 
362
375
 
363
- vec2 kK(float radius, float xi) {
376
+ vec2 lD(float radius, float xi) {
364
377
  float x = 0.25;
365
378
  for (int iteration = 0; iteration < 10; iteration++) {
366
379
  float x2 = x * x;
367
380
  float x3 = x2 * x;
368
- float la = 1.0 - x;
381
+ float lU = 1.0 - x;
369
382
  float value = 10.0 * x2 - 20.0 * x3 + 15.0 * x2 * x2 -
370
383
  4.0 * x2 * x3 - xi;
371
- float mJ = 20.0 * x * la * la * la;
372
- if (abs(value) < 1e-6 || mJ == 0.0) break;
373
- x = clamp(x - value / mJ, 0.0, 1.0);
384
+ float nL = 20.0 * x * lU * lU * lU;
385
+ if (abs(value) < 1e-6 || nL == 0.0) break;
386
+ x = clamp(x - value / nL, 0.0, 1.0);
374
387
  }
375
- float jr = x * radius;
388
+ float jW = x * radius;
376
389
  return vec2(
377
- jr,
378
- sqrt(max(radius * radius - jr * jr, 0.0))
390
+ jW,
391
+ sqrt(max(radius * radius - jW * jW, 0.0))
379
392
  );
380
393
  }
381
394
 
382
- float bevelCubicPdf(float radius, float gu) {
383
- if (gu >= radius) return 0.0;
384
- float falloff = radius - gu;
395
+ float bevelCubicPdf(float radius, float gO) {
396
+ if (gO >= radius) return 0.0;
397
+ float falloff = radius - gO;
385
398
  return falloff * falloff * falloff;
386
399
  }
387
400
 
388
401
 
389
- vec3 mT(SurfaceInteraction source, float radius) {
402
+ vec3 kB(SurfaceInteraction source, float radius) {
390
403
  vec3 geometricNormal = source.faceNormal;
391
404
  if (dot(geometricNormal, source.vertexNormal) < 0.0) geometricNormal = -geometricNormal;
392
405
  vec3 tangent;
393
406
  vec3 bitangent;
394
407
  sampling_orthonormal_basis(geometricNormal, tangent, bitangent);
395
- vec3 iE = vec3(0.0);
396
-
397
- for (int ih = 0; ih < BEVEL_SAMPLES; ih++) {
398
- vec2 qa = sample2D(CAMERA_BEVEL_BASE + uint(ih));
399
- float cr = qa.x;
400
- float pj = qa.y;
401
- vec3 cZ = geometricNormal;
402
- vec3 fI = tangent;
403
- vec3 eh = bitangent;
404
- float ge = 0.5;
405
- float hW = 0.25;
406
- float gC = 0.25;
407
- if (cr < 0.5) {
408
- cr *= 2.0;
409
- }
410
- else if (cr < 0.75) {
411
- vec3 nr = cZ;
412
- cZ = fI;
413
- fI = nr;
414
- ge = 0.25;
415
- hW = 0.5;
416
- cr = (cr - 0.5) * 4.0;
408
+ vec3 jd = vec3(0.0);
409
+
410
+ for (int iN = 0; iN < BEVEL_SAMPLES; iN++) {
411
+ vec2 rh = sample2D(CAMERA_BEVEL_BASE + uint(iN));
412
+ float cu = rh.x;
413
+ float qt = rh.y;
414
+ vec3 dc = geometricNormal;
415
+ vec3 fU = tangent;
416
+ vec3 eo = bitangent;
417
+ float gw = 0.5;
418
+ float iH = 0.25;
419
+ float gV = 0.25;
420
+ if (cu < 0.5) {
421
+ cu *= 2.0;
422
+ }
423
+ else if (cu < 0.75) {
424
+ vec3 os = dc;
425
+ dc = fU;
426
+ fU = os;
427
+ gw = 0.25;
428
+ iH = 0.5;
429
+ cu = (cu - 0.5) * 4.0;
417
430
  }
418
431
  else {
419
- vec3 nr = cZ;
420
- cZ = eh;
421
- eh = nr;
422
- ge = 0.25;
423
- gC = 0.5;
424
- cr = (cr - 0.75) * 4.0;
425
- }
426
-
427
- vec2 gQ = kK(radius, pj);
428
- float phi = TWOPI * cr;
429
- vec3 rr = gQ.x *
430
- (cos(phi) * fI + sin(phi) * eh);
432
+ vec3 os = dc;
433
+ dc = eo;
434
+ eo = os;
435
+ gw = 0.25;
436
+ gV = 0.5;
437
+ cu = (cu - 0.75) * 4.0;
438
+ }
439
+
440
+ vec2 hm = lD(radius, qt);
441
+ float phi = TWOPI * cu;
442
+ vec3 sI = hm.x *
443
+ (cos(phi) * fU + sin(phi) * eo);
431
444
  Ray ray;
432
445
  initRay(
433
446
  ray,
434
- source.position + cZ * gQ.y + rr,
435
- -cZ
447
+ source.position + dc * hm.y + sI,
448
+ -dc
436
449
  );
437
450
  SurfaceInteraction hit;
438
451
  intersectSceneBevel(
439
452
  ray,
440
453
  hit,
441
454
  source.instanceIndex,
442
- max(2.0 * gQ.y, EPS)
455
+ max(2.0 * hm.y, EPS)
443
456
  );
444
457
  if (!hit.hit) continue;
445
458
 
446
- float lc = ge * abs(dot(cZ, hit.faceNormal));
447
- float nj = hW * abs(dot(fI, hit.faceNormal));
448
- float kj = gC * abs(dot(eh, hit.faceNormal));
449
- float weight = lc / max(
450
- lc * lc + nj * nj +
451
- kj * kj,
459
+ float lV = gw * abs(dot(dc, hit.faceNormal));
460
+ float oi = iH * abs(dot(fU, hit.faceNormal));
461
+ float kR = gV * abs(dot(eo, hit.faceNormal));
462
+ float weight = lV / max(
463
+ lV * lV + oi * oi +
464
+ kR * kR,
452
465
  1e-8
453
466
  );
454
467
  weight *= bevelCubicPdf(radius, distance(hit.position, source.position)) /
455
- max(bevelCubicPdf(radius, gQ.x), 1e-8);
456
- iE += weight * hit.vertexNormal;
468
+ max(bevelCubicPdf(radius, hm.x), 1e-8);
469
+ jd += weight * hit.vertexNormal;
457
470
  }
458
471
 
459
- if (dot(iE, iE) <= 1e-12) return source.normal;
460
- vec3 jM = normalize(iE);
461
- vec3 result = source.normal + jM - source.vertexNormal;
472
+ if (dot(jd, jd) <= 1e-12) return source.normal;
473
+ vec3 kt = normalize(jd);
474
+ vec3 result = source.normal + kt - source.vertexNormal;
462
475
  return dot(result, result) > 1e-12 ? normalize(result) : source.normal;
463
476
  }
464
477
 
465
- vec4 cG(SurfaceInteraction si, Ray ray, OpenPbrResolvedMaterial mat, inout RayTraceAuxiliary outAux) {
466
- Path path;
478
+ vec4 cJ(SurfaceInteraction si, Ray ray, OpenPbrResolvedMaterial mat, inout RayTraceAuxiliary outAux) {
479
+ Path path; path.scatteringMediumEntered = false;
467
480
  path.ray = ray;
468
481
  path.li = vec3(0);
469
482
  path.alpha = transmissiveOutputAlphaMin < 1.0 ? 0.0 : 1.0;
@@ -476,63 +489,94 @@ path.scatteringIsDelta = false;
476
489
  path.isNextRefraction = false;
477
490
  path.abort = false;
478
491
  int depth = 0;
479
- ${intelMac ? bounceCodeOnIntelMac : bounceCodeOnOther}
480
- return vec4(path.li, path.alpha);
492
+ ${sharePrefix ? /* glsl */ ` int spSlot = qz++;
493
+ if (spActive && spChannel > 1 && eB[spSlot].ready) return rN(spSlot, outAux);
494
+ bool isOpaque = !si.isTransparency;
495
+ bool sampleIgnored = false, spResume = false;
496
+ int spEvent = 0;
497
+ if (spActive && spChannel > 1 && fC == spSlot) {
498
+ int idx = 0;
499
+ ${prefixRestore('spSurface', surfacePrefix)}
500
+ spEvent = idx; spResume = true; qA(path);
501
+ }
502
+ int activeBounceLimit = min(BOUNCES, bounceLimit);
503
+ for (int idx = ${intelMac ? '0' : 'spEvent'}; idx < ${intelMac ? 'BOUNCES' : `min(BOUNCES * 3, ${MAX_PATH_EVENTS_WEBGL})`}; idx++) {
504
+ ${intelMac ? ' if (idx < spEvent) continue;' : ' if (isOpaque && idx > activeBounceLimit) path.abort = true;'}
505
+ if (path.abort) break;
506
+ if (!spResume) {
507
+ shadeSurfaceVertex(path, depth, si, mat, outAux, sampleIgnored);
508
+ if (!path.abort) {
509
+ intersectScene(path.ray, si, true);
510
+ getMaterial(mat, si.materialIndex, si.uv, si.uv1, si.instanceIndex, si.vertexColor);
511
+ si.isTransparency = mat.transmissionWeight > 0.001 || mat.subsurfaceWeight > 0.001 || mat.alpha < 0.999;
512
+ }
513
+ }
514
+ spResume = false;
515
+ if (!path.abort) {
516
+ if (spActive && mat.transmissionWeight > 0.001 && gf(mat)) {
517
+ ${prefixSave('spSurface', surfacePrefix)}
518
+ fC = spSlot; qA(path);
519
+ }
520
+ qU(path, depth, si, mat, sampleIgnored);
521
+ }
522
+ }
523
+ return spFinish(spSlot, vec4(path.li, path.alpha), outAux);` : /* glsl */ `${intelMac ? bounceCodeOnIntelMac : bounceCodeOnOther}
524
+ return vec4(path.li, path.alpha);`}
481
525
  }
482
526
 
483
- vec4 iC(SurfaceInteraction si, Ray ray, OpenPbrResolvedMaterial mat, inout RayTraceAuxiliary outAux) {
527
+ vec4 jb(SurfaceInteraction si, Ray ray, OpenPbrResolvedMaterial mat, inout RayTraceAuxiliary outAux) {
484
528
  float coverage = clamp(mat.alpha, 0.0, 1.0);
485
529
  if (!si.hit || (mat.materialType != STANDARD && mat.materialType != UNLIT) || coverage >= 1.0) {
486
- return cG(si, ray, mat, outAux);
530
+ return cJ(si, ray, mat, outAux);
487
531
  }
488
532
 
489
533
 
490
534
 
491
535
 
492
536
 
493
- Ray uK = ray;
494
- uK.o = si.position + ray.d * (EPS * 0.02);
495
- SurfaceInteraction jL = si;
496
- jL.albedoSampled = false;
497
- intersectScene(uK, jL, false);
498
- OpenPbrResolvedMaterial oH;
499
- getMaterial(oH, jL.materialIndex, jL.uv, jL.uv1, jL.instanceIndex, jL.vertexColor);
500
- RayTraceAuxiliary eg = outAux;
501
- if (jL.hit && (oH.materialType == STANDARD || oH.materialType == UNLIT)) {
502
- eg.albedo = oH.transmissionWeight > 0.5
537
+ Ray wt = ray;
538
+ wt.o = si.position + ray.d * (EPS * 0.02);
539
+ SurfaceInteraction kq = si;
540
+ kq.albedoSampled = false;
541
+ intersectScene(wt, kq, false);
542
+ OpenPbrResolvedMaterial pN;
543
+ getMaterial(pN, kq.materialIndex, kq.uv, kq.uv1, kq.instanceIndex, kq.vertexColor);
544
+ RayTraceAuxiliary backAux = outAux;
545
+ if (kq.hit && (pN.materialType == STANDARD || pN.materialType == UNLIT)) {
546
+ backAux.albedo = pN.transmissionWeight > 0.5
503
547
  ? vec3(1.0)
504
- : oH.baseColor;
505
- eg.normal = dot(
506
- jL.normal,
507
- jL.position - vec3(viewInv[3])
548
+ : pN.baseColor;
549
+ backAux.normal = dot(
550
+ kq.normal,
551
+ kq.position - vec3(viewInv[3])
508
552
  ) > 0.0
509
- ? -jL.normal
510
- : jL.normal;
511
- jL.albedoSampled = oH.transmissionWeight > 0.5;
553
+ ? -kq.normal
554
+ : kq.normal;
555
+ kq.albedoSampled = pN.transmissionWeight > 0.5;
512
556
  }
513
- vec4 back = cG(jL, uK, oH, eg);
557
+ vec4 back = cJ(kq, wt, pN, backAux);
514
558
  if (coverage <= 0.0) {
515
- outAux = eg;
559
+ outAux = backAux;
516
560
  return back;
517
561
  }
518
562
 
519
- SurfaceInteraction yc = si;
520
- OpenPbrResolvedMaterial vD = mat;
521
- vD.alpha = 1.0;
522
- RayTraceAuxiliary sa = outAux;
523
- vec4 front = cG(yc, ray, vD, sa);
524
- outAux.albedo = mix(eg.albedo, sa.albedo, coverage);
525
- vec3 cS = mix(eg.normal, sa.normal, coverage);
526
- outAux.normal = dot(cS, cS) > 1e-12
527
- ? normalize(cS)
563
+ SurfaceInteraction zY = si;
564
+ OpenPbrResolvedMaterial xq = mat;
565
+ xq.alpha = 1.0;
566
+ RayTraceAuxiliary tA = outAux;
567
+ vec4 front = cJ(zY, ray, xq, tA);
568
+ outAux.albedo = mix(backAux.albedo, tA.albedo, coverage);
569
+ vec3 aS = mix(backAux.normal, tA.normal, coverage);
570
+ outAux.normal = dot(aS, aS) > 1e-12
571
+ ? normalize(aS)
528
572
  : vec3(0.0);
529
- outAux.isBlank = eg.isBlank && sa.isBlank;
573
+ outAux.isBlank = backAux.isBlank && tA.isBlank;
530
574
  return mix(back, front, coverage);
531
575
  }
532
576
 
533
577
 
534
578
 
535
- vec4 hR(Ray ray, out RayTraceAuxiliary outAux) {
579
+ vec4 hq(Ray ray, out RayTraceAuxiliary outAux) {
536
580
 
537
581
  SurfaceInteraction si;
538
582
  OpenPbrResolvedMaterial mat;
@@ -545,13 +589,13 @@ si.mediumScattering = vec3(0.0);
545
589
  si.mediumAnisotropy = 0.0;
546
590
  #endif
547
591
 
548
- intersectScene(ray, si, false);
592
+ ${sharePrefix ? ' if (spChannel == 1) {\n' : ''} intersectScene(ray, si, false);
549
593
  getMaterial(mat, si.materialIndex, si.uv, si.uv1, si.instanceIndex, si.vertexColor);
550
594
  si.isTransparency = mat.transmissionWeight > 0.001 || mat.subsurfaceWeight > 0.001 || mat.alpha < 0.999;
551
595
 
552
596
  #ifdef HAS_BEVEL
553
597
  if (bevelEnabled && mat.bevel > 0.0) {
554
- si.normal = mT(si, mat.bevel);
598
+ si.normal = kB(si, mat.bevel);
555
599
  }
556
600
  #endif
557
601
 
@@ -567,7 +611,15 @@ outAux.normal = dot(si.normal, si.position - vec3(viewInv[3])) > 0.0
567
611
  si.albedoSampled = mat.transmissionWeight > 0.5;
568
612
  }
569
613
 
570
- if (mat.transmissionDispersionScale > 0.001) {
614
+ ${sharePrefix ? /* glsl */ ` lY = qI(si, mat, outAux, s0, hashedCounter, samplingBounce);
615
+ } else {
616
+ si = lY.si; mat = lY.mat; outAux = lY.aux;
617
+ s0 = lY.rng; hashedCounter = lY.counter; samplingBounce = lY.bounce;
618
+ }
619
+ spActive = ${enabled ? 'false' : '!(mat.transmissionDispersionScale > 0.001 && mat.specularIor != 1.0)'};
620
+ pathChannel = spActive ? 0 : spChannel;
621
+ qz = 0;
622
+ ` : ''} if (mat.transmissionDispersionScale > 0.001) {
571
623
  mat.specularIor = sampling_cauchy_ior(
572
624
  pathWavelength,
573
625
  mat.specularIor,
@@ -575,31 +627,31 @@ mat.transmissionDispersionScale,
575
627
  mat.dispersionAbbeNumber
576
628
  );
577
629
  }
578
- return iC(si, ray, mat, outAux);
630
+ return jb(si, ray, mat, outAux);
579
631
  }
580
632
 
581
- void main() {
633
+ void ${sharePrefix ? 'traceSpectralWavelength' : 'main'}(${sharePrefix ? 'int channel' : ''}) {
582
634
 
583
- ${fragments?.debugInit ?? ''} rA();
584
- fi(v_Texcoord * viewportSize, int(uint(sampleCount) ^ cB(uint(sequenceSeed))));
635
+ ${fragments?.debugInit ?? ''} sP();
636
+ fA(v_Texcoord * viewportSize, int(uint(sampleCount) ^ cD(uint(sequenceSeed))));
585
637
 
586
638
 
587
- pathWavelength = 0.0;
639
+ ${sharePrefix ? ' spChannel = channel;\n' : ''} pathWavelength = 0.0;
588
640
  pathChannel = 0;
589
641
  if (spectralChannel > 0) {
590
- float aZ = sample1D(CAMERA_WAVELENGTH);
642
+ float aE = sample1D(CAMERA_WAVELENGTH);
591
643
  if (dispersionWavelengths == 1) {
592
- qg = min(int(aZ * 3.0), 2) + 1;
593
- qh = cU(qg - 1, fract(aZ * 3.0));
644
+ rp = min(int(aE * 3.0), 2) + 1;
645
+ rq = ce(rp - 1, fract(aE * 3.0));
594
646
  } else {
595
- pathChannel = spectralChannel;
596
- pathWavelength = cU(spectralChannel - 1, aZ);
647
+ pathChannel = ${sharePrefix ? 'spChannel' : 'spectralChannel'};
648
+ pathWavelength = ce(${sharePrefix ? 'spChannel' : 'spectralChannel'} - 1, aE);
597
649
  }
598
650
  }
599
651
 
600
652
 
601
653
 
602
- Ray cam = ow();
654
+ Ray cam = pq();
603
655
 
604
656
  RayTraceAuxiliary outAux;
605
657
  outAux.albedo = vec3(0.0);
@@ -607,7 +659,7 @@ outAux.normal = vec3(0.0);
607
659
  outAux.isBlank = false;
608
660
  outAux.isShadowCatcher = false;
609
661
 
610
- vec4 liAndAlpha = hR(cam, outAux);
662
+ vec4 liAndAlpha = hq(cam, outAux);
611
663
 
612
664
 
613
665
 
@@ -635,12 +687,23 @@ out_albedo = vec4(outAux.albedo, outAux.isBlank ? 0.0 : 1.0);
635
687
  out_normal = vec4(outAux.normal, 1.0);
636
688
 
637
689
 
638
- float jw = dot(liAndAlpha.rgb, vec3(0.2126, 0.7152, 0.0722));
690
+ float jZ = dot(liAndAlpha.rgb, vec3(0.2126, 0.7152, 0.0722));
639
691
  out_moments = outAux.isShadowCatcher
640
692
  ? vec4(0.0)
641
- : vec4(jw, jw * jw, 1.0, 0.0);
693
+ : vec4(jZ, jZ * jZ, 1.0, 0.0);
694
+
695
+ }${sharePrefix ? /* glsl */ `
696
+ void main() {
697
+ eB[0].ready = false; eB[1].ready = false;
698
+ vec4 color = vec4(0.0), albedo = vec4(0.0), normal = vec4(0.0), moments = vec4(0.0);
642
699
 
643
- }`
700
+ for (int channel = 1; channel <= dispersionWavelengths; channel++) {
701
+ traceSpectralWavelength(channel);
702
+ color += out_color; albedo += out_albedo; normal += out_normal; moments += out_moments;
703
+ }
704
+ out_color = color; out_albedo = albedo; out_normal = normal; out_moments = moments;
705
+ }
706
+ ` : ''}`
644
707
  });
645
708
  }
646
709
  //# sourceMappingURL=rayTrace.frag.js.map