@meimu/mutracer 0.1.3 → 0.1.4
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/dist/assets/bvh.worker.js +1 -1
- package/dist/mutracer.umd.js +4114 -4015
- package/docs/api.md +11 -9
- package/docs/threejs.md +30 -4
- package/lib/Engine.js +18 -1
- package/lib/Engine.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/MaterialTable.d.ts +1 -0
- package/lib/renderer/MaterialTable.js +10 -4
- package/lib/renderer/MaterialTable.js.map +1 -1
- package/lib/renderer/WGPUBloomPass.js +18 -18
- package/lib/renderer/WGPUFullQuadPass.js +6 -6
- package/lib/renderer/WGPUJNLMDenoiser.js +69 -69
- package/lib/renderer/WGPURayTraceOutput.js +14 -14
- package/lib/renderer/WGPURayTracePass.d.ts +2 -0
- package/lib/renderer/WGPURayTracePass.js +12 -6
- package/lib/renderer/WGPURayTracePass.js.map +1 -1
- package/lib/renderer/WGPURenderingPipeline.js +15 -15
- package/lib/renderer/WebGLJNLMDenoiser.js +69 -69
- package/lib/renderer/WebGLRayTraceOutputPass.js +4 -4
- package/lib/renderer/WebGLRayTracePass.d.ts +1 -0
- package/lib/renderer/WebGLRayTracePass.js +7 -1
- package/lib/renderer/WebGLRayTracePass.js.map +1 -1
- package/lib/renderer/envMapCreation.d.ts +5 -1
- package/lib/renderer/envMapCreation.js +42 -5
- package/lib/renderer/envMapCreation.js.map +1 -1
- package/lib/renderer/geometryUpdates.js +1 -1
- package/lib/renderer/geometryUpdates.js.map +1 -1
- package/lib/renderer/glsl/chunks/cameraRay.glsl.js +12 -12
- package/lib/renderer/glsl/chunks/envMap.glsl.js +66 -54
- package/lib/renderer/glsl/chunks/envMap.glsl.js.map +1 -1
- package/lib/renderer/glsl/chunks/intersect.glsl.js +316 -310
- package/lib/renderer/glsl/chunks/intersect.glsl.js.map +1 -1
- package/lib/renderer/glsl/chunks/materialBuffer.glsl.js +151 -119
- package/lib/renderer/glsl/chunks/materialBuffer.glsl.js.map +1 -1
- package/lib/renderer/glsl/chunks/openPbrBsdf.glsl.js +414 -414
- package/lib/renderer/glsl/chunks/rand.glsl.js +3 -3
- package/lib/renderer/glsl/chunks/random.glsl.js +3 -3
- package/lib/renderer/glsl/chunks/rayTraceCore.glsl.js +40 -39
- package/lib/renderer/glsl/chunks/rayTraceCore.glsl.js.map +1 -1
- package/lib/renderer/glsl/chunks/sampleLight.glsl.js +69 -69
- package/lib/renderer/glsl/chunks/sampleMaterial.glsl.js +78 -78
- package/lib/renderer/glsl/chunks/sampleShadowCatcher.glsl.js +12 -12
- package/lib/renderer/glsl/chunks/sampling.glsl.js +75 -75
- package/lib/renderer/glsl/chunks/sobol.glsl.js +61 -61
- 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 +5 -5
- package/lib/renderer/glsl/depthQuery.frag.js.map +1 -1
- package/lib/renderer/glsl/normalizeRayTraceOutput.frag.js +8 -8
- package/lib/renderer/glsl/rayTrace.frag.js +133 -133
- package/lib/renderer/glsl/rayTrace.frag.js.map +1 -1
- package/lib/renderer/glsl/shadowCatcher.frag.js +9 -9
- package/lib/renderer/glsl/shadowCatcher.frag.js.map +1 -1
- package/lib/renderer/glsl/webglPipeline.frag.js +52 -52
- package/lib/renderer/lightsUtil.js +6 -4
- package/lib/renderer/lightsUtil.js.map +1 -1
- package/lib/renderer/materialChanges.js +1 -1
- package/lib/renderer/materialChanges.js.map +1 -1
- package/lib/renderer/materialComparison.generated.js +36 -18
- package/lib/renderer/materialComparison.generated.js.map +1 -1
- package/lib/renderer/prepareMeshBVH.js +2 -2
- package/lib/renderer/prepareMeshBVH.js.map +1 -1
- package/lib/renderer/sceneChangeDetector.js +4 -1
- package/lib/renderer/sceneChangeDetector.js.map +1 -1
- package/lib/renderer/sceneLightChanges.js +3 -2
- package/lib/renderer/sceneLightChanges.js.map +1 -1
- package/lib/renderer/scratchSampling.js +18 -18
- package/lib/renderer/wgsl/chunks/common.wgsl.js +4 -4
- package/lib/renderer/wgsl/chunks/envMap.wgsl.d.ts +1 -1
- package/lib/renderer/wgsl/chunks/envMap.wgsl.js +39 -31
- package/lib/renderer/wgsl/chunks/envMap.wgsl.js.map +1 -1
- package/lib/renderer/wgsl/chunks/intersect.wgsl.js +475 -469
- package/lib/renderer/wgsl/chunks/intersect.wgsl.js.map +1 -1
- package/lib/renderer/wgsl/chunks/intersectionAlpha.wgsl.js +8 -8
- package/lib/renderer/wgsl/chunks/materialBuffer.wgsl.js +93 -59
- package/lib/renderer/wgsl/chunks/materialBuffer.wgsl.js.map +1 -1
- package/lib/renderer/wgsl/chunks/openPbrBsdf.wgsl.js +469 -469
- package/lib/renderer/wgsl/chunks/pdm_displacement.wgsl.d.ts +1 -1
- package/lib/renderer/wgsl/chunks/pdm_displacement.wgsl.js +117 -120
- package/lib/renderer/wgsl/chunks/pdm_displacement.wgsl.js.map +1 -1
- package/lib/renderer/wgsl/chunks/rand.wgsl.js +3 -3
- package/lib/renderer/wgsl/chunks/rayTraceCore.wgsl.js +25 -22
- package/lib/renderer/wgsl/chunks/rayTraceCore.wgsl.js.map +1 -1
- package/lib/renderer/wgsl/chunks/sampleLight.wgsl.js +127 -127
- package/lib/renderer/wgsl/chunks/sampleMaterial.wgsl.js +136 -136
- package/lib/renderer/wgsl/chunks/sampleShadowCatcher.wgsl.js +6 -6
- package/lib/renderer/wgsl/chunks/sampling.wgsl.js +73 -73
- package/lib/renderer/wgsl/chunks/sobol.wgsl.js +62 -62
- package/lib/renderer/wgsl/chunks/uvProjection.wgsl.js +11 -11
- package/lib/renderer/wgsl/compose.frag.wgsl.js +105 -105
- 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 +5 -5
- package/lib/renderer/wgsl/depthQuery.wgsl.js.map +1 -1
- package/lib/renderer/wgsl/offlineAdaptive.compute.js +28 -28
- package/lib/renderer/wgsl/rayTrace.compute.js +251 -248
- package/lib/renderer/wgsl/rayTrace.compute.js.map +1 -1
- package/lib/scene/EnvironmentLight.d.ts +9 -3
- package/lib/scene/EnvironmentLight.js +9 -2
- package/lib/scene/EnvironmentLight.js.map +1 -1
- package/lib/scene/Scene.d.ts +4 -0
- package/lib/scene/Scene.js.map +1 -1
- package/lib/scene/SpotLight.d.ts +2 -2
- package/lib/scene/SpotLight.js +1 -1
- package/lib/scene/SpotLight.js.map +1 -1
- package/lib/scene/Texture.d.ts +17 -6
- package/lib/scene/Texture.js +13 -4
- package/lib/scene/Texture.js.map +1 -1
- package/lib/util/fromTHREE.js +151 -29
- 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 +1 -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 kh(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 vx(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
|
+
vx(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
|
|
13
|
+
void su() {
|
|
14
14
|
bc = uvec2(v_Texcoord / pixelSize);
|
|
15
15
|
bd = uint(sampleCount);
|
|
16
16
|
cF = 0u; em = 0u;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
vec2
|
|
19
|
+
vec2 sa() {
|
|
20
20
|
if (samplingPattern == 0 || samplingPattern == 1) {
|
|
21
|
-
return (
|
|
21
|
+
return (fo(CAMERA_PIXEL) - 0.5) * pixelSize;
|
|
22
22
|
}
|
|
23
23
|
return jitter;
|
|
24
24
|
}
|
|
@@ -23,7 +23,7 @@ export default createShaderMixin({
|
|
|
23
23
|
main: glsl `
|
|
24
24
|
|
|
25
25
|
const vec3 luminance = vec3(0.2126, 0.7152, 0.0722);
|
|
26
|
-
const int
|
|
26
|
+
const int vE = 8;
|
|
27
27
|
|
|
28
28
|
#define RAY_MAX_DISTANCE 9999.0
|
|
29
29
|
|
|
@@ -48,6 +48,7 @@ vec3 shadowOffset;
|
|
|
48
48
|
|
|
49
49
|
vec2 uv;
|
|
50
50
|
vec2 uv1;
|
|
51
|
+
vec3 vertexColor;
|
|
51
52
|
|
|
52
53
|
#ifdef USE_TANGENT
|
|
53
54
|
vec3 tangent;
|
|
@@ -156,26 +157,26 @@ float selectionCdf;
|
|
|
156
157
|
vec3 iesReference;
|
|
157
158
|
};
|
|
158
159
|
|
|
159
|
-
void
|
|
160
|
+
void iC(inout Ray ray, vec3 origin, vec3 direction) {
|
|
160
161
|
ray.o = origin;
|
|
161
162
|
ray.d = direction;
|
|
162
163
|
ray.tMax = RAY_MAX_DISTANCE;
|
|
163
164
|
}
|
|
164
165
|
|
|
165
166
|
|
|
166
|
-
ivec2
|
|
167
|
+
ivec2 gQ(int i, int jz) {
|
|
167
168
|
ivec2 u;
|
|
168
|
-
u.y = i >>
|
|
169
|
-
u.x = i - (u.y <<
|
|
169
|
+
u.y = i >> jz;
|
|
170
|
+
u.x = i - (u.y << jz);
|
|
170
171
|
return u;
|
|
171
172
|
}
|
|
172
173
|
|
|
173
|
-
vec4
|
|
174
|
-
return texelFetch(s,
|
|
174
|
+
vec4 kG(sampler2D s, int i, int jz) {
|
|
175
|
+
return texelFetch(s, gQ(i, jz), 0);
|
|
175
176
|
}
|
|
176
177
|
|
|
177
|
-
ivec4
|
|
178
|
-
return texelFetch(s,
|
|
178
|
+
ivec4 kG(highp isampler2D s, int i, int jz) {
|
|
179
|
+
return texelFetch(s, gQ(i, jz), 0);
|
|
179
180
|
}
|
|
180
181
|
|
|
181
182
|
struct Path {
|
|
@@ -200,24 +201,24 @@ bool isDelta;
|
|
|
200
201
|
};
|
|
201
202
|
|
|
202
203
|
|
|
203
|
-
Light
|
|
204
|
+
Light qx(int i) {
|
|
204
205
|
int firstTexel = i * 6;
|
|
205
|
-
vec4
|
|
206
|
+
vec4 pO = texelFetch(
|
|
206
207
|
lightsTex,
|
|
207
208
|
ivec2(firstTexel, 0),
|
|
208
209
|
0
|
|
209
210
|
);
|
|
210
|
-
vec4
|
|
211
|
+
vec4 po = texelFetch(
|
|
211
212
|
lightsTex,
|
|
212
213
|
ivec2(firstTexel + 1, 0),
|
|
213
214
|
0
|
|
214
215
|
);
|
|
215
|
-
vec4
|
|
216
|
+
vec4 nQ = texelFetch(
|
|
216
217
|
lightsTex,
|
|
217
218
|
ivec2(firstTexel + 2, 0),
|
|
218
219
|
0
|
|
219
220
|
);
|
|
220
|
-
vec4
|
|
221
|
+
vec4 lN = texelFetch(
|
|
221
222
|
lightsTex,
|
|
222
223
|
ivec2(firstTexel + 3, 0),
|
|
223
224
|
0
|
|
@@ -228,36 +229,36 @@ ivec2(firstTexel + 4, 0),
|
|
|
228
229
|
0
|
|
229
230
|
);
|
|
230
231
|
return Light(
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
232
|
+
pO.xyz,
|
|
233
|
+
po.xyz,
|
|
234
|
+
nQ.xyz,
|
|
235
|
+
lN.xyz,
|
|
235
236
|
shape.x,
|
|
236
237
|
shape.y,
|
|
237
238
|
shape.z,
|
|
238
|
-
int(
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
239
|
+
int(lN.w),
|
|
240
|
+
nQ.w,
|
|
241
|
+
pO.w,
|
|
242
|
+
po.w,
|
|
242
243
|
texelFetch(lightsTex, ivec2(firstTexel + 5, 0), 0).xyz
|
|
243
244
|
);
|
|
244
245
|
}
|
|
245
246
|
|
|
246
|
-
float cL(int dV, int
|
|
247
|
-
int
|
|
247
|
+
float cL(int dV, int ls) {
|
|
248
|
+
int im = dV + ls / 4;
|
|
248
249
|
vec4 packed = texelFetch(
|
|
249
250
|
iesProfileData,
|
|
250
|
-
ivec2(
|
|
251
|
+
ivec2(im % iesProfileColumns, im / iesProfileColumns),
|
|
251
252
|
0
|
|
252
253
|
);
|
|
253
|
-
return packed[
|
|
254
|
+
return packed[ls % 4];
|
|
254
255
|
}
|
|
255
256
|
|
|
256
|
-
float
|
|
257
|
+
float kR(int dV, vec2 uv) {
|
|
257
258
|
if (dV < 0) return 1.0;
|
|
258
|
-
vec2
|
|
259
|
-
ivec2 p0 = ivec2(floor(
|
|
260
|
-
vec2 f = fract(
|
|
259
|
+
vec2 fP = fract(uv) * 128.0 - 0.5;
|
|
260
|
+
ivec2 p0 = ivec2(floor(fP));
|
|
261
|
+
vec2 f = fract(fP);
|
|
261
262
|
int xa = p0.x < 0 ? 127 : p0.x;
|
|
262
263
|
int xb = p0.x >= 127 ? 0 : p0.x + 1;
|
|
263
264
|
int ya = p0.y < 0 ? 127 : p0.y;
|
|
@@ -269,18 +270,18 @@ float d = cL(dV, yb * 128 + xb);
|
|
|
269
270
|
return mix(mix(a, b, f.x), mix(c, d, f.x), f.y);
|
|
270
271
|
}
|
|
271
272
|
|
|
272
|
-
float bL(Light light, vec3
|
|
273
|
+
float bL(Light light, vec3 dK) {
|
|
273
274
|
vec3 axis = normalize(light.u);
|
|
274
|
-
float cc = dot(axis,
|
|
275
|
-
float
|
|
276
|
-
? smoothstep(light.v.x, light.v.
|
|
275
|
+
float cc = dot(axis, dK);
|
|
276
|
+
float tP = light.v.y > light.v.x + 1e-6
|
|
277
|
+
? smoothstep(light.v.x, light.v.y, cc)
|
|
277
278
|
: step(light.v.x, cc);
|
|
278
|
-
if (
|
|
279
|
-
vec3
|
|
280
|
-
vec3
|
|
279
|
+
if (tP <= 0.0 || light.textureIndex < 0) return tP;
|
|
280
|
+
vec3 uj = light.iesReference;
|
|
281
|
+
vec3 vD = cross(axis, uj);
|
|
281
282
|
float vertical = acos(clamp(cc, -1.0, 1.0));
|
|
282
|
-
float horizontal = atan(dot(
|
|
283
|
-
return
|
|
283
|
+
float horizontal = atan(dot(dK, vD), dot(dK, uj));
|
|
284
|
+
return tP * kR(light.textureIndex, vec2(vertical / PI, horizontal / TWOPI + 0.5));
|
|
284
285
|
}
|
|
285
286
|
`
|
|
286
287
|
});
|
|
@@ -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,qBAAqB,CAAC;AAE1D,eAAe,iBAAiB,CAAC;IAC/B,QAAQ,EAAE;QACR,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC;QACtC,cAAc,EAAE,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC;QAC3C,iBAAiB,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;QAC3C,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;QACjC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;QAC9B,WAAW,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;QAClC,oBAAoB,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;KACjD;IACD,OAAO,EAAE;QACP,QAAQ,EAAE,CAAC;QACX,KAAK,EAAE,aAAa;QACpB,cAAc,EAAE,qBAAqB;QACrC,UAAU,EAAE,mBAAmB;KAChC;IACD,IAAI,EAAE,IAAI,CAAA
|
|
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,qBAAqB,CAAC;AAE1D,eAAe,iBAAiB,CAAC;IAC/B,QAAQ,EAAE;QACR,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC;QACtC,cAAc,EAAE,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC;QAC3C,iBAAiB,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;QAC3C,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;QACjC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;QAC9B,WAAW,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;QAClC,oBAAoB,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;KACjD;IACD,OAAO,EAAE;QACP,QAAQ,EAAE,CAAC;QACX,KAAK,EAAE,aAAa;QACpB,cAAc,EAAE,qBAAqB;QACrC,UAAU,EAAE,mBAAmB;KAChC;IACD,IAAI,EAAE,IAAI,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuQX;CACA,CAAC,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 '../../lightsUtil.js';\n\nexport default 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 NUM_COAT_NORMAL_MAPS\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;\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 NUM_COAT_NORMAL_MAPS\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;\n};\n\nstruct LightSampleRec {\n vec3 normal;\n vec3 emission;\n vec3 direction;\n float dist;\n float pdf;\n bool isDelta;\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"]}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { glsl } from '../../shader.js';
|
|
2
2
|
export default glsl `
|
|
3
3
|
#ifdef NUM_LIGHTS
|
|
4
|
-
void
|
|
4
|
+
void eM(
|
|
5
5
|
in Light light,
|
|
6
6
|
in vec3 shadingPoint,
|
|
7
7
|
in vec2 samplePoint,
|
|
8
8
|
inout LightSampleRec result
|
|
9
9
|
) {
|
|
10
|
-
vec3
|
|
11
|
-
float aj = length(
|
|
10
|
+
vec3 nS = light.position - shadingPoint;
|
|
11
|
+
float aj = length(nS);
|
|
12
12
|
if (light.radius <= 0.0) {
|
|
13
13
|
if (aj <= 1e-6) {
|
|
14
14
|
result.direction = vec3(0.0, 0.0, 1.0);
|
|
@@ -19,7 +19,7 @@ result.emission = vec3(0.0);
|
|
|
19
19
|
result.isDelta = true;
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
22
|
-
result.direction =
|
|
22
|
+
result.direction = nS / aj;
|
|
23
23
|
result.normal = -result.direction;
|
|
24
24
|
result.dist = aj;
|
|
25
25
|
result.pdf = 1.0;
|
|
@@ -33,36 +33,36 @@ vec3 direction;
|
|
|
33
33
|
|
|
34
34
|
if (aj <= radius) {
|
|
35
35
|
float z = 1.0 - 2.0 * samplePoint.x;
|
|
36
|
-
float
|
|
36
|
+
float fl = sqrt(max(0.0, 1.0 - z * z));
|
|
37
37
|
float br = TWOPI * samplePoint.y;
|
|
38
|
-
direction = vec3(
|
|
38
|
+
direction = vec3(fl * cos(br), fl * sin(br), z);
|
|
39
39
|
result.pdf = INV4PI;
|
|
40
40
|
}
|
|
41
41
|
else {
|
|
42
|
-
vec3 axis =
|
|
43
|
-
float
|
|
42
|
+
vec3 axis = nS / aj;
|
|
43
|
+
float rT = min(
|
|
44
44
|
1.0,
|
|
45
45
|
radius * radius / (aj * aj)
|
|
46
46
|
);
|
|
47
|
-
float
|
|
48
|
-
float au = mix(1.0,
|
|
49
|
-
float
|
|
47
|
+
float rW = sqrt(max(0.0, 1.0 - rT));
|
|
48
|
+
float au = mix(1.0, rW, samplePoint.x);
|
|
49
|
+
float ud = sqrt(max(0.0, 1.0 - au * au));
|
|
50
50
|
float br = TWOPI * samplePoint.y;
|
|
51
51
|
vec3 tangent;
|
|
52
52
|
vec3 bitangent;
|
|
53
53
|
aL(axis, tangent, bitangent);
|
|
54
54
|
direction = axis * au
|
|
55
|
-
+ tangent * (
|
|
56
|
-
+ bitangent * (
|
|
57
|
-
result.pdf = 1.0 / max(TWOPI * (1.0 -
|
|
55
|
+
+ tangent * (ud * cos(br))
|
|
56
|
+
+ bitangent * (ud * sin(br));
|
|
57
|
+
result.pdf = 1.0 / max(TWOPI * (1.0 - rW), 1e-8);
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
float
|
|
61
|
-
float ej =
|
|
62
|
-
- dot(
|
|
63
|
-
float
|
|
64
|
-
float cN =
|
|
65
|
-
float cC =
|
|
60
|
+
float jf = dot(direction, nS);
|
|
61
|
+
float ej = jf * jf
|
|
62
|
+
- dot(nS, nS) + radius * radius;
|
|
63
|
+
float wK = sqrt(max(0.0, ej));
|
|
64
|
+
float cN = jf - wK;
|
|
65
|
+
float cC = jf + wK;
|
|
66
66
|
result.dist = cN > 1e-6 ? cN : cC;
|
|
67
67
|
result.direction = direction;
|
|
68
68
|
vec3 surfacePoint = shadingPoint + direction * result.dist;
|
|
@@ -70,7 +70,7 @@ result.normal = normalize(surfacePoint - light.position);
|
|
|
70
70
|
result.emission = light.emission;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
void
|
|
73
|
+
void da(
|
|
74
74
|
in Light light,
|
|
75
75
|
in vec3 surfacePoint,
|
|
76
76
|
in vec3 lowerLeft,
|
|
@@ -80,17 +80,17 @@ inout LightSampleRec result
|
|
|
80
80
|
if (light.textureIndex >= 0) {
|
|
81
81
|
float width = length(light.u);
|
|
82
82
|
float height = length(light.v);
|
|
83
|
-
vec3
|
|
83
|
+
vec3 ib = surfacePoint - lowerLeft;
|
|
84
84
|
vec2 uv = vec2(
|
|
85
|
-
dot(
|
|
86
|
-
dot(
|
|
85
|
+
dot(ib, light.u / width) / width,
|
|
86
|
+
dot(ib, light.v / height) / height
|
|
87
87
|
);
|
|
88
88
|
result.emission *= sampleMap(light.textureIndex, uv).rgb;
|
|
89
89
|
}
|
|
90
90
|
#endif
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
void
|
|
93
|
+
void jS(
|
|
94
94
|
in Light light,
|
|
95
95
|
in vec3 shadingPoint,
|
|
96
96
|
in vec2 samplePoint,
|
|
@@ -101,28 +101,28 @@ vec3 lowerLeft = light.position - 0.5 * (light.u + light.v);
|
|
|
101
101
|
float spread = clamp(light.spread, 0.0, 1.0);
|
|
102
102
|
|
|
103
103
|
if (spread <= 0.001) {
|
|
104
|
-
float
|
|
105
|
-
vec3 surfacePoint = shadingPoint - normal *
|
|
106
|
-
vec3
|
|
104
|
+
float gf = dot(normal, shadingPoint - light.position);
|
|
105
|
+
vec3 surfacePoint = shadingPoint - normal * gf;
|
|
106
|
+
vec3 ib = surfacePoint - lowerLeft;
|
|
107
107
|
float width = length(light.u);
|
|
108
108
|
float height = length(light.v);
|
|
109
109
|
vec2 uv = vec2(
|
|
110
|
-
dot(
|
|
111
|
-
dot(
|
|
110
|
+
dot(ib, light.u / width) / width,
|
|
111
|
+
dot(ib, light.v / height) / height
|
|
112
112
|
);
|
|
113
|
-
if (
|
|
113
|
+
if (gf <= 0.0 || any(lessThan(uv, vec2(0.0)))
|
|
114
114
|
|| any(greaterThan(uv, vec2(1.0)))) {
|
|
115
115
|
result.emission = vec3(0.0);
|
|
116
116
|
result.pdf = 0.0;
|
|
117
117
|
return;
|
|
118
118
|
}
|
|
119
119
|
result.direction = -normal;
|
|
120
|
-
result.dist =
|
|
120
|
+
result.dist = gf;
|
|
121
121
|
result.normal = normal;
|
|
122
122
|
result.emission = light.emission;
|
|
123
123
|
result.pdf = 1.0;
|
|
124
124
|
result.isDelta = true;
|
|
125
|
-
|
|
125
|
+
da(light, surfacePoint, lowerLeft, result);
|
|
126
126
|
return;
|
|
127
127
|
}
|
|
128
128
|
|
|
@@ -130,23 +130,23 @@ vec3 surfacePoint = lowerLeft
|
|
|
130
130
|
+ light.u * samplePoint.x
|
|
131
131
|
+ light.v * samplePoint.y;
|
|
132
132
|
vec3 offset = surfacePoint - shadingPoint;
|
|
133
|
-
float
|
|
134
|
-
result.dist = sqrt(
|
|
133
|
+
float hq = dot(offset, offset);
|
|
134
|
+
result.dist = sqrt(hq);
|
|
135
135
|
result.direction = offset / result.dist;
|
|
136
136
|
result.normal = normal;
|
|
137
|
-
float
|
|
138
|
-
float
|
|
139
|
-
if (
|
|
137
|
+
float fZ = dot(-result.direction, normal);
|
|
138
|
+
float oO = cos(0.5 * PI * spread);
|
|
139
|
+
if (fZ <= 0.0 || fZ < oO) {
|
|
140
140
|
result.emission = vec3(0.0);
|
|
141
141
|
result.pdf = 0.0;
|
|
142
142
|
return;
|
|
143
143
|
}
|
|
144
144
|
result.emission = light.emission;
|
|
145
|
-
result.pdf =
|
|
146
|
-
|
|
145
|
+
result.pdf = hq / max(light.area * fZ, 1e-8);
|
|
146
|
+
da(light, surfacePoint, lowerLeft, result);
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
-
void
|
|
149
|
+
void gc(
|
|
150
150
|
in Light light,
|
|
151
151
|
in vec3 shadingPoint,
|
|
152
152
|
inout LightSampleRec result
|
|
@@ -159,13 +159,13 @@ result.pdf = 1.0;
|
|
|
159
159
|
result.isDelta = true;
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
-
void
|
|
162
|
+
void jT(
|
|
163
163
|
in Light light,
|
|
164
164
|
in vec3 shadingPoint,
|
|
165
165
|
in vec2 samplePoint,
|
|
166
166
|
inout LightSampleRec result
|
|
167
167
|
) {
|
|
168
|
-
|
|
168
|
+
eM(light, shadingPoint, samplePoint, result);
|
|
169
169
|
vec3 surfacePoint = shadingPoint + result.direction * result.dist;
|
|
170
170
|
result.emission *= bL(
|
|
171
171
|
light,
|
|
@@ -173,42 +173,42 @@ normalize(shadingPoint - surfacePoint)
|
|
|
173
173
|
);
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
-
void
|
|
176
|
+
void iQ(
|
|
177
177
|
in Light light,
|
|
178
178
|
in vec3 shadingPoint,
|
|
179
179
|
in vec2 samplePoint,
|
|
180
180
|
inout LightSampleRec result
|
|
181
181
|
) {
|
|
182
|
-
int
|
|
182
|
+
int dP = int(light.type);
|
|
183
183
|
#ifdef HAS_RECT_LIGHTS
|
|
184
|
-
if (
|
|
185
|
-
|
|
184
|
+
if (dP == RECT_LIGHT) {
|
|
185
|
+
jS(light, shadingPoint, samplePoint, result);
|
|
186
186
|
return;
|
|
187
187
|
}
|
|
188
188
|
#endif
|
|
189
189
|
#ifdef HAS_SPHERE_LIGHTS
|
|
190
|
-
if (
|
|
191
|
-
|
|
190
|
+
if (dP == SPHERE_LIGHT) {
|
|
191
|
+
eM(light, shadingPoint, samplePoint, result);
|
|
192
192
|
return;
|
|
193
193
|
}
|
|
194
194
|
#endif
|
|
195
195
|
#ifdef HAS_SPOT_LIGHTS
|
|
196
|
-
if (
|
|
197
|
-
|
|
196
|
+
if (dP == SPOT_LIGHT) {
|
|
197
|
+
jT(light, shadingPoint, samplePoint, result);
|
|
198
198
|
return;
|
|
199
199
|
}
|
|
200
200
|
#endif
|
|
201
201
|
#ifdef HAS_DIRECTIONAL_LIGHTS
|
|
202
|
-
if (
|
|
203
|
-
|
|
202
|
+
if (dP == DIRECTIONAL_LIGHT) {
|
|
203
|
+
gc(light, shadingPoint, result);
|
|
204
204
|
}
|
|
205
205
|
#endif
|
|
206
206
|
}
|
|
207
207
|
#endif
|
|
208
208
|
|
|
209
|
-
void
|
|
209
|
+
void mH(in vec2 samplePoint, inout LightSampleRec result) {
|
|
210
210
|
vec2 uv;
|
|
211
|
-
result.direction =
|
|
211
|
+
result.direction = oM(samplePoint, uv, result.pdf);
|
|
212
212
|
result.emission = textureLinear(envMap, uv).rgb;
|
|
213
213
|
result.dist = INF;
|
|
214
214
|
}
|
|
@@ -217,36 +217,36 @@ void sampleLight(
|
|
|
217
217
|
in vec3 shadingPoint,
|
|
218
218
|
in vec3 randomSampleValue,
|
|
219
219
|
inout LightSampleRec result,
|
|
220
|
-
bool
|
|
220
|
+
bool sc
|
|
221
221
|
) {
|
|
222
222
|
result.isDelta = false;
|
|
223
|
-
float
|
|
224
|
-
bool
|
|
223
|
+
float uc = randomSampleValue.z;
|
|
224
|
+
bool kA = false;
|
|
225
225
|
#ifdef USE_ENVMAP
|
|
226
|
-
|
|
227
|
-
if (
|
|
228
|
-
|
|
226
|
+
kA = uc < envLightSelectionPmf;
|
|
227
|
+
if (kA) {
|
|
228
|
+
mH(randomSampleValue.xy, result);
|
|
229
229
|
result.pdf *= envLightSelectionPmf;
|
|
230
230
|
}
|
|
231
231
|
#endif
|
|
232
232
|
|
|
233
233
|
#ifdef NUM_LIGHTS
|
|
234
|
-
if (!
|
|
235
|
-
int
|
|
234
|
+
if (!kA) {
|
|
235
|
+
int lc = NUM_LIGHTS - 1;
|
|
236
236
|
for (int index = 0; index < NUM_LIGHTS; index++) {
|
|
237
|
-
if (
|
|
238
|
-
|
|
237
|
+
if (uc < qx(index).selectionCdf) {
|
|
238
|
+
lc = index;
|
|
239
239
|
break;
|
|
240
240
|
}
|
|
241
241
|
}
|
|
242
|
-
Light
|
|
243
|
-
|
|
244
|
-
|
|
242
|
+
Light qn = qx(lc);
|
|
243
|
+
iQ(
|
|
244
|
+
qn,
|
|
245
245
|
shadingPoint,
|
|
246
246
|
randomSampleValue.xy,
|
|
247
247
|
result
|
|
248
248
|
);
|
|
249
|
-
result.pdf *=
|
|
249
|
+
result.pdf *= qn.selectionPmf;
|
|
250
250
|
}
|
|
251
251
|
#endif
|
|
252
252
|
}
|