@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
@@ -5,13 +5,13 @@ import { glsl } from '../../shader.js';
5
5
  export default glsl `
6
6
  uvec4 s0;
7
7
 
8
- void fi(vec2 p, int frame) {
8
+ void fA(vec2 p, int frame) {
9
9
 
10
10
  s0 = uvec4(p, uint(frame), uint(p.x) + uint(p.y));
11
11
  }
12
12
 
13
13
 
14
- void xF(inout uvec4 v) {
14
+ void zF(inout uvec4 v) {
15
15
  v = v * 1664525u + 1013904223u;
16
16
  v.x += v.y*v.w; v.y += v.z*v.x; v.z += v.x*v.y; v.w += v.y*v.z;
17
17
  v = v ^ (v>>16u);
@@ -19,7 +19,7 @@ v.x += v.y*v.w; v.y += v.z*v.x; v.z += v.x*v.y; v.w += v.y*v.z;
19
19
  }
20
20
 
21
21
  float rand() {
22
- xF(s0); return float(s0.x)/float(0xffffffffu);
22
+ zF(s0); return float(s0.x)/float(0xffffffffu);
23
23
  }
24
24
 
25
25
  `;
@@ -10,13 +10,13 @@ export default createShaderMixin({
10
10
 
11
11
  ${sobol}
12
12
 
13
- void rA() {
14
- aI = uvec2(v_Texcoord / pixelSize);
13
+ void sP() {
14
+ aJ = uvec2(v_Texcoord / pixelSize);
15
15
  aC = uint(sampleCount);
16
- samplingBounce = 0u; ca = 0u;
16
+ samplingBounce = 0u; hashedCounter = 0u;
17
17
  }
18
18
 
19
- vec2 te() {
19
+ vec2 uH() {
20
20
  if (samplingPattern == 0 || samplingPattern == 1) {
21
21
  return (sample2D(CAMERA_PIXEL) - 0.5) * pixelSize;
22
22
  }
@@ -24,7 +24,7 @@ export function createRayTraceCoreGlsl(fragments = {}) {
24
24
  main: glsl `
25
25
 
26
26
  const vec3 luminance = vec3(0.2126, 0.7152, 0.0722);
27
- const int xO = 8;
27
+ const int zL = 8;
28
28
 
29
29
  #define RAY_MAX_DISTANCE 9999.0
30
30
 
@@ -165,22 +165,24 @@ ray.tMax = RAY_MAX_DISTANCE;
165
165
  }
166
166
 
167
167
 
168
- ivec2 gM(int i, int jE) {
168
+ ivec2 uO(int i, int ki) {
169
169
  ivec2 u;
170
- u.y = i >> jE;
171
- u.x = i - (u.y << jE);
170
+ u.y = i >> ki;
171
+ u.x = i - (u.y << ki);
172
172
  return u;
173
173
  }
174
174
 
175
- vec4 fetchData(sampler2D s, int i, int jE) {
176
- return texelFetch(s, gM(i, jE), 0);
175
+ vec4 fetchData(sampler2D s, int i, int ki) {
176
+ return texelFetch(s, uO(i, ki), 0);
177
177
  }
178
178
 
179
- ivec4 fetchData(highp isampler2D s, int i, int jE) {
180
- return texelFetch(s, gM(i, jE), 0);
179
+ ivec4 fetchData(highp isampler2D s, int i, int ki) {
180
+ return texelFetch(s, uO(i, ki), 0);
181
181
  }
182
182
 
183
183
  struct Path {
184
+
185
+ bool scatteringMediumEntered;
184
186
  Ray ray;
185
187
  vec3 li;
186
188
  float alpha;
@@ -216,12 +218,12 @@ lightsTex,
216
218
  ivec2(firstTexel + 1, 0),
217
219
  0
218
220
  );
219
- vec4 oB = texelFetch(
221
+ vec4 pG = texelFetch(
220
222
  lightsTex,
221
223
  ivec2(firstTexel + 2, 0),
222
224
  0
223
225
  );
224
- vec4 me = texelFetch(
226
+ vec4 mW = texelFetch(
225
227
  lightsTex,
226
228
  ivec2(firstTexel + 3, 0),
227
229
  0
@@ -234,31 +236,31 @@ ivec2(firstTexel + 4, 0),
234
236
  return Light(
235
237
  positionAndPmf.xyz,
236
238
  emissionAndCdf.xyz,
237
- oB.xyz,
238
- me.xyz,
239
+ pG.xyz,
240
+ mW.xyz,
239
241
  shape.x,
240
242
  shape.y,
241
243
  shape.z,
242
- int(me.w),
243
- oB.w,
244
+ int(mW.w),
245
+ pG.w,
244
246
  positionAndPmf.w,
245
247
  emissionAndCdf.w,
246
248
  texelFetch(lightsTex, ivec2(firstTexel + 5, 0), 0).xyz
247
249
  );
248
250
  }
249
251
 
250
- float cF(int dV, int lK) {
251
- int im = dV + lK / 4;
252
+ float cI(int ec, int mC) {
253
+ int iR = ec + mC / 4;
252
254
  vec4 packed = texelFetch(
253
255
  iesProfileData,
254
- ivec2(im % iesProfileColumns, im / iesProfileColumns),
256
+ ivec2(iR % iesProfileColumns, iR / iesProfileColumns),
255
257
  0
256
258
  );
257
- return packed[lK % 4];
259
+ return packed[mC % 4];
258
260
  }
259
261
 
260
- float ld(int dV, vec2 uv) {
261
- if (dV < 0) return 1.0;
262
+ float lW(int ec, vec2 uv) {
263
+ if (ec < 0) return 1.0;
262
264
  vec2 pixel = fract(uv) * 128.0 - 0.5;
263
265
  ivec2 p0 = ivec2(floor(pixel));
264
266
  vec2 f = fract(pixel);
@@ -266,25 +268,25 @@ int xa = p0.x < 0 ? 127 : p0.x;
266
268
  int xb = p0.x >= 127 ? 0 : p0.x + 1;
267
269
  int ya = p0.y < 0 ? 127 : p0.y;
268
270
  int yb = p0.y >= 127 ? 0 : p0.y + 1;
269
- float a = cF(dV, ya * 128 + xa);
270
- float b = cF(dV, ya * 128 + xb);
271
- float c = cF(dV, yb * 128 + xa);
272
- float d = cF(dV, yb * 128 + xb);
271
+ float a = cI(ec, ya * 128 + xa);
272
+ float b = cI(ec, ya * 128 + xb);
273
+ float c = cI(ec, yb * 128 + xa);
274
+ float d = cI(ec, yb * 128 + xb);
273
275
  return mix(mix(a, b, f.x), mix(c, d, f.x), f.y);
274
276
  }
275
277
 
276
- float evaluateSpotEmissionMultiplier(Light light, vec3 dI) {
278
+ float evaluateSpotEmissionMultiplier(Light light, vec3 dL) {
277
279
  vec3 axis = normalize(light.u);
278
- float ct = dot(axis, dI);
279
- float vw = light.v.y > light.v.x + 1e-6
280
- ? smoothstep(light.v.x, light.v.y, ct)
281
- : step(light.v.x, ct);
282
- if (vw <= 0.0 || light.textureIndex < 0) return vw;
283
- vec3 vX = light.iesReference;
284
- vec3 xN = cross(axis, vX);
285
- float vertical = acos(clamp(ct, -1.0, 1.0));
286
- float horizontal = atan(dot(dI, xN), dot(dI, vX));
287
- return vw * ld(light.textureIndex, vec2(vertical / PI, horizontal / TWOPI + 0.5));
280
+ float cv = dot(axis, dL);
281
+ float xm = light.v.y > light.v.x + 1e-6
282
+ ? smoothstep(light.v.x, light.v.y, cv)
283
+ : step(light.v.x, cv);
284
+ if (xm <= 0.0 || light.textureIndex < 0) return xm;
285
+ vec3 xT = light.iesReference;
286
+ vec3 zK = cross(axis, xT);
287
+ float vertical = acos(clamp(cv, -1.0, 1.0));
288
+ float horizontal = atan(dot(dL, zK), dot(dL, xT));
289
+ return xm * lW(light.textureIndex, vec2(vertical / PI, horizontal / TWOPI + 0.5));
288
290
  }
289
291
  `
290
292
  });
@@ -1 +1 @@
1
- {"version":3,"file":"rayTraceCore.glsl.js","sourceRoot":"","sources":["../../../../src/renderer/glsl/chunks/rayTraceCore.glsl.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,sDAAsD;AACtD,kFAAkF;AAElF,OAAO,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC7E,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAE9D,MAAM,UAAU,sBAAsB,CAAC,YAA8C,EAAE;IAAI,OAAO,iBAAiB,CAAC;QAClH,QAAQ,EAAE;YACR,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC;YACtC,cAAc,EAAE,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC;YAC3C,iBAAiB,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;YAC3C,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;YACjC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;YAC9B,WAAW,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;YAClC,oBAAoB,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;SACjD;QACD,OAAO,EAAE;YACP,QAAQ,EAAE,CAAC;YACX,KAAK,EAAE,aAAa;YACpB,cAAc,EAAE,qBAAqB;YACrC,UAAU,EAAE,mBAAmB;SAChC;QACD,IAAI,EAAE,IAAI,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BA6DgB,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA2G1B,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiGjD;KACA,CAAC,CAAC;AACH,CAAC;AACD,eAAe,sBAAsB,EAAE,CAAC","sourcesContent":["// Portions adapted from ray-tracing-renderer@0.10.15\n// (https://github.com/hoverinc/ray-tracing-renderer).\n// Copyright (c) 2019 HOVER, MIT license; see LICENSES/RayTracingRenderer-MIT.txt.\n\nimport { createShaderMixin, glsl, Shader } from '../../shader.js';\nimport { ShadowCatcherMaterial, UnlitMaterial } from '../../../constants.js';\nimport { CONSTANT_SPOT_LIGHT } from '../../lightConstants.js';\n\nexport function createRayTraceCoreGlsl(fragments: Readonly<Record<string, string>> = {}) { return createShaderMixin({\n uniforms: {\n lightsTex: Shader.uniform('sampler2D'),\n iesProfileData: Shader.uniform('sampler2D'),\n iesProfileColumns: Shader.uniform('int', 1),\n pixelSize: Shader.uniform('vec2'),\n jitter: Shader.uniform('vec2'),\n sampleCount: Shader.uniform('int'),\n envLightSelectionPmf: Shader.uniform('float', 0)\n },\n defines: {\n STANDARD: 0,\n UNLIT: UnlitMaterial,\n SHADOW_CATCHER: ShadowCatcherMaterial,\n SPOT_LIGHT: CONSTANT_SPOT_LIGHT\n },\n main: glsl`\n// https://www.w3.org/WAI/GL/wiki/Relative_luminance\nconst vec3 luminance = vec3(0.2126, 0.7152, 0.0722);\nconst int bounceSamples = 8;\n\n#define RAY_MAX_DISTANCE 9999.0\n\n#define NO_UNROLL(X) (X + min(0, sampleCount))\n#define NO_UNROLLU(X) (X + uint(min(0, sampleCount)))\n\nstruct Ray {\n vec3 o;\n vec3 d;\n float tMax;\n};\n\nstruct SurfaceInteraction {\n bool hit;\n vec3 position;\n vec3 normal; // material shading normal\n#ifdef USE_COAT_NORMAL_FRAMES\n vec3 coatNormal;\n#endif\n vec3 vertexNormal; // interpolated mesh normal before normal mapping\n vec3 shadowOffset; // smooth-surface offset used by direct-light shadow rays\n \n vec2 uv;\n vec2 uv1;\n vec3 vertexColor;\n\n#ifdef USE_TANGENT\n vec3 tangent;\n#endif\n vec3 directionTangent;\n vec3 directionBitangent;\n vec3 geometryTangent;\n vec3 geometryBitangent;\n vec3 faceNormal; // normal of the triangle\n\n bool isTransparency;\n // For perfect specular or transmission surface\n // We use the albedo and normal of first diffuse or glossy surface hit instead for denoising\n // See albedo section in https://www.openimagedenoise.org/documentation.html\n bool albedoSampled;\n\n int triangleIndex;\n int instanceIndex;\n int materialIndex;\n\n int mediumType;\n vec3 mediumExtinction;\n vec3 mediumScattering;\n float mediumAnisotropy;\n};\n\n// Texture-resolved OpenPBR inputs used by the surface integrator. The storage\n// buffer keeps its compact legacy layout; getMaterial() is the compatibility\n// boundary that maps it to these canonical names.\nstruct OpenPbrResolvedMaterial {\n int materialType;\n\n float specularRoughness;${fragments['core0'] ?? ''}\n float baseMetalness;\n vec3 baseColor;\n float specularIor;\n vec3 emission;\n float transmissionWeight;\n bool thinWalled;\n float specularAnisotropy;\n float alpha;\n\n float transmissionDispersionScale;\n float dispersionAbbeNumber;\n float thinFilmThickness;\n float thinFilmIor;\n float thinFilmWeight;\n\n // Medium\n int mediumType;\n vec3 mediumExtinction;\n vec3 mediumScattering;\n float mediumAnisotropy;\n\n float baseWeight;\n float diffuseRoughness;\n float specularWeight;\n vec3 specularColor;\n float subsurfaceWeight;\n vec3 subsurfaceColor;\n vec3 transmissionColor;\n float fuzzWeight;\n vec3 fuzzColor;\n float fuzzRoughness;\n float coatWeight;\n vec3 coatColor;\n float coatRoughness;\n float coatAnisotropy;\n vec2 anisotropyDirection;\n bool anisotropyDirectionEnabled;\n float coatAnisotropyRotation;\n vec3 directionTangent;\n vec3 directionBitangent;\n vec3 geometryTangent;\n vec3 geometryBitangent;\n#ifdef USE_COAT_NORMAL_FRAMES\n vec3 coatNormal;\n bool coatNormalEnabled;\n vec3 geometricNormal;\n#endif\n float coatIor;\n float coatDarkening;\n\n float bevel;\n\n // Calculated\n float relativeIor;\n bool inside;\n float alphaX;\n float alphaY;\n};\n\n\nstruct Light {\n vec3 position;\n vec3 emission;\n vec3 u;\n vec3 v;\n float radius;\n float area;\n float type;\n int textureIndex;\n float spread;\n float selectionPmf;\n float selectionCdf;\n vec3 iesReference;\n};\n\nvoid initRay(inout Ray ray, vec3 origin, vec3 direction) {\n ray.o = origin;\n ray.d = direction;\n ray.tMax = RAY_MAX_DISTANCE;\n}\n\n// given the index from a 1D array, retrieve corresponding position from packed 2D texture\nivec2 unpackTexel(int i, int columnsLog2) {\n ivec2 u;\n u.y = i >> columnsLog2; // equivalent to (i / 2^columnsLog2)\n u.x = i - (u.y << columnsLog2); // equivalent to (i % 2^columnsLog2)\n return u;\n}\n\nvec4 fetchData(sampler2D s, int i, int columnsLog2) {\n return texelFetch(s, unpackTexel(i, columnsLog2), 0);\n}\n\nivec4 fetchData(highp isampler2D s, int i, int columnsLog2) {\n return texelFetch(s, unpackTexel(i, columnsLog2), 0);\n}\n\nstruct Path {\n Ray ray;\n vec3 li;\n float alpha;\n vec3 beta;\n bool fromEye;\n bool abort;\n float scatteringPdf;\n bool scatteringIsDelta;\n bool isNextRefraction;${fragments['core1'] ?? ''}\n};\n\nstruct LightSampleRec {\n vec3 normal;\n vec3 emission;\n vec3 direction;\n float dist;\n float pdf;\n bool isDelta;\n int sourceType;\n int sourceIndex;\n};\n\n\nLight fetchLight(int i) {\n int firstTexel = i * 6;\n vec4 positionAndPmf = texelFetch(\n lightsTex,\n ivec2(firstTexel, 0),\n 0\n );\n vec4 emissionAndCdf = texelFetch(\n lightsTex,\n ivec2(firstTexel + 1, 0),\n 0\n );\n vec4 tangentAndSpread = texelFetch(\n lightsTex,\n ivec2(firstTexel + 2, 0),\n 0\n );\n vec4 bitangentAndTexture = texelFetch(\n lightsTex,\n ivec2(firstTexel + 3, 0),\n 0\n );\n vec4 shape = texelFetch(\n lightsTex,\n ivec2(firstTexel + 4, 0),\n 0\n );\n return Light(\n positionAndPmf.xyz,\n emissionAndCdf.xyz,\n tangentAndSpread.xyz,\n bitangentAndTexture.xyz,\n shape.x,\n shape.y,\n shape.z,\n int(bitangentAndTexture.w),\n tangentAndSpread.w,\n positionAndPmf.w,\n emissionAndCdf.w,\n texelFetch(lightsTex, ivec2(firstTexel + 5, 0), 0).xyz\n );\n}\n\nfloat iesProfileScalar(int baseTexel, int scalarIndex) {\n int texelIndex = baseTexel + scalarIndex / 4;\n vec4 packed = texelFetch(\n iesProfileData,\n ivec2(texelIndex % iesProfileColumns, texelIndex / iesProfileColumns),\n 0\n );\n return packed[scalarIndex % 4];\n}\n\nfloat sampleIESProfile(int baseTexel, vec2 uv) {\n if (baseTexel < 0) return 1.0;\n vec2 pixel = fract(uv) * 128.0 - 0.5;\n ivec2 p0 = ivec2(floor(pixel));\n vec2 f = fract(pixel);\n int xa = p0.x < 0 ? 127 : p0.x;\n int xb = p0.x >= 127 ? 0 : p0.x + 1;\n int ya = p0.y < 0 ? 127 : p0.y;\n int yb = p0.y >= 127 ? 0 : p0.y + 1;\n float a = iesProfileScalar(baseTexel, ya * 128 + xa);\n float b = iesProfileScalar(baseTexel, ya * 128 + xb);\n float c = iesProfileScalar(baseTexel, yb * 128 + xa);\n float d = iesProfileScalar(baseTexel, yb * 128 + xb);\n return mix(mix(a, b, f.x), mix(c, d, f.x), f.y);\n}\n\nfloat evaluateSpotEmissionMultiplier(Light light, vec3 lightToSurface) {\n vec3 axis = normalize(light.u);\n float cosTheta = dot(axis, lightToSurface);\n float cone = light.v.y > light.v.x + 1e-6\n ? smoothstep(light.v.x, light.v.y, cosTheta)\n : step(light.v.x, cosTheta);\n if (cone <= 0.0 || light.textureIndex < 0) return cone;\n vec3 xAxis = light.iesReference;\n vec3 yAxis = cross(axis, xAxis);\n float vertical = acos(clamp(cosTheta, -1.0, 1.0));\n float horizontal = atan(dot(lightToSurface, yAxis), dot(lightToSurface, xAxis));\n return cone * sampleIESProfile(light.textureIndex, vec2(vertical / PI, horizontal / TWOPI + 0.5));\n}\n`\n});\n}\nexport default createRayTraceCoreGlsl();\n"]}
1
+ {"version":3,"file":"rayTraceCore.glsl.js","sourceRoot":"","sources":["../../../../src/renderer/glsl/chunks/rayTraceCore.glsl.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,sDAAsD;AACtD,kFAAkF;AAElF,OAAO,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC7E,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAE9D,MAAM,UAAU,sBAAsB,CAAC,YAA8C,EAAE;IAAI,OAAO,iBAAiB,CAAC;QAClH,QAAQ,EAAE;YACR,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC;YACtC,cAAc,EAAE,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC;YAC3C,iBAAiB,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;YAC3C,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;YACjC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;YAC9B,WAAW,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;YAClC,oBAAoB,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;SACjD;QACD,OAAO,EAAE;YACP,QAAQ,EAAE,CAAC;YACX,KAAK,EAAE,aAAa;YACpB,cAAc,EAAE,qBAAqB;YACrC,UAAU,EAAE,mBAAmB;SAChC;QACD,IAAI,EAAE,IAAI,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BA6DgB,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA6G1B,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiGjD;KACA,CAAC,CAAC;AACH,CAAC;AACD,eAAe,sBAAsB,EAAE,CAAC","sourcesContent":["// Portions adapted from ray-tracing-renderer@0.10.15\n// (https://github.com/hoverinc/ray-tracing-renderer).\n// Copyright (c) 2019 HOVER, MIT license; see LICENSES/RayTracingRenderer-MIT.txt.\n\nimport { createShaderMixin, glsl, Shader } from '../../shader.js';\nimport { ShadowCatcherMaterial, UnlitMaterial } from '../../../constants.js';\nimport { CONSTANT_SPOT_LIGHT } from '../../lightConstants.js';\n\nexport function createRayTraceCoreGlsl(fragments: Readonly<Record<string, string>> = {}) { return createShaderMixin({\n uniforms: {\n lightsTex: Shader.uniform('sampler2D'),\n iesProfileData: Shader.uniform('sampler2D'),\n iesProfileColumns: Shader.uniform('int', 1),\n pixelSize: Shader.uniform('vec2'),\n jitter: Shader.uniform('vec2'),\n sampleCount: Shader.uniform('int'),\n envLightSelectionPmf: Shader.uniform('float', 0)\n },\n defines: {\n STANDARD: 0,\n UNLIT: UnlitMaterial,\n SHADOW_CATCHER: ShadowCatcherMaterial,\n SPOT_LIGHT: CONSTANT_SPOT_LIGHT\n },\n main: glsl`\n// https://www.w3.org/WAI/GL/wiki/Relative_luminance\nconst vec3 luminance = vec3(0.2126, 0.7152, 0.0722);\nconst int bounceSamples = 8;\n\n#define RAY_MAX_DISTANCE 9999.0\n\n#define NO_UNROLL(X) (X + min(0, sampleCount))\n#define NO_UNROLLU(X) (X + uint(min(0, sampleCount)))\n\nstruct Ray {\n vec3 o;\n vec3 d;\n float tMax;\n};\n\nstruct SurfaceInteraction {\n bool hit;\n vec3 position;\n vec3 normal; // material shading normal\n#ifdef USE_COAT_NORMAL_FRAMES\n vec3 coatNormal;\n#endif\n vec3 vertexNormal; // interpolated mesh normal before normal mapping\n vec3 shadowOffset; // smooth-surface offset used by direct-light shadow rays\n \n vec2 uv;\n vec2 uv1;\n vec3 vertexColor;\n\n#ifdef USE_TANGENT\n vec3 tangent;\n#endif\n vec3 directionTangent;\n vec3 directionBitangent;\n vec3 geometryTangent;\n vec3 geometryBitangent;\n vec3 faceNormal; // normal of the triangle\n\n bool isTransparency;\n // For perfect specular or transmission surface\n // We use the albedo and normal of first diffuse or glossy surface hit instead for denoising\n // See albedo section in https://www.openimagedenoise.org/documentation.html\n bool albedoSampled;\n\n int triangleIndex;\n int instanceIndex;\n int materialIndex;\n\n int mediumType;\n vec3 mediumExtinction;\n vec3 mediumScattering;\n float mediumAnisotropy;\n};\n\n// Texture-resolved OpenPBR inputs used by the surface integrator. The storage\n// buffer keeps its compact legacy layout; getMaterial() is the compatibility\n// boundary that maps it to these canonical names.\nstruct OpenPbrResolvedMaterial {\n int materialType;\n\n float specularRoughness;${fragments['core0'] ?? ''}\n float baseMetalness;\n vec3 baseColor;\n float specularIor;\n vec3 emission;\n float transmissionWeight;\n bool thinWalled;\n float specularAnisotropy;\n float alpha;\n\n float transmissionDispersionScale;\n float dispersionAbbeNumber;\n float thinFilmThickness;\n float thinFilmIor;\n float thinFilmWeight;\n\n // Medium\n int mediumType;\n vec3 mediumExtinction;\n vec3 mediumScattering;\n float mediumAnisotropy;\n\n float baseWeight;\n float diffuseRoughness;\n float specularWeight;\n vec3 specularColor;\n float subsurfaceWeight;\n vec3 subsurfaceColor;\n vec3 transmissionColor;\n float fuzzWeight;\n vec3 fuzzColor;\n float fuzzRoughness;\n float coatWeight;\n vec3 coatColor;\n float coatRoughness;\n float coatAnisotropy;\n vec2 anisotropyDirection;\n bool anisotropyDirectionEnabled;\n float coatAnisotropyRotation;\n vec3 directionTangent;\n vec3 directionBitangent;\n vec3 geometryTangent;\n vec3 geometryBitangent;\n#ifdef USE_COAT_NORMAL_FRAMES\n vec3 coatNormal;\n bool coatNormalEnabled;\n vec3 geometricNormal;\n#endif\n float coatIor;\n float coatDarkening;\n\n float bevel;\n\n // Calculated\n float relativeIor;\n bool inside;\n float alphaX;\n float alphaY;\n};\n\n\nstruct Light {\n vec3 position;\n vec3 emission;\n vec3 u;\n vec3 v;\n float radius;\n float area;\n float type;\n int textureIndex;\n float spread;\n float selectionPmf;\n float selectionCdf;\n vec3 iesReference;\n};\n\nvoid initRay(inout Ray ray, vec3 origin, vec3 direction) {\n ray.o = origin;\n ray.d = direction;\n ray.tMax = RAY_MAX_DISTANCE;\n}\n\n// given the index from a 1D array, retrieve corresponding position from packed 2D texture\nivec2 unpackTexel(int i, int columnsLog2) {\n ivec2 u;\n u.y = i >> columnsLog2; // equivalent to (i / 2^columnsLog2)\n u.x = i - (u.y << columnsLog2); // equivalent to (i % 2^columnsLog2)\n return u;\n}\n\nvec4 fetchData(sampler2D s, int i, int columnsLog2) {\n return texelFetch(s, unpackTexel(i, columnsLog2), 0);\n}\n\nivec4 fetchData(highp isampler2D s, int i, int columnsLog2) {\n return texelFetch(s, unpackTexel(i, columnsLog2), 0);\n}\n\nstruct Path {\n // Retain deferred roulette after an SSS walk reaches its boundary.\n bool scatteringMediumEntered;\n Ray ray;\n vec3 li;\n float alpha;\n vec3 beta;\n bool fromEye;\n bool abort;\n float scatteringPdf;\n bool scatteringIsDelta;\n bool isNextRefraction;${fragments['core1'] ?? ''}\n};\n\nstruct LightSampleRec {\n vec3 normal;\n vec3 emission;\n vec3 direction;\n float dist;\n float pdf;\n bool isDelta;\n int sourceType;\n int sourceIndex;\n};\n\n\nLight fetchLight(int i) {\n int firstTexel = i * 6;\n vec4 positionAndPmf = texelFetch(\n lightsTex,\n ivec2(firstTexel, 0),\n 0\n );\n vec4 emissionAndCdf = texelFetch(\n lightsTex,\n ivec2(firstTexel + 1, 0),\n 0\n );\n vec4 tangentAndSpread = texelFetch(\n lightsTex,\n ivec2(firstTexel + 2, 0),\n 0\n );\n vec4 bitangentAndTexture = texelFetch(\n lightsTex,\n ivec2(firstTexel + 3, 0),\n 0\n );\n vec4 shape = texelFetch(\n lightsTex,\n ivec2(firstTexel + 4, 0),\n 0\n );\n return Light(\n positionAndPmf.xyz,\n emissionAndCdf.xyz,\n tangentAndSpread.xyz,\n bitangentAndTexture.xyz,\n shape.x,\n shape.y,\n shape.z,\n int(bitangentAndTexture.w),\n tangentAndSpread.w,\n positionAndPmf.w,\n emissionAndCdf.w,\n texelFetch(lightsTex, ivec2(firstTexel + 5, 0), 0).xyz\n );\n}\n\nfloat iesProfileScalar(int baseTexel, int scalarIndex) {\n int texelIndex = baseTexel + scalarIndex / 4;\n vec4 packed = texelFetch(\n iesProfileData,\n ivec2(texelIndex % iesProfileColumns, texelIndex / iesProfileColumns),\n 0\n );\n return packed[scalarIndex % 4];\n}\n\nfloat sampleIESProfile(int baseTexel, vec2 uv) {\n if (baseTexel < 0) return 1.0;\n vec2 pixel = fract(uv) * 128.0 - 0.5;\n ivec2 p0 = ivec2(floor(pixel));\n vec2 f = fract(pixel);\n int xa = p0.x < 0 ? 127 : p0.x;\n int xb = p0.x >= 127 ? 0 : p0.x + 1;\n int ya = p0.y < 0 ? 127 : p0.y;\n int yb = p0.y >= 127 ? 0 : p0.y + 1;\n float a = iesProfileScalar(baseTexel, ya * 128 + xa);\n float b = iesProfileScalar(baseTexel, ya * 128 + xb);\n float c = iesProfileScalar(baseTexel, yb * 128 + xa);\n float d = iesProfileScalar(baseTexel, yb * 128 + xb);\n return mix(mix(a, b, f.x), mix(c, d, f.x), f.y);\n}\n\nfloat evaluateSpotEmissionMultiplier(Light light, vec3 lightToSurface) {\n vec3 axis = normalize(light.u);\n float cosTheta = dot(axis, lightToSurface);\n float cone = light.v.y > light.v.x + 1e-6\n ? smoothstep(light.v.x, light.v.y, cosTheta)\n : step(light.v.x, cosTheta);\n if (cone <= 0.0 || light.textureIndex < 0) return cone;\n vec3 xAxis = light.iesReference;\n vec3 yAxis = cross(axis, xAxis);\n float vertical = acos(clamp(cosTheta, -1.0, 1.0));\n float horizontal = atan(dot(lightToSurface, yAxis), dot(lightToSurface, xAxis));\n return cone * sampleIESProfile(light.textureIndex, vec2(vertical / PI, horizontal / TWOPI + 0.5));\n}\n`\n});\n}\nexport default createRayTraceCoreGlsl();\n"]}
@@ -2,14 +2,14 @@ import emissive from './emissiveLight.glsl.js';
2
2
  import { glsl } from '../../shader.js';
3
3
  export default glsl `
4
4
  #ifdef NUM_LIGHTS
5
- void eH(
5
+ void eR(
6
6
  in Light light,
7
7
  in vec3 shadingPoint,
8
8
  in vec2 samplePoint,
9
9
  inout LightSampleRec result
10
10
  ) {
11
- vec3 oC = light.position - shadingPoint;
12
- float ao = length(oC);
11
+ vec3 pH = light.position - shadingPoint;
12
+ float ao = length(pH);
13
13
  if (light.radius <= 0.0) {
14
14
  if (ao <= 1e-6) {
15
15
  result.direction = vec3(0.0, 0.0, 1.0);
@@ -20,7 +20,7 @@ result.emission = vec3(0.0);
20
20
  result.isDelta = true;
21
21
  return;
22
22
  }
23
- result.direction = oC / ao;
23
+ result.direction = pH / ao;
24
24
  result.normal = -result.direction;
25
25
  result.dist = ao;
26
26
  result.pdf = 1.0;
@@ -29,57 +29,53 @@ result.isDelta = true;
29
29
  return;
30
30
  }
31
31
  float radius = max(light.radius, 1e-6);
32
- #ifdef HAS_EMISSIVE_LIGHTS
33
- jb(shadingPoint,randomSampleValue,result);return;
34
- #endif
35
- result.sourceType=0;result.sourceIndex=-1;
36
32
  result.isDelta = false;
37
33
  vec3 direction;
38
34
 
39
35
  if (ao <= radius) {
40
36
  float z = 1.0 - 2.0 * samplePoint.x;
41
- float dr = sqrt(max(0.0, 1.0 - z * z));
37
+ float dw = sqrt(max(0.0, 1.0 - z * z));
42
38
  float azimuth = TWOPI * samplePoint.y;
43
- direction = vec3(dr * cos(azimuth), dr * sin(azimuth), z);
39
+ direction = vec3(dw * cos(azimuth), dw * sin(azimuth), z);
44
40
  result.pdf = INV4PI;
45
41
  }
46
42
  else {
47
- vec3 axis = oC / ao;
48
- float oz = min(
43
+ vec3 axis = pH / ao;
44
+ float pv = min(
49
45
  1.0,
50
46
  radius * radius / (ao * ao)
51
47
  );
52
- float vA = sqrt(max(0.0, 1.0 - oz));
48
+ float xn = sqrt(max(0.0, 1.0 - pv));
53
49
 
54
50
 
55
- float mf = oz / (1.0 + vA);
56
- float ng = samplePoint.x * mf;
57
- float cosine = 1.0 - ng;
58
- float uC = sqrt(max(0.0, ng * (2.0 - ng)));
51
+ float mX = pv / (1.0 + xn);
52
+ float oe = samplePoint.x * mX;
53
+ float cosine = 1.0 - oe;
54
+ float wk = sqrt(max(0.0, oe * (2.0 - oe)));
59
55
  float azimuth = TWOPI * samplePoint.y;
60
56
  vec3 tangent;
61
57
  vec3 bitangent;
62
58
  sampling_orthonormal_basis(axis, tangent, bitangent);
63
59
  direction = axis * cosine
64
- + tangent * (uC * cos(azimuth))
65
- + bitangent * (uC * sin(azimuth));
66
- result.pdf = 1.0 / max(TWOPI * mf, 1e-8);
60
+ + tangent * (wk * cos(azimuth))
61
+ + bitangent * (wk * sin(azimuth));
62
+ result.pdf = 1.0 / max(TWOPI * mX, 1e-8);
67
63
  }
68
64
 
69
- float ji = dot(direction, oC);
70
- float bj = ji * ji
71
- - dot(oC, oC) + radius * radius;
72
- float root = sqrt(max(0.0, bj));
73
- float cI = ji - root;
74
- float cw = ji + root;
75
- result.dist = cI > 1e-6 ? cI : cw;
65
+ float jM = dot(direction, pH);
66
+ float bk = jM * jM
67
+ - dot(pH, pH) + radius * radius;
68
+ float root = sqrt(max(0.0, bk));
69
+ float cK = jM - root;
70
+ float cB = jM + root;
71
+ result.dist = cK > 1e-6 ? cK : cB;
76
72
  result.direction = direction;
77
73
  vec3 surfacePoint = shadingPoint + direction * result.dist;
78
74
  result.normal = normalize(surfacePoint - light.position);
79
75
  result.emission = light.emission;
80
76
  }
81
77
 
82
- void bC(
78
+ void bD(
83
79
  in Light light,
84
80
  in vec3 surfacePoint,
85
81
  in vec3 lowerLeft,
@@ -89,17 +85,17 @@ inout LightSampleRec result
89
85
  if (light.textureIndex >= 0) {
90
86
  float width = length(light.u);
91
87
  float height = length(light.v);
92
- vec3 dU = surfacePoint - lowerLeft;
88
+ vec3 ea = surfacePoint - lowerLeft;
93
89
  vec2 uv = vec2(
94
- dot(dU, light.u / width) / width,
95
- dot(dU, light.v / height) / height
90
+ dot(ea, light.u / width) / width,
91
+ dot(ea, light.v / height) / height
96
92
  );
97
93
  result.emission *= sampleMap(light.textureIndex, uv).rgb;
98
94
  }
99
95
  #endif
100
96
  }
101
97
 
102
- void jZ(
98
+ void kF(
103
99
  in Light light,
104
100
  in vec3 shadingPoint,
105
101
  in vec2 samplePoint,
@@ -110,28 +106,28 @@ vec3 lowerLeft = light.position - 0.5 * (light.u + light.v);
110
106
  float spread = clamp(light.spread, 0.0, 1.0);
111
107
 
112
108
  if (spread <= 0.001) {
113
- float gg = dot(normal, shadingPoint - light.position);
114
- vec3 surfacePoint = shadingPoint - normal * gg;
115
- vec3 dU = surfacePoint - lowerLeft;
109
+ float gy = dot(normal, shadingPoint - light.position);
110
+ vec3 surfacePoint = shadingPoint - normal * gy;
111
+ vec3 ea = surfacePoint - lowerLeft;
116
112
  float width = length(light.u);
117
113
  float height = length(light.v);
118
114
  vec2 uv = vec2(
119
- dot(dU, light.u / width) / width,
120
- dot(dU, light.v / height) / height
115
+ dot(ea, light.u / width) / width,
116
+ dot(ea, light.v / height) / height
121
117
  );
122
- if (gg <= 0.0 || any(lessThan(uv, vec2(0.0)))
118
+ if (gy <= 0.0 || any(lessThan(uv, vec2(0.0)))
123
119
  || any(greaterThan(uv, vec2(1.0)))) {
124
120
  result.emission = vec3(0.0);
125
121
  result.pdf = 0.0;
126
122
  return;
127
123
  }
128
124
  result.direction = -normal;
129
- result.dist = gg;
125
+ result.dist = gy;
130
126
  result.normal = normal;
131
127
  result.emission = light.emission;
132
128
  result.pdf = 1.0;
133
129
  result.isDelta = true;
134
- bC(light, surfacePoint, lowerLeft, result);
130
+ bD(light, surfacePoint, lowerLeft, result);
135
131
  return;
136
132
  }
137
133
 
@@ -143,19 +139,19 @@ float bG = dot(offset, offset);
143
139
  result.dist = sqrt(bG);
144
140
  result.direction = offset / result.dist;
145
141
  result.normal = normal;
146
- float fY = dot(-result.direction, normal);
147
- float pp = cos(0.5 * PI * spread);
148
- if (fY <= 0.0 || fY < pp) {
142
+ float gq = dot(-result.direction, normal);
143
+ float qB = cos(0.5 * PI * spread);
144
+ if (gq <= 0.0 || gq < qB) {
149
145
  result.emission = vec3(0.0);
150
146
  result.pdf = 0.0;
151
147
  return;
152
148
  }
153
149
  result.emission = light.emission;
154
- result.pdf = bG / max(light.area * fY, 1e-8);
155
- bC(light, surfacePoint, lowerLeft, result);
150
+ result.pdf = bG / max(light.area * gq, 1e-8);
151
+ bD(light, surfacePoint, lowerLeft, result);
156
152
  }
157
153
 
158
- void gc(
154
+ void gs(
159
155
  in Light light,
160
156
  in vec3 shadingPoint,
161
157
  inout LightSampleRec result
@@ -168,13 +164,13 @@ result.pdf = 1.0;
168
164
  result.isDelta = true;
169
165
  }
170
166
 
171
- void ka(
167
+ void kG(
172
168
  in Light light,
173
169
  in vec3 shadingPoint,
174
170
  in vec2 samplePoint,
175
171
  inout LightSampleRec result
176
172
  ) {
177
- eH(light, shadingPoint, samplePoint, result);
173
+ eR(light, shadingPoint, samplePoint, result);
178
174
  vec3 surfacePoint = shadingPoint + result.direction * result.dist;
179
175
  result.emission *= evaluateSpotEmissionMultiplier(
180
176
  light,
@@ -188,36 +184,36 @@ in vec3 shadingPoint,
188
184
  in vec2 samplePoint,
189
185
  inout LightSampleRec result
190
186
  ) {
191
- int dO = int(light.type);
187
+ int dU = int(light.type);
192
188
  #ifdef HAS_RECT_LIGHTS
193
- if (dO == RECT_LIGHT) {
194
- jZ(light, shadingPoint, samplePoint, result);
189
+ if (dU == RECT_LIGHT) {
190
+ kF(light, shadingPoint, samplePoint, result);
195
191
  return;
196
192
  }
197
193
  #endif
198
194
  #ifdef HAS_SPHERE_LIGHTS
199
- if (dO == SPHERE_LIGHT) {
200
- eH(light, shadingPoint, samplePoint, result);
195
+ if (dU == SPHERE_LIGHT) {
196
+ eR(light, shadingPoint, samplePoint, result);
201
197
  return;
202
198
  }
203
199
  #endif
204
200
  #ifdef HAS_SPOT_LIGHTS
205
- if (dO == SPOT_LIGHT) {
206
- ka(light, shadingPoint, samplePoint, result);
201
+ if (dU == SPOT_LIGHT) {
202
+ kG(light, shadingPoint, samplePoint, result);
207
203
  return;
208
204
  }
209
205
  #endif
210
206
  #ifdef HAS_DIRECTIONAL_LIGHTS
211
- if (dO == DIRECTIONAL_LIGHT) {
212
- gc(light, shadingPoint, result);
207
+ if (dU == DIRECTIONAL_LIGHT) {
208
+ gs(light, shadingPoint, result);
213
209
  }
214
210
  #endif
215
211
  }
216
212
  #endif
217
213
 
218
- void ig(in vec2 samplePoint, inout LightSampleRec result) {
214
+ void iM(in vec2 samplePoint, inout LightSampleRec result) {
219
215
  vec2 uv;
220
- result.direction = pn(samplePoint, uv, result.pdf);
216
+ result.direction = qx(samplePoint, uv, result.pdf);
221
217
  result.emission = textureLinear(envMap, uv).rgb;
222
218
  result.dist = INF;
223
219
  }
@@ -230,41 +226,41 @@ void sampleLight(
230
226
  in vec3 shadingPoint,
231
227
  in vec3 randomSampleValue,
232
228
  inout LightSampleRec result,
233
- bool tk
229
+ bool uP
234
230
  ) {
235
231
  #ifdef HAS_EMISSIVE_LIGHTS
236
- jb(shadingPoint,randomSampleValue,result);return;
232
+ pc(shadingPoint,randomSampleValue,result);return;
237
233
  #endif
238
234
  result.sourceType=0;result.sourceIndex=-1;
239
235
  result.isDelta = false;
240
- float vP = randomSampleValue.z;
241
- bool kN = false;
236
+ float xJ = randomSampleValue.z;
237
+ bool lG = false;
242
238
  #ifdef USE_ENVMAP
243
- kN = vP < envLightSelectionPmf;
244
- if (kN) {
245
- ig(randomSampleValue.xy, result);
239
+ lG = xJ < envLightSelectionPmf;
240
+ if (lG) {
241
+ iM(randomSampleValue.xy, result);
246
242
  result.pdf *= envLightSelectionPmf;
247
243
  }
248
244
  #endif
249
245
 
250
246
  #ifdef NUM_LIGHTS
251
- if (!kN) {
252
- int jc = NUM_LIGHTS - 1;
247
+ if (!lG) {
248
+ int jG = NUM_LIGHTS - 1;
253
249
  for (int index = 0; index < NUM_LIGHTS; index++) {
254
- if (vP < fetchLight(index).selectionCdf) {
255
- jc = index;
250
+ if (xJ < fetchLight(index).selectionCdf) {
251
+ jG = index;
256
252
  break;
257
253
  }
258
254
  }
259
- result.sourceType=2;result.sourceIndex=jc;
260
- Light rh = fetchLight(jc);
255
+ result.sourceType=2;result.sourceIndex=jG;
256
+ Light sz = fetchLight(jG);
261
257
  sampleAnalyticLight(
262
- rh,
258
+ sz,
263
259
  shadingPoint,
264
260
  randomSampleValue.xy,
265
261
  result
266
262
  );
267
- result.pdf *= rh.selectionPmf;
263
+ result.pdf *= sz.selectionPmf;
268
264
  }
269
265
  #endif
270
266
  }
@@ -1 +1 @@
1
- {"version":3,"file":"sampleLight.glsl.js","sourceRoot":"","sources":["../../../../src/renderer/glsl/chunks/sampleLight.glsl.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEvC,eAAe,IAAI,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+NjB,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6CT,CAAC","sourcesContent":["import emissive from './emissiveLight.glsl.js';\nimport { glsl } from '../../shader.js';\n\nexport default glsl`\n#ifdef NUM_LIGHTS\nvoid light_sample_sphere(\n in Light light,\n in vec3 shadingPoint,\n in vec2 samplePoint,\n inout LightSampleRec result\n) {\n vec3 toCenter = light.position - shadingPoint;\n float centerDistance = length(toCenter);\n if (light.radius <= 0.0) {\n if (centerDistance <= 1e-6) {\n result.direction = vec3(0.0, 0.0, 1.0);\n result.normal = vec3(0.0, 0.0, -1.0);\n result.dist = 0.0;\n result.pdf = 1.0;\n result.emission = vec3(0.0);\n result.isDelta = true;\n return;\n }\n result.direction = toCenter / centerDistance;\n result.normal = -result.direction;\n result.dist = centerDistance;\n result.pdf = 1.0;\n result.emission = light.emission / max(centerDistance * centerDistance, 1e-8);\n result.isDelta = true;\n return;\n }\n float radius = max(light.radius, 1e-6);\n#ifdef HAS_EMISSIVE_LIGHTS\n sampleEmissiveSceneLight(shadingPoint,randomSampleValue,result);return;\n#endif\n result.sourceType=0;result.sourceIndex=-1;\n result.isDelta = false;\n vec3 direction;\n\n if (centerDistance <= radius) {\n float z = 1.0 - 2.0 * samplePoint.x;\n float radial = sqrt(max(0.0, 1.0 - z * z));\n float azimuth = TWOPI * samplePoint.y;\n direction = vec3(radial * cos(azimuth), radial * sin(azimuth), z);\n result.pdf = INV4PI;\n }\n else {\n vec3 axis = toCenter / centerDistance;\n float sineLimitSquared = min(\n 1.0,\n radius * radius / (centerDistance * centerDistance)\n );\n float cosineLimit = sqrt(max(0.0, 1.0 - sineLimitSquared));\n // Keep the small solid angle and sampled sine without subtracting\n // nearly equal floats; otherwise small emitters produce irradiance bands.\n float oneMinusCosineLimit = sineLimitSquared / (1.0 + cosineLimit);\n float oneMinusCosine = samplePoint.x * oneMinusCosineLimit;\n float cosine = 1.0 - oneMinusCosine;\n float sine = sqrt(max(0.0, oneMinusCosine * (2.0 - oneMinusCosine)));\n float azimuth = TWOPI * samplePoint.y;\n vec3 tangent;\n vec3 bitangent;\n sampling_orthonormal_basis(axis, tangent, bitangent);\n direction = axis * cosine\n + tangent * (sine * cos(azimuth))\n + bitangent * (sine * sin(azimuth));\n result.pdf = 1.0 / max(TWOPI * oneMinusCosineLimit, 1e-8);\n }\n\n float projectedCenter = dot(direction, toCenter);\n float discriminant = projectedCenter * projectedCenter\n - dot(toCenter, toCenter) + radius * radius;\n float root = sqrt(max(0.0, discriminant));\n float nearDistance = projectedCenter - root;\n float farDistance = projectedCenter + root;\n result.dist = nearDistance > 1e-6 ? nearDistance : farDistance;\n result.direction = direction;\n vec3 surfacePoint = shadingPoint + direction * result.dist;\n result.normal = normalize(surfacePoint - light.position);\n result.emission = light.emission;\n}\n\nvoid light_apply_rect_texture(\n in Light light,\n in vec3 surfacePoint,\n in vec3 lowerLeft,\n inout LightSampleRec result\n) {\n#ifdef NUM_MAPS\n if (light.textureIndex >= 0) {\n float width = length(light.u);\n float height = length(light.v);\n vec3 relative = surfacePoint - lowerLeft;\n vec2 uv = vec2(\n dot(relative, light.u / width) / width,\n dot(relative, light.v / height) / height\n );\n result.emission *= sampleMap(light.textureIndex, uv).rgb;\n }\n#endif\n}\n\nvoid light_sample_rect(\n in Light light,\n in vec3 shadingPoint,\n in vec2 samplePoint,\n inout LightSampleRec result\n) {\n vec3 normal = normalize(cross(light.u, light.v));\n vec3 lowerLeft = light.position - 0.5 * (light.u + light.v);\n float spread = clamp(light.spread, 0.0, 1.0);\n\n if (spread <= 0.001) {\n float planeDistance = dot(normal, shadingPoint - light.position);\n vec3 surfacePoint = shadingPoint - normal * planeDistance;\n vec3 relative = surfacePoint - lowerLeft;\n float width = length(light.u);\n float height = length(light.v);\n vec2 uv = vec2(\n dot(relative, light.u / width) / width,\n dot(relative, light.v / height) / height\n );\n if (planeDistance <= 0.0 || any(lessThan(uv, vec2(0.0)))\n || any(greaterThan(uv, vec2(1.0)))) {\n result.emission = vec3(0.0);\n result.pdf = 0.0;\n return;\n }\n result.direction = -normal;\n result.dist = planeDistance;\n result.normal = normal;\n result.emission = light.emission;\n result.pdf = 1.0;\n result.isDelta = true;\n light_apply_rect_texture(light, surfacePoint, lowerLeft, result);\n return;\n }\n\n vec3 surfacePoint = lowerLeft\n + light.u * samplePoint.x\n + light.v * samplePoint.y;\n vec3 offset = surfacePoint - shadingPoint;\n float distanceSquared = dot(offset, offset);\n result.dist = sqrt(distanceSquared);\n result.direction = offset / result.dist;\n result.normal = normal;\n float emitterCosine = dot(-result.direction, normal);\n float spreadCosine = cos(0.5 * PI * spread);\n if (emitterCosine <= 0.0 || emitterCosine < spreadCosine) {\n result.emission = vec3(0.0);\n result.pdf = 0.0;\n return;\n }\n result.emission = light.emission;\n result.pdf = distanceSquared / max(light.area * emitterCosine, 1e-8);\n light_apply_rect_texture(light, surfacePoint, lowerLeft, result);\n}\n\nvoid light_sample_directional(\n in Light light,\n in vec3 shadingPoint,\n inout LightSampleRec result\n) {\n result.direction = normalize(-light.u);\n result.normal = -result.direction;\n result.emission = light.emission;\n result.dist = INF;\n result.pdf = 1.0;\n result.isDelta = true;\n}\n\nvoid light_sample_spot(\n in Light light,\n in vec3 shadingPoint,\n in vec2 samplePoint,\n inout LightSampleRec result\n) {\n light_sample_sphere(light, shadingPoint, samplePoint, result);\n vec3 surfacePoint = shadingPoint + result.direction * result.dist;\n result.emission *= evaluateSpotEmissionMultiplier(\n light,\n normalize(shadingPoint - surfacePoint)\n );\n}\n\nvoid sampleAnalyticLight(\n in Light light,\n in vec3 shadingPoint,\n in vec2 samplePoint,\n inout LightSampleRec result\n) {\n int lightType = int(light.type);\n#ifdef HAS_RECT_LIGHTS\n if (lightType == RECT_LIGHT) {\n light_sample_rect(light, shadingPoint, samplePoint, result);\n return;\n }\n#endif\n#ifdef HAS_SPHERE_LIGHTS\n if (lightType == SPHERE_LIGHT) {\n light_sample_sphere(light, shadingPoint, samplePoint, result);\n return;\n }\n#endif\n#ifdef HAS_SPOT_LIGHTS\n if (lightType == SPOT_LIGHT) {\n light_sample_spot(light, shadingPoint, samplePoint, result);\n return;\n }\n#endif\n#ifdef HAS_DIRECTIONAL_LIGHTS\n if (lightType == DIRECTIONAL_LIGHT) {\n light_sample_directional(light, shadingPoint, result);\n }\n#endif\n}\n#endif\n\nvoid sampleEnvLight(in vec2 samplePoint, inout LightSampleRec result) {\n vec2 uv;\n result.direction = sampleEnvmap(samplePoint, uv, result.pdf);\n result.emission = textureLinear(envMap, uv).rgb;\n result.dist = INF;\n}\n\n#ifdef HAS_EMISSIVE_LIGHTS\n${emissive}\n#endif\n\nvoid sampleLight(\n in vec3 shadingPoint,\n in vec3 randomSampleValue,\n inout LightSampleRec result,\n bool distByIntensity\n) {\n#ifdef HAS_EMISSIVE_LIGHTS\n sampleEmissiveSceneLight(shadingPoint,randomSampleValue,result);return;\n#endif\n result.sourceType=0;result.sourceIndex=-1;\n result.isDelta = false;\n float selector = randomSampleValue.z;\n bool choseEnvironment = false;\n#ifdef USE_ENVMAP\n choseEnvironment = selector < envLightSelectionPmf;\n if (choseEnvironment) {\n sampleEnvLight(randomSampleValue.xy, result);\n result.pdf *= envLightSelectionPmf;\n }\n#endif\n\n#ifdef NUM_LIGHTS\n if (!choseEnvironment) {\n int selectedIndex = NUM_LIGHTS - 1;\n for (int index = 0; index < NUM_LIGHTS; index++) {\n if (selector < fetchLight(index).selectionCdf) {\n selectedIndex = index;\n break;\n }\n }\n result.sourceType=2;result.sourceIndex=selectedIndex;\n Light selectedLight = fetchLight(selectedIndex);\n sampleAnalyticLight(\n selectedLight,\n shadingPoint,\n randomSampleValue.xy,\n result\n );\n result.pdf *= selectedLight.selectionPmf;\n }\n#endif\n}\n`;\n"]}
1
+ {"version":3,"file":"sampleLight.glsl.js","sourceRoot":"","sources":["../../../../src/renderer/glsl/chunks/sampleLight.glsl.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEvC,eAAe,IAAI,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2NjB,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6CT,CAAC","sourcesContent":["import emissive from './emissiveLight.glsl.js';\nimport { glsl } from '../../shader.js';\n\nexport default glsl`\n#ifdef NUM_LIGHTS\nvoid light_sample_sphere(\n in Light light,\n in vec3 shadingPoint,\n in vec2 samplePoint,\n inout LightSampleRec result\n) {\n vec3 toCenter = light.position - shadingPoint;\n float centerDistance = length(toCenter);\n if (light.radius <= 0.0) {\n if (centerDistance <= 1e-6) {\n result.direction = vec3(0.0, 0.0, 1.0);\n result.normal = vec3(0.0, 0.0, -1.0);\n result.dist = 0.0;\n result.pdf = 1.0;\n result.emission = vec3(0.0);\n result.isDelta = true;\n return;\n }\n result.direction = toCenter / centerDistance;\n result.normal = -result.direction;\n result.dist = centerDistance;\n result.pdf = 1.0;\n result.emission = light.emission / max(centerDistance * centerDistance, 1e-8);\n result.isDelta = true;\n return;\n }\n float radius = max(light.radius, 1e-6);\n result.isDelta = false;\n vec3 direction;\n\n if (centerDistance <= radius) {\n float z = 1.0 - 2.0 * samplePoint.x;\n float radial = sqrt(max(0.0, 1.0 - z * z));\n float azimuth = TWOPI * samplePoint.y;\n direction = vec3(radial * cos(azimuth), radial * sin(azimuth), z);\n result.pdf = INV4PI;\n }\n else {\n vec3 axis = toCenter / centerDistance;\n float sineLimitSquared = min(\n 1.0,\n radius * radius / (centerDistance * centerDistance)\n );\n float cosineLimit = sqrt(max(0.0, 1.0 - sineLimitSquared));\n // Keep the small solid angle and sampled sine without subtracting\n // nearly equal floats; otherwise small emitters produce irradiance bands.\n float oneMinusCosineLimit = sineLimitSquared / (1.0 + cosineLimit);\n float oneMinusCosine = samplePoint.x * oneMinusCosineLimit;\n float cosine = 1.0 - oneMinusCosine;\n float sine = sqrt(max(0.0, oneMinusCosine * (2.0 - oneMinusCosine)));\n float azimuth = TWOPI * samplePoint.y;\n vec3 tangent;\n vec3 bitangent;\n sampling_orthonormal_basis(axis, tangent, bitangent);\n direction = axis * cosine\n + tangent * (sine * cos(azimuth))\n + bitangent * (sine * sin(azimuth));\n result.pdf = 1.0 / max(TWOPI * oneMinusCosineLimit, 1e-8);\n }\n\n float projectedCenter = dot(direction, toCenter);\n float discriminant = projectedCenter * projectedCenter\n - dot(toCenter, toCenter) + radius * radius;\n float root = sqrt(max(0.0, discriminant));\n float nearDistance = projectedCenter - root;\n float farDistance = projectedCenter + root;\n result.dist = nearDistance > 1e-6 ? nearDistance : farDistance;\n result.direction = direction;\n vec3 surfacePoint = shadingPoint + direction * result.dist;\n result.normal = normalize(surfacePoint - light.position);\n result.emission = light.emission;\n}\n\nvoid light_apply_rect_texture(\n in Light light,\n in vec3 surfacePoint,\n in vec3 lowerLeft,\n inout LightSampleRec result\n) {\n#ifdef NUM_MAPS\n if (light.textureIndex >= 0) {\n float width = length(light.u);\n float height = length(light.v);\n vec3 relative = surfacePoint - lowerLeft;\n vec2 uv = vec2(\n dot(relative, light.u / width) / width,\n dot(relative, light.v / height) / height\n );\n result.emission *= sampleMap(light.textureIndex, uv).rgb;\n }\n#endif\n}\n\nvoid light_sample_rect(\n in Light light,\n in vec3 shadingPoint,\n in vec2 samplePoint,\n inout LightSampleRec result\n) {\n vec3 normal = normalize(cross(light.u, light.v));\n vec3 lowerLeft = light.position - 0.5 * (light.u + light.v);\n float spread = clamp(light.spread, 0.0, 1.0);\n\n if (spread <= 0.001) {\n float planeDistance = dot(normal, shadingPoint - light.position);\n vec3 surfacePoint = shadingPoint - normal * planeDistance;\n vec3 relative = surfacePoint - lowerLeft;\n float width = length(light.u);\n float height = length(light.v);\n vec2 uv = vec2(\n dot(relative, light.u / width) / width,\n dot(relative, light.v / height) / height\n );\n if (planeDistance <= 0.0 || any(lessThan(uv, vec2(0.0)))\n || any(greaterThan(uv, vec2(1.0)))) {\n result.emission = vec3(0.0);\n result.pdf = 0.0;\n return;\n }\n result.direction = -normal;\n result.dist = planeDistance;\n result.normal = normal;\n result.emission = light.emission;\n result.pdf = 1.0;\n result.isDelta = true;\n light_apply_rect_texture(light, surfacePoint, lowerLeft, result);\n return;\n }\n\n vec3 surfacePoint = lowerLeft\n + light.u * samplePoint.x\n + light.v * samplePoint.y;\n vec3 offset = surfacePoint - shadingPoint;\n float distanceSquared = dot(offset, offset);\n result.dist = sqrt(distanceSquared);\n result.direction = offset / result.dist;\n result.normal = normal;\n float emitterCosine = dot(-result.direction, normal);\n float spreadCosine = cos(0.5 * PI * spread);\n if (emitterCosine <= 0.0 || emitterCosine < spreadCosine) {\n result.emission = vec3(0.0);\n result.pdf = 0.0;\n return;\n }\n result.emission = light.emission;\n result.pdf = distanceSquared / max(light.area * emitterCosine, 1e-8);\n light_apply_rect_texture(light, surfacePoint, lowerLeft, result);\n}\n\nvoid light_sample_directional(\n in Light light,\n in vec3 shadingPoint,\n inout LightSampleRec result\n) {\n result.direction = normalize(-light.u);\n result.normal = -result.direction;\n result.emission = light.emission;\n result.dist = INF;\n result.pdf = 1.0;\n result.isDelta = true;\n}\n\nvoid light_sample_spot(\n in Light light,\n in vec3 shadingPoint,\n in vec2 samplePoint,\n inout LightSampleRec result\n) {\n light_sample_sphere(light, shadingPoint, samplePoint, result);\n vec3 surfacePoint = shadingPoint + result.direction * result.dist;\n result.emission *= evaluateSpotEmissionMultiplier(\n light,\n normalize(shadingPoint - surfacePoint)\n );\n}\n\nvoid sampleAnalyticLight(\n in Light light,\n in vec3 shadingPoint,\n in vec2 samplePoint,\n inout LightSampleRec result\n) {\n int lightType = int(light.type);\n#ifdef HAS_RECT_LIGHTS\n if (lightType == RECT_LIGHT) {\n light_sample_rect(light, shadingPoint, samplePoint, result);\n return;\n }\n#endif\n#ifdef HAS_SPHERE_LIGHTS\n if (lightType == SPHERE_LIGHT) {\n light_sample_sphere(light, shadingPoint, samplePoint, result);\n return;\n }\n#endif\n#ifdef HAS_SPOT_LIGHTS\n if (lightType == SPOT_LIGHT) {\n light_sample_spot(light, shadingPoint, samplePoint, result);\n return;\n }\n#endif\n#ifdef HAS_DIRECTIONAL_LIGHTS\n if (lightType == DIRECTIONAL_LIGHT) {\n light_sample_directional(light, shadingPoint, result);\n }\n#endif\n}\n#endif\n\nvoid sampleEnvLight(in vec2 samplePoint, inout LightSampleRec result) {\n vec2 uv;\n result.direction = sampleEnvmap(samplePoint, uv, result.pdf);\n result.emission = textureLinear(envMap, uv).rgb;\n result.dist = INF;\n}\n\n#ifdef HAS_EMISSIVE_LIGHTS\n${emissive}\n#endif\n\nvoid sampleLight(\n in vec3 shadingPoint,\n in vec3 randomSampleValue,\n inout LightSampleRec result,\n bool distByIntensity\n) {\n#ifdef HAS_EMISSIVE_LIGHTS\n sampleEmissiveSceneLight(shadingPoint,randomSampleValue,result);return;\n#endif\n result.sourceType=0;result.sourceIndex=-1;\n result.isDelta = false;\n float selector = randomSampleValue.z;\n bool choseEnvironment = false;\n#ifdef USE_ENVMAP\n choseEnvironment = selector < envLightSelectionPmf;\n if (choseEnvironment) {\n sampleEnvLight(randomSampleValue.xy, result);\n result.pdf *= envLightSelectionPmf;\n }\n#endif\n\n#ifdef NUM_LIGHTS\n if (!choseEnvironment) {\n int selectedIndex = NUM_LIGHTS - 1;\n for (int index = 0; index < NUM_LIGHTS; index++) {\n if (selector < fetchLight(index).selectionCdf) {\n selectedIndex = index;\n break;\n }\n }\n result.sourceType=2;result.sourceIndex=selectedIndex;\n Light selectedLight = fetchLight(selectedIndex);\n sampleAnalyticLight(\n selectedLight,\n shadingPoint,\n randomSampleValue.xy,\n result\n );\n result.pdf *= selectedLight.selectionPmf;\n }\n#endif\n}\n`;\n"]}
@@ -1,3 +1,3 @@
1
- export declare function createSampleMaterialGlsl(fragments?: Readonly<Record<string, string>>): string;
1
+ export declare function createSampleMaterialGlsl(fragments?: Readonly<Record<string, string>>, channelIndependentLight?: boolean): string;
2
2
  declare const _default: string;
3
3
  export default _default;