How to avoid using StandardMaterial to reduce bundle size, and getting rid of unwanted PBR files

Hi, I’ve noticed the ES6 docs say you could avoid importing StandardMaterial if you don’t need the default material.

By default, any mesh in a scene are using the scene defaultMaterial. With tree shaking you might not need this material so we do not force it as a dependency in the code. That said, would you need to use it, you can simply `import "@babylonjs/core/Materials/standardMaterial";` to ensure that the default material would be operationnal.

This is the case for me, but I’m not sure what to replace it with. I need to apply an image texture or colour texture (done via diffuseTexture at the moment), with nothing too fancy. With StandardMaterial I have been setting diffuseTexture.

Also, I have a large amount of PBR related files being included which I think is a result of me using “@babylonjs/loaders/glTF”. Is there a way of cutting down on these?

my output from source-map-explorer, a lot of the things I don’t think I need are on the right under shaders/materials

and for safe measure, my imports and source


As long as you are using gltf, you need PBR materials as this is the base material for it.

About StandardMaterial, You could not import it and instead use a PBRMaterial in unlit mode:

pbr.albedoTexture  = ...;
pbr.unlit = true;
1 Like

Thanks! I wasn’t aware gLTF used PBR materials.

Is there a performance cost to using PBRMaterial like this instead of StandardMaterial?
And if there is, is there a way to swap it out for a standard material on my gLTF imported meshes? Currently my application is CPU bound with most time being used by rendering, so I don’t want to make it worse :grinning_face_with_smiling_eyes:

1 Like

It should be fine in unlit mode and cpu side should be similar to standard material. I would advise to freeze materials/meshes as much as you can.

1 Like