Renderer · class

OcclusionBuffer

Explained in Hello world.

class OcclusionBuffer
import { OcclusionBuffer } from '@driftengine/core';

Constructor

new

constructor(options: OcclusionOptions)
ParameterTypeDescription
optionsOcclusionOptions

Accessors

NameTypeDescription
widthgetnumber
heightgetnumber
declaredgetnumberHow many occluders were declared this frame. Zero means every test answers "draw it".

Methods

resize

resize(options: OcclusionOptions): void

Rebuild the pyramid for a new size. Called when the drawing buffer's aspect changes.

ParameterTypeDescription
optionsOcclusionOptions
More

Levels stop at 1x1: the coarsest level is one texel covering the whole frame, which is what a rectangle spanning the screen is tested against.

begin

begin(viewProj: ReadonlyMat4): void

Start a frame: clear to the far plane and take the matrix everything will be projected by.

ParameterTypeDescription
viewProjReadonlyMat4

addOccluder

addOccluder(min: ReadonlyArray<number> | Float32Array, max: ReadonlyArray<number> | Float32Array, model: ReadonlyMat4): void

Declare one occluder: a box in local space, placed by a model matrix.

ParameterTypeDescription
minReadonlyArray<number> | Float32Array
maxReadonlyArray<number> | Float32Array
modelReadonlyMat4
More

A box rather than the mesh, which is the same bargain a bounding sphere makes for the frustum: an occluder that is smaller than the thing it stands for is conservative, and a consumer knows the box that fits inside its wall. What would make it wrong is a consumer handing the mesh's own bounds for a shape with a hole in it, which would occlude through the hole — so the parameter is the box you may safely be hidden by, not the box you occupy.

occluded

occluded(bounds: Bounds, model: ReadonlyMat4): boolean

Whether a bounding sphere is entirely behind the declared occluders.

ParameterTypeDescription
boundsBounds
modelReadonlyMat4
More

False whenever anything is uncertain, which is every case the arithmetic cannot settle: no occluders, a sphere crossing the near plane, a rectangle off the side of the frame. Drawing something hidden costs a draw call; culling something visible is a hole.

occludedBox

occludedBox(min: ArrayLike<number>, max: ArrayLike<number>): boolean

Whether a world-space box is entirely behind the declared occluders — the tighter question for something that is a box, where the cube around its sphere reaches far past it. A flat region is the case it exists for: a city block's sphere is half as deep underground as it is wide, nothing there occludes it, and the sphere test abstains for every block in the city. False whenever anything is uncertain, exactly as occluded.

ParameterTypeDescription
minArrayLike<number>
maxArrayLike<number>