materialHelper.d.ts 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. import type { Nullable } from "../types";
  2. import type { Scene } from "../scene";
  3. import type { Engine } from "../Engines/engine";
  4. import type { AbstractMesh } from "../Meshes/abstractMesh";
  5. import type { Light } from "../Lights/light";
  6. import type { PrePassConfiguration } from "../Materials/prePassConfiguration";
  7. import type { UniformBuffer } from "./uniformBuffer";
  8. import type { Effect, IEffectCreationOptions } from "./effect";
  9. import type { BaseTexture } from "../Materials/Textures/baseTexture";
  10. import type { MaterialDefines } from "./materialDefines";
  11. import type { EffectFallbacks } from "./effectFallbacks";
  12. import type { Material } from "./material";
  13. /**
  14. * "Static Class" containing the most commonly used helper while dealing with material for rendering purpose.
  15. *
  16. * It contains the basic tools to help defining defines, binding uniform for the common part of the materials.
  17. *
  18. * This works by convention in BabylonJS but is meant to be use only with shader following the in place naming rules and conventions.
  19. */
  20. export declare class MaterialHelper {
  21. /**
  22. * Binds the scene's uniform buffer to the effect.
  23. * @param effect defines the effect to bind to the scene uniform buffer
  24. * @param sceneUbo defines the uniform buffer storing scene data
  25. */
  26. static BindSceneUniformBuffer: (effect: Effect, sceneUbo: UniformBuffer) => void;
  27. /**
  28. * Helps preparing the defines values about the UVs in used in the effect.
  29. * UVs are shared as much as we can across channels in the shaders.
  30. * @param texture The texture we are preparing the UVs for
  31. * @param defines The defines to update
  32. * @param key The channel key "diffuse", "specular"... used in the shader
  33. */
  34. static PrepareDefinesForMergedUV: (texture: BaseTexture, defines: any, key: string) => void;
  35. /**
  36. * Binds a texture matrix value to its corresponding uniform
  37. * @param texture The texture to bind the matrix for
  38. * @param uniformBuffer The uniform buffer receiving the data
  39. * @param key The channel key "diffuse", "specular"... used in the shader
  40. */
  41. static BindTextureMatrix: (texture: BaseTexture, uniformBuffer: UniformBuffer, key: string) => void;
  42. /**
  43. * Gets the current status of the fog (should it be enabled?)
  44. * @param mesh defines the mesh to evaluate for fog support
  45. * @param scene defines the hosting scene
  46. * @returns true if fog must be enabled
  47. */
  48. static GetFogState: (mesh: AbstractMesh, scene: Scene) => boolean;
  49. /**
  50. * Helper used to prepare the list of defines associated with misc. values for shader compilation
  51. * @param mesh defines the current mesh
  52. * @param scene defines the current scene
  53. * @param useLogarithmicDepth defines if logarithmic depth has to be turned on
  54. * @param pointsCloud defines if point cloud rendering has to be turned on
  55. * @param fogEnabled defines if fog has to be turned on
  56. * @param alphaTest defines if alpha testing has to be turned on
  57. * @param defines defines the current list of defines
  58. * @param applyDecalAfterDetail Defines if the decal is applied after or before the detail
  59. */
  60. static PrepareDefinesForMisc: (mesh: AbstractMesh, scene: Scene, useLogarithmicDepth: boolean, pointsCloud: boolean, fogEnabled: boolean, alphaTest: boolean, defines: any, applyDecalAfterDetail?: boolean) => void;
  61. /**
  62. * Helper used to prepare the defines relative to the active camera
  63. * @param scene defines the current scene
  64. * @param defines specifies the list of active defines
  65. * @returns true if the defines have been updated, else false
  66. */
  67. static PrepareDefinesForCamera: (scene: Scene, defines: any) => boolean;
  68. /**
  69. * Helper used to prepare the list of defines associated with frame values for shader compilation
  70. * @param scene defines the current scene
  71. * @param engine defines the current engine
  72. * @param material defines the material we are compiling the shader for
  73. * @param defines specifies the list of active defines
  74. * @param useInstances defines if instances have to be turned on
  75. * @param useClipPlane defines if clip plane have to be turned on
  76. * @param useThinInstances defines if thin instances have to be turned on
  77. */
  78. static PrepareDefinesForFrameBoundValues: (scene: Scene, engine: Engine, material: Material, defines: any, useInstances: boolean, useClipPlane?: Nullable<boolean>, useThinInstances?: boolean) => void;
  79. /**
  80. * Prepares the defines for bones
  81. * @param mesh The mesh containing the geometry data we will draw
  82. * @param defines The defines to update
  83. */
  84. static PrepareDefinesForBones: (mesh: AbstractMesh, defines: any) => void;
  85. /**
  86. * Prepares the defines for morph targets
  87. * @param mesh The mesh containing the geometry data we will draw
  88. * @param defines The defines to update
  89. */
  90. static PrepareDefinesForMorphTargets: (mesh: AbstractMesh, defines: any) => void;
  91. /**
  92. * Prepares the defines for baked vertex animation
  93. * @param mesh The mesh containing the geometry data we will draw
  94. * @param defines The defines to update
  95. */
  96. static PrepareDefinesForBakedVertexAnimation: (mesh: AbstractMesh, defines: any) => void;
  97. /**
  98. * Prepares the defines used in the shader depending on the attributes data available in the mesh
  99. * @param mesh The mesh containing the geometry data we will draw
  100. * @param defines The defines to update
  101. * @param useVertexColor Precise whether vertex colors should be used or not (override mesh info)
  102. * @param useBones Precise whether bones should be used or not (override mesh info)
  103. * @param useMorphTargets Precise whether morph targets should be used or not (override mesh info)
  104. * @param useVertexAlpha Precise whether vertex alpha should be used or not (override mesh info)
  105. * @param useBakedVertexAnimation Precise whether baked vertex animation should be used or not (override mesh info)
  106. * @returns false if defines are considered not dirty and have not been checked
  107. */
  108. static PrepareDefinesForAttributes: (mesh: AbstractMesh, defines: any, useVertexColor: boolean, useBones: boolean, useMorphTargets?: boolean, useVertexAlpha?: boolean, useBakedVertexAnimation?: boolean) => boolean;
  109. /**
  110. * Prepares the defines related to multiview
  111. * @param scene The scene we are intending to draw
  112. * @param defines The defines to update
  113. */
  114. static PrepareDefinesForMultiview: (scene: Scene, defines: any) => void;
  115. /**
  116. * Prepares the defines related to order independant transparency
  117. * @param scene The scene we are intending to draw
  118. * @param defines The defines to update
  119. * @param needAlphaBlending Determines if the material needs alpha blending
  120. */
  121. static PrepareDefinesForOIT: (scene: Scene, defines: any, needAlphaBlending: boolean) => void;
  122. /**
  123. * Prepares the defines related to the prepass
  124. * @param scene The scene we are intending to draw
  125. * @param defines The defines to update
  126. * @param canRenderToMRT Indicates if this material renders to several textures in the prepass
  127. */
  128. static PrepareDefinesForPrePass: (scene: Scene, defines: any, canRenderToMRT: boolean) => void;
  129. /**
  130. * Prepares the defines related to the light information passed in parameter
  131. * @param scene The scene we are intending to draw
  132. * @param mesh The mesh the effect is compiling for
  133. * @param light The light the effect is compiling for
  134. * @param lightIndex The index of the light
  135. * @param defines The defines to update
  136. * @param specularSupported Specifies whether specular is supported or not (override lights data)
  137. * @param state Defines the current state regarding what is needed (normals, etc...)
  138. * @param state.needNormals
  139. * @param state.needRebuild
  140. * @param state.shadowEnabled
  141. * @param state.specularEnabled
  142. * @param state.lightmapMode
  143. */
  144. static PrepareDefinesForLight: (scene: Scene, mesh: AbstractMesh, light: Light, lightIndex: number, defines: any, specularSupported: boolean, state: {
  145. needNormals: boolean;
  146. needRebuild: boolean;
  147. shadowEnabled: boolean;
  148. specularEnabled: boolean;
  149. lightmapMode: boolean;
  150. }) => void;
  151. /**
  152. * Prepares the defines related to the light information passed in parameter
  153. * @param scene The scene we are intending to draw
  154. * @param mesh The mesh the effect is compiling for
  155. * @param defines The defines to update
  156. * @param specularSupported Specifies whether specular is supported or not (override lights data)
  157. * @param maxSimultaneousLights Specifies how manuy lights can be added to the effect at max
  158. * @param disableLighting Specifies whether the lighting is disabled (override scene and light)
  159. * @returns true if normals will be required for the rest of the effect
  160. */
  161. static PrepareDefinesForLights: (scene: Scene, mesh: AbstractMesh, defines: any, specularSupported: boolean, maxSimultaneousLights?: number, disableLighting?: boolean) => boolean;
  162. /**
  163. * Prepares the uniforms and samplers list to be used in the effect (for a specific light)
  164. * @param lightIndex defines the light index
  165. * @param uniformsList The uniform list
  166. * @param samplersList The sampler list
  167. * @param projectedLightTexture defines if projected texture must be used
  168. * @param uniformBuffersList defines an optional list of uniform buffers
  169. * @param updateOnlyBuffersList True to only update the uniformBuffersList array
  170. */
  171. static PrepareUniformsAndSamplersForLight: (lightIndex: number, uniformsList: string[], samplersList: string[], projectedLightTexture?: any, uniformBuffersList?: Nullable<string[]>, updateOnlyBuffersList?: boolean) => void;
  172. /**
  173. * Prepares the uniforms and samplers list to be used in the effect
  174. * @param uniformsListOrOptions The uniform names to prepare or an EffectCreationOptions containing the list and extra information
  175. * @param samplersList The sampler list
  176. * @param defines The defines helping in the list generation
  177. * @param maxSimultaneousLights The maximum number of simultaneous light allowed in the effect
  178. */
  179. static PrepareUniformsAndSamplersList: (uniformsListOrOptions: string[] | IEffectCreationOptions, samplersList?: string[], defines?: any, maxSimultaneousLights?: number) => void;
  180. /**
  181. * This helps decreasing rank by rank the shadow quality (0 being the highest rank and quality)
  182. * @param defines The defines to update while falling back
  183. * @param fallbacks The authorized effect fallbacks
  184. * @param maxSimultaneousLights The maximum number of lights allowed
  185. * @param rank the current rank of the Effect
  186. * @returns The newly affected rank
  187. */
  188. static HandleFallbacksForShadows: (defines: any, fallbacks: EffectFallbacks, maxSimultaneousLights?: number, rank?: number) => number;
  189. /**
  190. * Prepares the list of attributes required for morph targets according to the effect defines.
  191. * @param attribs The current list of supported attribs
  192. * @param mesh The mesh to prepare the morph targets attributes for
  193. * @param influencers The number of influencers
  194. */
  195. static PrepareAttributesForMorphTargetsInfluencers: (attribs: string[], mesh: AbstractMesh, influencers: number) => void;
  196. /**
  197. * Prepares the list of attributes required for morph targets according to the effect defines.
  198. * @param attribs The current list of supported attribs
  199. * @param mesh The mesh to prepare the morph targets attributes for
  200. * @param defines The current Defines of the effect
  201. */
  202. static PrepareAttributesForMorphTargets: (attribs: string[], mesh: AbstractMesh, defines: any) => void;
  203. /**
  204. * Prepares the list of attributes required for baked vertex animations according to the effect defines.
  205. * @param attribs The current list of supported attribs
  206. * @param mesh The mesh to prepare for baked vertex animations
  207. * @param defines The current Defines of the effect
  208. */
  209. static PrepareAttributesForBakedVertexAnimation: (attribs: string[], mesh: AbstractMesh, defines: any) => void;
  210. /**
  211. * Prepares the list of attributes required for bones according to the effect defines.
  212. * @param attribs The current list of supported attribs
  213. * @param mesh The mesh to prepare the bones attributes for
  214. * @param defines The current Defines of the effect
  215. * @param fallbacks The current effect fallback strategy
  216. */
  217. static PrepareAttributesForBones: (attribs: string[], mesh: AbstractMesh, defines: any, fallbacks: EffectFallbacks) => void;
  218. /**
  219. * Check and prepare the list of attributes required for instances according to the effect defines.
  220. * @param attribs The current list of supported attribs
  221. * @param defines The current MaterialDefines of the effect
  222. */
  223. static PrepareAttributesForInstances: (attribs: string[], defines: MaterialDefines) => void;
  224. /**
  225. * Add the list of attributes required for instances to the attribs array.
  226. * @param attribs The current list of supported attribs
  227. * @param needsPreviousMatrices If the shader needs previous matrices
  228. */
  229. static PushAttributesForInstances: (attribs: string[], needsPreviousMatrices?: boolean) => void;
  230. /**
  231. * Binds the light information to the effect.
  232. * @param light The light containing the generator
  233. * @param effect The effect we are binding the data to
  234. * @param lightIndex The light index in the effect used to render
  235. */
  236. static BindLightProperties: (light: Light, effect: Effect, lightIndex: number) => void;
  237. /**
  238. * Binds the lights information from the scene to the effect for the given mesh.
  239. * @param light Light to bind
  240. * @param lightIndex Light index
  241. * @param scene The scene where the light belongs to
  242. * @param effect The effect we are binding the data to
  243. * @param useSpecular Defines if specular is supported
  244. * @param receiveShadows Defines if the effect (mesh) we bind the light for receives shadows
  245. */
  246. static BindLight: (light: Light, lightIndex: number, scene: Scene, effect: Effect, useSpecular: boolean, receiveShadows?: boolean) => void;
  247. /**
  248. * Binds the lights information from the scene to the effect for the given mesh.
  249. * @param scene The scene the lights belongs to
  250. * @param mesh The mesh we are binding the information to render
  251. * @param effect The effect we are binding the data to
  252. * @param defines The generated defines for the effect
  253. * @param maxSimultaneousLights The maximum number of light that can be bound to the effect
  254. */
  255. static BindLights: (scene: Scene, mesh: AbstractMesh, effect: Effect, defines: any, maxSimultaneousLights?: number) => void;
  256. /**
  257. * Binds the fog information from the scene to the effect for the given mesh.
  258. * @param scene The scene the lights belongs to
  259. * @param mesh The mesh we are binding the information to render
  260. * @param effect The effect we are binding the data to
  261. * @param linearSpace Defines if the fog effect is applied in linear space
  262. */
  263. static BindFogParameters: (scene: Scene, mesh?: AbstractMesh, effect?: Effect, linearSpace?: boolean) => void;
  264. /**
  265. * Binds the bones information from the mesh to the effect.
  266. * @param mesh The mesh we are binding the information to render
  267. * @param effect The effect we are binding the data to
  268. * @param prePassConfiguration Configuration for the prepass, in case prepass is activated
  269. */
  270. static BindBonesParameters: (mesh?: AbstractMesh, effect?: Effect, prePassConfiguration?: PrePassConfiguration) => void;
  271. /**
  272. * Binds the morph targets information from the mesh to the effect.
  273. * @param abstractMesh The mesh we are binding the information to render
  274. * @param effect The effect we are binding the data to
  275. */
  276. static BindMorphTargetParameters: (abstractMesh: AbstractMesh, effect: Effect) => void;
  277. /**
  278. * Binds the logarithmic depth information from the scene to the effect for the given defines.
  279. * @param defines The generated defines used in the effect
  280. * @param effect The effect we are binding the data to
  281. * @param scene The scene we are willing to render with logarithmic scale for
  282. */
  283. static BindLogDepth: (defines: any, effect: Effect, scene: Scene) => void;
  284. }