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