Texture blinks when change texture

hi
I have some problems when i change the texture for the first time,the new texture will be highlighted and then back to normal.This only happens once when switching to a new texture, and lasts about a frame.
Here is my code to change the texture.

new BABYLON.Texture(local_path, scene, true, false, 3, ()=>{
mesh.material.albedoTexture = texture;
})

I wish the switch could be more natural,what should i do?

I tried assetsManager but couldn’t avoid it.

let assetsManager = new BABYLON.AssetsManager(scene);
let textureTask = assetsManager.addTextureTask(“bottom task”, local_path, true, false)
textureTask.onSuccess = (task)=>{
mesh.material.albedoTexture = task.texture;
};
assetsManager.useDefaultLoadingScreen = false;
assetsManager.load();

Welcome aboard!

Are you able to provide a repro?

It should normally not happen as when you set the albedo texture the shader has to be recompiled to create a new effect, but as long as the new effect is not ready we are reusing the existing current effect. So the switching from the previous effect to the new one should be instantaneous without any rendering artifacts.

My example didn’t reproduce, I’ll try it later

It flashes when it is replaced for the first time.I took a screenshot of that frame.The one on the left is the highlighted frame, and the one on the right is the final result. You can run several times to see the effect.

1 Like

There’s a security problem with the PG:

:disappointed_relieved: well…I recorded a video

Maybe you should load texture first, then load scene. So texture is ready to be applied immediately.

It doesn’t happen if I use StandardMaterial and emissiveTexture. But I need use pbr and albedoTexture

This seems to be caused by gammaSpace.Error frame gammaSpace is equal to false

I have a new discovery. If I replace the texture in the model, there will be flickering. If I replace the texture given in the code, there is no flickering.

I think I reproduce the problem here:

And it is fixed here:

Can you try to add this code in your PG and let us know if that fixes the problem:

    BABYLON.SceneLoader.OnPluginActivatedObservable.add((plugin) => {
        if (plugin.name === "gltf") {
            plugin.useSRGBBuffers = false;
        }
    });

If the problem is fixed, then it could be related to the bug in Angle where sRGB texture loading is using a slow path: see Glb with huge texture load much slower in 5.0.0 - #3 by carolhmj and Added option to force sRGB Buffer support state by RaananW · Pull Request #11758 · BabylonJS/Babylon.js · GitHub.

2 Likes

Thank you so much! Doing this really solves the texture flickering problem!

1 Like