rafx

API Design

rafx-visibility is a low-level crate used by rafx-framework for providing a VisibilityWorld. A VisibilityWorld is like a physics world – it’s a retained API that maintains a shadow state of the application’s game world. The API encapsulates the game code from changes to the visibility’s code algorithms or data structures. As new features are added to rafx-visibility like occlusion culling or hierarchical cull structures for large game scenes, those features will become available transparently to the applications relying on rafx-visibility.

High-level Overview

Public API

The public API to rafx-visibility is contained in src/* and src/geometry/*.

The main entry point is the VisibilityWorldArc. The application creates VisibilityWorldArc and registers new Objects, Models, Zones, Volumes, and View Frustums with it to mirror their game’s scene. Additionally, the application can use a channel to send asynchronous commands to the VisibilityWorldArc in a thread-safe manner that can be processed during the next update of the VisibilityWorld.

The VisibilityWorld uses handles to avoid bleeding internal design into the application.

The public API also includes a VisibleBounds struct for processing an arbitrary PolygonSoup provided by the application into the VisibilityWorld’s internal bounding structures. VisibilityBounds may be computed offline and provided to the VisibilityWorld during loading for initializing Models. The reason for preferring an internal structure is that the VisibilityWorld will need to simplify application models into simpler OccluderBounds in the future when occlusion culling is added.

Visibility Queries

The VisibilityWorldArc defines the query_visibility function. This function is thread-safe.

pub fn query_visibility(
    &self,
    view_frustum: ViewFrustumHandle,
    result: &mut VisibilityQuery,
) -> Result<(), QueryError> 

The result of a VisibilityQuery is a Vec of VisibilityResult<T> where T is either an VisibilityObjectHandle or a VolumeHandle. Each VisibilityResult contains the following information:

pub struct VisibilityResult<T> {
    pub handle: T,
    pub id: u64,
    pub bounding_sphere: BoundingSphere,
    pub distance_from_view_frustum: f32,
}

Internals

[1] https://en.wikipedia.org/wiki/Portal_rendering

[2] Lengyel, Eric. (2019). Foundations of Game Engine Development: Vol 2. Rendering.

[3] http://advances.realtimerendering.com/destiny/gdc_2015/Tatarchuk_GDC_2015__Destiny_Renderer_web.pdf

[4] https://www.ea.com/frostbite/news/culling-the-battlefield-data-oriented-design-in-practice