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