/** * The base renderer functionality to allow implementation of specialized renderers. * * @ignore */ export class Renderer { /** * Create a new instance. * * @param {GraphicsDevice} graphicsDevice - The graphics device used by the renderer. * @param {Scene} scene - The scene. */ constructor(graphicsDevice: GraphicsDevice, scene: Scene); /** @type {boolean} */ clustersDebugRendered: boolean; /** @type {Scene} */ scene: Scene; /** * The scene visibility culler: per-camera light visibility, mesh-instance culling (request / * execute) and shadow-caster culling. * * @type {Culler} * @ignore */ culler: Culler; /** * @type {WorldClustersAllocator} * @ignore */ worldClustersAllocator: WorldClustersAllocator; /** * A list of all unique lights in the layer composition. * * @type {Light[]} */ lights: Light[]; /** * A list of all unique local lights (spot & omni) in the layer composition. * * @type {Light[]} */ localLights: Light[]; /** * Formats of the view uniform buffer, by clustered lighting mode and then by the light layout * of the pass they serve. See {@link Renderer#getViewUniformFormat}. * * @type {Map[]} */ _viewUniformFormats: Map[]; /** * The uniforms of each light slot, by slot index. See {@link Renderer#getLightSlotUniforms}. * * @type {LightSlotUniforms[]} */ _lightSlotUniforms: LightSlotUniforms[]; /** * Shared non-persistent view uniform buffers, keyed by their uniform format, one per view * index. Reused every frame, with the storage sourced from the dynamic buffer system. A * multiview pass fills one per view, as the view bind groups holding textures hold the buffer * of their view. * * @type {WeakMap} */ _viewUniformBuffers: WeakMap; /** * All view bind groups holding textures, destroyed with the renderer. * * @type {BindGroup[]} */ _viewTextureBindGroups: BindGroup[]; /** * Counts the passes set up by {@link Renderer#setupViewUniformBuffers}, so that a view bind * group holding textures updates once per pass. * * @type {number} */ _viewPass: number; /** * The number of views of the current pass, or 0 when it is not multiview. * * @type {number} */ _passViewCount: number; /** * The view uniform buffers of the current pass, one per view. * * @type {ViewUniformBuffer[]} */ _passViewUniformBuffers: ViewUniformBuffer[]; /** * The format of the view bind group bound by the current pass, or null for the bind group of * just the view uniform buffer. * * @type {BindGroupFormat|null} */ _boundViewBindGroupFormat: BindGroupFormat | null; /** * True when the current pass has bound the empty bind group at the mesh bind group index. * * @type {boolean} */ _emptyMeshBindGroupBound: boolean; /** * True when the current pass has bound a mesh uniform buffer of a shader without mesh uniforms, * which the draws of such shaders then share, see {@link Shader#meshUniformBufferEmpty}. * * @type {boolean} * @private */ private _emptyMeshUniformBufferBound; /** * The version of the mesh instance storage the view bind groups of the current pass were updated * with, see {@link Renderer#updateStorageSlot}. * * @type {number} * @private */ private _meshInstanceStorageVersion; /** * Reusable receiver for a view uniform buffer's dynamic bind group + offset. * * @type {DynamicBindGroup} */ _dynamicViewBindGroup: DynamicBindGroup; /** * The dynamic bind group of just the view uniform buffer, of each view of the current multiview * pass (allocations may span dynamic buffers, so the bind group is captured per view alongside * its offset). * * @type {BindGroup[]} */ _passDynamicViewBindGroups: BindGroup[]; /** @type {number[]} */ _passDynamicViewOffsets: number[]; /** * The view bind group of each view of the current multiview pass, for the shader set last, * which the forward render loop binds per view. * * @type {BindGroup[]} */ _viewBindGroups: BindGroup[]; /** @type {number[]} */ _viewBindGroupOffsets: number[]; /** * Reused single-element array passed as the dynamic offsets to per-view setBindGroup, to avoid * per-draw allocation. A typed array, as the device passes it to WebGPU without conversion. * * @type {Uint32Array} */ _viewOffsetScratch: Uint32Array; blueNoise: BlueNoise; /** * A gsplat director for unified splat rendering. * * @type {GSplatDirector|null} */ gsplatDirector: GSplatDirector | null; device: GraphicsDevice; lightTextureAtlas: LightTextureAtlas; shadowMapCache: ShadowMapCache; shadowRenderer: ShadowRenderer; _shadowRendererLocal: ShadowRendererLocal; _shadowRendererDirectional: ShadowRendererDirectional; _renderPassUpdateClustered: FramePassUpdateClustered; _skinTime: number; _morphTime: number; _cullTime: number; _shadowMapTime: number; _lightClustersTime: number; _layerCompositionUpdateTime: number; _shadowDrawCalls: number; _skinDrawCalls: number; _instancedDrawCalls: number; _shadowMapUpdates: number; _numDrawCallsCulled: number; _camerasRendered: number; _lightClusters: number; _gsplatCount: number; boneTextureId: import("../../index.js").ScopeId; modelMatrixId: import("../../index.js").ScopeId; normalMatrixId: import("../../index.js").ScopeId; viewInvId: import("../../index.js").ScopeId; viewPos: Float32Array; viewPosId: import("../../index.js").ScopeId; projId: import("../../index.js").ScopeId; projSkyboxId: import("../../index.js").ScopeId; viewId: import("../../index.js").ScopeId; viewId3: import("../../index.js").ScopeId; viewProjId: import("../../index.js").ScopeId; flipYId: import("../../index.js").ScopeId; tbnBasis: import("../../index.js").ScopeId; cameraParams: Float32Array; cameraParamsId: import("../../index.js").ScopeId; viewportSize: Float32Array; viewportSizeId: import("../../index.js").ScopeId; viewIndexId: import("../../index.js").ScopeId; blueNoiseJitterVersion: number; blueNoiseJitterVec: Vec4; blueNoiseJitterData: Float32Array; blueNoiseJitterId: import("../../index.js").ScopeId; blueNoiseTextureId: import("../../index.js").ScopeId; alphaTestId: import("../../index.js").ScopeId; exposureId: import("../../index.js").ScopeId; morphPositionTex: import("../../index.js").ScopeId; morphNormalTex: import("../../index.js").ScopeId; morphTexParams: import("../../index.js").ScopeId; lightCube: LightCube; constantLightCube: import("../../index.js").ScopeId; destroy(): void; /** * Set up the viewport and the scissor for camera rendering. * * @param {Camera} camera - The camera containing the viewport information. * @param {RenderTarget} [renderTarget] - The render target. NULL for the default one. */ setupViewport(camera: Camera, renderTarget?: RenderTarget): void; setCameraUniforms(camera: any, target: any): any; /** * Clears the active render target. If the viewport is already set up, only its area is cleared. * * @param {Camera} camera - The camera supplying the value to clear to. * @param {boolean} [clearColor] - True if the color buffer should be cleared. Uses the value * from the camera if not supplied. * @param {boolean} [clearDepth] - True if the depth buffer should be cleared. Uses the value * from the camera if not supplied. * @param {boolean} [clearStencil] - True if the stencil buffer should be cleared. Uses the * value from the camera if not supplied. */ clear(camera: Camera, clearColor?: boolean, clearDepth?: boolean, clearStencil?: boolean): void; setupCullModeAndFrontFace(cullFaces: any, flipFactor: any, drawCall: any): void; setupCullMode(cullFaces: any, flipFactor: any, drawCall: any): void; updateCpuSkinMatrices(drawCalls: any): void; /** * Update skin matrices ahead of rendering. * * @param {MeshInstance[]|Set} drawCalls - MeshInstances containing skinInstance. * @ignore */ updateGpuSkinMatrices(drawCalls: MeshInstance[] | Set): void; /** * Update morphing ahead of rendering. * * @param {MeshInstance[]|Set} drawCalls - MeshInstances containing morphInstance. * @ignore */ updateMorphing(drawCalls: MeshInstance[] | Set): void; /** * Update gsplats ahead of rendering. * * @param {MeshInstance[]|Set} drawCalls - MeshInstances containing gsplatInstances. * @ignore */ updateGSplats(drawCalls: MeshInstance[] | Set): void; /** * Update draw calls ahead of rendering. * * @param {MeshInstance[]|Set} drawCalls - MeshInstances requiring updates. * @ignore */ gpuUpdate(drawCalls: MeshInstance[] | Set): void; setVertexBuffers(device: any, mesh: any): void; setMorphing(device: any, morphInstance: any): void; setSkinning(device: any, meshInstance: any): void; dispatchViewPos(position: any): void; /** * Returns the format of the view uniform buffer of a pass: the view uniforms, the clustered * lighting parameters when enabled, and the uniforms of the lights of the pass. A light's * uniforms are the same for every mesh instance drawn, so they travel with the view, uploaded * once per pass, instead of in the per-draw mesh uniform buffer. The formats are cached by the * light layout, which the light list key identifies - as does the shader variant, so a shader is * only ever processed against the format of the passes it draws in. * * @param {boolean} isClustered - Whether clustered lighting is enabled. * @param {LightList} lightList - The lights of the pass. * @returns {UniformBufferFormat} The format. */ getViewUniformFormat(isClustered: boolean, lightList: LightList): UniformBufferFormat; /** * Returns the uniforms of a light slot - `light_*` - creating them on first use. A slot * is a position in the light list of a pass rather than a light, so the instances are few and * live as long as the renderer: the view uniform format declares from them whatever the light * holding the slot needs, and the light dispatch writes its values through them. * * @param {number} slot - The light slot. * @returns {LightSlotUniforms} The uniforms of the slot. */ getLightSlotUniforms(slot: number): LightSlotUniforms; /** * Set up uniforms for an XR view. */ setupViewUniforms(view: any, index: any): void; /** * Returns the shared non-persistent view uniform buffer for the given format and view index, * creating it on first use. * * @param {UniformBufferFormat} viewUniformFormat - The view uniform buffer format. * @param {number} viewIndex - The index of the view, 0 when the pass is not multiview. * @returns {ViewUniformBuffer} The shared view uniform buffer. */ getViewUniformBuffer(viewUniformFormat: UniformBufferFormat, viewIndex: number): ViewUniformBuffer; /** * Sets up the shared (per-format) view uniform buffer for the current camera, which starts a * pass. For a single view it updates the buffer and binds it immediately; for multiview (XR) * it updates a buffer per view and captures the per-view bind group and dynamic offset, which * the forward render loop then binds per draw. The bind group and dynamic offset come from the * dynamic buffer system. A shader reading textures in the view bind group binds its own group * at the shader switch, see {@link Renderer#setupViewBindGroup}. * * @param {UniformBufferFormat} viewUniformFormat - The view uniform buffer format. * @param {RenderView[]|null} viewList - The list of XR views for multiview, or null for a * single view. */ setupViewUniformBuffers(viewUniformFormat: UniformBufferFormat, viewList: RenderView[] | null): void; /** * The bind group bound at the material bind group index by the current pass, or null. * * @type {BindGroup|null} * @private */ private _boundMaterialBindGroup; /** * Binds the view bind group a shader expects, called after each shader switch. The textures * the renderer supplies per pass are in the view bind group of a shader reading them, * following the view uniform buffer - one bind group per format and view, updated once per * pass, see {@link ShaderProcessorOptions#viewTextures}. Other shaders use the bind group of * just the view uniform buffer. Rebinds only when the format differs from the one bound. * * @param {Shader} shader - The shader set on the device. * @param {boolean} [force] - True to bind the view bind group even when its format is bound, * used when the resources it holds changed. Defaults to false. */ setupViewBindGroup(shader: Shader, force?: boolean): void; /** * Returns the view bind group of a view uniform buffer holding the textures of a format, * creating it on first use, and updated once per pass: the textures are taken from the scope * and the uniform buffer offset from its allocation for the pass. * * @param {ViewUniformBuffer} viewUniformBuffer - The view uniform buffer. * @param {BindGroupFormat} format - The format of the view bind group. * @param {number} pass - The current pass. * @returns {BindGroup} The bind group. * @private */ private getViewTextureBindGroup; /** * Binds the bind group of a material at the material bind group index, or the empty bind group * for a material without one so the pipeline layout has no gap. Called at a material switch, * and again after a draw that bound a mesh instance's copy of the material uniform buffer. * Rebinds only when the group differs from the one bound by the previous draw. * * @param {Material} material - The material. */ setupMaterialBindGroup(material: Material): void; /** * Binds a mesh instance's copy of the material uniform buffer, with the uniforms it overrides * applied, at the material bind group index. Only called for a mesh instance that overrides * some of them, or whose parameters need splitting against a changed material layout, see * {@link Renderer#needsMaterialOverrideBindGroup}. * * @param {MeshInstance} meshInstance - The mesh instance being drawn. */ setupMaterialOverrideBindGroup(meshInstance: MeshInstance): void; /** * Unsets the overrides of a mesh instance back to the values of its material, after its draw * when the next draw uses the same material, which then keeps the state the material switch * set: the material bind group when the mesh instance bound its copy of it, and the scope * parameters. The alpha test reference is set from the material by the renderer rather than * being a material parameter, so it is restored with them. * * @param {MeshInstance} meshInstance - The mesh instance drawn. * @param {Material} material - Its material. */ restoreMaterialOverrides(meshInstance: MeshInstance, material: Material): void; /** * True when this mesh instance overrides something in the material's bind group, and so a draw * of it binds its own copy of that group. Kept to field reads, as this runs for every draw. * * @param {MeshInstance} meshInstance - The mesh instance being drawn. * @returns {boolean} True when the mesh instance overrides a uniform or a texture. */ hasMaterialOverrides(meshInstance: MeshInstance): boolean; /** * True when a draw of this mesh instance needs its own copy of the material's bind group: it * overrides something in it, or the set of typed properties of the material changed and its * parameters need splitting against the new layout again. Kept to field reads, as this runs for * every draw. * * @param {MeshInstance} meshInstance - The mesh instance being drawn. * @param {Material} material - Its material. * @returns {boolean} True when the copy is needed. */ needsMaterialOverrideBindGroup(meshInstance: MeshInstance, material: Material): boolean; setupMeshUniformBuffers(shaderInstance: any): void; /** * Returns the slot of a mesh instance in the mesh instance storage of the device, for a draw * with a shader reading it, which passes the slot as the first instance of the draw, see * {@link Shader#usesMeshInstanceStorage}. The slot is allocated on the first such draw, and its * matrices are written when the transform of the node changed since they were last written, or * when the mesh instance was given a different node. When the allocation grows the storage, the * view bind group of the shader, which holds the storage, is updated and bound again. * * @param {MeshInstance} meshInstance - The mesh instance being drawn. * @param {Shader} shader - The shader of the draw, set on the device. * @returns {number} The slot. */ updateStorageSlot(meshInstance: MeshInstance, shader: Shader): number; setMeshInstanceMatrices(meshInstance: any, setNormalMatrix?: boolean): void; collectLights(comp: any): void; /** * @param {MeshInstance[]} drawCalls - Mesh instances. * @param {boolean} onlyLitShaders - Limits the update to shaders affected by lighting. */ updateShaders(drawCalls: MeshInstance[], onlyLitShaders: boolean): void; updateFrameUniforms(): void; /** * @param {LayerComposition} comp - The layer composition to update. */ beginFrame(comp: LayerComposition): void; updateLightTextureAtlas(): void; /** * Updates the layer composition for rendering. * * @param {LayerComposition} comp - The layer composition to update. */ updateLayerComposition(comp: LayerComposition): void; frameUpdate(): void; } import type { Scene } from '../scene.js'; import { Culler } from './culler.js'; import { WorldClustersAllocator } from './world-clusters-allocator.js'; import type { Light } from '../light.js'; import { UniformBufferFormat } from '../../platform/graphics/uniform-buffer-format.js'; import { LightSlotUniforms } from '../lighting/light-slot-uniforms.js'; /** * A view uniform buffer, together with the view bind groups holding it with textures. * * @ignore */ declare class ViewUniformBuffer { /** * @param {UniformBuffer} uniformBuffer - The view uniform buffer. */ constructor(uniformBuffer: UniformBuffer); /** @type {UniformBuffer} */ uniformBuffer: UniformBuffer; /** * The view bind groups holding textures, by their format. * * @type {Map} */ textureBindGroups: Map; } import { BindGroup } from '../../platform/graphics/bind-group.js'; import type { BindGroupFormat } from '../../platform/graphics/bind-group-format.js'; import { DynamicBindGroup } from '../../platform/graphics/bind-group.js'; import { BlueNoise } from '../../core/math/blue-noise.js'; import type { GSplatDirector } from '../gsplat-unified/gsplat-director.js'; import type { GraphicsDevice } from '../../platform/graphics/graphics-device.js'; import { LightTextureAtlas } from '../lighting/light-texture-atlas.js'; import { ShadowMapCache } from './shadow-map-cache.js'; import { ShadowRenderer } from './shadow-renderer.js'; import { ShadowRendererLocal } from './shadow-renderer-local.js'; import { ShadowRendererDirectional } from './shadow-renderer-directional.js'; import { FramePassUpdateClustered } from './frame-pass-update-clustered.js'; import { Vec4 } from '../../core/math/vec4.js'; import { LightCube } from '../graphics/light-cube.js'; import { Camera } from '../camera.js'; import type { RenderTarget } from '../../platform/graphics/render-target.js'; import type { MeshInstance } from '../mesh-instance.js'; import type { LightList } from '../lighting/light-list.js'; import type { RenderView } from '../render-view.js'; import type { Shader } from '../../platform/graphics/shader.js'; import { Material } from '../materials/material.js'; import type { LayerComposition } from '../composition/layer-composition.js'; import { UniformBuffer } from '../../platform/graphics/uniform-buffer.js'; /** * A view bind group holding textures, see {@link Renderer#setupViewBindGroup}. * * @ignore */ declare class ViewTextureBindGroup { /** * @param {BindGroup} bindGroup - The bind group. */ constructor(bindGroup: BindGroup); /** @type {BindGroup} */ bindGroup: BindGroup; /** * The pass the bind group was last updated in, see {@link Renderer#_viewPass}. * * @type {number} */ pass: number; } export {};