playcanvas
Version:
Open-source WebGL/WebGPU 3D engine for the web
112 lines (111 loc) • 4.27 kB
TypeScript
/**
* Frustum culling data for GSplat octree nodes. Manages bounding-sphere and
* transform storage buffers and computes frustum planes from camera matrices.
* The actual culling test is performed inline by the interval compaction compute shader.
*
* @ignore
*/
export class GSplatFrustumCuller {
/**
* @param {GraphicsDevice} device - The graphics device.
*/
constructor(device: GraphicsDevice);
/** @type {GraphicsDevice} */
device: GraphicsDevice;
/**
* Storage buffer holding interleaved BoundsEntry structs (center.xyz, radius,
* transformIndex, pad x3). 32 bytes per entry.
*
* @type {StorageBuffer|null}
*/
boundsBuffer: StorageBuffer | null;
/**
* Total number of bounds entries across all GSplatInfos.
*/
totalBoundsEntries: number;
/** @type {number} */
_allocatedBoundsEntries: number;
/** @type {Float32Array|null} */
_boundsFloatView: Float32Array | null;
/** @type {Uint32Array|null} */
_boundsUintView: Uint32Array | null;
/** @type {Float32Array|null} */
_tmpSpheres: Float32Array | null;
/**
* Storage buffer holding world matrices as vec4f triplets (3 vec4f per matrix,
* rows of a 4x3 affine matrix). 48 bytes per matrix.
*
* @type {StorageBuffer|null}
*/
transformsBuffer: StorageBuffer | null;
/** @type {number} */
_allocatedTransformCount: number;
/** @type {Float32Array|null} */
_transformsData: Float32Array | null;
/**
* Packed frustum planes (6 planes x 4 floats: nx, ny, nz, distance).
* Updated by {@link computeFrustumPlanes} and consumed by the interval cull shader.
*
* @type {Float32Array}
*/
frustumPlanes: Float32Array;
/**
* Camera world position for fisheye cone culling (xyz).
*
* @type {Float32Array}
*/
fisheyeCameraPos: Float32Array;
/**
* Camera forward direction (normalized) for fisheye cone culling (xyz).
*
* @type {Float32Array}
*/
fisheyeCameraForward: Float32Array;
/**
* Maximum visible angle from forward direction for fisheye cone culling.
*/
fisheyeMaxTheta: number;
destroy(): void;
/**
* Updates the bounds buffer with local-space bounding spheres and transform
* indices from pre-built bounds groups.
*
* @param {Array<{splat: GSplatInfo, boundsBaseIndex: number, numBoundsEntries: number}>} boundsGroups - Pre-built bounds groups.
*/
updateBoundsData(boundsGroups: Array<{
splat: GSplatInfo;
boundsBaseIndex: number;
numBoundsEntries: number;
}>): void;
/**
* Updates the transforms buffer with one world matrix per bounds group.
* Each matrix is stored as 3 vec4f (rows of a 4x3 affine matrix).
*
* @param {Array<{splat: GSplatInfo, boundsBaseIndex: number, numBoundsEntries: number}>} boundsGroups - Pre-built bounds groups.
*/
updateTransformsData(boundsGroups: Array<{
splat: GSplatInfo;
boundsBaseIndex: number;
numBoundsEntries: number;
}>): void;
/**
* Computes frustum planes from camera matrices and stores them in
* {@link frustumPlanes} for use by the interval cull compute shader.
*
* @param {Mat4} projectionMatrix - The camera projection matrix.
* @param {Mat4} viewMatrix - The camera view matrix.
*/
computeFrustumPlanes(projectionMatrix: Mat4, viewMatrix: Mat4): void;
/**
* Sets fisheye cone culling data for the interval cull shader.
*
* @param {import('../../core/math/vec3.js').Vec3} cameraPos - Camera world position.
* @param {import('../../core/math/vec3.js').Vec3} cameraForward - Camera forward direction (normalized).
* @param {number} maxTheta - Maximum visible angle from forward direction in radians.
*/
setFisheyeData(cameraPos: import("../../core/math/vec3.js").Vec3, cameraForward: import("../../core/math/vec3.js").Vec3, maxTheta: number): void;
}
import type { GraphicsDevice } from '../../platform/graphics/graphics-device.js';
import { StorageBuffer } from '../../platform/graphics/storage-buffer.js';
import type { GSplatInfo } from "./gsplat-info.js";
import { Mat4 } from '../../core/math/mat4.js';