@meimu/mutracer 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +222 -0
- package/LICENSES/FidelityFX-FSR.txt +19 -0
- package/LICENSES/pbrt-v4-Apache-2.0.txt +202 -0
- package/THIRD_PARTY_NOTICES.md +18 -4
- package/dist/assets/bvh.worker.js +1 -1
- package/dist/mutracer.umd.js +6260 -5580
- package/docs/api.md +45 -18
- package/docs/materials.md +4 -2
- package/docs/performance.md +7 -0
- package/docs/post-processing.md +62 -9
- package/docs/progressive-rendering.md +3 -0
- package/docs/sampling.md +4 -0
- package/docs/technical/acceleration.md +52 -0
- package/docs/technical/aovs.md +79 -0
- package/docs/technical/caustics.md +109 -0
- package/docs/technical/continuous-spectrum.md +29 -0
- package/docs/technical/display-upscale.md +82 -0
- package/docs/technical/openpbr.md +99 -0
- package/docs/technical/pbrt-import.md +168 -0
- package/docs/technical/tiling.md +74 -0
- package/docs/technical/webgl.md +53 -0
- package/docs/viewer.md +11 -1
- package/lib/Display.d.ts +19 -5
- package/lib/Display.js +10 -7
- package/lib/Display.js.map +1 -1
- package/lib/Engine.d.ts +2 -1
- package/lib/Engine.js +30 -2
- package/lib/Engine.js.map +1 -1
- package/lib/Render.d.ts +20 -11
- package/lib/Render.js +32 -7
- package/lib/Render.js.map +1 -1
- package/lib/main.d.ts +3 -1
- package/lib/main.js +1 -0
- package/lib/main.js.map +1 -1
- package/lib/oidn.d.ts +1 -1
- package/lib/renderer/AovPrimitiveCache.js +39 -8
- package/lib/renderer/AovPrimitiveCache.js.map +1 -1
- package/lib/renderer/DisplayPostProcess.d.ts +8 -3
- package/lib/renderer/DisplayPostProcess.js +51 -18
- package/lib/renderer/DisplayPostProcess.js.map +1 -1
- package/lib/renderer/MaterialData.js +7 -2
- package/lib/renderer/MaterialData.js.map +1 -1
- package/lib/renderer/RenderingPipeline.d.ts +7 -1
- package/lib/renderer/RenderingPipeline.js.map +1 -1
- package/lib/renderer/TileRender.d.ts +2 -2
- package/lib/renderer/TileRender.js +128 -7
- package/lib/renderer/TileRender.js.map +1 -1
- package/lib/renderer/WGPUAov.d.ts +6 -1
- package/lib/renderer/WGPUAov.js +108 -14
- package/lib/renderer/WGPUAov.js.map +1 -1
- package/lib/renderer/WGPUCanvasSurface.js +12 -1
- package/lib/renderer/WGPUCanvasSurface.js.map +1 -1
- package/lib/renderer/WGPUEnvMapDistribution.js +19 -19
- package/lib/renderer/WGPUFullQuadPass.js +3 -3
- package/lib/renderer/WGPURayTraceOutput.js +12 -12
- package/lib/renderer/WGPURayTracePass.d.ts +17 -4
- package/lib/renderer/WGPURayTracePass.js +194 -71
- package/lib/renderer/WGPURayTracePass.js.map +1 -1
- package/lib/renderer/WGPURenderingPipeline.js +46 -40
- package/lib/renderer/WGPURenderingPipeline.js.map +1 -1
- package/lib/renderer/WebGLAov.js +3 -3
- package/lib/renderer/WebGLAov.js.map +1 -1
- package/lib/renderer/WebGLFullQuadPass.d.ts +1 -1
- package/lib/renderer/WebGLFullQuadPass.js +8 -2
- package/lib/renderer/WebGLFullQuadPass.js.map +1 -1
- package/lib/renderer/WebGLJNLMDenoiser.js +66 -66
- package/lib/renderer/WebGLJNLMDenoiser.js.map +1 -1
- package/lib/renderer/WebGLRayTraceOutputPass.js +4 -4
- package/lib/renderer/WebGLRayTracePass.d.ts +14 -10
- package/lib/renderer/WebGLRayTracePass.js +115 -111
- package/lib/renderer/WebGLRayTracePass.js.map +1 -1
- package/lib/renderer/WebGLRenderingPipeline.js +10 -3
- package/lib/renderer/WebGLRenderingPipeline.js.map +1 -1
- package/lib/renderer/WebGLSkyBaker.js +57 -57
- package/lib/renderer/aov.d.ts +13 -1
- package/lib/renderer/aov.js +21 -2
- package/lib/renderer/aov.js.map +1 -1
- package/lib/renderer/aovDisplay.js +2 -2
- package/lib/renderer/aovDisplay.js.map +1 -1
- package/lib/renderer/binnedSahBvh.d.ts +2 -1
- package/lib/renderer/binnedSahBvh.js +24 -17
- package/lib/renderer/binnedSahBvh.js.map +1 -1
- package/lib/renderer/bvhAccel.d.ts +3 -1
- package/lib/renderer/bvhAccel.js +36 -6
- package/lib/renderer/bvhAccel.js.map +1 -1
- package/lib/renderer/cameraUniform.d.ts +1 -1
- package/lib/renderer/cameraUniform.js +6 -2
- package/lib/renderer/cameraUniform.js.map +1 -1
- package/lib/renderer/compactVertices.d.ts +14 -0
- package/lib/renderer/compactVertices.js +124 -0
- package/lib/renderer/compactVertices.js.map +1 -0
- package/lib/renderer/easu.d.ts +11 -0
- package/lib/renderer/easu.js +156 -0
- package/lib/renderer/easu.js.map +1 -0
- package/lib/renderer/geometryUpdateState.d.ts +1 -0
- package/lib/renderer/geometryUpdateState.js.map +1 -1
- package/lib/renderer/geometryUpdates.js +3 -2
- package/lib/renderer/geometryUpdates.js.map +1 -1
- package/lib/renderer/glsl/aovDisplay.frag.js +5 -5
- package/lib/renderer/glsl/aovReflectance.glsl.js +35 -35
- package/lib/renderer/glsl/aovReflectanceSamples.glsl.js +1 -1
- package/lib/renderer/glsl/aovTrace.frag.js +44 -36
- package/lib/renderer/glsl/aovTrace.frag.js.map +1 -1
- package/lib/renderer/glsl/chunks/cameraProjection.glsl.d.ts +2 -0
- package/lib/renderer/glsl/chunks/cameraProjection.glsl.js +16 -0
- package/lib/renderer/glsl/chunks/cameraProjection.glsl.js.map +1 -0
- package/lib/renderer/glsl/chunks/cameraRay.glsl.d.ts +1 -1
- package/lib/renderer/glsl/chunks/cameraRay.glsl.js +9 -16
- package/lib/renderer/glsl/chunks/cameraRay.glsl.js.map +1 -1
- package/lib/renderer/glsl/chunks/emissiveLight.glsl.js +8 -8
- package/lib/renderer/glsl/chunks/envMap.glsl.js +67 -67
- package/lib/renderer/glsl/chunks/intersect.glsl.js +390 -375
- package/lib/renderer/glsl/chunks/intersect.glsl.js.map +1 -1
- package/lib/renderer/glsl/chunks/materialBuffer.glsl.js +120 -120
- package/lib/renderer/glsl/chunks/openPbrBsdf.glsl.js +562 -562
- package/lib/renderer/glsl/chunks/rand.glsl.js +3 -3
- package/lib/renderer/glsl/chunks/random.glsl.js +4 -4
- package/lib/renderer/glsl/chunks/rayTraceCore.glsl.js +37 -35
- package/lib/renderer/glsl/chunks/rayTraceCore.glsl.js.map +1 -1
- package/lib/renderer/glsl/chunks/sampleLight.glsl.js +70 -74
- package/lib/renderer/glsl/chunks/sampleLight.glsl.js.map +1 -1
- package/lib/renderer/glsl/chunks/sampleMaterial.glsl.d.ts +1 -1
- package/lib/renderer/glsl/chunks/sampleMaterial.glsl.js +107 -88
- package/lib/renderer/glsl/chunks/sampleMaterial.glsl.js.map +1 -1
- package/lib/renderer/glsl/chunks/sampleShadowCatcher.glsl.js +11 -11
- package/lib/renderer/glsl/chunks/sampling.glsl.js +77 -77
- package/lib/renderer/glsl/chunks/sobol.glsl.js +70 -70
- package/lib/renderer/glsl/chunks/spectralPrefix.glsl.d.ts +6 -0
- package/lib/renderer/glsl/chunks/spectralPrefix.glsl.js +47 -0
- package/lib/renderer/glsl/chunks/spectralPrefix.glsl.js.map +1 -0
- package/lib/renderer/glsl/chunks/textureLinear.glsl.js +5 -5
- package/lib/renderer/glsl/chunks/uvProjection.glsl.js +11 -11
- package/lib/renderer/glsl/depthQuery.frag.js +12 -6
- package/lib/renderer/glsl/depthQuery.frag.js.map +1 -1
- package/lib/renderer/glsl/normalizeRayTraceOutput.frag.js +10 -10
- package/lib/renderer/glsl/rayTrace.frag.js +233 -170
- package/lib/renderer/glsl/rayTrace.frag.js.map +1 -1
- package/lib/renderer/glsl/shadowCatcher.frag.js +10 -9
- package/lib/renderer/glsl/shadowCatcher.frag.js.map +1 -1
- package/lib/renderer/glsl/webglPipeline.frag.js +58 -58
- package/lib/renderer/gpuMemory.js +1 -1
- package/lib/renderer/gpuMemory.js.map +1 -1
- package/lib/renderer/openPbrEnergyLut.d.ts +2 -1
- package/lib/renderer/openPbrEnergyLut.js +18 -1
- package/lib/renderer/openPbrEnergyLut.js.map +1 -1
- package/lib/renderer/pathLimits.d.ts +5 -4
- package/lib/renderer/pathLimits.js +6 -5
- package/lib/renderer/pathLimits.js.map +1 -1
- package/lib/renderer/prepareMeshBVH.d.ts +2 -0
- package/lib/renderer/prepareMeshBVH.js +5 -3
- package/lib/renderer/prepareMeshBVH.js.map +1 -1
- package/lib/renderer/progressiveScheduler.js +1 -1
- package/lib/renderer/progressiveScheduler.js.map +1 -1
- package/lib/renderer/renderPipeline.d.ts +4 -0
- package/lib/renderer/renderPipeline.js +1 -0
- package/lib/renderer/renderPipeline.js.map +1 -1
- package/lib/renderer/researchTransport.d.ts +1 -1
- package/lib/renderer/researchTransport.js.map +1 -1
- package/lib/renderer/sceneAssembly.d.ts +1 -1
- package/lib/renderer/sceneAssembly.js +4 -3
- package/lib/renderer/sceneAssembly.js.map +1 -1
- package/lib/renderer/sceneChangeDetector.d.ts +1 -1
- package/lib/renderer/sceneChangeDetector.js +3 -1
- package/lib/renderer/sceneChangeDetector.js.map +1 -1
- package/lib/renderer/sceneLayoutSchema.d.ts +1 -0
- package/lib/renderer/sceneLayoutSchema.js +2 -2
- package/lib/renderer/sceneLayoutSchema.js.map +1 -1
- package/lib/renderer/scenePreparation.d.ts +3 -2
- package/lib/renderer/scenePreparation.js +18 -2
- package/lib/renderer/scenePreparation.js.map +1 -1
- package/lib/renderer/scratchSampling.js +6 -6
- package/lib/renderer/spectrum.js +2 -2
- package/lib/renderer/staticBvhPreparation.d.ts +9 -0
- package/lib/renderer/staticBvhPreparation.js +8 -2
- package/lib/renderer/staticBvhPreparation.js.map +1 -1
- package/lib/renderer/surfaceHit.d.ts +10 -0
- package/lib/renderer/surfaceHit.js +22 -0
- package/lib/renderer/surfaceHit.js.map +1 -0
- package/lib/renderer/tangentRequirements.d.ts +2 -0
- package/lib/renderer/tangentRequirements.js +7 -0
- package/lib/renderer/tangentRequirements.js.map +1 -0
- package/lib/renderer/textureAtlas.d.ts +4 -0
- package/lib/renderer/textureAtlas.js +48 -2
- package/lib/renderer/textureAtlas.js.map +1 -1
- package/lib/renderer/webgl.js +4 -0
- package/lib/renderer/webgl.js.map +1 -1
- package/lib/renderer/webglVertexAttributes.d.ts +17 -0
- package/lib/renderer/webglVertexAttributes.js +44 -0
- package/lib/renderer/webglVertexAttributes.js.map +1 -0
- package/lib/renderer/wgpuBindlessSource.js +2 -2
- package/lib/renderer/wgpuMaterialConstants.js +4 -3
- package/lib/renderer/wgpuMaterialConstants.js.map +1 -1
- package/lib/renderer/wgpuSceneUniform.js +2 -2
- package/lib/renderer/wgpuSceneUniform.js.map +1 -1
- package/lib/renderer/wgpuShaderSource.d.ts +15 -0
- package/lib/renderer/wgpuShaderSource.js +1 -1
- package/lib/renderer/wgpuShaderSource.js.map +1 -1
- package/lib/renderer/wgsl/aovCompact.wgsl.d.ts +4 -0
- package/lib/renderer/wgsl/aovCompact.wgsl.js +26 -0
- package/lib/renderer/wgsl/aovCompact.wgsl.js.map +1 -0
- package/lib/renderer/wgsl/aovDisplay.wgsl.js +9 -9
- package/lib/renderer/wgsl/aovReflectance.wgsl.js +39 -39
- package/lib/renderer/wgsl/aovReflectanceSamples.wgsl.js +1 -1
- package/lib/renderer/wgsl/aovResolve.wgsl.d.ts +4 -0
- package/lib/renderer/wgsl/aovResolve.wgsl.js +21 -2
- package/lib/renderer/wgsl/aovResolve.wgsl.js.map +1 -1
- package/lib/renderer/wgsl/aovSnapshot.wgsl.js +2 -2
- package/lib/renderer/wgsl/aovSnapshot.wgsl.js.map +1 -1
- package/lib/renderer/wgsl/aovTrace.wgsl.js +31 -31
- package/lib/renderer/wgsl/aovTraceDisplay.wgsl.d.ts +2 -0
- package/lib/renderer/wgsl/aovTraceDisplay.wgsl.js +56 -0
- package/lib/renderer/wgsl/aovTraceDisplay.wgsl.js.map +1 -0
- package/lib/renderer/wgsl/bloom.wgsl.js +18 -18
- package/lib/renderer/wgsl/causticLight.compute.d.ts +1 -1
- package/lib/renderer/wgsl/causticLight.compute.js +121 -119
- package/lib/renderer/wgsl/causticLight.compute.js.map +1 -1
- package/lib/renderer/wgsl/chunks/background.wgsl.js +46 -46
- package/lib/renderer/wgsl/chunks/causticAdjoint.wgsl.js +4 -4
- package/lib/renderer/wgsl/chunks/causticAtomic.wgsl.js +3 -3
- package/lib/renderer/wgsl/chunks/caustics.wgsl.js +3 -3
- package/lib/renderer/wgsl/chunks/common.wgsl.js +4 -4
- package/lib/renderer/wgsl/chunks/envMap.wgsl.js +30 -30
- package/lib/renderer/wgsl/chunks/intersect.wgsl.d.ts +6 -2
- package/lib/renderer/wgsl/chunks/intersect.wgsl.js +550 -542
- package/lib/renderer/wgsl/chunks/intersect.wgsl.js.map +1 -1
- package/lib/renderer/wgsl/chunks/intersectionAlpha.wgsl.d.ts +1 -1
- package/lib/renderer/wgsl/chunks/intersectionAlpha.wgsl.js +18 -16
- package/lib/renderer/wgsl/chunks/intersectionAlpha.wgsl.js.map +1 -1
- package/lib/renderer/wgsl/chunks/materialBuffer.wgsl.d.ts +2 -1
- package/lib/renderer/wgsl/chunks/materialBuffer.wgsl.js +70 -69
- package/lib/renderer/wgsl/chunks/materialBuffer.wgsl.js.map +1 -1
- package/lib/renderer/wgsl/chunks/openPbrBsdf.wgsl.js +593 -593
- package/lib/renderer/wgsl/chunks/pdm_displacement.wgsl.js +118 -118
- package/lib/renderer/wgsl/chunks/rand.wgsl.js +3 -3
- package/lib/renderer/wgsl/chunks/rayTraceCore.wgsl.d.ts +4 -1
- package/lib/renderer/wgsl/chunks/rayTraceCore.wgsl.js +32 -26
- package/lib/renderer/wgsl/chunks/rayTraceCore.wgsl.js.map +1 -1
- package/lib/renderer/wgsl/chunks/sampleLight.wgsl.js +114 -114
- package/lib/renderer/wgsl/chunks/sampleMaterial.wgsl.d.ts +1 -1
- package/lib/renderer/wgsl/chunks/sampleMaterial.wgsl.js +159 -137
- package/lib/renderer/wgsl/chunks/sampleMaterial.wgsl.js.map +1 -1
- package/lib/renderer/wgsl/chunks/sampleShadowCatcher.wgsl.js +8 -8
- package/lib/renderer/wgsl/chunks/sampling.wgsl.js +74 -74
- package/lib/renderer/wgsl/chunks/sobol.wgsl.js +74 -74
- package/lib/renderer/wgsl/chunks/spectralPrefix.wgsl.d.ts +6 -0
- package/lib/renderer/wgsl/chunks/spectralPrefix.wgsl.js +66 -0
- package/lib/renderer/wgsl/chunks/spectralPrefix.wgsl.js.map +1 -0
- package/lib/renderer/wgsl/chunks/uvProjection.wgsl.js +11 -11
- package/lib/renderer/wgsl/chunks/vertexAttributes.wgsl.d.ts +2 -0
- package/lib/renderer/wgsl/chunks/vertexAttributes.wgsl.js +61 -0
- package/lib/renderer/wgsl/chunks/vertexAttributes.wgsl.js.map +1 -0
- package/lib/renderer/wgsl/compose.frag.wgsl.d.ts +2 -0
- package/lib/renderer/wgsl/compose.frag.wgsl.js +99 -97
- package/lib/renderer/wgsl/compose.frag.wgsl.js.map +1 -1
- package/lib/renderer/wgsl/customDenoise.wgsl.js +10 -10
- package/lib/renderer/wgsl/depthQuery.wgsl.d.ts +1 -1
- package/lib/renderer/wgsl/depthQuery.wgsl.js +11 -2
- package/lib/renderer/wgsl/depthQuery.wgsl.js.map +1 -1
- package/lib/renderer/wgsl/easu.wgsl.d.ts +2 -0
- package/lib/renderer/wgsl/easu.wgsl.js +80 -0
- package/lib/renderer/wgsl/easu.wgsl.js.map +1 -0
- package/lib/renderer/wgsl/easuDetail.wgsl.d.ts +21 -0
- package/lib/renderer/wgsl/easuDetail.wgsl.js +230 -0
- package/lib/renderer/wgsl/easuDetail.wgsl.js.map +1 -0
- package/lib/renderer/wgsl/jnlm.compute.js +74 -74
- package/lib/renderer/wgsl/jnlm.compute.js.map +1 -1
- package/lib/renderer/wgsl/offlineAdaptive.compute.js +26 -26
- package/lib/renderer/wgsl/oidnAuxiliary.wgsl.js +3 -3
- package/lib/renderer/wgsl/photonMap.compute.js +89 -89
- package/lib/renderer/wgsl/proceduralSky.compute.js +61 -61
- package/lib/renderer/wgsl/rayTrace.compute.d.ts +14 -0
- package/lib/renderer/wgsl/rayTrace.compute.js +395 -333
- package/lib/renderer/wgsl/rayTrace.compute.js.map +1 -1
- package/lib/scene/Scene.js.map +1 -1
- package/lib/settings/render.d.ts +11 -0
- package/lib/settings/render.js +1 -0
- package/lib/settings/render.js.map +1 -1
- package/lib/util/fromTHREE.js +21 -14
- package/lib/util/fromTHREE.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/lib/version.js.map +1 -1
- package/package.json +5 -2
- package/lib/oidnBundledWeights.cdn.d.ts +0 -2
- package/lib/oidnBundledWeights.cdn.js +0 -5
- package/lib/oidnBundledWeights.cdn.js.map +0 -1
- package/lib/renderer/bvh.worker.d.ts +0 -1
- package/lib/renderer/bvh.worker.js +0 -16
- package/lib/renderer/bvh.worker.js.map +0 -1
- package/lib/renderer/bvhWorkerBuild.d.ts +0 -13
- package/lib/renderer/bvhWorkerBuild.js +0 -17
- package/lib/renderer/bvhWorkerBuild.js.map +0 -1
- package/lib/renderer/lightCore.d.ts +0 -12
- package/lib/renderer/lightCore.js +0 -13
- package/lib/renderer/lightCore.js.map +0 -1
- package/lib/renderer/materialCore.d.ts +0 -8
- package/lib/renderer/materialCore.js +0 -9
- package/lib/renderer/materialCore.js.map +0 -1
- package/lib/scene/PixelTexture.d.ts +0 -6
- package/lib/scene/PixelTexture.js +0 -10
- package/lib/scene/PixelTexture.js.map +0 -1
- package/lib/util/studioLighting.d.ts +0 -18
- package/lib/util/studioLighting.js +0 -36
- package/lib/util/studioLighting.js.map +0 -1
|
@@ -5,13 +5,13 @@ import { glsl } from '../../shader.js';
|
|
|
5
5
|
export default glsl `
|
|
6
6
|
uvec4 s0;
|
|
7
7
|
|
|
8
|
-
void
|
|
8
|
+
void fA(vec2 p, int frame) {
|
|
9
9
|
|
|
10
10
|
s0 = uvec4(p, uint(frame), uint(p.x) + uint(p.y));
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
void
|
|
14
|
+
void zF(inout uvec4 v) {
|
|
15
15
|
v = v * 1664525u + 1013904223u;
|
|
16
16
|
v.x += v.y*v.w; v.y += v.z*v.x; v.z += v.x*v.y; v.w += v.y*v.z;
|
|
17
17
|
v = v ^ (v>>16u);
|
|
@@ -19,7 +19,7 @@ v.x += v.y*v.w; v.y += v.z*v.x; v.z += v.x*v.y; v.w += v.y*v.z;
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
float rand() {
|
|
22
|
-
|
|
22
|
+
zF(s0); return float(s0.x)/float(0xffffffffu);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
`;
|
|
@@ -10,13 +10,13 @@ export default createShaderMixin({
|
|
|
10
10
|
|
|
11
11
|
${sobol}
|
|
12
12
|
|
|
13
|
-
void
|
|
14
|
-
|
|
13
|
+
void sP() {
|
|
14
|
+
aJ = uvec2(v_Texcoord / pixelSize);
|
|
15
15
|
aC = uint(sampleCount);
|
|
16
|
-
samplingBounce = 0u;
|
|
16
|
+
samplingBounce = 0u; hashedCounter = 0u;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
vec2
|
|
19
|
+
vec2 uH() {
|
|
20
20
|
if (samplingPattern == 0 || samplingPattern == 1) {
|
|
21
21
|
return (sample2D(CAMERA_PIXEL) - 0.5) * pixelSize;
|
|
22
22
|
}
|
|
@@ -24,7 +24,7 @@ export function createRayTraceCoreGlsl(fragments = {}) {
|
|
|
24
24
|
main: glsl `
|
|
25
25
|
|
|
26
26
|
const vec3 luminance = vec3(0.2126, 0.7152, 0.0722);
|
|
27
|
-
const int
|
|
27
|
+
const int zL = 8;
|
|
28
28
|
|
|
29
29
|
#define RAY_MAX_DISTANCE 9999.0
|
|
30
30
|
|
|
@@ -165,22 +165,24 @@ ray.tMax = RAY_MAX_DISTANCE;
|
|
|
165
165
|
}
|
|
166
166
|
|
|
167
167
|
|
|
168
|
-
ivec2
|
|
168
|
+
ivec2 uO(int i, int ki) {
|
|
169
169
|
ivec2 u;
|
|
170
|
-
u.y = i >>
|
|
171
|
-
u.x = i - (u.y <<
|
|
170
|
+
u.y = i >> ki;
|
|
171
|
+
u.x = i - (u.y << ki);
|
|
172
172
|
return u;
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
-
vec4 fetchData(sampler2D s, int i, int
|
|
176
|
-
return texelFetch(s,
|
|
175
|
+
vec4 fetchData(sampler2D s, int i, int ki) {
|
|
176
|
+
return texelFetch(s, uO(i, ki), 0);
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
ivec4 fetchData(highp isampler2D s, int i, int
|
|
180
|
-
return texelFetch(s,
|
|
179
|
+
ivec4 fetchData(highp isampler2D s, int i, int ki) {
|
|
180
|
+
return texelFetch(s, uO(i, ki), 0);
|
|
181
181
|
}
|
|
182
182
|
|
|
183
183
|
struct Path {
|
|
184
|
+
|
|
185
|
+
bool scatteringMediumEntered;
|
|
184
186
|
Ray ray;
|
|
185
187
|
vec3 li;
|
|
186
188
|
float alpha;
|
|
@@ -216,12 +218,12 @@ lightsTex,
|
|
|
216
218
|
ivec2(firstTexel + 1, 0),
|
|
217
219
|
0
|
|
218
220
|
);
|
|
219
|
-
vec4
|
|
221
|
+
vec4 pG = texelFetch(
|
|
220
222
|
lightsTex,
|
|
221
223
|
ivec2(firstTexel + 2, 0),
|
|
222
224
|
0
|
|
223
225
|
);
|
|
224
|
-
vec4
|
|
226
|
+
vec4 mW = texelFetch(
|
|
225
227
|
lightsTex,
|
|
226
228
|
ivec2(firstTexel + 3, 0),
|
|
227
229
|
0
|
|
@@ -234,31 +236,31 @@ ivec2(firstTexel + 4, 0),
|
|
|
234
236
|
return Light(
|
|
235
237
|
positionAndPmf.xyz,
|
|
236
238
|
emissionAndCdf.xyz,
|
|
237
|
-
|
|
238
|
-
|
|
239
|
+
pG.xyz,
|
|
240
|
+
mW.xyz,
|
|
239
241
|
shape.x,
|
|
240
242
|
shape.y,
|
|
241
243
|
shape.z,
|
|
242
|
-
int(
|
|
243
|
-
|
|
244
|
+
int(mW.w),
|
|
245
|
+
pG.w,
|
|
244
246
|
positionAndPmf.w,
|
|
245
247
|
emissionAndCdf.w,
|
|
246
248
|
texelFetch(lightsTex, ivec2(firstTexel + 5, 0), 0).xyz
|
|
247
249
|
);
|
|
248
250
|
}
|
|
249
251
|
|
|
250
|
-
float
|
|
251
|
-
int
|
|
252
|
+
float cI(int ec, int mC) {
|
|
253
|
+
int iR = ec + mC / 4;
|
|
252
254
|
vec4 packed = texelFetch(
|
|
253
255
|
iesProfileData,
|
|
254
|
-
ivec2(
|
|
256
|
+
ivec2(iR % iesProfileColumns, iR / iesProfileColumns),
|
|
255
257
|
0
|
|
256
258
|
);
|
|
257
|
-
return packed[
|
|
259
|
+
return packed[mC % 4];
|
|
258
260
|
}
|
|
259
261
|
|
|
260
|
-
float
|
|
261
|
-
if (
|
|
262
|
+
float lW(int ec, vec2 uv) {
|
|
263
|
+
if (ec < 0) return 1.0;
|
|
262
264
|
vec2 pixel = fract(uv) * 128.0 - 0.5;
|
|
263
265
|
ivec2 p0 = ivec2(floor(pixel));
|
|
264
266
|
vec2 f = fract(pixel);
|
|
@@ -266,25 +268,25 @@ int xa = p0.x < 0 ? 127 : p0.x;
|
|
|
266
268
|
int xb = p0.x >= 127 ? 0 : p0.x + 1;
|
|
267
269
|
int ya = p0.y < 0 ? 127 : p0.y;
|
|
268
270
|
int yb = p0.y >= 127 ? 0 : p0.y + 1;
|
|
269
|
-
float a =
|
|
270
|
-
float b =
|
|
271
|
-
float c =
|
|
272
|
-
float d =
|
|
271
|
+
float a = cI(ec, ya * 128 + xa);
|
|
272
|
+
float b = cI(ec, ya * 128 + xb);
|
|
273
|
+
float c = cI(ec, yb * 128 + xa);
|
|
274
|
+
float d = cI(ec, yb * 128 + xb);
|
|
273
275
|
return mix(mix(a, b, f.x), mix(c, d, f.x), f.y);
|
|
274
276
|
}
|
|
275
277
|
|
|
276
|
-
float evaluateSpotEmissionMultiplier(Light light, vec3
|
|
278
|
+
float evaluateSpotEmissionMultiplier(Light light, vec3 dL) {
|
|
277
279
|
vec3 axis = normalize(light.u);
|
|
278
|
-
float
|
|
279
|
-
float
|
|
280
|
-
? smoothstep(light.v.x, light.v.y,
|
|
281
|
-
: step(light.v.x,
|
|
282
|
-
if (
|
|
283
|
-
vec3
|
|
284
|
-
vec3
|
|
285
|
-
float vertical = acos(clamp(
|
|
286
|
-
float horizontal = atan(dot(
|
|
287
|
-
return
|
|
280
|
+
float cv = dot(axis, dL);
|
|
281
|
+
float xm = light.v.y > light.v.x + 1e-6
|
|
282
|
+
? smoothstep(light.v.x, light.v.y, cv)
|
|
283
|
+
: step(light.v.x, cv);
|
|
284
|
+
if (xm <= 0.0 || light.textureIndex < 0) return xm;
|
|
285
|
+
vec3 xT = light.iesReference;
|
|
286
|
+
vec3 zK = cross(axis, xT);
|
|
287
|
+
float vertical = acos(clamp(cv, -1.0, 1.0));
|
|
288
|
+
float horizontal = atan(dot(dL, zK), dot(dL, xT));
|
|
289
|
+
return xm * lW(light.textureIndex, vec2(vertical / PI, horizontal / TWOPI + 0.5));
|
|
288
290
|
}
|
|
289
291
|
`
|
|
290
292
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rayTraceCore.glsl.js","sourceRoot":"","sources":["../../../../src/renderer/glsl/chunks/rayTraceCore.glsl.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,sDAAsD;AACtD,kFAAkF;AAElF,OAAO,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC7E,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAE9D,MAAM,UAAU,sBAAsB,CAAC,YAA8C,EAAE;IAAI,OAAO,iBAAiB,CAAC;QAClH,QAAQ,EAAE;YACR,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC;YACtC,cAAc,EAAE,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC;YAC3C,iBAAiB,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;YAC3C,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;YACjC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;YAC9B,WAAW,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;YAClC,oBAAoB,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;SACjD;QACD,OAAO,EAAE;YACP,QAAQ,EAAE,CAAC;YACX,KAAK,EAAE,aAAa;YACpB,cAAc,EAAE,qBAAqB;YACrC,UAAU,EAAE,mBAAmB;SAChC;QACD,IAAI,EAAE,IAAI,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BA6DgB,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE
|
|
1
|
+
{"version":3,"file":"rayTraceCore.glsl.js","sourceRoot":"","sources":["../../../../src/renderer/glsl/chunks/rayTraceCore.glsl.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,sDAAsD;AACtD,kFAAkF;AAElF,OAAO,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC7E,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAE9D,MAAM,UAAU,sBAAsB,CAAC,YAA8C,EAAE;IAAI,OAAO,iBAAiB,CAAC;QAClH,QAAQ,EAAE;YACR,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC;YACtC,cAAc,EAAE,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC;YAC3C,iBAAiB,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;YAC3C,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;YACjC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;YAC9B,WAAW,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;YAClC,oBAAoB,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;SACjD;QACD,OAAO,EAAE;YACP,QAAQ,EAAE,CAAC;YACX,KAAK,EAAE,aAAa;YACpB,cAAc,EAAE,qBAAqB;YACrC,UAAU,EAAE,mBAAmB;SAChC;QACD,IAAI,EAAE,IAAI,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BA6DgB,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA6G1B,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiGjD;KACA,CAAC,CAAC;AACH,CAAC;AACD,eAAe,sBAAsB,EAAE,CAAC","sourcesContent":["// Portions adapted from ray-tracing-renderer@0.10.15\n// (https://github.com/hoverinc/ray-tracing-renderer).\n// Copyright (c) 2019 HOVER, MIT license; see LICENSES/RayTracingRenderer-MIT.txt.\n\nimport { createShaderMixin, glsl, Shader } from '../../shader.js';\nimport { ShadowCatcherMaterial, UnlitMaterial } from '../../../constants.js';\nimport { CONSTANT_SPOT_LIGHT } from '../../lightConstants.js';\n\nexport function createRayTraceCoreGlsl(fragments: Readonly<Record<string, string>> = {}) { return createShaderMixin({\n uniforms: {\n lightsTex: Shader.uniform('sampler2D'),\n iesProfileData: Shader.uniform('sampler2D'),\n iesProfileColumns: Shader.uniform('int', 1),\n pixelSize: Shader.uniform('vec2'),\n jitter: Shader.uniform('vec2'),\n sampleCount: Shader.uniform('int'),\n envLightSelectionPmf: Shader.uniform('float', 0)\n },\n defines: {\n STANDARD: 0,\n UNLIT: UnlitMaterial,\n SHADOW_CATCHER: ShadowCatcherMaterial,\n SPOT_LIGHT: CONSTANT_SPOT_LIGHT\n },\n main: glsl`\n// https://www.w3.org/WAI/GL/wiki/Relative_luminance\nconst vec3 luminance = vec3(0.2126, 0.7152, 0.0722);\nconst int bounceSamples = 8;\n\n#define RAY_MAX_DISTANCE 9999.0\n\n#define NO_UNROLL(X) (X + min(0, sampleCount))\n#define NO_UNROLLU(X) (X + uint(min(0, sampleCount)))\n\nstruct Ray {\n vec3 o;\n vec3 d;\n float tMax;\n};\n\nstruct SurfaceInteraction {\n bool hit;\n vec3 position;\n vec3 normal; // material shading normal\n#ifdef USE_COAT_NORMAL_FRAMES\n vec3 coatNormal;\n#endif\n vec3 vertexNormal; // interpolated mesh normal before normal mapping\n vec3 shadowOffset; // smooth-surface offset used by direct-light shadow rays\n \n vec2 uv;\n vec2 uv1;\n vec3 vertexColor;\n\n#ifdef USE_TANGENT\n vec3 tangent;\n#endif\n vec3 directionTangent;\n vec3 directionBitangent;\n vec3 geometryTangent;\n vec3 geometryBitangent;\n vec3 faceNormal; // normal of the triangle\n\n bool isTransparency;\n // For perfect specular or transmission surface\n // We use the albedo and normal of first diffuse or glossy surface hit instead for denoising\n // See albedo section in https://www.openimagedenoise.org/documentation.html\n bool albedoSampled;\n\n int triangleIndex;\n int instanceIndex;\n int materialIndex;\n\n int mediumType;\n vec3 mediumExtinction;\n vec3 mediumScattering;\n float mediumAnisotropy;\n};\n\n// Texture-resolved OpenPBR inputs used by the surface integrator. The storage\n// buffer keeps its compact legacy layout; getMaterial() is the compatibility\n// boundary that maps it to these canonical names.\nstruct OpenPbrResolvedMaterial {\n int materialType;\n\n float specularRoughness;${fragments['core0'] ?? ''}\n float baseMetalness;\n vec3 baseColor;\n float specularIor;\n vec3 emission;\n float transmissionWeight;\n bool thinWalled;\n float specularAnisotropy;\n float alpha;\n\n float transmissionDispersionScale;\n float dispersionAbbeNumber;\n float thinFilmThickness;\n float thinFilmIor;\n float thinFilmWeight;\n\n // Medium\n int mediumType;\n vec3 mediumExtinction;\n vec3 mediumScattering;\n float mediumAnisotropy;\n\n float baseWeight;\n float diffuseRoughness;\n float specularWeight;\n vec3 specularColor;\n float subsurfaceWeight;\n vec3 subsurfaceColor;\n vec3 transmissionColor;\n float fuzzWeight;\n vec3 fuzzColor;\n float fuzzRoughness;\n float coatWeight;\n vec3 coatColor;\n float coatRoughness;\n float coatAnisotropy;\n vec2 anisotropyDirection;\n bool anisotropyDirectionEnabled;\n float coatAnisotropyRotation;\n vec3 directionTangent;\n vec3 directionBitangent;\n vec3 geometryTangent;\n vec3 geometryBitangent;\n#ifdef USE_COAT_NORMAL_FRAMES\n vec3 coatNormal;\n bool coatNormalEnabled;\n vec3 geometricNormal;\n#endif\n float coatIor;\n float coatDarkening;\n\n float bevel;\n\n // Calculated\n float relativeIor;\n bool inside;\n float alphaX;\n float alphaY;\n};\n\n\nstruct Light {\n vec3 position;\n vec3 emission;\n vec3 u;\n vec3 v;\n float radius;\n float area;\n float type;\n int textureIndex;\n float spread;\n float selectionPmf;\n float selectionCdf;\n vec3 iesReference;\n};\n\nvoid initRay(inout Ray ray, vec3 origin, vec3 direction) {\n ray.o = origin;\n ray.d = direction;\n ray.tMax = RAY_MAX_DISTANCE;\n}\n\n// given the index from a 1D array, retrieve corresponding position from packed 2D texture\nivec2 unpackTexel(int i, int columnsLog2) {\n ivec2 u;\n u.y = i >> columnsLog2; // equivalent to (i / 2^columnsLog2)\n u.x = i - (u.y << columnsLog2); // equivalent to (i % 2^columnsLog2)\n return u;\n}\n\nvec4 fetchData(sampler2D s, int i, int columnsLog2) {\n return texelFetch(s, unpackTexel(i, columnsLog2), 0);\n}\n\nivec4 fetchData(highp isampler2D s, int i, int columnsLog2) {\n return texelFetch(s, unpackTexel(i, columnsLog2), 0);\n}\n\nstruct Path {\n // Retain deferred roulette after an SSS walk reaches its boundary.\n bool scatteringMediumEntered;\n Ray ray;\n vec3 li;\n float alpha;\n vec3 beta;\n bool fromEye;\n bool abort;\n float scatteringPdf;\n bool scatteringIsDelta;\n bool isNextRefraction;${fragments['core1'] ?? ''}\n};\n\nstruct LightSampleRec {\n vec3 normal;\n vec3 emission;\n vec3 direction;\n float dist;\n float pdf;\n bool isDelta;\n int sourceType;\n int sourceIndex;\n};\n\n\nLight fetchLight(int i) {\n int firstTexel = i * 6;\n vec4 positionAndPmf = texelFetch(\n lightsTex,\n ivec2(firstTexel, 0),\n 0\n );\n vec4 emissionAndCdf = texelFetch(\n lightsTex,\n ivec2(firstTexel + 1, 0),\n 0\n );\n vec4 tangentAndSpread = texelFetch(\n lightsTex,\n ivec2(firstTexel + 2, 0),\n 0\n );\n vec4 bitangentAndTexture = texelFetch(\n lightsTex,\n ivec2(firstTexel + 3, 0),\n 0\n );\n vec4 shape = texelFetch(\n lightsTex,\n ivec2(firstTexel + 4, 0),\n 0\n );\n return Light(\n positionAndPmf.xyz,\n emissionAndCdf.xyz,\n tangentAndSpread.xyz,\n bitangentAndTexture.xyz,\n shape.x,\n shape.y,\n shape.z,\n int(bitangentAndTexture.w),\n tangentAndSpread.w,\n positionAndPmf.w,\n emissionAndCdf.w,\n texelFetch(lightsTex, ivec2(firstTexel + 5, 0), 0).xyz\n );\n}\n\nfloat iesProfileScalar(int baseTexel, int scalarIndex) {\n int texelIndex = baseTexel + scalarIndex / 4;\n vec4 packed = texelFetch(\n iesProfileData,\n ivec2(texelIndex % iesProfileColumns, texelIndex / iesProfileColumns),\n 0\n );\n return packed[scalarIndex % 4];\n}\n\nfloat sampleIESProfile(int baseTexel, vec2 uv) {\n if (baseTexel < 0) return 1.0;\n vec2 pixel = fract(uv) * 128.0 - 0.5;\n ivec2 p0 = ivec2(floor(pixel));\n vec2 f = fract(pixel);\n int xa = p0.x < 0 ? 127 : p0.x;\n int xb = p0.x >= 127 ? 0 : p0.x + 1;\n int ya = p0.y < 0 ? 127 : p0.y;\n int yb = p0.y >= 127 ? 0 : p0.y + 1;\n float a = iesProfileScalar(baseTexel, ya * 128 + xa);\n float b = iesProfileScalar(baseTexel, ya * 128 + xb);\n float c = iesProfileScalar(baseTexel, yb * 128 + xa);\n float d = iesProfileScalar(baseTexel, yb * 128 + xb);\n return mix(mix(a, b, f.x), mix(c, d, f.x), f.y);\n}\n\nfloat evaluateSpotEmissionMultiplier(Light light, vec3 lightToSurface) {\n vec3 axis = normalize(light.u);\n float cosTheta = dot(axis, lightToSurface);\n float cone = light.v.y > light.v.x + 1e-6\n ? smoothstep(light.v.x, light.v.y, cosTheta)\n : step(light.v.x, cosTheta);\n if (cone <= 0.0 || light.textureIndex < 0) return cone;\n vec3 xAxis = light.iesReference;\n vec3 yAxis = cross(axis, xAxis);\n float vertical = acos(clamp(cosTheta, -1.0, 1.0));\n float horizontal = atan(dot(lightToSurface, yAxis), dot(lightToSurface, xAxis));\n return cone * sampleIESProfile(light.textureIndex, vec2(vertical / PI, horizontal / TWOPI + 0.5));\n}\n`\n});\n}\nexport default createRayTraceCoreGlsl();\n"]}
|
|
@@ -2,14 +2,14 @@ import emissive from './emissiveLight.glsl.js';
|
|
|
2
2
|
import { glsl } from '../../shader.js';
|
|
3
3
|
export default glsl `
|
|
4
4
|
#ifdef NUM_LIGHTS
|
|
5
|
-
void
|
|
5
|
+
void eR(
|
|
6
6
|
in Light light,
|
|
7
7
|
in vec3 shadingPoint,
|
|
8
8
|
in vec2 samplePoint,
|
|
9
9
|
inout LightSampleRec result
|
|
10
10
|
) {
|
|
11
|
-
vec3
|
|
12
|
-
float ao = length(
|
|
11
|
+
vec3 pH = light.position - shadingPoint;
|
|
12
|
+
float ao = length(pH);
|
|
13
13
|
if (light.radius <= 0.0) {
|
|
14
14
|
if (ao <= 1e-6) {
|
|
15
15
|
result.direction = vec3(0.0, 0.0, 1.0);
|
|
@@ -20,7 +20,7 @@ result.emission = vec3(0.0);
|
|
|
20
20
|
result.isDelta = true;
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
|
-
result.direction =
|
|
23
|
+
result.direction = pH / ao;
|
|
24
24
|
result.normal = -result.direction;
|
|
25
25
|
result.dist = ao;
|
|
26
26
|
result.pdf = 1.0;
|
|
@@ -29,57 +29,53 @@ result.isDelta = true;
|
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
31
|
float radius = max(light.radius, 1e-6);
|
|
32
|
-
#ifdef HAS_EMISSIVE_LIGHTS
|
|
33
|
-
jb(shadingPoint,randomSampleValue,result);return;
|
|
34
|
-
#endif
|
|
35
|
-
result.sourceType=0;result.sourceIndex=-1;
|
|
36
32
|
result.isDelta = false;
|
|
37
33
|
vec3 direction;
|
|
38
34
|
|
|
39
35
|
if (ao <= radius) {
|
|
40
36
|
float z = 1.0 - 2.0 * samplePoint.x;
|
|
41
|
-
float
|
|
37
|
+
float dw = sqrt(max(0.0, 1.0 - z * z));
|
|
42
38
|
float azimuth = TWOPI * samplePoint.y;
|
|
43
|
-
direction = vec3(
|
|
39
|
+
direction = vec3(dw * cos(azimuth), dw * sin(azimuth), z);
|
|
44
40
|
result.pdf = INV4PI;
|
|
45
41
|
}
|
|
46
42
|
else {
|
|
47
|
-
vec3 axis =
|
|
48
|
-
float
|
|
43
|
+
vec3 axis = pH / ao;
|
|
44
|
+
float pv = min(
|
|
49
45
|
1.0,
|
|
50
46
|
radius * radius / (ao * ao)
|
|
51
47
|
);
|
|
52
|
-
float
|
|
48
|
+
float xn = sqrt(max(0.0, 1.0 - pv));
|
|
53
49
|
|
|
54
50
|
|
|
55
|
-
float
|
|
56
|
-
float
|
|
57
|
-
float cosine = 1.0 -
|
|
58
|
-
float
|
|
51
|
+
float mX = pv / (1.0 + xn);
|
|
52
|
+
float oe = samplePoint.x * mX;
|
|
53
|
+
float cosine = 1.0 - oe;
|
|
54
|
+
float wk = sqrt(max(0.0, oe * (2.0 - oe)));
|
|
59
55
|
float azimuth = TWOPI * samplePoint.y;
|
|
60
56
|
vec3 tangent;
|
|
61
57
|
vec3 bitangent;
|
|
62
58
|
sampling_orthonormal_basis(axis, tangent, bitangent);
|
|
63
59
|
direction = axis * cosine
|
|
64
|
-
+ tangent * (
|
|
65
|
-
+ bitangent * (
|
|
66
|
-
result.pdf = 1.0 / max(TWOPI *
|
|
60
|
+
+ tangent * (wk * cos(azimuth))
|
|
61
|
+
+ bitangent * (wk * sin(azimuth));
|
|
62
|
+
result.pdf = 1.0 / max(TWOPI * mX, 1e-8);
|
|
67
63
|
}
|
|
68
64
|
|
|
69
|
-
float
|
|
70
|
-
float
|
|
71
|
-
- dot(
|
|
72
|
-
float root = sqrt(max(0.0,
|
|
73
|
-
float
|
|
74
|
-
float
|
|
75
|
-
result.dist =
|
|
65
|
+
float jM = dot(direction, pH);
|
|
66
|
+
float bk = jM * jM
|
|
67
|
+
- dot(pH, pH) + radius * radius;
|
|
68
|
+
float root = sqrt(max(0.0, bk));
|
|
69
|
+
float cK = jM - root;
|
|
70
|
+
float cB = jM + root;
|
|
71
|
+
result.dist = cK > 1e-6 ? cK : cB;
|
|
76
72
|
result.direction = direction;
|
|
77
73
|
vec3 surfacePoint = shadingPoint + direction * result.dist;
|
|
78
74
|
result.normal = normalize(surfacePoint - light.position);
|
|
79
75
|
result.emission = light.emission;
|
|
80
76
|
}
|
|
81
77
|
|
|
82
|
-
void
|
|
78
|
+
void bD(
|
|
83
79
|
in Light light,
|
|
84
80
|
in vec3 surfacePoint,
|
|
85
81
|
in vec3 lowerLeft,
|
|
@@ -89,17 +85,17 @@ inout LightSampleRec result
|
|
|
89
85
|
if (light.textureIndex >= 0) {
|
|
90
86
|
float width = length(light.u);
|
|
91
87
|
float height = length(light.v);
|
|
92
|
-
vec3
|
|
88
|
+
vec3 ea = surfacePoint - lowerLeft;
|
|
93
89
|
vec2 uv = vec2(
|
|
94
|
-
dot(
|
|
95
|
-
dot(
|
|
90
|
+
dot(ea, light.u / width) / width,
|
|
91
|
+
dot(ea, light.v / height) / height
|
|
96
92
|
);
|
|
97
93
|
result.emission *= sampleMap(light.textureIndex, uv).rgb;
|
|
98
94
|
}
|
|
99
95
|
#endif
|
|
100
96
|
}
|
|
101
97
|
|
|
102
|
-
void
|
|
98
|
+
void kF(
|
|
103
99
|
in Light light,
|
|
104
100
|
in vec3 shadingPoint,
|
|
105
101
|
in vec2 samplePoint,
|
|
@@ -110,28 +106,28 @@ vec3 lowerLeft = light.position - 0.5 * (light.u + light.v);
|
|
|
110
106
|
float spread = clamp(light.spread, 0.0, 1.0);
|
|
111
107
|
|
|
112
108
|
if (spread <= 0.001) {
|
|
113
|
-
float
|
|
114
|
-
vec3 surfacePoint = shadingPoint - normal *
|
|
115
|
-
vec3
|
|
109
|
+
float gy = dot(normal, shadingPoint - light.position);
|
|
110
|
+
vec3 surfacePoint = shadingPoint - normal * gy;
|
|
111
|
+
vec3 ea = surfacePoint - lowerLeft;
|
|
116
112
|
float width = length(light.u);
|
|
117
113
|
float height = length(light.v);
|
|
118
114
|
vec2 uv = vec2(
|
|
119
|
-
dot(
|
|
120
|
-
dot(
|
|
115
|
+
dot(ea, light.u / width) / width,
|
|
116
|
+
dot(ea, light.v / height) / height
|
|
121
117
|
);
|
|
122
|
-
if (
|
|
118
|
+
if (gy <= 0.0 || any(lessThan(uv, vec2(0.0)))
|
|
123
119
|
|| any(greaterThan(uv, vec2(1.0)))) {
|
|
124
120
|
result.emission = vec3(0.0);
|
|
125
121
|
result.pdf = 0.0;
|
|
126
122
|
return;
|
|
127
123
|
}
|
|
128
124
|
result.direction = -normal;
|
|
129
|
-
result.dist =
|
|
125
|
+
result.dist = gy;
|
|
130
126
|
result.normal = normal;
|
|
131
127
|
result.emission = light.emission;
|
|
132
128
|
result.pdf = 1.0;
|
|
133
129
|
result.isDelta = true;
|
|
134
|
-
|
|
130
|
+
bD(light, surfacePoint, lowerLeft, result);
|
|
135
131
|
return;
|
|
136
132
|
}
|
|
137
133
|
|
|
@@ -143,19 +139,19 @@ float bG = dot(offset, offset);
|
|
|
143
139
|
result.dist = sqrt(bG);
|
|
144
140
|
result.direction = offset / result.dist;
|
|
145
141
|
result.normal = normal;
|
|
146
|
-
float
|
|
147
|
-
float
|
|
148
|
-
if (
|
|
142
|
+
float gq = dot(-result.direction, normal);
|
|
143
|
+
float qB = cos(0.5 * PI * spread);
|
|
144
|
+
if (gq <= 0.0 || gq < qB) {
|
|
149
145
|
result.emission = vec3(0.0);
|
|
150
146
|
result.pdf = 0.0;
|
|
151
147
|
return;
|
|
152
148
|
}
|
|
153
149
|
result.emission = light.emission;
|
|
154
|
-
result.pdf = bG / max(light.area *
|
|
155
|
-
|
|
150
|
+
result.pdf = bG / max(light.area * gq, 1e-8);
|
|
151
|
+
bD(light, surfacePoint, lowerLeft, result);
|
|
156
152
|
}
|
|
157
153
|
|
|
158
|
-
void
|
|
154
|
+
void gs(
|
|
159
155
|
in Light light,
|
|
160
156
|
in vec3 shadingPoint,
|
|
161
157
|
inout LightSampleRec result
|
|
@@ -168,13 +164,13 @@ result.pdf = 1.0;
|
|
|
168
164
|
result.isDelta = true;
|
|
169
165
|
}
|
|
170
166
|
|
|
171
|
-
void
|
|
167
|
+
void kG(
|
|
172
168
|
in Light light,
|
|
173
169
|
in vec3 shadingPoint,
|
|
174
170
|
in vec2 samplePoint,
|
|
175
171
|
inout LightSampleRec result
|
|
176
172
|
) {
|
|
177
|
-
|
|
173
|
+
eR(light, shadingPoint, samplePoint, result);
|
|
178
174
|
vec3 surfacePoint = shadingPoint + result.direction * result.dist;
|
|
179
175
|
result.emission *= evaluateSpotEmissionMultiplier(
|
|
180
176
|
light,
|
|
@@ -188,36 +184,36 @@ in vec3 shadingPoint,
|
|
|
188
184
|
in vec2 samplePoint,
|
|
189
185
|
inout LightSampleRec result
|
|
190
186
|
) {
|
|
191
|
-
int
|
|
187
|
+
int dU = int(light.type);
|
|
192
188
|
#ifdef HAS_RECT_LIGHTS
|
|
193
|
-
if (
|
|
194
|
-
|
|
189
|
+
if (dU == RECT_LIGHT) {
|
|
190
|
+
kF(light, shadingPoint, samplePoint, result);
|
|
195
191
|
return;
|
|
196
192
|
}
|
|
197
193
|
#endif
|
|
198
194
|
#ifdef HAS_SPHERE_LIGHTS
|
|
199
|
-
if (
|
|
200
|
-
|
|
195
|
+
if (dU == SPHERE_LIGHT) {
|
|
196
|
+
eR(light, shadingPoint, samplePoint, result);
|
|
201
197
|
return;
|
|
202
198
|
}
|
|
203
199
|
#endif
|
|
204
200
|
#ifdef HAS_SPOT_LIGHTS
|
|
205
|
-
if (
|
|
206
|
-
|
|
201
|
+
if (dU == SPOT_LIGHT) {
|
|
202
|
+
kG(light, shadingPoint, samplePoint, result);
|
|
207
203
|
return;
|
|
208
204
|
}
|
|
209
205
|
#endif
|
|
210
206
|
#ifdef HAS_DIRECTIONAL_LIGHTS
|
|
211
|
-
if (
|
|
212
|
-
|
|
207
|
+
if (dU == DIRECTIONAL_LIGHT) {
|
|
208
|
+
gs(light, shadingPoint, result);
|
|
213
209
|
}
|
|
214
210
|
#endif
|
|
215
211
|
}
|
|
216
212
|
#endif
|
|
217
213
|
|
|
218
|
-
void
|
|
214
|
+
void iM(in vec2 samplePoint, inout LightSampleRec result) {
|
|
219
215
|
vec2 uv;
|
|
220
|
-
result.direction =
|
|
216
|
+
result.direction = qx(samplePoint, uv, result.pdf);
|
|
221
217
|
result.emission = textureLinear(envMap, uv).rgb;
|
|
222
218
|
result.dist = INF;
|
|
223
219
|
}
|
|
@@ -230,41 +226,41 @@ void sampleLight(
|
|
|
230
226
|
in vec3 shadingPoint,
|
|
231
227
|
in vec3 randomSampleValue,
|
|
232
228
|
inout LightSampleRec result,
|
|
233
|
-
bool
|
|
229
|
+
bool uP
|
|
234
230
|
) {
|
|
235
231
|
#ifdef HAS_EMISSIVE_LIGHTS
|
|
236
|
-
|
|
232
|
+
pc(shadingPoint,randomSampleValue,result);return;
|
|
237
233
|
#endif
|
|
238
234
|
result.sourceType=0;result.sourceIndex=-1;
|
|
239
235
|
result.isDelta = false;
|
|
240
|
-
float
|
|
241
|
-
bool
|
|
236
|
+
float xJ = randomSampleValue.z;
|
|
237
|
+
bool lG = false;
|
|
242
238
|
#ifdef USE_ENVMAP
|
|
243
|
-
|
|
244
|
-
if (
|
|
245
|
-
|
|
239
|
+
lG = xJ < envLightSelectionPmf;
|
|
240
|
+
if (lG) {
|
|
241
|
+
iM(randomSampleValue.xy, result);
|
|
246
242
|
result.pdf *= envLightSelectionPmf;
|
|
247
243
|
}
|
|
248
244
|
#endif
|
|
249
245
|
|
|
250
246
|
#ifdef NUM_LIGHTS
|
|
251
|
-
if (!
|
|
252
|
-
int
|
|
247
|
+
if (!lG) {
|
|
248
|
+
int jG = NUM_LIGHTS - 1;
|
|
253
249
|
for (int index = 0; index < NUM_LIGHTS; index++) {
|
|
254
|
-
if (
|
|
255
|
-
|
|
250
|
+
if (xJ < fetchLight(index).selectionCdf) {
|
|
251
|
+
jG = index;
|
|
256
252
|
break;
|
|
257
253
|
}
|
|
258
254
|
}
|
|
259
|
-
result.sourceType=2;result.sourceIndex=
|
|
260
|
-
Light
|
|
255
|
+
result.sourceType=2;result.sourceIndex=jG;
|
|
256
|
+
Light sz = fetchLight(jG);
|
|
261
257
|
sampleAnalyticLight(
|
|
262
|
-
|
|
258
|
+
sz,
|
|
263
259
|
shadingPoint,
|
|
264
260
|
randomSampleValue.xy,
|
|
265
261
|
result
|
|
266
262
|
);
|
|
267
|
-
result.pdf *=
|
|
263
|
+
result.pdf *= sz.selectionPmf;
|
|
268
264
|
}
|
|
269
265
|
#endif
|
|
270
266
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sampleLight.glsl.js","sourceRoot":"","sources":["../../../../src/renderer/glsl/chunks/sampleLight.glsl.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEvC,eAAe,IAAI,CAAA
|
|
1
|
+
{"version":3,"file":"sampleLight.glsl.js","sourceRoot":"","sources":["../../../../src/renderer/glsl/chunks/sampleLight.glsl.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEvC,eAAe,IAAI,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2NjB,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6CT,CAAC","sourcesContent":["import emissive from './emissiveLight.glsl.js';\nimport { glsl } from '../../shader.js';\n\nexport default glsl`\n#ifdef NUM_LIGHTS\nvoid light_sample_sphere(\n in Light light,\n in vec3 shadingPoint,\n in vec2 samplePoint,\n inout LightSampleRec result\n) {\n vec3 toCenter = light.position - shadingPoint;\n float centerDistance = length(toCenter);\n if (light.radius <= 0.0) {\n if (centerDistance <= 1e-6) {\n result.direction = vec3(0.0, 0.0, 1.0);\n result.normal = vec3(0.0, 0.0, -1.0);\n result.dist = 0.0;\n result.pdf = 1.0;\n result.emission = vec3(0.0);\n result.isDelta = true;\n return;\n }\n result.direction = toCenter / centerDistance;\n result.normal = -result.direction;\n result.dist = centerDistance;\n result.pdf = 1.0;\n result.emission = light.emission / max(centerDistance * centerDistance, 1e-8);\n result.isDelta = true;\n return;\n }\n float radius = max(light.radius, 1e-6);\n result.isDelta = false;\n vec3 direction;\n\n if (centerDistance <= radius) {\n float z = 1.0 - 2.0 * samplePoint.x;\n float radial = sqrt(max(0.0, 1.0 - z * z));\n float azimuth = TWOPI * samplePoint.y;\n direction = vec3(radial * cos(azimuth), radial * sin(azimuth), z);\n result.pdf = INV4PI;\n }\n else {\n vec3 axis = toCenter / centerDistance;\n float sineLimitSquared = min(\n 1.0,\n radius * radius / (centerDistance * centerDistance)\n );\n float cosineLimit = sqrt(max(0.0, 1.0 - sineLimitSquared));\n // Keep the small solid angle and sampled sine without subtracting\n // nearly equal floats; otherwise small emitters produce irradiance bands.\n float oneMinusCosineLimit = sineLimitSquared / (1.0 + cosineLimit);\n float oneMinusCosine = samplePoint.x * oneMinusCosineLimit;\n float cosine = 1.0 - oneMinusCosine;\n float sine = sqrt(max(0.0, oneMinusCosine * (2.0 - oneMinusCosine)));\n float azimuth = TWOPI * samplePoint.y;\n vec3 tangent;\n vec3 bitangent;\n sampling_orthonormal_basis(axis, tangent, bitangent);\n direction = axis * cosine\n + tangent * (sine * cos(azimuth))\n + bitangent * (sine * sin(azimuth));\n result.pdf = 1.0 / max(TWOPI * oneMinusCosineLimit, 1e-8);\n }\n\n float projectedCenter = dot(direction, toCenter);\n float discriminant = projectedCenter * projectedCenter\n - dot(toCenter, toCenter) + radius * radius;\n float root = sqrt(max(0.0, discriminant));\n float nearDistance = projectedCenter - root;\n float farDistance = projectedCenter + root;\n result.dist = nearDistance > 1e-6 ? nearDistance : farDistance;\n result.direction = direction;\n vec3 surfacePoint = shadingPoint + direction * result.dist;\n result.normal = normalize(surfacePoint - light.position);\n result.emission = light.emission;\n}\n\nvoid light_apply_rect_texture(\n in Light light,\n in vec3 surfacePoint,\n in vec3 lowerLeft,\n inout LightSampleRec result\n) {\n#ifdef NUM_MAPS\n if (light.textureIndex >= 0) {\n float width = length(light.u);\n float height = length(light.v);\n vec3 relative = surfacePoint - lowerLeft;\n vec2 uv = vec2(\n dot(relative, light.u / width) / width,\n dot(relative, light.v / height) / height\n );\n result.emission *= sampleMap(light.textureIndex, uv).rgb;\n }\n#endif\n}\n\nvoid light_sample_rect(\n in Light light,\n in vec3 shadingPoint,\n in vec2 samplePoint,\n inout LightSampleRec result\n) {\n vec3 normal = normalize(cross(light.u, light.v));\n vec3 lowerLeft = light.position - 0.5 * (light.u + light.v);\n float spread = clamp(light.spread, 0.0, 1.0);\n\n if (spread <= 0.001) {\n float planeDistance = dot(normal, shadingPoint - light.position);\n vec3 surfacePoint = shadingPoint - normal * planeDistance;\n vec3 relative = surfacePoint - lowerLeft;\n float width = length(light.u);\n float height = length(light.v);\n vec2 uv = vec2(\n dot(relative, light.u / width) / width,\n dot(relative, light.v / height) / height\n );\n if (planeDistance <= 0.0 || any(lessThan(uv, vec2(0.0)))\n || any(greaterThan(uv, vec2(1.0)))) {\n result.emission = vec3(0.0);\n result.pdf = 0.0;\n return;\n }\n result.direction = -normal;\n result.dist = planeDistance;\n result.normal = normal;\n result.emission = light.emission;\n result.pdf = 1.0;\n result.isDelta = true;\n light_apply_rect_texture(light, surfacePoint, lowerLeft, result);\n return;\n }\n\n vec3 surfacePoint = lowerLeft\n + light.u * samplePoint.x\n + light.v * samplePoint.y;\n vec3 offset = surfacePoint - shadingPoint;\n float distanceSquared = dot(offset, offset);\n result.dist = sqrt(distanceSquared);\n result.direction = offset / result.dist;\n result.normal = normal;\n float emitterCosine = dot(-result.direction, normal);\n float spreadCosine = cos(0.5 * PI * spread);\n if (emitterCosine <= 0.0 || emitterCosine < spreadCosine) {\n result.emission = vec3(0.0);\n result.pdf = 0.0;\n return;\n }\n result.emission = light.emission;\n result.pdf = distanceSquared / max(light.area * emitterCosine, 1e-8);\n light_apply_rect_texture(light, surfacePoint, lowerLeft, result);\n}\n\nvoid light_sample_directional(\n in Light light,\n in vec3 shadingPoint,\n inout LightSampleRec result\n) {\n result.direction = normalize(-light.u);\n result.normal = -result.direction;\n result.emission = light.emission;\n result.dist = INF;\n result.pdf = 1.0;\n result.isDelta = true;\n}\n\nvoid light_sample_spot(\n in Light light,\n in vec3 shadingPoint,\n in vec2 samplePoint,\n inout LightSampleRec result\n) {\n light_sample_sphere(light, shadingPoint, samplePoint, result);\n vec3 surfacePoint = shadingPoint + result.direction * result.dist;\n result.emission *= evaluateSpotEmissionMultiplier(\n light,\n normalize(shadingPoint - surfacePoint)\n );\n}\n\nvoid sampleAnalyticLight(\n in Light light,\n in vec3 shadingPoint,\n in vec2 samplePoint,\n inout LightSampleRec result\n) {\n int lightType = int(light.type);\n#ifdef HAS_RECT_LIGHTS\n if (lightType == RECT_LIGHT) {\n light_sample_rect(light, shadingPoint, samplePoint, result);\n return;\n }\n#endif\n#ifdef HAS_SPHERE_LIGHTS\n if (lightType == SPHERE_LIGHT) {\n light_sample_sphere(light, shadingPoint, samplePoint, result);\n return;\n }\n#endif\n#ifdef HAS_SPOT_LIGHTS\n if (lightType == SPOT_LIGHT) {\n light_sample_spot(light, shadingPoint, samplePoint, result);\n return;\n }\n#endif\n#ifdef HAS_DIRECTIONAL_LIGHTS\n if (lightType == DIRECTIONAL_LIGHT) {\n light_sample_directional(light, shadingPoint, result);\n }\n#endif\n}\n#endif\n\nvoid sampleEnvLight(in vec2 samplePoint, inout LightSampleRec result) {\n vec2 uv;\n result.direction = sampleEnvmap(samplePoint, uv, result.pdf);\n result.emission = textureLinear(envMap, uv).rgb;\n result.dist = INF;\n}\n\n#ifdef HAS_EMISSIVE_LIGHTS\n${emissive}\n#endif\n\nvoid sampleLight(\n in vec3 shadingPoint,\n in vec3 randomSampleValue,\n inout LightSampleRec result,\n bool distByIntensity\n) {\n#ifdef HAS_EMISSIVE_LIGHTS\n sampleEmissiveSceneLight(shadingPoint,randomSampleValue,result);return;\n#endif\n result.sourceType=0;result.sourceIndex=-1;\n result.isDelta = false;\n float selector = randomSampleValue.z;\n bool choseEnvironment = false;\n#ifdef USE_ENVMAP\n choseEnvironment = selector < envLightSelectionPmf;\n if (choseEnvironment) {\n sampleEnvLight(randomSampleValue.xy, result);\n result.pdf *= envLightSelectionPmf;\n }\n#endif\n\n#ifdef NUM_LIGHTS\n if (!choseEnvironment) {\n int selectedIndex = NUM_LIGHTS - 1;\n for (int index = 0; index < NUM_LIGHTS; index++) {\n if (selector < fetchLight(index).selectionCdf) {\n selectedIndex = index;\n break;\n }\n }\n result.sourceType=2;result.sourceIndex=selectedIndex;\n Light selectedLight = fetchLight(selectedIndex);\n sampleAnalyticLight(\n selectedLight,\n shadingPoint,\n randomSampleValue.xy,\n result\n );\n result.pdf *= selectedLight.selectionPmf;\n }\n#endif\n}\n`;\n"]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare function createSampleMaterialGlsl(fragments?: Readonly<Record<string, string
|
|
1
|
+
export declare function createSampleMaterialGlsl(fragments?: Readonly<Record<string, string>>, channelIndependentLight?: boolean): string;
|
|
2
2
|
declare const _default: string;
|
|
3
3
|
export default _default;
|