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

Implement simplification of generated occluders in OccluderInstance3D #50408

Conversation

Calinou
Copy link
Member

@Calinou Calinou commented Jul 13, 2021

The meshoptimizer library is used if the bake_simplify property is set to a value greater than 0.

The default simplifcation threshold (0.02) is fairly aggressive, but occluders don't need to be very detailed to work well.

This also adds documentation for occlusion culling in the class reference XML.

Testing project: test_occlusion_culling.zip

Preview

In this particular scene, even the most aggressive simplification still provides good culling capabilities. However, this may not be true in more complex scenes.

Remember to tweak the Bake Mask to exclude dynamic objects, small objects and fixtures from your occluder mesh.

No simplification (0.0)

Lots of stuttering.

No simplification

Most conservative simplification (0.0001)

Still a fair bit of stuttering.

Most conservative simplification

Balanced simplification (0.01)

No more stuttering.
Note: The default simplification value is now 0.02, which is more aggressive but still works quite well.*

Balanced simplification

Aggressive simplification (0.1)

No more stuttering.

Aggressive simplification

@Calinou Calinou requested review from a team as code owners July 13, 2021 01:39
@Calinou Calinou added this to the 4.0 milestone Jul 13, 2021
@Calinou Calinou force-pushed the occluderinstance3d-add-simplification branch from 926954e to fa92872 Compare July 13, 2021 01:42
@Calinou Calinou requested a review from JFonS July 13, 2021 01:43
@Calinou Calinou force-pushed the occluderinstance3d-add-simplification branch from fa92872 to c0cfea3 Compare July 13, 2021 01:44
@lawnjelly
Copy link
Member

This looks great! 👍

I wonder whether with the bake simplification values exposed to the user whether it be a good idea to standardize these (to say a range 0.0 to 1.0, with 0.5 default), and then convert these values to the meaningful (esoteric) values used by the mesh library. This could make it easier from a user perspective, and also give a bit of insulation should we decide to change the mesh library at a later date.

@Calinou Calinou force-pushed the occluderinstance3d-add-simplification branch from c0cfea3 to 15204d6 Compare August 16, 2021 03:51
@akien-mga
Copy link
Member

scene/3d/occluder_instance_3d.cpp: In member function 'void OccluderInstance3D::_bake_node(Node*, PackedVector3Array&, PackedInt32Array&)':
scene/3d/occluder_instance_3d.cpp:284:15: error: declaration of 'i' shadows a previous local [-Werror=shadow=local]
  284 |      for (int i = 0; i < vertices.size(); i++) {
      |               ^
scene/3d/occluder_instance_3d.cpp:255:13: note: shadowed declaration is here
  255 |    for (int i = 0; i < mesh->get_surface_count(); i++) {
      |             ^
scene/3d/occluder_instance_3d.cpp:287:15: error: declaration of 'i' shadows a previous local [-Werror=shadow=local]
  287 |      for (int i = 0; i < indices.size(); i++) {
      |               ^
scene/3d/occluder_instance_3d.cpp:255:13: note: shadowed declaration is here
  255 |    for (int i = 0; i < mesh->get_surface_count(); i++) {
      |             ^

@clayjohn
Copy link
Member

Does this work well with concave geometry? My concern is that such a simple decimation of the mesh will result in false positives I'm the occlusion code. We should experiment with a range of meshes.

The meshoptimizer library is used if the `bake_simplify` property is set
to a value greater than 0.

The default simplifcation threshold (0.02) is fairly aggressive,
but occluders don't need to be very detailed to work well.

This also adds documentation for occlusion culling in the
class reference XML.
@Calinou Calinou force-pushed the occluderinstance3d-add-simplification branch from 15204d6 to e6199a5 Compare August 16, 2021 15:35
@Calinou
Copy link
Member Author

Calinou commented Aug 16, 2021

Does this work well with concave geometry? My concern is that such a simple decimation of the mesh will result in false positives I'm the occlusion code. We should experiment with a range of meshes.

I made a testing project: test_oc.zip

The whole level (from https://github.com/Calinou/game-maps-obj) is a single mesh, but dynamic objects (boxes here) can still be occluded. I've subdivided them and duplicated them at the same location so that you can spot them easily while using the wireframe and overdraw debug draw modes.

With the default simplifcation factor, I couldn't notice any false negatives (objects being occluded when they shouldn't be) after several minutes of flying around the level. False positives (objects not being occluded when they should be) will happen more often with simplification enabled, but it's likely not as problematic.

If this is an issue, we could default to having simplification disabled, or set to the most conservative value (0.0001).

@Calinou
Copy link
Member Author

Calinou commented Feb 8, 2022

Superseded by #57627.

I'll open a separate PR to improve documentation once #57627 is merged.
Edit: Done in #57889.

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.

4 participants