Skip to main content

PortalBasedCullingCamera

A class in Root.Township, the global namespace.

Client: on the camera, hides chunks behind culling portals the camera is facing away from, starting from the chunk the local player is in.

Constructors​

MemberWhat it is
PortalBasedCullingCamera()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

5 private and internal fields
MemberWhat it is
private Vector3 cameraPositionCamera position for this frame.
private Transform cameraTransformThe camera's transform.
private LocationChunk initialChunkThe local player's chunk this frame.
private static bool isCullingBacking field for IsCulling.
private Vector3 myCameraForwardCamera forward for this frame.

Properties​

MemberWhat it is
static bool IsCulling { get; }Shared on or off flag for portal culling.

Events​

MemberWhat it is
static event Action CullingChangedFires when IsCulling changes.

Methods​

MemberWhat it is
static void ForceSetIsCulling(bool value)Sets IsCulling and always fires CullingChanged.
static void SetIsCulling(bool value)Sets IsCulling and fires CullingChanged if it changed.
7 private and internal methods
MemberWhat it is
private bool CalculateCulling(CullingPortal portal, bool isLookingAtFrontChunk, LocationChunk targetChunk)Decides if a portal should be culled from its distance and the camera's facing. Portals within 10 m are never culled.
private void CullPortal(LocationChunk targetChunk, CullingPortal portal, bool isCullingFrontChunk)Hides the target chunk's terrain and culls that side of the portal.
private bool IsFarEnoughToUseGeneralViewDirection(float distanceSquared)True beyond 20 m, where the portal's facing alone can decide.
private bool IsLookingAwayFromPortal(float distanceToPortalSquared, float dotProductCameraForwardToPortal)True if the portal is behind the camera or outside a cone around its forward.
private bool IsTooCloseToCalculateCulling(float distanceSquared)True within 10 m.
private void OnPreCull()Checks every portal of the local player's chunk before the camera renders.
private void ProcessPortal(CullingPortal portal, bool isLookingAtFrontChunk)Culls a portal, or shows the chunk's terrain and unculls that side.

Used in​

Members of other types that take, return or hold a PortalBasedCullingCamera: