Skip to content

@relu-interactives/spatial-ecs


@relu-interactives/spatial-ecs / index / OcclusionCullingSystem

Class: OcclusionCullingSystem ​

Defined in: systems/OcclusionCullingSystem.ts:66

Skips drawing objects hidden behind OccluderComponents.

Every frame, after the camera has moved, the occluders' boxes are drawn into a small CPU depth buffer (OcclusionBuffer) and each model and primitive is tested against it. An object becomes visible the frame it's no longer covered, and is hidden only after two covered frames in a row.

A default system. Off in the editor, off in a world without occluders, and off while a headset presents unless xr is set: the test uses one camera, a headset draws two eyes.

Implements ​

Constructors ​

Constructor ​

ts
new OcclusionCullingSystem(isEditor?): OcclusionCullingSystem;

Defined in: systems/OcclusionCullingSystem.ts:90

Parameters ​

ParameterTypeDefault value
isEditorbooleanfalse

Returns ​

OcclusionCullingSystem

Properties ​

PropertyModifierTypeDefault valueDescriptionDefined in
runsWhilePausedreadonlytruetrueKeep ticking while the world is paused. Leave it unset for anything that moves the game on: such a system stops at world.pause() and picks up where it was at world.resume().systems/OcclusionCullingSystem.ts:67
enabledpublicbooleantrueTurn occlusion culling off without removing occluders.systems/OcclusionCullingSystem.ts:69
xrpublicbooleanfalseAlso cull while a headset presents (tested from the head, not each eye).systems/OcclusionCullingSystem.ts:71
maxOccluderspublicnumber64Most occluders drawn a frame: the biggest on screen first.systems/OcclusionCullingSystem.ts:73
idleIntervalpublicnumber15While nothing has been hidden for this many frames, test only one frame in this many: a scene where occluders hide nothing doesn't pay for them every frame. 1 tests every frame.systems/OcclusionCullingSystem.ts:79
bufferpublicOcclusionBufferundefinedThe depth buffer. 256 x 128 by default; setResolution for slower devices.systems/OcclusionCullingSystem.ts:83

Methods ​

addOccluderSource() ​

ts
addOccluderSource(source): () => void;

Defined in: systems/OcclusionCullingSystem.ts:93

Let another system add occluders each frame (terrain does). Returns a remover.

Parameters ​

ParameterType
sourceOccluderSource

Returns ​

() => void


setResolution() ​

ts
setResolution(width, height): void;

Defined in: systems/OcclusionCullingSystem.ts:99

A smaller buffer is cheaper and hides less.

Parameters ​

ParameterType
widthnumber
heightnumber

Returns ​

void


getStats() ​

ts
getStats(): OcclusionStats;

Defined in: systems/OcclusionCullingSystem.ts:103

Returns ​

OcclusionStats


update() ​

ts
update(world): void;

Defined in: systems/OcclusionCullingSystem.ts:107

Parameters ​

ParameterType
worldWorld

Returns ​

void

Implementation of ​

EcsSystem.update