Hi guys,
Thanks for great suggestions!
I also have an idea how to improve things. Here is a screenshot from the Chrome Dev Tools, performance tab. As you can see, significant part of time is taken by updateMatrixWorld and projectObject functions. At the same time, both of these functions can be run in parallel. I mean that there are many of independent objects which need to be updated. So we could create several Workers and split tasks for update objects between Workers.
Just in case, I don’t mean to run updateMatrixWorld and projectObject in parallel, this is wrong because projectObject requires the matrixWorld be updated.
I understand that the structure of objects (and hierarchy) is not suitable to pass them to Worker. But may be eventually it will be possible during Three JS evolves.
Don’t forget that you would need a copy of the entire scene graph in those workers. Transferring them an keeping this in sync is a challenge you’d probably want to solve first, since this may introduce a pretty bad performance bottleneck.
I use a lot of workers and they run on my tablet and my Ubuntu desktop computer in Chrome and Firefox without any problems. I use the workers to generate terrains. I also use SharedArrayBuffer for this.
I posted a video somewhere in the forum where I fly from space to the surface. My Mars has original scale (radius: 3390000 m).
I use workers not only for the terrain but also for the virtual texture system (more than 40000 maps)
Workers are a very powerful tool.
My mainthread pays attention to which worker is currently returning values.
I also use workers in my webgpu ocean repo V1 that I uploaded to github.
made something interesting in that regard GitHub - pmndrs/react-three-offscreen: 📺 Offscreen worker canvas for react-three-fiber
this takes care of the drawbacks you would normally encounter: no events, no controls, textures don’t work, gltfs don’t load, etc. and of course the biggest drawback, the app would have to be written in two variants, one in a worker, the other on the main thread as a fallback for browsers without support.
rt/offscreen allows you to take your existing app, as it is without changes, and throw it into a worker whole. everything will work as before. this includes things that aren’t even made for workers, like your physics engine etc.
Maybe in the future there will be something like a computeGeometry with the webgpuRenderer. This would then be able to replace the workers for geometry creation. Workers are great but they require a certain amount of management and are not as easy to use as it would be with the compute shaders.
Something like that would further reduce the distance to unreal and unity. A lot has already happened this year when it comes to webgpu in threejs.
nice
Is there a live demo to watch ?
No, unfortunately I can’t do a live demo. For this I need my own server that I can configure “cross-origin-isolated”. Without this special configuration, browsers do not allow the use of sharedArrayBuffers. And given the mass of data that the app has to handle, this cannot be done efficiently without sharedArrayBuffers.
Renting my own server that I can freely configure with plenty of storage space for the mars maps but unfortunately costs significantly more than a normal server space
Otherwise I would have already done that.