@meimu/mutracer 0.1.3 → 0.1.5

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 (125) hide show
  1. package/dist/assets/bvh.worker.js +1 -1
  2. package/dist/mutracer.umd.js +4155 -4052
  3. package/docs/api.md +13 -10
  4. package/docs/materials.md +17 -26
  5. package/docs/threejs.md +35 -9
  6. package/docs/viewer.md +36 -3
  7. package/lib/Engine.js +18 -1
  8. package/lib/Engine.js.map +1 -1
  9. package/lib/main.d.ts +1 -1
  10. package/lib/main.js.map +1 -1
  11. package/lib/oidn.d.ts +1 -1
  12. package/lib/oidnBundledWeights.cdn.d.ts +2 -2
  13. package/lib/renderer/MaterialTable.d.ts +1 -0
  14. package/lib/renderer/MaterialTable.js +10 -4
  15. package/lib/renderer/MaterialTable.js.map +1 -1
  16. package/lib/renderer/WGPUBloomPass.js +18 -18
  17. package/lib/renderer/WGPUFullQuadPass.js +6 -6
  18. package/lib/renderer/WGPUJNLMDenoiser.js +69 -69
  19. package/lib/renderer/WGPURayTraceOutput.js +14 -14
  20. package/lib/renderer/WGPURayTracePass.d.ts +2 -0
  21. package/lib/renderer/WGPURayTracePass.js +17 -9
  22. package/lib/renderer/WGPURayTracePass.js.map +1 -1
  23. package/lib/renderer/WGPURenderingPipeline.js +15 -15
  24. package/lib/renderer/WebGLJNLMDenoiser.js +69 -69
  25. package/lib/renderer/WebGLRayTraceOutputPass.js +4 -4
  26. package/lib/renderer/WebGLRayTracePass.d.ts +1 -0
  27. package/lib/renderer/WebGLRayTracePass.js +8 -1
  28. package/lib/renderer/WebGLRayTracePass.js.map +1 -1
  29. package/lib/renderer/envMapCreation.d.ts +5 -1
  30. package/lib/renderer/envMapCreation.js +42 -5
  31. package/lib/renderer/envMapCreation.js.map +1 -1
  32. package/lib/renderer/geometryUpdates.js +1 -1
  33. package/lib/renderer/geometryUpdates.js.map +1 -1
  34. package/lib/renderer/glsl/chunks/cameraRay.glsl.js +12 -12
  35. package/lib/renderer/glsl/chunks/envMap.glsl.js +66 -54
  36. package/lib/renderer/glsl/chunks/envMap.glsl.js.map +1 -1
  37. package/lib/renderer/glsl/chunks/intersect.glsl.js +323 -315
  38. package/lib/renderer/glsl/chunks/intersect.glsl.js.map +1 -1
  39. package/lib/renderer/glsl/chunks/materialBuffer.glsl.js +154 -121
  40. package/lib/renderer/glsl/chunks/materialBuffer.glsl.js.map +1 -1
  41. package/lib/renderer/glsl/chunks/openPbrBsdf.glsl.js +434 -434
  42. package/lib/renderer/glsl/chunks/openPbrBsdf.glsl.js.map +1 -1
  43. package/lib/renderer/glsl/chunks/rand.glsl.js +3 -3
  44. package/lib/renderer/glsl/chunks/random.glsl.js +3 -3
  45. package/lib/renderer/glsl/chunks/rayTraceCore.glsl.js +42 -41
  46. package/lib/renderer/glsl/chunks/rayTraceCore.glsl.js.map +1 -1
  47. package/lib/renderer/glsl/chunks/sampleLight.glsl.js +69 -69
  48. package/lib/renderer/glsl/chunks/sampleMaterial.glsl.js +84 -84
  49. package/lib/renderer/glsl/chunks/sampleMaterial.glsl.js.map +1 -1
  50. package/lib/renderer/glsl/chunks/sampleShadowCatcher.glsl.js +12 -12
  51. package/lib/renderer/glsl/chunks/sampling.glsl.js +75 -75
  52. package/lib/renderer/glsl/chunks/sobol.glsl.js +61 -61
  53. package/lib/renderer/glsl/chunks/textureLinear.glsl.js +5 -5
  54. package/lib/renderer/glsl/chunks/uvProjection.glsl.js +11 -11
  55. package/lib/renderer/glsl/depthQuery.frag.js +5 -5
  56. package/lib/renderer/glsl/depthQuery.frag.js.map +1 -1
  57. package/lib/renderer/glsl/normalizeRayTraceOutput.frag.js +8 -8
  58. package/lib/renderer/glsl/rayTrace.frag.js +133 -133
  59. package/lib/renderer/glsl/rayTrace.frag.js.map +1 -1
  60. package/lib/renderer/glsl/shadowCatcher.frag.js +9 -9
  61. package/lib/renderer/glsl/shadowCatcher.frag.js.map +1 -1
  62. package/lib/renderer/glsl/webglPipeline.frag.js +52 -52
  63. package/lib/renderer/lightsUtil.js +6 -4
  64. package/lib/renderer/lightsUtil.js.map +1 -1
  65. package/lib/renderer/materialChanges.js +1 -1
  66. package/lib/renderer/materialChanges.js.map +1 -1
  67. package/lib/renderer/materialComparison.generated.js +36 -18
  68. package/lib/renderer/materialComparison.generated.js.map +1 -1
  69. package/lib/renderer/prepareMeshBVH.js +2 -2
  70. package/lib/renderer/prepareMeshBVH.js.map +1 -1
  71. package/lib/renderer/sceneChangeDetector.js +4 -1
  72. package/lib/renderer/sceneChangeDetector.js.map +1 -1
  73. package/lib/renderer/sceneLightChanges.js +3 -2
  74. package/lib/renderer/sceneLightChanges.js.map +1 -1
  75. package/lib/renderer/scratchSampling.js +18 -18
  76. package/lib/renderer/wgsl/chunks/common.wgsl.js +4 -4
  77. package/lib/renderer/wgsl/chunks/envMap.wgsl.d.ts +1 -1
  78. package/lib/renderer/wgsl/chunks/envMap.wgsl.js +39 -31
  79. package/lib/renderer/wgsl/chunks/envMap.wgsl.js.map +1 -1
  80. package/lib/renderer/wgsl/chunks/intersect.wgsl.js +476 -470
  81. package/lib/renderer/wgsl/chunks/intersect.wgsl.js.map +1 -1
  82. package/lib/renderer/wgsl/chunks/intersectionAlpha.wgsl.js +8 -8
  83. package/lib/renderer/wgsl/chunks/materialBuffer.wgsl.js +95 -60
  84. package/lib/renderer/wgsl/chunks/materialBuffer.wgsl.js.map +1 -1
  85. package/lib/renderer/wgsl/chunks/openPbrBsdf.wgsl.js +469 -469
  86. package/lib/renderer/wgsl/chunks/pdm_displacement.wgsl.d.ts +1 -1
  87. package/lib/renderer/wgsl/chunks/pdm_displacement.wgsl.js +117 -120
  88. package/lib/renderer/wgsl/chunks/pdm_displacement.wgsl.js.map +1 -1
  89. package/lib/renderer/wgsl/chunks/rand.wgsl.js +3 -3
  90. package/lib/renderer/wgsl/chunks/rayTraceCore.wgsl.js +25 -22
  91. package/lib/renderer/wgsl/chunks/rayTraceCore.wgsl.js.map +1 -1
  92. package/lib/renderer/wgsl/chunks/sampleLight.wgsl.js +127 -127
  93. package/lib/renderer/wgsl/chunks/sampleMaterial.wgsl.js +136 -136
  94. package/lib/renderer/wgsl/chunks/sampleShadowCatcher.wgsl.js +6 -6
  95. package/lib/renderer/wgsl/chunks/sampling.wgsl.js +73 -73
  96. package/lib/renderer/wgsl/chunks/sobol.wgsl.js +62 -62
  97. package/lib/renderer/wgsl/chunks/uvProjection.wgsl.js +11 -11
  98. package/lib/renderer/wgsl/compose.frag.wgsl.js +105 -105
  99. package/lib/renderer/wgsl/customDenoise.wgsl.js +10 -10
  100. package/lib/renderer/wgsl/depthQuery.wgsl.d.ts +1 -1
  101. package/lib/renderer/wgsl/depthQuery.wgsl.js +5 -5
  102. package/lib/renderer/wgsl/depthQuery.wgsl.js.map +1 -1
  103. package/lib/renderer/wgsl/offlineAdaptive.compute.js +28 -28
  104. package/lib/renderer/wgsl/rayTrace.compute.js +251 -248
  105. package/lib/renderer/wgsl/rayTrace.compute.js.map +1 -1
  106. package/lib/scene/EnvironmentLight.d.ts +9 -3
  107. package/lib/scene/EnvironmentLight.js +9 -2
  108. package/lib/scene/EnvironmentLight.js.map +1 -1
  109. package/lib/scene/OpenPBRMaterial.d.ts +1 -1
  110. package/lib/scene/OpenPBRMaterial.js +1 -1
  111. package/lib/scene/OpenPBRMaterial.js.map +1 -1
  112. package/lib/scene/Scene.d.ts +4 -0
  113. package/lib/scene/Scene.js.map +1 -1
  114. package/lib/scene/SpotLight.d.ts +2 -2
  115. package/lib/scene/SpotLight.js +1 -1
  116. package/lib/scene/SpotLight.js.map +1 -1
  117. package/lib/scene/Texture.d.ts +17 -6
  118. package/lib/scene/Texture.js +13 -4
  119. package/lib/scene/Texture.js.map +1 -1
  120. package/lib/util/fromTHREE.js +151 -29
  121. package/lib/util/fromTHREE.js.map +1 -1
  122. package/lib/version.d.ts +1 -1
  123. package/lib/version.js +1 -1
  124. package/lib/version.js.map +1 -1
  125. package/package.json +1 -1
@@ -1 +1 @@
1
-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;;;;;;;;;;;;;;;;;;;;;;;;;gCAyDN,CAAC,CAAC,CAAC,UAAU,CAAC,qCAAyD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2BAkJjF,cAAc,KAAK,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqG3D,CAAC;IACA,0EAA0E;IAC1E,8DAA8D;IAC9D,4EAA4E;IAC5E,8BAA8B;IAC9B,IAAI,iBAAiB,GAAG,MAAM,GAAG,cAAc,CAAC;IAChD,MAAM,cAAc,GAA2B;QAC7C,cAAc,EAAE,CAAC;QACjB,kBAAkB,EAAE,CAAC;QACrB,uBAAuB,EAAE,CAAC;KAC3B,CAAC;IACF,iBAAiB,GAAG,iBAAiB,CAAC,OAAO,CAC3C,oEAAoE,EACpE,CAAC,IAAI,EAAE,EAAE,CAAC,iCAAiC,cAAc,CAAC,IAAI,CAAC,SAAS,CACzE,CAAC;IACF,iBAAiB,GAAG,iBAAiB,CAAC,OAAO,CAC3C,IAAI,MAAM,CAAC,SAAS,MAAM,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,EAC9E,IAAI,CAAC,EAAE,CAAC,mCAAmC,uBAAuB,CAAC,IAAI,CAAC,WAAW,CACpF,CAAC;IACF,OAAO,iBAAiB,CAAC;AAC3B,CAAC","sourcesContent":["import { MAX_PATH_EVENTS } from '../pathLimits.js';\nimport shadowCatcherAccumulationWGSL from './chunks/shadowCatcherAccumulation.wgsl.js';\nimport depthQueryWGSL from './depthQuery.wgsl.js';\n// 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 commonWgsl from './chunks/common.wgsl.js';\nimport { WGPU_SCENE_FEATURE_BITS } from '../WGPUSceneFeatures.js';\nimport rayTraceCoreWgsl from './chunks/rayTraceCore.wgsl.js';\nimport { createMaterialBufferWgsl } from './chunks/materialBuffer.wgsl.js';\nimport createIntersectionWgsl from './chunks/intersect.wgsl.js';\nimport randomWgsl from './chunks/random.wgsl.js';\nimport randWgsl from './chunks/rand.wgsl.js';\nimport { createSampleMaterialWgsl } from './chunks/sampleMaterial.wgsl.js';\nimport sampleLightWgsl from './chunks/sampleLight.wgsl.js';\nimport { createOpenPbrBsdfWgsl } from './chunks/openPbrBsdf.wgsl.js';\nimport samplingWgsl from './chunks/sampling.wgsl.js';\nimport sampleShadowCatcherWgsl from './chunks/sampleShadowCatcher.wgsl.js';\nimport envMapWgsl from './chunks/envMap.wgsl.js';\nimport uvProjectionWgsl from './chunks/uvProjection.wgsl.js';\nexport const WORKGROUP_SIZE = 8;\n\nexport interface RayTraceShaderOptions {\n hasDisplacement: boolean;\n /** Include direction frames only when used, preserving the legacy shader arithmetic otherwise. */\n hasAnisotropyDirections?: boolean;\n /** Include independent coat normals only when a material uses that slot. */\n hasCoatNormals?: boolean;\n /** Split glTF BLEND primary hits deterministically instead of stochastically. */\n hasAlpha?: boolean;\n /** Any scene material uses alpha mask or blend. */\n hasSceneAlpha?: boolean;\n /** Bit mask of the BLAS layouts present in the scene (bvh2, bvh4, bvh-gpu, cwbvh). */\n blasLayoutMask?: number;\n}\n\n/** Generates the WebGPU megakernel path tracing compute shader. */\nexport default function rayTraceCompute({\n hasDisplacement,\n hasAnisotropyDirections = false,\n hasCoatNormals = false,\n hasAlpha = true,\n hasSceneAlpha = true,\n blasLayoutMask = 1\n}: RayTraceShaderOptions) {\n hasAnisotropyDirections ||= hasCoatNormals;\n const deterministicPrimaryAlpha = hasAlpha;\n const source = /* wgsl */ `\n\n${commonWgsl}\n\n${rayTraceCoreWgsl({ hasSceneAlpha, hasAnisotropyDirections, hasCoatNormals })}\n\n${uvProjectionWgsl}\n\n${createMaterialBufferWgsl({ hasSceneAlpha, hasAnisotropyDirections, hasCoatNormals })}\n\n${createIntersectionWgsl({ hasDisplacement, blasLayoutMask, hasAnisotropyDirections, hasCoatNormals })}\n${randWgsl}\n${randomWgsl}\n${envMapWgsl}\n\n${samplingWgsl}\n${createOpenPbrBsdfWgsl(hasAnisotropyDirections, hasCoatNormals)}\n${sampleLightWgsl}\n\n// Index of the path vertex currently being shaded.\nvar<private> bounceIndex: u32 = 0u;\n\n// Number of light candidates resampled for each NEE estimate. Interactive\n// preview caps the budget at two.\nfn neeCandidateCount() -> u32 {\n return u32(max(rtUniform.directLightCandidates, 1));\n}\n\n// Hash-based random number used to select among light candidates. It is\n// independent of the path sample stream so the candidate count does not\n// change the dimensions consumed by later bounces.\nfn lightCandidateRandom(salt: u32) -> f32 {\n // Reservoir replacement needs the full [0, 1) interval: sample1D's EPS\n // remapping makes small positive replacement probabilities unreachable.\n // Preserve the legacy sequential RNG draw in the random sampling mode so\n // subsequent path samples retain their stream; selection uses the hash.\n if (SAMPLING_PATTERN == 2) { _ = rand(); }\n let pixelID = samplingPixel.x + samplingPixel.y * u32(rtUniform.outputSize.x);\n let key = sampleSeed(sampleSeed(pixelID, pixelSampleIndex), rtUniform.sequenceSeed);\n let dimension = sampleSeed(samplingBounce, salt) ^ 0xa511e9b3u;\n return f32(sampleHash(key ^ dimension) >> 8u) * (1.0 / 16777216.0);\n}\n\n// MIS weight of a light-sampled contribution. With several resampled\n// candidates the NEE technique is drawn neeCandidateCount() times.\nfn neeMISWeight(lightPdf: f32, scatteringPdf: f32) -> f32 {\n let candidateCount = neeCandidateCount();\n if (candidateCount <= 1u) {\n return sampling_power_heuristic(lightPdf, scatteringPdf);\n }\n let weightedLightPdf = f32(candidateCount) * lightPdf;\n return weightedLightPdf /\n max(weightedLightPdf + scatteringPdf, 1e-20);\n}\n\n// MIS weight of a BSDF-sampled ray that hits a light.\nfn bsdfMISWeight(scatteringPdf: f32, lightPdf: f32) -> f32 {\n let candidateCount = neeCandidateCount();\n if (candidateCount <= 1u) {\n return sampling_power_heuristic(scatteringPdf, lightPdf);\n }\n let weightedLightPdf = f32(candidateCount) * lightPdf;\n return scatteringPdf /\n max(scatteringPdf + weightedLightPdf, 1e-20);\n}\n\n${createSampleMaterialWgsl(hasAnisotropyDirections, hasCoatNormals)}\n${sampleShadowCatcherWgsl}\n\n// Output\n@group(3) @binding(0) var<storage, read_write> outColor: array<vec4f>;\n@group(3) @binding(1) var<storage, read_write> outNormal: array<vec4f>;\n@group(3) @binding(2) var<storage, read_write> outAlbedo: array<vec4f>;\n\n${shadowCatcherAccumulationWGSL}\n@group(3) @binding(3) var<storage, read_write> outShadowCatcher: array<ShadowCatcherAccumulation>;\n\n\nfn accumulateNormalOrVariance(\n pixelIndex: u32,\n radiance: vec3f,\n normal: vec3f\n) {\n if (rtUniform.varianceMoments != 0) {\n let value = dot(radiance, luminance);\n outNormal[pixelIndex] += vec4f(value * value, 0.0, 0.0, 1.0);\n }\n else {\n outNormal[pixelIndex] += vec4f(normal, 1.0);\n }\n}\n\n// Moments of the per-sample value the built-in denoiser compares, used to\n// estimate the variance of each pixel's mean.\nfn accumulateDenoiseMoments(pixelIndex: u32, value: f32) {\n outShadowCatcher[pixelIndex].moments += vec4f(value, value * value, 0.0, 0.0);\n}\n\n\nstruct RayTraceAuxiliary {\n // Denoising guides and auxiliary pixel classification.\n albedo: vec3f,\n isShadowCatcher: bool,\n normal: vec3f,\n isBlank: bool,\n}\n\nfn groundedSurfaceDistance(point: vec3f, height: f32, radius: f32) -> f32 {\n let pointLength = length(point);\n if (pointLength < 0.00001) {\n return -radius;\n }\n\n let originalY = radius * point.y / pointLength;\n let transitionY = -1.5 * height;\n var surfaceRadius: f32;\n if (originalY >= 0.0) {\n surfaceRadius = radius;\n }\n else if (originalY < transitionY) {\n surfaceRadius = -height * pointLength / point.y;\n }\n else {\n let factor = 1.0\n - originalY * originalY / (3.0 * transitionY * transitionY);\n surfaceRadius = radius * factor;\n }\n return pointLength - surfaceRadius;\n}\n\nfn groundedBackgroundDirection(origin: vec3f, direction: vec3f) -> vec3f {\n if (!USE_GROUNDED_BACKGROUND) {\n return direction;\n }\n let params = rtUniform.groundedBackgroundParams;\n let rayDirection = normalize(direction);\n let center = vec3f(\n rtUniform.groundedBackgroundCenter.x,\n params.z + params.x,\n rtUniform.groundedBackgroundCenter.y\n );\n let localOrigin = origin - center;\n let projectedOrigin = dot(localOrigin, rayDirection);\n let discriminant = projectedOrigin * projectedOrigin\n - dot(localOrigin, localOrigin) + params.y * params.y;\n if (\n discriminant <= 0.0\n || groundedSurfaceDistance(localOrigin, params.x, params.y) > 0.0\n ) {\n return direction;\n }\n\n var farDistance = -projectedOrigin + sqrt(discriminant);\n if (farDistance <= 0.0) {\n return direction;\n }\n\n let sphereHit = localOrigin + rayDirection * farDistance;\n if (sphereHit.y >= 0.0) {\n return normalize(sphereHit);\n }\n\n if (rayDirection.y < -0.00001 && params.y > 1.5 * params.x) {\n let groundDistance = (-params.x - localOrigin.y) / rayDirection.y;\n let groundHit = localOrigin + rayDirection * groundDistance;\n let groundRadius = (2.0 / 3.0)\n * sqrt(params.y * params.y - 2.25 * params.x * params.x);\n if (groundDistance > 0.0 && length(groundHit.xz) <= groundRadius) {\n return normalize(groundHit);\n }\n }\n\n var nearDistance = 0.0;\n for (var i = 0; i < 14; i++) {\n let middleDistance = (nearDistance + farDistance) * 0.5;\n let middlePoint = localOrigin + rayDirection * middleDistance;\n if (groundedSurfaceDistance(middlePoint, params.x, params.y) > 0.0) {\n farDistance = middleDistance;\n }\n else {\n nearDistance = middleDistance;\n }\n }\n let hit = localOrigin + rayDirection * ((nearDistance + farDistance) * 0.5);\n return normalize(hit);\n}\n\nfn sampleSceneBackground(ray: Ray) -> vec4f {\n var bg = vec4f(0.0);\n if (USE_BACKGROUND_MAP) {\n let backgroundDirection = groundedBackgroundDirection(ray.o, ray.d);\n bg = textureLinear(backgroundMap, cartesianToEquirect(backgroundDirection));\n }\n else if (USE_BACKGROUND) {\n bg = rtUniform.backgroundColor;\n }\n else if (USE_ENVMAP) {\n bg = textureLinear(envMap, cartesianToEquirect(ray.d));\n }\n return bg;\n}\n\nfn sampleSpectralSceneBackground(ray: Ray, wavelength: f32) -> vec4f {\n let bg = sampleSceneBackground(ray);\n if (SPECTRAL) {\n return vec4f(sampling_spectral_rgb_filter(bg.rgb, wavelength), bg.a);\n }\n return bg;\n}\n\nfn bounce(uv: vec2f, path: ptr<function, Path>, depth: ptr<function, i32>, si: ptr<function, SurfaceInteraction>, ma: ptr<function, OpenPbrResolvedMaterial>, outAux: ptr<function, RayTraceAuxiliary>) {\n samplingBounce = u32(max(*depth, 0));\n let matType = (*ma).materialType;\n let isShadowCatcher = matType == SHADOW_CATCHER;\n if (isShadowCatcher) {\n if ((*path).fromEye) {\n (*si).hit = false;\n }\n else {\n // The catcher only contributes to the separate shadow mask. Secondary\n // rays must see the environment behind it instead of its default white\n // material, otherwise it appears in reflections.\n if (USE_ENVMAP) {\n if ((*path).isNextRefraction) {\n // A camera-visible transmitted ray can hit the invisible catcher\n // before the grounded skybox. Preserve the displayed projection.\n let bg = sampleSpectralSceneBackground(\n (*path).ray,\n (*si).wavelength\n );\n let backgroundMisWeight = select(bsdfMISWeight((*path).scatteringPdf,\n envMapPdf(cartesianToEquirect((*path).ray.d)) * rtUniform.envLightPmf),\n 1.0, (*path).scatteringIsDelta);\n (*path).li += backgroundMisWeight * (*path).beta * bg.rgb * bg.a;\n (*path).alpha = max((*path).alpha, bg.a);\n }\n else {\n let envUv = cartesianToEquirect((*path).ray.d);\n var emission = textureLinear(envMap, envUv).rgb;\n if (SPECTRAL) {\n emission = sampling_spectral_rgb_filter(emission, (*si).wavelength);\n }\n (*path).li += (*path).beta * emission *\n bsdfMISWeight((*path).scatteringPdf, envMapPdf(envUv));\n }\n }\n else {\n let bg = sampleSpectralSceneBackground(\n (*path).ray,\n (*si).wavelength\n );\n (*path).li += (*path).beta * bg.rgb * bg.a;\n }\n (*path).abort = true;\n return;\n }\n }\n if (!(*si).hit) {\n // The spectral integrator traces red, green, and blue paths separately.\n // Split background radiance by wavelength as well so the three paths\n // reconstruct the skybox instead of adding three full RGB copies.\n let bg = sampleSpectralSceneBackground(\n (*path).ray,\n (*si).wavelength\n );\n if ((*path).fromEye) {\n // Sample from background if first ray not hit anything.\n (*path).li = (*path).beta * bg.rgb * bg.a;\n (*path).alpha = bg.a;\n // Only treat as blank pixels when the background is transparent\n (*outAux).isBlank = bg.a < 0.001 ||\n (USE_BACKGROUND && !USE_BACKGROUND_MAP);\n }\n else {\n let cam = initCameraRay(uv);\n let towardsCam = dot(cam.d, (*path).ray.d) > 0.0;\n if (rtUniform.transmissiveOutputAlphaMin < 1.0) {\n if (towardsCam) {\n (*path).alpha = max((*path).alpha, bg.a);\n } else {\n (*path).alpha = 1.0;\n }\n }\n if (!USE_ENVMAP) {\n // A display background is not an illumination environment, but a\n // visible secondary ray (e.g. through glass) still resolves it.\n if (towardsCam) {\n // This is a terminal BSDF-hit contribution, not a replacement for\n // NEE accumulated at earlier vertices on the same path.\n (*path).li += (*path).beta *\n bsdfMISWeight((*path).scatteringPdf, 1.0) * bg.rgb;\n }\n }\n }\n (*path).abort = true;\n return;\n }\n\n var sampleIgnored = false;\n if ((matType == STANDARD || matType == UNLIT)) {\n let alpha = clamp((*ma).alpha, 0.0, 1.0);\n \n if (alpha < 1.0) {\n // Alpha is stochastic coverage. Keep accepted surface radiance at full\n // weight instead of multiplying it by alpha a second time.\n if (alpha <= 0.0 || hashedSample(3u) > alpha) {\n sampleIgnored = true;\n }\n }\n if (!sampleIgnored && rtUniform.transmissiveOutputAlphaMin < 1.0) {\n // A selected stochastic coverage sample is fully covered. Ignored\n // samples leave output alpha untouched and continue to the back layer.\n let outputAlpha = max(1.0 - (*ma).transmissionWeight, 1.0 - pow(1.0 - rtUniform.transmissiveOutputAlphaMin, f32(*depth)));\n (*path).alpha = max(outputAlpha, (*path).alpha);\n }\n if (!sampleIgnored) {\n bounceIndex = u32(max(*depth, 0));\n SampleMaterial(si, ma, path);\n }\n else {\n // Alpha-null traversal does not consume the receiver event. The first\n // accepted surface behind it is still the receiver for NEE/AOVs.\n (*path).ray.o = (*si).position + (*path).ray.d * EPS;\n }\n }\n\n if (!(*si).albedoSampled && !sampleIgnored) {\n // Select denoising guides.\n if ((matType == STANDARD || matType == UNLIT)) {\n if (!((*ma).transmissionWeight > 0.5 ||\n ((*ma).specularRoughness <= 0.02 && (*ma).baseMetalness > 0.98))) {\n (*outAux).albedo = (*ma).baseColor;\n (*outAux).normal = select(\n (*si).normal,\n -(*si).normal,\n dot(\n (*si).normal,\n (*si).position - cameraUniform.viewInv[3].xyz\n ) > 0.0\n );\n (*si).albedoSampled = true;\n }\n // TODO pick albedo and normal on the surface if ray is too deep and can't hit any rough or opaque surfaces.\n if (*depth > 4) {\n (*si).albedoSampled = true;\n }\n }\n }\n\n // Russian roulette with throughput compensation.\n if (USE_RR) {\n if (*depth >= RR_MAX && !sampleIgnored) {\n let rouletteBeta = (*path).beta;\n // Max-component survival (pbrt-v4) avoids over-amplifying saturated paths.\n let maxComponent = max(max(rouletteBeta.x, rouletteBeta.y), rouletteBeta.z);\n let q: f32 = max(0.0, 1.0 - maxComponent);\n if (sample1D(bounceDim(RUSSIAN_ROULETTE)) < q) {\n // TODO we force use alpha 1.0 here.\n // To avoid the glass pixels is transparent even if it's on an opaque object.\n (*path).alpha = 1.0;\n (*path).abort = true;\n }\n else {\n (*path).beta /= 1.0 - q;\n }\n }\n }\n if ((*path).abort) {\n return;\n }\n\n intersectScene((*path).ray, si, *depth, true, (*path).isNextRefraction);\n getMaterial(ma, (*si).materialIndex, (*si).uv, (*si).uv1, (*si).instanceIndex);\n\n if (SPECTRAL) {\n // Is glass\n if ((*ma).transmissionWeight > 0.001) {\n (*ma).specularIor = sampling_cauchy_ior(\n (*si).wavelength,\n (*ma).specularIor,\n (*ma).transmissionDispersionScale,\n (*ma).dispersionAbbeNumber\n );\n }\n }\n\n if (sampleIgnored) {\n return;\n }\n\n // Use light if hit the light\n var lightSample: LightSampleRec;\n let isAlphaOccluded = hashedSample(3u) < (*ma).alpha;\n for (var i = 0; i < rtUniform.lightsCount; i++) {\n // Fetch light Data\n let light: Light = analyticLights[i];\n let d = intersectLight((*path).ray, light, &lightSample);\n lightSample.pdf *= light.selectionPmf;\n let occluded = (*si).hit && d > distance((*si).position, (*path).ray.o);\n if (d != INF && !(occluded && isAlphaOccluded)) {\n let misWeight = bsdfMISWeight((*path).scatteringPdf, lightSample.pdf);\n if (SPECTRAL) {\n lightSample.emission = sampling_spectral_rgb_filter(lightSample.emission, (*si).wavelength);\n }\n (*path).li += misWeight * (*path).beta * lightSample.emission;\n (*path).alpha = 1.0;\n (*path).abort = true;\n }\n }\n\n if (USE_ENVMAP) {\n if (!((*si).hit && isAlphaOccluded)) {\n if ((*path).isNextRefraction) {\n // Camera-visible transmission follows the displayed background,\n // including grounded projection. Other rays use the raw environment\n // map as the physically sampled lighting source.\n let bg = sampleSpectralSceneBackground(\n (*path).ray,\n (*si).wavelength\n );\n let backgroundMisWeight = select(bsdfMISWeight((*path).scatteringPdf,\n envMapPdf(cartesianToEquirect((*path).ray.d)) * rtUniform.envLightPmf),\n 1.0, (*path).scatteringIsDelta);\n (*path).li += backgroundMisWeight * (*path).beta * bg.rgb * bg.a;\n (*path).alpha = max((*path).alpha, bg.a);\n (*path).abort = true;\n return;\n }\n let _uv = cartesianToEquirect((*path).ray.d);\n var emission = textureLinear(envMap, _uv).rgb;\n let misWeight = bsdfMISWeight(\n (*path).scatteringPdf,\n envMapPdf(_uv) * rtUniform.envLightPmf\n );\n if (SPECTRAL) {\n emission = sampling_spectral_rgb_filter(emission, (*si).wavelength);\n }\n // TODO force the min alpha to be 1 when showing envmap as background\n if (!USE_BACKGROUND) {\n (*path).alpha = 1.0;\n }\n (*path).li += (*path).beta * emission * misWeight;\n (*path).abort = true;\n }\n }\n\n *depth = *depth + 1;\n}\n\nfn initCameraRay(coord: vec2f) -> Ray {\n let origin = cameraUniform.viewProjectionInv * vec4f(coord * 2.0 - 1.0, -1.0, 1.0);\n let center = cameraUniform.viewProjectionInv * vec4f(coord * 2.0 - 1.0, 1.0, 1.0);\n var cam: Ray;\n initRay(&cam, origin.xyz / origin.w, normalize(center.xyz * origin.w - origin.xyz * center.w));\n\n return cam;\n}\n\n\nfn bevelCubicSample(radius: f32, xi: f32) -> vec2f {\n var x = 0.25;\n for (var iteration = 0; iteration < 10; iteration++) {\n let x2 = x * x;\n let x3 = x2 * x;\n let oneMinusX = 1.0 - x;\n let value = 10.0 * x2 - 20.0 * x3 + 15.0 * x2 * x2 -\n 4.0 * x2 * x3 - xi;\n let derivative = 20.0 * x * oneMinusX * oneMinusX * oneMinusX;\n if (abs(value) < 1e-6 || derivative == 0.0) { break; }\n x = clamp(x - value / derivative, 0.0, 1.0);\n }\n let diskRadius = x * radius;\n return vec2f(diskRadius, sqrt(max(radius * radius - diskRadius * diskRadius, 0.0)));\n}\n\nfn bevelCubicPdf(radius: f32, distanceToSource: f32) -> f32 {\n if (distanceToSource >= radius) { return 0.0; }\n let falloff = radius - distanceToSource;\n return falloff * falloff * falloff;\n}\n\n// Shader bevel. Usage: docs/materials.md (Renderer extensions)\nfn getBevelNormal(source: SurfaceInteraction, radius: f32) -> vec3f {\n var geometricNormal = source.faceNormal;\n if (dot(geometricNormal, source.vertexNormal) < 0.0) {\n geometricNormal = -geometricNormal;\n }\n var tangent: vec3f;\n var bitangent: vec3f;\n sampling_orthonormal_basis(geometricNormal, &tangent, &bitangent);\n var normalSum = vec3f(0.0);\n\n for (var sampleIndex = 0; sampleIndex < BEVEL_SAMPLES; sampleIndex++) {\n let bevelRnd = sample2D(CAMERA_BEVEL_BASE + u32(sampleIndex));\n var axisSample = bevelRnd.x;\n let radialSample = bevelRnd.y;\n var diskNormal = geometricNormal;\n var diskTangent = tangent;\n var diskBitangent = bitangent;\n var pickPdfNormal = 0.5;\n var pickPdfTangent = 0.25;\n var pickPdfBitangent = 0.25;\n if (axisSample < 0.5) {\n axisSample *= 2.0;\n }\n else if (axisSample < 0.75) {\n let swapAxis = diskNormal;\n diskNormal = diskTangent;\n diskTangent = swapAxis;\n pickPdfNormal = 0.25;\n pickPdfTangent = 0.5;\n axisSample = (axisSample - 0.5) * 4.0;\n }\n else {\n let swapAxis = diskNormal;\n diskNormal = diskBitangent;\n diskBitangent = swapAxis;\n pickPdfNormal = 0.25;\n pickPdfBitangent = 0.5;\n axisSample = (axisSample - 0.75) * 4.0;\n }\n\n let diskSample = bevelCubicSample(radius, radialSample);\n let phi = TWOPI * axisSample;\n let diskOffset = diskSample.x *\n (cos(phi) * diskTangent + sin(phi) * diskBitangent);\n var ray: Ray;\n initRay(\n &ray,\n source.position + diskNormal * diskSample.y + diskOffset,\n -diskNormal\n );\n var hit: SurfaceInteraction;\n intersectSceneBevel(\n ray,\n &hit,\n source.instanceIndex,\n max(2.0 * diskSample.y, EPS)\n );\n if (!hit.hit) { continue; }\n\n let pdfNormal = pickPdfNormal * abs(dot(diskNormal, hit.faceNormal));\n let pdfTangent = pickPdfTangent * abs(dot(diskTangent, hit.faceNormal));\n let pdfBitangent = pickPdfBitangent * abs(dot(diskBitangent, hit.faceNormal));\n var weight = pdfNormal / max(\n pdfNormal * pdfNormal + pdfTangent * pdfTangent +\n pdfBitangent * pdfBitangent,\n 1e-8\n );\n weight *= bevelCubicPdf(radius, distance(hit.position, source.position)) /\n max(bevelCubicPdf(radius, diskSample.x), 1e-8);\n normalSum += weight * hit.vertexNormal;\n }\n\n if (dot(normalSum, normalSum) <= 1e-12) { return source.normal; }\n let bevelVertexNormal = normalize(normalSum);\n let result = source.normal + bevelVertexNormal - source.vertexNormal;\n if (dot(result, result) > 1e-12) { return normalize(result); }\n return source.normal;\n}\n\nfn integrateOnePathSample(uv: vec2f, si: ptr<function, SurfaceInteraction>, ray: Ray, ma: ptr<function, OpenPbrResolvedMaterial>, outAux: ptr<function, RayTraceAuxiliary>) -> vec4f {\n var path: Path;\n path.ray = ray;\n path.li = vec3f(0.0);\n path.alpha = select(1.0, 0.0, rtUniform.transmissiveOutputAlphaMin < 1.0);\n path.beta = vec3f(1.0);\n path.fromEye = true;\n path.scatteringPdf = 0.0;\n path.scatteringIsDelta = false;\n path.isNextRefraction = false;\n path.abort = false;\n\n let isNotTransparent = (*ma).transmissionWeight < 0.001 && (*ma).subsurfaceWeight < 0.001 && (*ma).alpha > 0.99;\n let bounceLimit = max(rtUniform.bounces, 0);\n var depth = 0;\n // Transparent paths may take up to three times the configured bounces.\n for (var idx: i32 = 0; idx < min(bounceLimit * 3, ${MAX_PATH_EVENTS}); idx = idx + 1) {\n if (isNotTransparent && idx > bounceLimit) {\n path.abort = true;\n }\n if (path.abort) {\n break;\n }\n bounce(uv, &path, &depth, si, ma, outAux);\n }\n\n return vec4f(path.li, path.alpha);\n}\n\nfn integrateOnePath(uv: vec2f, si: ptr<function, SurfaceInteraction>, ray: Ray, ma: ptr<function, OpenPbrResolvedMaterial>, outAux: ptr<function, RayTraceAuxiliary>) -> vec4f {\n ${deterministicPrimaryAlpha ? /* wgsl */ `let coverage = clamp((*ma).alpha, 0.0, 1.0);\n if (!(*si).hit || ((*ma).materialType != STANDARD && (*ma).materialType != UNLIT) || coverage >= 1.0) {\n return integrateOnePathSample(uv, si, ray, ma, outAux);\n }\n\n // glTF BLEND is source-over opacity, not a physical glass boundary. Split\n // the primary ray so reflected radiance is attenuated by alpha every sample\n // while the complementary branch continues straight to the scene behind it.\n // Secondary alpha hits remain stochastic to avoid exponential path growth.\n var backRay = ray;\n backRay.o = (*si).position + ray.d * (EPS * 0.02);\n var backSi = *si;\n backSi.albedoSampled = false;\n intersectScene(backRay, &backSi, 0, false, false);\n var backMa: OpenPbrResolvedMaterial;\n getMaterial(&backMa, backSi.materialIndex, backSi.uv, backSi.uv1, backSi.instanceIndex);\n var backAux = *outAux;\n if (backSi.hit && backMa.materialType == STANDARD) {\n backAux.albedo = select(\n backMa.baseColor,\n vec3f(1.0),\n backMa.transmissionWeight > 0.5\n );\n backAux.normal = select(\n backSi.normal,\n -backSi.normal,\n dot(\n backSi.normal,\n backSi.position - cameraUniform.viewInv[3].xyz\n ) > 0.0\n );\n backSi.albedoSampled = backMa.transmissionWeight > 0.5;\n }\n let back = integrateOnePathSample(\n uv, &backSi, backRay, &backMa, &backAux\n );\n if (coverage <= 0.0) {\n *outAux = backAux;\n return back;\n }\n\n var frontSi = *si;\n var frontMa = *ma;\n frontMa.alpha = 1.0;\n var frontAux = *outAux;\n let front = integrateOnePathSample(\n uv, &frontSi, ray, &frontMa, &frontAux\n );\n (*outAux).albedo = mix(backAux.albedo, frontAux.albedo, coverage);\n let blendedNormal = mix(backAux.normal, frontAux.normal, coverage);\n (*outAux).normal = select(\n vec3f(0.0),\n normalize(blendedNormal),\n dot(blendedNormal, blendedNormal) > 1e-12\n );\n (*outAux).isBlank = backAux.isBlank && frontAux.isBlank;\n (*outAux).isShadowCatcher = backAux.isShadowCatcher && frontAux.isShadowCatcher;\n return mix(back, front, coverage);` : /* wgsl */ `return integrateOnePathSample(uv, si, ray, ma, outAux);`}\n}\n\n// Path tracing integrator as described in\n// http://www.pbr-book.org/3ed-2018/Light_Transport_I_Surface_Reflection/Path_Tracing.html#\nfn integrator(uv: vec2f, ray: Ray, outAux: ptr<function, RayTraceAuxiliary>) -> vec4f {\n var si: SurfaceInteraction;\n var ma: OpenPbrResolvedMaterial;\n si.albedoSampled = false;\n si.mediumType = 0;\n si.mediumExtinction = vec3f(0.0);\n si.mediumScattering = vec3f(0.0);\n si.mediumAnisotropy = 0.0;\n si.barycentrics = vec2f(0.0);\n\n // TODO not put tMax in ray. So we don't need to use pointer of ray here.\n intersectScene(ray, &si, 0, false, false);\n getMaterial(&ma, si.materialIndex, si.uv, si.uv1, si.instanceIndex);\n\n if (si.hit && ma.materialType == SHADOW_CATCHER) {\n (*outAux).isShadowCatcher = true;\n // The composed denoising input includes this receiver's shadow. Supply\n // neutral reflectance and its shading normal, independent of visibility.\n (*outAux).albedo = vec3f(1.0);\n (*outAux).normal = select(si.normal, -si.normal, dot(si.normal, ray.d) > 0.0);\n var path: Path;\n path.ray = ray;\n path.fromEye = true;\n sampleShadowCatcher(si, 0, &path);\n // RGB stores primary catcher coverage independently from the stochastic\n // visibility in alpha. Composition uses this raw coverage to clip any\n // shadow-mask denoising bleed at model silhouettes.\n return vec4f(vec3f(1.0), path.alpha);\n }\n else {\n if (HAS_BEVEL && rtUniform.bevel != 0) {\n if (ma.bevel > 0.0) {\n si.normal = getBevelNormal(si, ma.bevel);\n }\n }\n\n // Store a clean first-hit fallback. Glass retains this stable guide;\n // other delta paths may replace it at their first non-delta hit.\n if (si.hit && (ma.materialType == STANDARD || ma.materialType == UNLIT)) {\n (*outAux).albedo = select(ma.baseColor, vec3f(1.0), ma.transmissionWeight > 0.5);\n (*outAux).normal = select(\n si.normal,\n -si.normal,\n dot(si.normal, si.position - cameraUniform.viewInv[3].xyz) > 0.0\n );\n\n // Do not replace a glass guide with a randomly selected downstream\n // refraction/reflection hit; OIDN auxiliary features must stay clean.\n si.albedoSampled = ma.transmissionWeight > 0.5;\n }\n\n (*outAux).isShadowCatcher = false;\n\n if (SPECTRAL) {\n // Keep one source-level integrateOnePath call for both interactive\n // preview and offline RGB splitting. A runtime loop bound prevents the\n // WGSL compiler from cloning the full path graph three times while the\n // uniform still selects the exact existing preview/offline behavior.\n let rgbWaveLengths = array<f32, 3>(650.0, 510.0, 475.0);\n var colAccum = vec3f(0.0);\n var alpha = 0.0;\n var accumulatedGuideAlbedo = vec3f(0.0);\n var accumulatedGuideNormal = vec3f(0.0);\n var allBlank = true;\n var si2 = si;\n var ma2 = ma;\n let wavelengthRngState = s0;\n let wavelengthHashedCounter = hashedCounter;\n let singleWavelength = rtUniform.dispersionWavelengths == 1;\n let dispersivePrimary = si.hit &&\n ma.transmissionWeight > 0.001 &&\n ma.transmissionDispersionScale > 0.001;\n let wavelengthCount = select(3, 1, singleWavelength);\n var heroWavelengthIndex = 0;\n if (singleWavelength && dispersivePrimary) {\n // Stochastic hero wavelength: one RGB channel per pixel keeps the\n // preview spectral at one-third of the full three-path cost.\n heroWavelengthIndex = min(i32(floor(sample1D(CAMERA_WAVELENGTH) * 3.0)), 2);\n }\n for (var i = 0; i < wavelengthCount; i++) {\n // Common random numbers keep Monte Carlo error correlated between\n // RGB wavelengths. This removes much of the colored variance that\n // otherwise turns into dirty chromatic patches after OIDN.\n if (!singleWavelength) {\n s0 = wavelengthRngState;\n hashedCounter = wavelengthHashedCounter;\n samplingBounce = 0u;\n }\n si.wavelength = 0.0;\n if (!singleWavelength || dispersivePrimary) {\n si.wavelength = rgbWaveLengths[select(i, heroWavelengthIndex, singleWavelength)];\n ma.specularIor = sampling_cauchy_ior(\n si.wavelength,\n ma.specularIor,\n ma.transmissionDispersionScale,\n ma.dispersionAbbeNumber\n );\n }\n var wavelengthAux: RayTraceAuxiliary;\n if (singleWavelength) {\n wavelengthAux = *outAux;\n } else {\n wavelengthAux.albedo = (*outAux).albedo;\n wavelengthAux.normal = (*outAux).normal;\n wavelengthAux.isBlank = false;\n wavelengthAux.isShadowCatcher = false;\n }\n let res = integrateOnePath(uv, &si, ray, &ma, &wavelengthAux);\n if (singleWavelength) {\n *outAux = wavelengthAux;\n let scale = select(1.0, 3.0, dispersivePrimary);\n return vec4f(res.rgb * scale, res.a);\n }\n colAccum += res.rgb;\n alpha = max(alpha, res.a);\n accumulatedGuideAlbedo += wavelengthAux.albedo;\n accumulatedGuideNormal += wavelengthAux.normal;\n allBlank = allBlank && wavelengthAux.isBlank;\n si = si2;\n ma = ma2;\n }\n (*outAux).albedo = accumulatedGuideAlbedo / 3.0;\n (*outAux).normal = accumulatedGuideNormal / 3.0;\n (*outAux).isBlank = allBlank;\n return vec4f(colAccum, alpha);\n }\n else {\n return integrateOnePath(uv, &si, ray, &ma, outAux);\n }\n }\n}\n\nfn sampleCircle(ip: vec2f) -> vec2f {\n let p = 2.0 * ip - 1.0;\n let greater = abs(p.x) > abs(p.y);\n let r = select(p.y, p.x, greater);\n let theta = select(PI * (0.5 - 0.25 * p.x / p.y), 0.25 * PI * p.y / p.x, greater);\n return r * vec2f(cos(theta), sin(theta));\n}\n\n\n@compute @workgroup_size(${WORKGROUP_SIZE}, ${WORKGROUP_SIZE}, 1)\nfn main(@builtin(global_invocation_id) globalId: vec3u) {\n let outputSize = rtUniform.outputSize;\n let scaleOffset = rtUniform.scaleOffset;\n var jitter = rtUniform.jitter;\n // TODO if outputSize is not multiple of 8?\n let coord = globalId.xy * vec2u(scaleOffset.xy) + vec2u(scaleOffset.zw);\n if (coord.x >= u32(outputSize.x) || coord.y >= u32(outputSize.y)) {\n return;\n }\n let idx = coord.x + coord.y * u32(outputSize.x);\n\n if (\n rtUniform.adaptiveSampling != 0 &&\n outNormal[idx].a >= textureLoad(\n adaptiveSampleTargets,\n vec2i(coord),\n 0\n ).r\n ) {\n return;\n }\n\n // Match WebGL's rasterized v_Texcoord, whose sample is at the center of\n // each pixel. Keeping the same origin is material relevant: a half-pixel\n // shift moves a narrow metal highlight across several pixels.\n let uv = (vec2<f32>(f32(coord.x), f32(coord.y)) + vec2f(0.5)) / outputSize;\n\n samplingPixel = coord;\n pixelSampleIndex = u32(outNormal[idx].a) + rtUniform.sampleSequenceOffset;\n samplingBounce = 0u; hashedCounter = 0u;\n if (SAMPLING_PATTERN == 0 || SAMPLING_PATTERN == 1) {\n jitter = (sample2D(CAMERA_PIXEL) - 0.5) / outputSize;\n }\n rng_initialize(coord, i32(pixelSampleIndex ^ sampleHash(rtUniform.sequenceSeed)));\n var cam = initCameraRay(uv + jitter);\n\n if (cameraUniform.apertureRadius > 0.0) {\n // Thin lens: the focus plane is perpendicular to the view direction.\n let eye = cameraUniform.viewInv[3].xyz;\n let forward = -normalize(cameraUniform.viewInv[2].xyz);\n let focusPoint = eye + cam.d * (cameraUniform.focusDistance / dot(cam.d, forward));\n let lensPoint = cameraUniform.apertureRadius * sampleCircle(sample2D(CAMERA_LENS));\n let origin = (cameraUniform.viewInv * vec4f(lensPoint, 0.0, 1.0)).xyz;\n let dir = normalize(focusPoint - origin);\n initRay(&cam, origin, dir);\n }\n\n var outAux: RayTraceAuxiliary;\n outAux.albedo = vec3f(0.0);\n outAux.normal = vec3f(0.0);\n outAux.isBlank = false;\n outAux.isShadowCatcher = false;\n var liAndAlpha = integrator(uv + jitter, cam, &outAux);\n\n // Clamp at Integration Level to reduce fireflies.\n // TODO Path level configuration?\n if (rtUniform.clamping > 0.0) {\n let clamping = rtUniform.clamping;\n liAndAlpha = vec4(clamp(liAndAlpha.rgb, -vec3f(clamping), vec3f(clamping)), liAndAlpha.a);\n }\n if (!(liAndAlpha.x < INF && liAndAlpha.x > -EPS)) {\n liAndAlpha = vec4f(0.0, 0.0, 0.0, 1.0);\n }\n\n if (outAux.isShadowCatcher) {\n // The catcher is invisible, so the main color at this pixel must still\n // contain whatever the camera ray would have seen behind it.\n let backgroundSample = sampleSceneBackground(cam);\n let backgroundHit = select(0.0, 1.0, backgroundSample.a >= 0.01);\n let backgroundPremultiplied = vec4f(backgroundSample.rgb * backgroundSample.a, backgroundSample.a);\n // Keep the background contribution separate from geometry at silhouettes.\n // mask: catcher coverage, background alpha, background hits, shadow opacity.\n outShadowCatcher[idx].mask += vec4f(1.0, backgroundSample.a, backgroundHit, liAndAlpha.a);\n outShadowCatcher[idx].background += backgroundPremultiplied;\n outColor[idx] += backgroundPremultiplied;\n outAlbedo[idx] += vec4f(outAux.albedo, backgroundHit);\n accumulateNormalOrVariance(idx, backgroundSample.rgb, outAux.normal);\n // The composed catcher is the background darkened by the shadow. Over a\n // transparent background the shadow is only its opacity.\n let visibility = 1.0 - liAndAlpha.a;\n accumulateDenoiseMoments(idx, visibility * select(\n 1.0, dot(backgroundSample.rgb, luminance), backgroundSample.a >= 0.01\n ));\n }\n else {\n if (HAS_SHADOW_CATCHER && outAux.isBlank && USE_BACKGROUND && !USE_BACKGROUND_MAP && rtUniform.backgroundColor.a >= 0.99999) {\n // A primary miss sees the same opaque display backdrop as a catcher\n // hit, but must never receive its shadow. Keep that radiance and alpha\n // out of the geometry layer before hit-count normalization/tone mapping.\n // Red/blue still count only actual catcher hits; green counts all\n // background alpha removed from the foreground during normalization.\n outShadowCatcher[idx].background += liAndAlpha;\n outShadowCatcher[idx].mask.g += liAndAlpha.a;\n }\n outColor[idx] += liAndAlpha;\n outAlbedo[idx] += vec4f(outAux.albedo, select(1.0, 0.0, outAux.isBlank));\n accumulateNormalOrVariance(idx, liAndAlpha.rgb, outAux.normal);\n accumulateDenoiseMoments(idx, dot(liAndAlpha.rgb, luminance));\n }\n}\n`;\n // The query entry point shares the exact BVH and material implementation.\n // It has no effect on the beauty entry point or its bindings.\n // Gate optional material layers on scene-level feature flags so drivers can\n // skip the unused BSDF lobes.\n let specializedSource = source + depthQueryWGSL;\n const backgroundBits: Record<string, number> = {\n USE_BACKGROUND: 1,\n USE_BACKGROUND_MAP: 2,\n USE_GROUNDED_BACKGROUND: 4\n };\n specializedSource = specializedSource.replace(\n /\\b(?:USE_BACKGROUND|USE_BACKGROUND_MAP|USE_GROUNDED_BACKGROUND)\\b/g,\n (name) => `((rtUniform.backgroundFlags & ${backgroundBits[name]}) != 0)`\n );\n specializedSource = specializedSource.replace(\n new RegExp(`\\\\b(?:${Object.keys(WGPU_SCENE_FEATURE_BITS).join('|')})\\\\b`, 'g'),\n name => `((rtUniform.sceneFeatureFlags & ${WGPU_SCENE_FEATURE_BITS[name]}u) != 0u)`\n );\n return specializedSource;\n}\n"]}
1
+ {"version":3,"file":"rayTrace.compute.js","sourceRoot":"","sources":["../../../src/renderer/wgsl/rayTrace.compute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,6BAA6B,MAAM,4CAA4C,CAAC;AACvF,OAAO,cAAc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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2BAkJjF,cAAc,KAAK,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqG3D,CAAC;IACA,0EAA0E;IAC1E,8DAA8D;IAC9D,4EAA4E;IAC5E,8BAA8B;IAC9B,IAAI,iBAAiB,GAAG,MAAM,GAAG,cAAc,CAAC;IAChD,MAAM,cAAc,GAA2B;QAC7C,cAAc,EAAE,CAAC;QACjB,kBAAkB,EAAE,CAAC;QACrB,uBAAuB,EAAE,CAAC;KAC3B,CAAC;IACF,iBAAiB,GAAG,iBAAiB,CAAC,OAAO,CAC3C,oEAAoE,EACpE,CAAC,IAAI,EAAE,EAAE,CAAC,iCAAiC,cAAc,CAAC,IAAI,CAAC,SAAS,CACzE,CAAC;IACF,iBAAiB,GAAG,iBAAiB,CAAC,OAAO,CAC3C,IAAI,MAAM,CAAC,SAAS,MAAM,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,EAC9E,IAAI,CAAC,EAAE,CAAC,mCAAmC,uBAAuB,CAAC,IAAI,CAAC,WAAW,CACpF,CAAC;IACF,OAAO,iBAAiB,CAAC;AAC3B,CAAC","sourcesContent":["import { MAX_PATH_EVENTS } from '../pathLimits.js';\nimport shadowCatcherAccumulationWGSL from './chunks/shadowCatcherAccumulation.wgsl.js';\nimport depthQueryWGSL from './depthQuery.wgsl.js';\n// 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 commonWgsl from './chunks/common.wgsl.js';\nimport { WGPU_SCENE_FEATURE_BITS } from '../WGPUSceneFeatures.js';\nimport rayTraceCoreWgsl from './chunks/rayTraceCore.wgsl.js';\nimport { createMaterialBufferWgsl } from './chunks/materialBuffer.wgsl.js';\nimport createIntersectionWgsl from './chunks/intersect.wgsl.js';\nimport randomWgsl from './chunks/random.wgsl.js';\nimport randWgsl from './chunks/rand.wgsl.js';\nimport { createSampleMaterialWgsl } from './chunks/sampleMaterial.wgsl.js';\nimport sampleLightWgsl from './chunks/sampleLight.wgsl.js';\nimport { createOpenPbrBsdfWgsl } from './chunks/openPbrBsdf.wgsl.js';\nimport samplingWgsl from './chunks/sampling.wgsl.js';\nimport sampleShadowCatcherWgsl from './chunks/sampleShadowCatcher.wgsl.js';\nimport envMapWgsl from './chunks/envMap.wgsl.js';\nimport uvProjectionWgsl from './chunks/uvProjection.wgsl.js';\nexport const WORKGROUP_SIZE = 8;\n\nexport interface RayTraceShaderOptions {\n hasDisplacement: boolean;\n /** Include direction frames only when used, preserving the legacy shader arithmetic otherwise. */\n hasAnisotropyDirections?: boolean;\n /** Include independent coat normals only when a material uses that slot. */\n hasCoatNormals?: boolean;\n /** Split glTF BLEND primary hits deterministically instead of stochastically. */\n hasAlpha?: boolean;\n /** Any scene material uses alpha mask or blend. */\n hasSceneAlpha?: boolean;\n /** Bit mask of the BLAS layouts present in the scene (bvh2, bvh4, bvh-gpu, cwbvh). */\n blasLayoutMask?: number;\n}\n\n/** Generates the WebGPU megakernel path tracing compute shader. */\nexport default function rayTraceCompute({\n hasDisplacement,\n hasAnisotropyDirections = false,\n hasCoatNormals = false,\n hasAlpha = true,\n hasSceneAlpha = true,\n blasLayoutMask = 1\n}: RayTraceShaderOptions) {\n hasAnisotropyDirections ||= hasCoatNormals;\n const deterministicPrimaryAlpha = hasAlpha;\n const source = /* wgsl */ `\n\n${commonWgsl}\n\n${rayTraceCoreWgsl({ hasSceneAlpha, hasAnisotropyDirections, hasCoatNormals })}\n\n${uvProjectionWgsl}\n\n${createMaterialBufferWgsl({ hasSceneAlpha, hasAnisotropyDirections, hasCoatNormals })}\n\n${createIntersectionWgsl({ hasDisplacement, blasLayoutMask, hasAnisotropyDirections, hasCoatNormals })}\n${randWgsl}\n${randomWgsl}\n${envMapWgsl}\n\n${samplingWgsl}\n${createOpenPbrBsdfWgsl(hasAnisotropyDirections, hasCoatNormals)}\n${sampleLightWgsl}\n\n// Index of the path vertex currently being shaded.\nvar<private> bounceIndex: u32 = 0u;\n\n// Number of light candidates resampled for each NEE estimate. Interactive\n// preview caps the budget at two.\nfn neeCandidateCount() -> u32 {\n return u32(max(rtUniform.directLightCandidates, 1));\n}\n\n// Hash-based random number used to select among light candidates. It is\n// independent of the path sample stream so the candidate count does not\n// change the dimensions consumed by later bounces.\nfn lightCandidateRandom(salt: u32) -> f32 {\n // Reservoir replacement needs the full [0, 1) interval: sample1D's EPS\n // remapping makes small positive replacement probabilities unreachable.\n // Preserve the legacy sequential RNG draw in the random sampling mode so\n // subsequent path samples retain their stream; selection uses the hash.\n if (SAMPLING_PATTERN == 2) { _ = rand(); }\n let pixelID = samplingPixel.x + samplingPixel.y * u32(rtUniform.outputSize.x);\n let key = sampleSeed(sampleSeed(pixelID, pixelSampleIndex), rtUniform.sequenceSeed);\n let dimension = sampleSeed(samplingBounce, salt) ^ 0xa511e9b3u;\n return f32(sampleHash(key ^ dimension) >> 8u) * (1.0 / 16777216.0);\n}\n\n// MIS weight of a light-sampled contribution. With several resampled\n// candidates the NEE technique is drawn neeCandidateCount() times.\nfn neeMISWeight(lightPdf: f32, scatteringPdf: f32) -> f32 {\n let candidateCount = neeCandidateCount();\n if (candidateCount <= 1u) {\n return sampling_power_heuristic(lightPdf, scatteringPdf);\n }\n let weightedLightPdf = f32(candidateCount) * lightPdf;\n return weightedLightPdf /\n max(weightedLightPdf + scatteringPdf, 1e-20);\n}\n\n// MIS weight of a BSDF-sampled ray that hits a light.\nfn bsdfMISWeight(scatteringPdf: f32, lightPdf: f32) -> f32 {\n let candidateCount = neeCandidateCount();\n if (candidateCount <= 1u) {\n return sampling_power_heuristic(scatteringPdf, lightPdf);\n }\n let weightedLightPdf = f32(candidateCount) * lightPdf;\n return scatteringPdf /\n max(scatteringPdf + weightedLightPdf, 1e-20);\n}\n\n${createSampleMaterialWgsl(hasAnisotropyDirections, hasCoatNormals)}\n${sampleShadowCatcherWgsl}\n\n// Output\n@group(3) @binding(0) var<storage, read_write> outColor: array<vec4f>;\n@group(3) @binding(1) var<storage, read_write> outNormal: array<vec4f>;\n@group(3) @binding(2) var<storage, read_write> outAlbedo: array<vec4f>;\n\n${shadowCatcherAccumulationWGSL}\n@group(3) @binding(3) var<storage, read_write> outShadowCatcher: array<ShadowCatcherAccumulation>;\n\n\nfn accumulateNormalOrVariance(\n pixelIndex: u32,\n radiance: vec3f,\n normal: vec3f\n) {\n if (rtUniform.varianceMoments != 0) {\n let value = dot(radiance, luminance);\n outNormal[pixelIndex] += vec4f(value * value, 0.0, 0.0, 1.0);\n }\n else {\n outNormal[pixelIndex] += vec4f(normal, 1.0);\n }\n}\n\n// Moments of the per-sample value the built-in denoiser compares, used to\n// estimate the variance of each pixel's mean.\nfn accumulateDenoiseMoments(pixelIndex: u32, value: f32) {\n outShadowCatcher[pixelIndex].moments += vec4f(value, value * value, 0.0, 0.0);\n}\n\n\nstruct RayTraceAuxiliary {\n // Denoising guides and auxiliary pixel classification.\n albedo: vec3f,\n isShadowCatcher: bool,\n normal: vec3f,\n isBlank: bool,\n}\n\nfn groundedSurfaceDistance(point: vec3f, height: f32, radius: f32) -> f32 {\n let pointLength = length(point);\n if (pointLength < 0.00001) {\n return -radius;\n }\n\n let originalY = radius * point.y / pointLength;\n let transitionY = -1.5 * height;\n var surfaceRadius: f32;\n if (originalY >= 0.0) {\n surfaceRadius = radius;\n }\n else if (originalY < transitionY) {\n surfaceRadius = -height * pointLength / point.y;\n }\n else {\n let factor = 1.0\n - originalY * originalY / (3.0 * transitionY * transitionY);\n surfaceRadius = radius * factor;\n }\n return pointLength - surfaceRadius;\n}\n\nfn groundedBackgroundDirection(origin: vec3f, direction: vec3f) -> vec3f {\n if (!USE_GROUNDED_BACKGROUND) {\n return direction;\n }\n let params = rtUniform.groundedBackgroundParams;\n let rayDirection = normalize(direction);\n let center = vec3f(\n rtUniform.groundedBackgroundCenter.x,\n params.z + params.x,\n rtUniform.groundedBackgroundCenter.y\n );\n let localOrigin = origin - center;\n let projectedOrigin = dot(localOrigin, rayDirection);\n let discriminant = projectedOrigin * projectedOrigin\n - dot(localOrigin, localOrigin) + params.y * params.y;\n if (\n discriminant <= 0.0\n || groundedSurfaceDistance(localOrigin, params.x, params.y) > 0.0\n ) {\n return direction;\n }\n\n var farDistance = -projectedOrigin + sqrt(discriminant);\n if (farDistance <= 0.0) {\n return direction;\n }\n\n let sphereHit = localOrigin + rayDirection * farDistance;\n if (sphereHit.y >= 0.0) {\n return normalize(sphereHit);\n }\n\n if (rayDirection.y < -0.00001 && params.y > 1.5 * params.x) {\n let groundDistance = (-params.x - localOrigin.y) / rayDirection.y;\n let groundHit = localOrigin + rayDirection * groundDistance;\n let groundRadius = (2.0 / 3.0)\n * sqrt(params.y * params.y - 2.25 * params.x * params.x);\n if (groundDistance > 0.0 && length(groundHit.xz) <= groundRadius) {\n return normalize(groundHit);\n }\n }\n\n var nearDistance = 0.0;\n for (var i = 0; i < 14; i++) {\n let middleDistance = (nearDistance + farDistance) * 0.5;\n let middlePoint = localOrigin + rayDirection * middleDistance;\n if (groundedSurfaceDistance(middlePoint, params.x, params.y) > 0.0) {\n farDistance = middleDistance;\n }\n else {\n nearDistance = middleDistance;\n }\n }\n let hit = localOrigin + rayDirection * ((nearDistance + farDistance) * 0.5);\n return normalize(hit);\n}\n\nfn sampleSceneBackground(ray: Ray) -> vec4f {\n var bg = vec4f(0.0);\n if (USE_BACKGROUND_MAP) {\n let d = groundedBackgroundDirection(ray.o, ray.d);\n let t = rtUniform.backgroundMapTransform;\n let backgroundDirection = vec3f(t.x * d.x - t.y * d.z, d.y, t.y * d.x + t.x * d.z);\n let backgroundSample = textureLinear(backgroundMap, cartesianToEquirect(backgroundDirection));\n bg = vec4f(backgroundSample.rgb * t.z, backgroundSample.a);\n }\n else if (USE_BACKGROUND) {\n bg = rtUniform.backgroundColor;\n }\n else if (USE_ENVMAP) {\n bg = textureLinear(envMap, environmentUv(ray.d));\n }\n return bg;\n}\n\nfn sampleSpectralSceneBackground(ray: Ray, wavelength: f32) -> vec4f {\n let bg = sampleSceneBackground(ray);\n if (SPECTRAL) {\n return vec4f(sampling_spectral_rgb_filter(bg.rgb, wavelength), bg.a);\n }\n return bg;\n}\n\nfn bounce(uv: vec2f, path: ptr<function, Path>, depth: ptr<function, i32>, si: ptr<function, SurfaceInteraction>, ma: ptr<function, OpenPbrResolvedMaterial>, outAux: ptr<function, RayTraceAuxiliary>) {\n samplingBounce = u32(max(*depth, 0));\n let matType = (*ma).materialType;\n let isShadowCatcher = matType == SHADOW_CATCHER;\n if (isShadowCatcher) {\n if ((*path).fromEye) {\n (*si).hit = false;\n }\n else {\n // The catcher only contributes to the separate shadow mask. Secondary\n // rays must see the environment behind it instead of its default white\n // material, otherwise it appears in reflections.\n if (USE_ENVMAP) {\n if ((*path).isNextRefraction) {\n // A camera-visible transmitted ray can hit the invisible catcher\n // before the grounded skybox. Preserve the displayed projection.\n let bg = sampleSpectralSceneBackground(\n (*path).ray,\n (*si).wavelength\n );\n let backgroundMisWeight = select(bsdfMISWeight((*path).scatteringPdf,\n envMapPdf(environmentUv((*path).ray.d)) * rtUniform.envLightPmf),\n 1.0, (*path).scatteringIsDelta);\n (*path).li += backgroundMisWeight * (*path).beta * bg.rgb * bg.a;\n (*path).alpha = max((*path).alpha, bg.a);\n }\n else {\n let envUv = environmentUv((*path).ray.d);\n var emission = textureLinear(envMap, envUv).rgb;\n if (SPECTRAL) {\n emission = sampling_spectral_rgb_filter(emission, (*si).wavelength);\n }\n (*path).li += (*path).beta * emission *\n bsdfMISWeight((*path).scatteringPdf, envMapPdf(envUv));\n }\n }\n else {\n let bg = sampleSpectralSceneBackground(\n (*path).ray,\n (*si).wavelength\n );\n (*path).li += (*path).beta * bg.rgb * bg.a;\n }\n (*path).abort = true;\n return;\n }\n }\n if (!(*si).hit) {\n // The spectral integrator traces red, green, and blue paths separately.\n // Split background radiance by wavelength as well so the three paths\n // reconstruct the skybox instead of adding three full RGB copies.\n let bg = sampleSpectralSceneBackground(\n (*path).ray,\n (*si).wavelength\n );\n if ((*path).fromEye) {\n // Sample from background if first ray not hit anything.\n (*path).li = (*path).beta * bg.rgb * bg.a;\n (*path).alpha = bg.a;\n // Only treat as blank pixels when the background is transparent\n (*outAux).isBlank = bg.a < 0.001 ||\n (USE_BACKGROUND && !USE_BACKGROUND_MAP);\n }\n else {\n let cam = initCameraRay(uv);\n let towardsCam = dot(cam.d, (*path).ray.d) > 0.0;\n if (rtUniform.transmissiveOutputAlphaMin < 1.0) {\n if (towardsCam) {\n (*path).alpha = max((*path).alpha, bg.a);\n } else {\n (*path).alpha = 1.0;\n }\n }\n if (!USE_ENVMAP) {\n // A display background is not an illumination environment, but a\n // visible secondary ray (e.g. through glass) still resolves it.\n if (towardsCam) {\n // This is a terminal BSDF-hit contribution, not a replacement for\n // NEE accumulated at earlier vertices on the same path.\n (*path).li += (*path).beta *\n bsdfMISWeight((*path).scatteringPdf, 1.0) * bg.rgb;\n }\n }\n }\n (*path).abort = true;\n return;\n }\n\n var sampleIgnored = false;\n if ((matType == STANDARD || matType == UNLIT)) {\n let alpha = clamp((*ma).alpha, 0.0, 1.0);\n \n if (alpha < 1.0) {\n // Alpha is stochastic coverage. Keep accepted surface radiance at full\n // weight instead of multiplying it by alpha a second time.\n if (alpha <= 0.0 || hashedSample(3u) > alpha) {\n sampleIgnored = true;\n }\n }\n if (!sampleIgnored && rtUniform.transmissiveOutputAlphaMin < 1.0) {\n // A selected stochastic coverage sample is fully covered. Ignored\n // samples leave output alpha untouched and continue to the back layer.\n let outputAlpha = max(1.0 - (*ma).transmissionWeight, 1.0 - pow(1.0 - rtUniform.transmissiveOutputAlphaMin, f32(*depth)));\n (*path).alpha = max(outputAlpha, (*path).alpha);\n }\n if (!sampleIgnored) {\n bounceIndex = u32(max(*depth, 0));\n SampleMaterial(si, ma, path);\n }\n else {\n // Alpha-null traversal does not consume the receiver event. The first\n // accepted surface behind it is still the receiver for NEE/AOVs.\n (*path).ray.o = (*si).position + (*path).ray.d * EPS;\n }\n }\n\n if (!(*si).albedoSampled && !sampleIgnored) {\n // Select denoising guides.\n if ((matType == STANDARD || matType == UNLIT)) {\n if (!((*ma).transmissionWeight > 0.5 ||\n ((*ma).specularRoughness <= 0.02 && (*ma).baseMetalness > 0.98))) {\n (*outAux).albedo = (*ma).baseColor;\n (*outAux).normal = select(\n (*si).normal,\n -(*si).normal,\n dot(\n (*si).normal,\n (*si).position - cameraUniform.viewInv[3].xyz\n ) > 0.0\n );\n (*si).albedoSampled = true;\n }\n // TODO pick albedo and normal on the surface if ray is too deep and can't hit any rough or opaque surfaces.\n if (*depth > 4) {\n (*si).albedoSampled = true;\n }\n }\n }\n\n // Russian roulette with throughput compensation.\n if (USE_RR) {\n if (*depth >= RR_MAX && !sampleIgnored) {\n let rouletteBeta = (*path).beta;\n // Max-component survival (pbrt-v4) avoids over-amplifying saturated paths.\n let maxComponent = max(max(rouletteBeta.x, rouletteBeta.y), rouletteBeta.z);\n let q: f32 = max(0.0, 1.0 - maxComponent);\n if (sample1D(bounceDim(RUSSIAN_ROULETTE)) < q) {\n // TODO we force use alpha 1.0 here.\n // To avoid the glass pixels is transparent even if it's on an opaque object.\n (*path).alpha = 1.0;\n (*path).abort = true;\n }\n else {\n (*path).beta /= 1.0 - q;\n }\n }\n }\n if ((*path).abort) {\n return;\n }\n\n intersectScene((*path).ray, si, *depth, true, (*path).isNextRefraction);\n getMaterial(ma, (*si).materialIndex, (*si).uv, (*si).uv1, (*si).instanceIndex, (*si).vertexColor);\n\n if (SPECTRAL) {\n // Is glass\n if ((*ma).transmissionWeight > 0.001) {\n (*ma).specularIor = sampling_cauchy_ior(\n (*si).wavelength,\n (*ma).specularIor,\n (*ma).transmissionDispersionScale,\n (*ma).dispersionAbbeNumber\n );\n }\n }\n\n if (sampleIgnored) {\n return;\n }\n\n // Use light if hit the light\n var lightSample: LightSampleRec;\n let isAlphaOccluded = hashedSample(3u) < (*ma).alpha;\n for (var i = 0; i < rtUniform.lightsCount; i++) {\n // Fetch light Data\n let light: Light = analyticLights[i];\n let d = intersectLight((*path).ray, light, &lightSample);\n lightSample.pdf *= light.selectionPmf;\n let occluded = (*si).hit && d > distance((*si).position, (*path).ray.o);\n if (d != INF && !(occluded && isAlphaOccluded)) {\n let misWeight = bsdfMISWeight((*path).scatteringPdf, lightSample.pdf);\n if (SPECTRAL) {\n lightSample.emission = sampling_spectral_rgb_filter(lightSample.emission, (*si).wavelength);\n }\n (*path).li += misWeight * (*path).beta * lightSample.emission;\n (*path).alpha = 1.0;\n (*path).abort = true;\n }\n }\n\n if (USE_ENVMAP) {\n if (!((*si).hit && isAlphaOccluded)) {\n if ((*path).isNextRefraction) {\n // Camera-visible transmission follows the displayed background,\n // including grounded projection. Other rays use the raw environment\n // map as the physically sampled lighting source.\n let bg = sampleSpectralSceneBackground(\n (*path).ray,\n (*si).wavelength\n );\n let backgroundMisWeight = select(bsdfMISWeight((*path).scatteringPdf,\n envMapPdf(environmentUv((*path).ray.d)) * rtUniform.envLightPmf),\n 1.0, (*path).scatteringIsDelta);\n (*path).li += backgroundMisWeight * (*path).beta * bg.rgb * bg.a;\n (*path).alpha = max((*path).alpha, bg.a);\n (*path).abort = true;\n return;\n }\n let _uv = environmentUv((*path).ray.d);\n var emission = textureLinear(envMap, _uv).rgb;\n let misWeight = bsdfMISWeight(\n (*path).scatteringPdf,\n envMapPdf(_uv) * rtUniform.envLightPmf\n );\n if (SPECTRAL) {\n emission = sampling_spectral_rgb_filter(emission, (*si).wavelength);\n }\n // TODO force the min alpha to be 1 when showing envmap as background\n if (!USE_BACKGROUND) {\n (*path).alpha = 1.0;\n }\n (*path).li += (*path).beta * emission * misWeight;\n (*path).abort = true;\n }\n }\n\n *depth = *depth + 1;\n}\n\nfn initCameraRay(coord: vec2f) -> Ray {\n let origin = cameraUniform.viewProjectionInv * vec4f(coord * 2.0 - 1.0, -1.0, 1.0);\n let center = cameraUniform.viewProjectionInv * vec4f(coord * 2.0 - 1.0, 1.0, 1.0);\n var cam: Ray;\n initRay(&cam, origin.xyz / origin.w, normalize(center.xyz * origin.w - origin.xyz * center.w));\n\n return cam;\n}\n\n\nfn bevelCubicSample(radius: f32, xi: f32) -> vec2f {\n var x = 0.25;\n for (var iteration = 0; iteration < 10; iteration++) {\n let x2 = x * x;\n let x3 = x2 * x;\n let oneMinusX = 1.0 - x;\n let value = 10.0 * x2 - 20.0 * x3 + 15.0 * x2 * x2 -\n 4.0 * x2 * x3 - xi;\n let derivative = 20.0 * x * oneMinusX * oneMinusX * oneMinusX;\n if (abs(value) < 1e-6 || derivative == 0.0) { break; }\n x = clamp(x - value / derivative, 0.0, 1.0);\n }\n let diskRadius = x * radius;\n return vec2f(diskRadius, sqrt(max(radius * radius - diskRadius * diskRadius, 0.0)));\n}\n\nfn bevelCubicPdf(radius: f32, distanceToSource: f32) -> f32 {\n if (distanceToSource >= radius) { return 0.0; }\n let falloff = radius - distanceToSource;\n return falloff * falloff * falloff;\n}\n\n// Shader bevel. Usage: docs/materials.md (Renderer extensions)\nfn getBevelNormal(source: SurfaceInteraction, radius: f32) -> vec3f {\n var geometricNormal = source.faceNormal;\n if (dot(geometricNormal, source.vertexNormal) < 0.0) {\n geometricNormal = -geometricNormal;\n }\n var tangent: vec3f;\n var bitangent: vec3f;\n sampling_orthonormal_basis(geometricNormal, &tangent, &bitangent);\n var normalSum = vec3f(0.0);\n\n for (var sampleIndex = 0; sampleIndex < BEVEL_SAMPLES; sampleIndex++) {\n let bevelRnd = sample2D(CAMERA_BEVEL_BASE + u32(sampleIndex));\n var axisSample = bevelRnd.x;\n let radialSample = bevelRnd.y;\n var diskNormal = geometricNormal;\n var diskTangent = tangent;\n var diskBitangent = bitangent;\n var pickPdfNormal = 0.5;\n var pickPdfTangent = 0.25;\n var pickPdfBitangent = 0.25;\n if (axisSample < 0.5) {\n axisSample *= 2.0;\n }\n else if (axisSample < 0.75) {\n let swapAxis = diskNormal;\n diskNormal = diskTangent;\n diskTangent = swapAxis;\n pickPdfNormal = 0.25;\n pickPdfTangent = 0.5;\n axisSample = (axisSample - 0.5) * 4.0;\n }\n else {\n let swapAxis = diskNormal;\n diskNormal = diskBitangent;\n diskBitangent = swapAxis;\n pickPdfNormal = 0.25;\n pickPdfBitangent = 0.5;\n axisSample = (axisSample - 0.75) * 4.0;\n }\n\n let diskSample = bevelCubicSample(radius, radialSample);\n let phi = TWOPI * axisSample;\n let diskOffset = diskSample.x *\n (cos(phi) * diskTangent + sin(phi) * diskBitangent);\n var ray: Ray;\n initRay(\n &ray,\n source.position + diskNormal * diskSample.y + diskOffset,\n -diskNormal\n );\n var hit: SurfaceInteraction;\n intersectSceneBevel(\n ray,\n &hit,\n source.instanceIndex,\n max(2.0 * diskSample.y, EPS)\n );\n if (!hit.hit) { continue; }\n\n let pdfNormal = pickPdfNormal * abs(dot(diskNormal, hit.faceNormal));\n let pdfTangent = pickPdfTangent * abs(dot(diskTangent, hit.faceNormal));\n let pdfBitangent = pickPdfBitangent * abs(dot(diskBitangent, hit.faceNormal));\n var weight = pdfNormal / max(\n pdfNormal * pdfNormal + pdfTangent * pdfTangent +\n pdfBitangent * pdfBitangent,\n 1e-8\n );\n weight *= bevelCubicPdf(radius, distance(hit.position, source.position)) /\n max(bevelCubicPdf(radius, diskSample.x), 1e-8);\n normalSum += weight * hit.vertexNormal;\n }\n\n if (dot(normalSum, normalSum) <= 1e-12) { return source.normal; }\n let bevelVertexNormal = normalize(normalSum);\n let result = source.normal + bevelVertexNormal - source.vertexNormal;\n if (dot(result, result) > 1e-12) { return normalize(result); }\n return source.normal;\n}\n\nfn integrateOnePathSample(uv: vec2f, si: ptr<function, SurfaceInteraction>, ray: Ray, ma: ptr<function, OpenPbrResolvedMaterial>, outAux: ptr<function, RayTraceAuxiliary>) -> vec4f {\n var path: Path;\n path.ray = ray;\n path.li = vec3f(0.0);\n path.alpha = select(1.0, 0.0, rtUniform.transmissiveOutputAlphaMin < 1.0);\n path.beta = vec3f(1.0);\n path.fromEye = true;\n path.scatteringPdf = 0.0;\n path.scatteringIsDelta = false;\n path.isNextRefraction = false;\n path.abort = false;\n\n let isNotTransparent = (*ma).transmissionWeight < 0.001 && (*ma).subsurfaceWeight < 0.001 && (*ma).alpha > 0.99;\n let bounceLimit = max(rtUniform.bounces, 0);\n var depth = 0;\n // Transparent paths may take up to three times the configured bounces.\n for (var idx: i32 = 0; idx < min(bounceLimit * 3, ${MAX_PATH_EVENTS}); idx = idx + 1) {\n if (isNotTransparent && idx > bounceLimit) {\n path.abort = true;\n }\n if (path.abort) {\n break;\n }\n bounce(uv, &path, &depth, si, ma, outAux);\n }\n\n return vec4f(path.li, path.alpha);\n}\n\nfn integrateOnePath(uv: vec2f, si: ptr<function, SurfaceInteraction>, ray: Ray, ma: ptr<function, OpenPbrResolvedMaterial>, outAux: ptr<function, RayTraceAuxiliary>) -> vec4f {\n ${deterministicPrimaryAlpha ? /* wgsl */ `let coverage = clamp((*ma).alpha, 0.0, 1.0);\n if (!(*si).hit || ((*ma).materialType != STANDARD && (*ma).materialType != UNLIT) || coverage >= 1.0) {\n return integrateOnePathSample(uv, si, ray, ma, outAux);\n }\n\n // glTF BLEND is source-over opacity, not a physical glass boundary. Split\n // the primary ray so reflected radiance is attenuated by alpha every sample\n // while the complementary branch continues straight to the scene behind it.\n // Secondary alpha hits remain stochastic to avoid exponential path growth.\n var backRay = ray;\n backRay.o = (*si).position + ray.d * (EPS * 0.02);\n var backSi = *si;\n backSi.albedoSampled = false;\n intersectScene(backRay, &backSi, 0, false, false);\n var backMa: OpenPbrResolvedMaterial;\n getMaterial(&backMa, backSi.materialIndex, backSi.uv, backSi.uv1, backSi.instanceIndex, backSi.vertexColor);\n var backAux = *outAux;\n if (backSi.hit && backMa.materialType == STANDARD) {\n backAux.albedo = select(\n backMa.baseColor,\n vec3f(1.0),\n backMa.transmissionWeight > 0.5\n );\n backAux.normal = select(\n backSi.normal,\n -backSi.normal,\n dot(\n backSi.normal,\n backSi.position - cameraUniform.viewInv[3].xyz\n ) > 0.0\n );\n backSi.albedoSampled = backMa.transmissionWeight > 0.5;\n }\n let back = integrateOnePathSample(\n uv, &backSi, backRay, &backMa, &backAux\n );\n if (coverage <= 0.0) {\n *outAux = backAux;\n return back;\n }\n\n var frontSi = *si;\n var frontMa = *ma;\n frontMa.alpha = 1.0;\n var frontAux = *outAux;\n let front = integrateOnePathSample(\n uv, &frontSi, ray, &frontMa, &frontAux\n );\n (*outAux).albedo = mix(backAux.albedo, frontAux.albedo, coverage);\n let blendedNormal = mix(backAux.normal, frontAux.normal, coverage);\n (*outAux).normal = select(\n vec3f(0.0),\n normalize(blendedNormal),\n dot(blendedNormal, blendedNormal) > 1e-12\n );\n (*outAux).isBlank = backAux.isBlank && frontAux.isBlank;\n (*outAux).isShadowCatcher = backAux.isShadowCatcher && frontAux.isShadowCatcher;\n return mix(back, front, coverage);` : /* wgsl */ `return integrateOnePathSample(uv, si, ray, ma, outAux);`}\n}\n\n// Path tracing integrator as described in\n// http://www.pbr-book.org/3ed-2018/Light_Transport_I_Surface_Reflection/Path_Tracing.html#\nfn integrator(uv: vec2f, ray: Ray, outAux: ptr<function, RayTraceAuxiliary>) -> vec4f {\n var si: SurfaceInteraction;\n var ma: OpenPbrResolvedMaterial;\n si.albedoSampled = false;\n si.mediumType = 0;\n si.mediumExtinction = vec3f(0.0);\n si.mediumScattering = vec3f(0.0);\n si.mediumAnisotropy = 0.0;\n si.barycentrics = vec2f(0.0);\n\n // TODO not put tMax in ray. So we don't need to use pointer of ray here.\n intersectScene(ray, &si, 0, false, false);\n getMaterial(&ma, si.materialIndex, si.uv, si.uv1, si.instanceIndex, si.vertexColor);\n\n if (si.hit && ma.materialType == SHADOW_CATCHER) {\n (*outAux).isShadowCatcher = true;\n // The composed denoising input includes this receiver's shadow. Supply\n // neutral reflectance and its shading normal, independent of visibility.\n (*outAux).albedo = vec3f(1.0);\n (*outAux).normal = select(si.normal, -si.normal, dot(si.normal, ray.d) > 0.0);\n var path: Path;\n path.ray = ray;\n path.fromEye = true;\n sampleShadowCatcher(si, 0, &path);\n // RGB stores primary catcher coverage independently from the stochastic\n // visibility in alpha. Composition uses this raw coverage to clip any\n // shadow-mask denoising bleed at model silhouettes.\n return vec4f(vec3f(1.0), path.alpha);\n }\n else {\n if (HAS_BEVEL && rtUniform.bevel != 0) {\n if (ma.bevel > 0.0) {\n si.normal = getBevelNormal(si, ma.bevel);\n }\n }\n\n // Store a clean first-hit fallback. Glass retains this stable guide;\n // other delta paths may replace it at their first non-delta hit.\n if (si.hit && (ma.materialType == STANDARD || ma.materialType == UNLIT)) {\n (*outAux).albedo = select(ma.baseColor, vec3f(1.0), ma.transmissionWeight > 0.5);\n (*outAux).normal = select(\n si.normal,\n -si.normal,\n dot(si.normal, si.position - cameraUniform.viewInv[3].xyz) > 0.0\n );\n\n // Do not replace a glass guide with a randomly selected downstream\n // refraction/reflection hit; OIDN auxiliary features must stay clean.\n si.albedoSampled = ma.transmissionWeight > 0.5;\n }\n\n (*outAux).isShadowCatcher = false;\n\n if (SPECTRAL) {\n // Keep one source-level integrateOnePath call for both interactive\n // preview and offline RGB splitting. A runtime loop bound prevents the\n // WGSL compiler from cloning the full path graph three times while the\n // uniform still selects the exact existing preview/offline behavior.\n let rgbWaveLengths = array<f32, 3>(650.0, 510.0, 475.0);\n var colAccum = vec3f(0.0);\n var alpha = 0.0;\n var accumulatedGuideAlbedo = vec3f(0.0);\n var accumulatedGuideNormal = vec3f(0.0);\n var allBlank = true;\n var si2 = si;\n var ma2 = ma;\n let wavelengthRngState = s0;\n let wavelengthHashedCounter = hashedCounter;\n let singleWavelength = rtUniform.dispersionWavelengths == 1;\n let dispersivePrimary = si.hit &&\n ma.transmissionWeight > 0.001 &&\n ma.transmissionDispersionScale > 0.001;\n let wavelengthCount = select(3, 1, singleWavelength);\n var heroWavelengthIndex = 0;\n if (singleWavelength && dispersivePrimary) {\n // Stochastic hero wavelength: one RGB channel per pixel keeps the\n // preview spectral at one-third of the full three-path cost.\n heroWavelengthIndex = min(i32(floor(sample1D(CAMERA_WAVELENGTH) * 3.0)), 2);\n }\n for (var i = 0; i < wavelengthCount; i++) {\n // Common random numbers keep Monte Carlo error correlated between\n // RGB wavelengths. This removes much of the colored variance that\n // otherwise turns into dirty chromatic patches after OIDN.\n if (!singleWavelength) {\n s0 = wavelengthRngState;\n hashedCounter = wavelengthHashedCounter;\n samplingBounce = 0u;\n }\n si.wavelength = 0.0;\n if (!singleWavelength || dispersivePrimary) {\n si.wavelength = rgbWaveLengths[select(i, heroWavelengthIndex, singleWavelength)];\n ma.specularIor = sampling_cauchy_ior(\n si.wavelength,\n ma.specularIor,\n ma.transmissionDispersionScale,\n ma.dispersionAbbeNumber\n );\n }\n var wavelengthAux: RayTraceAuxiliary;\n if (singleWavelength) {\n wavelengthAux = *outAux;\n } else {\n wavelengthAux.albedo = (*outAux).albedo;\n wavelengthAux.normal = (*outAux).normal;\n wavelengthAux.isBlank = false;\n wavelengthAux.isShadowCatcher = false;\n }\n let res = integrateOnePath(uv, &si, ray, &ma, &wavelengthAux);\n if (singleWavelength) {\n *outAux = wavelengthAux;\n let scale = select(1.0, 3.0, dispersivePrimary);\n return vec4f(res.rgb * scale, res.a);\n }\n colAccum += res.rgb;\n alpha = max(alpha, res.a);\n accumulatedGuideAlbedo += wavelengthAux.albedo;\n accumulatedGuideNormal += wavelengthAux.normal;\n allBlank = allBlank && wavelengthAux.isBlank;\n si = si2;\n ma = ma2;\n }\n (*outAux).albedo = accumulatedGuideAlbedo / 3.0;\n (*outAux).normal = accumulatedGuideNormal / 3.0;\n (*outAux).isBlank = allBlank;\n return vec4f(colAccum, alpha);\n }\n else {\n return integrateOnePath(uv, &si, ray, &ma, outAux);\n }\n }\n}\n\nfn sampleCircle(ip: vec2f) -> vec2f {\n let p = 2.0 * ip - 1.0;\n let greater = abs(p.x) > abs(p.y);\n let r = select(p.y, p.x, greater);\n let theta = select(PI * (0.5 - 0.25 * p.x / p.y), 0.25 * PI * p.y / p.x, greater);\n return r * vec2f(cos(theta), sin(theta));\n}\n\n\n@compute @workgroup_size(${WORKGROUP_SIZE}, ${WORKGROUP_SIZE}, 1)\nfn main(@builtin(global_invocation_id) globalId: vec3u) {\n let outputSize = rtUniform.outputSize;\n let scaleOffset = rtUniform.scaleOffset;\n var jitter = rtUniform.jitter;\n // TODO if outputSize is not multiple of 8?\n let coord = globalId.xy * vec2u(scaleOffset.xy) + vec2u(scaleOffset.zw);\n if (coord.x >= u32(outputSize.x) || coord.y >= u32(outputSize.y)) {\n return;\n }\n let idx = coord.x + coord.y * u32(outputSize.x);\n\n if (\n rtUniform.adaptiveSampling != 0 &&\n outNormal[idx].a >= textureLoad(\n adaptiveSampleTargets,\n vec2i(coord),\n 0\n ).r\n ) {\n return;\n }\n\n // Match WebGL's rasterized v_Texcoord, whose sample is at the center of\n // each pixel. Keeping the same origin is material relevant: a half-pixel\n // shift moves a narrow metal highlight across several pixels.\n let uv = (vec2<f32>(f32(coord.x), f32(coord.y)) + vec2f(0.5)) / outputSize;\n\n samplingPixel = coord;\n pixelSampleIndex = u32(outNormal[idx].a) + rtUniform.sampleSequenceOffset;\n samplingBounce = 0u; hashedCounter = 0u;\n if (SAMPLING_PATTERN == 0 || SAMPLING_PATTERN == 1) {\n jitter = (sample2D(CAMERA_PIXEL) - 0.5) / outputSize;\n }\n rng_initialize(coord, i32(pixelSampleIndex ^ sampleHash(rtUniform.sequenceSeed)));\n var cam = initCameraRay(uv + jitter);\n\n if (cameraUniform.apertureRadius > 0.0) {\n // Thin lens: the focus plane is perpendicular to the view direction.\n let eye = cameraUniform.viewInv[3].xyz;\n let forward = -normalize(cameraUniform.viewInv[2].xyz);\n let focusPoint = eye + cam.d * (cameraUniform.focusDistance / dot(cam.d, forward));\n let lensPoint = cameraUniform.apertureRadius * sampleCircle(sample2D(CAMERA_LENS));\n let origin = (cameraUniform.viewInv * vec4f(lensPoint, 0.0, 1.0)).xyz;\n let dir = normalize(focusPoint - origin);\n initRay(&cam, origin, dir);\n }\n\n var outAux: RayTraceAuxiliary;\n outAux.albedo = vec3f(0.0);\n outAux.normal = vec3f(0.0);\n outAux.isBlank = false;\n outAux.isShadowCatcher = false;\n var liAndAlpha = integrator(uv + jitter, cam, &outAux);\n\n // Clamp at Integration Level to reduce fireflies.\n // TODO Path level configuration?\n if (rtUniform.clamping > 0.0) {\n let clamping = rtUniform.clamping;\n liAndAlpha = vec4(clamp(liAndAlpha.rgb, -vec3f(clamping), vec3f(clamping)), liAndAlpha.a);\n }\n if (!(liAndAlpha.x < INF && liAndAlpha.x > -EPS)) {\n liAndAlpha = vec4f(0.0, 0.0, 0.0, 1.0);\n }\n\n if (outAux.isShadowCatcher) {\n // The catcher is invisible, so the main color at this pixel must still\n // contain whatever the camera ray would have seen behind it.\n let backgroundSample = sampleSceneBackground(cam);\n let backgroundHit = select(0.0, 1.0, backgroundSample.a >= 0.01);\n let backgroundPremultiplied = vec4f(backgroundSample.rgb * backgroundSample.a, backgroundSample.a);\n // Keep the background contribution separate from geometry at silhouettes.\n // mask: catcher coverage, background alpha, background hits, shadow opacity.\n outShadowCatcher[idx].mask += vec4f(1.0, backgroundSample.a, backgroundHit, liAndAlpha.a);\n outShadowCatcher[idx].background += backgroundPremultiplied;\n outColor[idx] += backgroundPremultiplied;\n outAlbedo[idx] += vec4f(outAux.albedo, backgroundHit);\n accumulateNormalOrVariance(idx, backgroundSample.rgb, outAux.normal);\n // The composed catcher is the background darkened by the shadow. Over a\n // transparent background the shadow is only its opacity.\n let visibility = 1.0 - liAndAlpha.a;\n accumulateDenoiseMoments(idx, visibility * select(\n 1.0, dot(backgroundSample.rgb, luminance), backgroundSample.a >= 0.01\n ));\n }\n else {\n if (HAS_SHADOW_CATCHER && outAux.isBlank && USE_BACKGROUND && !USE_BACKGROUND_MAP && rtUniform.backgroundColor.a >= 0.99999) {\n // A primary miss sees the same opaque display backdrop as a catcher\n // hit, but must never receive its shadow. Keep that radiance and alpha\n // out of the geometry layer before hit-count normalization/tone mapping.\n // Red/blue still count only actual catcher hits; green counts all\n // background alpha removed from the foreground during normalization.\n outShadowCatcher[idx].background += liAndAlpha;\n outShadowCatcher[idx].mask.g += liAndAlpha.a;\n }\n outColor[idx] += liAndAlpha;\n outAlbedo[idx] += vec4f(outAux.albedo, select(1.0, 0.0, outAux.isBlank));\n accumulateNormalOrVariance(idx, liAndAlpha.rgb, outAux.normal);\n accumulateDenoiseMoments(idx, dot(liAndAlpha.rgb, luminance));\n }\n}\n`;\n // The query entry point shares the exact BVH and material implementation.\n // It has no effect on the beauty entry point or its bindings.\n // Gate optional material layers on scene-level feature flags so drivers can\n // skip the unused BSDF lobes.\n let specializedSource = source + depthQueryWGSL;\n const backgroundBits: Record<string, number> = {\n USE_BACKGROUND: 1,\n USE_BACKGROUND_MAP: 2,\n USE_GROUNDED_BACKGROUND: 4\n };\n specializedSource = specializedSource.replace(\n /\\b(?:USE_BACKGROUND|USE_BACKGROUND_MAP|USE_GROUNDED_BACKGROUND)\\b/g,\n (name) => `((rtUniform.backgroundFlags & ${backgroundBits[name]}) != 0)`\n );\n specializedSource = specializedSource.replace(\n new RegExp(`\\\\b(?:${Object.keys(WGPU_SCENE_FEATURE_BITS).join('|')})\\\\b`, 'g'),\n name => `((rtUniform.sceneFeatureFlags & ${WGPU_SCENE_FEATURE_BITS[name]}u) != 0u)`\n );\n return specializedSource;\n}\n"]}
@@ -1,14 +1,20 @@
1
1
  import Texture from './Texture.js';
2
+ import SceneNode from './SceneNode.js';
2
3
  /**
3
4
  * Image-based lighting from an equirectangular (latitude-longitude) HDR map,
4
5
  * for example one loaded with `loadRGBE()`. Importance sampled.
6
+ * `transform` rotates the environment from local to world space (default identity);
7
+ * translation and positive axis scale are ignored.
5
8
  */
6
- export default class EnvironmentLight {
9
+ export default class EnvironmentLight extends SceneNode {
7
10
  /** Light discriminator; always `EnvironmentLight`. */
8
11
  readonly type: "EnvironmentLight";
9
- /** Equirectangular radiance map in linear color. */
12
+ /** Equirectangular radiance map in linear color. The first row is the zenith (+Y); `flipY` is ignored. */
10
13
  map: Texture;
14
+ /** Nonnegative radiance multiplier; zero disables this light. Default `1`. */
15
+ intensity: number;
11
16
  constructor(params: {
12
- map: Texture;
17
+ /** Required equirectangular radiance map; no default. */ map: Texture;
18
+ /** Nonnegative radiance multiplier; zero disables this light. Default `1`. */ intensity?: number;
13
19
  });
14
20
  }
@@ -1,14 +1,21 @@
1
+ import SceneNode from './SceneNode.js';
1
2
  /**
2
3
  * Image-based lighting from an equirectangular (latitude-longitude) HDR map,
3
4
  * for example one loaded with `loadRGBE()`. Importance sampled.
5
+ * `transform` rotates the environment from local to world space (default identity);
6
+ * translation and positive axis scale are ignored.
4
7
  */
5
- export default class EnvironmentLight {
8
+ export default class EnvironmentLight extends SceneNode {
6
9
  /** Light discriminator; always `EnvironmentLight`. */
7
10
  type = 'EnvironmentLight';
8
- /** Equirectangular radiance map in linear color. */
11
+ /** Equirectangular radiance map in linear color. The first row is the zenith (+Y); `flipY` is ignored. */
9
12
  map;
13
+ /** Nonnegative radiance multiplier; zero disables this light. Default `1`. */
14
+ intensity = 1;
10
15
  constructor(params) {
16
+ super();
11
17
  this.map = params.map;
18
+ this.intensity = params.intensity ?? 1;
12
19
  }
13
20
  }
14
21
  //# sourceMappingURL=EnvironmentLight.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"EnvironmentLight.js","sourceRoot":"","sources":["../../src/scene/EnvironmentLight.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,gBAAgB;IACnC,sDAAsD;IAC7C,IAAI,GAAG,kBAA2B,CAAC;IAC5C,oDAAoD;IACpD,GAAG,CAAU;IACb,YAAY,MAAkF;QAC5F,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;IACxB,CAAC;CACF","sourcesContent":["import Texture from './Texture.js';\n\n/**\n * Image-based lighting from an equirectangular (latitude-longitude) HDR map,\n * for example one loaded with `loadRGBE()`. Importance sampled.\n */\nexport default class EnvironmentLight {\n /** Light discriminator; always `EnvironmentLight`. */\n readonly type = 'EnvironmentLight' as const;\n /** Equirectangular radiance map in linear color. */\n map: Texture;\n constructor(params: { /** Required equirectangular radiance map; no default. */ map: Texture }) {\n this.map = params.map;\n }\n}\n"]}
1
+ {"version":3,"file":"EnvironmentLight.js","sourceRoot":"","sources":["../../src/scene/EnvironmentLight.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,gBAAgB,CAAC;AAEvC;;;;;GAKG;AACH,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,SAAS;IACrD,sDAAsD;IAC7C,IAAI,GAAG,kBAA2B,CAAC;IAC5C,0GAA0G;IAC1G,GAAG,CAAU;IACb,8EAA8E;IAC9E,SAAS,GAAG,CAAC,CAAC;IACd,YAAY,MAGX;QACC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;QACtB,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,IAAI,CAAC,CAAC;IACzC,CAAC;CACF","sourcesContent":["import Texture from './Texture.js';\nimport SceneNode from './SceneNode.js';\n\n/**\n * Image-based lighting from an equirectangular (latitude-longitude) HDR map,\n * for example one loaded with `loadRGBE()`. Importance sampled.\n * `transform` rotates the environment from local to world space (default identity);\n * translation and positive axis scale are ignored.\n */\nexport default class EnvironmentLight extends SceneNode {\n /** Light discriminator; always `EnvironmentLight`. */\n readonly type = 'EnvironmentLight' as const;\n /** Equirectangular radiance map in linear color. The first row is the zenith (+Y); `flipY` is ignored. */\n map: Texture;\n /** Nonnegative radiance multiplier; zero disables this light. Default `1`. */\n intensity = 1;\n constructor(params: {\n /** Required equirectangular radiance map; no default. */ map: Texture;\n /** Nonnegative radiance multiplier; zero disables this light. Default `1`. */ intensity?: number;\n }) {\n super();\n this.map = params.map;\n this.intensity = params.intensity ?? 1;\n }\n}\n"]}
@@ -163,7 +163,7 @@ export default class OpenPBRMaterial {
163
163
  specularAnisotropyModel: 'openpbr' | 'gltf';
164
164
  /** Linear RG tangent direction and B strength multiplier for the base specular layer. Default `undefined`. */
165
165
  anisotropyMap?: Texture;
166
- /** Independent tangent-space coat normal in linear RGB. Without a map, coat shares the existing shading normal. Default `undefined`. */
166
+ /** Independent tangent-space coat normal in linear RGB. Without a map, coat uses the surface normal before base normal mapping. Default `undefined`. */
167
167
  coatNormalMap?: Texture;
168
168
  /** XY strength of coatNormalMap; independent of normalScale. Default `[1, 1]`. */
169
169
  coatNormalScale: Vec2;
@@ -168,7 +168,7 @@ export default class OpenPBRMaterial {
168
168
  specularAnisotropyModel = 'openpbr';
169
169
  /** Linear RG tangent direction and B strength multiplier for the base specular layer. Default `undefined`. */
170
170
  anisotropyMap;
171
- /** Independent tangent-space coat normal in linear RGB. Without a map, coat shares the existing shading normal. Default `undefined`. */
171
+ /** Independent tangent-space coat normal in linear RGB. Without a map, coat uses the surface normal before base normal mapping. Default `undefined`. */
172
172
  coatNormalMap;
173
173
  /** XY strength of coatNormalMap; independent of normalScale. Default `[1, 1]`. */
174
174
  coatNormalScale = materialDefault('coatNormalScale');
@@ -1 +1 @@
1
- {"version":3,"file":"OpenPBRMaterial.js","sourceRoot":"","sources":["../../src/scene/OpenPBRMaterial.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAO1E;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,OAAO,OAAO,eAAe;IAClC,4EAA4E;IAC5E,YAAY,SAAgC,EAAE;QAC5C,mBAAmB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACpC,CAAC;IAED,OAAO;IACP,yJAAyJ;IACzJ,UAAU,GAAW,eAAe,CAAC,YAAY,CAAC,CAAC;IACnD,sDA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IAC1E,eAAe,CAAW;IAC1B,yEAAyE;IACzE,wBAAwB,GAAiB,eAAe,CAAC,0BAA0B,CAAC,CAAC;IACrF,kEAAkE;IAClE,6BAA6B,GAAW,eAAe,CAAC,+BAA+B,CAAC,CAAC;IACzF,wFAAwF;IACxF,iBAAiB,GAAW,eAAe,CAAC,mBAAmB,CAAC,CAAC;IACjE,iIAAiI;IACjI,gBAAgB,GAAW,eAAe,CAAC,kBAAkB,CAAC,CAAC;IAC/D,4GAA4G;IAC5G,oBAAoB,GAAW,eAAe,CAAC,sBAAsB,CAAC,CAAC;CAExE;AACD,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,MAAM,EAAE,CAAC;IACT,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;CACA,CAAC;AAIX,MAAM,UAAU,wBAAwB,CACtC,QAAyB;IAEzB,IAAI,QAAQ,CAAC,SAAS,KAAK,MAAM;QAAE,OAAO,QAAQ,CAAC,SAAS,CAAC;IAC7D,IAAI,QAAQ,CAAC,WAAW,GAAG,CAAC;QAAE,OAAO,MAAM,CAAC;IAC5C,IACE,QAAQ,CAAC,OAAO,GAAG,CAAC;QACpB,QAAQ,CAAC,aAAa,KAAK,OAAO;QAClC,QAAQ,CAAC,QAAQ,EACjB,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["import type { Vec2 } from '../types.js';\nimport { ColorRGB } from '../types.js';\nimport type Texture from './Texture.js';\nimport type { ThinFilmMapChannel } from './thinFilmParameters.js';\nimport { materialDefault, applyMaterialParams } from './openPbrSchema.js';\n\nexport type UVProjection = 'none' | 'triplanar' | 'spherical' | 'cylindrical';\nexport type MaterialAlphaMode = 'auto' | 'opaque' | 'mask' | 'blend';\n\nexport type { MaterialTextureName } from './materialTextureNames.js';\n\n/**\n * OpenPBR 1.1 surface material.\n *\n * Property names are camelCase OpenPBR inputs plus documented compatibility names\n * (https://academysoftwarefoundation.github.io/OpenPBR/). Colors are linear\n * RGB. Length-valued inputs (`transmissionDepth`, `subsurfaceRadius`) use\n * scene units; `thinFilmThickness` is in micrometres as in OpenPBR.\n *\n * ```ts\n * const gold = new OpenPBRMaterial({\n * baseColor: [1.0, 0.78, 0.34], baseMetalness: 1, specularRoughness: 0.2\n * });\n * ```\n *\n * Edit parameters in place; the next `engine.update()` detects the changes.\n */\nexport default class OpenPBRMaterial {\n /** Creates a material. Omitted properties use their documented defaults. */\n constructor(params: OpenPBRMaterialParams = {}) {\n applyMaterialParams(this, params);\n }\n\n // Base\n /** Multiplier of diffuse reflection and metallic normal-incidence color; does not scale dielectric specular, transmission or subsurface. Default `1`. */\n baseWeight: number = materialDefault('baseWeight');\n /** Diffuse/metal color. Default `[0.8, 0.8, 0.8]`. */\n baseColor: ColorRGB = materialDefault('baseColor');\n /** Oren-Nayar style roughness of the diffuse lobe. Default `0`. */\n baseDiffuseRoughness: number = materialDefault('baseDiffuseRoughness');\n /** `0` dielectric, `1` metal. Default `0`. */\n baseMetalness: number = materialDefault('baseMetalness');\n\n // Specular\n /** Dielectric specular strength (via IOR) and overall metallic Fresnel multiplier. Default `1`. */\n specularWeight: number = materialDefault('specularWeight');\n /** Dielectric specular tint and metallic F82 near-grazing tint. Default `[1, 1, 1]`. */\n specularColor: ColorRGB = materialDefault('specularColor');\n /** Microfacet roughness, `0` mirror to `1` rough; retains source perceptual roughness in `gltf` anisotropy mode. Default `0.3`. */\n specularRoughness: number = materialDefault('specularRoughness');\n /** Index of refraction. Default `1.5`. */\n specularIor: number = materialDefault('specularIor');\n /**\n * GGX anisotropy strength, 0 to 1 (requires tangents); native OpenPBR or source glTF strength according to specularAnisotropyModel. Default `0`.\n * @deprecated Use specularRoughnessAnisotropy.\n */\n specularAnisotropy: number = materialDefault('specularAnisotropy');\n\n // Transmission\n /** `1` makes the dielectric base fully transmissive (glass). Default `0`. */\n transmissionWeight: number = materialDefault('transmissionWeight');\n /** Transmission tint, or the medium color at `transmissionDepth`. Default `[1, 1, 1]`. */\n transmissionColor: ColorRGB = materialDefault('transmissionColor');\n /** Depth at which `transmissionColor` is reached; `0` tints at the surface. Default `0`. */\n transmissionDepth: number = materialDefault('transmissionDepth');\n /** Volume scattering color of the transmissive medium. Default `[0, 0, 0]`. */\n transmissionScatter: ColorRGB = materialDefault('transmissionScatter');\n /** Henyey-Greenstein anisotropy of the medium, -1 to 1. Default `0`. */\n transmissionScatterAnisotropy: number = materialDefault('transmissionScatterAnisotropy');\n /** Dispersion strength; `> 0` enables spectral rendering. Default `0`. */\n transmissionDispersionScale: number = materialDefault('transmissionDispersionScale');\n /** Abbe number controlling dispersion. Default `20`. */\n transmissionDispersionAbbeNumber: number = materialDefault('transmissionDispersionAbbeNumber');\n\n // Subsurface\n /** Subsurface scattering weight. Default `0`. */\n subsurfaceWeight: number = materialDefault('subsurfaceWeight');\n /** Subsurface color. Default `[0.8, 0.8, 0.8]`. */\n subsurfaceColor: ColorRGB = materialDefault('subsurfaceColor');\n /** Mean free path in scene units. Default `1`. */\n subsurfaceRadius: number = materialDefault('subsurfaceRadius');\n /** Per-channel multiplier of `subsurfaceRadius`. Default `[1, 0.5, 0.25]`. */\n subsurfaceRadiusScale: ColorRGB = materialDefault('subsurfaceRadiusScale');\n /**\n * Scattering anisotropy, -1 to 1. Default `0`.\n * @deprecated Use subsurfaceScatterAnisotropy.\n */\n subsurfaceAnisotropy: number = materialDefault('subsurfaceAnisotropy');\n\n // Fuzz (sheen)\n /** Fuzz (sheen) layer weight. Default `0`. */\n fuzzWeight: number = materialDefault('fuzzWeight');\n /** Fuzz reflection color; substrate attenuation uses white fuzz albedo. Default `[1, 1, 1]`. */\n fuzzColor: ColorRGB = materialDefault('fuzzColor');\n /** Fuzz roughness; imported from Three.js `sheenRoughness`. Default `0.5`. */\n fuzzRoughness: number = materialDefault('fuzzRoughness');\n\n // Coat\n /** Clear coat weight. Default `0`. */\n coatWeight: number = materialDefault('coatWeight');\n /** Squared coat transmittance at normal incidence; colors the base and emission, not coat reflection. Default `[1, 1, 1]`. */\n coatColor: ColorRGB = materialDefault('coatColor');\n /** Coat roughness. Default `0`. */\n coatRoughness: number = materialDefault('coatRoughness');\n /**\n * OpenPBR GGX coat anisotropy, 0 to 1; uses the base geometry tangent. Default `0`.\n * @deprecated Use coatRoughnessAnisotropy.\n */\n coatAnisotropy: number = materialDefault('coatAnisotropy');\n /** Coat index of refraction. Default `1.6`. */\n coatIor: number = materialDefault('coatIor');\n /** Internal-reflection darkening: 0 compensates darkening, 1 is physical; absorption remains at 0. Default `1`. */\n coatDarkening: number = materialDefault('coatDarkening');\n\n // Thin film\n /** Thin-film interference weight (iridescence). Default `0`. */\n thinFilmWeight: number = materialDefault('thinFilmWeight');\n /** Film thickness in micrometres; maximum endpoint when thinFilmMap is present. Default `0.5`. */\n thinFilmThickness: number = materialDefault('thinFilmThickness');\n /** Film index of refraction. Default `1.4`. */\n thinFilmIor: number = materialDefault('thinFilmIor');\n\n /** Thickness at a thinFilmMap sample of zero, in micrometres; ignored without a map. May exceed thinFilmThickness. Default `0`. */\n thinFilmThicknessMinimum: number = materialDefault('thinFilmThicknessMinimum');\n /** Linear channel sampled by thinFilmMap. Default `r`. */\n thinFilmMapChannel: ThinFilmMapChannel = materialDefault('thinFilmMapChannel');\n\n // Emission and geometry\n /** Emission color. Default `[1, 1, 1]`. */\n emissionColor: ColorRGB = materialDefault('emissionColor');\n /** Emitted radiance scale; `0` disables emission. Default `0`. */\n emissionLuminance: number = materialDefault('emissionLuminance');\n /**\n * Coverage, `1` opaque. See `alphaMode`. Default `1`.\n * @deprecated Use geometryOpacity.\n */\n opacity: number = materialDefault('opacity');\n /**\n * Treat the surface as an infinitely thin shell (leaves, paper). Default `false`.\n * @deprecated Use geometryThinWalled.\n */\n thinWalled: boolean = materialDefault('thinWalled');\n /** Disables geometric back-face culling for this material. Default `false`. */\n doubleSided: boolean = materialDefault('doubleSided');\n\n // Textures\n /** Base color texture, multiplied with `baseColor` using Texture color encoding. Default `undefined`. */\n map?: Texture;\n /** Standalone opacity texture sampled from its green channel, matching Three.js. Default `undefined`. */\n alphaMap?: Texture;\n /**\n * Coverage for surface and shadow rays: `opaque` ignores alpha inputs,\n * `mask` uses binary alpha testing, `blend` retains fractional coverage.\n * `auto` derives the mode from the alpha inputs. Default `auto`.\n */\n alphaMode: MaterialAlphaMode = materialDefault('alphaMode');\n /** Alpha-test threshold for `mask` mode; equality is fully covered. Default `0`. */\n alphaCutoff: number = materialDefault('alphaCutoff');\n /** Emission texture multiplied with `emissionColor`. Default `undefined`. */\n emissiveMap?: Texture;\n /** Tangent-space normal map. */\n normalMap?: Texture;\n /** Normal map strength per axis. Default `[1, 1]`. */\n normalScale: Vec2 = materialDefault('normalScale');\n /** glTF-compatible B=metalness, G=specular roughness texture. Default `undefined`. */\n metallicRoughnessMap?: Texture;\n /** Standalone roughness texture sampled from its green channel. Default `undefined`. */\n roughnessMap?: Texture;\n /** Standalone metalness texture sampled from its blue channel. Default `undefined`. */\n metalnessMap?: Texture;\n /** Multiplies transmission weight using the texture's red channel. Default `undefined`. */\n transmissionMap?: Texture;\n /** Linear thickness-range texture; R and zero minimum preserve multiplication semantics. Default `undefined`. */\n thinFilmMap?: Texture;\n\n /** Multiplies coatWeight by the linear red channel. Default `undefined`. */\n coatWeightMap?: Texture;\n /** Multiplies coatRoughness by the linear green channel. Default `undefined`. */\n coatRoughnessMap?: Texture;\n /** Multiplies fuzzColor by RGB channels using Texture color encoding. Default `undefined`. */\n fuzzColorMap?: Texture;\n /** Multiplies fuzzRoughness by the linear alpha channel. Default `undefined`. */\n fuzzRoughnessMap?: Texture;\n /** Multiplies specularWeight by the linear alpha channel. Default `undefined`. */\n specularWeightMap?: Texture;\n /** Multiplies specularColor by RGB channels using Texture color encoding. Default `undefined`. */\n specularColorMap?: Texture;\n\n\n /** Source convention for base specular anisotropy. `gltf` converts textured roughness and strength before coat roughening; `openpbr` uses native parameters. Default `openpbr`. */\n specularAnisotropyModel: 'openpbr' | 'gltf' = 'openpbr';\n /** Linear RG tangent direction and B strength multiplier for the base specular layer. Default `undefined`. */\n anisotropyMap?: Texture;\n /** Independent tangent-space coat normal in linear RGB. Without a map, coat shares the existing shading normal. Default `undefined`. */\n coatNormalMap?: Texture;\n /** XY strength of coatNormalMap; independent of normalScale. Default `[1, 1]`. */\n coatNormalScale: Vec2 = materialDefault('coatNormalScale');\n /** Base direction rotation in radians, counter-clockwise in tangent/bitangent space after RG decoding. Default `0`. */\n specularAnisotropyRotation: number = 0;\n /** Coat direction rotation in radians relative to the geometry tangent. Default `0`. */\n coatAnisotropyRotation: number = 0;\n\n /** GGX roughness anisotropy in [0, 1]; native OpenPBR or source glTF strength according to specularAnisotropyModel. Requires tangents. Default `0`. */\n get specularRoughnessAnisotropy(): number { return this.specularAnisotropy; }\n set specularRoughnessAnisotropy(value: number) { this.specularAnisotropy = value; }\n\n /** OpenPBR coat GGX roughness anisotropy in [0, 1]. Default `0`. */\n get coatRoughnessAnisotropy(): number { return this.coatAnisotropy; }\n set coatRoughnessAnisotropy(value: number) { this.coatAnisotropy = value; }\n\n /** Subsurface scattering anisotropy in [-1, 1]. Default `0`. */\n get subsurfaceScatterAnisotropy(): number { return this.subsurfaceAnisotropy; }\n set subsurfaceScatterAnisotropy(value: number) { this.subsurfaceAnisotropy = value; }\n\n /** Surface coverage; alphaMode controls testing and blending. Default `1`. */\n get geometryOpacity(): number { return this.opacity; }\n set geometryOpacity(value: number) { this.opacity = value; }\n\n /** Treat the surface as an infinitely thin shell. Default `false`. */\n get geometryThinWalled(): boolean { return this.thinWalled; }\n set geometryThinWalled(value: boolean) { this.thinWalled = value; }\n\n // Renderer extensions\n /**\n * Invisible ground that only receives shadows, composited over the\n * background. Default `false`.\n */\n shadowCatcher: boolean = materialDefault('shadowCatcher');\n /** Displays emission without scattering or illuminating other surfaces. Default `false`. */\n unlit: boolean = materialDefault('unlit');\n /** Radius of rounded-edge shading (shader bevel) in scene units. `0` disables it. Default `0`. */\n bevelSize: number = materialDefault('bevelSize');\n /** How map alpha is used: ignored, opacity or transmission. Default `opaque`. */\n mapAlphaUsage: 'opaque' | 'alpha' | 'transmission' = materialDefault('mapAlphaUsage');\n /** Procedural UV projection for textures without (good) UVs. Default `none`. */\n uvProjection: UVProjection = materialDefault('uvProjection');\n /** UV scale used with `uvProjection`. Default `[1, 1]`. */\n uvProjectionScale: Vec2 = materialDefault('uvProjectionScale');\n\n // Displacement\n /** Height texture (red channel) for displacement. Default `undefined`. */\n displacementMap?: Texture;\n /** Procedural UV projection for the displacement map. Default `none`. */\n displacementUvProjection: UVProjection = materialDefault('displacementUvProjection');\n /** UV scale used with `displacementUvProjection`. Default `1`. */\n displacementUvProjectionScale: number = materialDefault('displacementUvProjectionScale');\n /** Height multiplier in mesh-local units; 0 removes height variation. Default `0.1`. */\n displacementScale: number = materialDefault('displacementScale');\n /** Offset added after scaling the height map, along the normal in mesh-local units; requires a displacement map. Default `0`. */\n displacementBias: number = materialDefault('displacementBias');\n /** Ray-marching step in mesh-local units; 0 automatically uses abs(displacementScale) / 32. Default `0`. */\n displacementStepSize: number = materialDefault('displacementStepSize');\n\n}\nexport const materialAlphaModeConstants = {\n opaque: 0,\n mask: 1,\n blend: 2\n} as const;\n\nexport type ResolvedMaterialAlphaMode = Exclude<MaterialAlphaMode, 'auto'>;\n\nexport function resolveMaterialAlphaMode(\n material: OpenPBRMaterial\n): ResolvedMaterialAlphaMode {\n if (material.alphaMode !== 'auto') return material.alphaMode;\n if (material.alphaCutoff > 0) return 'mask';\n if (\n material.opacity < 1 ||\n material.mapAlphaUsage === \"alpha\" ||\n material.alphaMap\n ) {\n return 'blend';\n }\n return 'opaque';\n}\n\nexport { materialKeys, materialTextureKeys, materialGeometryKeys, materialParamKeys, getMaterialHashKey, resetMaterialTextureId } from './openPbrSchema.js';\n\n/** Optional material properties; defaults are documented on OpenPBRMaterial. */\nexport type OpenPBRMaterialParams = Partial<OpenPBRMaterial>;\n"]}
1
+ {"version":3,"file":"OpenPBRMaterial.js","sourceRoot":"","sources":["../../src/scene/OpenPBRMaterial.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAO1E;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,OAAO,OAAO,eAAe;IAClC,4EAA4E;IAC5E,YAAY,SAAgC,EAAE;QAC5C,mBAAmB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACpC,CAAC;IAED,OAAO;IACP,yJAAyJ;IACzJ,UAAU,GAAW,eAAe,CAAC,YAAY,CAAC,CAAC;IACnD,sDAAsD;IACtD,SAAS,GAAa,eAAe,CAAC,WAAW,CAAC,CAAC;IACnD,mEAAmE;IACnE,oBAAoB,GAAW,eAAe,CAAC,sBAAsB,CAAC,CAAC;IACvE,8CAA8C;IAC9C,aAAa,GAAW,eAAe,CAAC,eAAe,CAAC,CAAC;IAEzD,WAAW;IACX,mGAAmG;IACnG,cAAc,GAAW,eAAe,CAAC,gBAAgB,CAAC,CAAC;IAC3D,wFAAwF;IACxF,aAAa,GAAa,eAAe,CAAC,eAAe,CAAC,CAAC;IAC3D,mIAAmI;IACnI,iBAAiB,GAAW,eAAe,CAAC,mBAAmB,CAAC,CAAC;IACjE,0CAA0C;IAC1C,WAAW,GAAW,eAAe,CAAC,aAAa,CAAC,CAAC;IACrD;;;OAGG;IACH,kBAAkB,GAAW,eAAe,CAAC,oBAAoB,CAAC,CAAC;IAEnE,eAAe;IACf,6EAA6E;IAC7E,kBAAkB,GAAW,eAAe,CAAC,oBAAoB,CAAC,CAAC;IACnE,0FAA0F;IAC1F,iBAAiB,GAAa,eAAe,CAAC,mBAAmB,CAAC,CAAC;IACnE,4FAA4F;IAC5F,iBAAiB,GAAW,eAAe,CAAC,mBAAmB,CAAC,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AAC,aAAa,KAAK,OAAO;QAClC,QAAQ,CAAC,QAAQ,EACjB,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["import type { Vec2 } from '../types.js';\nimport { ColorRGB } from '../types.js';\nimport type Texture from './Texture.js';\nimport type { ThinFilmMapChannel } from './thinFilmParameters.js';\nimport { materialDefault, applyMaterialParams } from './openPbrSchema.js';\n\nexport type UVProjection = 'none' | 'triplanar' | 'spherical' | 'cylindrical';\nexport type MaterialAlphaMode = 'auto' | 'opaque' | 'mask' | 'blend';\n\nexport type { MaterialTextureName } from './materialTextureNames.js';\n\n/**\n * OpenPBR 1.1 surface material.\n *\n * Property names are camelCase OpenPBR inputs plus documented compatibility names\n * (https://academysoftwarefoundation.github.io/OpenPBR/). Colors are linear\n * RGB. Length-valued inputs (`transmissionDepth`, `subsurfaceRadius`) use\n * scene units; `thinFilmThickness` is in micrometres as in OpenPBR.\n *\n * ```ts\n * const gold = new OpenPBRMaterial({\n * baseColor: [1.0, 0.78, 0.34], baseMetalness: 1, specularRoughness: 0.2\n * });\n * ```\n *\n * Edit parameters in place; the next `engine.update()` detects the changes.\n */\nexport default class OpenPBRMaterial {\n /** Creates a material. Omitted properties use their documented defaults. */\n constructor(params: OpenPBRMaterialParams = {}) {\n applyMaterialParams(this, params);\n }\n\n // Base\n /** Multiplier of diffuse reflection and metallic normal-incidence color; does not scale dielectric specular, transmission or subsurface. Default `1`. */\n baseWeight: number = materialDefault('baseWeight');\n /** Diffuse/metal color. Default `[0.8, 0.8, 0.8]`. */\n baseColor: ColorRGB = materialDefault('baseColor');\n /** Oren-Nayar style roughness of the diffuse lobe. Default `0`. */\n baseDiffuseRoughness: number = materialDefault('baseDiffuseRoughness');\n /** `0` dielectric, `1` metal. Default `0`. */\n baseMetalness: number = materialDefault('baseMetalness');\n\n // Specular\n /** Dielectric specular strength (via IOR) and overall metallic Fresnel multiplier. Default `1`. */\n specularWeight: number = materialDefault('specularWeight');\n /** Dielectric specular tint and metallic F82 near-grazing tint. Default `[1, 1, 1]`. */\n specularColor: ColorRGB = materialDefault('specularColor');\n /** Microfacet roughness, `0` mirror to `1` rough; retains source perceptual roughness in `gltf` anisotropy mode. Default `0.3`. */\n specularRoughness: number = materialDefault('specularRoughness');\n /** Index of refraction. Default `1.5`. */\n specularIor: number = materialDefault('specularIor');\n /**\n * GGX anisotropy strength, 0 to 1 (requires tangents); native OpenPBR or source glTF strength according to specularAnisotropyModel. Default `0`.\n * @deprecated Use specularRoughnessAnisotropy.\n */\n specularAnisotropy: number = materialDefault('specularAnisotropy');\n\n // Transmission\n /** `1` makes the dielectric base fully transmissive (glass). Default `0`. */\n transmissionWeight: number = materialDefault('transmissionWeight');\n /** Transmission tint, or the medium color at `transmissionDepth`. Default `[1, 1, 1]`. */\n transmissionColor: ColorRGB = materialDefault('transmissionColor');\n /** Depth at which `transmissionColor` is reached; `0` tints at the surface. Default `0`. */\n transmissionDepth: number = materialDefault('transmissionDepth');\n /** Volume scattering color of the transmissive medium. Default `[0, 0, 0]`. */\n transmissionScatter: ColorRGB = materialDefault('transmissionScatter');\n /** Henyey-Greenstein anisotropy of the medium, -1 to 1. Default `0`. */\n transmissionScatterAnisotropy: number = materialDefault('transmissionScatterAnisotropy');\n /** Dispersion strength; `> 0` enables spectral rendering. Default `0`. */\n transmissionDispersionScale: number = materialDefault('transmissionDispersionScale');\n /** Abbe number controlling dispersion. Default `20`. */\n transmissionDispersionAbbeNumber: number = materialDefault('transmissionDispersionAbbeNumber');\n\n // Subsurface\n /** Subsurface scattering weight. Default `0`. */\n subsurfaceWeight: number = materialDefault('subsurfaceWeight');\n /** Subsurface color. Default `[0.8, 0.8, 0.8]`. */\n subsurfaceColor: ColorRGB = materialDefault('subsurfaceColor');\n /** Mean free path in scene units. Default `1`. */\n subsurfaceRadius: number = materialDefault('subsurfaceRadius');\n /** Per-channel multiplier of `subsurfaceRadius`. Default `[1, 0.5, 0.25]`. */\n subsurfaceRadiusScale: ColorRGB = materialDefault('subsurfaceRadiusScale');\n /**\n * Scattering anisotropy, -1 to 1. Default `0`.\n * @deprecated Use subsurfaceScatterAnisotropy.\n */\n subsurfaceAnisotropy: number = materialDefault('subsurfaceAnisotropy');\n\n // Fuzz (sheen)\n /** Fuzz (sheen) layer weight. Default `0`. */\n fuzzWeight: number = materialDefault('fuzzWeight');\n /** Fuzz reflection color; substrate attenuation uses white fuzz albedo. Default `[1, 1, 1]`. */\n fuzzColor: ColorRGB = materialDefault('fuzzColor');\n /** Fuzz roughness; imported from Three.js `sheenRoughness`. Default `0.5`. */\n fuzzRoughness: number = materialDefault('fuzzRoughness');\n\n // Coat\n /** Clear coat weight. Default `0`. */\n coatWeight: number = materialDefault('coatWeight');\n /** Squared coat transmittance at normal incidence; colors the base and emission, not coat reflection. Default `[1, 1, 1]`. */\n coatColor: ColorRGB = materialDefault('coatColor');\n /** Coat roughness. Default `0`. */\n coatRoughness: number = materialDefault('coatRoughness');\n /**\n * OpenPBR GGX coat anisotropy, 0 to 1; uses the base geometry tangent. Default `0`.\n * @deprecated Use coatRoughnessAnisotropy.\n */\n coatAnisotropy: number = materialDefault('coatAnisotropy');\n /** Coat index of refraction. Default `1.6`. */\n coatIor: number = materialDefault('coatIor');\n /** Internal-reflection darkening: 0 compensates darkening, 1 is physical; absorption remains at 0. Default `1`. */\n coatDarkening: number = materialDefault('coatDarkening');\n\n // Thin film\n /** Thin-film interference weight (iridescence). Default `0`. */\n thinFilmWeight: number = materialDefault('thinFilmWeight');\n /** Film thickness in micrometres; maximum endpoint when thinFilmMap is present. Default `0.5`. */\n thinFilmThickness: number = materialDefault('thinFilmThickness');\n /** Film index of refraction. Default `1.4`. */\n thinFilmIor: number = materialDefault('thinFilmIor');\n\n /** Thickness at a thinFilmMap sample of zero, in micrometres; ignored without a map. May exceed thinFilmThickness. Default `0`. */\n thinFilmThicknessMinimum: number = materialDefault('thinFilmThicknessMinimum');\n /** Linear channel sampled by thinFilmMap. Default `r`. */\n thinFilmMapChannel: ThinFilmMapChannel = materialDefault('thinFilmMapChannel');\n\n // Emission and geometry\n /** Emission color. Default `[1, 1, 1]`. */\n emissionColor: ColorRGB = materialDefault('emissionColor');\n /** Emitted radiance scale; `0` disables emission. Default `0`. */\n emissionLuminance: number = materialDefault('emissionLuminance');\n /**\n * Coverage, `1` opaque. See `alphaMode`. Default `1`.\n * @deprecated Use geometryOpacity.\n */\n opacity: number = materialDefault('opacity');\n /**\n * Treat the surface as an infinitely thin shell (leaves, paper). Default `false`.\n * @deprecated Use geometryThinWalled.\n */\n thinWalled: boolean = materialDefault('thinWalled');\n /** Disables geometric back-face culling for this material. Default `false`. */\n doubleSided: boolean = materialDefault('doubleSided');\n\n // Textures\n /** Base color texture, multiplied with `baseColor` using Texture color encoding. Default `undefined`. */\n map?: Texture;\n /** Standalone opacity texture sampled from its green channel, matching Three.js. Default `undefined`. */\n alphaMap?: Texture;\n /**\n * Coverage for surface and shadow rays: `opaque` ignores alpha inputs,\n * `mask` uses binary alpha testing, `blend` retains fractional coverage.\n * `auto` derives the mode from the alpha inputs. Default `auto`.\n */\n alphaMode: MaterialAlphaMode = materialDefault('alphaMode');\n /** Alpha-test threshold for `mask` mode; equality is fully covered. Default `0`. */\n alphaCutoff: number = materialDefault('alphaCutoff');\n /** Emission texture multiplied with `emissionColor`. Default `undefined`. */\n emissiveMap?: Texture;\n /** Tangent-space normal map. */\n normalMap?: Texture;\n /** Normal map strength per axis. Default `[1, 1]`. */\n normalScale: Vec2 = materialDefault('normalScale');\n /** glTF-compatible B=metalness, G=specular roughness texture. Default `undefined`. */\n metallicRoughnessMap?: Texture;\n /** Standalone roughness texture sampled from its green channel. Default `undefined`. */\n roughnessMap?: Texture;\n /** Standalone metalness texture sampled from its blue channel. Default `undefined`. */\n metalnessMap?: Texture;\n /** Multiplies transmission weight using the texture's red channel. Default `undefined`. */\n transmissionMap?: Texture;\n /** Linear thickness-range texture; R and zero minimum preserve multiplication semantics. Default `undefined`. */\n thinFilmMap?: Texture;\n\n /** Multiplies coatWeight by the linear red channel. Default `undefined`. */\n coatWeightMap?: Texture;\n /** Multiplies coatRoughness by the linear green channel. Default `undefined`. */\n coatRoughnessMap?: Texture;\n /** Multiplies fuzzColor by RGB channels using Texture color encoding. Default `undefined`. */\n fuzzColorMap?: Texture;\n /** Multiplies fuzzRoughness by the linear alpha channel. Default `undefined`. */\n fuzzRoughnessMap?: Texture;\n /** Multiplies specularWeight by the linear alpha channel. Default `undefined`. */\n specularWeightMap?: Texture;\n /** Multiplies specularColor by RGB channels using Texture color encoding. Default `undefined`. */\n specularColorMap?: Texture;\n\n\n /** Source convention for base specular anisotropy. `gltf` converts textured roughness and strength before coat roughening; `openpbr` uses native parameters. Default `openpbr`. */\n specularAnisotropyModel: 'openpbr' | 'gltf' = 'openpbr';\n /** Linear RG tangent direction and B strength multiplier for the base specular layer. Default `undefined`. */\n anisotropyMap?: Texture;\n /** Independent tangent-space coat normal in linear RGB. Without a map, coat uses the surface normal before base normal mapping. Default `undefined`. */\n coatNormalMap?: Texture;\n /** XY strength of coatNormalMap; independent of normalScale. Default `[1, 1]`. */\n coatNormalScale: Vec2 = materialDefault('coatNormalScale');\n /** Base direction rotation in radians, counter-clockwise in tangent/bitangent space after RG decoding. Default `0`. */\n specularAnisotropyRotation: number = 0;\n /** Coat direction rotation in radians relative to the geometry tangent. Default `0`. */\n coatAnisotropyRotation: number = 0;\n\n /** GGX roughness anisotropy in [0, 1]; native OpenPBR or source glTF strength according to specularAnisotropyModel. Requires tangents. Default `0`. */\n get specularRoughnessAnisotropy(): number { return this.specularAnisotropy; }\n set specularRoughnessAnisotropy(value: number) { this.specularAnisotropy = value; }\n\n /** OpenPBR coat GGX roughness anisotropy in [0, 1]. Default `0`. */\n get coatRoughnessAnisotropy(): number { return this.coatAnisotropy; }\n set coatRoughnessAnisotropy(value: number) { this.coatAnisotropy = value; }\n\n /** Subsurface scattering anisotropy in [-1, 1]. Default `0`. */\n get subsurfaceScatterAnisotropy(): number { return this.subsurfaceAnisotropy; }\n set subsurfaceScatterAnisotropy(value: number) { this.subsurfaceAnisotropy = value; }\n\n /** Surface coverage; alphaMode controls testing and blending. Default `1`. */\n get geometryOpacity(): number { return this.opacity; }\n set geometryOpacity(value: number) { this.opacity = value; }\n\n /** Treat the surface as an infinitely thin shell. Default `false`. */\n get geometryThinWalled(): boolean { return this.thinWalled; }\n set geometryThinWalled(value: boolean) { this.thinWalled = value; }\n\n // Renderer extensions\n /**\n * Invisible ground that only receives shadows, composited over the\n * background. Default `false`.\n */\n shadowCatcher: boolean = materialDefault('shadowCatcher');\n /** Displays emission without scattering or illuminating other surfaces. Default `false`. */\n unlit: boolean = materialDefault('unlit');\n /** Radius of rounded-edge shading (shader bevel) in scene units. `0` disables it. Default `0`. */\n bevelSize: number = materialDefault('bevelSize');\n /** How map alpha is used: ignored, opacity or transmission. Default `opaque`. */\n mapAlphaUsage: 'opaque' | 'alpha' | 'transmission' = materialDefault('mapAlphaUsage');\n /** Procedural UV projection for textures without (good) UVs. Default `none`. */\n uvProjection: UVProjection = materialDefault('uvProjection');\n /** UV scale used with `uvProjection`. Default `[1, 1]`. */\n uvProjectionScale: Vec2 = materialDefault('uvProjectionScale');\n\n // Displacement\n /** Height texture (red channel) for displacement. Default `undefined`. */\n displacementMap?: Texture;\n /** Procedural UV projection for the displacement map. Default `none`. */\n displacementUvProjection: UVProjection = materialDefault('displacementUvProjection');\n /** UV scale used with `displacementUvProjection`. Default `1`. */\n displacementUvProjectionScale: number = materialDefault('displacementUvProjectionScale');\n /** Height multiplier in mesh-local units; 0 removes height variation. Default `0.1`. */\n displacementScale: number = materialDefault('displacementScale');\n /** Offset added after scaling the height map, along the normal in mesh-local units; requires a displacement map. Default `0`. */\n displacementBias: number = materialDefault('displacementBias');\n /** Ray-marching step in mesh-local units; 0 automatically uses abs(displacementScale) / 32. Default `0`. */\n displacementStepSize: number = materialDefault('displacementStepSize');\n\n}\nexport const materialAlphaModeConstants = {\n opaque: 0,\n mask: 1,\n blend: 2\n} as const;\n\nexport type ResolvedMaterialAlphaMode = Exclude<MaterialAlphaMode, 'auto'>;\n\nexport function resolveMaterialAlphaMode(\n material: OpenPBRMaterial\n): ResolvedMaterialAlphaMode {\n if (material.alphaMode !== 'auto') return material.alphaMode;\n if (material.alphaCutoff > 0) return 'mask';\n if (\n material.opacity < 1 ||\n material.mapAlphaUsage === \"alpha\" ||\n material.alphaMap\n ) {\n return 'blend';\n }\n return 'opaque';\n}\n\nexport { materialKeys, materialTextureKeys, materialGeometryKeys, materialParamKeys, getMaterialHashKey, resetMaterialTextureId } from './openPbrSchema.js';\n\n/** Optional material properties; defaults are documented on OpenPBRMaterial. */\nexport type OpenPBRMaterialParams = Partial<OpenPBRMaterial>;\n"]}
@@ -29,6 +29,10 @@ export interface GroundedSkyboxBackground {
29
29
  groundHeight?: number;
30
30
  /** Capture X/Z center in scene units. Default `[0, 0]`. */
31
31
  center?: [number, number];
32
+ /** Background rotation around +Y in radians, about the capture center. Default `0`; ground stays level. */
33
+ rotation?: number;
34
+ /** Nonnegative background RGB multiplier. Default `1`; lighting and alpha are unchanged. */
35
+ intensity?: number;
32
36
  }
33
37
  /**
34
38
  * What camera rays that miss the scene show: a linear RGBA color (alpha 0
@@ -1 +1 @@
1
- {"version":3,"file":"Scene.js","sourceRoot":"","sources":["../../src/scene/Scene.ts"],"names":[],"mappings":"","sourcesContent":["import { ColorRGBA } from '../types.js';\nimport AmbientLight from './AmbientLight.js';\nimport DirectionalLight from './DirectionalLight.js';\nimport EnvironmentLight from './EnvironmentLight.js';\nimport Mesh from './Mesh.js';\nimport InstancedMesh from './InstancedMesh.js';\nimport RectLight from './RectLight.js';\nimport SphereLight from './SphereLight.js';\nimport SpotLight from './SpotLight.js';\nimport Texture from './Texture.js';\n\n/** Lights with an analytic shape. */\nexport type AnalyticLight = RectLight | SphereLight | SpotLight | DirectionalLight;\n/** Any light that can be placed in {@link Scene.lights}. */\nexport type SceneLight = AmbientLight | EnvironmentLight | AnalyticLight;\n\n/**\n * Environment map projected onto a ground plane and sky dome, so objects\n * appear to stand on the photographed ground.\n */\nexport interface GroundedSkyboxBackground {\n /** Ground projection discriminator; always `GroundedSkybox`. */\n type: 'GroundedSkybox';\n /** Required equirectangular environment texture. */\n map: Texture;\n /** Required capture height above ground in scene units. */\n height: number;\n /** Required projected sky-dome radius in scene units. */\n radius: number;\n /** Ground plane Y in scene units. Default `0`. */\n groundHeight?: number;\n /** Capture X/Z center in scene units. Default `[0, 0]`. */\n center?: [number, number];\n}\n\n/**\n * What camera rays that miss the scene show: a linear RGBA color (alpha 0\n * for a transparent canvas), an equirectangular texture, or a grounded\n * skybox. When omitted, the environment light is shown.\n */\nexport type SceneBackground = ColorRGBA | Texture | GroundedSkyboxBackground;\n/**\n * Everything the renderer draws. A plain object; mesh and light membership,\n * mesh transforms, material parameters, resource references, light parameters and background\n * values are detected automatically, including edits within existing arrays.\n * Call `markUpdated()` on a Geometry after attribute edits, and a Texture\n * after pixel or UV-array element edits.\n * InstancedMesh matrix/color elements require markUpdated() or the dedicated\n * markTransformsUpdated()/markColorsUpdated() notifications.\n */\nexport interface Scene {\n /** Required mesh instances; use an empty array for an empty scene. */\n meshes: (Mesh | InstancedMesh)[];\n /** Required lights; use an empty array for an unlit scene. */\n lights: SceneLight[];\n /** Camera-ray background; defaults to the environment light when omitted. */\n background?: SceneBackground;\n\n}\n"]}
1
+ {"version":3,"file":"Scene.js","sourceRoot":"","sources":["../../src/scene/Scene.ts"],"names":[],"mappings":"","sourcesContent":["import { ColorRGBA } from '../types.js';\nimport AmbientLight from './AmbientLight.js';\nimport DirectionalLight from './DirectionalLight.js';\nimport EnvironmentLight from './EnvironmentLight.js';\nimport Mesh from './Mesh.js';\nimport InstancedMesh from './InstancedMesh.js';\nimport RectLight from './RectLight.js';\nimport SphereLight from './SphereLight.js';\nimport SpotLight from './SpotLight.js';\nimport Texture from './Texture.js';\n\n/** Lights with an analytic shape. */\nexport type AnalyticLight = RectLight | SphereLight | SpotLight | DirectionalLight;\n/** Any light that can be placed in {@link Scene.lights}. */\nexport type SceneLight = AmbientLight | EnvironmentLight | AnalyticLight;\n\n/**\n * Environment map projected onto a ground plane and sky dome, so objects\n * appear to stand on the photographed ground.\n */\nexport interface GroundedSkyboxBackground {\n /** Ground projection discriminator; always `GroundedSkybox`. */\n type: 'GroundedSkybox';\n /** Required equirectangular environment texture. */\n map: Texture;\n /** Required capture height above ground in scene units. */\n height: number;\n /** Required projected sky-dome radius in scene units. */\n radius: number;\n /** Ground plane Y in scene units. Default `0`. */\n groundHeight?: number;\n /** Capture X/Z center in scene units. Default `[0, 0]`. */\n center?: [number, number];\n /** Background rotation around +Y in radians, about the capture center. Default `0`; ground stays level. */\n rotation?: number;\n /** Nonnegative background RGB multiplier. Default `1`; lighting and alpha are unchanged. */\n intensity?: number;\n}\n\n/**\n * What camera rays that miss the scene show: a linear RGBA color (alpha 0\n * for a transparent canvas), an equirectangular texture, or a grounded\n * skybox. When omitted, the environment light is shown.\n */\nexport type SceneBackground = ColorRGBA | Texture | GroundedSkyboxBackground;\n/**\n * Everything the renderer draws. A plain object; mesh and light membership,\n * mesh transforms, material parameters, resource references, light parameters and background\n * values are detected automatically, including edits within existing arrays.\n * Call `markUpdated()` on a Geometry after attribute edits, and a Texture\n * after pixel or UV-array element edits.\n * InstancedMesh matrix/color elements require markUpdated() or the dedicated\n * markTransformsUpdated()/markColorsUpdated() notifications.\n */\nexport interface Scene {\n /** Required mesh instances; use an empty array for an empty scene. */\n meshes: (Mesh | InstancedMesh)[];\n /** Required lights; use an empty array for an unlit scene. */\n lights: SceneLight[];\n /** Camera-ray background; defaults to the environment light when omitted. */\n background?: SceneBackground;\n\n}\n"]}
@@ -13,7 +13,7 @@ export default class SpotLight extends SceneNode {
13
13
  radius: number;
14
14
  /** Full-intensity cone half-angle in degrees. Default `30`. */
15
15
  innerAngle: number;
16
- /** Cutoff cone half-angle in degrees, at most 180. Default `45`. */
16
+ /** Cutoff cone half-angle in degrees, at most 180. Intensity falls off smoothly in cosine from the inner angle. Default `45`. */
17
17
  outerAngle: number;
18
18
  /** Optional photometric emission profile. Default `undefined`. */
19
19
  iesProfile: IESProfile | undefined;
@@ -27,7 +27,7 @@ export default class SpotLight extends SceneNode {
27
27
  radius?: number;
28
28
  /** Full-intensity cone half-angle in degrees. Default `30`. */
29
29
  innerAngle?: number;
30
- /** Cutoff cone half-angle in degrees, at most 180. Default `45`. */
30
+ /** Cutoff cone half-angle in degrees, at most 180. Intensity falls off smoothly in cosine from the inner angle. Default `45`. */
31
31
  outerAngle?: number;
32
32
  /** Optional photometric emission profile. Default `undefined`. */
33
33
  iesProfile?: IESProfile | undefined;
@@ -11,7 +11,7 @@ export default class SpotLight extends SceneNode {
11
11
  radius = 0.01;
12
12
  /** Full-intensity cone half-angle in degrees. Default `30`. */
13
13
  innerAngle = 30;
14
- /** Cutoff cone half-angle in degrees, at most 180. Default `45`. */
14
+ /** Cutoff cone half-angle in degrees, at most 180. Intensity falls off smoothly in cosine from the inner angle. Default `45`. */
15
15
  outerAngle = 45;
16
16
  /** Optional photometric emission profile. Default `undefined`. */
17
17
  iesProfile = undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"SpotLight.js","sourceRoot":"","sources":["../../src/scene/SpotLight.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,gBAAgB,CAAC;AAGvC,kHAAkH;AAClH,MAAM,CAAC,OAAO,OAAO,SAAU,SAAQ,SAAS;IAC9C,2BAA2B;IAClB,IAAI,GAAG,WAAoB,CAAC;IACrC,6CAA6C;IAC7C,KAAK,GAAa,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAC5B,+CAA+C;IAC/C,SAAS,GAAW,CAAC,CAAC;IACtB,2EAA2E;IAC3E,MAAM,GAAW,IAAI,CAAC;IACtB,+DAA+D;IAC/D,UAAU,GAAW,EAAE,CAAC;IACxB,oEAAoE;IACpE,UAAU,GAAW,EAAE,CAAC;IACxB,kEAAkE;IAClE,UAAU,GAA2B,SAAS,CAAC;IAE/C,kEAAkE;IAClE,YAAY,SAaR,EAAE;QACJ,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QACvC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,IAAI,CAAC,CAAC;QACvC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,IAAI,CAAC;QACpC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC;QAC1C,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC;QAC1C,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,IAAI,SAAS,CAAC;IACnD,CAAC;CACF","sourcesContent":["import type { ColorRGB } from '../types.js';\nimport SceneNode from './SceneNode.js';\nimport type IESProfile from './IESProfile.js';\n\n/** Analytic light placed with transform; local -Z is the emission direction and local +X is the IES reference. */\nexport default class SpotLight extends SceneNode {\n /** Light discriminator. */\n readonly type = 'SpotLight' as const;\n /** Linear RGB color. Default `[1, 1, 1]`. */\n color: ColorRGB = [1, 1, 1];\n /** Axial intensity in candela. Default `1`. */\n intensity: number = 1;\n /** Emitter radius in scene units; 0 is a point emitter. Default `0.01`. */\n radius: number = 0.01;\n /** Full-intensity cone half-angle in degrees. Default `30`. */\n innerAngle: number = 30;\n /** Cutoff cone half-angle in degrees, at most 180. Default `45`. */\n outerAngle: number = 45;\n /** Optional photometric emission profile. Default `undefined`. */\n iesProfile: IESProfile | undefined = undefined;\n\n /** Creates a light; omitted options retain the field defaults. */\n constructor(params: {\n /** Linear RGB color. Default `[1, 1, 1]`. */\n color?: ColorRGB;\n /** Axial intensity in candela. Default `1`. */\n intensity?: number;\n /** Emitter radius in scene units; 0 is a point emitter. Default `0.01`. */\n radius?: number;\n /** Full-intensity cone half-angle in degrees. Default `30`. */\n innerAngle?: number;\n /** Cutoff cone half-angle in degrees, at most 180. Default `45`. */\n outerAngle?: number;\n /** Optional photometric emission profile. Default `undefined`. */\n iesProfile?: IESProfile | undefined;\n } = {}) {\n super();\n this.color = params.color ?? [1, 1, 1];\n this.intensity = params.intensity ?? 1;\n this.radius = params.radius ?? 0.01;\n this.innerAngle = params.innerAngle ?? 30;\n this.outerAngle = params.outerAngle ?? 45;\n this.iesProfile = params.iesProfile ?? undefined;\n }\n}\n"]}
1
+ {"version":3,"file":"SpotLight.js","sourceRoot":"","sources":["../../src/scene/SpotLight.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,gBAAgB,CAAC;AAGvC,kHAAkH;AAClH,MAAM,CAAC,OAAO,OAAO,SAAU,SAAQ,SAAS;IAC9C,2BAA2B;IAClB,IAAI,GAAG,WAAoB,CAAC;IACrC,6CAA6C;IAC7C,KAAK,GAAa,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAC5B,+CAA+C;IAC/C,SAAS,GAAW,CAAC,CAAC;IACtB,2EAA2E;IAC3E,MAAM,GAAW,IAAI,CAAC;IACtB,+DAA+D;IAC/D,UAAU,GAAW,EAAE,CAAC;IACxB,iIAAiI;IACjI,UAAU,GAAW,EAAE,CAAC;IACxB,kEAAkE;IAClE,UAAU,GAA2B,SAAS,CAAC;IAE/C,kEAAkE;IAClE,YAAY,SAaR,EAAE;QACJ,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QACvC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,IAAI,CAAC,CAAC;QACvC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,IAAI,CAAC;QACpC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC;QAC1C,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC;QAC1C,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,IAAI,SAAS,CAAC;IACnD,CAAC;CACF","sourcesContent":["import type { ColorRGB } from '../types.js';\nimport SceneNode from './SceneNode.js';\nimport type IESProfile from './IESProfile.js';\n\n/** Analytic light placed with transform; local -Z is the emission direction and local +X is the IES reference. */\nexport default class SpotLight extends SceneNode {\n /** Light discriminator. */\n readonly type = 'SpotLight' as const;\n /** Linear RGB color. Default `[1, 1, 1]`. */\n color: ColorRGB = [1, 1, 1];\n /** Axial intensity in candela. Default `1`. */\n intensity: number = 1;\n /** Emitter radius in scene units; 0 is a point emitter. Default `0.01`. */\n radius: number = 0.01;\n /** Full-intensity cone half-angle in degrees. Default `30`. */\n innerAngle: number = 30;\n /** Cutoff cone half-angle in degrees, at most 180. Intensity falls off smoothly in cosine from the inner angle. Default `45`. */\n outerAngle: number = 45;\n /** Optional photometric emission profile. Default `undefined`. */\n iesProfile: IESProfile | undefined = undefined;\n\n /** Creates a light; omitted options retain the field defaults. */\n constructor(params: {\n /** Linear RGB color. Default `[1, 1, 1]`. */\n color?: ColorRGB;\n /** Axial intensity in candela. Default `1`. */\n intensity?: number;\n /** Emitter radius in scene units; 0 is a point emitter. Default `0.01`. */\n radius?: number;\n /** Full-intensity cone half-angle in degrees. Default `30`. */\n innerAngle?: number;\n /** Cutoff cone half-angle in degrees, at most 180. Intensity falls off smoothly in cosine from the inner angle. Default `45`. */\n outerAngle?: number;\n /** Optional photometric emission profile. Default `undefined`. */\n iesProfile?: IESProfile | undefined;\n } = {}) {\n super();\n this.color = params.color ?? [1, 1, 1];\n this.intensity = params.intensity ?? 1;\n this.radius = params.radius ?? 0.01;\n this.innerAngle = params.innerAngle ?? 30;\n this.outerAngle = params.outerAngle ?? 45;\n this.iesProfile = params.iesProfile ?? undefined;\n }\n}\n"]}
@@ -1,15 +1,20 @@
1
- /** Raw RGBA pixels, rows top to bottom. Bytes encode sRGB color; float data is linear HDR. */
1
+ /** Raw RGBA pixels, rows top to bottom. Color encoding defaults to sRGB for bytes and linear for floats. */
2
2
  export interface TextureDataSource {
3
- /** Required RGBA pixels in row-major order. Uint8Array/Uint8ClampedArray encode sRGB color; Float32Array/Int32Array contain linear values. Data-map channels are always linear. */
3
+ /** Required RGBA pixels in row-major order. Uint8Array/Uint8ClampedArray default to sRGB color; Float32Array/Int32Array default to linear values. Texture.colorSpace can override color encoding; data-map channels are always linear. */
4
4
  data: Float32Array | Uint8Array | Uint8ClampedArray | Int32Array;
5
5
  /** Required pixel width. */
6
6
  width: number;
7
7
  /** Required pixel height. */
8
8
  height: number;
9
9
  }
10
+ /** Transfer function for material color slots; data-map channels remain linear. */
11
+ export type TextureColorSpace = 'srgb' | 'linear';
12
+ /** Addressing of coordinates outside a material texture's [0, 1] range. */
13
+ export type TextureWrapMode = 'repeat' | 'clamp-to-edge' | 'mirrored-repeat';
14
+ export declare function textureWrapIndex(mode: TextureWrapMode): number;
10
15
  /**
11
- * Image used by materials, lights and backgrounds. 8-bit color textures are
12
- * treated as sRGB; float data as linear.
16
+ * Image used by materials, lights and backgrounds. Material color slots default
17
+ * to sRGB for images/bytes and linear for float data; colorSpace overrides this.
13
18
  */
14
19
  export default class Texture {
15
20
  /** Image or raw RGBA pixels supplied to the constructor; no default. */
@@ -24,14 +29,20 @@ export default class Texture {
24
29
  uvScale: [number, number];
25
30
  /** UV translation applied after repeat and before wrapping. Default `[0, 0]`. */
26
31
  uvOffset: [number, number];
32
+ /** Horizontal material-texture addressing after UV scale/offset. Default `'repeat'`. */
33
+ wrapS: TextureWrapMode;
34
+ /** Vertical material-texture addressing after UV scale/offset. Default `'repeat'`. */
35
+ wrapT: TextureWrapMode;
36
+ /** Material color encoding. Default undefined: sRGB for images/bytes, linear for float/integer HDR data. Data-map channels ignore this option. */
37
+ colorSpace?: TextureColorSpace;
27
38
  /** Geometry UV set used by this texture (Three.js Texture.channel). Default `0`. */
28
39
  uvChannel: 0 | 1;
29
40
  constructor(image: HTMLImageElement | HTMLCanvasElement | ImageBitmap | OffscreenCanvas | TextureDataSource);
30
41
  /**
31
42
  * Call after editing image pixels or UV array elements in place. Increments
32
43
  * version so the next render refreshes all materials, lights and backgrounds
33
- * using this texture. Assigning a new image, UV array, flipY or uvChannel is
34
- * detected automatically.
44
+ * using this texture. Assigning a new image, UV array, flipY, wrapS, wrapT, colorSpace or
45
+ * uvChannel is detected automatically.
35
46
  */
36
47
  markUpdated(): this;
37
48
  }
@@ -1,6 +1,9 @@
1
+ export function textureWrapIndex(mode) {
2
+ return mode === 'clamp-to-edge' ? 1 : mode === 'mirrored-repeat' ? 2 : 0;
3
+ }
1
4
  /**
2
- * Image used by materials, lights and backgrounds. 8-bit color textures are
3
- * treated as sRGB; float data as linear.
5
+ * Image used by materials, lights and backgrounds. Material color slots default
6
+ * to sRGB for images/bytes and linear for float data; colorSpace overrides this.
4
7
  */
5
8
  export default class Texture {
6
9
  /** Image or raw RGBA pixels supplied to the constructor; no default. */
@@ -15,6 +18,12 @@ export default class Texture {
15
18
  uvScale = [1, 1];
16
19
  /** UV translation applied after repeat and before wrapping. Default `[0, 0]`. */
17
20
  uvOffset = [0, 0];
21
+ /** Horizontal material-texture addressing after UV scale/offset. Default `'repeat'`. */
22
+ wrapS = 'repeat';
23
+ /** Vertical material-texture addressing after UV scale/offset. Default `'repeat'`. */
24
+ wrapT = 'repeat';
25
+ /** Material color encoding. Default undefined: sRGB for images/bytes, linear for float/integer HDR data. Data-map channels ignore this option. */
26
+ colorSpace;
18
27
  /** Geometry UV set used by this texture (Three.js Texture.channel). Default `0`. */
19
28
  uvChannel = 0;
20
29
  constructor(image) {
@@ -23,8 +32,8 @@ export default class Texture {
23
32
  /**
24
33
  * Call after editing image pixels or UV array elements in place. Increments
25
34
  * version so the next render refreshes all materials, lights and backgrounds
26
- * using this texture. Assigning a new image, UV array, flipY or uvChannel is
27
- * detected automatically.
35
+ * using this texture. Assigning a new image, UV array, flipY, wrapS, wrapT, colorSpace or
36
+ * uvChannel is detected automatically.
28
37
  */
29
38
  markUpdated() {
30
39
  this.version++;
@@ -1 +1 @@
1
- {"version":3,"file":"Texture.js","sourceRoot":"","sources":["../../src/scene/Texture.ts"],"names":[],"mappings":"AAUA;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,OAAO;IAC1B,wEAAwE;IACxE,KAAK,CAA2F;IAChG,8EAA8E;IAC9E,MAAM,CAAU;IAChB,sCAAsC;IACtC,OAAO,GAAG,CAAC,CAAC;IAEZ,iEAAiE;IACjE,KAAK,GAAY,KAAK,CAAC;IACvB,wEAAwE;IACxE,OAAO,GAAqB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACnC,iFAAiF;IACjF,QAAQ,GAAqB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACpC,oFAAoF;IACpF,SAAS,GAAU,CAAC,CAAC;IACrB,YAAY,KAA+F;QACzG,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED;;;;;OAKG;IACH,WAAW;QACT,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED,MAAM,UAAU,mBAAmB,CACjC,KAAc;IAEd,OAAO,CAAC,CAAC,CAAC,KAAK,IAAK,KAA2B,CAAC,IAAI,CAAC,CAAC;AACxD,CAAC","sourcesContent":["/** Raw RGBA pixels, rows top to bottom. Bytes encode sRGB color; float data is linear HDR. */\nexport interface TextureDataSource {\n /** Required RGBA pixels in row-major order. Uint8Array/Uint8ClampedArray encode sRGB color; Float32Array/Int32Array contain linear values. Data-map channels are always linear. */\n data: Float32Array | Uint8Array | Uint8ClampedArray | Int32Array;\n /** Required pixel width. */\n width: number;\n /** Required pixel height. */\n height: number;\n}\n\n/**\n * Image used by materials, lights and backgrounds. 8-bit color textures are\n * treated as sRGB; float data as linear.\n */\nexport default class Texture {\n /** Image or raw RGBA pixels supplied to the constructor; no default. */\n image: HTMLImageElement | HTMLCanvasElement | ImageBitmap | OffscreenCanvas | TextureDataSource;\n /** Optional stable identity of the texture in an adapter such as Three.js. */\n source?: object;\n /** Incremented by `markUpdated()`. */\n version = 0;\n\n /** Flip the image vertically when uploading. Default `false`. */\n flipY: boolean = false;\n /** UV repeat applied before sampling this texture. Default `[1, 1]`. */\n uvScale: [number, number] = [1, 1];\n /** UV translation applied after repeat and before wrapping. Default `[0, 0]`. */\n uvOffset: [number, number] = [0, 0];\n /** Geometry UV set used by this texture (Three.js Texture.channel). Default `0`. */\n uvChannel: 0 | 1 = 0;\n constructor(image: HTMLImageElement | HTMLCanvasElement | ImageBitmap | OffscreenCanvas | TextureDataSource) {\n this.image = image;\n }\n\n /**\n * Call after editing image pixels or UV array elements in place. Increments\n * version so the next render refreshes all materials, lights and backgrounds\n * using this texture. Assigning a new image, UV array, flipY or uvChannel is\n * detected automatically.\n */\n markUpdated() {\n this.version++;\n return this;\n }\n}\n\nexport function isTextureDataSource(\n image: unknown\n): image is TextureDataSource {\n return !!(image && (image as TextureDataSource).data);\n}\n\n"]}
1
+ {"version":3,"file":"Texture.js","sourceRoot":"","sources":["../../src/scene/Texture.ts"],"names":[],"mappings":"AAgBA,MAAM,UAAU,gBAAgB,CAAC,IAAqB;IACpD,OAAO,IAAI,KAAK,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3E,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,OAAO;IAC1B,wEAAwE;IACxE,KAAK,CAA2F;IAChG,8EAA8E;IAC9E,MAAM,CAAU;IAChB,sCAAsC;IACtC,OAAO,GAAG,CAAC,CAAC;IAEZ,iEAAiE;IACjE,KAAK,GAAY,KAAK,CAAC;IACvB,wEAAwE;IACxE,OAAO,GAAqB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACnC,iFAAiF;IACjF,QAAQ,GAAqB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACpC,wFAAwF;IACxF,KAAK,GAAoB,QAAQ,CAAC;IAClC,sFAAsF;IACtF,KAAK,GAAoB,QAAQ,CAAC;IAClC,kJAAkJ;IAClJ,UAAU,CAAqB;IAC/B,oFAAoF;IACpF,SAAS,GAAU,CAAC,CAAC;IACrB,YAAY,KAA+F;QACzG,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED;;;;;OAKG;IACH,WAAW;QACT,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED,MAAM,UAAU,mBAAmB,CACjC,KAAc;IAEd,OAAO,CAAC,CAAC,CAAC,KAAK,IAAK,KAA2B,CAAC,IAAI,CAAC,CAAC;AACxD,CAAC","sourcesContent":["/** Raw RGBA pixels, rows top to bottom. Color encoding defaults to sRGB for bytes and linear for floats. */\nexport interface TextureDataSource {\n /** Required RGBA pixels in row-major order. Uint8Array/Uint8ClampedArray default to sRGB color; Float32Array/Int32Array default to linear values. Texture.colorSpace can override color encoding; data-map channels are always linear. */\n data: Float32Array | Uint8Array | Uint8ClampedArray | Int32Array;\n /** Required pixel width. */\n width: number;\n /** Required pixel height. */\n height: number;\n}\n\n/** Transfer function for material color slots; data-map channels remain linear. */\nexport type TextureColorSpace = 'srgb' | 'linear';\n\n/** Addressing of coordinates outside a material texture's [0, 1] range. */\nexport type TextureWrapMode = 'repeat' | 'clamp-to-edge' | 'mirrored-repeat';\n\nexport function textureWrapIndex(mode: TextureWrapMode): number {\n return mode === 'clamp-to-edge' ? 1 : mode === 'mirrored-repeat' ? 2 : 0;\n}\n\n/**\n * Image used by materials, lights and backgrounds. Material color slots default\n * to sRGB for images/bytes and linear for float data; colorSpace overrides this.\n */\nexport default class Texture {\n /** Image or raw RGBA pixels supplied to the constructor; no default. */\n image: HTMLImageElement | HTMLCanvasElement | ImageBitmap | OffscreenCanvas | TextureDataSource;\n /** Optional stable identity of the texture in an adapter such as Three.js. */\n source?: object;\n /** Incremented by `markUpdated()`. */\n version = 0;\n\n /** Flip the image vertically when uploading. Default `false`. */\n flipY: boolean = false;\n /** UV repeat applied before sampling this texture. Default `[1, 1]`. */\n uvScale: [number, number] = [1, 1];\n /** UV translation applied after repeat and before wrapping. Default `[0, 0]`. */\n uvOffset: [number, number] = [0, 0];\n /** Horizontal material-texture addressing after UV scale/offset. Default `'repeat'`. */\n wrapS: TextureWrapMode = 'repeat';\n /** Vertical material-texture addressing after UV scale/offset. Default `'repeat'`. */\n wrapT: TextureWrapMode = 'repeat';\n /** Material color encoding. Default undefined: sRGB for images/bytes, linear for float/integer HDR data. Data-map channels ignore this option. */\n colorSpace?: TextureColorSpace;\n /** Geometry UV set used by this texture (Three.js Texture.channel). Default `0`. */\n uvChannel: 0 | 1 = 0;\n constructor(image: HTMLImageElement | HTMLCanvasElement | ImageBitmap | OffscreenCanvas | TextureDataSource) {\n this.image = image;\n }\n\n /**\n * Call after editing image pixels or UV array elements in place. Increments\n * version so the next render refreshes all materials, lights and backgrounds\n * using this texture. Assigning a new image, UV array, flipY, wrapS, wrapT, colorSpace or\n * uvChannel is detected automatically.\n */\n markUpdated() {\n this.version++;\n return this;\n }\n}\n\nexport function isTextureDataSource(\n image: unknown\n): image is TextureDataSource {\n return !!(image && (image as TextureDataSource).data);\n}\n\n"]}