playcanvas
Version:
Open-source WebGL/WebGPU 3D engine for the web
109 lines (108 loc) • 5.13 kB
TypeScript
/**
* @import { StorageBuffer } from '../../platform/graphics/storage-buffer.js'
* @import { GraphNode } from '../graph-node.js'
* @import { GraphicsDevice } from '../../platform/graphics/graphics-device.js'
* @import { Layer } from '../layer.js'
* @import { GSplatWorkBuffer } from './gsplat-work-buffer.js'
*/
/**
* Renders splats from a pre-projected cache built by the projector compute pass
* (see {@link GSplatProjector}) and a globally radix-sorted index array. The
* vertex shader is `gsplatHybridVS`; the fragment is the existing `gsplatPS`.
*
* Supports forward rendering and explicit pick/prepass paths. Shadow rendering is
* intentionally not supported because the projection cache is camera-specific.
*
* @ignore
*/
export class GSplatHybridRenderer extends GSplatRenderer {
/** @type {ShaderMaterial} */
_material: ShaderMaterial;
/** @type {MeshInstance} */
meshInstance: MeshInstance;
/** @type {ShaderMaterial|null} */
_pickMaterial: ShaderMaterial | null;
/** @type {MeshInstance|null} */
_pickMeshInstance: MeshInstance | null;
/**
* Per-camera `clipToViewZ` value for the forward material. Persistent: the GPU
* upload happens at draw time, so the buffer must outlive `setHybridSortedRendering`.
*
* @type {Float32Array}
*/
_clipToViewZ: Float32Array;
/**
* Per-camera `clipToViewZ` value for the pick material. Allocated on first
* `prepareForPicking` call and reused thereafter.
*
* @type {Float32Array|null}
*/
_clipToViewZPick: Float32Array | null;
/** @type {number} */
originalBlendType: number;
/** @type {Set<string>} */
_internalDefines: Set<string>;
/** @type {boolean} */
forceCopyMaterial: boolean;
configureMaterial(): void;
update(count: any, textureSize: any): void;
/**
* Configures the renderer to draw from the projector's caches.
*
* @param {number} drawSlot - The indirect draw slot index.
* @param {StorageBuffer} sortedIndices - Globally-sorted indices into projCache.
* @param {StorageBuffer} projCache - Per-splat projection cache produced by the projector.
* @param {StorageBuffer} numSplatsBuffer - GPU-written visible-splat count.
*/
setHybridSortedRendering(drawSlot: number, sortedIndices: StorageBuffer, projCache: StorageBuffer, numSplatsBuffer: StorageBuffer): void;
/**
* Configures and returns a transient pick mesh instance for the picker render pass.
*
* @param {number} drawSlot - The indirect draw slot index.
* @param {StorageBuffer} sortedIndices - Globally-sorted indices into projCache.
* @param {StorageBuffer} projCache - Per-splat projection cache produced by the projector.
* @param {StorageBuffer} numSplatsBuffer - GPU-written visible-splat count.
* @param {number} alphaClip - Fragment alpha threshold for picking.
* @param {number} alphaClipForward - Forward alpha floor (must match {@link GSplatRenderer#frameUpdate}).
* @param {GraphNode} cameraNode - The picker camera node, used to derive the
* `clipToViewZ` reconstruction uniform.
* @returns {MeshInstance} The pick mesh instance.
*/
prepareForPicking(drawSlot: number, sortedIndices: StorageBuffer, projCache: StorageBuffer, numSplatsBuffer: StorageBuffer, alphaClip: number, alphaClipForward: number, cameraNode: GraphNode): MeshInstance;
/**
* Computes the per-camera `clipToViewZ` value into `dst`. The hybrid VS dot-products
* this with the cached `clipPos` to recover linear view depth, used by fog / overdraw
* / prepass.
*
* - Perspective + orthographic: `dst = -inverse(matrix_projection)[row 2]`. The
* projector stores `clipPos.w` in slot [3] and the dot-product yields `-view.z`.
* - Fisheye: `dst = (0, 0, far - near, near)`. The projector stores depthNdc in
* slot [2] and `1.0` in slot [3], so the dot-product reduces to
* `depthNdc * (far - near) + near`, which equals linear `-view.z`.
*
* The destination buffer must be retained by the caller (typically a per-material
* instance field) because the GPU upload happens at draw time.
*
* @param {GraphNode} cameraNode - Camera node to derive the uniform from.
* @param {Float32Array} dst - 4-element destination, written in place.
* @private
*/
private _computeClipToViewZ;
frameUpdate(params: any): void;
_lastNoFog: any;
/**
* Updates pick ID defines to match the work-buffer format.
*
* @param {ShaderMaterial} material - Material to update.
* @returns {boolean} True if the material defines changed.
* @private
*/
private _updateIdDefines;
updateOverdrawMode(params: any): void;
createMeshInstance(): MeshInstance;
}
import { GSplatRenderer } from './gsplat-renderer.js';
import { ShaderMaterial } from '../materials/shader-material.js';
import { MeshInstance } from '../mesh-instance.js';
import type { StorageBuffer } from '../../platform/graphics/storage-buffer.js';
import type { GraphNode } from '../graph-node.js';