geometryBufferRenderer.d.ts 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. import { Matrix } from "../Maths/math.vector";
  2. import type { SubMesh } from "../Meshes/subMesh";
  3. import type { InternalTexture } from "../Materials/Textures/internalTexture";
  4. import { MultiRenderTarget } from "../Materials/Textures/multiRenderTarget";
  5. import type { PrePassRenderer } from "../Rendering/prePassRenderer";
  6. import type { Scene } from "../scene";
  7. import type { AbstractMesh } from "../Meshes/abstractMesh";
  8. import type { Nullable } from "../types";
  9. import "../Shaders/geometry.fragment";
  10. import "../Shaders/geometry.vertex";
  11. /** @internal */
  12. interface ISavedTransformationMatrix {
  13. world: Matrix;
  14. viewProjection: Matrix;
  15. }
  16. /**
  17. * This renderer is helpful to fill one of the render target with a geometry buffer.
  18. */
  19. export declare class GeometryBufferRenderer {
  20. /**
  21. * Constant used to retrieve the depth texture index in the G-Buffer textures array
  22. * using getIndex(GeometryBufferRenderer.DEPTH_TEXTURE_INDEX)
  23. */
  24. static readonly DEPTH_TEXTURE_TYPE = 0;
  25. /**
  26. * Constant used to retrieve the normal texture index in the G-Buffer textures array
  27. * using getIndex(GeometryBufferRenderer.NORMAL_TEXTURE_INDEX)
  28. */
  29. static readonly NORMAL_TEXTURE_TYPE = 1;
  30. /**
  31. * Constant used to retrieve the position texture index in the G-Buffer textures array
  32. * using getIndex(GeometryBufferRenderer.POSITION_TEXTURE_INDEX)
  33. */
  34. static readonly POSITION_TEXTURE_TYPE = 2;
  35. /**
  36. * Constant used to retrieve the velocity texture index in the G-Buffer textures array
  37. * using getIndex(GeometryBufferRenderer.VELOCITY_TEXTURE_INDEX)
  38. */
  39. static readonly VELOCITY_TEXTURE_TYPE = 3;
  40. /**
  41. * Constant used to retrieve the reflectivity texture index in the G-Buffer textures array
  42. * using the getIndex(GeometryBufferRenderer.REFLECTIVITY_TEXTURE_TYPE)
  43. */
  44. static readonly REFLECTIVITY_TEXTURE_TYPE = 4;
  45. /**
  46. * Dictionary used to store the previous transformation matrices of each rendered mesh
  47. * in order to compute objects velocities when enableVelocity is set to "true"
  48. * @internal
  49. */
  50. _previousTransformationMatrices: {
  51. [index: number]: ISavedTransformationMatrix;
  52. };
  53. /**
  54. * Dictionary used to store the previous bones transformation matrices of each rendered mesh
  55. * in order to compute objects velocities when enableVelocity is set to "true"
  56. * @internal
  57. */
  58. _previousBonesTransformationMatrices: {
  59. [index: number]: Float32Array;
  60. };
  61. /**
  62. * Array used to store the ignored skinned meshes while computing velocity map (typically used by the motion blur post-process).
  63. * Avoids computing bones velocities and computes only mesh's velocity itself (position, rotation, scaling).
  64. */
  65. excludedSkinnedMeshesFromVelocity: AbstractMesh[];
  66. /** Gets or sets a boolean indicating if transparent meshes should be rendered */
  67. renderTransparentMeshes: boolean;
  68. /**
  69. * Gets or sets a boolean indicating if normals should be generated in world space (default: false, meaning normals are generated in view space)
  70. */
  71. generateNormalsInWorldSpace: boolean;
  72. private _normalsAreUnsigned;
  73. /**
  74. * 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
  75. */
  76. get normalsAreUnsigned(): boolean;
  77. private _scene;
  78. private _resizeObserver;
  79. private _multiRenderTarget;
  80. private _textureTypesAndFormats;
  81. private _ratioOrDimensions;
  82. private _enablePosition;
  83. private _enableVelocity;
  84. private _enableReflectivity;
  85. private _depthFormat;
  86. private _clearColor;
  87. private _clearDepthColor;
  88. private _positionIndex;
  89. private _velocityIndex;
  90. private _reflectivityIndex;
  91. private _depthIndex;
  92. private _normalIndex;
  93. private _linkedWithPrePass;
  94. private _prePassRenderer;
  95. private _attachmentsFromPrePass;
  96. private _useUbo;
  97. protected _cachedDefines: string;
  98. /**
  99. * @internal
  100. * Sets up internal structures to share outputs with PrePassRenderer
  101. * This method should only be called by the PrePassRenderer itself
  102. */
  103. _linkPrePassRenderer(prePassRenderer: PrePassRenderer): void;
  104. /**
  105. * @internal
  106. * Separates internal structures from PrePassRenderer so the geometry buffer can now operate by itself.
  107. * This method should only be called by the PrePassRenderer itself
  108. */
  109. _unlinkPrePassRenderer(): void;
  110. /**
  111. * @internal
  112. * Resets the geometry buffer layout
  113. */
  114. _resetLayout(): void;
  115. /**
  116. * @internal
  117. * Replaces a texture in the geometry buffer renderer
  118. * Useful when linking textures of the prepass renderer
  119. */
  120. _forceTextureType(geometryBufferType: number, index: number): void;
  121. /**
  122. * @internal
  123. * Sets texture attachments
  124. * Useful when linking textures of the prepass renderer
  125. */
  126. _setAttachments(attachments: number[]): void;
  127. /**
  128. * @internal
  129. * Replaces the first texture which is hard coded as a depth texture in the geometry buffer
  130. * Useful when linking textures of the prepass renderer
  131. */
  132. _linkInternalTexture(internalTexture: InternalTexture): void;
  133. /**
  134. * Gets the render list (meshes to be rendered) used in the G buffer.
  135. */
  136. get renderList(): Nullable<AbstractMesh[]>;
  137. /**
  138. * Set the render list (meshes to be rendered) used in the G buffer.
  139. */
  140. set renderList(meshes: Nullable<AbstractMesh[]>);
  141. /**
  142. * Gets whether or not G buffer are supported by the running hardware.
  143. * This requires draw buffer supports
  144. */
  145. get isSupported(): boolean;
  146. /**
  147. * Returns the index of the given texture type in the G-Buffer textures array
  148. * @param textureType The texture type constant. For example GeometryBufferRenderer.POSITION_TEXTURE_INDEX
  149. * @returns the index of the given texture type in the G-Buffer textures array
  150. */
  151. getTextureIndex(textureType: number): number;
  152. /**
  153. * @returns a boolean indicating if objects positions are enabled for the G buffer.
  154. */
  155. get enablePosition(): boolean;
  156. /**
  157. * Sets whether or not objects positions are enabled for the G buffer.
  158. */
  159. set enablePosition(enable: boolean);
  160. /**
  161. * @returns a boolean indicating if objects velocities are enabled for the G buffer.
  162. */
  163. get enableVelocity(): boolean;
  164. /**
  165. * Sets whether or not objects velocities are enabled for the G buffer.
  166. */
  167. set enableVelocity(enable: boolean);
  168. /**
  169. * Gets a boolean indicating if objects reflectivity are enabled in the G buffer.
  170. */
  171. get enableReflectivity(): boolean;
  172. /**
  173. * Sets whether or not objects reflectivity are enabled for the G buffer.
  174. * For Metallic-Roughness workflow with ORM texture, we assume that ORM texture is defined according to the default layout:
  175. * pbr.useRoughnessFromMetallicTextureAlpha = false;
  176. * pbr.useRoughnessFromMetallicTextureGreen = true;
  177. * pbr.useMetallnessFromMetallicTextureBlue = true;
  178. */
  179. set enableReflectivity(enable: boolean);
  180. /**
  181. * 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)
  182. * If set to false, the depth texture is always cleared with 0.
  183. */
  184. useSpecificClearForDepthTexture: boolean;
  185. /**
  186. * Gets the scene associated with the buffer.
  187. */
  188. get scene(): Scene;
  189. /**
  190. * Gets the ratio used by the buffer during its creation.
  191. * How big is the buffer related to the main canvas.
  192. */
  193. get ratio(): number;
  194. /**
  195. * @internal
  196. */
  197. static _SceneComponentInitialization: (scene: Scene) => void;
  198. /**
  199. * Creates a new G Buffer for the scene
  200. * @param scene The scene the buffer belongs to
  201. * @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
  202. * @param depthFormat Format of the depth texture (default: Constants.TEXTUREFORMAT_DEPTH16)
  203. * @param textureTypesAndFormats The types and formats 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.
  204. */
  205. constructor(scene: Scene, ratioOrDimensions?: number | {
  206. width: number;
  207. height: number;
  208. }, depthFormat?: number, textureTypesAndFormats?: {
  209. [key: number]: {
  210. textureType: number;
  211. textureFormat: number;
  212. };
  213. });
  214. /**
  215. * Checks whether everything is ready to render a submesh to the G buffer.
  216. * @param subMesh the submesh to check readiness for
  217. * @param useInstances is the mesh drawn using instance or not
  218. * @returns true if ready otherwise false
  219. */
  220. isReady(subMesh: SubMesh, useInstances: boolean): boolean;
  221. /**
  222. * Gets the current underlying G Buffer.
  223. * @returns the buffer
  224. */
  225. getGBuffer(): MultiRenderTarget;
  226. /**
  227. * Gets the number of samples used to render the buffer (anti aliasing).
  228. */
  229. get samples(): number;
  230. /**
  231. * Sets the number of samples used to render the buffer (anti aliasing).
  232. */
  233. set samples(value: number);
  234. /**
  235. * Disposes the renderer and frees up associated resources.
  236. */
  237. dispose(): void;
  238. private _assignRenderTargetIndices;
  239. protected _createRenderTargets(): void;
  240. private _copyBonesTransformationMatrices;
  241. }
  242. export {};