Skip to content

Stack/04 culling#371

Merged
JucanAndreiDaniel merged 4 commits into
mainfrom
stack/04-culling
Jun 15, 2026
Merged

Stack/04 culling#371
JucanAndreiDaniel merged 4 commits into
mainfrom
stack/04-culling

Conversation

@JucanAndreiDaniel

Copy link
Copy Markdown
Contributor

Summary

Reworks distance culling to be band-based with hysteresis and lets NPC routines progress while meshes are unloaded.

Changes

  • Shared base — common bounding-sphere/bucket plumbing moved into AbstractCullingDomain/AbstractCullingService.
  • NPC culling — distance bands with hysteresis (no thrashing at the boundary); visible NPCs tracked in a HashSet; routine waypoints advance even while the mesh is culled, so NPCs are in the right place when they re-appear.
  • VOB mesh culling — three near-identical wrapper handlers collapsed into one per-bucket closure loop.
  • VOB sound cullingList + ToArray() replaced by a reusable doubling array (no per-update allocation).

How to test

  • Walk toward/away from NPCs and confirm they load/unload at the band edges without flicker near the threshold.
  • Leave an NPC's area, return after some time, and confirm it has progressed along its routine.
  • Confirm VOB meshes and positional sounds cull correctly with no GC spikes.

@JucanAndreiDaniel JucanAndreiDaniel self-assigned this Jun 13, 2026
@JucanAndreiDaniel JucanAndreiDaniel added the improvement Optimize an existing feature label Jun 13, 2026
@JucanAndreiDaniel JucanAndreiDaniel force-pushed the stack/03-animation-playables branch 2 times, most recently from 1189242 to 175c6f5 Compare June 14, 2026 08:54
Base automatically changed from stack/03-animation-playables to main June 15, 2026 03:50
Switches NPC culling to distance bands with hysteresis, tracks visible NPCs in a HashSet, and progresses routine waypoints even while meshes are unloaded.
Replaces the three near-identical wrapper handlers with a single closure loop capturing each bucket.
@JucanAndreiDaniel JucanAndreiDaniel marked this pull request as ready for review June 15, 2026 03:54
/// Band 1 - [cullingDistance...*1.15) - Hysteresis zone: VOB keeps its current state to avoid border flickering.
/// Band 2 - [cullingDistance*1.15...inf) - VOB is disabled.
///
/// We deliberately ignore evt.isVisible: Frustum culling of Renderers is done by Unity/URP itself.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't know if that is correct. We need to check in Scene View when game is running. Turning around and see, if a Vob is getting invisible or stays. Because Frustum should be handled for static objects. But how about Items?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I tested it. Works as expected. Thanks a lot. Less checks per frame are always appreciated. :-)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No more custom frustum, everything that is in range is left active but culled by unity itself. in scene view we can still see the vobs, but that's because the scene view is another camera.

But perhaps there is a case for truly static vobs (not interactable/movable/items) to be culled by custom frustum.

@JaXt0r JaXt0r left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Works like a charm. Performance improvements like this are always appreciated. 🙇

@JucanAndreiDaniel JucanAndreiDaniel merged commit facbdb1 into main Jun 15, 2026
@JucanAndreiDaniel JucanAndreiDaniel deleted the stack/04-culling branch June 15, 2026 04:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Optimize an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants