UNPKG

@babylonjs/core

Version:

Getting started? Play directly with the Babylon.js API using our [playground](https://playground.babylonjs.com/). It also contains a lot of samples to learn how to use it.

332 lines (331 loc) 13.2 kB
import { Matrix } from "../Maths/math.vector.js"; import { type SubMesh } from "../Meshes/subMesh.js"; import { type InternalTexture } from "../Materials/Textures/internalTexture.js"; import { MultiRenderTarget } from "../Materials/Textures/multiRenderTarget.js"; import { type PrePassRenderer } from "../Rendering/prePassRenderer.js"; import { type Scene } from "../scene.js"; import { type AbstractMesh } from "../Meshes/abstractMesh.js"; import { type Nullable } from "../types.js"; import "../Shaders/geometry.fragment.js"; import "../Shaders/geometry.vertex.js"; import "../Engines/Extensions/engine.multiRender.js"; import { ShaderLanguage } from "../Materials/shaderLanguage.js"; /** @internal */ interface ISavedTransformationMatrix { world: Matrix; viewProjection: Matrix; } /** * Type, format and sampling settings for a geometry buffer render target. */ export interface IGeometryBufferTextureTypeAndFormat { /** Texture type for the target. */ textureType: number; /** Texture format for the target. */ textureFormat: number; /** Optional sampling mode for the target texture. Defaults to bilinear when omitted. */ samplingMode?: number; } /** * This renderer is helpful to fill one of the render target with a geometry buffer. */ export declare class GeometryBufferRenderer { /** * Force all the standard materials to compile to glsl even on WebGPU engines. * False by default. This is mostly meant for backward compatibility. */ static ForceGLSL: boolean; /** * Constant used to retrieve the depth texture index in the G-Buffer textures array * using getIndex(GeometryBufferRenderer.DEPTH_TEXTURE_INDEX) */ static readonly DEPTH_TEXTURE_TYPE = 0; /** * Constant used to retrieve the normal texture index in the G-Buffer textures array * using getIndex(GeometryBufferRenderer.NORMAL_TEXTURE_INDEX) */ static readonly NORMAL_TEXTURE_TYPE = 1; /** * Constant used to retrieve the position texture index in the G-Buffer textures array * using getIndex(GeometryBufferRenderer.POSITION_TEXTURE_INDEX) */ static readonly POSITION_TEXTURE_TYPE = 2; /** * Constant used to retrieve the velocity texture index in the G-Buffer textures array * using getIndex(GeometryBufferRenderer.VELOCITY_TEXTURE_INDEX) */ static readonly VELOCITY_TEXTURE_TYPE = 3; /** * Constant used to retrieve the reflectivity texture index in the G-Buffer textures array * using the getIndex(GeometryBufferRenderer.REFLECTIVITY_TEXTURE_TYPE) */ static readonly REFLECTIVITY_TEXTURE_TYPE = 4; /** * Constant used to retrieve the screen-space depth texture index in the G-Buffer textures array * using getIndex(GeometryBufferRenderer.SCREENSPACE_DEPTH_TEXTURE_TYPE) */ static readonly SCREENSPACE_DEPTH_TEXTURE_TYPE = 5; /** * Constant used to retrieve the linear velocity texture index in the G-Buffer textures array * using getIndex(GeometryBufferRenderer.VELOCITY_LINEAR_TEXTURE_TYPE) */ static readonly VELOCITY_LINEAR_TEXTURE_TYPE = 6; /** * Constant used to retrieve the irradiance texture index in the G-Buffer textures array * using getIndex(GeometryBufferRenderer.IRRADIANCE_TEXTURE_TYPE) */ static readonly IRRADIANCE_TEXTURE_TYPE = 7; /** * Dictionary used to store the previous transformation matrices of each rendered mesh * in order to compute objects velocities when enableVelocity is set to "true" * @internal */ _previousTransformationMatrices: { [index: number]: ISavedTransformationMatrix; }; /** * Dictionary used to store the previous bones transformation matrices of each rendered mesh * in order to compute objects velocities when enableVelocity is set to "true" * @internal */ _previousBonesTransformationMatrices: { [index: number]: Float32Array; }; /** * Array used to store the ignored skinned meshes while computing velocity map (typically used by the motion blur post-process). * Avoids computing bones velocities and computes only mesh's velocity itself (position, rotation, scaling). */ excludedSkinnedMeshesFromVelocity: AbstractMesh[]; /** Gets or sets a boolean indicating if transparent meshes should be rendered */ renderTransparentMeshes: boolean; /** * Gets or sets a boolean indicating if normals should be generated in world space (default: false, meaning normals are generated in view space) */ generateNormalsInWorldSpace: boolean; private _normalsAreUnsigned; /** * Gets a boolean indicating if normals are encoded in the [0,1] range in the render target. If true, you should do `normal = normal_rt * 2.0 - 1.0` to get the right normal */ get normalsAreUnsigned(): boolean; private _scene; private _resizeObserver; private _multiRenderTarget; private _textureTypesAndFormats; private _ratioOrDimensions; private _enableDepth; private _enableNormal; private _enablePosition; private _enableVelocity; private _enableVelocityLinear; private _enableReflectivity; private _enableScreenspaceDepth; private _enableIrradiance; private _depthFormat; private _clearColor; private _clearDepthColor; private _positionIndex; private _velocityIndex; private _velocityLinearIndex; private _reflectivityIndex; private _depthIndex; private _normalIndex; private _screenspaceDepthIndex; private _irradianceIndex; private _linkedWithPrePass; private _prePassRenderer; private _attachmentsFromPrePass; private _useUbo; protected _cachedDefines: string; /** * @internal * Sets up internal structures to share outputs with PrePassRenderer * This method should only be called by the PrePassRenderer itself */ _linkPrePassRenderer(prePassRenderer: PrePassRenderer): void; /** * @internal * Separates internal structures from PrePassRenderer so the geometry buffer can now operate by itself. * This method should only be called by the PrePassRenderer itself */ _unlinkPrePassRenderer(): void; /** * @internal * Resets the geometry buffer layout */ _resetLayout(): void; /** * @internal * Replaces a texture in the geometry buffer renderer * Useful when linking textures of the prepass renderer */ _forceTextureType(geometryBufferType: number, index: number): void; /** * @internal * Sets texture attachments * Useful when linking textures of the prepass renderer */ _setAttachments(attachments: number[]): void; /** * @internal * Replaces the first texture which is hard coded as a depth texture in the geometry buffer * Useful when linking textures of the prepass renderer */ _linkInternalTexture(internalTexture: InternalTexture): void; /** * Gets the render list (meshes to be rendered) used in the G buffer. */ get renderList(): Nullable<AbstractMesh[]>; /** * Set the render list (meshes to be rendered) used in the G buffer. */ set renderList(meshes: Nullable<AbstractMesh[]>); /** * Gets whether or not G buffer are supported by the running hardware. * This requires draw buffer supports */ get isSupported(): boolean; /** * Returns the index of the given texture type in the G-Buffer textures array * @param textureType The texture type constant. For example GeometryBufferRenderer.POSITION_TEXTURE_INDEX * @returns the index of the given texture type in the G-Buffer textures array */ getTextureIndex(textureType: number): number; /** * @returns a boolean indicating if object's depths are enabled for the G buffer. */ get enableDepth(): boolean; /** * Sets whether or not object's depths are enabled for the G buffer. */ set enableDepth(enable: boolean); /** * @returns a boolean indicating if object's normals are enabled for the G buffer. */ get enableNormal(): boolean; /** * Sets whether or not object's normals are enabled for the G buffer. */ set enableNormal(enable: boolean); /** * @returns a boolean indicating if objects positions are enabled for the G buffer. */ get enablePosition(): boolean; /** * Sets whether or not objects positions are enabled for the G buffer. */ set enablePosition(enable: boolean); /** * @returns a boolean indicating if objects velocities are enabled for the G buffer. */ get enableVelocity(): boolean; /** * Sets whether or not objects velocities are enabled for the G buffer. */ set enableVelocity(enable: boolean); /** * @returns a boolean indicating if object's linear velocities are enabled for the G buffer. */ get enableVelocityLinear(): boolean; /** * Sets whether or not object's linear velocities are enabled for the G buffer. */ set enableVelocityLinear(enable: boolean); /** * Gets a boolean indicating if objects reflectivity are enabled in the G buffer. */ get enableReflectivity(): boolean; /** * Sets whether or not objects reflectivity are enabled for the G buffer. * For Metallic-Roughness workflow with ORM texture, we assume that ORM texture is defined according to the default layout: * pbr.useRoughnessFromMetallicTextureAlpha = false; * pbr.useRoughnessFromMetallicTextureGreen = true; * pbr.useMetallnessFromMetallicTextureBlue = true; */ set enableReflectivity(enable: boolean); /** * Sets whether or not objects screenspace depth are enabled for the G buffer. */ get enableScreenspaceDepth(): boolean; set enableScreenspaceDepth(enable: boolean); /** * Gets a boolean indicating if objects irradiance are enabled in the G buffer. */ get enableIrradiance(): boolean; /** * Sets whether or not objects irradiance are enabled for the G buffer. */ set enableIrradiance(enable: boolean); /** * This will store a mask in the alpha channel of the irradiance texture to indicate which pixels have * scattering and should be taken into account when applying image-based lighting. */ generateIrradianceWithScatterMask: boolean; /** * If set to true (default: false), the depth texture will be cleared with the depth value corresponding to the far plane (1 in normal mode, 0 in reverse depth buffer mode) * If set to false, the depth texture is always cleared with 0. */ useSpecificClearForDepthTexture: boolean; /** * Gets the scene associated with the buffer. */ get scene(): Scene; /** * Gets the ratio used by the buffer during its creation. * How big is the buffer related to the main canvas. */ get ratio(): number; /** Shader language used by the material */ protected _shaderLanguage: ShaderLanguage; /** * Gets the shader language used in this material. */ get shaderLanguage(): ShaderLanguage; /** * @internal */ static _SceneComponentInitialization: (scene: Scene) => void; /** * Creates a new G Buffer for the scene * @param scene The scene the buffer belongs to * @param ratioOrDimensions How big is the buffer related to the main canvas (default: 1). You can also directly pass a width and height for the generated textures * @param depthFormat Format of the depth texture (default: Constants.TEXTUREFORMAT_DEPTH16) * @param textureTypesAndFormats The types, formats and optional sampling modes of textures to create as render targets. * If not provided, all textures will be RGBA and float or half float, depending on the engine capabilities. */ constructor(scene: Scene, ratioOrDimensions?: number | { width: number; height: number; }, depthFormat?: number, textureTypesAndFormats?: { [key: number]: IGeometryBufferTextureTypeAndFormat; }); private _shadersLoaded; private _initShaderSourceAsync; /** * Checks whether everything is ready to render a submesh to the G buffer. * @param subMesh the submesh to check readiness for * @param useInstances is the mesh drawn using instance or not * @returns true if ready otherwise false */ isReady(subMesh: SubMesh, useInstances: boolean): boolean; /** * Gets the current underlying G Buffer. * @returns the buffer */ getGBuffer(): MultiRenderTarget; /** * Gets the number of samples used to render the buffer (anti aliasing). */ get samples(): number; /** * Sets the number of samples used to render the buffer (anti aliasing). */ set samples(value: number); /** * Disposes the renderer and frees up associated resources. */ dispose(): void; private _assignRenderTargetIndices; protected _createRenderTargets(): void; private _copyBonesTransformationMatrices; } export {};