Shader compilation error when loading GLTF model using AssetContainer

I found a weird bug that only happens in certain conditions.

this is an error message

BJS - [13:25:19]: Offending line [646] in fragment code: refractionIntensity*=refractionIntensityMap.r; logger.js:56:30
BJS - [13:25:19]: Error: FRAGMENT SHADER ERROR: 0:646: 'refractionIntensity' : undeclared identifier
ERROR: 0:646: 'assign' : l-value required (can't modify a const)

If you export a mesh with a material with a Transmisson texture in the blender to GLTF
the problem will be reproduced.

Here’s a glb file that reproduces that error.

gltf_load_test.zip (634.8 KB)

This error can only be reproduced by loading using the asset container.
The code is as follows:

const assetContainer = await SceneLoader.LoadAssetContainerAsync("res/gltf_load_test.glb");
assetContainer.addAllToScene();

If you run addAllToScene in setTimeout, there will be no problems.

const assetContainer = await SceneLoader.LoadAssetContainerAsync("res/gltf_load_test.glb");
setTimeout(() => {
    assetContainer.addAllToScene();
}, 1000);

There is no error even if you use the SceneLoader.Append

SceneLoader.Append("res/gltf_load_test.glb",);

I don’t know exactly what the problem is, but I presume it’s a problem related to refraction.

When I analyzed the code to find the cause, I found one oddity: in the pbrSubSurfaceConfiguration, _isRefractionEnabled is initialized to false and I couldn’t find any code to override it to true anywhere. I think it’s probably related to this bug.

https://github.com/BabylonJS/Babylon.js/blob/d24425cb89c225a710da15a1ba4be3ba8b4ca7d3/packages/dev/core/src/Materials/PBR/pbrSubSurfaceConfiguration.ts#L68

Thank you in advance for your help.

This PR will fix the problem:

3 Likes