glowLayer.d.ts 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. import type { Nullable } from "../types";
  2. import type { Camera } from "../Cameras/camera";
  3. import type { Scene } from "../scene";
  4. import type { SubMesh } from "../Meshes/subMesh";
  5. import type { AbstractMesh } from "../Meshes/abstractMesh";
  6. import type { Mesh } from "../Meshes/mesh";
  7. import { Texture } from "../Materials/Textures/texture";
  8. import type { Effect } from "../Materials/effect";
  9. import { Material } from "../Materials/material";
  10. import { EffectLayer } from "./effectLayer";
  11. import { Color4 } from "../Maths/math.color";
  12. import "../Shaders/glowMapMerge.fragment";
  13. import "../Shaders/glowMapMerge.vertex";
  14. import "../Layers/effectLayerSceneComponent";
  15. declare module "../abstractScene" {
  16. interface AbstractScene {
  17. /**
  18. * Return the first glow layer of the scene with a given name.
  19. * @param name The name of the glow layer to look for.
  20. * @returns The glow layer if found otherwise null.
  21. */
  22. getGlowLayerByName(name: string): Nullable<GlowLayer>;
  23. }
  24. }
  25. /**
  26. * Glow layer options. This helps customizing the behaviour
  27. * of the glow layer.
  28. */
  29. export interface IGlowLayerOptions {
  30. /**
  31. * Multiplication factor apply to the canvas size to compute the render target size
  32. * used to generated the glowing objects (the smaller the faster). Default: 0.5
  33. */
  34. mainTextureRatio: number;
  35. /**
  36. * Enforces a fixed size texture to ensure resize independent blur. Default: undefined
  37. */
  38. mainTextureFixedSize?: number;
  39. /**
  40. * How big is the kernel of the blur texture. Default: 32
  41. */
  42. blurKernelSize: number;
  43. /**
  44. * The camera attached to the layer. Default: null
  45. */
  46. camera: Nullable<Camera>;
  47. /**
  48. * Enable MSAA by choosing the number of samples. Default: 1
  49. */
  50. mainTextureSamples?: number;
  51. /**
  52. * The rendering group to draw the layer in. Default: -1
  53. */
  54. renderingGroupId: number;
  55. /**
  56. * Forces the merge step to be done in ldr (clamp values > 1). Default: false
  57. */
  58. ldrMerge?: boolean;
  59. /**
  60. * Defines the blend mode used by the merge. Default: ALPHA_ADD
  61. */
  62. alphaBlendingMode?: number;
  63. /**
  64. * The type of the main texture. Default: TEXTURETYPE_UNSIGNED_INT
  65. */
  66. mainTextureType: number;
  67. /**
  68. * Whether or not to generate a stencil buffer. Default: false
  69. */
  70. generateStencilBuffer: boolean;
  71. }
  72. /**
  73. * The glow layer Helps adding a glow effect around the emissive parts of a mesh.
  74. *
  75. * Once instantiated in a scene, by default, all the emissive meshes will glow.
  76. *
  77. * Documentation: https://doc.babylonjs.com/features/featuresDeepDive/mesh/glowLayer
  78. */
  79. export declare class GlowLayer extends EffectLayer {
  80. /**
  81. * Effect Name of the layer.
  82. */
  83. static readonly EffectName = "GlowLayer";
  84. /**
  85. * The default blur kernel size used for the glow.
  86. */
  87. static DefaultBlurKernelSize: number;
  88. /**
  89. * The default texture size ratio used for the glow.
  90. */
  91. static DefaultTextureRatio: number;
  92. /**
  93. * Sets the kernel size of the blur.
  94. */
  95. set blurKernelSize(value: number);
  96. /**
  97. * Gets the kernel size of the blur.
  98. */
  99. get blurKernelSize(): number;
  100. /**
  101. * Sets the glow intensity.
  102. */
  103. set intensity(value: number);
  104. /**
  105. * Gets the glow intensity.
  106. */
  107. get intensity(): number;
  108. private _options;
  109. private _intensity;
  110. private _horizontalBlurPostprocess1;
  111. private _verticalBlurPostprocess1;
  112. private _horizontalBlurPostprocess2;
  113. private _verticalBlurPostprocess2;
  114. private _blurTexture1;
  115. private _blurTexture2;
  116. private _postProcesses1;
  117. private _postProcesses2;
  118. private _includedOnlyMeshes;
  119. private _excludedMeshes;
  120. private _meshesUsingTheirOwnMaterials;
  121. /**
  122. * Callback used to let the user override the color selection on a per mesh basis
  123. */
  124. customEmissiveColorSelector: (mesh: Mesh, subMesh: SubMesh, material: Material, result: Color4) => void;
  125. /**
  126. * Callback used to let the user override the texture selection on a per mesh basis
  127. */
  128. customEmissiveTextureSelector: (mesh: Mesh, subMesh: SubMesh, material: Material) => Texture;
  129. /**
  130. * Instantiates a new glow Layer and references it to the scene.
  131. * @param name The name of the layer
  132. * @param scene The scene to use the layer in
  133. * @param options Sets of none mandatory options to use with the layer (see IGlowLayerOptions for more information)
  134. */
  135. constructor(name: string, scene?: Scene, options?: Partial<IGlowLayerOptions>);
  136. /**
  137. * Get the effect name of the layer.
  138. * @returns The effect name
  139. */
  140. getEffectName(): string;
  141. /**
  142. * @internal
  143. * Create the merge effect. This is the shader use to blit the information back
  144. * to the main canvas at the end of the scene rendering.
  145. */
  146. protected _createMergeEffect(): Effect;
  147. /**
  148. * Creates the render target textures and post processes used in the glow layer.
  149. */
  150. protected _createTextureAndPostProcesses(): void;
  151. /**
  152. * @returns The blur kernel size used by the glow.
  153. * Note: The value passed in the options is divided by 2 for back compatibility.
  154. */
  155. private _getEffectiveBlurKernelSize;
  156. /**
  157. * Checks for the readiness of the element composing the layer.
  158. * @param subMesh the mesh to check for
  159. * @param useInstances specify whether or not to use instances to render the mesh
  160. * @returns true if ready otherwise, false
  161. */
  162. isReady(subMesh: SubMesh, useInstances: boolean): boolean;
  163. /**
  164. * @returns whether or not the layer needs stencil enabled during the mesh rendering.
  165. */
  166. needStencil(): boolean;
  167. /**
  168. * Returns true if the mesh can be rendered, otherwise false.
  169. * @param mesh The mesh to render
  170. * @param material The material used on the mesh
  171. * @returns true if it can be rendered otherwise false
  172. */
  173. protected _canRenderMesh(mesh: AbstractMesh, material: Material): boolean;
  174. /**
  175. * Implementation specific of rendering the generating effect on the main canvas.
  176. * @param effect The effect used to render through
  177. */
  178. protected _internalRender(effect: Effect): void;
  179. /**
  180. * Sets the required values for both the emissive texture and and the main color.
  181. * @param mesh
  182. * @param subMesh
  183. * @param material
  184. */
  185. protected _setEmissiveTextureAndColor(mesh: Mesh, subMesh: SubMesh, material: Material): void;
  186. /**
  187. * Returns true if the mesh should render, otherwise false.
  188. * @param mesh The mesh to render
  189. * @returns true if it should render otherwise false
  190. */
  191. protected _shouldRenderMesh(mesh: Mesh): boolean;
  192. /**
  193. * Adds specific effects defines.
  194. * @param defines The defines to add specifics to.
  195. */
  196. protected _addCustomEffectDefines(defines: string[]): void;
  197. /**
  198. * Add a mesh in the exclusion list to prevent it to impact or being impacted by the glow layer.
  199. * @param mesh The mesh to exclude from the glow layer
  200. */
  201. addExcludedMesh(mesh: Mesh): void;
  202. /**
  203. * Remove a mesh from the exclusion list to let it impact or being impacted by the glow layer.
  204. * @param mesh The mesh to remove
  205. */
  206. removeExcludedMesh(mesh: Mesh): void;
  207. /**
  208. * Add a mesh in the inclusion list to impact or being impacted by the glow layer.
  209. * @param mesh The mesh to include in the glow layer
  210. */
  211. addIncludedOnlyMesh(mesh: Mesh): void;
  212. /**
  213. * Remove a mesh from the Inclusion list to prevent it to impact or being impacted by the glow layer.
  214. * @param mesh The mesh to remove
  215. */
  216. removeIncludedOnlyMesh(mesh: Mesh): void;
  217. /**
  218. * Determine if a given mesh will be used in the glow layer
  219. * @param mesh The mesh to test
  220. * @returns true if the mesh will be highlighted by the current glow layer
  221. */
  222. hasMesh(mesh: AbstractMesh): boolean;
  223. /**
  224. * Defines whether the current material of the mesh should be use to render the effect.
  225. * @param mesh defines the current mesh to render
  226. * @returns true if the material of the mesh should be use to render the effect
  227. */
  228. protected _useMeshMaterial(mesh: AbstractMesh): boolean;
  229. /**
  230. * Add a mesh to be rendered through its own material and not with emissive only.
  231. * @param mesh The mesh for which we need to use its material
  232. */
  233. referenceMeshToUseItsOwnMaterial(mesh: AbstractMesh): void;
  234. /**
  235. * Remove a mesh from being rendered through its own material and not with emissive only.
  236. * @param mesh The mesh for which we need to not use its material
  237. */
  238. unReferenceMeshFromUsingItsOwnMaterial(mesh: AbstractMesh): void;
  239. /**
  240. * Free any resources and references associated to a mesh.
  241. * Internal use
  242. * @param mesh The mesh to free.
  243. * @internal
  244. */
  245. _disposeMesh(mesh: Mesh): void;
  246. /**
  247. * Gets the class name of the effect layer
  248. * @returns the string with the class name of the effect layer
  249. */
  250. getClassName(): string;
  251. /**
  252. * Serializes this glow layer
  253. * @returns a serialized glow layer object
  254. */
  255. serialize(): any;
  256. /**
  257. * Creates a Glow Layer from parsed glow layer data
  258. * @param parsedGlowLayer defines glow layer data
  259. * @param scene defines the current scene
  260. * @param rootUrl defines the root URL containing the glow layer information
  261. * @returns a parsed Glow Layer
  262. */
  263. static Parse(parsedGlowLayer: any, scene: Scene, rootUrl: string): GlowLayer;
  264. }