@luma.gl/shadertools 9.2.5 → 9.3.0-alpha.10
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 +4798 -6439
- package/dist/dist.min.js +2047 -311
- package/dist/index.cjs +3033 -507
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +12 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/preprocessor/preprocessor.d.ts.map +1 -1
- package/dist/lib/preprocessor/preprocessor.js +35 -8
- 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 +20 -3
- 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 +214 -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 +7 -4
- 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 +91 -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 +209 -0
- package/dist/lib/shader-module/shader-module-uniform-layout.js.map +1 -0
- package/dist/lib/shader-module/shader-module.d.ts +12 -6
- 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/assert.d.ts.map +1 -1
- package/dist/lib/utils/assert.js +3 -1
- package/dist/lib/utils/assert.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 +5 -2
- package/dist/modules/engine/picking/picking.d.ts.map +1 -1
- package/dist/modules/engine/picking/picking.js +5 -2
- package/dist/modules/engine/picking/picking.js.map +1 -1
- package/dist/modules/engine/project/project.d.ts +1 -1
- package/dist/modules/engine/project/project.js +1 -1
- package/dist/modules/engine/skin/skin.d.ts +30 -0
- package/dist/modules/engine/skin/skin.d.ts.map +1 -0
- package/dist/modules/engine/skin/skin.js +86 -0
- package/dist/modules/engine/skin/skin.js.map +1 -0
- 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 +44 -38
- 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 +46 -18
- package/dist/modules/lighting/lights/lighting-wgsl.js.map +1 -1
- package/dist/modules/lighting/lights/lighting.d.ts +104 -62
- package/dist/modules/lighting/lights/lighting.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting.js +107 -68
- package/dist/modules/lighting/lights/lighting.js.map +1 -1
- package/dist/modules/lighting/no-material/dirlight.d.ts +8 -3
- package/dist/modules/lighting/no-material/dirlight.d.ts.map +1 -1
- package/dist/modules/lighting/no-material/dirlight.js +4 -2
- 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 +581 -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 +850 -107
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts +172 -41
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material.js +109 -1
- 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 +14 -2
- package/dist/modules/lighting/pbr-material/pbr-projection.js.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-scene.d.ts +40 -0
- package/dist/modules/lighting/pbr-material/pbr-scene.d.ts.map +1 -0
- package/dist/modules/lighting/pbr-material/pbr-scene.js +67 -0
- package/dist/modules/lighting/pbr-material/pbr-scene.js.map +1 -0
- 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 +17 -6
- 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 -40
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.js +71 -76
- 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 +42 -11
- 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/dist/modules/math/random/random.d.ts +1 -1
- package/dist/modules/math/random/random.d.ts.map +1 -1
- package/dist/modules/math/random/random.js +2 -3
- package/dist/modules/math/random/random.js.map +1 -1
- package/package.json +4 -5
- package/src/index.ts +37 -6
- package/src/lib/preprocessor/preprocessor.ts +44 -8
- package/src/lib/shader-assembler.ts +25 -3
- package/src/lib/shader-assembly/assemble-shaders.ts +384 -12
- package/src/lib/shader-assembly/wgsl-binding-debug.ts +216 -0
- package/src/lib/shader-generator/glsl/generate-glsl.ts +11 -5
- package/src/lib/shader-generator/wgsl/generate-wgsl.ts +6 -0
- package/src/lib/shader-module/shader-module-uniform-layout.ts +346 -0
- package/src/lib/shader-module/shader-module.ts +17 -7
- package/src/lib/utils/assert.ts +3 -1
- package/src/lib/utils/uniform-types.ts +24 -9
- package/src/modules/engine/picking/picking.ts +5 -2
- package/src/modules/engine/project/project.ts +1 -1
- package/src/modules/engine/skin/skin.ts +114 -0
- 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 +44 -38
- package/src/modules/lighting/lights/lighting-wgsl.ts +46 -18
- package/src/modules/lighting/lights/lighting.ts +198 -99
- package/src/modules/lighting/no-material/dirlight.ts +4 -2
- package/src/modules/lighting/pbr-material/pbr-material-glsl.ts +581 -28
- package/src/modules/lighting/pbr-material/pbr-material-wgsl.ts +850 -107
- package/src/modules/lighting/pbr-material/pbr-material.ts +185 -5
- package/src/modules/lighting/pbr-material/pbr-projection.ts +15 -2
- package/src/modules/lighting/pbr-material/pbr-scene.ts +91 -0
- package/src/modules/lighting/phong-material/phong-material.ts +5 -0
- package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +17 -6
- package/src/modules/lighting/phong-material/phong-shaders-wgsl.ts +71 -77
- package/src/modules/math/fp64/fp64-arithmetic-glsl.ts +42 -11
- package/src/modules/math/fp64/fp64-arithmetic-wgsl.ts +212 -0
- package/src/modules/math/fp64/fp64.ts +9 -3
- package/src/modules/math/random/random.ts +2 -3
- package/dist/lib/wgsl/get-shader-layout-wgsl.d.ts +0 -8
- package/dist/lib/wgsl/get-shader-layout-wgsl.d.ts.map +0 -1
- package/dist/lib/wgsl/get-shader-layout-wgsl.js +0 -95
- package/dist/lib/wgsl/get-shader-layout-wgsl.js.map +0 -1
- package/src/lib/wgsl/get-shader-layout-wgsl.ts +0 -105
|
@@ -44,7 +44,7 @@ void pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, ve
|
|
|
44
44
|
export const fs = /* glsl */ `\
|
|
45
45
|
precision highp float;
|
|
46
46
|
|
|
47
|
-
uniform pbrMaterialUniforms {
|
|
47
|
+
layout(std140) uniform pbrMaterialUniforms {
|
|
48
48
|
// Material is unlit
|
|
49
49
|
bool unlit;
|
|
50
50
|
|
|
@@ -66,6 +66,42 @@ uniform pbrMaterialUniforms {
|
|
|
66
66
|
|
|
67
67
|
bool alphaCutoffEnabled;
|
|
68
68
|
float alphaCutoff; // #ifdef ALPHA_CUTOFF
|
|
69
|
+
|
|
70
|
+
vec3 specularColorFactor;
|
|
71
|
+
float specularIntensityFactor;
|
|
72
|
+
bool specularColorMapEnabled;
|
|
73
|
+
bool specularIntensityMapEnabled;
|
|
74
|
+
|
|
75
|
+
float ior;
|
|
76
|
+
|
|
77
|
+
float transmissionFactor;
|
|
78
|
+
bool transmissionMapEnabled;
|
|
79
|
+
|
|
80
|
+
float thicknessFactor;
|
|
81
|
+
float attenuationDistance;
|
|
82
|
+
vec3 attenuationColor;
|
|
83
|
+
|
|
84
|
+
float clearcoatFactor;
|
|
85
|
+
float clearcoatRoughnessFactor;
|
|
86
|
+
bool clearcoatMapEnabled;
|
|
87
|
+
bool clearcoatRoughnessMapEnabled;
|
|
88
|
+
|
|
89
|
+
vec3 sheenColorFactor;
|
|
90
|
+
float sheenRoughnessFactor;
|
|
91
|
+
bool sheenColorMapEnabled;
|
|
92
|
+
bool sheenRoughnessMapEnabled;
|
|
93
|
+
|
|
94
|
+
float iridescenceFactor;
|
|
95
|
+
float iridescenceIor;
|
|
96
|
+
vec2 iridescenceThicknessRange;
|
|
97
|
+
bool iridescenceMapEnabled;
|
|
98
|
+
|
|
99
|
+
float anisotropyStrength;
|
|
100
|
+
float anisotropyRotation;
|
|
101
|
+
vec2 anisotropyDirection;
|
|
102
|
+
bool anisotropyMapEnabled;
|
|
103
|
+
|
|
104
|
+
float emissiveStrength;
|
|
69
105
|
|
|
70
106
|
// IBL
|
|
71
107
|
bool IBLenabled;
|
|
@@ -94,12 +130,42 @@ uniform sampler2D pbr_metallicRoughnessSampler;
|
|
|
94
130
|
#ifdef HAS_OCCLUSIONMAP
|
|
95
131
|
uniform sampler2D pbr_occlusionSampler;
|
|
96
132
|
#endif
|
|
97
|
-
#ifdef
|
|
98
|
-
uniform
|
|
99
|
-
|
|
100
|
-
|
|
133
|
+
#ifdef HAS_SPECULARCOLORMAP
|
|
134
|
+
uniform sampler2D pbr_specularColorSampler;
|
|
135
|
+
#endif
|
|
136
|
+
#ifdef HAS_SPECULARINTENSITYMAP
|
|
137
|
+
uniform sampler2D pbr_specularIntensitySampler;
|
|
138
|
+
#endif
|
|
139
|
+
#ifdef HAS_TRANSMISSIONMAP
|
|
140
|
+
uniform sampler2D pbr_transmissionSampler;
|
|
141
|
+
#endif
|
|
142
|
+
#ifdef HAS_THICKNESSMAP
|
|
143
|
+
uniform sampler2D pbr_thicknessSampler;
|
|
144
|
+
#endif
|
|
145
|
+
#ifdef HAS_CLEARCOATMAP
|
|
146
|
+
uniform sampler2D pbr_clearcoatSampler;
|
|
147
|
+
#endif
|
|
148
|
+
#ifdef HAS_CLEARCOATROUGHNESSMAP
|
|
149
|
+
uniform sampler2D pbr_clearcoatRoughnessSampler;
|
|
150
|
+
#endif
|
|
151
|
+
#ifdef HAS_CLEARCOATNORMALMAP
|
|
152
|
+
uniform sampler2D pbr_clearcoatNormalSampler;
|
|
153
|
+
#endif
|
|
154
|
+
#ifdef HAS_SHEENCOLORMAP
|
|
155
|
+
uniform sampler2D pbr_sheenColorSampler;
|
|
156
|
+
#endif
|
|
157
|
+
#ifdef HAS_SHEENROUGHNESSMAP
|
|
158
|
+
uniform sampler2D pbr_sheenRoughnessSampler;
|
|
159
|
+
#endif
|
|
160
|
+
#ifdef HAS_IRIDESCENCEMAP
|
|
161
|
+
uniform sampler2D pbr_iridescenceSampler;
|
|
162
|
+
#endif
|
|
163
|
+
#ifdef HAS_IRIDESCENCETHICKNESSMAP
|
|
164
|
+
uniform sampler2D pbr_iridescenceThicknessSampler;
|
|
165
|
+
#endif
|
|
166
|
+
#ifdef HAS_ANISOTROPYMAP
|
|
167
|
+
uniform sampler2D pbr_anisotropySampler;
|
|
101
168
|
#endif
|
|
102
|
-
|
|
103
169
|
// Inputs from vertex shader
|
|
104
170
|
|
|
105
171
|
in vec3 pbr_vPosition;
|
|
@@ -136,6 +202,8 @@ struct PBRInfo {
|
|
|
136
202
|
const float M_PI = 3.141592653589793;
|
|
137
203
|
const float c_MinRoughness = 0.04;
|
|
138
204
|
|
|
205
|
+
vec3 calculateFinalColor(PBRInfo pbrInfo, vec3 lightColor);
|
|
206
|
+
|
|
139
207
|
vec4 SRGBtoLINEAR(vec4 srgbIn)
|
|
140
208
|
{
|
|
141
209
|
#ifdef MANUAL_SRGB
|
|
@@ -151,11 +219,9 @@ vec4 SRGBtoLINEAR(vec4 srgbIn)
|
|
|
151
219
|
#endif //MANUAL_SRGB
|
|
152
220
|
}
|
|
153
221
|
|
|
154
|
-
//
|
|
155
|
-
|
|
156
|
-
vec3 getNormal()
|
|
222
|
+
// Build the tangent basis from interpolated attributes or screen-space derivatives.
|
|
223
|
+
mat3 getTBN()
|
|
157
224
|
{
|
|
158
|
-
// Retrieve the tangent space matrix
|
|
159
225
|
#ifndef HAS_TANGENTS
|
|
160
226
|
vec3 pos_dx = dFdx(pbr_vPosition);
|
|
161
227
|
vec3 pos_dy = dFdy(pbr_vPosition);
|
|
@@ -176,9 +242,21 @@ vec3 getNormal()
|
|
|
176
242
|
mat3 tbn = pbr_vTBN;
|
|
177
243
|
#endif
|
|
178
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
|
+
{
|
|
179
258
|
#ifdef HAS_NORMALMAP
|
|
180
|
-
vec3 n =
|
|
181
|
-
n = normalize(tbn * ((2.0 * n - 1.0) * vec3(pbrMaterial.normalScale, pbrMaterial.normalScale, 1.0)));
|
|
259
|
+
vec3 n = getMappedNormal(pbr_normalSampler, tbn, pbrMaterial.normalScale);
|
|
182
260
|
#else
|
|
183
261
|
// The tbn matrix is linearly interpolated, so we need to re-normalize
|
|
184
262
|
vec3 n = normalize(tbn[2].xyz);
|
|
@@ -187,6 +265,15 @@ vec3 getNormal()
|
|
|
187
265
|
return n;
|
|
188
266
|
}
|
|
189
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
|
+
|
|
190
277
|
// Calculation of the lighting contribution from an optional Image Based Light source.
|
|
191
278
|
// Precomputed Environment Maps are required uniform inputs and are computed as outlined in [1].
|
|
192
279
|
// See our README.md on Environment Maps [3] for additional discussion.
|
|
@@ -262,6 +349,169 @@ float microfacetDistribution(PBRInfo pbrInfo)
|
|
|
262
349
|
return roughnessSq / (M_PI * f * f);
|
|
263
350
|
}
|
|
264
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
|
+
|
|
265
515
|
void PBRInfo_setAmbientLight(inout PBRInfo pbrInfo) {
|
|
266
516
|
pbrInfo.NdotL = 1.0;
|
|
267
517
|
pbrInfo.NdotH = 0.0;
|
|
@@ -286,6 +536,11 @@ void PBRInfo_setPointLight(inout PBRInfo pbrInfo, PointLight pointLight) {
|
|
|
286
536
|
PBRInfo_setDirectionalLight(pbrInfo, light_direction);
|
|
287
537
|
}
|
|
288
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
|
+
|
|
289
544
|
vec3 calculateFinalColor(PBRInfo pbrInfo, vec3 lightColor) {
|
|
290
545
|
// Calculate the shading terms for the microfacet specular shading model
|
|
291
546
|
vec3 F = specularReflection(pbrInfo);
|
|
@@ -316,6 +571,8 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
316
571
|
|
|
317
572
|
vec3 color = vec3(0, 0, 0);
|
|
318
573
|
|
|
574
|
+
float transmission = 0.0;
|
|
575
|
+
|
|
319
576
|
if(pbrMaterial.unlit){
|
|
320
577
|
color.rgb = baseColor.rgb;
|
|
321
578
|
}
|
|
@@ -334,14 +591,252 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
334
591
|
#endif
|
|
335
592
|
perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0);
|
|
336
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
|
+
|
|
337
818
|
// Roughness is authored as perceptual roughness; as is convention,
|
|
338
819
|
// convert to material roughness by squaring the perceptual roughness [2].
|
|
339
820
|
float alphaRoughness = perceptualRoughness * perceptualRoughness;
|
|
340
821
|
|
|
341
|
-
|
|
342
|
-
vec3
|
|
343
|
-
|
|
344
|
-
|
|
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;
|
|
345
840
|
|
|
346
841
|
// Compute reflectance.
|
|
347
842
|
float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);
|
|
@@ -353,11 +848,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
353
848
|
float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);
|
|
354
849
|
vec3 specularEnvironmentR0 = specularColor.rgb;
|
|
355
850
|
vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;
|
|
356
|
-
|
|
357
|
-
vec3 n = getNormal(); // normal at surface point
|
|
358
|
-
vec3 v = normalize(pbrProjection.camera - pbr_vPosition); // Vector from surface point to camera
|
|
359
|
-
|
|
360
|
-
float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
|
|
361
851
|
vec3 reflection = -normalize(reflect(v, n));
|
|
362
852
|
|
|
363
853
|
PBRInfo pbrInfo = PBRInfo(
|
|
@@ -381,13 +871,33 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
381
871
|
#ifdef USE_LIGHTS
|
|
382
872
|
// Apply ambient light
|
|
383
873
|
PBRInfo_setAmbientLight(pbrInfo);
|
|
384
|
-
color +=
|
|
874
|
+
color += calculateMaterialLightColor(
|
|
875
|
+
pbrInfo,
|
|
876
|
+
lighting.ambientColor,
|
|
877
|
+
clearcoatNormal,
|
|
878
|
+
clearcoatFactor,
|
|
879
|
+
clearcoatRoughness,
|
|
880
|
+
sheenColor,
|
|
881
|
+
sheenRoughness,
|
|
882
|
+
anisotropyTangent,
|
|
883
|
+
anisotropyStrength
|
|
884
|
+
);
|
|
385
885
|
|
|
386
886
|
// Apply directional light
|
|
387
887
|
for(int i = 0; i < lighting.directionalLightCount; i++) {
|
|
388
888
|
if (i < lighting.directionalLightCount) {
|
|
389
889
|
PBRInfo_setDirectionalLight(pbrInfo, lighting_getDirectionalLight(i).direction);
|
|
390
|
-
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
|
+
);
|
|
391
901
|
}
|
|
392
902
|
}
|
|
393
903
|
|
|
@@ -396,7 +906,35 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
396
906
|
if (i < lighting.pointLightCount) {
|
|
397
907
|
PBRInfo_setPointLight(pbrInfo, lighting_getPointLight(i));
|
|
398
908
|
float attenuation = getPointLightAttenuation(lighting_getPointLight(i), distance(lighting_getPointLight(i).position, pbr_vPosition));
|
|
399
|
-
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
|
+
);
|
|
400
938
|
}
|
|
401
939
|
}
|
|
402
940
|
#endif
|
|
@@ -404,7 +942,16 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
404
942
|
// Calculate lighting contribution from image based lighting source (IBL)
|
|
405
943
|
#ifdef USE_IBL
|
|
406
944
|
if (pbrMaterial.IBLenabled) {
|
|
407
|
-
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;
|
|
408
955
|
}
|
|
409
956
|
#endif
|
|
410
957
|
|
|
@@ -416,12 +963,17 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
416
963
|
}
|
|
417
964
|
#endif
|
|
418
965
|
|
|
966
|
+
vec3 emissive = pbrMaterial.emissiveFactor;
|
|
419
967
|
#ifdef HAS_EMISSIVEMAP
|
|
420
968
|
if (pbrMaterial.emissiveMapEnabled) {
|
|
421
|
-
|
|
422
|
-
color += emissive;
|
|
969
|
+
emissive *= SRGBtoLINEAR(texture(pbr_emissiveSampler, pbr_vUV)).rgb;
|
|
423
970
|
}
|
|
424
971
|
#endif
|
|
972
|
+
color += emissive * pbrMaterial.emissiveStrength;
|
|
973
|
+
|
|
974
|
+
if (transmission > 0.0) {
|
|
975
|
+
color = mix(color, color * getVolumeAttenuation(thickness), transmission);
|
|
976
|
+
}
|
|
425
977
|
|
|
426
978
|
// This section uses mix to override final color for reference app visualization
|
|
427
979
|
// of various parameters in the lighting equation.
|
|
@@ -441,7 +993,8 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
441
993
|
|
|
442
994
|
}
|
|
443
995
|
|
|
444
|
-
|
|
996
|
+
float alpha = clamp(baseColor.a * (1.0 - transmission), 0.0, 1.0);
|
|
997
|
+
return vec4(pow(color,vec3(1.0/2.2)), alpha);
|
|
445
998
|
}
|
|
446
999
|
`;
|
|
447
1000
|
//# sourceMappingURL=pbr-material-glsl.js.map
|