@luma.gl/gltf 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 +420 -239
- package/dist/dist.min.js +168 -122
- package/dist/gltf/create-gltf-model.d.ts.map +1 -1
- package/dist/gltf/create-gltf-model.js +12 -6
- package/dist/index.cjs +31 -25
- package/dist/index.cjs.map +2 -2
- package/dist/pbr/parse-pbr-material.d.ts +4 -3
- package/dist/pbr/parse-pbr-material.d.ts.map +1 -1
- package/dist/pbr/parse-pbr-material.js +41 -40
- package/package.json +3 -3
- package/src/gltf/create-gltf-model.ts +15 -6
- package/src/pbr/parse-pbr-material.ts +51 -43
|
@@ -26,8 +26,8 @@ export function parsePBRMaterial(device, material, attributes, options) {
|
|
|
26
26
|
bindings: {},
|
|
27
27
|
uniforms: {
|
|
28
28
|
// TODO: find better values?
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
camera: [0, 0, 0], // Model should override
|
|
30
|
+
metallicRoughnessValues: [1, 1] // Default is 1 and 1
|
|
31
31
|
},
|
|
32
32
|
parameters: {},
|
|
33
33
|
glParameters: {},
|
|
@@ -37,16 +37,17 @@ export function parsePBRMaterial(device, material, attributes, options) {
|
|
|
37
37
|
parsedMaterial.defines.USE_TEX_LOD = 1;
|
|
38
38
|
const { imageBasedLightingEnvironment } = options;
|
|
39
39
|
if (imageBasedLightingEnvironment) {
|
|
40
|
-
parsedMaterial.bindings.
|
|
41
|
-
parsedMaterial.bindings.
|
|
42
|
-
|
|
43
|
-
parsedMaterial.
|
|
40
|
+
parsedMaterial.bindings.pbr_diffuseEnvSampler = imageBasedLightingEnvironment.diffuseEnvSampler;
|
|
41
|
+
parsedMaterial.bindings.pbr_specularEnvSampler =
|
|
42
|
+
imageBasedLightingEnvironment.specularEnvSampler;
|
|
43
|
+
parsedMaterial.bindings.pbr_BrdfLUT = imageBasedLightingEnvironment.brdfLutTexture;
|
|
44
|
+
parsedMaterial.uniforms.scaleIBLAmbient = [1, 1];
|
|
44
45
|
}
|
|
45
46
|
if (options?.pbrDebug) {
|
|
46
47
|
parsedMaterial.defines.PBR_DEBUG = 1;
|
|
47
48
|
// Override final color for reference app visualization of various parameters in the lighting equation.
|
|
48
|
-
parsedMaterial.uniforms.
|
|
49
|
-
parsedMaterial.uniforms.
|
|
49
|
+
parsedMaterial.uniforms.scaleDiffBaseMR = [0, 0, 0, 0];
|
|
50
|
+
parsedMaterial.uniforms.scaleFGDSpec = [0, 0, 0, 0];
|
|
50
51
|
}
|
|
51
52
|
if (attributes.NORMAL)
|
|
52
53
|
parsedMaterial.defines.HAS_NORMALS = 1;
|
|
@@ -65,29 +66,29 @@ export function parsePBRMaterial(device, material, attributes, options) {
|
|
|
65
66
|
}
|
|
66
67
|
/** Parse GLTF material record */
|
|
67
68
|
function parseMaterial(device, material, parsedMaterial) {
|
|
68
|
-
parsedMaterial.uniforms.
|
|
69
|
+
parsedMaterial.uniforms.unlit = Boolean(material.unlit);
|
|
69
70
|
if (material.pbrMetallicRoughness) {
|
|
70
71
|
parsePbrMetallicRoughness(device, material.pbrMetallicRoughness, parsedMaterial);
|
|
71
72
|
}
|
|
72
73
|
if (material.normalTexture) {
|
|
73
|
-
addTexture(device, material.normalTexture, '
|
|
74
|
+
addTexture(device, material.normalTexture, 'pbr_normalSampler', 'HAS_NORMALMAP', parsedMaterial);
|
|
74
75
|
const { scale = 1 } = material.normalTexture;
|
|
75
|
-
parsedMaterial.uniforms.
|
|
76
|
+
parsedMaterial.uniforms.normalScale = scale;
|
|
76
77
|
}
|
|
77
78
|
if (material.occlusionTexture) {
|
|
78
|
-
addTexture(device, material.occlusionTexture, '
|
|
79
|
+
addTexture(device, material.occlusionTexture, 'pbr_occlusionSampler', 'HAS_OCCLUSIONMAP', parsedMaterial);
|
|
79
80
|
const { strength = 1 } = material.occlusionTexture;
|
|
80
|
-
parsedMaterial.uniforms.
|
|
81
|
+
parsedMaterial.uniforms.occlusionStrength = strength;
|
|
81
82
|
}
|
|
82
83
|
if (material.emissiveTexture) {
|
|
83
|
-
addTexture(device, material.emissiveTexture, '
|
|
84
|
-
parsedMaterial.uniforms.
|
|
84
|
+
addTexture(device, material.emissiveTexture, 'pbr_emissiveSampler', 'HAS_EMISSIVEMAP', parsedMaterial);
|
|
85
|
+
parsedMaterial.uniforms.emissiveFactor = material.emissiveFactor || [0, 0, 0];
|
|
85
86
|
}
|
|
86
87
|
switch (material.alphaMode) {
|
|
87
88
|
case 'MASK':
|
|
88
89
|
const { alphaCutoff = 0.5 } = material;
|
|
89
90
|
parsedMaterial.defines.ALPHA_CUTOFF = 1;
|
|
90
|
-
parsedMaterial.uniforms.
|
|
91
|
+
parsedMaterial.uniforms.alphaCutoff = alphaCutoff;
|
|
91
92
|
break;
|
|
92
93
|
case 'BLEND':
|
|
93
94
|
log.warn('glTF BLEND alphaMode might not work well because it requires mesh sorting')();
|
|
@@ -113,14 +114,14 @@ function parseMaterial(device, material, parsedMaterial) {
|
|
|
113
114
|
/** Parse GLTF material sub record */
|
|
114
115
|
function parsePbrMetallicRoughness(device, pbrMetallicRoughness, parsedMaterial) {
|
|
115
116
|
if (pbrMetallicRoughness.baseColorTexture) {
|
|
116
|
-
addTexture(device, pbrMetallicRoughness.baseColorTexture, '
|
|
117
|
+
addTexture(device, pbrMetallicRoughness.baseColorTexture, 'pbr_baseColorSampler', 'HAS_BASECOLORMAP', parsedMaterial);
|
|
117
118
|
}
|
|
118
|
-
parsedMaterial.uniforms.
|
|
119
|
+
parsedMaterial.uniforms.baseColorFactor = pbrMetallicRoughness.baseColorFactor || [1, 1, 1, 1];
|
|
119
120
|
if (pbrMetallicRoughness.metallicRoughnessTexture) {
|
|
120
|
-
addTexture(device, pbrMetallicRoughness.metallicRoughnessTexture, '
|
|
121
|
+
addTexture(device, pbrMetallicRoughness.metallicRoughnessTexture, 'pbr_metallicRoughnessSampler', 'HAS_METALROUGHNESSMAP', parsedMaterial);
|
|
121
122
|
}
|
|
122
123
|
const { metallicFactor = 1, roughnessFactor = 1 } = pbrMetallicRoughness;
|
|
123
|
-
parsedMaterial.uniforms.
|
|
124
|
+
parsedMaterial.uniforms.metallicRoughnessValues = [metallicFactor, roughnessFactor];
|
|
124
125
|
}
|
|
125
126
|
/** Create a texture from a glTF texture/sampler/image combo and add it to bindings */
|
|
126
127
|
function addTexture(device, gltfTexture, uniformName, define = null, parsedMaterial) {
|
|
@@ -186,9 +187,9 @@ export class PBRMaterialParser {
|
|
|
186
187
|
|
|
187
188
|
this.uniforms = {
|
|
188
189
|
// TODO: find better values?
|
|
189
|
-
|
|
190
|
+
camera: [0, 0, 0], // Model should override
|
|
190
191
|
|
|
191
|
-
|
|
192
|
+
metallicRoughnessValues: [1, 1] // Default is 1 and 1
|
|
192
193
|
};
|
|
193
194
|
|
|
194
195
|
this.bindings = {};
|
|
@@ -197,17 +198,17 @@ export class PBRMaterialParser {
|
|
|
197
198
|
this.generatedTextures = [];
|
|
198
199
|
|
|
199
200
|
if (imageBasedLightingEnvironment) {
|
|
200
|
-
this.bindings.
|
|
201
|
-
this.bindings.
|
|
202
|
-
this.bindings.
|
|
203
|
-
this.uniforms.
|
|
201
|
+
this.bindings.pbr_diffuseEnvSampler = imageBasedLightingEnvironment.getDiffuseEnvSampler();
|
|
202
|
+
this.bindings.pbr_specularEnvSampler = imageBasedLightingEnvironment.getSpecularEnvSampler();
|
|
203
|
+
this.bindings.pbr_BrdfLUT = imageBasedLightingEnvironment.getBrdfTexture();
|
|
204
|
+
this.uniforms.scaleIBLAmbient = [1, 1];
|
|
204
205
|
}
|
|
205
206
|
|
|
206
207
|
if (pbrDebug) {
|
|
207
208
|
// Override final color for reference app visualization
|
|
208
209
|
// of various parameters in the lighting equation.
|
|
209
|
-
this.uniforms.
|
|
210
|
-
this.uniforms.
|
|
210
|
+
this.uniforms.scaleDiffBaseMR = [0, 0, 0, 0];
|
|
211
|
+
this.uniforms.scaleFGDSpec = [0, 0, 0, 0];
|
|
211
212
|
}
|
|
212
213
|
|
|
213
214
|
this.defineIfPresent(attributes.NORMAL, 'HAS_NORMALS');
|
|
@@ -239,31 +240,31 @@ export class PBRMaterialParser {
|
|
|
239
240
|
|
|
240
241
|
/** Parse GLTF material record *
|
|
241
242
|
parseMaterial(material) {
|
|
242
|
-
this.uniforms.
|
|
243
|
+
this.uniforms.unlit = Boolean(material.unlit);
|
|
243
244
|
|
|
244
245
|
if (material.pbrMetallicRoughness) {
|
|
245
246
|
this.parsePbrMetallicRoughness(material.pbrMetallicRoughness);
|
|
246
247
|
}
|
|
247
248
|
if (material.normalTexture) {
|
|
248
|
-
this.addTexture(material.normalTexture, '
|
|
249
|
+
this.addTexture(material.normalTexture, 'pbr_normalSampler', 'HAS_NORMALMAP');
|
|
249
250
|
|
|
250
251
|
const {scale = 1} = material.normalTexture;
|
|
251
|
-
this.uniforms.
|
|
252
|
+
this.uniforms.normalScale = scale;
|
|
252
253
|
}
|
|
253
254
|
if (material.occlusionTexture) {
|
|
254
|
-
this.addTexture(material.occlusionTexture, '
|
|
255
|
+
this.addTexture(material.occlusionTexture, 'pbr_occlusionSampler', 'HAS_OCCLUSIONMAP');
|
|
255
256
|
|
|
256
257
|
const {strength = 1} = material.occlusionTexture;
|
|
257
|
-
this.uniforms.
|
|
258
|
+
this.uniforms.occlusionStrength = strength;
|
|
258
259
|
}
|
|
259
260
|
if (material.emissiveTexture) {
|
|
260
|
-
this.addTexture(material.emissiveTexture, '
|
|
261
|
-
this.uniforms.
|
|
261
|
+
this.addTexture(material.emissiveTexture, 'pbr_emissiveSampler', 'HAS_EMISSIVEMAP');
|
|
262
|
+
this.uniforms.emissiveFactor = material.emissiveFactor || [0, 0, 0];
|
|
262
263
|
}
|
|
263
264
|
if (material.alphaMode === 'MASK') {
|
|
264
265
|
const {alphaCutoff = 0.5} = material;
|
|
265
266
|
this.defines.ALPHA_CUTOFF = 1;
|
|
266
|
-
this.uniforms.
|
|
267
|
+
this.uniforms.alphaCutoff = alphaCutoff;
|
|
267
268
|
} else if (material.alphaMode === 'BLEND') {
|
|
268
269
|
log.warn('BLEND alphaMode might not work well because it requires mesh sorting')();
|
|
269
270
|
Object.assign(this.parameters, {
|
|
@@ -279,21 +280,21 @@ export class PBRMaterialParser {
|
|
|
279
280
|
if (pbrMetallicRoughness.baseColorTexture) {
|
|
280
281
|
this.addTexture(
|
|
281
282
|
pbrMetallicRoughness.baseColorTexture,
|
|
282
|
-
'
|
|
283
|
+
'pbr_baseColorSampler',
|
|
283
284
|
'HAS_BASECOLORMAP'
|
|
284
285
|
);
|
|
285
286
|
}
|
|
286
|
-
this.uniforms.
|
|
287
|
+
this.uniforms.baseColorFactor = pbrMetallicRoughness.baseColorFactor || [1, 1, 1, 1];
|
|
287
288
|
|
|
288
289
|
if (pbrMetallicRoughness.metallicRoughnessTexture) {
|
|
289
290
|
this.addTexture(
|
|
290
291
|
pbrMetallicRoughness.metallicRoughnessTexture,
|
|
291
|
-
'
|
|
292
|
+
'pbr_metallicRoughnessSampler',
|
|
292
293
|
'HAS_METALROUGHNESSMAP'
|
|
293
294
|
);
|
|
294
295
|
}
|
|
295
296
|
const {metallicFactor = 1, roughnessFactor = 1} = pbrMetallicRoughness;
|
|
296
|
-
this.uniforms.
|
|
297
|
+
this.uniforms.metallicRoughnessValues = [metallicFactor, roughnessFactor];
|
|
297
298
|
}
|
|
298
299
|
|
|
299
300
|
/** Create a texture from a glTF texture/sampler/image combo and add it to bindings *
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luma.gl/gltf",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.24",
|
|
4
4
|
"description": "glTF support for luma.gl",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@loaders.gl/textures": "^4.2.0",
|
|
49
|
-
"@luma.gl/shadertools": "9.0.
|
|
49
|
+
"@luma.gl/shadertools": "9.0.24",
|
|
50
50
|
"@math.gl/core": "^4.0.0"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "7fa4bc29cb5b4eb1997ac33a37139d2186c0a7f0"
|
|
53
53
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {Device, RenderPipelineParameters, log} from '@luma.gl/core';
|
|
2
|
-
import {
|
|
2
|
+
import {pbrMaterial} from '@luma.gl/shadertools';
|
|
3
3
|
import {Geometry, Model, ModelNode, ModelProps} from '@luma.gl/engine';
|
|
4
4
|
import {ParsePBRMaterialOptions, parsePBRMaterial} from '../pbr/parse-pbr-material';
|
|
5
|
+
import {ShaderModule} from '@luma.gl/shadertools';
|
|
5
6
|
|
|
6
7
|
// TODO rename attributes to POSITION/NORMAL etc
|
|
7
8
|
// See gpu-geometry.ts: getAttributeBuffersFromGeometry()
|
|
@@ -48,7 +49,7 @@ const vs = `
|
|
|
48
49
|
#endif
|
|
49
50
|
|
|
50
51
|
pbr_setPositionNormalTangentUV(positions, _NORMAL, _TANGENT, _TEXCOORD_0);
|
|
51
|
-
gl_Position =
|
|
52
|
+
gl_Position = pbrProjection.modelViewProjectionMatrix * positions;
|
|
52
53
|
}
|
|
53
54
|
`;
|
|
54
55
|
|
|
@@ -100,18 +101,26 @@ export function createGLTFModel(device: Device, options: CreateGLTFModelOptions)
|
|
|
100
101
|
geometry,
|
|
101
102
|
topology: geometry.topology,
|
|
102
103
|
vertexCount,
|
|
103
|
-
modules: [
|
|
104
|
+
modules: [pbrMaterial as unknown as ShaderModule],
|
|
104
105
|
vs: addVersionToShader(device, vs),
|
|
105
106
|
fs: addVersionToShader(device, fs),
|
|
107
|
+
// TODO can this be removed? Does deck need it?
|
|
106
108
|
...modelOptions,
|
|
107
109
|
|
|
108
|
-
bindings: {...parsedMaterial.bindings, ...modelOptions.bindings},
|
|
109
110
|
defines: {...parsedMaterial.defines, ...modelOptions.defines},
|
|
110
|
-
parameters: {...parameters, ...parsedMaterial.parameters, ...modelOptions.parameters}
|
|
111
|
-
uniforms: {...parsedMaterial.uniforms, ...modelOptions.uniforms}
|
|
111
|
+
parameters: {...parameters, ...parsedMaterial.parameters, ...modelOptions.parameters}
|
|
112
112
|
};
|
|
113
113
|
|
|
114
114
|
const model = new Model(device, modelProps);
|
|
115
|
+
|
|
116
|
+
const {camera, ...pbrMaterialProps} = {
|
|
117
|
+
...parsedMaterial.uniforms,
|
|
118
|
+
...modelOptions.uniforms,
|
|
119
|
+
...parsedMaterial.bindings,
|
|
120
|
+
...modelOptions.bindings
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
model.shaderInputs.setProps({pbrMaterial: pbrMaterialProps, pbrProjection: {camera}});
|
|
115
124
|
return new ModelNode({managedResources, model});
|
|
116
125
|
}
|
|
117
126
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type {Device, Texture,
|
|
1
|
+
import type {Device, Texture, Parameters} from '@luma.gl/core';
|
|
2
2
|
import {log} from '@luma.gl/core';
|
|
3
3
|
import {PBREnvironment} from './pbr-environment';
|
|
4
|
+
import {PBRMaterialBindings, PBRMaterialUniforms, PBRProjectionProps} from '@luma.gl/shadertools';
|
|
4
5
|
|
|
5
6
|
/* eslint-disable camelcase */
|
|
6
7
|
|
|
@@ -17,8 +18,8 @@ export type ParsePBRMaterialOptions = {
|
|
|
17
18
|
|
|
18
19
|
export type ParsedPBRMaterial = {
|
|
19
20
|
readonly defines: Record<string, number | boolean>;
|
|
20
|
-
readonly bindings:
|
|
21
|
-
readonly uniforms:
|
|
21
|
+
readonly bindings: Partial<PBRMaterialBindings>;
|
|
22
|
+
readonly uniforms: Partial<PBRProjectionProps & PBRMaterialUniforms>;
|
|
22
23
|
readonly parameters: Parameters;
|
|
23
24
|
readonly glParameters: Record<string, any>;
|
|
24
25
|
/** List of all generated textures, makes it easy to destroy them later */
|
|
@@ -57,9 +58,9 @@ export function parsePBRMaterial(
|
|
|
57
58
|
bindings: {},
|
|
58
59
|
uniforms: {
|
|
59
60
|
// TODO: find better values?
|
|
60
|
-
|
|
61
|
+
camera: [0, 0, 0], // Model should override
|
|
61
62
|
|
|
62
|
-
|
|
63
|
+
metallicRoughnessValues: [1, 1] // Default is 1 and 1
|
|
63
64
|
},
|
|
64
65
|
parameters: {},
|
|
65
66
|
glParameters: {},
|
|
@@ -71,17 +72,18 @@ export function parsePBRMaterial(
|
|
|
71
72
|
|
|
72
73
|
const {imageBasedLightingEnvironment} = options;
|
|
73
74
|
if (imageBasedLightingEnvironment) {
|
|
74
|
-
parsedMaterial.bindings.
|
|
75
|
-
parsedMaterial.bindings.
|
|
76
|
-
|
|
77
|
-
parsedMaterial.
|
|
75
|
+
parsedMaterial.bindings.pbr_diffuseEnvSampler = imageBasedLightingEnvironment.diffuseEnvSampler;
|
|
76
|
+
parsedMaterial.bindings.pbr_specularEnvSampler =
|
|
77
|
+
imageBasedLightingEnvironment.specularEnvSampler;
|
|
78
|
+
parsedMaterial.bindings.pbr_BrdfLUT = imageBasedLightingEnvironment.brdfLutTexture;
|
|
79
|
+
parsedMaterial.uniforms.scaleIBLAmbient = [1, 1];
|
|
78
80
|
}
|
|
79
81
|
|
|
80
82
|
if (options?.pbrDebug) {
|
|
81
83
|
parsedMaterial.defines.PBR_DEBUG = 1;
|
|
82
84
|
// Override final color for reference app visualization of various parameters in the lighting equation.
|
|
83
|
-
parsedMaterial.uniforms.
|
|
84
|
-
parsedMaterial.uniforms.
|
|
85
|
+
parsedMaterial.uniforms.scaleDiffBaseMR = [0, 0, 0, 0];
|
|
86
|
+
parsedMaterial.uniforms.scaleFGDSpec = [0, 0, 0, 0];
|
|
85
87
|
}
|
|
86
88
|
|
|
87
89
|
if (attributes.NORMAL) parsedMaterial.defines.HAS_NORMALS = 1;
|
|
@@ -100,45 +102,51 @@ export function parsePBRMaterial(
|
|
|
100
102
|
|
|
101
103
|
/** Parse GLTF material record */
|
|
102
104
|
function parseMaterial(device: Device, material, parsedMaterial: ParsedPBRMaterial): void {
|
|
103
|
-
parsedMaterial.uniforms.
|
|
105
|
+
parsedMaterial.uniforms.unlit = Boolean(material.unlit);
|
|
104
106
|
|
|
105
107
|
if (material.pbrMetallicRoughness) {
|
|
106
108
|
parsePbrMetallicRoughness(device, material.pbrMetallicRoughness, parsedMaterial);
|
|
107
109
|
}
|
|
108
110
|
if (material.normalTexture) {
|
|
109
|
-
addTexture(
|
|
111
|
+
addTexture(
|
|
112
|
+
device,
|
|
113
|
+
material.normalTexture,
|
|
114
|
+
'pbr_normalSampler',
|
|
115
|
+
'HAS_NORMALMAP',
|
|
116
|
+
parsedMaterial
|
|
117
|
+
);
|
|
110
118
|
|
|
111
119
|
const {scale = 1} = material.normalTexture;
|
|
112
|
-
parsedMaterial.uniforms.
|
|
120
|
+
parsedMaterial.uniforms.normalScale = scale;
|
|
113
121
|
}
|
|
114
122
|
if (material.occlusionTexture) {
|
|
115
123
|
addTexture(
|
|
116
124
|
device,
|
|
117
125
|
material.occlusionTexture,
|
|
118
|
-
'
|
|
126
|
+
'pbr_occlusionSampler',
|
|
119
127
|
'HAS_OCCLUSIONMAP',
|
|
120
128
|
parsedMaterial
|
|
121
129
|
);
|
|
122
130
|
|
|
123
131
|
const {strength = 1} = material.occlusionTexture;
|
|
124
|
-
parsedMaterial.uniforms.
|
|
132
|
+
parsedMaterial.uniforms.occlusionStrength = strength;
|
|
125
133
|
}
|
|
126
134
|
if (material.emissiveTexture) {
|
|
127
135
|
addTexture(
|
|
128
136
|
device,
|
|
129
137
|
material.emissiveTexture,
|
|
130
|
-
'
|
|
138
|
+
'pbr_emissiveSampler',
|
|
131
139
|
'HAS_EMISSIVEMAP',
|
|
132
140
|
parsedMaterial
|
|
133
141
|
);
|
|
134
|
-
parsedMaterial.uniforms.
|
|
142
|
+
parsedMaterial.uniforms.emissiveFactor = material.emissiveFactor || [0, 0, 0];
|
|
135
143
|
}
|
|
136
144
|
|
|
137
145
|
switch (material.alphaMode) {
|
|
138
146
|
case 'MASK':
|
|
139
147
|
const {alphaCutoff = 0.5} = material;
|
|
140
148
|
parsedMaterial.defines.ALPHA_CUTOFF = 1;
|
|
141
|
-
parsedMaterial.uniforms.
|
|
149
|
+
parsedMaterial.uniforms.alphaCutoff = alphaCutoff;
|
|
142
150
|
break;
|
|
143
151
|
case 'BLEND':
|
|
144
152
|
log.warn('glTF BLEND alphaMode might not work well because it requires mesh sorting')();
|
|
@@ -176,24 +184,24 @@ function parsePbrMetallicRoughness(
|
|
|
176
184
|
addTexture(
|
|
177
185
|
device,
|
|
178
186
|
pbrMetallicRoughness.baseColorTexture,
|
|
179
|
-
'
|
|
187
|
+
'pbr_baseColorSampler',
|
|
180
188
|
'HAS_BASECOLORMAP',
|
|
181
189
|
parsedMaterial
|
|
182
190
|
);
|
|
183
191
|
}
|
|
184
|
-
parsedMaterial.uniforms.
|
|
192
|
+
parsedMaterial.uniforms.baseColorFactor = pbrMetallicRoughness.baseColorFactor || [1, 1, 1, 1];
|
|
185
193
|
|
|
186
194
|
if (pbrMetallicRoughness.metallicRoughnessTexture) {
|
|
187
195
|
addTexture(
|
|
188
196
|
device,
|
|
189
197
|
pbrMetallicRoughness.metallicRoughnessTexture,
|
|
190
|
-
'
|
|
198
|
+
'pbr_metallicRoughnessSampler',
|
|
191
199
|
'HAS_METALROUGHNESSMAP',
|
|
192
200
|
parsedMaterial
|
|
193
201
|
);
|
|
194
202
|
}
|
|
195
203
|
const {metallicFactor = 1, roughnessFactor = 1} = pbrMetallicRoughness;
|
|
196
|
-
parsedMaterial.uniforms.
|
|
204
|
+
parsedMaterial.uniforms.metallicRoughnessValues = [metallicFactor, roughnessFactor];
|
|
197
205
|
}
|
|
198
206
|
|
|
199
207
|
/** Create a texture from a glTF texture/sampler/image combo and add it to bindings */
|
|
@@ -268,9 +276,9 @@ export class PBRMaterialParser {
|
|
|
268
276
|
|
|
269
277
|
this.uniforms = {
|
|
270
278
|
// TODO: find better values?
|
|
271
|
-
|
|
279
|
+
camera: [0, 0, 0], // Model should override
|
|
272
280
|
|
|
273
|
-
|
|
281
|
+
metallicRoughnessValues: [1, 1] // Default is 1 and 1
|
|
274
282
|
};
|
|
275
283
|
|
|
276
284
|
this.bindings = {};
|
|
@@ -279,17 +287,17 @@ export class PBRMaterialParser {
|
|
|
279
287
|
this.generatedTextures = [];
|
|
280
288
|
|
|
281
289
|
if (imageBasedLightingEnvironment) {
|
|
282
|
-
this.bindings.
|
|
283
|
-
this.bindings.
|
|
284
|
-
this.bindings.
|
|
285
|
-
this.uniforms.
|
|
290
|
+
this.bindings.pbr_diffuseEnvSampler = imageBasedLightingEnvironment.getDiffuseEnvSampler();
|
|
291
|
+
this.bindings.pbr_specularEnvSampler = imageBasedLightingEnvironment.getSpecularEnvSampler();
|
|
292
|
+
this.bindings.pbr_BrdfLUT = imageBasedLightingEnvironment.getBrdfTexture();
|
|
293
|
+
this.uniforms.scaleIBLAmbient = [1, 1];
|
|
286
294
|
}
|
|
287
295
|
|
|
288
296
|
if (pbrDebug) {
|
|
289
297
|
// Override final color for reference app visualization
|
|
290
298
|
// of various parameters in the lighting equation.
|
|
291
|
-
this.uniforms.
|
|
292
|
-
this.uniforms.
|
|
299
|
+
this.uniforms.scaleDiffBaseMR = [0, 0, 0, 0];
|
|
300
|
+
this.uniforms.scaleFGDSpec = [0, 0, 0, 0];
|
|
293
301
|
}
|
|
294
302
|
|
|
295
303
|
this.defineIfPresent(attributes.NORMAL, 'HAS_NORMALS');
|
|
@@ -321,31 +329,31 @@ export class PBRMaterialParser {
|
|
|
321
329
|
|
|
322
330
|
/** Parse GLTF material record *
|
|
323
331
|
parseMaterial(material) {
|
|
324
|
-
this.uniforms.
|
|
332
|
+
this.uniforms.unlit = Boolean(material.unlit);
|
|
325
333
|
|
|
326
334
|
if (material.pbrMetallicRoughness) {
|
|
327
335
|
this.parsePbrMetallicRoughness(material.pbrMetallicRoughness);
|
|
328
336
|
}
|
|
329
337
|
if (material.normalTexture) {
|
|
330
|
-
this.addTexture(material.normalTexture, '
|
|
338
|
+
this.addTexture(material.normalTexture, 'pbr_normalSampler', 'HAS_NORMALMAP');
|
|
331
339
|
|
|
332
340
|
const {scale = 1} = material.normalTexture;
|
|
333
|
-
this.uniforms.
|
|
341
|
+
this.uniforms.normalScale = scale;
|
|
334
342
|
}
|
|
335
343
|
if (material.occlusionTexture) {
|
|
336
|
-
this.addTexture(material.occlusionTexture, '
|
|
344
|
+
this.addTexture(material.occlusionTexture, 'pbr_occlusionSampler', 'HAS_OCCLUSIONMAP');
|
|
337
345
|
|
|
338
346
|
const {strength = 1} = material.occlusionTexture;
|
|
339
|
-
this.uniforms.
|
|
347
|
+
this.uniforms.occlusionStrength = strength;
|
|
340
348
|
}
|
|
341
349
|
if (material.emissiveTexture) {
|
|
342
|
-
this.addTexture(material.emissiveTexture, '
|
|
343
|
-
this.uniforms.
|
|
350
|
+
this.addTexture(material.emissiveTexture, 'pbr_emissiveSampler', 'HAS_EMISSIVEMAP');
|
|
351
|
+
this.uniforms.emissiveFactor = material.emissiveFactor || [0, 0, 0];
|
|
344
352
|
}
|
|
345
353
|
if (material.alphaMode === 'MASK') {
|
|
346
354
|
const {alphaCutoff = 0.5} = material;
|
|
347
355
|
this.defines.ALPHA_CUTOFF = 1;
|
|
348
|
-
this.uniforms.
|
|
356
|
+
this.uniforms.alphaCutoff = alphaCutoff;
|
|
349
357
|
} else if (material.alphaMode === 'BLEND') {
|
|
350
358
|
log.warn('BLEND alphaMode might not work well because it requires mesh sorting')();
|
|
351
359
|
Object.assign(this.parameters, {
|
|
@@ -361,21 +369,21 @@ export class PBRMaterialParser {
|
|
|
361
369
|
if (pbrMetallicRoughness.baseColorTexture) {
|
|
362
370
|
this.addTexture(
|
|
363
371
|
pbrMetallicRoughness.baseColorTexture,
|
|
364
|
-
'
|
|
372
|
+
'pbr_baseColorSampler',
|
|
365
373
|
'HAS_BASECOLORMAP'
|
|
366
374
|
);
|
|
367
375
|
}
|
|
368
|
-
this.uniforms.
|
|
376
|
+
this.uniforms.baseColorFactor = pbrMetallicRoughness.baseColorFactor || [1, 1, 1, 1];
|
|
369
377
|
|
|
370
378
|
if (pbrMetallicRoughness.metallicRoughnessTexture) {
|
|
371
379
|
this.addTexture(
|
|
372
380
|
pbrMetallicRoughness.metallicRoughnessTexture,
|
|
373
|
-
'
|
|
381
|
+
'pbr_metallicRoughnessSampler',
|
|
374
382
|
'HAS_METALROUGHNESSMAP'
|
|
375
383
|
);
|
|
376
384
|
}
|
|
377
385
|
const {metallicFactor = 1, roughnessFactor = 1} = pbrMetallicRoughness;
|
|
378
|
-
this.uniforms.
|
|
386
|
+
this.uniforms.metallicRoughnessValues = [metallicFactor, roughnessFactor];
|
|
379
387
|
}
|
|
380
388
|
|
|
381
389
|
/** Create a texture from a glTF texture/sampler/image combo and add it to bindings *
|