@luma.gl/shadertools 9.3.0-alpha.6 → 9.3.0-alpha.8
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/dist.dev.js +2550 -330
- package/dist/dist.min.js +1803 -283
- package/dist/index.cjs +2495 -358
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +9 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/preprocessor/preprocessor.d.ts.map +1 -1
- package/dist/lib/preprocessor/preprocessor.js +4 -3
- package/dist/lib/preprocessor/preprocessor.js.map +1 -1
- package/dist/lib/shader-assembler.d.ts +10 -0
- package/dist/lib/shader-assembler.d.ts.map +1 -1
- package/dist/lib/shader-assembler.js +12 -2
- package/dist/lib/shader-assembler.js.map +1 -1
- package/dist/lib/shader-assembly/assemble-shaders.d.ts +23 -2
- package/dist/lib/shader-assembly/assemble-shaders.d.ts.map +1 -1
- package/dist/lib/shader-assembly/assemble-shaders.js +211 -11
- package/dist/lib/shader-assembly/assemble-shaders.js.map +1 -1
- package/dist/lib/shader-assembly/wgsl-binding-debug.d.ts +37 -0
- package/dist/lib/shader-assembly/wgsl-binding-debug.d.ts.map +1 -0
- package/dist/lib/shader-assembly/wgsl-binding-debug.js +140 -0
- package/dist/lib/shader-assembly/wgsl-binding-debug.js.map +1 -0
- package/dist/lib/shader-generator/glsl/generate-glsl.js +3 -0
- package/dist/lib/shader-generator/glsl/generate-glsl.js.map +1 -1
- package/dist/lib/shader-generator/wgsl/generate-wgsl.d.ts.map +1 -1
- package/dist/lib/shader-generator/wgsl/generate-wgsl.js +3 -0
- package/dist/lib/shader-generator/wgsl/generate-wgsl.js.map +1 -1
- package/dist/lib/shader-module/shader-module-uniform-layout.d.ts +22 -0
- package/dist/lib/shader-module/shader-module-uniform-layout.d.ts.map +1 -0
- package/dist/lib/shader-module/shader-module-uniform-layout.js +112 -0
- package/dist/lib/shader-module/shader-module-uniform-layout.js.map +1 -0
- package/dist/lib/shader-module/shader-module.d.ts +11 -5
- package/dist/lib/shader-module/shader-module.d.ts.map +1 -1
- package/dist/lib/shader-module/shader-module.js.map +1 -1
- package/dist/lib/utils/uniform-types.d.ts +11 -7
- package/dist/lib/utils/uniform-types.d.ts.map +1 -1
- package/dist/modules/engine/picking/picking.d.ts +3 -0
- package/dist/modules/engine/picking/picking.d.ts.map +1 -1
- package/dist/modules/engine/picking/picking.js +3 -0
- package/dist/modules/engine/picking/picking.js.map +1 -1
- package/dist/modules/engine/skin/skin.d.ts +7 -6
- package/dist/modules/engine/skin/skin.d.ts.map +1 -1
- package/dist/modules/engine/skin/skin.js +3 -5
- package/dist/modules/engine/skin/skin.js.map +1 -1
- package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts +1 -0
- package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts.map +1 -1
- package/dist/modules/lighting/gouraud-material/gouraud-material.js +3 -0
- package/dist/modules/lighting/gouraud-material/gouraud-material.js.map +1 -1
- package/dist/modules/lighting/ibl/ibl.d.ts +26 -0
- package/dist/modules/lighting/ibl/ibl.d.ts.map +1 -0
- package/dist/modules/lighting/ibl/ibl.js +33 -0
- package/dist/modules/lighting/ibl/ibl.js.map +1 -0
- package/dist/modules/lighting/lambert-material/lambert-material.d.ts +10 -0
- package/dist/modules/lighting/lambert-material/lambert-material.d.ts.map +1 -0
- package/dist/modules/lighting/lambert-material/lambert-material.js +33 -0
- package/dist/modules/lighting/lambert-material/lambert-material.js.map +1 -0
- package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.d.ts +3 -0
- package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.d.ts.map +1 -0
- package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.js +60 -0
- package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.js.map +1 -0
- package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.d.ts +2 -0
- package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.d.ts.map +1 -0
- package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.js +73 -0
- package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.js.map +1 -0
- package/dist/modules/lighting/lights/lighting-glsl.d.ts +1 -1
- package/dist/modules/lighting/lights/lighting-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting-glsl.js +43 -55
- package/dist/modules/lighting/lights/lighting-glsl.js.map +1 -1
- package/dist/modules/lighting/lights/lighting-wgsl.d.ts +1 -1
- package/dist/modules/lighting/lights/lighting-wgsl.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting-wgsl.js +43 -65
- package/dist/modules/lighting/lights/lighting-wgsl.js.map +1 -1
- package/dist/modules/lighting/lights/lighting.d.ts +104 -86
- package/dist/modules/lighting/lights/lighting.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting.js +96 -83
- package/dist/modules/lighting/lights/lighting.js.map +1 -1
- package/dist/modules/lighting/no-material/dirlight.d.ts +7 -2
- package/dist/modules/lighting/no-material/dirlight.d.ts.map +1 -1
- package/dist/modules/lighting/no-material/dirlight.js +3 -1
- package/dist/modules/lighting/no-material/dirlight.js.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-glsl.d.ts +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-glsl.js +524 -28
- package/dist/modules/lighting/pbr-material/pbr-material-glsl.js.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts +2 -2
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js +706 -50
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts +110 -61
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material.js +85 -9
- package/dist/modules/lighting/pbr-material/pbr-material.js.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-projection.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-projection.js +2 -1
- package/dist/modules/lighting/pbr-material/pbr-projection.js.map +1 -1
- package/dist/modules/lighting/phong-material/phong-material.d.ts +1 -0
- package/dist/modules/lighting/phong-material/phong-material.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-material.js +4 -0
- package/dist/modules/lighting/phong-material/phong-material.js.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts +2 -2
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.js +15 -4
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.js.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.js +36 -5
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.js.map +1 -1
- package/dist/modules/math/fp64/fp64-arithmetic-glsl.d.ts +1 -1
- package/dist/modules/math/fp64/fp64-arithmetic-glsl.d.ts.map +1 -1
- package/dist/modules/math/fp64/fp64-arithmetic-glsl.js +41 -10
- package/dist/modules/math/fp64/fp64-arithmetic-glsl.js.map +1 -1
- package/dist/modules/math/fp64/fp64-arithmetic-wgsl.d.ts +2 -0
- package/dist/modules/math/fp64/fp64-arithmetic-wgsl.d.ts.map +1 -0
- package/dist/modules/math/fp64/fp64-arithmetic-wgsl.js +212 -0
- package/dist/modules/math/fp64/fp64-arithmetic-wgsl.js.map +1 -0
- package/dist/modules/math/fp64/fp64.d.ts +1 -0
- package/dist/modules/math/fp64/fp64.d.ts.map +1 -1
- package/dist/modules/math/fp64/fp64.js +8 -2
- package/dist/modules/math/fp64/fp64.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +19 -2
- package/src/lib/preprocessor/preprocessor.ts +6 -3
- package/src/lib/shader-assembler.ts +17 -2
- package/src/lib/shader-assembly/assemble-shaders.ts +377 -12
- package/src/lib/shader-assembly/wgsl-binding-debug.ts +216 -0
- package/src/lib/shader-generator/glsl/generate-glsl.ts +7 -1
- package/src/lib/shader-generator/wgsl/generate-wgsl.ts +6 -0
- package/src/lib/shader-module/shader-module-uniform-layout.ts +194 -0
- package/src/lib/shader-module/shader-module.ts +16 -6
- package/src/lib/utils/uniform-types.ts +24 -9
- package/src/modules/engine/picking/picking.ts +3 -0
- package/src/modules/engine/skin/skin.ts +3 -5
- package/src/modules/lighting/gouraud-material/gouraud-material.ts +4 -0
- package/src/modules/lighting/ibl/ibl.ts +44 -0
- package/src/modules/lighting/lambert-material/lambert-material.ts +42 -0
- package/src/modules/lighting/lambert-material/lambert-shaders-glsl.ts +61 -0
- package/src/modules/lighting/lambert-material/lambert-shaders-wgsl.ts +73 -0
- package/src/modules/lighting/lights/lighting-glsl.ts +43 -55
- package/src/modules/lighting/lights/lighting-wgsl.ts +43 -65
- package/src/modules/lighting/lights/lighting.ts +186 -123
- package/src/modules/lighting/no-material/dirlight.ts +3 -1
- package/src/modules/lighting/pbr-material/pbr-material-glsl.ts +524 -28
- package/src/modules/lighting/pbr-material/pbr-material-wgsl.ts +706 -50
- package/src/modules/lighting/pbr-material/pbr-material.ts +111 -18
- package/src/modules/lighting/pbr-material/pbr-projection.ts +2 -1
- package/src/modules/lighting/phong-material/phong-material.ts +5 -0
- package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +15 -4
- package/src/modules/lighting/phong-material/phong-shaders-wgsl.ts +36 -5
- package/src/modules/math/fp64/fp64-arithmetic-glsl.ts +41 -10
- package/src/modules/math/fp64/fp64-arithmetic-wgsl.ts +212 -0
- package/src/modules/math/fp64/fp64.ts +9 -3
|
@@ -84,10 +84,12 @@ uniform pbrMaterialUniforms {
|
|
|
84
84
|
float clearcoatFactor;
|
|
85
85
|
float clearcoatRoughnessFactor;
|
|
86
86
|
bool clearcoatMapEnabled;
|
|
87
|
+
bool clearcoatRoughnessMapEnabled;
|
|
87
88
|
|
|
88
89
|
vec3 sheenColorFactor;
|
|
89
90
|
float sheenRoughnessFactor;
|
|
90
91
|
bool sheenColorMapEnabled;
|
|
92
|
+
bool sheenRoughnessMapEnabled;
|
|
91
93
|
|
|
92
94
|
float iridescenceFactor;
|
|
93
95
|
float iridescenceIor;
|
|
@@ -137,26 +139,33 @@ uniform sampler2D pbr_specularIntensitySampler;
|
|
|
137
139
|
#ifdef HAS_TRANSMISSIONMAP
|
|
138
140
|
uniform sampler2D pbr_transmissionSampler;
|
|
139
141
|
#endif
|
|
142
|
+
#ifdef HAS_THICKNESSMAP
|
|
143
|
+
uniform sampler2D pbr_thicknessSampler;
|
|
144
|
+
#endif
|
|
140
145
|
#ifdef HAS_CLEARCOATMAP
|
|
141
146
|
uniform sampler2D pbr_clearcoatSampler;
|
|
147
|
+
#endif
|
|
148
|
+
#ifdef HAS_CLEARCOATROUGHNESSMAP
|
|
142
149
|
uniform sampler2D pbr_clearcoatRoughnessSampler;
|
|
143
150
|
#endif
|
|
151
|
+
#ifdef HAS_CLEARCOATNORMALMAP
|
|
152
|
+
uniform sampler2D pbr_clearcoatNormalSampler;
|
|
153
|
+
#endif
|
|
144
154
|
#ifdef HAS_SHEENCOLORMAP
|
|
145
155
|
uniform sampler2D pbr_sheenColorSampler;
|
|
156
|
+
#endif
|
|
157
|
+
#ifdef HAS_SHEENROUGHNESSMAP
|
|
146
158
|
uniform sampler2D pbr_sheenRoughnessSampler;
|
|
147
159
|
#endif
|
|
148
160
|
#ifdef HAS_IRIDESCENCEMAP
|
|
149
161
|
uniform sampler2D pbr_iridescenceSampler;
|
|
150
162
|
#endif
|
|
163
|
+
#ifdef HAS_IRIDESCENCETHICKNESSMAP
|
|
164
|
+
uniform sampler2D pbr_iridescenceThicknessSampler;
|
|
165
|
+
#endif
|
|
151
166
|
#ifdef HAS_ANISOTROPYMAP
|
|
152
167
|
uniform sampler2D pbr_anisotropySampler;
|
|
153
168
|
#endif
|
|
154
|
-
#ifdef USE_IBL
|
|
155
|
-
uniform samplerCube pbr_diffuseEnvSampler;
|
|
156
|
-
uniform samplerCube pbr_specularEnvSampler;
|
|
157
|
-
uniform sampler2D pbr_brdfLUT;
|
|
158
|
-
#endif
|
|
159
|
-
|
|
160
169
|
// Inputs from vertex shader
|
|
161
170
|
|
|
162
171
|
in vec3 pbr_vPosition;
|
|
@@ -193,6 +202,8 @@ struct PBRInfo {
|
|
|
193
202
|
const float M_PI = 3.141592653589793;
|
|
194
203
|
const float c_MinRoughness = 0.04;
|
|
195
204
|
|
|
205
|
+
vec3 calculateFinalColor(PBRInfo pbrInfo, vec3 lightColor);
|
|
206
|
+
|
|
196
207
|
vec4 SRGBtoLINEAR(vec4 srgbIn)
|
|
197
208
|
{
|
|
198
209
|
#ifdef MANUAL_SRGB
|
|
@@ -208,11 +219,9 @@ vec4 SRGBtoLINEAR(vec4 srgbIn)
|
|
|
208
219
|
#endif //MANUAL_SRGB
|
|
209
220
|
}
|
|
210
221
|
|
|
211
|
-
//
|
|
212
|
-
|
|
213
|
-
vec3 getNormal()
|
|
222
|
+
// Build the tangent basis from interpolated attributes or screen-space derivatives.
|
|
223
|
+
mat3 getTBN()
|
|
214
224
|
{
|
|
215
|
-
// Retrieve the tangent space matrix
|
|
216
225
|
#ifndef HAS_TANGENTS
|
|
217
226
|
vec3 pos_dx = dFdx(pbr_vPosition);
|
|
218
227
|
vec3 pos_dy = dFdy(pbr_vPosition);
|
|
@@ -233,9 +242,21 @@ vec3 getNormal()
|
|
|
233
242
|
mat3 tbn = pbr_vTBN;
|
|
234
243
|
#endif
|
|
235
244
|
|
|
245
|
+
return tbn;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// Find the normal for this fragment, pulling either from a predefined normal map
|
|
249
|
+
// or from the interpolated mesh normal and tangent attributes.
|
|
250
|
+
vec3 getMappedNormal(sampler2D normalSampler, mat3 tbn, float normalScale)
|
|
251
|
+
{
|
|
252
|
+
vec3 n = texture(normalSampler, pbr_vUV).rgb;
|
|
253
|
+
return normalize(tbn * ((2.0 * n - 1.0) * vec3(normalScale, normalScale, 1.0)));
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
vec3 getNormal(mat3 tbn)
|
|
257
|
+
{
|
|
236
258
|
#ifdef HAS_NORMALMAP
|
|
237
|
-
vec3 n =
|
|
238
|
-
n = normalize(tbn * ((2.0 * n - 1.0) * vec3(pbrMaterial.normalScale, pbrMaterial.normalScale, 1.0)));
|
|
259
|
+
vec3 n = getMappedNormal(pbr_normalSampler, tbn, pbrMaterial.normalScale);
|
|
239
260
|
#else
|
|
240
261
|
// The tbn matrix is linearly interpolated, so we need to re-normalize
|
|
241
262
|
vec3 n = normalize(tbn[2].xyz);
|
|
@@ -244,6 +265,15 @@ vec3 getNormal()
|
|
|
244
265
|
return n;
|
|
245
266
|
}
|
|
246
267
|
|
|
268
|
+
vec3 getClearcoatNormal(mat3 tbn, vec3 baseNormal)
|
|
269
|
+
{
|
|
270
|
+
#ifdef HAS_CLEARCOATNORMALMAP
|
|
271
|
+
return getMappedNormal(pbr_clearcoatNormalSampler, tbn, 1.0);
|
|
272
|
+
#else
|
|
273
|
+
return baseNormal;
|
|
274
|
+
#endif
|
|
275
|
+
}
|
|
276
|
+
|
|
247
277
|
// Calculation of the lighting contribution from an optional Image Based Light source.
|
|
248
278
|
// Precomputed Environment Maps are required uniform inputs and are computed as outlined in [1].
|
|
249
279
|
// See our README.md on Environment Maps [3] for additional discussion.
|
|
@@ -319,6 +349,169 @@ float microfacetDistribution(PBRInfo pbrInfo)
|
|
|
319
349
|
return roughnessSq / (M_PI * f * f);
|
|
320
350
|
}
|
|
321
351
|
|
|
352
|
+
float maxComponent(vec3 value)
|
|
353
|
+
{
|
|
354
|
+
return max(max(value.r, value.g), value.b);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
float getDielectricF0(float ior)
|
|
358
|
+
{
|
|
359
|
+
float clampedIor = max(ior, 1.0);
|
|
360
|
+
float ratio = (clampedIor - 1.0) / (clampedIor + 1.0);
|
|
361
|
+
return ratio * ratio;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
vec2 normalizeDirection(vec2 direction)
|
|
365
|
+
{
|
|
366
|
+
float directionLength = length(direction);
|
|
367
|
+
return directionLength > 0.0001 ? direction / directionLength : vec2(1.0, 0.0);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
vec2 rotateDirection(vec2 direction, float rotation)
|
|
371
|
+
{
|
|
372
|
+
float s = sin(rotation);
|
|
373
|
+
float c = cos(rotation);
|
|
374
|
+
return vec2(direction.x * c - direction.y * s, direction.x * s + direction.y * c);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
vec3 getIridescenceTint(float iridescence, float thickness, float NdotV)
|
|
378
|
+
{
|
|
379
|
+
if (iridescence <= 0.0) {
|
|
380
|
+
return vec3(1.0);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
float phase = 0.015 * thickness * pbrMaterial.iridescenceIor + (1.0 - NdotV) * 6.0;
|
|
384
|
+
vec3 thinFilmTint =
|
|
385
|
+
0.5 + 0.5 * cos(vec3(phase, phase + 2.0943951, phase + 4.1887902));
|
|
386
|
+
return mix(vec3(1.0), thinFilmTint, iridescence);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
vec3 getVolumeAttenuation(float thickness)
|
|
390
|
+
{
|
|
391
|
+
if (thickness <= 0.0) {
|
|
392
|
+
return vec3(1.0);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
vec3 attenuationCoefficient =
|
|
396
|
+
-log(max(pbrMaterial.attenuationColor, vec3(0.0001))) /
|
|
397
|
+
max(pbrMaterial.attenuationDistance, 0.0001);
|
|
398
|
+
return exp(-attenuationCoefficient * thickness);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
PBRInfo createClearcoatPBRInfo(PBRInfo basePBRInfo, vec3 clearcoatNormal, float clearcoatRoughness)
|
|
402
|
+
{
|
|
403
|
+
float perceptualRoughness = clamp(clearcoatRoughness, c_MinRoughness, 1.0);
|
|
404
|
+
float alphaRoughness = perceptualRoughness * perceptualRoughness;
|
|
405
|
+
float NdotV = clamp(abs(dot(clearcoatNormal, basePBRInfo.v)), 0.001, 1.0);
|
|
406
|
+
|
|
407
|
+
return PBRInfo(
|
|
408
|
+
basePBRInfo.NdotL,
|
|
409
|
+
NdotV,
|
|
410
|
+
basePBRInfo.NdotH,
|
|
411
|
+
basePBRInfo.LdotH,
|
|
412
|
+
basePBRInfo.VdotH,
|
|
413
|
+
perceptualRoughness,
|
|
414
|
+
0.0,
|
|
415
|
+
vec3(0.04),
|
|
416
|
+
vec3(1.0),
|
|
417
|
+
alphaRoughness,
|
|
418
|
+
vec3(0.0),
|
|
419
|
+
vec3(0.04),
|
|
420
|
+
clearcoatNormal,
|
|
421
|
+
basePBRInfo.v
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
vec3 calculateClearcoatContribution(
|
|
426
|
+
PBRInfo pbrInfo,
|
|
427
|
+
vec3 lightColor,
|
|
428
|
+
vec3 clearcoatNormal,
|
|
429
|
+
float clearcoatFactor,
|
|
430
|
+
float clearcoatRoughness
|
|
431
|
+
) {
|
|
432
|
+
if (clearcoatFactor <= 0.0) {
|
|
433
|
+
return vec3(0.0);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
PBRInfo clearcoatPBRInfo = createClearcoatPBRInfo(pbrInfo, clearcoatNormal, clearcoatRoughness);
|
|
437
|
+
return calculateFinalColor(clearcoatPBRInfo, lightColor) * clearcoatFactor;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
#ifdef USE_IBL
|
|
441
|
+
vec3 calculateClearcoatIBLContribution(
|
|
442
|
+
PBRInfo pbrInfo,
|
|
443
|
+
vec3 clearcoatNormal,
|
|
444
|
+
vec3 reflection,
|
|
445
|
+
float clearcoatFactor,
|
|
446
|
+
float clearcoatRoughness
|
|
447
|
+
) {
|
|
448
|
+
if (clearcoatFactor <= 0.0) {
|
|
449
|
+
return vec3(0.0);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
PBRInfo clearcoatPBRInfo = createClearcoatPBRInfo(pbrInfo, clearcoatNormal, clearcoatRoughness);
|
|
453
|
+
return getIBLContribution(clearcoatPBRInfo, clearcoatNormal, reflection) * clearcoatFactor;
|
|
454
|
+
}
|
|
455
|
+
#endif
|
|
456
|
+
|
|
457
|
+
vec3 calculateSheenContribution(
|
|
458
|
+
PBRInfo pbrInfo,
|
|
459
|
+
vec3 lightColor,
|
|
460
|
+
vec3 sheenColor,
|
|
461
|
+
float sheenRoughness
|
|
462
|
+
) {
|
|
463
|
+
if (maxComponent(sheenColor) <= 0.0) {
|
|
464
|
+
return vec3(0.0);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
float sheenFresnel = pow(clamp(1.0 - pbrInfo.VdotH, 0.0, 1.0), 5.0);
|
|
468
|
+
float sheenVisibility = mix(1.0, pbrInfo.NdotL * pbrInfo.NdotV, sheenRoughness);
|
|
469
|
+
return pbrInfo.NdotL *
|
|
470
|
+
lightColor *
|
|
471
|
+
sheenColor *
|
|
472
|
+
(0.25 + 0.75 * sheenFresnel) *
|
|
473
|
+
sheenVisibility *
|
|
474
|
+
(1.0 - pbrInfo.metalness);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
float calculateAnisotropyBoost(
|
|
478
|
+
PBRInfo pbrInfo,
|
|
479
|
+
vec3 anisotropyTangent,
|
|
480
|
+
float anisotropyStrength
|
|
481
|
+
) {
|
|
482
|
+
if (anisotropyStrength <= 0.0) {
|
|
483
|
+
return 1.0;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
vec3 anisotropyBitangent = normalize(cross(pbrInfo.n, anisotropyTangent));
|
|
487
|
+
float bitangentViewAlignment = abs(dot(pbrInfo.v, anisotropyBitangent));
|
|
488
|
+
return mix(1.0, 0.65 + 0.7 * bitangentViewAlignment, anisotropyStrength);
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
vec3 calculateMaterialLightColor(
|
|
492
|
+
PBRInfo pbrInfo,
|
|
493
|
+
vec3 lightColor,
|
|
494
|
+
vec3 clearcoatNormal,
|
|
495
|
+
float clearcoatFactor,
|
|
496
|
+
float clearcoatRoughness,
|
|
497
|
+
vec3 sheenColor,
|
|
498
|
+
float sheenRoughness,
|
|
499
|
+
vec3 anisotropyTangent,
|
|
500
|
+
float anisotropyStrength
|
|
501
|
+
) {
|
|
502
|
+
float anisotropyBoost = calculateAnisotropyBoost(pbrInfo, anisotropyTangent, anisotropyStrength);
|
|
503
|
+
vec3 color = calculateFinalColor(pbrInfo, lightColor) * anisotropyBoost;
|
|
504
|
+
color += calculateClearcoatContribution(
|
|
505
|
+
pbrInfo,
|
|
506
|
+
lightColor,
|
|
507
|
+
clearcoatNormal,
|
|
508
|
+
clearcoatFactor,
|
|
509
|
+
clearcoatRoughness
|
|
510
|
+
);
|
|
511
|
+
color += calculateSheenContribution(pbrInfo, lightColor, sheenColor, sheenRoughness);
|
|
512
|
+
return color;
|
|
513
|
+
}
|
|
514
|
+
|
|
322
515
|
void PBRInfo_setAmbientLight(inout PBRInfo pbrInfo) {
|
|
323
516
|
pbrInfo.NdotL = 1.0;
|
|
324
517
|
pbrInfo.NdotH = 0.0;
|
|
@@ -343,6 +536,11 @@ void PBRInfo_setPointLight(inout PBRInfo pbrInfo, PointLight pointLight) {
|
|
|
343
536
|
PBRInfo_setDirectionalLight(pbrInfo, light_direction);
|
|
344
537
|
}
|
|
345
538
|
|
|
539
|
+
void PBRInfo_setSpotLight(inout PBRInfo pbrInfo, SpotLight spotLight) {
|
|
540
|
+
vec3 light_direction = normalize(spotLight.position - pbr_vPosition);
|
|
541
|
+
PBRInfo_setDirectionalLight(pbrInfo, light_direction);
|
|
542
|
+
}
|
|
543
|
+
|
|
346
544
|
vec3 calculateFinalColor(PBRInfo pbrInfo, vec3 lightColor) {
|
|
347
545
|
// Calculate the shading terms for the microfacet specular shading model
|
|
348
546
|
vec3 F = specularReflection(pbrInfo);
|
|
@@ -373,6 +571,8 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
373
571
|
|
|
374
572
|
vec3 color = vec3(0, 0, 0);
|
|
375
573
|
|
|
574
|
+
float transmission = 0.0;
|
|
575
|
+
|
|
376
576
|
if(pbrMaterial.unlit){
|
|
377
577
|
color.rgb = baseColor.rgb;
|
|
378
578
|
}
|
|
@@ -391,14 +591,252 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
391
591
|
#endif
|
|
392
592
|
perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0);
|
|
393
593
|
metallic = clamp(metallic, 0.0, 1.0);
|
|
594
|
+
mat3 tbn = getTBN();
|
|
595
|
+
vec3 n = getNormal(tbn); // normal at surface point
|
|
596
|
+
vec3 v = normalize(pbrProjection.camera - pbr_vPosition); // Vector from surface point to camera
|
|
597
|
+
float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
|
|
598
|
+
#ifdef USE_MATERIAL_EXTENSIONS
|
|
599
|
+
bool useExtendedPBR =
|
|
600
|
+
pbrMaterial.specularColorMapEnabled ||
|
|
601
|
+
pbrMaterial.specularIntensityMapEnabled ||
|
|
602
|
+
abs(pbrMaterial.specularIntensityFactor - 1.0) > 0.0001 ||
|
|
603
|
+
maxComponent(abs(pbrMaterial.specularColorFactor - vec3(1.0))) > 0.0001 ||
|
|
604
|
+
abs(pbrMaterial.ior - 1.5) > 0.0001 ||
|
|
605
|
+
pbrMaterial.transmissionMapEnabled ||
|
|
606
|
+
pbrMaterial.transmissionFactor > 0.0001 ||
|
|
607
|
+
pbrMaterial.clearcoatMapEnabled ||
|
|
608
|
+
pbrMaterial.clearcoatRoughnessMapEnabled ||
|
|
609
|
+
pbrMaterial.clearcoatFactor > 0.0001 ||
|
|
610
|
+
pbrMaterial.clearcoatRoughnessFactor > 0.0001 ||
|
|
611
|
+
pbrMaterial.sheenColorMapEnabled ||
|
|
612
|
+
pbrMaterial.sheenRoughnessMapEnabled ||
|
|
613
|
+
maxComponent(pbrMaterial.sheenColorFactor) > 0.0001 ||
|
|
614
|
+
pbrMaterial.sheenRoughnessFactor > 0.0001 ||
|
|
615
|
+
pbrMaterial.iridescenceMapEnabled ||
|
|
616
|
+
pbrMaterial.iridescenceFactor > 0.0001 ||
|
|
617
|
+
abs(pbrMaterial.iridescenceIor - 1.3) > 0.0001 ||
|
|
618
|
+
abs(pbrMaterial.iridescenceThicknessRange.x - 100.0) > 0.0001 ||
|
|
619
|
+
abs(pbrMaterial.iridescenceThicknessRange.y - 400.0) > 0.0001 ||
|
|
620
|
+
pbrMaterial.anisotropyMapEnabled ||
|
|
621
|
+
pbrMaterial.anisotropyStrength > 0.0001 ||
|
|
622
|
+
abs(pbrMaterial.anisotropyRotation) > 0.0001 ||
|
|
623
|
+
length(pbrMaterial.anisotropyDirection - vec2(1.0, 0.0)) > 0.0001;
|
|
624
|
+
#else
|
|
625
|
+
bool useExtendedPBR = false;
|
|
626
|
+
#endif
|
|
627
|
+
|
|
628
|
+
if (!useExtendedPBR) {
|
|
629
|
+
// Keep the baseline metallic-roughness implementation byte-for-byte equivalent in behavior.
|
|
630
|
+
float alphaRoughness = perceptualRoughness * perceptualRoughness;
|
|
631
|
+
|
|
632
|
+
vec3 f0 = vec3(0.04);
|
|
633
|
+
vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - f0);
|
|
634
|
+
diffuseColor *= 1.0 - metallic;
|
|
635
|
+
vec3 specularColor = mix(f0, baseColor.rgb, metallic);
|
|
636
|
+
|
|
637
|
+
float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);
|
|
638
|
+
float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);
|
|
639
|
+
vec3 specularEnvironmentR0 = specularColor.rgb;
|
|
640
|
+
vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;
|
|
641
|
+
vec3 reflection = -normalize(reflect(v, n));
|
|
642
|
+
|
|
643
|
+
PBRInfo pbrInfo = PBRInfo(
|
|
644
|
+
0.0, // NdotL
|
|
645
|
+
NdotV,
|
|
646
|
+
0.0, // NdotH
|
|
647
|
+
0.0, // LdotH
|
|
648
|
+
0.0, // VdotH
|
|
649
|
+
perceptualRoughness,
|
|
650
|
+
metallic,
|
|
651
|
+
specularEnvironmentR0,
|
|
652
|
+
specularEnvironmentR90,
|
|
653
|
+
alphaRoughness,
|
|
654
|
+
diffuseColor,
|
|
655
|
+
specularColor,
|
|
656
|
+
n,
|
|
657
|
+
v
|
|
658
|
+
);
|
|
659
|
+
|
|
660
|
+
#ifdef USE_LIGHTS
|
|
661
|
+
PBRInfo_setAmbientLight(pbrInfo);
|
|
662
|
+
color += calculateFinalColor(pbrInfo, lighting.ambientColor);
|
|
663
|
+
|
|
664
|
+
for(int i = 0; i < lighting.directionalLightCount; i++) {
|
|
665
|
+
if (i < lighting.directionalLightCount) {
|
|
666
|
+
PBRInfo_setDirectionalLight(pbrInfo, lighting_getDirectionalLight(i).direction);
|
|
667
|
+
color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
for(int i = 0; i < lighting.pointLightCount; i++) {
|
|
672
|
+
if (i < lighting.pointLightCount) {
|
|
673
|
+
PBRInfo_setPointLight(pbrInfo, lighting_getPointLight(i));
|
|
674
|
+
float attenuation = getPointLightAttenuation(lighting_getPointLight(i), distance(lighting_getPointLight(i).position, pbr_vPosition));
|
|
675
|
+
color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color / attenuation);
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
for(int i = 0; i < lighting.spotLightCount; i++) {
|
|
680
|
+
if (i < lighting.spotLightCount) {
|
|
681
|
+
PBRInfo_setSpotLight(pbrInfo, lighting_getSpotLight(i));
|
|
682
|
+
float attenuation = getSpotLightAttenuation(lighting_getSpotLight(i), pbr_vPosition);
|
|
683
|
+
color += calculateFinalColor(pbrInfo, lighting_getSpotLight(i).color / attenuation);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
#endif
|
|
687
|
+
|
|
688
|
+
#ifdef USE_IBL
|
|
689
|
+
if (pbrMaterial.IBLenabled) {
|
|
690
|
+
color += getIBLContribution(pbrInfo, n, reflection);
|
|
691
|
+
}
|
|
692
|
+
#endif
|
|
693
|
+
|
|
694
|
+
#ifdef HAS_OCCLUSIONMAP
|
|
695
|
+
if (pbrMaterial.occlusionMapEnabled) {
|
|
696
|
+
float ao = texture(pbr_occlusionSampler, pbr_vUV).r;
|
|
697
|
+
color = mix(color, color * ao, pbrMaterial.occlusionStrength);
|
|
698
|
+
}
|
|
699
|
+
#endif
|
|
700
|
+
|
|
701
|
+
vec3 emissive = pbrMaterial.emissiveFactor;
|
|
702
|
+
#ifdef HAS_EMISSIVEMAP
|
|
703
|
+
if (pbrMaterial.emissiveMapEnabled) {
|
|
704
|
+
emissive *= SRGBtoLINEAR(texture(pbr_emissiveSampler, pbr_vUV)).rgb;
|
|
705
|
+
}
|
|
706
|
+
#endif
|
|
707
|
+
color += emissive * pbrMaterial.emissiveStrength;
|
|
708
|
+
|
|
709
|
+
#ifdef PBR_DEBUG
|
|
710
|
+
color = mix(color, baseColor.rgb, pbrMaterial.scaleDiffBaseMR.y);
|
|
711
|
+
color = mix(color, vec3(metallic), pbrMaterial.scaleDiffBaseMR.z);
|
|
712
|
+
color = mix(color, vec3(perceptualRoughness), pbrMaterial.scaleDiffBaseMR.w);
|
|
713
|
+
#endif
|
|
714
|
+
|
|
715
|
+
return vec4(pow(color, vec3(1.0 / 2.2)), baseColor.a);
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
float specularIntensity = pbrMaterial.specularIntensityFactor;
|
|
719
|
+
#ifdef HAS_SPECULARINTENSITYMAP
|
|
720
|
+
if (pbrMaterial.specularIntensityMapEnabled) {
|
|
721
|
+
specularIntensity *= texture(pbr_specularIntensitySampler, pbr_vUV).a;
|
|
722
|
+
}
|
|
723
|
+
#endif
|
|
724
|
+
|
|
725
|
+
vec3 specularFactor = pbrMaterial.specularColorFactor;
|
|
726
|
+
#ifdef HAS_SPECULARCOLORMAP
|
|
727
|
+
if (pbrMaterial.specularColorMapEnabled) {
|
|
728
|
+
specularFactor *= SRGBtoLINEAR(texture(pbr_specularColorSampler, pbr_vUV)).rgb;
|
|
729
|
+
}
|
|
730
|
+
#endif
|
|
731
|
+
|
|
732
|
+
transmission = pbrMaterial.transmissionFactor;
|
|
733
|
+
#ifdef HAS_TRANSMISSIONMAP
|
|
734
|
+
if (pbrMaterial.transmissionMapEnabled) {
|
|
735
|
+
transmission *= texture(pbr_transmissionSampler, pbr_vUV).r;
|
|
736
|
+
}
|
|
737
|
+
#endif
|
|
738
|
+
transmission = clamp(transmission * (1.0 - metallic), 0.0, 1.0);
|
|
739
|
+
float thickness = max(pbrMaterial.thicknessFactor, 0.0);
|
|
740
|
+
#ifdef HAS_THICKNESSMAP
|
|
741
|
+
thickness *= texture(pbr_thicknessSampler, pbr_vUV).g;
|
|
742
|
+
#endif
|
|
743
|
+
|
|
744
|
+
float clearcoatFactor = pbrMaterial.clearcoatFactor;
|
|
745
|
+
float clearcoatRoughness = pbrMaterial.clearcoatRoughnessFactor;
|
|
746
|
+
#ifdef HAS_CLEARCOATMAP
|
|
747
|
+
if (pbrMaterial.clearcoatMapEnabled) {
|
|
748
|
+
clearcoatFactor *= texture(pbr_clearcoatSampler, pbr_vUV).r;
|
|
749
|
+
}
|
|
750
|
+
#endif
|
|
751
|
+
#ifdef HAS_CLEARCOATROUGHNESSMAP
|
|
752
|
+
if (pbrMaterial.clearcoatRoughnessMapEnabled) {
|
|
753
|
+
clearcoatRoughness *= texture(pbr_clearcoatRoughnessSampler, pbr_vUV).g;
|
|
754
|
+
}
|
|
755
|
+
#endif
|
|
756
|
+
clearcoatFactor = clamp(clearcoatFactor, 0.0, 1.0);
|
|
757
|
+
clearcoatRoughness = clamp(clearcoatRoughness, c_MinRoughness, 1.0);
|
|
758
|
+
vec3 clearcoatNormal = getClearcoatNormal(tbn, n);
|
|
759
|
+
|
|
760
|
+
vec3 sheenColor = pbrMaterial.sheenColorFactor;
|
|
761
|
+
float sheenRoughness = pbrMaterial.sheenRoughnessFactor;
|
|
762
|
+
#ifdef HAS_SHEENCOLORMAP
|
|
763
|
+
if (pbrMaterial.sheenColorMapEnabled) {
|
|
764
|
+
sheenColor *= SRGBtoLINEAR(texture(pbr_sheenColorSampler, pbr_vUV)).rgb;
|
|
765
|
+
}
|
|
766
|
+
#endif
|
|
767
|
+
#ifdef HAS_SHEENROUGHNESSMAP
|
|
768
|
+
if (pbrMaterial.sheenRoughnessMapEnabled) {
|
|
769
|
+
sheenRoughness *= texture(pbr_sheenRoughnessSampler, pbr_vUV).a;
|
|
770
|
+
}
|
|
771
|
+
#endif
|
|
772
|
+
sheenRoughness = clamp(sheenRoughness, c_MinRoughness, 1.0);
|
|
773
|
+
|
|
774
|
+
float iridescence = pbrMaterial.iridescenceFactor;
|
|
775
|
+
#ifdef HAS_IRIDESCENCEMAP
|
|
776
|
+
if (pbrMaterial.iridescenceMapEnabled) {
|
|
777
|
+
iridescence *= texture(pbr_iridescenceSampler, pbr_vUV).r;
|
|
778
|
+
}
|
|
779
|
+
#endif
|
|
780
|
+
iridescence = clamp(iridescence, 0.0, 1.0);
|
|
781
|
+
float iridescenceThickness = mix(
|
|
782
|
+
pbrMaterial.iridescenceThicknessRange.x,
|
|
783
|
+
pbrMaterial.iridescenceThicknessRange.y,
|
|
784
|
+
0.5
|
|
785
|
+
);
|
|
786
|
+
#ifdef HAS_IRIDESCENCETHICKNESSMAP
|
|
787
|
+
iridescenceThickness = mix(
|
|
788
|
+
pbrMaterial.iridescenceThicknessRange.x,
|
|
789
|
+
pbrMaterial.iridescenceThicknessRange.y,
|
|
790
|
+
texture(pbr_iridescenceThicknessSampler, pbr_vUV).g
|
|
791
|
+
);
|
|
792
|
+
#endif
|
|
793
|
+
|
|
794
|
+
float anisotropyStrength = clamp(pbrMaterial.anisotropyStrength, 0.0, 1.0);
|
|
795
|
+
vec2 anisotropyDirection = normalizeDirection(pbrMaterial.anisotropyDirection);
|
|
796
|
+
#ifdef HAS_ANISOTROPYMAP
|
|
797
|
+
if (pbrMaterial.anisotropyMapEnabled) {
|
|
798
|
+
vec3 anisotropySample = texture(pbr_anisotropySampler, pbr_vUV).rgb;
|
|
799
|
+
anisotropyStrength *= anisotropySample.b;
|
|
800
|
+
vec2 mappedDirection = anisotropySample.rg * 2.0 - 1.0;
|
|
801
|
+
if (length(mappedDirection) > 0.0001) {
|
|
802
|
+
anisotropyDirection = normalize(mappedDirection);
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
#endif
|
|
806
|
+
anisotropyDirection = rotateDirection(anisotropyDirection, pbrMaterial.anisotropyRotation);
|
|
807
|
+
vec3 anisotropyTangent = normalize(tbn[0] * anisotropyDirection.x + tbn[1] * anisotropyDirection.y);
|
|
808
|
+
if (length(anisotropyTangent) < 0.0001) {
|
|
809
|
+
anisotropyTangent = normalize(tbn[0]);
|
|
810
|
+
}
|
|
811
|
+
float anisotropyViewAlignment = abs(dot(v, anisotropyTangent));
|
|
812
|
+
perceptualRoughness = mix(
|
|
813
|
+
perceptualRoughness,
|
|
814
|
+
clamp(perceptualRoughness * (1.0 - 0.6 * anisotropyViewAlignment), c_MinRoughness, 1.0),
|
|
815
|
+
anisotropyStrength
|
|
816
|
+
);
|
|
817
|
+
|
|
394
818
|
// Roughness is authored as perceptual roughness; as is convention,
|
|
395
819
|
// convert to material roughness by squaring the perceptual roughness [2].
|
|
396
820
|
float alphaRoughness = perceptualRoughness * perceptualRoughness;
|
|
397
821
|
|
|
398
|
-
|
|
399
|
-
vec3
|
|
400
|
-
|
|
401
|
-
|
|
822
|
+
float dielectricF0 = getDielectricF0(pbrMaterial.ior);
|
|
823
|
+
vec3 dielectricSpecularF0 = min(
|
|
824
|
+
vec3(dielectricF0) * specularFactor * specularIntensity,
|
|
825
|
+
vec3(1.0)
|
|
826
|
+
);
|
|
827
|
+
vec3 iridescenceTint = getIridescenceTint(iridescence, iridescenceThickness, NdotV);
|
|
828
|
+
dielectricSpecularF0 = mix(
|
|
829
|
+
dielectricSpecularF0,
|
|
830
|
+
dielectricSpecularF0 * iridescenceTint,
|
|
831
|
+
iridescence
|
|
832
|
+
);
|
|
833
|
+
vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - dielectricSpecularF0);
|
|
834
|
+
diffuseColor *= (1.0 - metallic) * (1.0 - transmission);
|
|
835
|
+
vec3 specularColor = mix(dielectricSpecularF0, baseColor.rgb, metallic);
|
|
836
|
+
|
|
837
|
+
float baseLayerEnergy = 1.0 - clearcoatFactor * 0.25;
|
|
838
|
+
diffuseColor *= baseLayerEnergy;
|
|
839
|
+
specularColor *= baseLayerEnergy;
|
|
402
840
|
|
|
403
841
|
// Compute reflectance.
|
|
404
842
|
float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);
|
|
@@ -410,11 +848,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
410
848
|
float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);
|
|
411
849
|
vec3 specularEnvironmentR0 = specularColor.rgb;
|
|
412
850
|
vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;
|
|
413
|
-
|
|
414
|
-
vec3 n = getNormal(); // normal at surface point
|
|
415
|
-
vec3 v = normalize(pbrProjection.camera - pbr_vPosition); // Vector from surface point to camera
|
|
416
|
-
|
|
417
|
-
float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
|
|
418
851
|
vec3 reflection = -normalize(reflect(v, n));
|
|
419
852
|
|
|
420
853
|
PBRInfo pbrInfo = PBRInfo(
|
|
@@ -438,13 +871,33 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
438
871
|
#ifdef USE_LIGHTS
|
|
439
872
|
// Apply ambient light
|
|
440
873
|
PBRInfo_setAmbientLight(pbrInfo);
|
|
441
|
-
color +=
|
|
874
|
+
color += calculateMaterialLightColor(
|
|
875
|
+
pbrInfo,
|
|
876
|
+
lighting.ambientColor,
|
|
877
|
+
clearcoatNormal,
|
|
878
|
+
clearcoatFactor,
|
|
879
|
+
clearcoatRoughness,
|
|
880
|
+
sheenColor,
|
|
881
|
+
sheenRoughness,
|
|
882
|
+
anisotropyTangent,
|
|
883
|
+
anisotropyStrength
|
|
884
|
+
);
|
|
442
885
|
|
|
443
886
|
// Apply directional light
|
|
444
887
|
for(int i = 0; i < lighting.directionalLightCount; i++) {
|
|
445
888
|
if (i < lighting.directionalLightCount) {
|
|
446
889
|
PBRInfo_setDirectionalLight(pbrInfo, lighting_getDirectionalLight(i).direction);
|
|
447
|
-
color +=
|
|
890
|
+
color += calculateMaterialLightColor(
|
|
891
|
+
pbrInfo,
|
|
892
|
+
lighting_getDirectionalLight(i).color,
|
|
893
|
+
clearcoatNormal,
|
|
894
|
+
clearcoatFactor,
|
|
895
|
+
clearcoatRoughness,
|
|
896
|
+
sheenColor,
|
|
897
|
+
sheenRoughness,
|
|
898
|
+
anisotropyTangent,
|
|
899
|
+
anisotropyStrength
|
|
900
|
+
);
|
|
448
901
|
}
|
|
449
902
|
}
|
|
450
903
|
|
|
@@ -453,7 +906,35 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
453
906
|
if (i < lighting.pointLightCount) {
|
|
454
907
|
PBRInfo_setPointLight(pbrInfo, lighting_getPointLight(i));
|
|
455
908
|
float attenuation = getPointLightAttenuation(lighting_getPointLight(i), distance(lighting_getPointLight(i).position, pbr_vPosition));
|
|
456
|
-
color +=
|
|
909
|
+
color += calculateMaterialLightColor(
|
|
910
|
+
pbrInfo,
|
|
911
|
+
lighting_getPointLight(i).color / attenuation,
|
|
912
|
+
clearcoatNormal,
|
|
913
|
+
clearcoatFactor,
|
|
914
|
+
clearcoatRoughness,
|
|
915
|
+
sheenColor,
|
|
916
|
+
sheenRoughness,
|
|
917
|
+
anisotropyTangent,
|
|
918
|
+
anisotropyStrength
|
|
919
|
+
);
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
for(int i = 0; i < lighting.spotLightCount; i++) {
|
|
924
|
+
if (i < lighting.spotLightCount) {
|
|
925
|
+
PBRInfo_setSpotLight(pbrInfo, lighting_getSpotLight(i));
|
|
926
|
+
float attenuation = getSpotLightAttenuation(lighting_getSpotLight(i), pbr_vPosition);
|
|
927
|
+
color += calculateMaterialLightColor(
|
|
928
|
+
pbrInfo,
|
|
929
|
+
lighting_getSpotLight(i).color / attenuation,
|
|
930
|
+
clearcoatNormal,
|
|
931
|
+
clearcoatFactor,
|
|
932
|
+
clearcoatRoughness,
|
|
933
|
+
sheenColor,
|
|
934
|
+
sheenRoughness,
|
|
935
|
+
anisotropyTangent,
|
|
936
|
+
anisotropyStrength
|
|
937
|
+
);
|
|
457
938
|
}
|
|
458
939
|
}
|
|
459
940
|
#endif
|
|
@@ -461,7 +942,16 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
461
942
|
// Calculate lighting contribution from image based lighting source (IBL)
|
|
462
943
|
#ifdef USE_IBL
|
|
463
944
|
if (pbrMaterial.IBLenabled) {
|
|
464
|
-
color += getIBLContribution(pbrInfo, n, reflection)
|
|
945
|
+
color += getIBLContribution(pbrInfo, n, reflection) *
|
|
946
|
+
calculateAnisotropyBoost(pbrInfo, anisotropyTangent, anisotropyStrength);
|
|
947
|
+
color += calculateClearcoatIBLContribution(
|
|
948
|
+
pbrInfo,
|
|
949
|
+
clearcoatNormal,
|
|
950
|
+
-normalize(reflect(v, clearcoatNormal)),
|
|
951
|
+
clearcoatFactor,
|
|
952
|
+
clearcoatRoughness
|
|
953
|
+
);
|
|
954
|
+
color += sheenColor * pbrMaterial.scaleIBLAmbient.x * (1.0 - sheenRoughness) * 0.25;
|
|
465
955
|
}
|
|
466
956
|
#endif
|
|
467
957
|
|
|
@@ -473,12 +963,17 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
473
963
|
}
|
|
474
964
|
#endif
|
|
475
965
|
|
|
966
|
+
vec3 emissive = pbrMaterial.emissiveFactor;
|
|
476
967
|
#ifdef HAS_EMISSIVEMAP
|
|
477
968
|
if (pbrMaterial.emissiveMapEnabled) {
|
|
478
|
-
|
|
479
|
-
color += emissive;
|
|
969
|
+
emissive *= SRGBtoLINEAR(texture(pbr_emissiveSampler, pbr_vUV)).rgb;
|
|
480
970
|
}
|
|
481
971
|
#endif
|
|
972
|
+
color += emissive * pbrMaterial.emissiveStrength;
|
|
973
|
+
|
|
974
|
+
if (transmission > 0.0) {
|
|
975
|
+
color = mix(color, color * getVolumeAttenuation(thickness), transmission);
|
|
976
|
+
}
|
|
482
977
|
|
|
483
978
|
// This section uses mix to override final color for reference app visualization
|
|
484
979
|
// of various parameters in the lighting equation.
|
|
@@ -498,7 +993,8 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
498
993
|
|
|
499
994
|
}
|
|
500
995
|
|
|
501
|
-
|
|
996
|
+
float alpha = clamp(baseColor.a * (1.0 - transmission), 0.0, 1.0);
|
|
997
|
+
return vec4(pow(color,vec3(1.0/2.2)), alpha);
|
|
502
998
|
}
|
|
503
999
|
`;
|
|
504
1000
|
//# sourceMappingURL=pbr-material-glsl.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pbr-material-glsl.js","sourceRoot":"","sources":["../../../../src/modules/lighting/pbr-material/pbr-material-glsl.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,eAAe;AACf,yEAAyE;AACzE,0FAA0F;AAC1F,yDAAyD;AAEzD,gDAAgD;AAEhD,MAAM,CAAC,MAAM,EAAE,GAAG,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkC5B,CAAC;AAEF,MAAM,CAAC,MAAM,EAAE,GAAG,UAAU,CAAC
|
|
1
|
+
{"version":3,"file":"pbr-material-glsl.js","sourceRoot":"","sources":["../../../../src/modules/lighting/pbr-material/pbr-material-glsl.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,eAAe;AACf,yEAAyE;AACzE,0FAA0F;AAC1F,yDAAyD;AAEzD,gDAAgD;AAEhD,MAAM,CAAC,MAAM,EAAE,GAAG,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkC5B,CAAC;AAEF,MAAM,CAAC,MAAM,EAAE,GAAG,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA27B5B,CAAC"}
|