VoxelGI parallel baking

Godot Version

4.4.1

Question

I spent couple of days trying to figure out how to bake VoxelGI in-game, in parallel of the main thread but using threads alone doesn’t look like a good idea since deferring baking basically get the entire SceneTree stuck, losing the benefit of threads.

Eventually I came to the hope of using RenderingServer.

Because VoxelGI.bake() require that all related objects are in a scene tree, my idea would be to run in a thread RenderingServer API calls to manage related resources.

Unfortunatelly the RenderingServer API doesn’t expose method to bake VoxelGI once it has been created with voxel_gi_create. Not to mention that after checking after Godot source code, VoxelGi need to be in active scene tree. In fact RenderingServer isn’t useful in this case so I don’t really know what to do from here.

Let me know if you need me to rephrase or elaborate on something confusing here.

Thank you :slight_smile:

Ok so I reply to myself since I came with a working solution and it might be useful for other peoples.

It’s not really elegant but it works. Also the whole issue may be addressed with a feature request. But let’s stick to the real world and what we have right now.

To achieve parallel baking I’m basically spawning a child process of the game configured to act as a rendering/baking server. The required VoxelGI data are generated and saved in a file from the server, and retrieve from the client when ready.

What is not ideal here is that the server require to have a window context (–headless mode doesn’t work with VoxelGI baking which is unfortunate). The main window, where the actual game is running, is enforced to be set to

Window.MODE_EXCLUSIVE_FULLSCREEN

hidding the child process window.

When I quit the game, the child process is killed by its parent. And voilà.

I was afraid that this solution would impact negatively the game performance but in fact it is all smooth and nice alongside the fact this is not to hard to implement so I guess this topic is solved :slight_smile:

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.