@luma.gl/shadertools 9.0.21 → 9.0.24
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 +102 -90
- package/dist/dist.min.js +127 -130
- package/dist/index.cjs +94 -79
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/modules/lighting/gouraud-material/gouraud-material.js +1 -1
- package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.js +49 -52
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts +10 -29
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material.js +14 -11
- package/dist/modules/lighting/pbr-material/pbr-projection.d.ts +10 -0
- package/dist/modules/lighting/pbr-material/pbr-projection.d.ts.map +1 -0
- package/dist/modules/lighting/pbr-material/pbr-projection.js +25 -0
- package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.js +8 -14
- package/dist/modules/lighting/phong-material/phong-material.js +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +7 -1
- package/src/modules/lighting/gouraud-material/gouraud-material.ts +1 -1
- package/src/modules/lighting/pbr-material/pbr-fragment-glsl.ts +56 -60
- package/src/modules/lighting/pbr-material/pbr-material.ts +25 -52
- package/src/modules/lighting/pbr-material/pbr-projection.ts +41 -0
- package/src/modules/lighting/pbr-material/pbr-vertex-glsl.ts +8 -16
- package/src/modules/lighting/phong-material/phong-material.ts +1 -1
- package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +0 -1
- package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.d.ts +0 -2
- package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.d.ts.map +0 -1
- package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.js +0 -48
- package/src/modules/lighting/pbr-material/pbr-uniforms-glsl.ts +0 -69
|
@@ -14,12 +14,7 @@ import {glsl} from '../../../lib/glsl-utils/highlight';
|
|
|
14
14
|
export const fs = glsl`\
|
|
15
15
|
precision highp float;
|
|
16
16
|
|
|
17
|
-
uniform
|
|
18
|
-
// Projection
|
|
19
|
-
uniform vec3 u_Camera;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
uniform pbrMaterial {
|
|
17
|
+
uniform pbrMaterialUniforms {
|
|
23
18
|
// Material is unlit
|
|
24
19
|
bool unlit;
|
|
25
20
|
|
|
@@ -51,40 +46,40 @@ uniform pbrMaterial {
|
|
|
51
46
|
vec4 scaleDiffBaseMR;
|
|
52
47
|
vec4 scaleFGDSpec;
|
|
53
48
|
// #endif
|
|
54
|
-
}
|
|
49
|
+
} pbrMaterial;
|
|
55
50
|
|
|
56
51
|
// Samplers
|
|
57
52
|
#ifdef HAS_BASECOLORMAP
|
|
58
|
-
uniform sampler2D
|
|
53
|
+
uniform sampler2D pbr_baseColorSampler;
|
|
59
54
|
#endif
|
|
60
55
|
#ifdef HAS_NORMALMAP
|
|
61
|
-
uniform sampler2D
|
|
56
|
+
uniform sampler2D pbr_normalSampler;
|
|
62
57
|
#endif
|
|
63
58
|
#ifdef HAS_EMISSIVEMAP
|
|
64
|
-
uniform sampler2D
|
|
59
|
+
uniform sampler2D pbr_emissiveSampler;
|
|
65
60
|
#endif
|
|
66
61
|
#ifdef HAS_METALROUGHNESSMAP
|
|
67
|
-
uniform sampler2D
|
|
62
|
+
uniform sampler2D pbr_metallicRoughnessSampler;
|
|
68
63
|
#endif
|
|
69
64
|
#ifdef HAS_OCCLUSIONMAP
|
|
70
|
-
uniform sampler2D
|
|
65
|
+
uniform sampler2D pbr_occlusionSampler;
|
|
71
66
|
#endif
|
|
72
67
|
#ifdef USE_IBL
|
|
73
|
-
uniform samplerCube
|
|
74
|
-
uniform samplerCube
|
|
75
|
-
uniform sampler2D
|
|
68
|
+
uniform samplerCube pbr_diffuseEnvSampler;
|
|
69
|
+
uniform samplerCube pbr_specularEnvSampler;
|
|
70
|
+
uniform sampler2D pbr_brdfLUT;
|
|
76
71
|
#endif
|
|
77
72
|
|
|
78
73
|
// Inputs from vertex shader
|
|
79
74
|
|
|
80
|
-
|
|
81
|
-
|
|
75
|
+
in vec3 pbr_vPosition;
|
|
76
|
+
in vec2 pbr_vUV;
|
|
82
77
|
|
|
83
78
|
#ifdef HAS_NORMALS
|
|
84
79
|
#ifdef HAS_TANGENTS
|
|
85
|
-
|
|
80
|
+
in mat3 pbr_vTBN;
|
|
86
81
|
#else
|
|
87
|
-
|
|
82
|
+
in vec3 pbr_vNormal;
|
|
88
83
|
#endif
|
|
89
84
|
#endif
|
|
90
85
|
|
|
@@ -152,8 +147,8 @@ vec3 getNormal()
|
|
|
152
147
|
#endif
|
|
153
148
|
|
|
154
149
|
#ifdef HAS_NORMALMAP
|
|
155
|
-
vec3 n =
|
|
156
|
-
n = normalize(tbn * ((2.0 * n - 1.0) * vec3(
|
|
150
|
+
vec3 n = texture(pbr_normalSampler, pbr_vUV).rgb;
|
|
151
|
+
n = normalize(tbn * ((2.0 * n - 1.0) * vec3(pbrMaterial.normalScale, pbrMaterial.normalScale, 1.0)));
|
|
157
152
|
#else
|
|
158
153
|
// The tbn matrix is linearly interpolated, so we need to re-normalize
|
|
159
154
|
vec3 n = normalize(tbn[2].xyz);
|
|
@@ -171,22 +166,22 @@ vec3 getIBLContribution(PBRInfo pbrInfo, vec3 n, vec3 reflection)
|
|
|
171
166
|
float mipCount = 9.0; // resolution of 512x512
|
|
172
167
|
float lod = (pbrInfo.perceptualRoughness * mipCount);
|
|
173
168
|
// retrieve a scale and bias to F0. See [1], Figure 3
|
|
174
|
-
vec3 brdf = SRGBtoLINEAR(
|
|
169
|
+
vec3 brdf = SRGBtoLINEAR(texture(pbr_brdfLUT,
|
|
175
170
|
vec2(pbrInfo.NdotV, 1.0 - pbrInfo.perceptualRoughness))).rgb;
|
|
176
|
-
vec3 diffuseLight = SRGBtoLINEAR(
|
|
171
|
+
vec3 diffuseLight = SRGBtoLINEAR(texture(pbr_diffuseEnvSampler, n)).rgb;
|
|
177
172
|
|
|
178
173
|
#ifdef USE_TEX_LOD
|
|
179
|
-
vec3 specularLight = SRGBtoLINEAR(
|
|
174
|
+
vec3 specularLight = SRGBtoLINEAR(texture(pbr_specularEnvSampler, reflection, lod)).rgb;
|
|
180
175
|
#else
|
|
181
|
-
vec3 specularLight = SRGBtoLINEAR(
|
|
176
|
+
vec3 specularLight = SRGBtoLINEAR(texture(pbr_specularEnvSampler, reflection)).rgb;
|
|
182
177
|
#endif
|
|
183
178
|
|
|
184
179
|
vec3 diffuse = diffuseLight * pbrInfo.diffuseColor;
|
|
185
180
|
vec3 specular = specularLight * (pbrInfo.specularColor * brdf.x + brdf.y);
|
|
186
181
|
|
|
187
182
|
// For presentation, this allows us to disable IBL terms
|
|
188
|
-
diffuse *=
|
|
189
|
-
specular *=
|
|
183
|
+
diffuse *= pbrMaterial.scaleIBLAmbient.x;
|
|
184
|
+
specular *= pbrMaterial.scaleIBLAmbient.y;
|
|
190
185
|
|
|
191
186
|
return diffuse + specular;
|
|
192
187
|
}
|
|
@@ -278,32 +273,32 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
278
273
|
{
|
|
279
274
|
// The albedo may be defined from a base texture or a flat color
|
|
280
275
|
#ifdef HAS_BASECOLORMAP
|
|
281
|
-
vec4 baseColor = SRGBtoLINEAR(
|
|
276
|
+
vec4 baseColor = SRGBtoLINEAR(texture(pbr_baseColorSampler, pbr_vUV)) * pbrMaterial.baseColorFactor;
|
|
282
277
|
#else
|
|
283
|
-
vec4 baseColor =
|
|
278
|
+
vec4 baseColor = pbrMaterial.baseColorFactor;
|
|
284
279
|
#endif
|
|
285
280
|
|
|
286
281
|
#ifdef ALPHA_CUTOFF
|
|
287
|
-
if (baseColor.a <
|
|
282
|
+
if (baseColor.a < pbrMaterial.alphaCutoff) {
|
|
288
283
|
discard;
|
|
289
284
|
}
|
|
290
285
|
#endif
|
|
291
286
|
|
|
292
287
|
vec3 color = vec3(0, 0, 0);
|
|
293
288
|
|
|
294
|
-
if(
|
|
289
|
+
if(pbrMaterial.unlit){
|
|
295
290
|
color.rgb = baseColor.rgb;
|
|
296
291
|
}
|
|
297
292
|
else{
|
|
298
293
|
// Metallic and Roughness material properties are packed together
|
|
299
294
|
// In glTF, these factors can be specified by fixed scalar values
|
|
300
295
|
// or from a metallic-roughness map
|
|
301
|
-
float perceptualRoughness =
|
|
302
|
-
float metallic =
|
|
296
|
+
float perceptualRoughness = pbrMaterial.metallicRoughnessValues.y;
|
|
297
|
+
float metallic = pbrMaterial.metallicRoughnessValues.x;
|
|
303
298
|
#ifdef HAS_METALROUGHNESSMAP
|
|
304
299
|
// Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
|
|
305
300
|
// This layout intentionally reserves the 'r' channel for (optional) occlusion map data
|
|
306
|
-
vec4 mrSample =
|
|
301
|
+
vec4 mrSample = texture(pbr_metallicRoughnessSampler, pbr_vUV);
|
|
307
302
|
perceptualRoughness = mrSample.g * perceptualRoughness;
|
|
308
303
|
metallic = mrSample.b * metallic;
|
|
309
304
|
#endif
|
|
@@ -330,7 +325,7 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
330
325
|
vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;
|
|
331
326
|
|
|
332
327
|
vec3 n = getNormal(); // normal at surface point
|
|
333
|
-
vec3 v = normalize(
|
|
328
|
+
vec3 v = normalize(pbrProjection.camera - pbr_vPosition); // Vector from surface point to camera
|
|
334
329
|
|
|
335
330
|
float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
|
|
336
331
|
vec3 reflection = -normalize(reflect(v, n));
|
|
@@ -352,47 +347,48 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
352
347
|
v
|
|
353
348
|
);
|
|
354
349
|
|
|
350
|
+
|
|
355
351
|
#ifdef USE_LIGHTS
|
|
356
352
|
// Apply ambient light
|
|
357
353
|
PBRInfo_setAmbientLight(pbrInfo);
|
|
358
|
-
color += calculateFinalColor(pbrInfo,
|
|
354
|
+
color += calculateFinalColor(pbrInfo, lighting.ambientColor);
|
|
359
355
|
|
|
360
356
|
// Apply directional light
|
|
361
|
-
for(int i = 0; i <
|
|
362
|
-
if (i <
|
|
363
|
-
PBRInfo_setDirectionalLight(pbrInfo,
|
|
364
|
-
color += calculateFinalColor(pbrInfo,
|
|
357
|
+
for(int i = 0; i < lighting.directionalLightCount; i++) {
|
|
358
|
+
if (i < lighting.directionalLightCount) {
|
|
359
|
+
PBRInfo_setDirectionalLight(pbrInfo, lighting_getDirectionalLight(i).direction);
|
|
360
|
+
color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);
|
|
365
361
|
}
|
|
366
362
|
}
|
|
367
363
|
|
|
368
364
|
// Apply point light
|
|
369
|
-
for(int i = 0; i <
|
|
370
|
-
if (i <
|
|
371
|
-
PBRInfo_setPointLight(pbrInfo,
|
|
372
|
-
float attenuation = getPointLightAttenuation(
|
|
373
|
-
color += calculateFinalColor(pbrInfo,
|
|
365
|
+
for(int i = 0; i < lighting.pointLightCount; i++) {
|
|
366
|
+
if (i < lighting.pointLightCount) {
|
|
367
|
+
PBRInfo_setPointLight(pbrInfo, lighting_getPointLight(i));
|
|
368
|
+
float attenuation = getPointLightAttenuation(lighting_getPointLight(i), distance(lighting_getPointLight(i).position, pbr_vPosition));
|
|
369
|
+
color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color / attenuation);
|
|
374
370
|
}
|
|
375
371
|
}
|
|
376
372
|
#endif
|
|
377
373
|
|
|
378
374
|
// Calculate lighting contribution from image based lighting source (IBL)
|
|
379
375
|
#ifdef USE_IBL
|
|
380
|
-
if (
|
|
376
|
+
if (pbrMaterial.IBLenabled) {
|
|
381
377
|
color += getIBLContribution(pbrInfo, n, reflection);
|
|
382
378
|
}
|
|
383
379
|
#endif
|
|
384
380
|
|
|
385
|
-
|
|
381
|
+
// Apply optional PBR terms for additional (optional) shading
|
|
386
382
|
#ifdef HAS_OCCLUSIONMAP
|
|
387
|
-
if (
|
|
388
|
-
float ao =
|
|
389
|
-
color = mix(color, color * ao,
|
|
383
|
+
if (pbrMaterial.occlusionMapEnabled) {
|
|
384
|
+
float ao = texture(pbr_occlusionSampler, pbr_vUV).r;
|
|
385
|
+
color = mix(color, color * ao, pbrMaterial.occlusionStrength);
|
|
390
386
|
}
|
|
391
387
|
#endif
|
|
392
388
|
|
|
393
389
|
#ifdef HAS_EMISSIVEMAP
|
|
394
|
-
if (
|
|
395
|
-
vec3 emissive = SRGBtoLINEAR(
|
|
390
|
+
if (pbrMaterial.emissiveMapEnabled) {
|
|
391
|
+
vec3 emissive = SRGBtoLINEAR(texture(pbr_emissiveSampler, pbr_vUV)).rgb * pbrMaterial.emissiveFactor;
|
|
396
392
|
color += emissive;
|
|
397
393
|
}
|
|
398
394
|
#endif
|
|
@@ -402,15 +398,15 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
402
398
|
#ifdef PBR_DEBUG
|
|
403
399
|
// TODO: Figure out how to debug multiple lights
|
|
404
400
|
|
|
405
|
-
// color = mix(color, F,
|
|
406
|
-
// color = mix(color, vec3(G),
|
|
407
|
-
// color = mix(color, vec3(D),
|
|
408
|
-
// color = mix(color, specContrib,
|
|
401
|
+
// color = mix(color, F, pbr_scaleFGDSpec.x);
|
|
402
|
+
// color = mix(color, vec3(G), pbr_scaleFGDSpec.y);
|
|
403
|
+
// color = mix(color, vec3(D), pbr_scaleFGDSpec.z);
|
|
404
|
+
// color = mix(color, specContrib, pbr_scaleFGDSpec.w);
|
|
409
405
|
|
|
410
|
-
// color = mix(color, diffuseContrib,
|
|
411
|
-
color = mix(color, baseColor.rgb,
|
|
412
|
-
color = mix(color, vec3(metallic),
|
|
413
|
-
color = mix(color, vec3(perceptualRoughness),
|
|
406
|
+
// color = mix(color, diffuseContrib, pbr_scaleDiffBaseMR.x);
|
|
407
|
+
color = mix(color, baseColor.rgb, pbrMaterial.scaleDiffBaseMR.y);
|
|
408
|
+
color = mix(color, vec3(metallic), pbrMaterial.scaleDiffBaseMR.z);
|
|
409
|
+
color = mix(color, vec3(perceptualRoughness), pbrMaterial.scaleDiffBaseMR.w);
|
|
414
410
|
#endif
|
|
415
411
|
|
|
416
412
|
}
|
|
@@ -13,52 +13,21 @@ import {lighting} from '../lights/lighting-uniforms';
|
|
|
13
13
|
|
|
14
14
|
import {vs} from './pbr-vertex-glsl';
|
|
15
15
|
import {fs} from './pbr-fragment-glsl';
|
|
16
|
-
|
|
17
|
-
export type PBRMaterialProps = PBRMaterialBindings & {
|
|
18
|
-
unlit: boolean;
|
|
19
|
-
|
|
20
|
-
// Base color map
|
|
21
|
-
baseColorMapEnabled: boolean;
|
|
22
|
-
baseColorFactor: Readonly<Vector4 | NumberArray4>;
|
|
23
|
-
|
|
24
|
-
normalMapEnabled: boolean;
|
|
25
|
-
normalScale: number; // #ifdef HAS_NORMALMAP
|
|
26
|
-
|
|
27
|
-
emissiveMapEnabled: boolean;
|
|
28
|
-
emissiveFactor: Readonly<Vector3 | NumberArray3>; // #ifdef HAS_EMISSIVEMAP
|
|
29
|
-
|
|
30
|
-
metallicRoughnessValues: Readonly<Vector2 | NumberArray2>;
|
|
31
|
-
metallicRoughnessMapEnabled: boolean;
|
|
32
|
-
|
|
33
|
-
occlusionMapEnabled: boolean;
|
|
34
|
-
occlusionStrength: number; // #ifdef HAS_OCCLUSIONMAP
|
|
35
|
-
|
|
36
|
-
alphaCutoffEnabled: boolean;
|
|
37
|
-
alphaCutoff: number; // #ifdef ALPHA_CUTOFF
|
|
38
|
-
|
|
39
|
-
// IBL
|
|
40
|
-
IBLenabled: boolean;
|
|
41
|
-
scaleIBLAmbient: Readonly<Vector2 | NumberArray2>; // #ifdef USE_IBL
|
|
42
|
-
|
|
43
|
-
// debugging flags used for shader output of intermediate PBR variables
|
|
44
|
-
// #ifdef PBR_DEBUG
|
|
45
|
-
scaleDiffBaseMR: Readonly<Vector4 | NumberArray4>;
|
|
46
|
-
scaleFGDSpec: Readonly<Vector4 | NumberArray4>;
|
|
47
|
-
};
|
|
16
|
+
import {pbrProjection} from './pbr-projection';
|
|
48
17
|
|
|
49
18
|
/** Non-uniform block bindings for pbr module */
|
|
50
|
-
type PBRMaterialBindings = {
|
|
19
|
+
export type PBRMaterialBindings = {
|
|
51
20
|
// Samplers
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
21
|
+
pbr_baseColorSampler?: Texture | null; // #ifdef HAS_BASECOLORMAP
|
|
22
|
+
pbr_normalSampler?: Texture | null; // #ifdef HAS_NORMALMAP
|
|
23
|
+
pbr_emissiveSampler?: Texture | null; // #ifdef HAS_EMISSIVEMAP
|
|
24
|
+
pbr_metallicRoughnessSampler?: Texture | null; // #ifdef HAS_METALROUGHNESSMAP
|
|
25
|
+
pbr_occlusionSampler?: Texture | null; // #ifdef HAS_OCCLUSIONMAP
|
|
57
26
|
|
|
58
27
|
// IBL Samplers
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
28
|
+
pbr_diffuseEnvSampler?: Texture | null; // #ifdef USE_IBL (samplerCube)
|
|
29
|
+
pbr_specularEnvSampler?: Texture | null; // #ifdef USE_IBL (samplerCube)
|
|
30
|
+
pbr_BrdfLUT?: Texture | null; // #ifdef USE_IBL
|
|
62
31
|
};
|
|
63
32
|
|
|
64
33
|
export type PBRMaterialUniforms = {
|
|
@@ -93,25 +62,29 @@ export type PBRMaterialUniforms = {
|
|
|
93
62
|
scaleFGDSpec: Readonly<Vector4 | NumberArray4>;
|
|
94
63
|
};
|
|
95
64
|
|
|
65
|
+
export type PBRMaterialProps = PBRMaterialBindings & PBRMaterialUniforms;
|
|
66
|
+
|
|
96
67
|
/**
|
|
97
68
|
* An implementation of PBR (Physically-Based Rendering).
|
|
98
69
|
* Physically Based Shading of a microfacet surface defined by a glTF material.
|
|
99
70
|
*/
|
|
100
71
|
export const pbrMaterial: ShaderModule<PBRMaterialProps, PBRMaterialUniforms> = {
|
|
101
|
-
name: '
|
|
72
|
+
name: 'pbrMaterial',
|
|
102
73
|
vs,
|
|
103
74
|
fs,
|
|
104
75
|
defines: {
|
|
105
|
-
LIGHTING_FRAGMENT: 1
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
76
|
+
LIGHTING_FRAGMENT: 1
|
|
77
|
+
// TODO defining these as 0 breaks shader
|
|
78
|
+
// HAS_NORMALMAP: 0
|
|
79
|
+
// HAS_EMISSIVEMAP: 0,
|
|
80
|
+
// HAS_OCCLUSIONMAP: 0,
|
|
81
|
+
// HAS_BASECOLORMAP: 0,
|
|
82
|
+
// HAS_METALROUGHNESSMAP: 0,
|
|
83
|
+
// ALPHA_CUTOFF: 0
|
|
84
|
+
// USE_IBL: 0
|
|
85
|
+
// PBR_DEBUG: 0
|
|
114
86
|
},
|
|
87
|
+
getUniforms: props => props,
|
|
115
88
|
uniformTypes: {
|
|
116
89
|
// Material is unlit
|
|
117
90
|
unlit: 'i32',
|
|
@@ -144,5 +117,5 @@ export const pbrMaterial: ShaderModule<PBRMaterialProps, PBRMaterialUniforms> =
|
|
|
144
117
|
scaleDiffBaseMR: 'vec4<f32>',
|
|
145
118
|
scaleFGDSpec: 'vec4<f32>'
|
|
146
119
|
},
|
|
147
|
-
dependencies: [lighting]
|
|
120
|
+
dependencies: [lighting, pbrProjection]
|
|
148
121
|
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
/* eslint-disable camelcase */
|
|
6
|
+
|
|
7
|
+
import type {NumberArray3, NumberArray16} from '../../../lib/utils/uniform-types';
|
|
8
|
+
|
|
9
|
+
import {ShaderModule} from '../../../lib/shader-module/shader-module';
|
|
10
|
+
|
|
11
|
+
import {glsl} from '../../../lib/glsl-utils/highlight';
|
|
12
|
+
|
|
13
|
+
const uniformBlock = glsl`\
|
|
14
|
+
uniform pbrProjectionUniforms {
|
|
15
|
+
mat4 modelViewProjectionMatrix;
|
|
16
|
+
mat4 modelMatrix;
|
|
17
|
+
mat4 normalMatrix;
|
|
18
|
+
vec3 camera;
|
|
19
|
+
} pbrProjection;
|
|
20
|
+
`;
|
|
21
|
+
|
|
22
|
+
export type PBRProjectionProps = {
|
|
23
|
+
modelViewProjectionMatrix: NumberArray16;
|
|
24
|
+
modelMatrix: NumberArray16;
|
|
25
|
+
normalMatrix: NumberArray16;
|
|
26
|
+
camera: NumberArray3;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const pbrProjection: ShaderModule<PBRProjectionProps> = {
|
|
30
|
+
name: 'pbrProjection',
|
|
31
|
+
vs: uniformBlock,
|
|
32
|
+
fs: uniformBlock,
|
|
33
|
+
// TODO why is this needed?
|
|
34
|
+
getUniforms: props => props,
|
|
35
|
+
uniformTypes: {
|
|
36
|
+
modelViewProjectionMatrix: 'mat4x4<f32>',
|
|
37
|
+
modelMatrix: 'mat4x4<f32>',
|
|
38
|
+
normalMatrix: 'mat4x4<f32>',
|
|
39
|
+
camera: 'vec3<i32>'
|
|
40
|
+
}
|
|
41
|
+
};
|
|
@@ -5,38 +5,30 @@
|
|
|
5
5
|
import {glsl} from '../../../lib/glsl-utils/highlight';
|
|
6
6
|
|
|
7
7
|
export const vs = glsl`\
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
mat4 u_ModelMatrix;
|
|
11
|
-
mat4 u_NormalMatrix;
|
|
12
|
-
// Projection
|
|
13
|
-
vec3 u_Camera;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
varying vec3 pbr_vPosition;
|
|
17
|
-
varying vec2 pbr_vUV;
|
|
8
|
+
out vec3 pbr_vPosition;
|
|
9
|
+
out vec2 pbr_vUV;
|
|
18
10
|
|
|
19
11
|
#ifdef HAS_NORMALS
|
|
20
12
|
# ifdef HAS_TANGENTS
|
|
21
|
-
|
|
13
|
+
out mat3 pbr_vTBN;
|
|
22
14
|
# else
|
|
23
|
-
|
|
15
|
+
out vec3 pbr_vNormal;
|
|
24
16
|
# endif
|
|
25
17
|
#endif
|
|
26
18
|
|
|
27
19
|
void pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, vec2 uv)
|
|
28
20
|
{
|
|
29
|
-
vec4 pos =
|
|
21
|
+
vec4 pos = pbrProjection.modelMatrix * position;
|
|
30
22
|
pbr_vPosition = vec3(pos.xyz) / pos.w;
|
|
31
23
|
|
|
32
24
|
#ifdef HAS_NORMALS
|
|
33
25
|
#ifdef HAS_TANGENTS
|
|
34
|
-
vec3 normalW = normalize(vec3(
|
|
35
|
-
vec3 tangentW = normalize(vec3(
|
|
26
|
+
vec3 normalW = normalize(vec3(pbrProjection.normalMatrix * vec4(normal.xyz, 0.0)));
|
|
27
|
+
vec3 tangentW = normalize(vec3(pbrProjection.modelMatrix * vec4(tangent.xyz, 0.0)));
|
|
36
28
|
vec3 bitangentW = cross(normalW, tangentW) * tangent.w;
|
|
37
29
|
pbr_vTBN = mat3(tangentW, bitangentW, normalW);
|
|
38
30
|
#else // HAS_TANGENTS != 1
|
|
39
|
-
pbr_vNormal = normalize(vec3(
|
|
31
|
+
pbr_vNormal = normalize(vec3(pbrProjection.modelMatrix * vec4(normal.xyz, 0.0)));
|
|
40
32
|
#endif
|
|
41
33
|
#endif
|
|
42
34
|
|
|
@@ -42,6 +42,6 @@ export const phongMaterial: ShaderModule<PhongMaterialProps> = {
|
|
|
42
42
|
if (uniforms.specularColor) {
|
|
43
43
|
uniforms.specularColor = uniforms.specularColor.map(x => x / 255) as NumberArray3;
|
|
44
44
|
}
|
|
45
|
-
return {...phongMaterial.defaultUniforms, ...
|
|
45
|
+
return {...phongMaterial.defaultUniforms, ...uniforms};
|
|
46
46
|
}
|
|
47
47
|
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pbr-uniforms-glsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/pbr-material/pbr-uniforms-glsl.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,mBAAmB,QA8D/B,CAAC"}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
// luma.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
import { glsl } from "../../../lib/glsl-utils/highlight.js";
|
|
5
|
-
export const pbrMaterialUniforms = `\
|
|
6
|
-
uniform Projection {
|
|
7
|
-
vec3 u_Camera;
|
|
8
|
-
};
|
|
9
|
-
uniform pbrMaterialUniforms {
|
|
10
|
-
bool unlit;
|
|
11
|
-
bool baseColorMapEnabled;
|
|
12
|
-
vec4 baseColorFactor;
|
|
13
|
-
bool normalMapEnabled;
|
|
14
|
-
float normalScale;
|
|
15
|
-
bool emissiveMapEnabled;
|
|
16
|
-
vec3 emissiveFactor;
|
|
17
|
-
vec2 metallicRoughnessValues;
|
|
18
|
-
bool metallicRoughnessMapEnabled;
|
|
19
|
-
bool occlusionMapEnabled;
|
|
20
|
-
float occlusionStrength;
|
|
21
|
-
bool alphaCutoffEnabled;
|
|
22
|
-
float alphaCutoff;
|
|
23
|
-
bool IBLenabled;
|
|
24
|
-
vec2 scaleIBLAmbient;
|
|
25
|
-
vec4 scaleDiffBaseMR;
|
|
26
|
-
vec4 scaleFGDSpec;
|
|
27
|
-
};
|
|
28
|
-
#ifdef HAS_BASECOLORMAP
|
|
29
|
-
uniform sampler2D u_BaseColorSampler;
|
|
30
|
-
#endif
|
|
31
|
-
#ifdef HAS_NORMALMAP
|
|
32
|
-
uniform sampler2D u_NormalSampler;
|
|
33
|
-
#endif
|
|
34
|
-
#ifdef HAS_EMISSIVEMAP
|
|
35
|
-
uniform sampler2D u_EmissiveSampler;
|
|
36
|
-
#endif
|
|
37
|
-
#ifdef HAS_METALROUGHNESSMAP
|
|
38
|
-
uniform sampler2D u_MetallicRoughnessSampler;
|
|
39
|
-
#endif
|
|
40
|
-
#ifdef HAS_OCCLUSIONMAP
|
|
41
|
-
uniform sampler2D u_OcclusionSampler;
|
|
42
|
-
#endif
|
|
43
|
-
#ifdef USE_IBL
|
|
44
|
-
uniform samplerCube u_DiffuseEnvSampler;
|
|
45
|
-
uniform samplerCube u_SpecularEnvSampler;
|
|
46
|
-
uniform sampler2D u_brdfLUT;
|
|
47
|
-
#endif
|
|
48
|
-
`;
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
// luma.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import {glsl} from '../../../lib/glsl-utils/highlight';
|
|
6
|
-
|
|
7
|
-
export const pbrMaterialUniforms = glsl`\
|
|
8
|
-
uniform Projection {
|
|
9
|
-
// Projection
|
|
10
|
-
vec3 u_Camera;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
uniform pbrMaterialUniforms {
|
|
14
|
-
// Material is unlit
|
|
15
|
-
bool unlit;
|
|
16
|
-
|
|
17
|
-
// Base color map
|
|
18
|
-
bool baseColorMapEnabled;
|
|
19
|
-
vec4 baseColorFactor;
|
|
20
|
-
|
|
21
|
-
bool normalMapEnabled;
|
|
22
|
-
float normalScale; // #ifdef HAS_NORMALMAP
|
|
23
|
-
|
|
24
|
-
bool emissiveMapEnabled;
|
|
25
|
-
vec3 emissiveFactor; // #ifdef HAS_EMISSIVEMAP
|
|
26
|
-
|
|
27
|
-
vec2 metallicRoughnessValues;
|
|
28
|
-
bool metallicRoughnessMapEnabled;
|
|
29
|
-
|
|
30
|
-
bool occlusionMapEnabled;
|
|
31
|
-
float occlusionStrength; // #ifdef HAS_OCCLUSIONMAP
|
|
32
|
-
|
|
33
|
-
bool alphaCutoffEnabled;
|
|
34
|
-
float alphaCutoff; // #ifdef ALPHA_CUTOFF
|
|
35
|
-
|
|
36
|
-
// IBL
|
|
37
|
-
bool IBLenabled;
|
|
38
|
-
vec2 scaleIBLAmbient; // #ifdef USE_IBL
|
|
39
|
-
|
|
40
|
-
// debugging flags used for shader output of intermediate PBR variables
|
|
41
|
-
// #ifdef PBR_DEBUG
|
|
42
|
-
vec4 scaleDiffBaseMR;
|
|
43
|
-
vec4 scaleFGDSpec;
|
|
44
|
-
// #endif
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
// Samplers
|
|
48
|
-
#ifdef HAS_BASECOLORMAP
|
|
49
|
-
uniform sampler2D u_BaseColorSampler;
|
|
50
|
-
#endif
|
|
51
|
-
#ifdef HAS_NORMALMAP
|
|
52
|
-
uniform sampler2D u_NormalSampler;
|
|
53
|
-
#endif
|
|
54
|
-
#ifdef HAS_EMISSIVEMAP
|
|
55
|
-
uniform sampler2D u_EmissiveSampler;
|
|
56
|
-
#endif
|
|
57
|
-
#ifdef HAS_METALROUGHNESSMAP
|
|
58
|
-
uniform sampler2D u_MetallicRoughnessSampler;
|
|
59
|
-
#endif
|
|
60
|
-
#ifdef HAS_OCCLUSIONMAP
|
|
61
|
-
uniform sampler2D u_OcclusionSampler;
|
|
62
|
-
#endif
|
|
63
|
-
#ifdef USE_IBL
|
|
64
|
-
uniform samplerCube u_DiffuseEnvSampler;
|
|
65
|
-
uniform samplerCube u_SpecularEnvSampler;
|
|
66
|
-
uniform sampler2D u_brdfLUT;
|
|
67
|
-
#endif
|
|
68
|
-
|
|
69
|
-
`;
|