Optimization: Built-in Culling
DunGen includes a basic, built-in visibility culling system designed primarily for optimizing interior dungeons viewed from a first-person (or over the shoulder third-person) perspective. It works particularly well when doorways have doors that automatically close behind the player.
Use Case Specific
This built-in solution is quite specific and may not be suitable for all game types, such as top-down games. It relies on a simple adjacency check rather than true camera frustum culling.
How it Works
The system determines which Tiles should be visible based on simple rules:
- Player's Location: The Tile the player (or target camera/object) is currently inside is always considered visible.
- Adjacency: Tiles directly connected to the player's current Tile are considered visible. This check can extend outwards to neighbours of neighbours, up to a configurable depth (
Adjacent Tile Depth). - Closed Doors (Optional): If enabled (
Cull Behind Closed Doors), tiles that would otherwise be visible via adjacency are hidden (culled) if the doorway connecting them to an already visible tile is blocked by a closedDoorcomponent.
Any Tile not considered visible by these rules will have its Renderers temporarily disabled, preventing them from being drawn by the camera.
Enabling Culling
To use the built-in culling:
- Select the Camera GameObject you want the culling to apply to in your scene.
- Add one of the following DunGen culling components to it:
Adjacent Room CullingAdjacent Room Culling (Multi-Cam)
Choosing the Right Component
There are two versions of the component, each with trade-offs:
-
Adjacent Room Culling(Basic):- Pros: Very efficient, minimal performance overhead.
- Cons:
- Only functions correctly for the single camera it's attached to. Results viewed from the Scene view or other cameras may appear incorrect.
- It directly modifies the enabled state of Renderers and leaves them in their culled state. This means any other script trying to control renderer visibility might conflict or have its changes overwritten.
-
Adjacent Room Culling (Multi-Cam):- Pros:
- Works correctly with multiple cameras viewing the scene.
- Properly restores the original enabled state of renderers after the camera finishes rendering, preventing conflicts with other scripts.
- Cons: Significantly more performance-intensive than the basic version due to the state management overhead per frame.
- Pros:
Which to Choose?
- Use
Adjacent Room Culling(Basic) if you only have one main game camera, performance is critical, and you don't have other systems managing renderer visibility. - Use
Adjacent Room Culling (Multi-Cam)if you need multi-camera support (like spectator cameras, mini-maps, split-screen) or if you need to ensure renderer states are preserved for other game systems.
Component Settings
Both culling components share the same settings:
-
Adjacent Tile Depth:- Controls how many steps away from the player's current tile are considered visible.
0: Only the tile the player is currently in is visible.1: The current tile and all directly adjacent tiles are visible.2: The current tile, its neighbours, and their neighbours are visible, and so on.- Higher values show more of the dungeon but reduce the effectiveness of the culling.
-
Cull Behind Closed Doors:- If checked, visibility checks will be blocked by doorways that have a
Doorcomponent whoseIsOpenproperty isfalse. - This requires that your door prefabs (used as Connectors in Doorways or via the Lock & Key system) have a script that correctly manages the
Doorcomponent and itsIsOpenstate. See the Doors page for more details on theDoorcomponent.
- If checked, visibility checks will be blocked by doorways that have a
-
Target Override:- An optional
Transformcomponent. By default, the culling system uses the position of the camera it's attached to for visibility checks. - If your player character controller is physically separate from the camera object, you can drag the player's root Transform here. The system will then use the
Target Overrideobject's position to determine the "current tile" instead of the camera's position.
- An optional
Alternatives & Integration
If the built-in culling doesn't meet your needs, consider:
- Third-Party Assets: Solutions like SECTR (which has direct DunGen integration) offer portal-based culling.
- Custom Integration: You can integrate other culling systems by creating a custom adapter class derived from
DunGen.Adapters.CullingAdapterand implementing thePrepareForCullingmethod. DunGen will execute this as part of its post-processing steps.