Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose runtime baking functionality in OccluderInstance3D #90590

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Calinou
Copy link
Member

@Calinou Calinou commented Apr 12, 2024

This can be used in editor plugins and exported projects.

Testing project: test_occluder_runtime_bake.zip

TODO

  • Move saving to disk to a different method (e.g. bake_scene_and_save()), so you can bake without saving to disk. This can be useful for procedurally generated levels that are discarded after a gameplay session, so caching wouldn't be relevant here.

doc/classes/OccluderInstance3D.xml Outdated Show resolved Hide resolved
doc/classes/OccluderInstance3D.xml Outdated Show resolved Hide resolved
doc/classes/OccluderInstance3D.xml Outdated Show resolved Hide resolved
@Calinou Calinou force-pushed the occluderinstance3d-expose-baking branch from 5525c4a to 535c7b0 Compare July 5, 2024 21:23
Copy link
Contributor

@Mickeon Mickeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs are fine now and the feature is intriguing by itself, but the TODO is intriguing, as well:

Move saving to disk to a different method

This can be used in editor plugins and exported projects.
@Calinou Calinou force-pushed the occluderinstance3d-expose-baking branch from 535c7b0 to 108ad4f Compare November 12, 2024 01:32
@RadiantUwU
Copy link
Contributor

i need this for my game... 😭

@clayjohn
Copy link
Member

Looking at the proposal it seems that the user was just asking for the simplify function to be exposed. They are already able to bake occluder nodes at run time, but they are missing the ability to simplify the generated mesh. Accordingly, I wouldn't go forward with exposing the bake function as-is, instead, to solve their problem, we should be exposing the simplify function in an easier to use way.

The problem with the bake function is that it does a bunch of additional things that will be harmful:

  1. It recursively walks over the entire sub scene
  2. It stalls the GPU by retrieving mesh data from the GPU
  3. it saves the resource (which is really bad for procedurally generated scenes)

@Calinou
Copy link
Member Author

Calinou commented Nov 12, 2024

They are already able to bake occluder nodes at run time, but they are missing the ability to simplify the generated mesh.

"Bake" isn't 100% correct here, as the user has to manually create the ArrayOccluder3D and set its vertex data by manually traversing the scene. This is still nontrivial to do correctly for users (especially when multimeshes are involved), so I think a high-level bake() function makes more sense to expose. I agree baking and saving should be separate functions for sure, and that simplification can be exposed separately (most likely in Mesh).

Stalling the GPU is inevitable either way (it will also happen if you manually query mesh data in your script), but it's expected that you only bake occluders when loading a scene, not during gameplay. The operation takes too long to be viable during gameplay anyway, and changing occluder data triggers an Embree BVH rebuild which further slows things down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow Baking OccluderInstances from script
4 participants