UNPKG

playcanvas

Version:

Open-source WebGL/WebGPU 3D engine for the web

138 lines (137 loc) 5.7 kB
/** * @import { StorageBuffer } from '../../platform/graphics/storage-buffer.js' * @import { ShaderMaterial } from '../materials/shader-material.js' * @import { Layer } from '../layer.js' * @import { GraphNode } from '../graph-node.js' * @import { GraphicsDevice } from '../../platform/graphics/graphics-device.js' * @import { GSplatWorkBuffer } from './gsplat-work-buffer.js' * @import { FogParams } from '../fog-params.js' */ /** * Base class for splat renderers. Holds common state shared by all renderer * implementations (instanced-quad, compute-based, etc.). Derived classes * implement the actual rendering strategy. * * @ignore */ export class GSplatRenderer { /** * @param {GraphicsDevice} device - The graphics device. * @param {GraphNode} node - The graph node. * @param {GraphNode} cameraNode - The camera node. * @param {Layer} layer - The layer to add mesh instances to. * @param {GSplatWorkBuffer} workBuffer - The work buffer containing splat data. */ constructor(device: GraphicsDevice, node: GraphNode, cameraNode: GraphNode, layer: Layer, workBuffer: GSplatWorkBuffer); /** @type {GraphicsDevice} */ device: GraphicsDevice; /** @type {GraphNode} */ node: GraphNode; /** @type {GraphNode} */ cameraNode: GraphNode; /** @type {Layer} */ layer: Layer; /** @type {GSplatWorkBuffer} */ workBuffer: GSplatWorkBuffer; /** @type {number|undefined} */ renderMode: number | undefined; /** * Cached work buffer format version for detecting extra stream changes. * * @protected */ protected _workBufferFormatVersion: number; /** * Fisheye projection helper shared by all renderer paths. * The manager calls update() during culling; renderers read the computed values * when binding uniforms. * * @type {FisheyeProjection} * @ignore */ fisheyeProj: FisheyeProjection; destroy(): void; /** * Sets the render mode for this renderer. * * @param {number} renderMode - Bitmask flags controlling render passes (GSPLAT_FORWARD, GSPLAT_SHADOW, or both). */ setRenderMode(renderMode: number): void; /** * Returns the material used by this renderer, or null if not applicable. * * @type {ShaderMaterial|null} */ get material(): ShaderMaterial | null; /** * Sets the data source providing format and texture access. The base implementation updates * the workBuffer and notifies derived classes of the format change. Derived classes (e.g. * the compute renderer) may override this to decouple from the work buffer entirely. * * The source object must provide: * - `format` — a {@link GSplatFormat} describing the texture streams and shader read code. * - `getTexture(name)` — a function returning a {@link Texture} for a given stream name. * * @param {object} source - The data source (typically a {@link GSplatWorkBuffer}). */ setDataSource(source: object): void; /** * Called when the work buffer format has changed. Derived classes reconfigure * their rendering resources (materials, pipelines, bindings, etc.). */ onWorkBufferFormatChanged(): void; /** * Updates the renderer with the current splat count and texture size. * * @param {number} count - The number of visible splats. * @param {number} textureSize - The work buffer texture size. */ update(count: number, textureSize: number): void; /** * Configures the renderer to use GPU-sorted data for rendering. * * @param {number} drawSlot - The indirect draw slot index. * @param {StorageBuffer} sortedIds - Buffer containing sorted visible splat IDs. * @param {StorageBuffer} numSplatsBuffer - Buffer containing the visible splat count. * @param {number} textureSize - The work buffer texture size. */ setGpuSortedRendering(drawSlot: number, sortedIds: StorageBuffer, numSplatsBuffer: StorageBuffer, textureSize: number): void; /** * Switches the renderer to CPU-sorted rendering mode. */ setCpuSortedRendering(): void; /** * Binds the current order data (texture or storage buffer) for CPU-sorted rendering. */ setOrderData(): void; /** * Per-frame update for the renderer (material syncing, parameter updates). * * @param {object} params - The gsplat parameters. * @param {number} [exposure] - Scene exposure value. * @param {FogParams} [fogParams] - Fog parameters. */ frameUpdate(params: object, exposure?: number, fogParams?: FogParams): void; /** * Updates the overdraw visualization mode. * * @param {object} params - The gsplat parameters. */ updateOverdrawMode(params: object): void; /** * Populates a cincludes map with tonemapping, gamma, decode and gsplatOutput * shader chunks needed by compute tile-count shaders. * * @param {Map<string, string>} cincludes - The shader includes map to populate. * @protected */ protected _createTonemapIncludes(cincludes: Map<string, string>): void; } import type { GraphicsDevice } from '../../platform/graphics/graphics-device.js'; import type { GraphNode } from '../graph-node.js'; import type { Layer } from '../layer.js'; import type { GSplatWorkBuffer } from './gsplat-work-buffer.js'; import { FisheyeProjection } from '../graphics/fisheye-projection.js'; import type { ShaderMaterial } from '../materials/shader-material.js'; import type { StorageBuffer } from '../../platform/graphics/storage-buffer.js'; import type { FogParams } from '../fog-params.js';