materialPluginBase.d.ts 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. import type { Nullable } from "../types";
  2. import { MaterialPluginManager } from "./materialPluginManager";
  3. import type { SmartArray } from "../Misc/smartArray";
  4. import type { AbstractEngine } from "../Engines/abstractEngine";
  5. import type { Scene } from "../scene";
  6. import type { AbstractMesh } from "../Meshes/abstractMesh";
  7. import type { SubMesh } from "../Meshes/subMesh";
  8. import type { IAnimatable } from "../Animations/animatable.interface";
  9. import type { UniformBuffer } from "./uniformBuffer";
  10. import type { EffectFallbacks } from "./effectFallbacks";
  11. import type { MaterialDefines } from "./materialDefines";
  12. import type { Material } from "./material";
  13. import type { BaseTexture } from "./Textures/baseTexture";
  14. import type { RenderTargetTexture } from "./Textures/renderTargetTexture";
  15. /**
  16. * Base class for material plugins.
  17. * @since 5.0
  18. */
  19. export declare class MaterialPluginBase {
  20. /**
  21. * Defines the name of the plugin
  22. */
  23. name: string;
  24. /**
  25. * Defines the priority of the plugin. Lower numbers run first.
  26. */
  27. priority: number;
  28. /**
  29. * Indicates that any #include directive in the plugin code must be replaced by the corresponding code.
  30. */
  31. resolveIncludes: boolean;
  32. /**
  33. * Indicates that this plugin should be notified for the extra events (HasRenderTargetTextures / FillRenderTargetTextures / HardBindForSubMesh)
  34. */
  35. registerForExtraEvents: boolean;
  36. protected _material: Material;
  37. protected _pluginManager: MaterialPluginManager;
  38. protected _pluginDefineNames?: {
  39. [name: string]: any;
  40. };
  41. protected _enable(enable: boolean): void;
  42. /**
  43. * Helper function to mark defines as being dirty.
  44. */
  45. readonly markAllDefinesAsDirty: () => void;
  46. /**
  47. * Creates a new material plugin
  48. * @param material parent material of the plugin
  49. * @param name name of the plugin
  50. * @param priority priority of the plugin
  51. * @param defines list of defines used by the plugin. The value of the property is the default value for this property
  52. * @param addToPluginList true to add the plugin to the list of plugins managed by the material plugin manager of the material (default: true)
  53. * @param enable true to enable the plugin (it is handy if the plugin does not handle properties to switch its current activation)
  54. * @param resolveIncludes Indicates that any #include directive in the plugin code must be replaced by the corresponding code (default: false)
  55. */
  56. constructor(material: Material, name: string, priority: number, defines?: {
  57. [key: string]: any;
  58. }, addToPluginList?: boolean, enable?: boolean, resolveIncludes?: boolean);
  59. /**
  60. * Gets the current class name useful for serialization or dynamic coding.
  61. * @returns The class name.
  62. */
  63. getClassName(): string;
  64. /**
  65. * Specifies that the submesh is ready to be used.
  66. * @param defines the list of "defines" to update.
  67. * @param scene defines the scene the material belongs to.
  68. * @param engine the engine this scene belongs to.
  69. * @param subMesh the submesh to check for readiness
  70. * @returns - boolean indicating that the submesh is ready or not.
  71. */
  72. isReadyForSubMesh(defines: MaterialDefines, scene: Scene, engine: AbstractEngine, subMesh: SubMesh): boolean;
  73. /**
  74. * Binds the material data (this function is called even if mustRebind() returns false)
  75. * @param uniformBuffer defines the Uniform buffer to fill in.
  76. * @param scene defines the scene the material belongs to.
  77. * @param engine defines the engine the material belongs to.
  78. * @param subMesh the submesh to bind data for
  79. */
  80. hardBindForSubMesh(uniformBuffer: UniformBuffer, scene: Scene, engine: AbstractEngine, subMesh: SubMesh): void;
  81. /**
  82. * Binds the material data.
  83. * @param uniformBuffer defines the Uniform buffer to fill in.
  84. * @param scene defines the scene the material belongs to.
  85. * @param engine the engine this scene belongs to.
  86. * @param subMesh the submesh to bind data for
  87. */
  88. bindForSubMesh(uniformBuffer: UniformBuffer, scene: Scene, engine: AbstractEngine, subMesh: SubMesh): void;
  89. /**
  90. * Disposes the resources of the material.
  91. * @param forceDisposeTextures - Forces the disposal of all textures.
  92. */
  93. dispose(forceDisposeTextures?: boolean): void;
  94. /**
  95. * Returns a list of custom shader code fragments to customize the shader.
  96. * @param shaderType "vertex" or "fragment"
  97. * @returns null if no code to be added, or a list of pointName =\> code.
  98. * Note that `pointName` can also be a regular expression if it starts with a `!`.
  99. * In that case, the string found by the regular expression (if any) will be
  100. * replaced by the code provided.
  101. */
  102. getCustomCode(shaderType: string): Nullable<{
  103. [pointName: string]: string;
  104. }>;
  105. /**
  106. * Collects all defines.
  107. * @param defines The object to append to.
  108. */
  109. collectDefines(defines: {
  110. [name: string]: {
  111. type: string;
  112. default: any;
  113. };
  114. }): void;
  115. /**
  116. * Sets the defines for the next rendering. Called before PrepareDefinesForAttributes is called.
  117. * @param defines the list of "defines" to update.
  118. * @param scene defines the scene to the material belongs to.
  119. * @param mesh the mesh being rendered
  120. */
  121. prepareDefinesBeforeAttributes(defines: MaterialDefines, scene: Scene, mesh: AbstractMesh): void;
  122. /**
  123. * Sets the defines for the next rendering
  124. * @param defines the list of "defines" to update.
  125. * @param scene defines the scene to the material belongs to.
  126. * @param mesh the mesh being rendered
  127. */
  128. prepareDefines(defines: MaterialDefines, scene: Scene, mesh: AbstractMesh): void;
  129. /**
  130. * Checks to see if a texture is used in the material.
  131. * @param texture - Base texture to use.
  132. * @returns - Boolean specifying if a texture is used in the material.
  133. */
  134. hasTexture(texture: BaseTexture): boolean;
  135. /**
  136. * Gets a boolean indicating that current material needs to register RTT
  137. * @returns true if this uses a render target otherwise false.
  138. */
  139. hasRenderTargetTextures(): boolean;
  140. /**
  141. * Fills the list of render target textures.
  142. * @param renderTargets the list of render targets to update
  143. */
  144. fillRenderTargetTextures(renderTargets: SmartArray<RenderTargetTexture>): void;
  145. /**
  146. * Returns an array of the actively used textures.
  147. * @param activeTextures Array of BaseTextures
  148. */
  149. getActiveTextures(activeTextures: BaseTexture[]): void;
  150. /**
  151. * Returns the animatable textures.
  152. * @param animatables Array of animatable textures.
  153. */
  154. getAnimatables(animatables: IAnimatable[]): void;
  155. /**
  156. * Add fallbacks to the effect fallbacks list.
  157. * @param defines defines the Base texture to use.
  158. * @param fallbacks defines the current fallback list.
  159. * @param currentRank defines the current fallback rank.
  160. * @returns the new fallback rank.
  161. */
  162. addFallbacks(defines: MaterialDefines, fallbacks: EffectFallbacks, currentRank: number): number;
  163. /**
  164. * Gets the samplers used by the plugin.
  165. * @param samplers list that the sampler names should be added to.
  166. */
  167. getSamplers(samplers: string[]): void;
  168. /**
  169. * Gets the attributes used by the plugin.
  170. * @param attributes list that the attribute names should be added to.
  171. * @param scene the scene that the material belongs to.
  172. * @param mesh the mesh being rendered.
  173. */
  174. getAttributes(attributes: string[], scene: Scene, mesh: AbstractMesh): void;
  175. /**
  176. * Gets the uniform buffers names added by the plugin.
  177. * @param ubos list that the ubo names should be added to.
  178. */
  179. getUniformBuffersNames(ubos: string[]): void;
  180. /**
  181. * Gets the description of the uniforms to add to the ubo (if engine supports ubos) or to inject directly in the vertex/fragment shaders (if engine does not support ubos)
  182. * @returns the description of the uniforms
  183. */
  184. getUniforms(): {
  185. ubo?: Array<{
  186. name: string;
  187. size?: number;
  188. type?: string;
  189. arraySize?: number;
  190. }>;
  191. vertex?: string;
  192. fragment?: string;
  193. };
  194. /**
  195. * Makes a duplicate of the current configuration into another one.
  196. * @param plugin define the config where to copy the info
  197. */
  198. copyTo(plugin: MaterialPluginBase): void;
  199. /**
  200. * Serializes this plugin configuration.
  201. * @returns - An object with the serialized config.
  202. */
  203. serialize(): any;
  204. /**
  205. * Parses a plugin configuration from a serialized object.
  206. * @param source - Serialized object.
  207. * @param scene Defines the scene we are parsing for
  208. * @param rootUrl Defines the rootUrl to load from
  209. */
  210. parse(source: any, scene: Scene, rootUrl: string): void;
  211. }