Texture preloading

Hey boys & girls,
new year, … same me :slight_smile:

I read a lot of topics about texture preloading and workers in the last few hours and I think I’m close to what I want but still something missing.
So the idea is simple, first load the scene with some low quality textures and later update them. And I tried to do this in a lot of ways, … 2 of them are pretty close to what I want, but still a little bit of fps drops when the texture is updated. And I’m curious if this is the maximum we can do here or there are still anything else I can do.

So, first I made this straight forward example ( actualy after few attempts :)))

Later I read about workers and I made this

where I tried to follow @Evgeni_Popov advice from here but for some reasons this is struggling to follow.

Between them I tried other options, like sent all of them together to and from worker, or create the babylon texture directly in worker, or try to updateURL of existing texture with the result from worker, but without success.

Any insight is welcome!

this is exactly how the msft_lod is currently working IIRC cc @bghgary

MSFT_lod as in this example from the doc also has FPS drop when textures are updated.

There might be a way to upload textures without dropping frames, but I don’t know if anyone has tried. One of the problems is decoding the image that is being uploaded as that blocks the JS thread.

If you take a profile of the example I mentioned, you will see slow frames caused by green ImageDecode blocks which on my machine is 20-30ms, which is already longer than a frame by itself. Add the rest of what’s happening with JS and it will be bigger than a few frames.

If it is indeed possible to load images off the main thread in a worker like @Evgeni_Popov mentioned in the referenced thread and if it’s possible to upload the result to a webgl texture off-thread, then it would be possible to not cause hitching during load.

1 Like

It’s not possible to use webgl commands on a context in two (or more) different threads. Maybe this post has some ideas for you:

2 Likes