material.d.ts 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  1. import type { IAnimatable } from "../Animations/animatable.interface";
  2. import type { SmartArray } from "../Misc/smartArray";
  3. import { Observable } from "../Misc/observable";
  4. import type { Nullable } from "../types";
  5. import type { Matrix } from "../Maths/math.vector";
  6. import { SubMesh } from "../Meshes/subMesh";
  7. import type { AbstractMesh } from "../Meshes/abstractMesh";
  8. import { UniformBuffer } from "./uniformBuffer";
  9. import type { Effect } from "./effect";
  10. import type { BaseTexture } from "../Materials/Textures/baseTexture";
  11. import type { RenderTargetTexture } from "../Materials/Textures/renderTargetTexture";
  12. import type { MaterialDefines } from "./materialDefines";
  13. import type { IInspectable } from "../Misc/iInspectable";
  14. import { Plane } from "../Maths/math.plane";
  15. import type { ShadowDepthWrapper } from "./shadowDepthWrapper";
  16. import type { IMaterialContext } from "../Engines/IMaterialContext";
  17. import { DrawWrapper } from "./drawWrapper";
  18. import { MaterialStencilState } from "./materialStencilState";
  19. import type { Scene } from "../scene";
  20. import type { AbstractScene } from "../abstractScene";
  21. import type { MaterialPluginDisposed, MaterialPluginIsReadyForSubMesh, MaterialPluginGetDefineNames, MaterialPluginBindForSubMesh, MaterialPluginGetActiveTextures, MaterialPluginHasTexture, MaterialPluginGetAnimatables, MaterialPluginPrepareDefines, MaterialPluginPrepareEffect, MaterialPluginPrepareUniformBuffer, MaterialPluginCreated, MaterialPluginFillRenderTargetTextures, MaterialPluginHasRenderTargetTextures, MaterialPluginHardBindForSubMesh } from "./materialPluginEvent";
  22. import type { ShaderCustomProcessingFunction } from "../Engines/Processors/shaderProcessingOptions";
  23. import type { IClipPlanesHolder } from "../Misc/interfaces/iClipPlanesHolder";
  24. import type { PrePassRenderer } from "../Rendering/prePassRenderer";
  25. import type { Mesh } from "../Meshes/mesh";
  26. import type { Animation } from "../Animations/animation";
  27. /**
  28. * Options for compiling materials.
  29. */
  30. export interface IMaterialCompilationOptions {
  31. /**
  32. * Defines whether clip planes are enabled.
  33. */
  34. clipPlane: boolean;
  35. /**
  36. * Defines whether instances are enabled.
  37. */
  38. useInstances: boolean;
  39. }
  40. /**
  41. * Options passed when calling customShaderNameResolve
  42. */
  43. export interface ICustomShaderNameResolveOptions {
  44. /**
  45. * If provided, will be called two times with the vertex and fragment code so that this code can be updated before it is compiled by the GPU
  46. */
  47. processFinalCode?: Nullable<ShaderCustomProcessingFunction>;
  48. }
  49. /**
  50. * Base class for the main features of a material in Babylon.js
  51. */
  52. export declare class Material implements IAnimatable, IClipPlanesHolder {
  53. /**
  54. * Returns the triangle fill mode
  55. */
  56. static readonly TriangleFillMode = 0;
  57. /**
  58. * Returns the wireframe mode
  59. */
  60. static readonly WireFrameFillMode = 1;
  61. /**
  62. * Returns the point fill mode
  63. */
  64. static readonly PointFillMode = 2;
  65. /**
  66. * Returns the point list draw mode
  67. */
  68. static readonly PointListDrawMode = 3;
  69. /**
  70. * Returns the line list draw mode
  71. */
  72. static readonly LineListDrawMode = 4;
  73. /**
  74. * Returns the line loop draw mode
  75. */
  76. static readonly LineLoopDrawMode = 5;
  77. /**
  78. * Returns the line strip draw mode
  79. */
  80. static readonly LineStripDrawMode = 6;
  81. /**
  82. * Returns the triangle strip draw mode
  83. */
  84. static readonly TriangleStripDrawMode = 7;
  85. /**
  86. * Returns the triangle fan draw mode
  87. */
  88. static readonly TriangleFanDrawMode = 8;
  89. /**
  90. * Stores the clock-wise side orientation
  91. */
  92. static readonly ClockWiseSideOrientation = 0;
  93. /**
  94. * Stores the counter clock-wise side orientation
  95. */
  96. static readonly CounterClockWiseSideOrientation = 1;
  97. /**
  98. * The dirty texture flag value
  99. */
  100. static readonly TextureDirtyFlag = 1;
  101. /**
  102. * The dirty light flag value
  103. */
  104. static readonly LightDirtyFlag = 2;
  105. /**
  106. * The dirty fresnel flag value
  107. */
  108. static readonly FresnelDirtyFlag = 4;
  109. /**
  110. * The dirty attribute flag value
  111. */
  112. static readonly AttributesDirtyFlag = 8;
  113. /**
  114. * The dirty misc flag value
  115. */
  116. static readonly MiscDirtyFlag = 16;
  117. /**
  118. * The dirty prepass flag value
  119. */
  120. static readonly PrePassDirtyFlag = 32;
  121. /**
  122. * The all dirty flag value
  123. */
  124. static readonly AllDirtyFlag = 63;
  125. /**
  126. * MaterialTransparencyMode: No transparency mode, Alpha channel is not use.
  127. */
  128. static readonly MATERIAL_OPAQUE = 0;
  129. /**
  130. * MaterialTransparencyMode: Alpha Test mode, pixel are discarded below a certain threshold defined by the alpha cutoff value.
  131. */
  132. static readonly MATERIAL_ALPHATEST = 1;
  133. /**
  134. * MaterialTransparencyMode: Pixels are blended (according to the alpha mode) with the already drawn pixels in the current frame buffer.
  135. */
  136. static readonly MATERIAL_ALPHABLEND = 2;
  137. /**
  138. * MaterialTransparencyMode: Pixels are blended (according to the alpha mode) with the already drawn pixels in the current frame buffer.
  139. * They are also discarded below the alpha cutoff threshold to improve performances.
  140. */
  141. static readonly MATERIAL_ALPHATESTANDBLEND = 3;
  142. /**
  143. * The Whiteout method is used to blend normals.
  144. * Details of the algorithm can be found here: https://blog.selfshadow.com/publications/blending-in-detail/
  145. */
  146. static readonly MATERIAL_NORMALBLENDMETHOD_WHITEOUT = 0;
  147. /**
  148. * The Reoriented Normal Mapping method is used to blend normals.
  149. * Details of the algorithm can be found here: https://blog.selfshadow.com/publications/blending-in-detail/
  150. */
  151. static readonly MATERIAL_NORMALBLENDMETHOD_RNM = 1;
  152. /**
  153. * Event observable which raises global events common to all materials (like MaterialPluginEvent.Created)
  154. */
  155. static OnEventObservable: Observable<Material>;
  156. /**
  157. * Custom callback helping to override the default shader used in the material.
  158. */
  159. customShaderNameResolve: (shaderName: string, uniforms: string[], uniformBuffers: string[], samplers: string[], defines: MaterialDefines | string[], attributes?: string[], options?: ICustomShaderNameResolveOptions) => string;
  160. /**
  161. * Custom shadow depth material to use for shadow rendering instead of the in-built one
  162. */
  163. shadowDepthWrapper: Nullable<ShadowDepthWrapper>;
  164. /**
  165. * Gets or sets a boolean indicating that the material is allowed (if supported) to do shader hot swapping.
  166. * This means that the material can keep using a previous shader while a new one is being compiled.
  167. * This is mostly used when shader parallel compilation is supported (true by default)
  168. */
  169. allowShaderHotSwapping: boolean;
  170. /**
  171. * The ID of the material
  172. */
  173. id: string;
  174. /**
  175. * Gets or sets the unique id of the material
  176. */
  177. uniqueId: number;
  178. /** @internal */
  179. _loadedUniqueId: string;
  180. /**
  181. * The name of the material
  182. */
  183. name: string;
  184. /**
  185. * Gets or sets user defined metadata
  186. */
  187. metadata: any;
  188. /** @internal */
  189. _internalMetadata: any;
  190. /**
  191. * For internal use only. Please do not use.
  192. */
  193. reservedDataStore: any;
  194. /**
  195. * Specifies if the ready state should be checked on each call
  196. */
  197. checkReadyOnEveryCall: boolean;
  198. /**
  199. * Specifies if the ready state should be checked once
  200. */
  201. checkReadyOnlyOnce: boolean;
  202. /**
  203. * The state of the material
  204. */
  205. state: string;
  206. /**
  207. * If the material can be rendered to several textures with MRT extension
  208. */
  209. get canRenderToMRT(): boolean;
  210. /**
  211. * The alpha value of the material
  212. */
  213. protected _alpha: number;
  214. /**
  215. * List of inspectable custom properties (used by the Inspector)
  216. * @see https://doc.babylonjs.com/toolsAndResources/inspector#extensibility
  217. */
  218. inspectableCustomProperties: IInspectable[];
  219. /**
  220. * Sets the alpha value of the material
  221. */
  222. set alpha(value: number);
  223. /**
  224. * Gets the alpha value of the material
  225. */
  226. get alpha(): number;
  227. /**
  228. * Specifies if back face culling is enabled
  229. */
  230. protected _backFaceCulling: boolean;
  231. /**
  232. * Sets the culling state (true to enable culling, false to disable)
  233. */
  234. set backFaceCulling(value: boolean);
  235. /**
  236. * Gets the culling state
  237. */
  238. get backFaceCulling(): boolean;
  239. /**
  240. * Specifies if back or front faces should be culled (when culling is enabled)
  241. */
  242. protected _cullBackFaces: boolean;
  243. /**
  244. * Sets the type of faces that should be culled (true for back faces, false for front faces)
  245. */
  246. set cullBackFaces(value: boolean);
  247. /**
  248. * Gets the type of faces that should be culled
  249. */
  250. get cullBackFaces(): boolean;
  251. private _blockDirtyMechanism;
  252. /**
  253. * Block the dirty-mechanism for this specific material
  254. * When set to false after being true the material will be marked as dirty.
  255. */
  256. get blockDirtyMechanism(): boolean;
  257. set blockDirtyMechanism(value: boolean);
  258. /**
  259. * This allows you to modify the material without marking it as dirty after every change.
  260. * This function should be used if you need to make more than one dirty-enabling change to the material - adding a texture, setting a new fill mode and so on.
  261. * The callback will pass the material as an argument, so you can make your changes to it.
  262. * @param callback the callback to be executed that will update the material
  263. */
  264. atomicMaterialsUpdate(callback: (material: this) => void): void;
  265. /**
  266. * Stores the value for side orientation
  267. */
  268. sideOrientation: number;
  269. /**
  270. * Callback triggered when the material is compiled
  271. */
  272. onCompiled: Nullable<(effect: Effect) => void>;
  273. /**
  274. * Callback triggered when an error occurs
  275. */
  276. onError: Nullable<(effect: Effect, errors: string) => void>;
  277. /**
  278. * Callback triggered to get the render target textures
  279. */
  280. getRenderTargetTextures: Nullable<() => SmartArray<RenderTargetTexture>>;
  281. /**
  282. * Gets a boolean indicating that current material needs to register RTT
  283. */
  284. get hasRenderTargetTextures(): boolean;
  285. /**
  286. * Specifies if the material should be serialized
  287. */
  288. doNotSerialize: boolean;
  289. /**
  290. * @internal
  291. */
  292. _storeEffectOnSubMeshes: boolean;
  293. /**
  294. * Stores the animations for the material
  295. */
  296. animations: Nullable<Array<Animation>>;
  297. /**
  298. * An event triggered when the material is disposed
  299. */
  300. onDisposeObservable: Observable<Material>;
  301. /**
  302. * An observer which watches for dispose events
  303. */
  304. private _onDisposeObserver;
  305. private _onUnBindObservable;
  306. /**
  307. * Called during a dispose event
  308. */
  309. set onDispose(callback: () => void);
  310. private _onBindObservable;
  311. /**
  312. * An event triggered when the material is bound
  313. */
  314. get onBindObservable(): Observable<AbstractMesh>;
  315. /**
  316. * An observer which watches for bind events
  317. */
  318. private _onBindObserver;
  319. /**
  320. * Called during a bind event
  321. */
  322. set onBind(callback: (Mesh: AbstractMesh) => void);
  323. /**
  324. * An event triggered when the material is unbound
  325. */
  326. get onUnBindObservable(): Observable<Material>;
  327. protected _onEffectCreatedObservable: Nullable<Observable<{
  328. effect: Effect;
  329. subMesh: Nullable<SubMesh>;
  330. }>>;
  331. /**
  332. * An event triggered when the effect is (re)created
  333. */
  334. get onEffectCreatedObservable(): Observable<{
  335. effect: Effect;
  336. subMesh: Nullable<SubMesh>;
  337. }>;
  338. /**
  339. * Stores the value of the alpha mode
  340. */
  341. private _alphaMode;
  342. /**
  343. * Sets the value of the alpha mode.
  344. *
  345. * | Value | Type | Description |
  346. * | --- | --- | --- |
  347. * | 0 | ALPHA_DISABLE | |
  348. * | 1 | ALPHA_ADD | |
  349. * | 2 | ALPHA_COMBINE | |
  350. * | 3 | ALPHA_SUBTRACT | |
  351. * | 4 | ALPHA_MULTIPLY | |
  352. * | 5 | ALPHA_MAXIMIZED | |
  353. * | 6 | ALPHA_ONEONE | |
  354. * | 7 | ALPHA_PREMULTIPLIED | |
  355. * | 8 | ALPHA_PREMULTIPLIED_PORTERDUFF | |
  356. * | 9 | ALPHA_INTERPOLATE | |
  357. * | 10 | ALPHA_SCREENMODE | |
  358. *
  359. */
  360. set alphaMode(value: number);
  361. /**
  362. * Gets the value of the alpha mode
  363. */
  364. get alphaMode(): number;
  365. /**
  366. * Stores the state of the need depth pre-pass value
  367. */
  368. private _needDepthPrePass;
  369. /**
  370. * Sets the need depth pre-pass value
  371. */
  372. set needDepthPrePass(value: boolean);
  373. /**
  374. * Gets the depth pre-pass value
  375. */
  376. get needDepthPrePass(): boolean;
  377. /**
  378. * Can this material render to prepass
  379. */
  380. get isPrePassCapable(): boolean;
  381. /**
  382. * Specifies if depth writing should be disabled
  383. */
  384. disableDepthWrite: boolean;
  385. /**
  386. * Specifies if color writing should be disabled
  387. */
  388. disableColorWrite: boolean;
  389. /**
  390. * Specifies if depth writing should be forced
  391. */
  392. forceDepthWrite: boolean;
  393. /**
  394. * Specifies the depth function that should be used. 0 means the default engine function
  395. */
  396. depthFunction: number;
  397. /**
  398. * Specifies if there should be a separate pass for culling
  399. */
  400. separateCullingPass: boolean;
  401. /**
  402. * Stores the state specifying if fog should be enabled
  403. */
  404. private _fogEnabled;
  405. /**
  406. * Sets the state for enabling fog
  407. */
  408. set fogEnabled(value: boolean);
  409. /**
  410. * Gets the value of the fog enabled state
  411. */
  412. get fogEnabled(): boolean;
  413. /**
  414. * Stores the size of points
  415. */
  416. pointSize: number;
  417. /**
  418. * Stores the z offset Factor value
  419. */
  420. zOffset: number;
  421. /**
  422. * Stores the z offset Units value
  423. */
  424. zOffsetUnits: number;
  425. get wireframe(): boolean;
  426. /**
  427. * Sets the state of wireframe mode
  428. */
  429. set wireframe(value: boolean);
  430. /**
  431. * Gets the value specifying if point clouds are enabled
  432. */
  433. get pointsCloud(): boolean;
  434. /**
  435. * Sets the state of point cloud mode
  436. */
  437. set pointsCloud(value: boolean);
  438. /**
  439. * Gets the material fill mode
  440. */
  441. get fillMode(): number;
  442. /**
  443. * Sets the material fill mode
  444. */
  445. set fillMode(value: number);
  446. /**
  447. * Gets or sets the active clipplane 1
  448. */
  449. clipPlane: Nullable<Plane>;
  450. /**
  451. * Gets or sets the active clipplane 2
  452. */
  453. clipPlane2: Nullable<Plane>;
  454. /**
  455. * Gets or sets the active clipplane 3
  456. */
  457. clipPlane3: Nullable<Plane>;
  458. /**
  459. * Gets or sets the active clipplane 4
  460. */
  461. clipPlane4: Nullable<Plane>;
  462. /**
  463. * Gets or sets the active clipplane 5
  464. */
  465. clipPlane5: Nullable<Plane>;
  466. /**
  467. * Gets or sets the active clipplane 6
  468. */
  469. clipPlane6: Nullable<Plane>;
  470. /**
  471. * Gives access to the stencil properties of the material
  472. */
  473. readonly stencil: MaterialStencilState;
  474. protected _useLogarithmicDepth: boolean;
  475. /**
  476. * In case the depth buffer does not allow enough depth precision for your scene (might be the case in large scenes)
  477. * You can try switching to logarithmic depth.
  478. * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/advanced/logarithmicDepthBuffer
  479. */
  480. get useLogarithmicDepth(): boolean;
  481. set useLogarithmicDepth(value: boolean);
  482. /**
  483. * @internal
  484. * Stores the effects for the material
  485. */
  486. _materialContext: IMaterialContext | undefined;
  487. protected _drawWrapper: DrawWrapper;
  488. /** @internal */
  489. _getDrawWrapper(): DrawWrapper;
  490. /**
  491. * @internal
  492. */
  493. _setDrawWrapper(drawWrapper: DrawWrapper): void;
  494. /**
  495. * Specifies if uniform buffers should be used
  496. */
  497. private _useUBO;
  498. /**
  499. * Stores a reference to the scene
  500. */
  501. private _scene;
  502. protected _needToBindSceneUbo: boolean;
  503. /**
  504. * Stores the fill mode state
  505. */
  506. private _fillMode;
  507. /**
  508. * Specifies if the depth write state should be cached
  509. */
  510. private _cachedDepthWriteState;
  511. /**
  512. * Specifies if the color write state should be cached
  513. */
  514. private _cachedColorWriteState;
  515. /**
  516. * Specifies if the depth function state should be cached
  517. */
  518. private _cachedDepthFunctionState;
  519. /**
  520. * Stores the uniform buffer
  521. * @internal
  522. */
  523. _uniformBuffer: UniformBuffer;
  524. /** @internal */
  525. _indexInSceneMaterialArray: number;
  526. /** @internal */
  527. meshMap: Nullable<{
  528. [id: string]: AbstractMesh | undefined;
  529. }>;
  530. /** @internal */
  531. _parentContainer: Nullable<AbstractScene>;
  532. /** @internal */
  533. _dirtyCallbacks: {
  534. [code: number]: () => void;
  535. };
  536. /** @internal */
  537. _uniformBufferLayoutBuilt: boolean;
  538. protected _eventInfo: MaterialPluginCreated & MaterialPluginDisposed & MaterialPluginHasTexture & MaterialPluginIsReadyForSubMesh & MaterialPluginGetDefineNames & MaterialPluginPrepareEffect & MaterialPluginPrepareDefines & MaterialPluginPrepareUniformBuffer & MaterialPluginBindForSubMesh & MaterialPluginGetAnimatables & MaterialPluginGetActiveTextures & MaterialPluginFillRenderTargetTextures & MaterialPluginHasRenderTargetTextures & MaterialPluginHardBindForSubMesh;
  539. /** @internal */
  540. _callbackPluginEventGeneric: (id: number, info: MaterialPluginGetActiveTextures | MaterialPluginGetAnimatables | MaterialPluginHasTexture | MaterialPluginDisposed | MaterialPluginGetDefineNames | MaterialPluginPrepareEffect | MaterialPluginPrepareUniformBuffer) => void;
  541. /** @internal */
  542. _callbackPluginEventIsReadyForSubMesh: (eventData: MaterialPluginIsReadyForSubMesh) => void;
  543. /** @internal */
  544. _callbackPluginEventPrepareDefines: (eventData: MaterialPluginPrepareDefines) => void;
  545. /** @internal */
  546. _callbackPluginEventPrepareDefinesBeforeAttributes: (eventData: MaterialPluginPrepareDefines) => void;
  547. /** @internal */
  548. _callbackPluginEventHardBindForSubMesh: (eventData: MaterialPluginHardBindForSubMesh) => void;
  549. /** @internal */
  550. _callbackPluginEventBindForSubMesh: (eventData: MaterialPluginBindForSubMesh) => void;
  551. /** @internal */
  552. _callbackPluginEventHasRenderTargetTextures: (eventData: MaterialPluginHasRenderTargetTextures) => void;
  553. /** @internal */
  554. _callbackPluginEventFillRenderTargetTextures: (eventData: MaterialPluginFillRenderTargetTextures) => void;
  555. /**
  556. * Creates a material instance
  557. * @param name defines the name of the material
  558. * @param scene defines the scene to reference
  559. * @param doNotAdd specifies if the material should be added to the scene
  560. */
  561. constructor(name: string, scene?: Nullable<Scene>, doNotAdd?: boolean);
  562. /**
  563. * Returns a string representation of the current material
  564. * @param fullDetails defines a boolean indicating which levels of logging is desired
  565. * @returns a string with material information
  566. */
  567. toString(fullDetails?: boolean): string;
  568. /**
  569. * Gets the class name of the material
  570. * @returns a string with the class name of the material
  571. */
  572. getClassName(): string;
  573. /** @internal */
  574. get _isMaterial(): boolean;
  575. /**
  576. * Specifies if updates for the material been locked
  577. */
  578. get isFrozen(): boolean;
  579. /**
  580. * Locks updates for the material
  581. */
  582. freeze(): void;
  583. /**
  584. * Unlocks updates for the material
  585. */
  586. unfreeze(): void;
  587. /**
  588. * Specifies if the material is ready to be used
  589. * @param mesh defines the mesh to check
  590. * @param useInstances specifies if instances should be used
  591. * @returns a boolean indicating if the material is ready to be used
  592. */
  593. isReady(mesh?: AbstractMesh, useInstances?: boolean): boolean;
  594. /**
  595. * Specifies that the submesh is ready to be used
  596. * @param mesh defines the mesh to check
  597. * @param subMesh defines which submesh to check
  598. * @param useInstances specifies that instances should be used
  599. * @returns a boolean indicating that the submesh is ready or not
  600. */
  601. isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
  602. /**
  603. * Returns the material effect
  604. * @returns the effect associated with the material
  605. */
  606. getEffect(): Nullable<Effect>;
  607. /**
  608. * Returns the current scene
  609. * @returns a Scene
  610. */
  611. getScene(): Scene;
  612. /**
  613. * Enforces alpha test in opaque or blend mode in order to improve the performances of some situations.
  614. */
  615. protected _forceAlphaTest: boolean;
  616. /**
  617. * The transparency mode of the material.
  618. */
  619. protected _transparencyMode: Nullable<number>;
  620. /**
  621. * Gets the current transparency mode.
  622. */
  623. get transparencyMode(): Nullable<number>;
  624. /**
  625. * Sets the transparency mode of the material.
  626. *
  627. * | Value | Type | Description |
  628. * | ----- | ----------------------------------- | ----------- |
  629. * | 0 | OPAQUE | |
  630. * | 1 | ALPHATEST | |
  631. * | 2 | ALPHABLEND | |
  632. * | 3 | ALPHATESTANDBLEND | |
  633. *
  634. */
  635. set transparencyMode(value: Nullable<number>);
  636. /**
  637. * Returns true if alpha blending should be disabled.
  638. */
  639. protected get _disableAlphaBlending(): boolean;
  640. /**
  641. * Specifies whether or not this material should be rendered in alpha blend mode.
  642. * @returns a boolean specifying if alpha blending is needed
  643. */
  644. needAlphaBlending(): boolean;
  645. /**
  646. * Specifies if the mesh will require alpha blending
  647. * @param mesh defines the mesh to check
  648. * @returns a boolean specifying if alpha blending is needed for the mesh
  649. */
  650. needAlphaBlendingForMesh(mesh: AbstractMesh): boolean;
  651. /**
  652. * Specifies whether or not this material should be rendered in alpha test mode.
  653. * @returns a boolean specifying if an alpha test is needed.
  654. */
  655. needAlphaTesting(): boolean;
  656. /**
  657. * Specifies if material alpha testing should be turned on for the mesh
  658. * @param mesh defines the mesh to check
  659. * @returns a boolean specifying if alpha testing should be turned on for the mesh
  660. */
  661. protected _shouldTurnAlphaTestOn(mesh: AbstractMesh): boolean;
  662. /**
  663. * Gets the texture used for the alpha test
  664. * @returns the texture to use for alpha testing
  665. */
  666. getAlphaTestTexture(): Nullable<BaseTexture>;
  667. /**
  668. * Marks the material to indicate that it needs to be re-calculated
  669. * @param forceMaterialDirty - Forces the material to be marked as dirty for all components (same as this.markAsDirty(Material.AllDirtyFlag)). You should use this flag if the material is frozen and you want to force a recompilation.
  670. */
  671. markDirty(forceMaterialDirty?: boolean): void;
  672. /**
  673. * @internal
  674. */
  675. _preBind(effect?: Effect | DrawWrapper, overrideOrientation?: Nullable<number>): boolean;
  676. /**
  677. * Binds the material to the mesh
  678. * @param world defines the world transformation matrix
  679. * @param mesh defines the mesh to bind the material to
  680. */
  681. bind(world: Matrix, mesh?: Mesh): void;
  682. /**
  683. * Initializes the uniform buffer layout for the shader.
  684. */
  685. buildUniformLayout(): void;
  686. /**
  687. * Binds the submesh to the material
  688. * @param world defines the world transformation matrix
  689. * @param mesh defines the mesh containing the submesh
  690. * @param subMesh defines the submesh to bind the material to
  691. */
  692. bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
  693. /**
  694. * Binds the world matrix to the material
  695. * @param world defines the world transformation matrix
  696. */
  697. bindOnlyWorldMatrix(world: Matrix): void;
  698. /**
  699. * Binds the view matrix to the effect
  700. * @param effect defines the effect to bind the view matrix to
  701. */
  702. bindView(effect: Effect): void;
  703. /**
  704. * Binds the view projection and projection matrices to the effect
  705. * @param effect defines the effect to bind the view projection and projection matrices to
  706. */
  707. bindViewProjection(effect: Effect): void;
  708. /**
  709. * Binds the view matrix to the effect
  710. * @param effect defines the effect to bind the view matrix to
  711. * @param variableName name of the shader variable that will hold the eye position
  712. */
  713. bindEyePosition(effect: Effect, variableName?: string): void;
  714. /**
  715. * Processes to execute after binding the material to a mesh
  716. * @param mesh defines the rendered mesh
  717. * @param effect defines the effect used to bind the material
  718. * @param _subMesh defines the subMesh that the material has been bound for
  719. */
  720. protected _afterBind(mesh?: Mesh, effect?: Nullable<Effect>, _subMesh?: SubMesh): void;
  721. /**
  722. * Unbinds the material from the mesh
  723. */
  724. unbind(): void;
  725. /**
  726. * Returns the animatable textures.
  727. * @returns - Array of animatable textures.
  728. */
  729. getAnimatables(): IAnimatable[];
  730. /**
  731. * Gets the active textures from the material
  732. * @returns an array of textures
  733. */
  734. getActiveTextures(): BaseTexture[];
  735. /**
  736. * Specifies if the material uses a texture
  737. * @param texture defines the texture to check against the material
  738. * @returns a boolean specifying if the material uses the texture
  739. */
  740. hasTexture(texture: BaseTexture): boolean;
  741. /**
  742. * Makes a duplicate of the material, and gives it a new name
  743. * @param name defines the new name for the duplicated material
  744. * @returns the cloned material
  745. */
  746. clone(name: string): Nullable<Material>;
  747. protected _clonePlugins(targetMaterial: Material, rootUrl: string): void;
  748. /**
  749. * Gets the meshes bound to the material
  750. * @returns an array of meshes bound to the material
  751. */
  752. getBindedMeshes(): AbstractMesh[];
  753. /**
  754. * Force shader compilation
  755. * @param mesh defines the mesh associated with this material
  756. * @param onCompiled defines a function to execute once the material is compiled
  757. * @param options defines the options to configure the compilation
  758. * @param onError defines a function to execute if the material fails compiling
  759. */
  760. forceCompilation(mesh: AbstractMesh, onCompiled?: (material: Material) => void, options?: Partial<IMaterialCompilationOptions>, onError?: (reason: string) => void): void;
  761. /**
  762. * Force shader compilation
  763. * @param mesh defines the mesh that will use this material
  764. * @param options defines additional options for compiling the shaders
  765. * @returns a promise that resolves when the compilation completes
  766. */
  767. forceCompilationAsync(mesh: AbstractMesh, options?: Partial<IMaterialCompilationOptions>): Promise<void>;
  768. private static readonly _AllDirtyCallBack;
  769. private static readonly _ImageProcessingDirtyCallBack;
  770. private static readonly _TextureDirtyCallBack;
  771. private static readonly _FresnelDirtyCallBack;
  772. private static readonly _MiscDirtyCallBack;
  773. private static readonly _PrePassDirtyCallBack;
  774. private static readonly _LightsDirtyCallBack;
  775. private static readonly _AttributeDirtyCallBack;
  776. private static _FresnelAndMiscDirtyCallBack;
  777. private static _TextureAndMiscDirtyCallBack;
  778. private static readonly _DirtyCallbackArray;
  779. private static readonly _RunDirtyCallBacks;
  780. /**
  781. * Marks a define in the material to indicate that it needs to be re-computed
  782. * @param flag defines a flag used to determine which parts of the material have to be marked as dirty
  783. */
  784. markAsDirty(flag: number): void;
  785. /**
  786. * Resets the draw wrappers cache for all submeshes that are using this material
  787. */
  788. resetDrawCache(): void;
  789. /**
  790. * Marks all submeshes of a material to indicate that their material defines need to be re-calculated
  791. * @param func defines a function which checks material defines against the submeshes
  792. */
  793. protected _markAllSubMeshesAsDirty(func: (defines: MaterialDefines) => void): void;
  794. /**
  795. * Indicates that the scene should check if the rendering now needs a prepass
  796. */
  797. protected _markScenePrePassDirty(): void;
  798. /**
  799. * Indicates that we need to re-calculated for all submeshes
  800. */
  801. protected _markAllSubMeshesAsAllDirty(): void;
  802. /**
  803. * Indicates that image processing needs to be re-calculated for all submeshes
  804. */
  805. protected _markAllSubMeshesAsImageProcessingDirty(): void;
  806. /**
  807. * Indicates that textures need to be re-calculated for all submeshes
  808. */
  809. protected _markAllSubMeshesAsTexturesDirty(): void;
  810. /**
  811. * Indicates that fresnel needs to be re-calculated for all submeshes
  812. */
  813. protected _markAllSubMeshesAsFresnelDirty(): void;
  814. /**
  815. * Indicates that fresnel and misc need to be re-calculated for all submeshes
  816. */
  817. protected _markAllSubMeshesAsFresnelAndMiscDirty(): void;
  818. /**
  819. * Indicates that lights need to be re-calculated for all submeshes
  820. */
  821. protected _markAllSubMeshesAsLightsDirty(): void;
  822. /**
  823. * Indicates that attributes need to be re-calculated for all submeshes
  824. */
  825. protected _markAllSubMeshesAsAttributesDirty(): void;
  826. /**
  827. * Indicates that misc needs to be re-calculated for all submeshes
  828. */
  829. protected _markAllSubMeshesAsMiscDirty(): void;
  830. /**
  831. * Indicates that prepass needs to be re-calculated for all submeshes
  832. */
  833. protected _markAllSubMeshesAsPrePassDirty(): void;
  834. /**
  835. * Indicates that textures and misc need to be re-calculated for all submeshes
  836. */
  837. protected _markAllSubMeshesAsTexturesAndMiscDirty(): void;
  838. protected _checkScenePerformancePriority(): void;
  839. /**
  840. * Sets the required values to the prepass renderer.
  841. * @param prePassRenderer defines the prepass renderer to setup.
  842. * @returns true if the pre pass is needed.
  843. */
  844. setPrePassRenderer(prePassRenderer: PrePassRenderer): boolean;
  845. /**
  846. * Disposes the material
  847. * @param forceDisposeEffect specifies if effects should be forcefully disposed
  848. * @param forceDisposeTextures specifies if textures should be forcefully disposed
  849. * @param notBoundToMesh specifies if the material that is being disposed is known to be not bound to any mesh
  850. */
  851. dispose(forceDisposeEffect?: boolean, forceDisposeTextures?: boolean, notBoundToMesh?: boolean): void;
  852. /**
  853. * @internal
  854. */
  855. private releaseVertexArrayObject;
  856. /**
  857. * Serializes this material
  858. * @returns the serialized material object
  859. */
  860. serialize(): any;
  861. protected _serializePlugins(serializationObject: any): void;
  862. /**
  863. * Creates a material from parsed material data
  864. * @param parsedMaterial defines parsed material data
  865. * @param scene defines the hosting scene
  866. * @param rootUrl defines the root URL to use to load textures
  867. * @returns a new material
  868. */
  869. static Parse(parsedMaterial: any, scene: Scene, rootUrl: string): Nullable<Material>;
  870. protected static _ParsePlugins(serializationObject: any, material: Material, scene: Scene, rootUrl: string): void;
  871. }