godot icon indicating copy to clipboard operation
godot copied to clipboard

Eliminate collision checks between geometry in rendering BVH.

Open lawnjelly opened this issue 3 years ago • 0 comments

Later logic using the pairable_mask would catch cases preventing pairing callbacks between geometry. However the collision checks were still taking place, wasting performance.

Here we utilize the tree_mask feature of BVH to totally eliminate unnecessary collision checks between geometry.

Notes

  • I noticed when profiling benchmarks of rotating cubes that BVH collision checks were occurring with no lights in the scene. This did not seem necessary.
  • I worked out from the logic that geometry always has a pairable_mask of zero, so is eliminated from pairing with other geometry in the templated UserCullTestFunction() callback used by the BVH, which happens near the end of the collision pipeline.
  • However it was simple to totally remove these collision checks from taking place by changing the tree collision mask (which was maybe introduced with the templated trees?).
  • The performance gains typically aren't massive from eliminating these checks, but are well worth doing as it is free speedup. More likely to be beneficial in scenes with lots of moving objects.
  • Will need a beta to check for regressions, I don't think there should be, based on the logic, but something could be unforeseen.
  • This improvement can eventually be also added to Godot 4.x (after 4.0 release) as the longterm intention has been to use the new BVH there too for rendering (it currently still uses the old dynamic_bvh.h by reduz for rendering).
  • I also removed the default parameters from the functions involved. These weren't used, and made it more complicated to work out what was going on.

lawnjelly avatar Feb 01 '23 12:02 lawnjelly