highlightLayer.d.ts 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. import { Observable } from "../Misc/observable";
  2. import type { Nullable } from "../types";
  3. import type { Camera } from "../Cameras/camera";
  4. import type { Scene } from "../scene";
  5. import type { SubMesh } from "../Meshes/subMesh";
  6. import type { AbstractMesh } from "../Meshes/abstractMesh";
  7. import type { Mesh } from "../Meshes/mesh";
  8. import type { Effect } from "../Materials/effect";
  9. import { Material } from "../Materials/material";
  10. import { EffectLayer } from "./effectLayer";
  11. import { Color4, Color3 } from "../Maths/math.color";
  12. import "../Shaders/glowMapMerge.fragment";
  13. import "../Shaders/glowMapMerge.vertex";
  14. import "../Shaders/glowBlurPostProcess.fragment";
  15. import "../Layers/effectLayerSceneComponent";
  16. declare module "../abstractScene" {
  17. interface AbstractScene {
  18. /**
  19. * Return a the first highlight layer of the scene with a given name.
  20. * @param name The name of the highlight layer to look for.
  21. * @returns The highlight layer if found otherwise null.
  22. */
  23. getHighlightLayerByName(name: string): Nullable<HighlightLayer>;
  24. }
  25. }
  26. /**
  27. * Highlight layer options. This helps customizing the behaviour
  28. * of the highlight layer.
  29. */
  30. export interface IHighlightLayerOptions {
  31. /**
  32. * Multiplication factor apply to the canvas size to compute the render target size
  33. * used to generated the glowing objects (the smaller the faster). Default: 0.5
  34. */
  35. mainTextureRatio: number;
  36. /**
  37. * Enforces a fixed size texture to ensure resize independent blur. Default: undefined
  38. */
  39. mainTextureFixedSize?: number;
  40. /**
  41. * Multiplication factor apply to the main texture size in the first step of the blur to reduce the size
  42. * of the picture to blur (the smaller the faster). Default: 0.5
  43. */
  44. blurTextureSizeRatio: number;
  45. /**
  46. * How big in texel of the blur texture is the vertical blur. Default: 1
  47. */
  48. blurVerticalSize: number;
  49. /**
  50. * How big in texel of the blur texture is the horizontal blur. Default: 1
  51. */
  52. blurHorizontalSize: number;
  53. /**
  54. * Alpha blending mode used to apply the blur. Default: ALPHA_COMBINE
  55. */
  56. alphaBlendingMode: number;
  57. /**
  58. * The camera attached to the layer. Default: null
  59. */
  60. camera: Nullable<Camera>;
  61. /**
  62. * Should we display highlight as a solid stroke? Default: false
  63. */
  64. isStroke?: boolean;
  65. /**
  66. * The rendering group to draw the layer in. Default: -1
  67. */
  68. renderingGroupId: number;
  69. /**
  70. * The type of the main texture. Default: TEXTURETYPE_UNSIGNED_INT
  71. */
  72. mainTextureType: number;
  73. }
  74. /**
  75. * The highlight layer Helps adding a glow effect around a mesh.
  76. *
  77. * Once instantiated in a scene, simply use the addMesh or removeMesh method to add or remove
  78. * glowy meshes to your scene.
  79. *
  80. * !!! THIS REQUIRES AN ACTIVE STENCIL BUFFER ON THE CANVAS !!!
  81. */
  82. export declare class HighlightLayer extends EffectLayer {
  83. name: string;
  84. /**
  85. * Effect Name of the highlight layer.
  86. */
  87. static readonly EffectName = "HighlightLayer";
  88. /**
  89. * The neutral color used during the preparation of the glow effect.
  90. * This is black by default as the blend operation is a blend operation.
  91. */
  92. static NeutralColor: Color4;
  93. /**
  94. * Stencil value used for glowing meshes.
  95. */
  96. static GlowingMeshStencilReference: number;
  97. /**
  98. * Stencil value used for the other meshes in the scene.
  99. */
  100. static NormalMeshStencilReference: number;
  101. /**
  102. * Specifies whether or not the inner glow is ACTIVE in the layer.
  103. */
  104. innerGlow: boolean;
  105. /**
  106. * Specifies whether or not the outer glow is ACTIVE in the layer.
  107. */
  108. outerGlow: boolean;
  109. /**
  110. * Specifies the horizontal size of the blur.
  111. */
  112. set blurHorizontalSize(value: number);
  113. /**
  114. * Specifies the vertical size of the blur.
  115. */
  116. set blurVerticalSize(value: number);
  117. /**
  118. * Gets the horizontal size of the blur.
  119. */
  120. get blurHorizontalSize(): number;
  121. /**
  122. * Gets the vertical size of the blur.
  123. */
  124. get blurVerticalSize(): number;
  125. /**
  126. * An event triggered when the highlight layer is being blurred.
  127. */
  128. onBeforeBlurObservable: Observable<HighlightLayer>;
  129. /**
  130. * An event triggered when the highlight layer has been blurred.
  131. */
  132. onAfterBlurObservable: Observable<HighlightLayer>;
  133. private _instanceGlowingMeshStencilReference;
  134. private _options;
  135. private _downSamplePostprocess;
  136. private _horizontalBlurPostprocess;
  137. private _verticalBlurPostprocess;
  138. private _blurTexture;
  139. private _meshes;
  140. private _excludedMeshes;
  141. /**
  142. * Instantiates a new highlight Layer and references it to the scene..
  143. * @param name The name of the layer
  144. * @param scene The scene to use the layer in
  145. * @param options Sets of none mandatory options to use with the layer (see IHighlightLayerOptions for more information)
  146. */
  147. constructor(name: string, scene?: Scene, options?: Partial<IHighlightLayerOptions>);
  148. /**
  149. * Get the effect name of the layer.
  150. * @returns The effect name
  151. */
  152. getEffectName(): string;
  153. protected _numInternalDraws(): number;
  154. /**
  155. * Create the merge effect. This is the shader use to blit the information back
  156. * to the main canvas at the end of the scene rendering.
  157. * @returns The effect created
  158. */
  159. protected _createMergeEffect(): Effect;
  160. /**
  161. * Creates the render target textures and post processes used in the highlight layer.
  162. */
  163. protected _createTextureAndPostProcesses(): void;
  164. /**
  165. * @returns whether or not the layer needs stencil enabled during the mesh rendering.
  166. */
  167. needStencil(): boolean;
  168. /**
  169. * Checks for the readiness of the element composing the layer.
  170. * @param subMesh the mesh to check for
  171. * @param useInstances specify whether or not to use instances to render the mesh
  172. * @returns true if ready otherwise, false
  173. */
  174. isReady(subMesh: SubMesh, useInstances: boolean): boolean;
  175. /**
  176. * Implementation specific of rendering the generating effect on the main canvas.
  177. * @param effect The effect used to render through
  178. * @param renderIndex
  179. */
  180. protected _internalRender(effect: Effect, renderIndex: number): void;
  181. /**
  182. * @returns true if the layer contains information to display, otherwise false.
  183. */
  184. shouldRender(): boolean;
  185. /**
  186. * Returns true if the mesh should render, otherwise false.
  187. * @param mesh The mesh to render
  188. * @returns true if it should render otherwise false
  189. */
  190. protected _shouldRenderMesh(mesh: Mesh): boolean;
  191. /**
  192. * Returns true if the mesh can be rendered, otherwise false.
  193. * @param mesh The mesh to render
  194. * @param material The material used on the mesh
  195. * @returns true if it can be rendered otherwise false
  196. */
  197. protected _canRenderMesh(mesh: AbstractMesh, material: Material): boolean;
  198. /**
  199. * Adds specific effects defines.
  200. * @param defines The defines to add specifics to.
  201. */
  202. protected _addCustomEffectDefines(defines: string[]): void;
  203. /**
  204. * Sets the required values for both the emissive texture and and the main color.
  205. * @param mesh
  206. * @param subMesh
  207. * @param material
  208. */
  209. protected _setEmissiveTextureAndColor(mesh: Mesh, subMesh: SubMesh, material: Material): void;
  210. /**
  211. * Add a mesh in the exclusion list to prevent it to impact or being impacted by the highlight layer.
  212. * @param mesh The mesh to exclude from the highlight layer
  213. */
  214. addExcludedMesh(mesh: Mesh): void;
  215. /**
  216. * Remove a mesh from the exclusion list to let it impact or being impacted by the highlight layer.
  217. * @param mesh The mesh to highlight
  218. */
  219. removeExcludedMesh(mesh: Mesh): void;
  220. /**
  221. * Determine if a given mesh will be highlighted by the current HighlightLayer
  222. * @param mesh mesh to test
  223. * @returns true if the mesh will be highlighted by the current HighlightLayer
  224. */
  225. hasMesh(mesh: AbstractMesh): boolean;
  226. /**
  227. * Add a mesh in the highlight layer in order to make it glow with the chosen color.
  228. * @param mesh The mesh to highlight
  229. * @param color The color of the highlight
  230. * @param glowEmissiveOnly Extract the glow from the emissive texture
  231. */
  232. addMesh(mesh: Mesh, color: Color3, glowEmissiveOnly?: boolean): void;
  233. /**
  234. * Remove a mesh from the highlight layer in order to make it stop glowing.
  235. * @param mesh The mesh to highlight
  236. */
  237. removeMesh(mesh: Mesh): void;
  238. /**
  239. * Remove all the meshes currently referenced in the highlight layer
  240. */
  241. removeAllMeshes(): void;
  242. /**
  243. * Force the stencil to the normal expected value for none glowing parts
  244. * @param mesh
  245. */
  246. private _defaultStencilReference;
  247. /**
  248. * Free any resources and references associated to a mesh.
  249. * Internal use
  250. * @param mesh The mesh to free.
  251. * @internal
  252. */
  253. _disposeMesh(mesh: Mesh): void;
  254. /**
  255. * Dispose the highlight layer and free resources.
  256. */
  257. dispose(): void;
  258. /**
  259. * Gets the class name of the effect layer
  260. * @returns the string with the class name of the effect layer
  261. */
  262. getClassName(): string;
  263. /**
  264. * Serializes this Highlight layer
  265. * @returns a serialized Highlight layer object
  266. */
  267. serialize(): any;
  268. /**
  269. * Creates a Highlight layer from parsed Highlight layer data
  270. * @param parsedHightlightLayer defines the Highlight layer data
  271. * @param scene defines the current scene
  272. * @param rootUrl defines the root URL containing the Highlight layer information
  273. * @returns a parsed Highlight layer
  274. */
  275. static Parse(parsedHightlightLayer: any, scene: Scene, rootUrl: string): HighlightLayer;
  276. }