@meimu/mutracer 0.2.0 → 0.3.0
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/README.md +3 -0
- package/dist/assets/bvh.worker.js +1 -1
- package/dist/mutracer.umd.js +8949 -7915
- package/docs/api.md +42 -21
- package/docs/caustics.md +80 -0
- package/docs/materials.md +5 -4
- package/docs/progressive-rendering.md +50 -9
- package/docs/technical/continuous-spectrum.md +93 -0
- package/docs/updates.md +3 -1
- package/docs/viewer-checklist.md +65 -0
- package/docs/viewer.md +7 -5
- package/lib/Display.js +1 -1
- package/lib/Display.js.map +1 -1
- package/lib/Engine.d.ts +2 -0
- package/lib/Engine.js +47 -12
- package/lib/Engine.js.map +1 -1
- package/lib/Render.d.ts +61 -13
- package/lib/Render.js +169 -19
- package/lib/Render.js.map +1 -1
- package/lib/RenderLoop.d.ts +7 -3
- package/lib/RenderLoop.js +68 -44
- package/lib/RenderLoop.js.map +1 -1
- package/lib/main.d.ts +1 -1
- package/lib/main.js.map +1 -1
- package/lib/oidn.d.ts +1 -1
- package/lib/oidnBundledWeights.cdn.d.ts +2 -2
- package/lib/renderer/GPUTraceQueue.d.ts +2 -1
- package/lib/renderer/GPUTraceQueue.js +3 -1
- package/lib/renderer/GPUTraceQueue.js.map +1 -1
- package/lib/renderer/RenderingPipeline.d.ts +4 -0
- package/lib/renderer/RenderingPipeline.js.map +1 -1
- package/lib/renderer/WGPUCausticLightPass.d.ts +48 -0
- package/lib/renderer/WGPUCausticLightPass.js +217 -0
- package/lib/renderer/WGPUCausticLightPass.js.map +1 -0
- package/lib/renderer/WGPUEnvMapDistribution.js +18 -18
- package/lib/renderer/WGPUFullQuadPass.js +3 -3
- package/lib/renderer/WGPUPhotonMap.d.ts +37 -0
- package/lib/renderer/WGPUPhotonMap.js +191 -0
- package/lib/renderer/WGPUPhotonMap.js.map +1 -0
- package/lib/renderer/WGPURayTraceOutput.d.ts +13 -1
- package/lib/renderer/WGPURayTraceOutput.js +122 -28
- package/lib/renderer/WGPURayTraceOutput.js.map +1 -1
- package/lib/renderer/WGPURayTracePass.d.ts +48 -17
- package/lib/renderer/WGPURayTracePass.js +538 -340
- package/lib/renderer/WGPURayTracePass.js.map +1 -1
- package/lib/renderer/WGPURenderingPipeline.js +83 -47
- package/lib/renderer/WGPURenderingPipeline.js.map +1 -1
- package/lib/renderer/WebGLFullQuadPass.d.ts +2 -1
- package/lib/renderer/WebGLFullQuadPass.js +4 -0
- package/lib/renderer/WebGLFullQuadPass.js.map +1 -1
- package/lib/renderer/WebGLJNLMDenoiser.js +66 -66
- package/lib/renderer/WebGLRayTraceOutputPass.js +4 -4
- package/lib/renderer/WebGLRayTracePass.d.ts +6 -1
- package/lib/renderer/WebGLRayTracePass.js +43 -6
- package/lib/renderer/WebGLRayTracePass.js.map +1 -1
- package/lib/renderer/WebGLRenderingPipeline.js +10 -14
- package/lib/renderer/WebGLRenderingPipeline.js.map +1 -1
- package/lib/renderer/WebGLSkyBaker.js +60 -60
- package/lib/renderer/accumulationTarget.d.ts +2 -1
- package/lib/renderer/accumulationTarget.js.map +1 -1
- package/lib/renderer/causticDiagnostics.d.ts +31 -0
- package/lib/renderer/causticDiagnostics.js +5 -0
- package/lib/renderer/causticDiagnostics.js.map +1 -0
- package/lib/renderer/causticEmission.d.ts +10 -0
- package/lib/renderer/causticEmission.js +40 -0
- package/lib/renderer/causticEmission.js.map +1 -0
- package/lib/renderer/causticUniform.d.ts +12 -0
- package/lib/renderer/causticUniform.js +22 -0
- package/lib/renderer/causticUniform.js.map +1 -0
- package/lib/renderer/caustics.d.ts +16 -0
- package/lib/renderer/caustics.js +93 -0
- package/lib/renderer/caustics.js.map +1 -0
- package/lib/renderer/glsl/aovDisplay.frag.js +5 -5
- package/lib/renderer/glsl/aovReflectance.glsl.js +53 -53
- package/lib/renderer/glsl/aovReflectanceSamples.glsl.js +1 -1
- package/lib/renderer/glsl/aovTrace.frag.js +33 -33
- package/lib/renderer/glsl/chunks/cameraRay.glsl.js +9 -9
- package/lib/renderer/glsl/chunks/emissiveLight.glsl.d.ts +2 -0
- package/lib/renderer/glsl/chunks/emissiveLight.glsl.js +35 -0
- package/lib/renderer/glsl/chunks/emissiveLight.glsl.js.map +1 -0
- package/lib/renderer/glsl/chunks/envMap.glsl.js +73 -73
- package/lib/renderer/glsl/chunks/intersect.glsl.js +426 -428
- package/lib/renderer/glsl/chunks/intersect.glsl.js.map +1 -1
- package/lib/renderer/glsl/chunks/materialBuffer.glsl.d.ts +1 -0
- package/lib/renderer/glsl/chunks/materialBuffer.glsl.js +156 -153
- package/lib/renderer/glsl/chunks/materialBuffer.glsl.js.map +1 -1
- package/lib/renderer/glsl/chunks/openPbrBsdf.glsl.js +771 -771
- package/lib/renderer/glsl/chunks/rand.glsl.js +3 -3
- package/lib/renderer/glsl/chunks/random.glsl.js +6 -6
- package/lib/renderer/glsl/chunks/rayTraceCore.glsl.d.ts +1 -0
- package/lib/renderer/glsl/chunks/rayTraceCore.glsl.js +68 -63
- package/lib/renderer/glsl/chunks/rayTraceCore.glsl.js.map +1 -1
- package/lib/renderer/glsl/chunks/sampleLight.glsl.js +94 -76
- package/lib/renderer/glsl/chunks/sampleLight.glsl.js.map +1 -1
- package/lib/renderer/glsl/chunks/sampleMaterial.glsl.d.ts +1 -0
- package/lib/renderer/glsl/chunks/sampleMaterial.glsl.js +140 -117
- package/lib/renderer/glsl/chunks/sampleMaterial.glsl.js.map +1 -1
- package/lib/renderer/glsl/chunks/sampleShadowCatcher.glsl.js +14 -14
- package/lib/renderer/glsl/chunks/sampling.glsl.js +89 -92
- package/lib/renderer/glsl/chunks/sampling.glsl.js.map +1 -1
- package/lib/renderer/glsl/chunks/sobol.glsl.js +79 -79
- 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 +2 -2
- package/lib/renderer/glsl/normalizeRayTraceOutput.frag.js +10 -10
- package/lib/renderer/glsl/rayTrace.frag.d.ts +1 -1
- package/lib/renderer/glsl/rayTrace.frag.js +260 -237
- package/lib/renderer/glsl/rayTrace.frag.js.map +1 -1
- package/lib/renderer/glsl/shadowCatcher.frag.js +26 -26
- package/lib/renderer/glsl/shadowCatcher.frag.js.map +1 -1
- package/lib/renderer/glsl/webglPipeline.frag.js +59 -59
- package/lib/renderer/lightSampling.d.ts +3 -2
- package/lib/renderer/lightSampling.js +14 -8
- package/lib/renderer/lightSampling.js.map +1 -1
- package/lib/renderer/progressiveScheduler.js +4 -3
- package/lib/renderer/progressiveScheduler.js.map +1 -1
- package/lib/renderer/renderPipeline.d.ts +1 -0
- package/lib/renderer/renderPipeline.js.map +1 -1
- package/lib/renderer/researchTransport.d.ts +31 -0
- package/lib/renderer/researchTransport.js +5 -0
- package/lib/renderer/researchTransport.js.map +1 -0
- 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/scratchSampling.js +6 -6
- package/lib/renderer/spectrum.d.ts +21 -0
- package/lib/renderer/spectrum.js +154 -0
- package/lib/renderer/spectrum.js.map +1 -0
- package/lib/renderer/webglLightSampling.d.ts +39 -0
- package/lib/renderer/webglLightSampling.js +15 -0
- package/lib/renderer/webglLightSampling.js.map +1 -0
- package/lib/renderer/wgpuBindlessSource.js +3 -3
- package/lib/renderer/wgpuShaderSource.d.ts +7 -0
- package/lib/renderer/wgpuShaderSource.js +2 -0
- package/lib/renderer/wgpuShaderSource.js.map +1 -1
- package/lib/renderer/wgsl/aovDisplay.wgsl.js +9 -9
- package/lib/renderer/wgsl/aovReflectance.wgsl.js +55 -55
- package/lib/renderer/wgsl/aovReflectanceSamples.wgsl.js +1 -1
- package/lib/renderer/wgsl/aovResolve.wgsl.js +2 -2
- package/lib/renderer/wgsl/aovSnapshot.wgsl.js +1 -1
- package/lib/renderer/wgsl/aovTrace.wgsl.js +33 -33
- package/lib/renderer/wgsl/bloom.wgsl.js +18 -18
- package/lib/renderer/wgsl/causticLight.compute.d.ts +6 -0
- package/lib/renderer/wgsl/causticLight.compute.js +537 -0
- package/lib/renderer/wgsl/causticLight.compute.js.map +1 -0
- package/lib/renderer/wgsl/chunks/background.wgsl.d.ts +2 -0
- package/lib/renderer/wgsl/chunks/background.wgsl.js +102 -0
- package/lib/renderer/wgsl/chunks/background.wgsl.js.map +1 -0
- package/lib/renderer/wgsl/chunks/causticAdjoint.wgsl.d.ts +2 -0
- package/lib/renderer/wgsl/chunks/causticAdjoint.wgsl.js +12 -0
- package/lib/renderer/wgsl/chunks/causticAdjoint.wgsl.js.map +1 -0
- package/lib/renderer/wgsl/chunks/causticAtomic.wgsl.d.ts +2 -0
- package/lib/renderer/wgsl/chunks/causticAtomic.wgsl.js +16 -0
- package/lib/renderer/wgsl/chunks/causticAtomic.wgsl.js.map +1 -0
- package/lib/renderer/wgsl/chunks/caustics.wgsl.d.ts +1 -0
- package/lib/renderer/wgsl/chunks/caustics.wgsl.js +62 -0
- package/lib/renderer/wgsl/chunks/caustics.wgsl.js.map +1 -0
- package/lib/renderer/wgsl/chunks/common.wgsl.js +4 -4
- package/lib/renderer/wgsl/chunks/envMap.wgsl.js +37 -37
- package/lib/renderer/wgsl/chunks/intersect.wgsl.js +598 -592
- package/lib/renderer/wgsl/chunks/intersect.wgsl.js.map +1 -1
- package/lib/renderer/wgsl/chunks/intersectionAlpha.wgsl.js +14 -14
- package/lib/renderer/wgsl/chunks/materialBuffer.wgsl.d.ts +2 -1
- package/lib/renderer/wgsl/chunks/materialBuffer.wgsl.js +75 -73
- package/lib/renderer/wgsl/chunks/materialBuffer.wgsl.js.map +1 -1
- package/lib/renderer/wgsl/chunks/openPbrBsdf.wgsl.js +794 -794
- package/lib/renderer/wgsl/chunks/pdm_displacement.wgsl.js +139 -139
- package/lib/renderer/wgsl/chunks/rand.wgsl.js +3 -3
- package/lib/renderer/wgsl/chunks/rayTraceCore.wgsl.d.ts +2 -1
- package/lib/renderer/wgsl/chunks/rayTraceCore.wgsl.js +35 -25
- package/lib/renderer/wgsl/chunks/rayTraceCore.wgsl.js.map +1 -1
- package/lib/renderer/wgsl/chunks/sampleLight.wgsl.d.ts +1 -1
- package/lib/renderer/wgsl/chunks/sampleLight.wgsl.js +142 -138
- package/lib/renderer/wgsl/chunks/sampleLight.wgsl.js.map +1 -1
- package/lib/renderer/wgsl/chunks/sampleMaterial.wgsl.d.ts +1 -1
- package/lib/renderer/wgsl/chunks/sampleMaterial.wgsl.js +204 -187
- package/lib/renderer/wgsl/chunks/sampleMaterial.wgsl.js.map +1 -1
- package/lib/renderer/wgsl/chunks/sampleShadowCatcher.wgsl.d.ts +1 -1
- package/lib/renderer/wgsl/chunks/sampleShadowCatcher.wgsl.js +11 -11
- package/lib/renderer/wgsl/chunks/sampleShadowCatcher.wgsl.js.map +1 -1
- package/lib/renderer/wgsl/chunks/sampling.wgsl.d.ts +1 -1
- package/lib/renderer/wgsl/chunks/sampling.wgsl.js +89 -93
- package/lib/renderer/wgsl/chunks/sampling.wgsl.js.map +1 -1
- package/lib/renderer/wgsl/chunks/sobol.wgsl.js +83 -83
- package/lib/renderer/wgsl/chunks/uvProjection.wgsl.js +11 -11
- package/lib/renderer/wgsl/compose.frag.wgsl.js +98 -98
- package/lib/renderer/wgsl/customDenoise.wgsl.js +10 -10
- package/lib/renderer/wgsl/depthQuery.wgsl.js +2 -2
- package/lib/renderer/wgsl/jnlm.compute.js +74 -74
- package/lib/renderer/wgsl/offlineAdaptive.compute.js +25 -25
- package/lib/renderer/wgsl/oidnAuxiliary.wgsl.js +3 -3
- package/lib/renderer/wgsl/photonMap.compute.d.ts +29 -0
- package/lib/renderer/wgsl/photonMap.compute.js +352 -0
- package/lib/renderer/wgsl/photonMap.compute.js.map +1 -0
- package/lib/renderer/wgsl/proceduralSky.compute.js +64 -64
- package/lib/renderer/wgsl/rayTrace.compute.d.ts +9 -1
- package/lib/renderer/wgsl/rayTrace.compute.js +448 -522
- package/lib/renderer/wgsl/rayTrace.compute.js.map +1 -1
- package/lib/scene/MaterialState.d.ts +2 -2
- package/lib/scene/MaterialState.js +2 -2
- package/lib/scene/MaterialState.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 +2 -2
- 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/llms.txt +2 -1
- package/package.json +3 -3
|
@@ -5,13 +5,13 @@ import { glsl } from '../../shader.js';
|
|
|
5
5
|
export default glsl `
|
|
6
6
|
uvec4 s0;
|
|
7
7
|
|
|
8
|
-
void
|
|
8
|
+
void fi(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 xF(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
|
+
xF(s0); return float(s0.x)/float(0xffffffffu);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
`;
|
|
@@ -10,15 +10,15 @@ export default createShaderMixin({
|
|
|
10
10
|
|
|
11
11
|
${sobol}
|
|
12
12
|
|
|
13
|
-
void
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
void rA() {
|
|
14
|
+
aI = uvec2(v_Texcoord / pixelSize);
|
|
15
|
+
aC = uint(sampleCount);
|
|
16
|
+
samplingBounce = 0u; ca = 0u;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
vec2
|
|
19
|
+
vec2 te() {
|
|
20
20
|
if (samplingPattern == 0 || samplingPattern == 1) {
|
|
21
|
-
return (
|
|
21
|
+
return (sample2D(CAMERA_PIXEL) - 0.5) * pixelSize;
|
|
22
22
|
}
|
|
23
23
|
return jitter;
|
|
24
24
|
}
|
|
@@ -4,26 +4,27 @@
|
|
|
4
4
|
import { createShaderMixin, glsl, Shader } from '../../shader.js';
|
|
5
5
|
import { ShadowCatcherMaterial, UnlitMaterial } from '../../../constants.js';
|
|
6
6
|
import { CONSTANT_SPOT_LIGHT } from '../../lightConstants.js';
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
7
|
+
export function createRayTraceCoreGlsl(fragments = {}) {
|
|
8
|
+
return createShaderMixin({
|
|
9
|
+
uniforms: {
|
|
10
|
+
lightsTex: Shader.uniform('sampler2D'),
|
|
11
|
+
iesProfileData: Shader.uniform('sampler2D'),
|
|
12
|
+
iesProfileColumns: Shader.uniform('int', 1),
|
|
13
|
+
pixelSize: Shader.uniform('vec2'),
|
|
14
|
+
jitter: Shader.uniform('vec2'),
|
|
15
|
+
sampleCount: Shader.uniform('int'),
|
|
16
|
+
envLightSelectionPmf: Shader.uniform('float', 0)
|
|
17
|
+
},
|
|
18
|
+
defines: {
|
|
19
|
+
STANDARD: 0,
|
|
20
|
+
UNLIT: UnlitMaterial,
|
|
21
|
+
SHADOW_CATCHER: ShadowCatcherMaterial,
|
|
22
|
+
SPOT_LIGHT: CONSTANT_SPOT_LIGHT
|
|
23
|
+
},
|
|
24
|
+
main: glsl `
|
|
24
25
|
|
|
25
26
|
const vec3 luminance = vec3(0.2126, 0.7152, 0.0722);
|
|
26
|
-
const int
|
|
27
|
+
const int xO = 8;
|
|
27
28
|
|
|
28
29
|
#define RAY_MAX_DISTANCE 9999.0
|
|
29
30
|
|
|
@@ -81,7 +82,7 @@ float mediumAnisotropy;
|
|
|
81
82
|
struct OpenPbrResolvedMaterial {
|
|
82
83
|
int materialType;
|
|
83
84
|
|
|
84
|
-
float specularRoughness
|
|
85
|
+
float specularRoughness;${fragments['core0'] ?? ''}
|
|
85
86
|
float baseMetalness;
|
|
86
87
|
vec3 baseColor;
|
|
87
88
|
float specularIor;
|
|
@@ -157,26 +158,26 @@ float selectionCdf;
|
|
|
157
158
|
vec3 iesReference;
|
|
158
159
|
};
|
|
159
160
|
|
|
160
|
-
void
|
|
161
|
+
void initRay(inout Ray ray, vec3 origin, vec3 direction) {
|
|
161
162
|
ray.o = origin;
|
|
162
163
|
ray.d = direction;
|
|
163
164
|
ray.tMax = RAY_MAX_DISTANCE;
|
|
164
165
|
}
|
|
165
166
|
|
|
166
167
|
|
|
167
|
-
ivec2
|
|
168
|
+
ivec2 gM(int i, int jE) {
|
|
168
169
|
ivec2 u;
|
|
169
|
-
u.y = i >>
|
|
170
|
-
u.x = i - (u.y <<
|
|
170
|
+
u.y = i >> jE;
|
|
171
|
+
u.x = i - (u.y << jE);
|
|
171
172
|
return u;
|
|
172
173
|
}
|
|
173
174
|
|
|
174
|
-
vec4
|
|
175
|
-
return texelFetch(s,
|
|
175
|
+
vec4 fetchData(sampler2D s, int i, int jE) {
|
|
176
|
+
return texelFetch(s, gM(i, jE), 0);
|
|
176
177
|
}
|
|
177
178
|
|
|
178
|
-
ivec4
|
|
179
|
-
return texelFetch(s,
|
|
179
|
+
ivec4 fetchData(highp isampler2D s, int i, int jE) {
|
|
180
|
+
return texelFetch(s, gM(i, jE), 0);
|
|
180
181
|
}
|
|
181
182
|
|
|
182
183
|
struct Path {
|
|
@@ -188,7 +189,7 @@ bool fromEye;
|
|
|
188
189
|
bool abort;
|
|
189
190
|
float scatteringPdf;
|
|
190
191
|
bool scatteringIsDelta;
|
|
191
|
-
bool isNextRefraction
|
|
192
|
+
bool isNextRefraction;${fragments['core1'] ?? ''}
|
|
192
193
|
};
|
|
193
194
|
|
|
194
195
|
struct LightSampleRec {
|
|
@@ -198,27 +199,29 @@ vec3 direction;
|
|
|
198
199
|
float dist;
|
|
199
200
|
float pdf;
|
|
200
201
|
bool isDelta;
|
|
202
|
+
int sourceType;
|
|
203
|
+
int sourceIndex;
|
|
201
204
|
};
|
|
202
205
|
|
|
203
206
|
|
|
204
|
-
Light
|
|
207
|
+
Light fetchLight(int i) {
|
|
205
208
|
int firstTexel = i * 6;
|
|
206
|
-
vec4
|
|
209
|
+
vec4 positionAndPmf = texelFetch(
|
|
207
210
|
lightsTex,
|
|
208
211
|
ivec2(firstTexel, 0),
|
|
209
212
|
0
|
|
210
213
|
);
|
|
211
|
-
vec4
|
|
214
|
+
vec4 emissionAndCdf = texelFetch(
|
|
212
215
|
lightsTex,
|
|
213
216
|
ivec2(firstTexel + 1, 0),
|
|
214
217
|
0
|
|
215
218
|
);
|
|
216
|
-
vec4
|
|
219
|
+
vec4 oB = texelFetch(
|
|
217
220
|
lightsTex,
|
|
218
221
|
ivec2(firstTexel + 2, 0),
|
|
219
222
|
0
|
|
220
223
|
);
|
|
221
|
-
vec4
|
|
224
|
+
vec4 me = texelFetch(
|
|
222
225
|
lightsTex,
|
|
223
226
|
ivec2(firstTexel + 3, 0),
|
|
224
227
|
0
|
|
@@ -229,33 +232,33 @@ ivec2(firstTexel + 4, 0),
|
|
|
229
232
|
0
|
|
230
233
|
);
|
|
231
234
|
return Light(
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
235
|
+
positionAndPmf.xyz,
|
|
236
|
+
emissionAndCdf.xyz,
|
|
237
|
+
oB.xyz,
|
|
238
|
+
me.xyz,
|
|
236
239
|
shape.x,
|
|
237
240
|
shape.y,
|
|
238
241
|
shape.z,
|
|
239
|
-
int(
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
242
|
+
int(me.w),
|
|
243
|
+
oB.w,
|
|
244
|
+
positionAndPmf.w,
|
|
245
|
+
emissionAndCdf.w,
|
|
243
246
|
texelFetch(lightsTex, ivec2(firstTexel + 5, 0), 0).xyz
|
|
244
247
|
);
|
|
245
248
|
}
|
|
246
249
|
|
|
247
|
-
float
|
|
248
|
-
int
|
|
250
|
+
float cF(int dV, int lK) {
|
|
251
|
+
int im = dV + lK / 4;
|
|
249
252
|
vec4 packed = texelFetch(
|
|
250
253
|
iesProfileData,
|
|
251
|
-
ivec2(
|
|
254
|
+
ivec2(im % iesProfileColumns, im / iesProfileColumns),
|
|
252
255
|
0
|
|
253
256
|
);
|
|
254
|
-
return packed[
|
|
257
|
+
return packed[lK % 4];
|
|
255
258
|
}
|
|
256
259
|
|
|
257
|
-
float
|
|
258
|
-
if (
|
|
260
|
+
float ld(int dV, vec2 uv) {
|
|
261
|
+
if (dV < 0) return 1.0;
|
|
259
262
|
vec2 pixel = fract(uv) * 128.0 - 0.5;
|
|
260
263
|
ivec2 p0 = ivec2(floor(pixel));
|
|
261
264
|
vec2 f = fract(pixel);
|
|
@@ -263,26 +266,28 @@ int xa = p0.x < 0 ? 127 : p0.x;
|
|
|
263
266
|
int xb = p0.x >= 127 ? 0 : p0.x + 1;
|
|
264
267
|
int ya = p0.y < 0 ? 127 : p0.y;
|
|
265
268
|
int yb = p0.y >= 127 ? 0 : p0.y + 1;
|
|
266
|
-
float a =
|
|
267
|
-
float b =
|
|
268
|
-
float c =
|
|
269
|
-
float d =
|
|
269
|
+
float a = cF(dV, ya * 128 + xa);
|
|
270
|
+
float b = cF(dV, ya * 128 + xb);
|
|
271
|
+
float c = cF(dV, yb * 128 + xa);
|
|
272
|
+
float d = cF(dV, yb * 128 + xb);
|
|
270
273
|
return mix(mix(a, b, f.x), mix(c, d, f.x), f.y);
|
|
271
274
|
}
|
|
272
275
|
|
|
273
|
-
float
|
|
276
|
+
float evaluateSpotEmissionMultiplier(Light light, vec3 dI) {
|
|
274
277
|
vec3 axis = normalize(light.u);
|
|
275
|
-
float
|
|
276
|
-
float
|
|
277
|
-
? smoothstep(light.v.x, light.v.y,
|
|
278
|
-
: step(light.v.x,
|
|
279
|
-
if (
|
|
280
|
-
vec3
|
|
281
|
-
vec3
|
|
282
|
-
float vertical = acos(clamp(
|
|
283
|
-
float horizontal = atan(dot(
|
|
284
|
-
return
|
|
278
|
+
float ct = dot(axis, dI);
|
|
279
|
+
float vw = light.v.y > light.v.x + 1e-6
|
|
280
|
+
? smoothstep(light.v.x, light.v.y, ct)
|
|
281
|
+
: step(light.v.x, ct);
|
|
282
|
+
if (vw <= 0.0 || light.textureIndex < 0) return vw;
|
|
283
|
+
vec3 vX = light.iesReference;
|
|
284
|
+
vec3 xN = cross(axis, vX);
|
|
285
|
+
float vertical = acos(clamp(ct, -1.0, 1.0));
|
|
286
|
+
float horizontal = atan(dot(dI, xN), dot(dI, vX));
|
|
287
|
+
return vw * ld(light.textureIndex, vec2(vertical / PI, horizontal / TWOPI + 0.5));
|
|
285
288
|
}
|
|
286
289
|
`
|
|
287
|
-
});
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
export default createRayTraceCoreGlsl();
|
|
288
293
|
//# sourceMappingURL=rayTraceCore.glsl.js.map
|
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"rayTraceCore.glsl.js","sourceRoot":"","sources":["../../../../src/renderer/glsl/chunks/rayTraceCore.glsl.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,sDAAsD;AACtD,kFAAkF;AAElF,OAAO,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC7E,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAE9D,MAAM,UAAU,sBAAsB,CAAC,YAA8C,EAAE;IAAI,OAAO,iBAAiB,CAAC;QAClH,QAAQ,EAAE;YACR,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC;YACtC,cAAc,EAAE,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC;YAC3C,iBAAiB,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;YAC3C,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;YACjC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;YAC9B,WAAW,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;YAClC,oBAAoB,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;SACjD;QACD,OAAO,EAAE;YACP,QAAQ,EAAE,CAAC;YACX,KAAK,EAAE,aAAa;YACpB,cAAc,EAAE,qBAAqB;YACrC,UAAU,EAAE,mBAAmB;SAChC;QACD,IAAI,EAAE,IAAI,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BA6DgB,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA2G1B,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiGjD;KACA,CAAC,CAAC;AACH,CAAC;AACD,eAAe,sBAAsB,EAAE,CAAC","sourcesContent":["// Portions adapted from ray-tracing-renderer@0.10.15\n// (https://github.com/hoverinc/ray-tracing-renderer).\n// Copyright (c) 2019 HOVER, MIT license; see LICENSES/RayTracingRenderer-MIT.txt.\n\nimport { createShaderMixin, glsl, Shader } from '../../shader.js';\nimport { ShadowCatcherMaterial, UnlitMaterial } from '../../../constants.js';\nimport { CONSTANT_SPOT_LIGHT } from '../../lightConstants.js';\n\nexport function createRayTraceCoreGlsl(fragments: Readonly<Record<string, string>> = {}) { return createShaderMixin({\n uniforms: {\n lightsTex: Shader.uniform('sampler2D'),\n iesProfileData: Shader.uniform('sampler2D'),\n iesProfileColumns: Shader.uniform('int', 1),\n pixelSize: Shader.uniform('vec2'),\n jitter: Shader.uniform('vec2'),\n sampleCount: Shader.uniform('int'),\n envLightSelectionPmf: Shader.uniform('float', 0)\n },\n defines: {\n STANDARD: 0,\n UNLIT: UnlitMaterial,\n SHADOW_CATCHER: ShadowCatcherMaterial,\n SPOT_LIGHT: CONSTANT_SPOT_LIGHT\n },\n main: glsl`\n// https://www.w3.org/WAI/GL/wiki/Relative_luminance\nconst vec3 luminance = vec3(0.2126, 0.7152, 0.0722);\nconst int bounceSamples = 8;\n\n#define RAY_MAX_DISTANCE 9999.0\n\n#define NO_UNROLL(X) (X + min(0, sampleCount))\n#define NO_UNROLLU(X) (X + uint(min(0, sampleCount)))\n\nstruct Ray {\n vec3 o;\n vec3 d;\n float tMax;\n};\n\nstruct SurfaceInteraction {\n bool hit;\n vec3 position;\n vec3 normal; // material shading normal\n#ifdef USE_COAT_NORMAL_FRAMES\n vec3 coatNormal;\n#endif\n vec3 vertexNormal; // interpolated mesh normal before normal mapping\n vec3 shadowOffset; // smooth-surface offset used by direct-light shadow rays\n \n vec2 uv;\n vec2 uv1;\n vec3 vertexColor;\n\n#ifdef USE_TANGENT\n vec3 tangent;\n#endif\n vec3 directionTangent;\n vec3 directionBitangent;\n vec3 geometryTangent;\n vec3 geometryBitangent;\n vec3 faceNormal; // normal of the triangle\n\n bool isTransparency;\n // For perfect specular or transmission surface\n // We use the albedo and normal of first diffuse or glossy surface hit instead for denoising\n // See albedo section in https://www.openimagedenoise.org/documentation.html\n bool albedoSampled;\n\n int triangleIndex;\n int instanceIndex;\n int materialIndex;\n\n int mediumType;\n vec3 mediumExtinction;\n vec3 mediumScattering;\n float mediumAnisotropy;\n};\n\n// Texture-resolved OpenPBR inputs used by the surface integrator. The storage\n// buffer keeps its compact legacy layout; getMaterial() is the compatibility\n// boundary that maps it to these canonical names.\nstruct OpenPbrResolvedMaterial {\n int materialType;\n\n float specularRoughness;${fragments['core0'] ?? ''}\n float baseMetalness;\n vec3 baseColor;\n float specularIor;\n vec3 emission;\n float transmissionWeight;\n bool thinWalled;\n float specularAnisotropy;\n float alpha;\n\n float transmissionDispersionScale;\n float dispersionAbbeNumber;\n float thinFilmThickness;\n float thinFilmIor;\n float thinFilmWeight;\n\n // Medium\n int mediumType;\n vec3 mediumExtinction;\n vec3 mediumScattering;\n float mediumAnisotropy;\n\n float baseWeight;\n float diffuseRoughness;\n float specularWeight;\n vec3 specularColor;\n float subsurfaceWeight;\n vec3 subsurfaceColor;\n vec3 transmissionColor;\n float fuzzWeight;\n vec3 fuzzColor;\n float fuzzRoughness;\n float coatWeight;\n vec3 coatColor;\n float coatRoughness;\n float coatAnisotropy;\n vec2 anisotropyDirection;\n bool anisotropyDirectionEnabled;\n float coatAnisotropyRotation;\n vec3 directionTangent;\n vec3 directionBitangent;\n vec3 geometryTangent;\n vec3 geometryBitangent;\n#ifdef USE_COAT_NORMAL_FRAMES\n vec3 coatNormal;\n bool coatNormalEnabled;\n vec3 geometricNormal;\n#endif\n float coatIor;\n float coatDarkening;\n\n float bevel;\n\n // Calculated\n float relativeIor;\n bool inside;\n float alphaX;\n float alphaY;\n};\n\n\nstruct Light {\n vec3 position;\n vec3 emission;\n vec3 u;\n vec3 v;\n float radius;\n float area;\n float type;\n int textureIndex;\n float spread;\n float selectionPmf;\n float selectionCdf;\n vec3 iesReference;\n};\n\nvoid initRay(inout Ray ray, vec3 origin, vec3 direction) {\n ray.o = origin;\n ray.d = direction;\n ray.tMax = RAY_MAX_DISTANCE;\n}\n\n// given the index from a 1D array, retrieve corresponding position from packed 2D texture\nivec2 unpackTexel(int i, int columnsLog2) {\n ivec2 u;\n u.y = i >> columnsLog2; // equivalent to (i / 2^columnsLog2)\n u.x = i - (u.y << columnsLog2); // equivalent to (i % 2^columnsLog2)\n return u;\n}\n\nvec4 fetchData(sampler2D s, int i, int columnsLog2) {\n return texelFetch(s, unpackTexel(i, columnsLog2), 0);\n}\n\nivec4 fetchData(highp isampler2D s, int i, int columnsLog2) {\n return texelFetch(s, unpackTexel(i, columnsLog2), 0);\n}\n\nstruct Path {\n Ray ray;\n vec3 li;\n float alpha;\n vec3 beta;\n bool fromEye;\n bool abort;\n float scatteringPdf;\n bool scatteringIsDelta;\n bool isNextRefraction;${fragments['core1'] ?? ''}\n};\n\nstruct LightSampleRec {\n vec3 normal;\n vec3 emission;\n vec3 direction;\n float dist;\n float pdf;\n bool isDelta;\n int sourceType;\n int sourceIndex;\n};\n\n\nLight fetchLight(int i) {\n int firstTexel = i * 6;\n vec4 positionAndPmf = texelFetch(\n lightsTex,\n ivec2(firstTexel, 0),\n 0\n );\n vec4 emissionAndCdf = texelFetch(\n lightsTex,\n ivec2(firstTexel + 1, 0),\n 0\n );\n vec4 tangentAndSpread = texelFetch(\n lightsTex,\n ivec2(firstTexel + 2, 0),\n 0\n );\n vec4 bitangentAndTexture = texelFetch(\n lightsTex,\n ivec2(firstTexel + 3, 0),\n 0\n );\n vec4 shape = texelFetch(\n lightsTex,\n ivec2(firstTexel + 4, 0),\n 0\n );\n return Light(\n positionAndPmf.xyz,\n emissionAndCdf.xyz,\n tangentAndSpread.xyz,\n bitangentAndTexture.xyz,\n shape.x,\n shape.y,\n shape.z,\n int(bitangentAndTexture.w),\n tangentAndSpread.w,\n positionAndPmf.w,\n emissionAndCdf.w,\n texelFetch(lightsTex, ivec2(firstTexel + 5, 0), 0).xyz\n );\n}\n\nfloat iesProfileScalar(int baseTexel, int scalarIndex) {\n int texelIndex = baseTexel + scalarIndex / 4;\n vec4 packed = texelFetch(\n iesProfileData,\n ivec2(texelIndex % iesProfileColumns, texelIndex / iesProfileColumns),\n 0\n );\n return packed[scalarIndex % 4];\n}\n\nfloat sampleIESProfile(int baseTexel, vec2 uv) {\n if (baseTexel < 0) return 1.0;\n vec2 pixel = fract(uv) * 128.0 - 0.5;\n ivec2 p0 = ivec2(floor(pixel));\n vec2 f = fract(pixel);\n int xa = p0.x < 0 ? 127 : p0.x;\n int xb = p0.x >= 127 ? 0 : p0.x + 1;\n int ya = p0.y < 0 ? 127 : p0.y;\n int yb = p0.y >= 127 ? 0 : p0.y + 1;\n float a = iesProfileScalar(baseTexel, ya * 128 + xa);\n float b = iesProfileScalar(baseTexel, ya * 128 + xb);\n float c = iesProfileScalar(baseTexel, yb * 128 + xa);\n float d = iesProfileScalar(baseTexel, yb * 128 + xb);\n return mix(mix(a, b, f.x), mix(c, d, f.x), f.y);\n}\n\nfloat evaluateSpotEmissionMultiplier(Light light, vec3 lightToSurface) {\n vec3 axis = normalize(light.u);\n float cosTheta = dot(axis, lightToSurface);\n float cone = light.v.y > light.v.x + 1e-6\n ? smoothstep(light.v.x, light.v.y, cosTheta)\n : step(light.v.x, cosTheta);\n if (cone <= 0.0 || light.textureIndex < 0) return cone;\n vec3 xAxis = light.iesReference;\n vec3 yAxis = cross(axis, xAxis);\n float vertical = acos(clamp(cosTheta, -1.0, 1.0));\n float horizontal = atan(dot(lightToSurface, yAxis), dot(lightToSurface, xAxis));\n return cone * sampleIESProfile(light.textureIndex, vec2(vertical / PI, horizontal / TWOPI + 0.5));\n}\n`\n});\n}\nexport default createRayTraceCoreGlsl();\n"]}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
+
import emissive from './emissiveLight.glsl.js';
|
|
1
2
|
import { glsl } from '../../shader.js';
|
|
2
3
|
export default glsl `
|
|
3
4
|
#ifdef NUM_LIGHTS
|
|
4
|
-
void
|
|
5
|
+
void eH(
|
|
5
6
|
in Light light,
|
|
6
7
|
in vec3 shadingPoint,
|
|
7
8
|
in vec2 samplePoint,
|
|
8
9
|
inout LightSampleRec result
|
|
9
10
|
) {
|
|
10
|
-
vec3
|
|
11
|
-
float
|
|
11
|
+
vec3 oC = light.position - shadingPoint;
|
|
12
|
+
float ao = length(oC);
|
|
12
13
|
if (light.radius <= 0.0) {
|
|
13
|
-
if (
|
|
14
|
+
if (ao <= 1e-6) {
|
|
14
15
|
result.direction = vec3(0.0, 0.0, 1.0);
|
|
15
16
|
result.normal = vec3(0.0, 0.0, -1.0);
|
|
16
17
|
result.dist = 0.0;
|
|
@@ -19,58 +20,66 @@ result.emission = vec3(0.0);
|
|
|
19
20
|
result.isDelta = true;
|
|
20
21
|
return;
|
|
21
22
|
}
|
|
22
|
-
result.direction =
|
|
23
|
+
result.direction = oC / ao;
|
|
23
24
|
result.normal = -result.direction;
|
|
24
|
-
result.dist =
|
|
25
|
+
result.dist = ao;
|
|
25
26
|
result.pdf = 1.0;
|
|
26
|
-
result.emission = light.emission / max(
|
|
27
|
+
result.emission = light.emission / max(ao * ao, 1e-8);
|
|
27
28
|
result.isDelta = true;
|
|
28
29
|
return;
|
|
29
30
|
}
|
|
30
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;
|
|
31
36
|
result.isDelta = false;
|
|
32
37
|
vec3 direction;
|
|
33
38
|
|
|
34
|
-
if (
|
|
39
|
+
if (ao <= radius) {
|
|
35
40
|
float z = 1.0 - 2.0 * samplePoint.x;
|
|
36
|
-
float
|
|
41
|
+
float dr = sqrt(max(0.0, 1.0 - z * z));
|
|
37
42
|
float azimuth = TWOPI * samplePoint.y;
|
|
38
|
-
direction = vec3(
|
|
43
|
+
direction = vec3(dr * cos(azimuth), dr * sin(azimuth), z);
|
|
39
44
|
result.pdf = INV4PI;
|
|
40
45
|
}
|
|
41
46
|
else {
|
|
42
|
-
vec3 axis =
|
|
43
|
-
float
|
|
47
|
+
vec3 axis = oC / ao;
|
|
48
|
+
float oz = min(
|
|
44
49
|
1.0,
|
|
45
|
-
radius * radius / (
|
|
50
|
+
radius * radius / (ao * ao)
|
|
46
51
|
);
|
|
47
|
-
float
|
|
48
|
-
|
|
49
|
-
|
|
52
|
+
float vA = sqrt(max(0.0, 1.0 - oz));
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
float mf = oz / (1.0 + vA);
|
|
56
|
+
float ng = samplePoint.x * mf;
|
|
57
|
+
float cosine = 1.0 - ng;
|
|
58
|
+
float uC = sqrt(max(0.0, ng * (2.0 - ng)));
|
|
50
59
|
float azimuth = TWOPI * samplePoint.y;
|
|
51
60
|
vec3 tangent;
|
|
52
61
|
vec3 bitangent;
|
|
53
|
-
|
|
62
|
+
sampling_orthonormal_basis(axis, tangent, bitangent);
|
|
54
63
|
direction = axis * cosine
|
|
55
|
-
+ tangent * (
|
|
56
|
-
+ bitangent * (
|
|
57
|
-
result.pdf = 1.0 / max(TWOPI *
|
|
64
|
+
+ tangent * (uC * cos(azimuth))
|
|
65
|
+
+ bitangent * (uC * sin(azimuth));
|
|
66
|
+
result.pdf = 1.0 / max(TWOPI * mf, 1e-8);
|
|
58
67
|
}
|
|
59
68
|
|
|
60
|
-
float
|
|
61
|
-
float
|
|
62
|
-
- dot(
|
|
63
|
-
float
|
|
64
|
-
float
|
|
65
|
-
float
|
|
66
|
-
result.dist =
|
|
69
|
+
float ji = dot(direction, oC);
|
|
70
|
+
float bj = ji * ji
|
|
71
|
+
- dot(oC, oC) + radius * radius;
|
|
72
|
+
float root = sqrt(max(0.0, bj));
|
|
73
|
+
float cI = ji - root;
|
|
74
|
+
float cw = ji + root;
|
|
75
|
+
result.dist = cI > 1e-6 ? cI : cw;
|
|
67
76
|
result.direction = direction;
|
|
68
77
|
vec3 surfacePoint = shadingPoint + direction * result.dist;
|
|
69
78
|
result.normal = normalize(surfacePoint - light.position);
|
|
70
79
|
result.emission = light.emission;
|
|
71
80
|
}
|
|
72
81
|
|
|
73
|
-
void
|
|
82
|
+
void bC(
|
|
74
83
|
in Light light,
|
|
75
84
|
in vec3 surfacePoint,
|
|
76
85
|
in vec3 lowerLeft,
|
|
@@ -80,17 +89,17 @@ inout LightSampleRec result
|
|
|
80
89
|
if (light.textureIndex >= 0) {
|
|
81
90
|
float width = length(light.u);
|
|
82
91
|
float height = length(light.v);
|
|
83
|
-
vec3
|
|
92
|
+
vec3 dU = surfacePoint - lowerLeft;
|
|
84
93
|
vec2 uv = vec2(
|
|
85
|
-
dot(
|
|
86
|
-
dot(
|
|
94
|
+
dot(dU, light.u / width) / width,
|
|
95
|
+
dot(dU, light.v / height) / height
|
|
87
96
|
);
|
|
88
97
|
result.emission *= sampleMap(light.textureIndex, uv).rgb;
|
|
89
98
|
}
|
|
90
99
|
#endif
|
|
91
100
|
}
|
|
92
101
|
|
|
93
|
-
void
|
|
102
|
+
void jZ(
|
|
94
103
|
in Light light,
|
|
95
104
|
in vec3 shadingPoint,
|
|
96
105
|
in vec2 samplePoint,
|
|
@@ -101,28 +110,28 @@ vec3 lowerLeft = light.position - 0.5 * (light.u + light.v);
|
|
|
101
110
|
float spread = clamp(light.spread, 0.0, 1.0);
|
|
102
111
|
|
|
103
112
|
if (spread <= 0.001) {
|
|
104
|
-
float
|
|
105
|
-
vec3 surfacePoint = shadingPoint - normal *
|
|
106
|
-
vec3
|
|
113
|
+
float gg = dot(normal, shadingPoint - light.position);
|
|
114
|
+
vec3 surfacePoint = shadingPoint - normal * gg;
|
|
115
|
+
vec3 dU = surfacePoint - lowerLeft;
|
|
107
116
|
float width = length(light.u);
|
|
108
117
|
float height = length(light.v);
|
|
109
118
|
vec2 uv = vec2(
|
|
110
|
-
dot(
|
|
111
|
-
dot(
|
|
119
|
+
dot(dU, light.u / width) / width,
|
|
120
|
+
dot(dU, light.v / height) / height
|
|
112
121
|
);
|
|
113
|
-
if (
|
|
122
|
+
if (gg <= 0.0 || any(lessThan(uv, vec2(0.0)))
|
|
114
123
|
|| any(greaterThan(uv, vec2(1.0)))) {
|
|
115
124
|
result.emission = vec3(0.0);
|
|
116
125
|
result.pdf = 0.0;
|
|
117
126
|
return;
|
|
118
127
|
}
|
|
119
128
|
result.direction = -normal;
|
|
120
|
-
result.dist =
|
|
129
|
+
result.dist = gg;
|
|
121
130
|
result.normal = normal;
|
|
122
131
|
result.emission = light.emission;
|
|
123
132
|
result.pdf = 1.0;
|
|
124
133
|
result.isDelta = true;
|
|
125
|
-
|
|
134
|
+
bC(light, surfacePoint, lowerLeft, result);
|
|
126
135
|
return;
|
|
127
136
|
}
|
|
128
137
|
|
|
@@ -130,23 +139,23 @@ vec3 surfacePoint = lowerLeft
|
|
|
130
139
|
+ light.u * samplePoint.x
|
|
131
140
|
+ light.v * samplePoint.y;
|
|
132
141
|
vec3 offset = surfacePoint - shadingPoint;
|
|
133
|
-
float
|
|
134
|
-
result.dist = sqrt(
|
|
142
|
+
float bG = dot(offset, offset);
|
|
143
|
+
result.dist = sqrt(bG);
|
|
135
144
|
result.direction = offset / result.dist;
|
|
136
145
|
result.normal = normal;
|
|
137
|
-
float
|
|
138
|
-
float
|
|
139
|
-
if (
|
|
146
|
+
float fY = dot(-result.direction, normal);
|
|
147
|
+
float pp = cos(0.5 * PI * spread);
|
|
148
|
+
if (fY <= 0.0 || fY < pp) {
|
|
140
149
|
result.emission = vec3(0.0);
|
|
141
150
|
result.pdf = 0.0;
|
|
142
151
|
return;
|
|
143
152
|
}
|
|
144
153
|
result.emission = light.emission;
|
|
145
|
-
result.pdf =
|
|
146
|
-
|
|
154
|
+
result.pdf = bG / max(light.area * fY, 1e-8);
|
|
155
|
+
bC(light, surfacePoint, lowerLeft, result);
|
|
147
156
|
}
|
|
148
157
|
|
|
149
|
-
void
|
|
158
|
+
void gc(
|
|
150
159
|
in Light light,
|
|
151
160
|
in vec3 shadingPoint,
|
|
152
161
|
inout LightSampleRec result
|
|
@@ -159,94 +168,103 @@ result.pdf = 1.0;
|
|
|
159
168
|
result.isDelta = true;
|
|
160
169
|
}
|
|
161
170
|
|
|
162
|
-
void
|
|
171
|
+
void ka(
|
|
163
172
|
in Light light,
|
|
164
173
|
in vec3 shadingPoint,
|
|
165
174
|
in vec2 samplePoint,
|
|
166
175
|
inout LightSampleRec result
|
|
167
176
|
) {
|
|
168
|
-
|
|
177
|
+
eH(light, shadingPoint, samplePoint, result);
|
|
169
178
|
vec3 surfacePoint = shadingPoint + result.direction * result.dist;
|
|
170
|
-
result.emission *=
|
|
179
|
+
result.emission *= evaluateSpotEmissionMultiplier(
|
|
171
180
|
light,
|
|
172
181
|
normalize(shadingPoint - surfacePoint)
|
|
173
182
|
);
|
|
174
183
|
}
|
|
175
184
|
|
|
176
|
-
void
|
|
185
|
+
void sampleAnalyticLight(
|
|
177
186
|
in Light light,
|
|
178
187
|
in vec3 shadingPoint,
|
|
179
188
|
in vec2 samplePoint,
|
|
180
189
|
inout LightSampleRec result
|
|
181
190
|
) {
|
|
182
|
-
int
|
|
191
|
+
int dO = int(light.type);
|
|
183
192
|
#ifdef HAS_RECT_LIGHTS
|
|
184
|
-
if (
|
|
185
|
-
|
|
193
|
+
if (dO == RECT_LIGHT) {
|
|
194
|
+
jZ(light, shadingPoint, samplePoint, result);
|
|
186
195
|
return;
|
|
187
196
|
}
|
|
188
197
|
#endif
|
|
189
198
|
#ifdef HAS_SPHERE_LIGHTS
|
|
190
|
-
if (
|
|
191
|
-
|
|
199
|
+
if (dO == SPHERE_LIGHT) {
|
|
200
|
+
eH(light, shadingPoint, samplePoint, result);
|
|
192
201
|
return;
|
|
193
202
|
}
|
|
194
203
|
#endif
|
|
195
204
|
#ifdef HAS_SPOT_LIGHTS
|
|
196
|
-
if (
|
|
197
|
-
|
|
205
|
+
if (dO == SPOT_LIGHT) {
|
|
206
|
+
ka(light, shadingPoint, samplePoint, result);
|
|
198
207
|
return;
|
|
199
208
|
}
|
|
200
209
|
#endif
|
|
201
210
|
#ifdef HAS_DIRECTIONAL_LIGHTS
|
|
202
|
-
if (
|
|
203
|
-
|
|
211
|
+
if (dO == DIRECTIONAL_LIGHT) {
|
|
212
|
+
gc(light, shadingPoint, result);
|
|
204
213
|
}
|
|
205
214
|
#endif
|
|
206
215
|
}
|
|
207
216
|
#endif
|
|
208
217
|
|
|
209
|
-
void
|
|
218
|
+
void ig(in vec2 samplePoint, inout LightSampleRec result) {
|
|
210
219
|
vec2 uv;
|
|
211
|
-
result.direction =
|
|
220
|
+
result.direction = pn(samplePoint, uv, result.pdf);
|
|
212
221
|
result.emission = textureLinear(envMap, uv).rgb;
|
|
213
222
|
result.dist = INF;
|
|
214
223
|
}
|
|
215
224
|
|
|
225
|
+
#ifdef HAS_EMISSIVE_LIGHTS
|
|
226
|
+
${emissive}
|
|
227
|
+
#endif
|
|
228
|
+
|
|
216
229
|
void sampleLight(
|
|
217
230
|
in vec3 shadingPoint,
|
|
218
231
|
in vec3 randomSampleValue,
|
|
219
232
|
inout LightSampleRec result,
|
|
220
233
|
bool tk
|
|
221
234
|
) {
|
|
235
|
+
#ifdef HAS_EMISSIVE_LIGHTS
|
|
236
|
+
jb(shadingPoint,randomSampleValue,result);return;
|
|
237
|
+
#endif
|
|
238
|
+
result.sourceType=0;result.sourceIndex=-1;
|
|
222
239
|
result.isDelta = false;
|
|
223
|
-
float
|
|
224
|
-
bool
|
|
240
|
+
float vP = randomSampleValue.z;
|
|
241
|
+
bool kN = false;
|
|
225
242
|
#ifdef USE_ENVMAP
|
|
226
|
-
|
|
227
|
-
if (
|
|
228
|
-
|
|
243
|
+
kN = vP < envLightSelectionPmf;
|
|
244
|
+
if (kN) {
|
|
245
|
+
ig(randomSampleValue.xy, result);
|
|
229
246
|
result.pdf *= envLightSelectionPmf;
|
|
230
247
|
}
|
|
231
248
|
#endif
|
|
232
249
|
|
|
233
250
|
#ifdef NUM_LIGHTS
|
|
234
|
-
if (!
|
|
235
|
-
int
|
|
251
|
+
if (!kN) {
|
|
252
|
+
int jc = NUM_LIGHTS - 1;
|
|
236
253
|
for (int index = 0; index < NUM_LIGHTS; index++) {
|
|
237
|
-
if (
|
|
238
|
-
|
|
254
|
+
if (vP < fetchLight(index).selectionCdf) {
|
|
255
|
+
jc = index;
|
|
239
256
|
break;
|
|
240
257
|
}
|
|
241
258
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
259
|
+
result.sourceType=2;result.sourceIndex=jc;
|
|
260
|
+
Light rh = fetchLight(jc);
|
|
261
|
+
sampleAnalyticLight(
|
|
262
|
+
rh,
|
|
245
263
|
shadingPoint,
|
|
246
264
|
randomSampleValue.xy,
|
|
247
265
|
result
|
|
248
266
|
);
|
|
249
|
-
result.pdf *=
|
|
267
|
+
result.pdf *= rh.selectionPmf;
|
|
250
268
|
}
|
|
251
269
|
#endif
|
|
252
270
|
}
|