@meimu/mutracer 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/bvh.worker.js +1 -1
- package/dist/mutracer.umd.js +4155 -4052
- package/docs/api.md +13 -10
- package/docs/materials.md +17 -26
- package/docs/threejs.md +35 -9
- package/docs/viewer.md +36 -3
- 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 +17 -9
- 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 +8 -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 +323 -315
- package/lib/renderer/glsl/chunks/intersect.glsl.js.map +1 -1
- package/lib/renderer/glsl/chunks/materialBuffer.glsl.js +154 -121
- package/lib/renderer/glsl/chunks/materialBuffer.glsl.js.map +1 -1
- package/lib/renderer/glsl/chunks/openPbrBsdf.glsl.js +434 -434
- package/lib/renderer/glsl/chunks/openPbrBsdf.glsl.js.map +1 -1
- 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 +42 -41
- 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 +84 -84
- package/lib/renderer/glsl/chunks/sampleMaterial.glsl.js.map +1 -1
- 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 +476 -470
- 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 +95 -60
- 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/OpenPBRMaterial.d.ts +1 -1
- package/lib/scene/OpenPBRMaterial.js +1 -1
- package/lib/scene/OpenPBRMaterial.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
|
@@ -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 nR = light.position - shadingPoint;
|
|
11
|
+
float aj = length(nR);
|
|
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 = nR / 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 = nR / 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, nR);
|
|
61
|
+
float ej = jf * jf
|
|
62
|
+
- dot(nR, nR) + 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 gg = dot(normal, shadingPoint - light.position);
|
|
105
|
+
vec3 surfacePoint = shadingPoint - normal * gg;
|
|
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 (gg <= 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 = gg;
|
|
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 ga = dot(-result.direction, normal);
|
|
138
|
+
float oN = cos(0.5 * PI * spread);
|
|
139
|
+
if (ga <= 0.0 || ga < oN) {
|
|
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 * ga, 1e-8);
|
|
146
|
+
da(light, surfacePoint, lowerLeft, result);
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
-
void
|
|
149
|
+
void gd(
|
|
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
|
+
gd(light, shadingPoint, result);
|
|
204
204
|
}
|
|
205
205
|
#endif
|
|
206
206
|
}
|
|
207
207
|
#endif
|
|
208
208
|
|
|
209
|
-
void
|
|
209
|
+
void mG(in vec2 samplePoint, inout LightSampleRec result) {
|
|
210
210
|
vec2 uv;
|
|
211
|
-
result.direction =
|
|
211
|
+
result.direction = oL(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
|
+
mG(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
|
}
|
|
@@ -2,33 +2,33 @@
|
|
|
2
2
|
// http://www.pbr-book.org/3ed-2018/Light_Transport_I_Surface_Reflection/Direct_Lighting.html#EstimatingtheDirectLightingIntegral
|
|
3
3
|
import { glsl } from '../../shader.js';
|
|
4
4
|
export default glsl `
|
|
5
|
-
vec3
|
|
6
|
-
float
|
|
7
|
-
vec3
|
|
5
|
+
vec3 mT(ad si, J mat, ag prepared, inout Path aa, vec3 ffnormal, bool gF) {
|
|
6
|
+
float mC = 1.0;
|
|
7
|
+
vec3 ln = vec3(fp(cw(LIGHT_POSITION)), dz(cw(LIGHT_SELECT)));
|
|
8
8
|
|
|
9
9
|
LightSampleRec lightSample;
|
|
10
|
-
sampleLight(si.position,
|
|
10
|
+
sampleLight(si.position, ln, lightSample, false);
|
|
11
11
|
lightSample.emission = ai(lightSample.emission, bf);
|
|
12
12
|
|
|
13
13
|
vec3 lightDir = lightSample.direction;
|
|
14
|
-
vec3
|
|
15
|
-
float
|
|
14
|
+
vec3 oS = -aa.ray.d;
|
|
15
|
+
float fg = lightSample.pdf;
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
float cosThetaL = dot(ffnormal, lightDir);
|
|
21
|
-
#ifdef
|
|
22
|
-
if (
|
|
21
|
+
#ifdef USE_COAT_NORMAL_FRAMES
|
|
22
|
+
if (gF && mat.coatNormalEnabled) { cosThetaL = dot(mat.geometricNormal, lightDir); }
|
|
23
23
|
#endif
|
|
24
24
|
|
|
25
|
-
if (
|
|
25
|
+
if (fg <= 0.0 || max(max(lightSample.emission.x, lightSample.emission.y), lightSample.emission.z) <= 0.0) {
|
|
26
26
|
return vec3(0.0);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
float scatteringPdf = 0.0;
|
|
30
30
|
vec3 f = vec3(0.0);
|
|
31
|
-
if (
|
|
31
|
+
if (gF) {
|
|
32
32
|
if (cosThetaL <= 0.0 && mat.transmissionWeight <= 0.0 && mat.subsurfaceWeight <= 0.0) {
|
|
33
33
|
return vec3(0.0);
|
|
34
34
|
}
|
|
@@ -36,7 +36,7 @@ f = bI(prepared, lightDir, scatteringPdf);
|
|
|
36
36
|
}
|
|
37
37
|
else {
|
|
38
38
|
scatteringPdf = bD(
|
|
39
|
-
dot(
|
|
39
|
+
dot(oS, lightDir),
|
|
40
40
|
si.mediumAnisotropy
|
|
41
41
|
);
|
|
42
42
|
f = vec3(scatteringPdf);
|
|
@@ -46,97 +46,97 @@ if (scatteringPdf <= 0.0 || max(max(f.x, f.y), f.z) <= 0.0) {
|
|
|
46
46
|
return vec3(0.0);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
Ray
|
|
50
|
-
vec3
|
|
51
|
-
if (
|
|
49
|
+
Ray mz;
|
|
50
|
+
vec3 hi = si.position + EPS * lightDir;
|
|
51
|
+
if (gF) {
|
|
52
52
|
const float bZ = 0.1;
|
|
53
53
|
float dr = dot(si.normal, lightDir);
|
|
54
|
-
#ifdef
|
|
54
|
+
#ifdef USE_COAT_NORMAL_FRAMES
|
|
55
55
|
if (mat.coatNormalEnabled) { dr = dot(si.faceNormal, lightDir); }
|
|
56
56
|
#endif
|
|
57
57
|
vec3 geometricNormal = dr < 0.0 ? -si.faceNormal : si.faceNormal;
|
|
58
58
|
dr = abs(dr);
|
|
59
|
-
float
|
|
60
|
-
float
|
|
59
|
+
float hS = dot(geometricNormal, lightDir);
|
|
60
|
+
float oB = dr < bZ
|
|
61
61
|
? clamp(
|
|
62
|
-
2.0 - (
|
|
62
|
+
2.0 - (hS + dr) / bZ,
|
|
63
63
|
0.0,
|
|
64
64
|
1.0
|
|
65
65
|
)
|
|
66
|
-
: clamp(1.0 -
|
|
67
|
-
|
|
66
|
+
: clamp(1.0 - hS / bZ, 0.0, 1.0);
|
|
67
|
+
hi += si.shadowOffset * oB;
|
|
68
68
|
}
|
|
69
|
-
|
|
70
|
-
if (ex(
|
|
69
|
+
iC(mz, hi, lightDir);
|
|
70
|
+
if (ex(mz, lightSample.dist - EPS, si.triangleIndex)) {
|
|
71
71
|
return vec3(0.0);
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
#ifdef USE_ENVMAP
|
|
75
75
|
|
|
76
76
|
|
|
77
|
-
if (
|
|
78
|
-
vec4 background = cx(
|
|
77
|
+
if (gF && cosThetaL < 0.0 && ln.z < envLightSelectionPmf) {
|
|
78
|
+
vec4 background = cx(mz.o, lightDir);
|
|
79
79
|
lightSample.emission = ai(background.rgb * background.a, bf);
|
|
80
80
|
}
|
|
81
81
|
#endif
|
|
82
82
|
|
|
83
83
|
|
|
84
84
|
|
|
85
|
-
float
|
|
85
|
+
float fa = lightSample.isDelta
|
|
86
86
|
? 1.0
|
|
87
|
-
: aG(
|
|
88
|
-
return
|
|
89
|
-
?
|
|
87
|
+
: aG(fg, scatteringPdf);
|
|
88
|
+
return fa > 0.0
|
|
89
|
+
? fa * lightSample.emission * f / fg
|
|
90
90
|
: vec3(0.0);
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
#ifdef
|
|
94
|
-
vec3
|
|
95
|
-
bool
|
|
96
|
-
vec3
|
|
97
|
-
vec3
|
|
98
|
-
if (dot(
|
|
99
|
-
return
|
|
93
|
+
#ifdef USE_COAT_NORMAL_FRAMES
|
|
94
|
+
vec3 fF(vec3 pG, vec3 tq, vec3 view) {
|
|
95
|
+
bool qY = dot(tq, view) >= 0.0;
|
|
96
|
+
vec3 uo = qY ? tq : -tq;
|
|
97
|
+
vec3 qX = qY ? pG : -pG;
|
|
98
|
+
if (dot(pG, tq) <= 0.0 || dot(qX, view) <= 1e-6) { return uo; }
|
|
99
|
+
return qX;
|
|
100
100
|
}
|
|
101
101
|
#endif
|
|
102
|
-
void
|
|
103
|
-
vec3
|
|
104
|
-
#ifdef
|
|
102
|
+
void mb(inout ad si, J mat, inout Path aa) {
|
|
103
|
+
vec3 ur = vec3(fp(cw(BSDF_DIRECTION)), dz(cw(BSDF_LOBE)));
|
|
104
|
+
#ifdef USE_COAT_NORMAL_FRAMES
|
|
105
105
|
vec3 bC = si.faceNormal;
|
|
106
|
-
vec3
|
|
106
|
+
vec3 mE = si.normal;
|
|
107
107
|
#endif
|
|
108
|
-
float
|
|
109
|
-
float
|
|
108
|
+
float rN = -dot(si.faceNormal, aa.ray.d);
|
|
109
|
+
float sG = -dot(si.normal, aa.ray.d);
|
|
110
110
|
if ((mat.transmissionWeight > 0.0 || mat.subsurfaceWeight > 0.0) && mat.thinWalled) {
|
|
111
111
|
|
|
112
|
-
if (
|
|
112
|
+
if (rN < 0.0) {
|
|
113
113
|
si.faceNormal = -si.faceNormal;
|
|
114
|
-
|
|
114
|
+
rN = -rN;
|
|
115
115
|
}
|
|
116
|
-
if (
|
|
116
|
+
if (sG < 0.0) {
|
|
117
117
|
si.normal = -si.normal;
|
|
118
|
-
|
|
118
|
+
sG = -sG;
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
|
|
123
|
-
bool
|
|
124
|
-
float ndv =
|
|
125
|
-
vec3 normal =
|
|
123
|
+
bool pU = rN >= 0.0 && sG < 0.0;
|
|
124
|
+
float ndv = pU ? rN : sG;
|
|
125
|
+
vec3 normal = pU ? si.faceNormal : si.normal;
|
|
126
126
|
|
|
127
127
|
mat.inside = ndv <= 0.0 && !mat.thinWalled;
|
|
128
128
|
|
|
129
129
|
mat.relativeIor = ndv > 0.0 ? (1.0 / mat.specularIor) : mat.specularIor;
|
|
130
130
|
vec3 ffnormal = ndv >= 0.0 ? normal : -normal;
|
|
131
|
-
#ifdef
|
|
131
|
+
#ifdef USE_COAT_NORMAL_FRAMES
|
|
132
132
|
if (mat.coatNormalEnabled) {
|
|
133
133
|
vec3 view = -aa.ray.d;
|
|
134
|
-
float
|
|
135
|
-
mat.geometricNormal =
|
|
136
|
-
ffnormal =
|
|
137
|
-
mat.coatNormal =
|
|
138
|
-
mat.inside =
|
|
139
|
-
mat.relativeIor = (
|
|
134
|
+
float gb = dot(bC, view);
|
|
135
|
+
mat.geometricNormal = gb >= 0.0 ? bC : -bC;
|
|
136
|
+
ffnormal = fF(mE, bC, view);
|
|
137
|
+
mat.coatNormal = fF(si.coatNormal, bC, view);
|
|
138
|
+
mat.inside = gb <= 0.0 && !mat.thinWalled;
|
|
139
|
+
mat.relativeIor = (gb > 0.0 || mat.thinWalled) ? 1.0 / mat.specularIor : mat.specularIor;
|
|
140
140
|
}
|
|
141
141
|
#endif
|
|
142
142
|
|
|
@@ -145,47 +145,47 @@ float scatteringPdf;
|
|
|
145
145
|
vec3 cG;
|
|
146
146
|
aa.scatteringIsDelta = false;
|
|
147
147
|
bool bl = false;
|
|
148
|
-
bool
|
|
148
|
+
bool hn = false;
|
|
149
149
|
ag prepared;
|
|
150
150
|
|
|
151
151
|
#ifdef HAS_MEDIUM
|
|
152
152
|
int mediumType = si.mediumType;
|
|
153
153
|
float d = distance(si.position, aa.ray.o);
|
|
154
|
-
vec3
|
|
154
|
+
vec3 nu = aa.ray.o;
|
|
155
155
|
vec3 extinction = si.mediumExtinction;
|
|
156
156
|
vec3 scattering = min(si.mediumScattering, extinction);
|
|
157
|
-
float
|
|
158
|
-
if (mediumType > 0 &&
|
|
157
|
+
float sC = max(max(extinction.x, extinction.y), extinction.z);
|
|
158
|
+
if (mediumType > 0 && sC > 0.0) {
|
|
159
159
|
|
|
160
160
|
|
|
161
161
|
|
|
162
162
|
|
|
163
|
-
int
|
|
164
|
-
float
|
|
165
|
-
float
|
|
166
|
-
? min(-log(max(dz(cw(MEDIUM_DISTANCE)), 1e-7)) /
|
|
163
|
+
int nj = min(int(dz(cw(MEDIUM_CHANNEL)) * 3.0), 2);
|
|
164
|
+
float fE = extinction[nj];
|
|
165
|
+
float ih = fE > 0.0
|
|
166
|
+
? min(-log(max(dz(cw(MEDIUM_DISTANCE)), 1e-7)) / fE, d)
|
|
167
167
|
: d;
|
|
168
|
-
bl =
|
|
169
|
-
vec3 ew = exp(-extinction *
|
|
170
|
-
vec3
|
|
168
|
+
bl = ih < d;
|
|
169
|
+
vec3 ew = exp(-extinction * ih);
|
|
170
|
+
vec3 nZ = bl
|
|
171
171
|
? extinction * ew
|
|
172
172
|
: ew;
|
|
173
|
-
float
|
|
174
|
-
(
|
|
173
|
+
float nK = max(
|
|
174
|
+
(nZ.x + nZ.y + nZ.z) / 3.0,
|
|
175
175
|
1e-8
|
|
176
176
|
);
|
|
177
177
|
if (bl) {
|
|
178
|
-
aa.beta *= ew * scattering /
|
|
178
|
+
aa.beta *= ew * scattering / nK;
|
|
179
179
|
|
|
180
|
-
aa.ray.o =
|
|
180
|
+
aa.ray.o = nu + ih * aa.ray.d;
|
|
181
181
|
si.position = aa.ray.o;
|
|
182
|
-
aa.li +=
|
|
182
|
+
aa.li += mT(si, mat, prepared, aa, ffnormal, false) * aa.beta;
|
|
183
183
|
|
|
184
184
|
|
|
185
|
-
cG =
|
|
185
|
+
cG = fq(
|
|
186
186
|
-aa.ray.d,
|
|
187
187
|
si.mediumAnisotropy,
|
|
188
|
-
|
|
188
|
+
fp(cw(PHASE_DIRECTION))
|
|
189
189
|
);
|
|
190
190
|
scatteringPdf = bD(
|
|
191
191
|
dot(cG, -aa.ray.d),
|
|
@@ -193,7 +193,7 @@ si.mediumAnisotropy
|
|
|
193
193
|
);
|
|
194
194
|
}
|
|
195
195
|
else {
|
|
196
|
-
aa.beta *= ew /
|
|
196
|
+
aa.beta *= ew / nK;
|
|
197
197
|
}
|
|
198
198
|
}
|
|
199
199
|
#endif
|
|
@@ -205,21 +205,21 @@ if (mat.materialType == UNLIT) {
|
|
|
205
205
|
aa.abort = true;
|
|
206
206
|
return;
|
|
207
207
|
}
|
|
208
|
-
vec3
|
|
208
|
+
vec3 pS = vec3(0.0);
|
|
209
209
|
#ifdef USE_TANGENT
|
|
210
|
-
|
|
210
|
+
pS = si.tangent;
|
|
211
211
|
#endif
|
|
212
212
|
mat.directionTangent = si.directionTangent;
|
|
213
213
|
mat.directionBitangent = si.directionBitangent;
|
|
214
214
|
mat.geometryTangent = si.geometryTangent;
|
|
215
215
|
mat.geometryBitangent = si.geometryBitangent;
|
|
216
|
-
prepared =
|
|
217
|
-
aa.li +=
|
|
216
|
+
prepared = eH(pS, mat, -aa.ray.d, ffnormal);
|
|
217
|
+
aa.li += mT(si, mat, prepared, aa, ffnormal, true) * aa.beta;
|
|
218
218
|
|
|
219
219
|
bool isNextRefraction;
|
|
220
220
|
vec3 f = dv(
|
|
221
221
|
prepared,
|
|
222
|
-
|
|
222
|
+
ur,
|
|
223
223
|
cG,
|
|
224
224
|
scatteringPdf,
|
|
225
225
|
isNextRefraction
|
|
@@ -238,19 +238,19 @@ aa.abort = true;
|
|
|
238
238
|
return;
|
|
239
239
|
}
|
|
240
240
|
aa.beta *= f / scatteringPdf;
|
|
241
|
-
|
|
241
|
+
hn = !mat.thinWalled &&
|
|
242
242
|
isNextRefraction;
|
|
243
243
|
aa.isNextRefraction = isNextRefraction;
|
|
244
244
|
|
|
245
245
|
|
|
246
246
|
aa.ray.o = si.position + EPS * cG;
|
|
247
|
-
#ifdef
|
|
247
|
+
#ifdef USE_COAT_NORMAL_FRAMES
|
|
248
248
|
if (mat.coatNormalEnabled) { aa.ray.o = si.position + EPS * (dot(bC, cG) >= 0.0 ? bC : -bC); }
|
|
249
249
|
#endif
|
|
250
250
|
}
|
|
251
251
|
|
|
252
252
|
aa.scatteringPdf = scatteringPdf;
|
|
253
|
-
|
|
253
|
+
iC(aa.ray, aa.ray.o, cG);
|
|
254
254
|
if (bl) {
|
|
255
255
|
aa.isNextRefraction = false;
|
|
256
256
|
}
|
|
@@ -259,8 +259,8 @@ aa.fromEye = false;
|
|
|
259
259
|
#ifdef HAS_MEDIUM
|
|
260
260
|
|
|
261
261
|
|
|
262
|
-
if (!bl &&
|
|
263
|
-
if (
|
|
262
|
+
if (!bl && hn && mat.mediumType > 0) {
|
|
263
|
+
if (rN >= 0.0) {
|
|
264
264
|
si.mediumType = mat.mediumType;
|
|
265
265
|
si.mediumExtinction = mat.mediumExtinction;
|
|
266
266
|
si.mediumScattering = mat.mediumScattering;
|