prePassRenderer.d.ts 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. import { PrePassRenderTarget } from "../Materials/Textures/prePassRenderTarget";
  2. import type { Scene } from "../scene";
  3. import type { Effect } from "../Materials/effect";
  4. import type { Nullable } from "../types";
  5. import type { AbstractMesh } from "../Meshes/abstractMesh";
  6. import type { Camera } from "../Cameras/camera";
  7. import { Material } from "../Materials/material";
  8. import type { SubMesh } from "../Meshes/subMesh";
  9. import type { PrePassEffectConfiguration } from "./prePassEffectConfiguration";
  10. import type { RenderTargetTexture } from "../Materials/Textures/renderTargetTexture";
  11. /**
  12. * Renders a pre pass of the scene
  13. * This means every mesh in the scene will be rendered to a render target texture
  14. * And then this texture will be composited to the rendering canvas with post processes
  15. * It is necessary for effects like subsurface scattering or deferred shading
  16. */
  17. export declare class PrePassRenderer {
  18. /**
  19. * @internal
  20. */
  21. static _SceneComponentInitialization: (scene: Scene) => void;
  22. /**
  23. * To save performance, we can excluded skinned meshes from the prepass
  24. */
  25. excludedSkinnedMesh: AbstractMesh[];
  26. /**
  27. * Force material to be excluded from the prepass
  28. * Can be useful when `useGeometryBufferFallback` is set to `true`
  29. * and you don't want a material to show in the effect.
  30. */
  31. excludedMaterials: Material[];
  32. private _scene;
  33. private _engine;
  34. /**
  35. * Number of textures in the multi render target texture where the scene is directly rendered
  36. */
  37. mrtCount: number;
  38. private _mrtTypes;
  39. private _mrtFormats;
  40. private _mrtLayout;
  41. private _mrtNames;
  42. private _textureIndices;
  43. private _multiRenderAttachments;
  44. private _defaultAttachments;
  45. private _clearAttachments;
  46. private _clearDepthAttachments;
  47. private _generateNormalsInWorldSpace;
  48. /**
  49. * Indicates if the prepass renderer is generating normals in world space or camera space (default: camera space)
  50. */
  51. get generateNormalsInWorldSpace(): boolean;
  52. set generateNormalsInWorldSpace(value: boolean);
  53. /**
  54. * Returns the index of a texture in the multi render target texture array.
  55. * @param type Texture type
  56. * @returns The index
  57. */
  58. getIndex(type: number): number;
  59. /**
  60. * How many samples are used for MSAA of the scene render target
  61. */
  62. get samples(): number;
  63. set samples(n: number);
  64. private _useSpecificClearForDepthTexture;
  65. /**
  66. * 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)
  67. * If set to false, the depth texture is always cleared with 0.
  68. */
  69. get useSpecificClearForDepthTexture(): boolean;
  70. set useSpecificClearForDepthTexture(value: boolean);
  71. /**
  72. * Describes the types and formats of the textures used by the pre-pass renderer
  73. */
  74. static TextureFormats: {
  75. purpose: number;
  76. type: number;
  77. format: number;
  78. name: string;
  79. }[];
  80. private _isDirty;
  81. /**
  82. * The render target where the scene is directly rendered
  83. */
  84. defaultRT: PrePassRenderTarget;
  85. /**
  86. * Configuration for prepass effects
  87. */
  88. private _effectConfigurations;
  89. /**
  90. * @returns the prepass render target for the rendering pass.
  91. * If we are currently rendering a render target, it returns the PrePassRenderTarget
  92. * associated with that render target. Otherwise, it returns the scene default PrePassRenderTarget
  93. */
  94. getRenderTarget(): PrePassRenderTarget;
  95. /**
  96. * @internal
  97. * Managed by the scene component
  98. * @param prePassRenderTarget
  99. */
  100. _setRenderTarget(prePassRenderTarget: Nullable<PrePassRenderTarget>): void;
  101. /**
  102. * Returns true if the currently rendered prePassRenderTarget is the one
  103. * associated with the scene.
  104. */
  105. get currentRTisSceneRT(): boolean;
  106. private _geometryBuffer;
  107. /**
  108. * Prevents the PrePassRenderer from using the GeometryBufferRenderer as a fallback
  109. */
  110. doNotUseGeometryRendererFallback: boolean;
  111. private _refreshGeometryBufferRendererLink;
  112. private _currentTarget;
  113. /**
  114. * All the render targets generated by prepass
  115. */
  116. renderTargets: PrePassRenderTarget[];
  117. private readonly _clearColor;
  118. private readonly _clearDepthColor;
  119. private _enabled;
  120. private _needsCompositionForThisPass;
  121. private _postProcessesSourceForThisPass;
  122. /**
  123. * Indicates if the prepass is enabled
  124. */
  125. get enabled(): boolean;
  126. /**
  127. * Set to true to disable gamma transform in PrePass.
  128. * Can be useful in case you already proceed to gamma transform on a material level
  129. * and your post processes don't need to be in linear color space.
  130. */
  131. disableGammaTransform: boolean;
  132. /**
  133. * Instantiates a prepass renderer
  134. * @param scene The scene
  135. */
  136. constructor(scene: Scene);
  137. /**
  138. * Creates a new PrePassRenderTarget
  139. * This should be the only way to instantiate a `PrePassRenderTarget`
  140. * @param name Name of the `PrePassRenderTarget`
  141. * @param renderTargetTexture RenderTarget the `PrePassRenderTarget` will be attached to.
  142. * Can be `null` if the created `PrePassRenderTarget` is attached to the scene (default framebuffer).
  143. * @internal
  144. */
  145. _createRenderTarget(name: string, renderTargetTexture: Nullable<RenderTargetTexture>): PrePassRenderTarget;
  146. /**
  147. * Indicates if rendering a prepass is supported
  148. */
  149. get isSupported(): boolean;
  150. /**
  151. * Sets the proper output textures to draw in the engine.
  152. * @param effect The effect that is drawn. It can be or not be compatible with drawing to several output textures.
  153. * @param subMesh Submesh on which the effect is applied
  154. */
  155. bindAttachmentsForEffect(effect: Effect, subMesh: SubMesh): void;
  156. private _reinitializeAttachments;
  157. private _resetLayout;
  158. private _updateGeometryBufferLayout;
  159. /**
  160. * Restores attachments for single texture draw.
  161. */
  162. restoreAttachments(): void;
  163. /**
  164. * @internal
  165. */
  166. _beforeDraw(camera?: Camera, faceIndex?: number, layer?: number): void;
  167. private _prepareFrame;
  168. /**
  169. * Sets an intermediary texture between prepass and postprocesses. This texture
  170. * will be used as input for post processes
  171. * @param rt The render target texture to use
  172. * @returns true if there are postprocesses that will use this texture,
  173. * false if there is no postprocesses - and the function has no effect
  174. */
  175. setCustomOutput(rt: RenderTargetTexture): boolean;
  176. private _renderPostProcesses;
  177. /**
  178. * @internal
  179. */
  180. _afterDraw(faceIndex?: number, layer?: number): void;
  181. /**
  182. * Clears the current prepass render target (in the sense of settings pixels to the scene clear color value)
  183. * @internal
  184. */
  185. _clear(): void;
  186. private _bindFrameBuffer;
  187. private _setEnabled;
  188. private _setRenderTargetEnabled;
  189. /**
  190. * Adds an effect configuration to the prepass render target.
  191. * If an effect has already been added, it won't add it twice and will return the configuration
  192. * already present.
  193. * @param cfg the effect configuration
  194. * @returns the effect configuration now used by the prepass
  195. */
  196. addEffectConfiguration(cfg: PrePassEffectConfiguration): PrePassEffectConfiguration;
  197. /**
  198. * Retrieves an effect configuration by name
  199. * @param name the name of the effect configuration
  200. * @returns the effect configuration, or null if not present
  201. */
  202. getEffectConfiguration(name: string): Nullable<PrePassEffectConfiguration>;
  203. private _enable;
  204. private _disable;
  205. private _getPostProcessesSource;
  206. private _setupOutputForThisPass;
  207. private _linkInternalTexture;
  208. /**
  209. * @internal
  210. */
  211. _unlinkInternalTexture(prePassRenderTarget: PrePassRenderTarget): void;
  212. private _needsImageProcessing;
  213. private _hasImageProcessing;
  214. /**
  215. * Internal, gets the first post proces.
  216. * @param postProcesses
  217. * @returns the first post process to be run on this camera.
  218. */
  219. private _getFirstPostProcess;
  220. /**
  221. * Marks the prepass renderer as dirty, triggering a check if the prepass is necessary for the next rendering.
  222. */
  223. markAsDirty(): void;
  224. /**
  225. * Enables a texture on the MultiRenderTarget for prepass
  226. * @param types
  227. */
  228. private _enableTextures;
  229. /**
  230. * Makes sure that the prepass renderer is up to date if it has been dirtified.
  231. */
  232. update(): void;
  233. private _update;
  234. private _markAllMaterialsAsPrePassDirty;
  235. /**
  236. * Disposes the prepass renderer.
  237. */
  238. dispose(): void;
  239. }