three-gpu-pathtracer 0.0.14 → 0.0.16
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/LICENSE +21 -21
- package/README.md +1004 -981
- package/build/index.module.js +7413 -6902
- package/build/index.module.js.map +1 -1
- package/build/index.umd.cjs +7446 -6933
- package/build/index.umd.cjs.map +1 -1
- package/package.json +73 -73
- package/src/core/DynamicPathTracingSceneGenerator.js +119 -119
- package/src/core/MaterialReducer.js +256 -256
- package/src/core/PathTracingRenderer.js +346 -346
- package/src/core/PathTracingSceneGenerator.js +69 -69
- package/src/core/QuiltPathTracingRenderer.js +223 -223
- package/src/detectors/CompatibilityDetector.js +38 -0
- package/src/detectors/MaterialCompileDetector.js +50 -0
- package/src/detectors/PrecisionDetector.js +85 -0
- package/src/detectors/PrecisionMaterial.js +160 -0
- package/src/index.js +40 -36
- package/src/materials/MaterialBase.js +56 -56
- package/src/materials/debug/GraphMaterial.js +243 -243
- package/src/materials/fullscreen/AlphaDisplayMaterial.js +50 -48
- package/src/materials/fullscreen/BlendMaterial.js +67 -67
- package/src/materials/fullscreen/DenoiseMaterial.js +142 -142
- package/src/materials/fullscreen/GradientMapMaterial.js +82 -0
- package/src/materials/pathtracing/LambertPathTracingMaterial.js +296 -296
- package/src/materials/pathtracing/PhysicalPathTracingMaterial.js +118 -196
- package/src/materials/pathtracing/glsl/attenuateHit.glsl.js +177 -179
- package/src/materials/pathtracing/glsl/cameraUtils.glsl.js +84 -81
- package/src/materials/pathtracing/glsl/directLightContribution.glsl.js +93 -0
- package/src/materials/pathtracing/glsl/getSurfaceRecord.glsl.js +323 -317
- package/src/materials/pathtracing/glsl/renderStructs.glsl.js +50 -0
- package/src/materials/pathtracing/glsl/traceScene.glsl.js +52 -54
- package/src/materials/surface/AmbientOcclusionMaterial.js +207 -207
- package/src/materials/surface/FogVolumeMaterial.js +23 -23
- package/src/objects/EquirectCamera.js +13 -13
- package/src/objects/PhysicalCamera.js +42 -28
- package/src/objects/PhysicalSpotLight.js +25 -14
- package/src/objects/ShapedAreaLight.js +22 -12
- package/src/shader/bsdf/bsdfSampling.glsl.js +499 -490
- package/src/shader/bsdf/fog.glsl.js +22 -23
- package/src/shader/bsdf/ggx.glsl.js +102 -102
- package/src/shader/bsdf/iridescence.glsl.js +135 -135
- package/src/shader/bsdf/sheen.glsl.js +98 -98
- package/src/shader/common/arraySamplerTexelFetch.glsl.js +25 -25
- package/src/shader/common/bvhAnyHit.glsl.js +76 -76
- package/src/shader/common/fresnel.glsl.js +98 -98
- package/src/shader/common/intersectShapes.glsl.js +62 -62
- package/src/shader/common/math.glsl.js +81 -81
- package/src/shader/common/utils.glsl.js +116 -116
- package/src/shader/rand/pcg.glsl.js +57 -57
- package/src/shader/rand/sobol.glsl.js +256 -256
- package/src/shader/sampling/equirectSampling.glsl.js +62 -62
- package/src/shader/sampling/lightSampling.glsl.js +223 -223
- package/src/shader/sampling/shapeSampling.glsl.js +86 -86
- package/src/shader/structs/cameraStruct.glsl.js +13 -13
- package/src/shader/structs/equirectStruct.glsl.js +13 -14
- package/src/shader/structs/fogMaterialBvh.glsl.js +62 -62
- package/src/shader/structs/lightsStruct.glsl.js +78 -78
- package/src/shader/structs/materialStruct.glsl.js +207 -207
- package/src/textures/GradientEquirectTexture.js +35 -35
- package/src/textures/ProceduralEquirectTexture.js +75 -75
- package/src/uniforms/AttributesTextureArray.js +35 -35
- package/src/uniforms/EquirectHdrInfoUniform.js +269 -277
- package/src/uniforms/FloatAttributeTextureArray.js +169 -169
- package/src/uniforms/IESProfilesTexture.js +100 -100
- package/src/uniforms/LightsInfoUniformStruct.js +212 -212
- package/src/uniforms/MaterialsTexture.js +503 -503
- package/src/uniforms/PhysicalCameraUniform.js +36 -36
- package/src/uniforms/RenderTarget2DArray.js +97 -97
- package/src/uniforms/utils.js +30 -30
- package/src/utils/BlurredEnvMapGenerator.js +116 -116
- package/src/utils/GeometryPreparationUtils.js +214 -214
- package/src/utils/IESLoader.js +325 -325
- package/src/utils/SobolNumberMapGenerator.js +80 -80
- package/src/utils/UVUnwrapper.js +101 -101
- package/src/utils/macroify.js +9 -9
- package/src/workers/PathTracingSceneWorker.js +42 -42
|
@@ -1,317 +1,323 @@
|
|
|
1
|
-
|
|
2
|
-
export const getSurfaceRecordGLSL = /* glsl */`
|
|
3
|
-
|
|
4
|
-
#define SKIP_SURFACE 0
|
|
5
|
-
#define HIT_SURFACE 1
|
|
6
|
-
int getSurfaceRecord(
|
|
7
|
-
Material material, sampler2DArray attributesArray,
|
|
8
|
-
float
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
fogSurface.
|
|
19
|
-
fogSurface.
|
|
20
|
-
fogSurface.
|
|
21
|
-
fogSurface.
|
|
22
|
-
fogSurface.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
//
|
|
56
|
-
//
|
|
57
|
-
// -
|
|
58
|
-
//
|
|
59
|
-
//
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
//
|
|
126
|
-
//
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
//
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
vec3
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
vec3
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
//
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
vec3
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
vec3
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
surf.
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
surf.
|
|
272
|
-
surf.
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
surf.
|
|
276
|
-
surf.
|
|
277
|
-
surf.
|
|
278
|
-
surf.
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
surf.
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
surf.
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
surf.
|
|
288
|
-
surf.
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
surf.
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
//
|
|
295
|
-
//
|
|
296
|
-
|
|
297
|
-
surf.
|
|
298
|
-
surf.
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
//
|
|
302
|
-
|
|
303
|
-
surf.
|
|
304
|
-
surf.
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
//
|
|
308
|
-
//
|
|
309
|
-
//
|
|
310
|
-
|
|
311
|
-
surf.
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
1
|
+
|
|
2
|
+
export const getSurfaceRecordGLSL = /* glsl */`
|
|
3
|
+
|
|
4
|
+
#define SKIP_SURFACE 0
|
|
5
|
+
#define HIT_SURFACE 1
|
|
6
|
+
int getSurfaceRecord(
|
|
7
|
+
Material material, SurfaceHit surfaceHit, sampler2DArray attributesArray,
|
|
8
|
+
float accumulatedRoughness,
|
|
9
|
+
out SurfaceRecord surf
|
|
10
|
+
) {
|
|
11
|
+
|
|
12
|
+
if ( material.fogVolume ) {
|
|
13
|
+
|
|
14
|
+
vec3 normal = vec3( 0, 0, 1 );
|
|
15
|
+
|
|
16
|
+
SurfaceRecord fogSurface;
|
|
17
|
+
fogSurface.volumeParticle = true;
|
|
18
|
+
fogSurface.color = material.color;
|
|
19
|
+
fogSurface.emission = material.emissiveIntensity * material.emissive;
|
|
20
|
+
fogSurface.normal = normal;
|
|
21
|
+
fogSurface.faceNormal = normal;
|
|
22
|
+
fogSurface.clearcoatNormal = normal;
|
|
23
|
+
|
|
24
|
+
surf = fogSurface;
|
|
25
|
+
return HIT_SURFACE;
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// uv coord for textures
|
|
30
|
+
vec2 uv = textureSampleBarycoord( attributesArray, ATTR_UV, surfaceHit.barycoord, surfaceHit.faceIndices.xyz ).xy;
|
|
31
|
+
vec4 vertexColor = textureSampleBarycoord( attributesArray, ATTR_COLOR, surfaceHit.barycoord, surfaceHit.faceIndices.xyz );
|
|
32
|
+
|
|
33
|
+
// albedo
|
|
34
|
+
vec4 albedo = vec4( material.color, material.opacity );
|
|
35
|
+
if ( material.map != - 1 ) {
|
|
36
|
+
|
|
37
|
+
vec3 uvPrime = material.mapTransform * vec3( uv, 1 );
|
|
38
|
+
albedo *= texture2D( textures, vec3( uvPrime.xy, material.map ) );
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if ( material.vertexColors ) {
|
|
42
|
+
|
|
43
|
+
albedo *= vertexColor;
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// alphaMap
|
|
48
|
+
if ( material.alphaMap != - 1 ) {
|
|
49
|
+
|
|
50
|
+
albedo.a *= texture2D( textures, vec3( uv, material.alphaMap ) ).x;
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// possibly skip this sample if it's transparent, alpha test is enabled, or we hit the wrong material side
|
|
55
|
+
// and it's single sided.
|
|
56
|
+
// - alpha test is disabled when it === 0
|
|
57
|
+
// - the material sidedness test is complicated because we want light to pass through the back side but still
|
|
58
|
+
// be able to see the front side. This boolean checks if the side we hit is the front side on the first ray
|
|
59
|
+
// and we're rendering the other then we skip it. Do the opposite on subsequent bounces to get incoming light.
|
|
60
|
+
float alphaTest = material.alphaTest;
|
|
61
|
+
bool useAlphaTest = alphaTest != 0.0;
|
|
62
|
+
if (
|
|
63
|
+
// material sidedness
|
|
64
|
+
material.side != 0.0 && surfaceHit.side != material.side
|
|
65
|
+
|
|
66
|
+
// alpha test
|
|
67
|
+
|| useAlphaTest && albedo.a < alphaTest
|
|
68
|
+
|
|
69
|
+
// opacity
|
|
70
|
+
|| material.transparent && ! useAlphaTest && albedo.a < sobol( 3 )
|
|
71
|
+
) {
|
|
72
|
+
|
|
73
|
+
return SKIP_SURFACE;
|
|
74
|
+
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// fetch the interpolated smooth normal
|
|
78
|
+
vec3 normal = normalize( textureSampleBarycoord(
|
|
79
|
+
attributesArray,
|
|
80
|
+
ATTR_NORMAL,
|
|
81
|
+
surfaceHit.barycoord,
|
|
82
|
+
surfaceHit.faceIndices.xyz
|
|
83
|
+
).xyz );
|
|
84
|
+
|
|
85
|
+
// roughness
|
|
86
|
+
float roughness = material.roughness;
|
|
87
|
+
if ( material.roughnessMap != - 1 ) {
|
|
88
|
+
|
|
89
|
+
vec3 uvPrime = material.roughnessMapTransform * vec3( uv, 1 );
|
|
90
|
+
roughness *= texture2D( textures, vec3( uvPrime.xy, material.roughnessMap ) ).g;
|
|
91
|
+
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// metalness
|
|
95
|
+
float metalness = material.metalness;
|
|
96
|
+
if ( material.metalnessMap != - 1 ) {
|
|
97
|
+
|
|
98
|
+
vec3 uvPrime = material.metalnessMapTransform * vec3( uv, 1 );
|
|
99
|
+
metalness *= texture2D( textures, vec3( uvPrime.xy, material.metalnessMap ) ).b;
|
|
100
|
+
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// emission
|
|
104
|
+
vec3 emission = material.emissiveIntensity * material.emissive;
|
|
105
|
+
if ( material.emissiveMap != - 1 ) {
|
|
106
|
+
|
|
107
|
+
vec3 uvPrime = material.emissiveMapTransform * vec3( uv, 1 );
|
|
108
|
+
emission *= texture2D( textures, vec3( uvPrime.xy, material.emissiveMap ) ).xyz;
|
|
109
|
+
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// transmission
|
|
113
|
+
float transmission = material.transmission;
|
|
114
|
+
if ( material.transmissionMap != - 1 ) {
|
|
115
|
+
|
|
116
|
+
vec3 uvPrime = material.transmissionMapTransform * vec3( uv, 1 );
|
|
117
|
+
transmission *= texture2D( textures, vec3( uvPrime.xy, material.transmissionMap ) ).r;
|
|
118
|
+
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// normal
|
|
122
|
+
if ( material.flatShading ) {
|
|
123
|
+
|
|
124
|
+
// if we're rendering a flat shaded object then use the face normals - the face normal
|
|
125
|
+
// is provided based on the side the ray hits the mesh so flip it to align with the
|
|
126
|
+
// interpolated vertex normals.
|
|
127
|
+
normal = surfaceHit.faceNormal * surfaceHit.side;
|
|
128
|
+
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
vec3 baseNormal = normal;
|
|
132
|
+
if ( material.normalMap != - 1 ) {
|
|
133
|
+
|
|
134
|
+
vec4 tangentSample = textureSampleBarycoord(
|
|
135
|
+
attributesArray,
|
|
136
|
+
ATTR_TANGENT,
|
|
137
|
+
surfaceHit.barycoord,
|
|
138
|
+
surfaceHit.faceIndices.xyz
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
// some provided tangents can be malformed (0, 0, 0) causing the normal to be degenerate
|
|
142
|
+
// resulting in NaNs and slow path tracing.
|
|
143
|
+
if ( length( tangentSample.xyz ) > 0.0 ) {
|
|
144
|
+
|
|
145
|
+
vec3 tangent = normalize( tangentSample.xyz );
|
|
146
|
+
vec3 bitangent = normalize( cross( normal, tangent ) * tangentSample.w );
|
|
147
|
+
mat3 vTBN = mat3( tangent, bitangent, normal );
|
|
148
|
+
|
|
149
|
+
vec3 uvPrime = material.normalMapTransform * vec3( uv, 1 );
|
|
150
|
+
vec3 texNormal = texture2D( textures, vec3( uvPrime.xy, material.normalMap ) ).xyz * 2.0 - 1.0;
|
|
151
|
+
texNormal.xy *= material.normalScale;
|
|
152
|
+
normal = vTBN * texNormal;
|
|
153
|
+
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
normal *= surfaceHit.side;
|
|
159
|
+
|
|
160
|
+
// clearcoat
|
|
161
|
+
float clearcoat = material.clearcoat;
|
|
162
|
+
if ( material.clearcoatMap != - 1 ) {
|
|
163
|
+
|
|
164
|
+
vec3 uvPrime = material.clearcoatMapTransform * vec3( uv, 1 );
|
|
165
|
+
clearcoat *= texture2D( textures, vec3( uvPrime.xy, material.clearcoatMap ) ).r;
|
|
166
|
+
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// clearcoatRoughness
|
|
170
|
+
float clearcoatRoughness = material.clearcoatRoughness;
|
|
171
|
+
if ( material.clearcoatRoughnessMap != - 1 ) {
|
|
172
|
+
|
|
173
|
+
vec3 uvPrime = material.clearcoatRoughnessMapTransform * vec3( uv, 1 );
|
|
174
|
+
clearcoatRoughness *= texture2D( textures, vec3( uvPrime.xy, material.clearcoatRoughnessMap ) ).g;
|
|
175
|
+
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// clearcoatNormal
|
|
179
|
+
vec3 clearcoatNormal = baseNormal;
|
|
180
|
+
if ( material.clearcoatNormalMap != - 1 ) {
|
|
181
|
+
|
|
182
|
+
vec4 tangentSample = textureSampleBarycoord(
|
|
183
|
+
attributesArray,
|
|
184
|
+
ATTR_TANGENT,
|
|
185
|
+
surfaceHit.barycoord,
|
|
186
|
+
surfaceHit.faceIndices.xyz
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
// some provided tangents can be malformed (0, 0, 0) causing the normal to be degenerate
|
|
190
|
+
// resulting in NaNs and slow path tracing.
|
|
191
|
+
if ( length( tangentSample.xyz ) > 0.0 ) {
|
|
192
|
+
|
|
193
|
+
vec3 tangent = normalize( tangentSample.xyz );
|
|
194
|
+
vec3 bitangent = normalize( cross( clearcoatNormal, tangent ) * tangentSample.w );
|
|
195
|
+
mat3 vTBN = mat3( tangent, bitangent, clearcoatNormal );
|
|
196
|
+
|
|
197
|
+
vec3 uvPrime = material.clearcoatNormalMapTransform * vec3( uv, 1 );
|
|
198
|
+
vec3 texNormal = texture2D( textures, vec3( uvPrime.xy, material.clearcoatNormalMap ) ).xyz * 2.0 - 1.0;
|
|
199
|
+
texNormal.xy *= material.clearcoatNormalScale;
|
|
200
|
+
clearcoatNormal = vTBN * texNormal;
|
|
201
|
+
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
clearcoatNormal *= surfaceHit.side;
|
|
207
|
+
|
|
208
|
+
// sheenColor
|
|
209
|
+
vec3 sheenColor = material.sheenColor;
|
|
210
|
+
if ( material.sheenColorMap != - 1 ) {
|
|
211
|
+
|
|
212
|
+
vec3 uvPrime = material.sheenColorMapTransform * vec3( uv, 1 );
|
|
213
|
+
sheenColor *= texture2D( textures, vec3( uvPrime.xy, material.sheenColorMap ) ).rgb;
|
|
214
|
+
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// sheenRoughness
|
|
218
|
+
float sheenRoughness = material.sheenRoughness;
|
|
219
|
+
if ( material.sheenRoughnessMap != - 1 ) {
|
|
220
|
+
|
|
221
|
+
vec3 uvPrime = material.sheenRoughnessMapTransform * vec3( uv, 1 );
|
|
222
|
+
sheenRoughness *= texture2D( textures, vec3( uvPrime.xy, material.sheenRoughnessMap ) ).a;
|
|
223
|
+
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// iridescence
|
|
227
|
+
float iridescence = material.iridescence;
|
|
228
|
+
if ( material.iridescenceMap != - 1 ) {
|
|
229
|
+
|
|
230
|
+
vec3 uvPrime = material.iridescenceMapTransform * vec3( uv, 1 );
|
|
231
|
+
iridescence *= texture2D( textures, vec3( uvPrime.xy, material.iridescenceMap ) ).r;
|
|
232
|
+
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// iridescence thickness
|
|
236
|
+
float iridescenceThickness = material.iridescenceThicknessMaximum;
|
|
237
|
+
if ( material.iridescenceThicknessMap != - 1 ) {
|
|
238
|
+
|
|
239
|
+
vec3 uvPrime = material.iridescenceThicknessMapTransform * vec3( uv, 1 );
|
|
240
|
+
float iridescenceThicknessSampled = texture2D( textures, vec3( uvPrime.xy, material.iridescenceThicknessMap ) ).g;
|
|
241
|
+
iridescenceThickness = mix( material.iridescenceThicknessMinimum, material.iridescenceThicknessMaximum, iridescenceThicknessSampled );
|
|
242
|
+
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
iridescence = iridescenceThickness == 0.0 ? 0.0 : iridescence;
|
|
246
|
+
|
|
247
|
+
// specular color
|
|
248
|
+
vec3 specularColor = material.specularColor;
|
|
249
|
+
if ( material.specularColorMap != - 1 ) {
|
|
250
|
+
|
|
251
|
+
vec3 uvPrime = material.specularColorMapTransform * vec3( uv, 1 );
|
|
252
|
+
specularColor *= texture2D( textures, vec3( uvPrime.xy, material.specularColorMap ) ).rgb;
|
|
253
|
+
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// specular intensity
|
|
257
|
+
float specularIntensity = material.specularIntensity;
|
|
258
|
+
if ( material.specularIntensityMap != - 1 ) {
|
|
259
|
+
|
|
260
|
+
vec3 uvPrime = material.specularIntensityMapTransform * vec3( uv, 1 );
|
|
261
|
+
specularIntensity *= texture2D( textures, vec3( uvPrime.xy, material.specularIntensityMap ) ).a;
|
|
262
|
+
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
surf.volumeParticle = false;
|
|
266
|
+
|
|
267
|
+
surf.faceNormal = surfaceHit.faceNormal;
|
|
268
|
+
surf.normal = normal;
|
|
269
|
+
|
|
270
|
+
surf.metalness = metalness;
|
|
271
|
+
surf.color = albedo.rgb;
|
|
272
|
+
surf.emission = emission;
|
|
273
|
+
|
|
274
|
+
surf.ior = material.ior;
|
|
275
|
+
surf.transmission = transmission;
|
|
276
|
+
surf.thinFilm = material.thinFilm;
|
|
277
|
+
surf.attenuationColor = material.attenuationColor;
|
|
278
|
+
surf.attenuationDistance = material.attenuationDistance;
|
|
279
|
+
|
|
280
|
+
surf.clearcoatNormal = clearcoatNormal;
|
|
281
|
+
surf.clearcoat = clearcoat;
|
|
282
|
+
|
|
283
|
+
surf.sheen = material.sheen;
|
|
284
|
+
surf.sheenColor = sheenColor;
|
|
285
|
+
|
|
286
|
+
surf.iridescence = iridescence;
|
|
287
|
+
surf.iridescenceIor = material.iridescenceIor;
|
|
288
|
+
surf.iridescenceThickness = iridescenceThickness;
|
|
289
|
+
|
|
290
|
+
surf.specularColor = specularColor;
|
|
291
|
+
surf.specularIntensity = specularIntensity;
|
|
292
|
+
|
|
293
|
+
// apply perceptual roughness factor from gltf. sheen perceptual roughness is
|
|
294
|
+
// applied by its brdf function
|
|
295
|
+
// https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#microfacet-surfaces
|
|
296
|
+
surf.roughness = roughness * roughness;
|
|
297
|
+
surf.clearcoatRoughness = clearcoatRoughness * clearcoatRoughness;
|
|
298
|
+
surf.sheenRoughness = sheenRoughness;
|
|
299
|
+
|
|
300
|
+
// frontFace is used to determine transmissive properties and PDF. If no transmission is used
|
|
301
|
+
// then we can just always assume this is a front face.
|
|
302
|
+
surf.frontFace = surfaceHit.side == 1.0 || transmission == 0.0;
|
|
303
|
+
surf.eta = material.thinFilm || surf.frontFace ? 1.0 / material.ior : material.ior;
|
|
304
|
+
surf.f0 = iorRatioToF0( surf.eta );
|
|
305
|
+
|
|
306
|
+
// Compute the filtered roughness value to use during specular reflection computations.
|
|
307
|
+
// The accumulated roughness value is scaled by a user setting and a "magic value" of 5.0.
|
|
308
|
+
// If we're exiting something transmissive then scale the factor down significantly so we can retain
|
|
309
|
+
// sharp internal reflections
|
|
310
|
+
surf.filteredRoughness = applyFilteredGlossy( surf.roughness, accumulatedRoughness );
|
|
311
|
+
surf.filteredClearcoatRoughness = applyFilteredGlossy( surf.clearcoatRoughness, accumulatedRoughness );
|
|
312
|
+
|
|
313
|
+
// get the normal frames
|
|
314
|
+
surf.normalBasis = getBasisFromNormal( surf.normal );
|
|
315
|
+
surf.normalInvBasis = inverse( surf.normalBasis );
|
|
316
|
+
|
|
317
|
+
surf.clearcoatBasis = getBasisFromNormal( surf.clearcoatNormal );
|
|
318
|
+
surf.clearcoatInvBasis = inverse( surf.clearcoatBasis );
|
|
319
|
+
|
|
320
|
+
return HIT_SURFACE;
|
|
321
|
+
|
|
322
|
+
}
|
|
323
|
+
`;
|