effect.d.ts 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. import { Observable } from "../Misc/observable";
  2. import type { FloatArray, Nullable } from "../types";
  3. import type { IDisposable } from "../scene";
  4. import type { IPipelineContext } from "../Engines/IPipelineContext";
  5. import type { DataBuffer } from "../Buffers/dataBuffer";
  6. import type { IShaderProcessor } from "../Engines/Processors/iShaderProcessor";
  7. import type { ShaderCustomProcessingFunction } from "../Engines/Processors/shaderProcessingOptions";
  8. import type { IMatrixLike, IVector2Like, IVector3Like, IVector4Like, IColor3Like, IColor4Like, IQuaternionLike } from "../Maths/math.like";
  9. import type { AbstractEngine } from "../Engines/abstractEngine";
  10. import type { IEffectFallbacks } from "./iEffectFallbacks";
  11. import { ShaderLanguage } from "./shaderLanguage";
  12. import type { InternalTexture } from "../Materials/Textures/internalTexture";
  13. import type { ThinTexture } from "../Materials/Textures/thinTexture";
  14. import type { RenderTargetTexture } from "../Materials/Textures/renderTargetTexture";
  15. import type { PostProcess } from "../PostProcesses/postProcess";
  16. /**
  17. * Defines the route to the shader code. The priority is as follows:
  18. * * object: `{ vertexSource: "vertex shader code string", fragmentSource: "fragment shader code string" }` for directly passing the shader code
  19. * * object: `{ vertexElement: "vertexShaderCode", fragmentElement: "fragmentShaderCode" }`, used with shader code in script tags
  20. * * object: `{ vertex: "custom", fragment: "custom" }`, used with `Effect.ShadersStore["customVertexShader"]` and `Effect.ShadersStore["customFragmentShader"]`
  21. * * string: `"./COMMON_NAME"`, used with external files COMMON_NAME.vertex.fx and COMMON_NAME.fragment.fx in index.html folder.
  22. */
  23. export type IShaderPath = {
  24. /**
  25. * Directly pass the shader code
  26. */
  27. vertexSource?: string;
  28. /**
  29. * Directly pass the shader code
  30. */
  31. fragmentSource?: string;
  32. /**
  33. * Used with Effect.ShadersStore. If the `vertex` is set to `"custom`, then
  34. * Babylon.js will read from Effect.ShadersStore["customVertexShader"]
  35. */
  36. vertex?: string;
  37. /**
  38. * Used with Effect.ShadersStore. If the `fragment` is set to `"custom`, then
  39. * Babylon.js will read from Effect.ShadersStore["customFragmentShader"]
  40. */
  41. fragment?: string;
  42. /**
  43. * Used with shader code in script tags
  44. */
  45. vertexElement?: string;
  46. /**
  47. * Used with shader code in script tags
  48. */
  49. fragmentElement?: string;
  50. };
  51. /**
  52. * Options to be used when creating an effect.
  53. */
  54. export interface IEffectCreationOptions {
  55. /**
  56. * Attributes that will be used in the shader.
  57. */
  58. attributes: string[];
  59. /**
  60. * Uniform variable names that will be set in the shader.
  61. */
  62. uniformsNames: string[];
  63. /**
  64. * Uniform buffer variable names that will be set in the shader.
  65. */
  66. uniformBuffersNames: string[];
  67. /**
  68. * Sampler texture variable names that will be set in the shader.
  69. */
  70. samplers: string[];
  71. /**
  72. * Define statements that will be set in the shader.
  73. */
  74. defines: any;
  75. /**
  76. * Possible fallbacks for this effect to improve performance when needed.
  77. */
  78. fallbacks: Nullable<IEffectFallbacks>;
  79. /**
  80. * Callback that will be called when the shader is compiled.
  81. */
  82. onCompiled: Nullable<(effect: Effect) => void>;
  83. /**
  84. * Callback that will be called if an error occurs during shader compilation.
  85. */
  86. onError: Nullable<(effect: Effect, errors: string) => void>;
  87. /**
  88. * Parameters to be used with Babylons include syntax to iterate over an array (eg. \{lights: 10\})
  89. */
  90. indexParameters?: any;
  91. /**
  92. * Max number of lights that can be used in the shader.
  93. */
  94. maxSimultaneousLights?: number;
  95. /**
  96. * See https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/transformFeedbackVaryings
  97. */
  98. transformFeedbackVaryings?: Nullable<string[]>;
  99. /**
  100. * 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
  101. */
  102. processFinalCode?: Nullable<ShaderCustomProcessingFunction>;
  103. /**
  104. * If provided, will be called two times with the vertex and fragment code so that this code can be updated after the #include have been processed
  105. */
  106. processCodeAfterIncludes?: Nullable<ShaderCustomProcessingFunction>;
  107. /**
  108. * Is this effect rendering to several color attachments ?
  109. */
  110. multiTarget?: boolean;
  111. /**
  112. * The language the shader is written in (default: GLSL)
  113. */
  114. shaderLanguage?: ShaderLanguage;
  115. }
  116. /**
  117. * Effect containing vertex and fragment shader that can be executed on an object.
  118. */
  119. export declare class Effect implements IDisposable {
  120. /**
  121. * Gets or sets the relative url used to load shaders if using the engine in non-minified mode
  122. */
  123. static get ShadersRepository(): string;
  124. static set ShadersRepository(repo: string);
  125. /**
  126. * Enable logging of the shader code when a compilation error occurs
  127. */
  128. static LogShaderCodeOnCompilationError: boolean;
  129. /**
  130. * Name of the effect.
  131. */
  132. name: IShaderPath | string;
  133. /**
  134. * String container all the define statements that should be set on the shader.
  135. */
  136. defines: string;
  137. /**
  138. * Callback that will be called when the shader is compiled.
  139. */
  140. onCompiled: Nullable<(effect: Effect) => void>;
  141. /**
  142. * Callback that will be called if an error occurs during shader compilation.
  143. */
  144. onError: Nullable<(effect: Effect, errors: string) => void>;
  145. /**
  146. * Callback that will be called when effect is bound.
  147. */
  148. onBind: Nullable<(effect: Effect) => void>;
  149. /**
  150. * Unique ID of the effect.
  151. */
  152. uniqueId: number;
  153. /**
  154. * Observable that will be called when the shader is compiled.
  155. * It is recommended to use executeWhenCompile() or to make sure that scene.isReady() is called to get this observable raised.
  156. */
  157. onCompileObservable: Observable<Effect>;
  158. /**
  159. * Observable that will be called if an error occurs during shader compilation.
  160. */
  161. onErrorObservable: Observable<Effect>;
  162. /** @internal */
  163. _onBindObservable: Nullable<Observable<Effect>>;
  164. private _isDisposed;
  165. /**
  166. * Observable that will be called when effect is bound.
  167. */
  168. get onBindObservable(): Observable<Effect>;
  169. /** @internal */
  170. _bonesComputationForcedToCPU: boolean;
  171. /** @internal */
  172. _uniformBuffersNames: {
  173. [key: string]: number;
  174. };
  175. /** @internal */
  176. _samplerList: string[];
  177. /** @internal */
  178. _multiTarget: boolean;
  179. private static _UniqueIdSeed;
  180. /** @internal */
  181. _engine: AbstractEngine;
  182. private _uniformBuffersNamesList;
  183. private _uniformsNames;
  184. private _samplers;
  185. private _isReady;
  186. private _compilationError;
  187. private _allFallbacksProcessed;
  188. private _attributesNames;
  189. private _attributes;
  190. private _attributeLocationByName;
  191. private _uniforms;
  192. /**
  193. * Key for the effect.
  194. * @internal
  195. */
  196. _key: string;
  197. private _indexParameters;
  198. private _fallbacks;
  199. private _vertexSourceCodeOverride;
  200. private _fragmentSourceCodeOverride;
  201. private _transformFeedbackVaryings;
  202. private _shaderLanguage;
  203. /**
  204. * Compiled shader to webGL program.
  205. * @internal
  206. */
  207. _pipelineContext: Nullable<IPipelineContext>;
  208. /** @internal */
  209. _vertexSourceCode: string;
  210. /** @internal */
  211. _fragmentSourceCode: string;
  212. /** @internal */
  213. private _vertexSourceCodeBeforeMigration;
  214. /** @internal */
  215. private _fragmentSourceCodeBeforeMigration;
  216. /** @internal */
  217. private _rawVertexSourceCode;
  218. /** @internal */
  219. private _rawFragmentSourceCode;
  220. private static _BaseCache;
  221. private _processingContext;
  222. private _processCodeAfterIncludes;
  223. private _processFinalCode;
  224. /**
  225. * Gets the shader language type used to write vertex and fragment source code.
  226. */
  227. get shaderLanguage(): ShaderLanguage;
  228. /**
  229. * Instantiates an effect.
  230. * An effect can be used to create/manage/execute vertex and fragment shaders.
  231. * @param baseName Name of the effect.
  232. * @param attributesNamesOrOptions List of attribute names that will be passed to the shader or set of all options to create the effect.
  233. * @param uniformsNamesOrEngine List of uniform variable names that will be passed to the shader or the engine that will be used to render effect.
  234. * @param samplers List of sampler variables that will be passed to the shader.
  235. * @param engine Engine to be used to render the effect
  236. * @param defines Define statements to be added to the shader.
  237. * @param fallbacks Possible fallbacks for this effect to improve performance when needed.
  238. * @param onCompiled Callback that will be called when the shader is compiled.
  239. * @param onError Callback that will be called if an error occurs during shader compilation.
  240. * @param indexParameters Parameters to be used with Babylons include syntax to iterate over an array (eg. \{lights: 10\})
  241. * @param key Effect Key identifying uniquely compiled shader variants
  242. * @param shaderLanguage the language the shader is written in (default: GLSL)
  243. */
  244. constructor(baseName: IShaderPath | string, attributesNamesOrOptions: string[] | IEffectCreationOptions, uniformsNamesOrEngine: string[] | AbstractEngine, samplers?: Nullable<string[]>, engine?: AbstractEngine, defines?: Nullable<string>, fallbacks?: Nullable<IEffectFallbacks>, onCompiled?: Nullable<(effect: Effect) => void>, onError?: Nullable<(effect: Effect, errors: string) => void>, indexParameters?: any, key?: string, shaderLanguage?: ShaderLanguage);
  245. /** @internal */
  246. _processShaderCode(shaderProcessor?: Nullable<IShaderProcessor>, keepExistingPipelineContext?: boolean): void;
  247. private _useFinalCode;
  248. /**
  249. * Unique key for this effect
  250. */
  251. get key(): string;
  252. /**
  253. * If the effect has been compiled and prepared.
  254. * @returns if the effect is compiled and prepared.
  255. */
  256. isReady(): boolean;
  257. private _isReadyInternal;
  258. /**
  259. * The engine the effect was initialized with.
  260. * @returns the engine.
  261. */
  262. getEngine(): AbstractEngine;
  263. /**
  264. * The pipeline context for this effect
  265. * @returns the associated pipeline context
  266. */
  267. getPipelineContext(): Nullable<IPipelineContext>;
  268. /**
  269. * The set of names of attribute variables for the shader.
  270. * @returns An array of attribute names.
  271. */
  272. getAttributesNames(): string[];
  273. /**
  274. * Returns the attribute at the given index.
  275. * @param index The index of the attribute.
  276. * @returns The location of the attribute.
  277. */
  278. getAttributeLocation(index: number): number;
  279. /**
  280. * Returns the attribute based on the name of the variable.
  281. * @param name of the attribute to look up.
  282. * @returns the attribute location.
  283. */
  284. getAttributeLocationByName(name: string): number;
  285. /**
  286. * The number of attributes.
  287. * @returns the number of attributes.
  288. */
  289. getAttributesCount(): number;
  290. /**
  291. * Gets the index of a uniform variable.
  292. * @param uniformName of the uniform to look up.
  293. * @returns the index.
  294. */
  295. getUniformIndex(uniformName: string): number;
  296. /**
  297. * Returns the attribute based on the name of the variable.
  298. * @param uniformName of the uniform to look up.
  299. * @returns the location of the uniform.
  300. */
  301. getUniform(uniformName: string): Nullable<WebGLUniformLocation>;
  302. /**
  303. * Returns an array of sampler variable names
  304. * @returns The array of sampler variable names.
  305. */
  306. getSamplers(): string[];
  307. /**
  308. * Returns an array of uniform variable names
  309. * @returns The array of uniform variable names.
  310. */
  311. getUniformNames(): string[];
  312. /**
  313. * Returns an array of uniform buffer variable names
  314. * @returns The array of uniform buffer variable names.
  315. */
  316. getUniformBuffersNames(): string[];
  317. /**
  318. * Returns the index parameters used to create the effect
  319. * @returns The index parameters object
  320. */
  321. getIndexParameters(): any;
  322. /**
  323. * The error from the last compilation.
  324. * @returns the error string.
  325. */
  326. getCompilationError(): string;
  327. /**
  328. * Gets a boolean indicating that all fallbacks were used during compilation
  329. * @returns true if all fallbacks were used
  330. */
  331. allFallbacksProcessed(): boolean;
  332. /**
  333. * Adds a callback to the onCompiled observable and call the callback immediately if already ready.
  334. * @param func The callback to be used.
  335. */
  336. executeWhenCompiled(func: (effect: Effect) => void): void;
  337. private _checkIsReady;
  338. private _loadShader;
  339. /**
  340. * Gets the vertex shader source code of this effect
  341. * This is the final source code that will be compiled, after all the processing has been done (pre-processing applied, code injection/replacement, etc)
  342. */
  343. get vertexSourceCode(): string;
  344. /**
  345. * Gets the fragment shader source code of this effect
  346. * This is the final source code that will be compiled, after all the processing has been done (pre-processing applied, code injection/replacement, etc)
  347. */
  348. get fragmentSourceCode(): string;
  349. /**
  350. * Gets the vertex shader source code before migration.
  351. * This is the source code after the include directives have been replaced by their contents but before the code is migrated, i.e. before ShaderProcess._ProcessShaderConversion is executed.
  352. * This method is, among other things, responsible for parsing #if/#define directives as well as converting GLES2 syntax to GLES3 (in the case of WebGL).
  353. */
  354. get vertexSourceCodeBeforeMigration(): string;
  355. /**
  356. * Gets the fragment shader source code before migration.
  357. * This is the source code after the include directives have been replaced by their contents but before the code is migrated, i.e. before ShaderProcess._ProcessShaderConversion is executed.
  358. * This method is, among other things, responsible for parsing #if/#define directives as well as converting GLES2 syntax to GLES3 (in the case of WebGL).
  359. */
  360. get fragmentSourceCodeBeforeMigration(): string;
  361. /**
  362. * Gets the vertex shader source code before it has been modified by any processing
  363. */
  364. get rawVertexSourceCode(): string;
  365. /**
  366. * Gets the fragment shader source code before it has been modified by any processing
  367. */
  368. get rawFragmentSourceCode(): string;
  369. /**
  370. * Recompiles the webGL program
  371. * @param vertexSourceCode The source code for the vertex shader.
  372. * @param fragmentSourceCode The source code for the fragment shader.
  373. * @param onCompiled Callback called when completed.
  374. * @param onError Callback called on error.
  375. * @internal
  376. */
  377. _rebuildProgram(vertexSourceCode: string, fragmentSourceCode: string, onCompiled: (pipelineContext: IPipelineContext) => void, onError: (message: string) => void): void;
  378. /**
  379. * Prepares the effect
  380. * @internal
  381. */
  382. _prepareEffect(keepExistingPipelineContext?: boolean): void;
  383. private _getShaderCodeAndErrorLine;
  384. private _processCompilationErrors;
  385. /**
  386. * Checks if the effect is supported. (Must be called after compilation)
  387. */
  388. get isSupported(): boolean;
  389. /**
  390. * Binds a texture to the engine to be used as output of the shader.
  391. * @param channel Name of the output variable.
  392. * @param texture Texture to bind.
  393. * @internal
  394. */
  395. _bindTexture(channel: string, texture: Nullable<InternalTexture>): void;
  396. /**
  397. * Sets a texture on the engine to be used in the shader.
  398. * @param channel Name of the sampler variable.
  399. * @param texture Texture to set.
  400. */
  401. setTexture(channel: string, texture: Nullable<ThinTexture>): void;
  402. /**
  403. * Sets a depth stencil texture from a render target on the engine to be used in the shader.
  404. * @param channel Name of the sampler variable.
  405. * @param texture Texture to set.
  406. */
  407. setDepthStencilTexture(channel: string, texture: Nullable<RenderTargetTexture>): void;
  408. /**
  409. * Sets an array of textures on the engine to be used in the shader.
  410. * @param channel Name of the variable.
  411. * @param textures Textures to set.
  412. */
  413. setTextureArray(channel: string, textures: ThinTexture[]): void;
  414. /**
  415. * Sets a texture to be the input of the specified post process. (To use the output, pass in the next post process in the pipeline)
  416. * @param channel Name of the sampler variable.
  417. * @param postProcess Post process to get the input texture from.
  418. */
  419. setTextureFromPostProcess(channel: string, postProcess: Nullable<PostProcess>): void;
  420. /**
  421. * (Warning! setTextureFromPostProcessOutput may be desired instead)
  422. * Sets the input texture of the passed in post process to be input of this effect. (To use the output of the passed in post process use setTextureFromPostProcessOutput)
  423. * @param channel Name of the sampler variable.
  424. * @param postProcess Post process to get the output texture from.
  425. */
  426. setTextureFromPostProcessOutput(channel: string, postProcess: Nullable<PostProcess>): void;
  427. /**
  428. * Binds a buffer to a uniform.
  429. * @param buffer Buffer to bind.
  430. * @param name Name of the uniform variable to bind to.
  431. */
  432. bindUniformBuffer(buffer: DataBuffer, name: string): void;
  433. /**
  434. * Binds block to a uniform.
  435. * @param blockName Name of the block to bind.
  436. * @param index Index to bind.
  437. */
  438. bindUniformBlock(blockName: string, index: number): void;
  439. /**
  440. * Sets an integer value on a uniform variable.
  441. * @param uniformName Name of the variable.
  442. * @param value Value to be set.
  443. * @returns this effect.
  444. */
  445. setInt(uniformName: string, value: number): Effect;
  446. /**
  447. * Sets an int2 value on a uniform variable.
  448. * @param uniformName Name of the variable.
  449. * @param x First int in int2.
  450. * @param y Second int in int2.
  451. * @returns this effect.
  452. */
  453. setInt2(uniformName: string, x: number, y: number): Effect;
  454. /**
  455. * Sets an int3 value on a uniform variable.
  456. * @param uniformName Name of the variable.
  457. * @param x First int in int3.
  458. * @param y Second int in int3.
  459. * @param z Third int in int3.
  460. * @returns this effect.
  461. */
  462. setInt3(uniformName: string, x: number, y: number, z: number): Effect;
  463. /**
  464. * Sets an int4 value on a uniform variable.
  465. * @param uniformName Name of the variable.
  466. * @param x First int in int4.
  467. * @param y Second int in int4.
  468. * @param z Third int in int4.
  469. * @param w Fourth int in int4.
  470. * @returns this effect.
  471. */
  472. setInt4(uniformName: string, x: number, y: number, z: number, w: number): Effect;
  473. /**
  474. * Sets an int array on a uniform variable.
  475. * @param uniformName Name of the variable.
  476. * @param array array to be set.
  477. * @returns this effect.
  478. */
  479. setIntArray(uniformName: string, array: Int32Array): Effect;
  480. /**
  481. * Sets an int array 2 on a uniform variable. (Array is specified as single array eg. [1,2,3,4] will result in [[1,2],[3,4]] in the shader)
  482. * @param uniformName Name of the variable.
  483. * @param array array to be set.
  484. * @returns this effect.
  485. */
  486. setIntArray2(uniformName: string, array: Int32Array): Effect;
  487. /**
  488. * Sets an int array 3 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6] will result in [[1,2,3],[4,5,6]] in the shader)
  489. * @param uniformName Name of the variable.
  490. * @param array array to be set.
  491. * @returns this effect.
  492. */
  493. setIntArray3(uniformName: string, array: Int32Array): Effect;
  494. /**
  495. * Sets an int array 4 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6,7,8] will result in [[1,2,3,4],[5,6,7,8]] in the shader)
  496. * @param uniformName Name of the variable.
  497. * @param array array to be set.
  498. * @returns this effect.
  499. */
  500. setIntArray4(uniformName: string, array: Int32Array): Effect;
  501. /**
  502. * Sets an unsigned integer value on a uniform variable.
  503. * @param uniformName Name of the variable.
  504. * @param value Value to be set.
  505. * @returns this effect.
  506. */
  507. setUInt(uniformName: string, value: number): Effect;
  508. /**
  509. * Sets an unsigned int2 value on a uniform variable.
  510. * @param uniformName Name of the variable.
  511. * @param x First unsigned int in uint2.
  512. * @param y Second unsigned int in uint2.
  513. * @returns this effect.
  514. */
  515. setUInt2(uniformName: string, x: number, y: number): Effect;
  516. /**
  517. * Sets an unsigned int3 value on a uniform variable.
  518. * @param uniformName Name of the variable.
  519. * @param x First unsigned int in uint3.
  520. * @param y Second unsigned int in uint3.
  521. * @param z Third unsigned int in uint3.
  522. * @returns this effect.
  523. */
  524. setUInt3(uniformName: string, x: number, y: number, z: number): Effect;
  525. /**
  526. * Sets an unsigned int4 value on a uniform variable.
  527. * @param uniformName Name of the variable.
  528. * @param x First unsigned int in uint4.
  529. * @param y Second unsigned int in uint4.
  530. * @param z Third unsigned int in uint4.
  531. * @param w Fourth unsigned int in uint4.
  532. * @returns this effect.
  533. */
  534. setUInt4(uniformName: string, x: number, y: number, z: number, w: number): Effect;
  535. /**
  536. * Sets an unsigned int array on a uniform variable.
  537. * @param uniformName Name of the variable.
  538. * @param array array to be set.
  539. * @returns this effect.
  540. */
  541. setUIntArray(uniformName: string, array: Uint32Array): Effect;
  542. /**
  543. * Sets an unsigned int array 2 on a uniform variable. (Array is specified as single array eg. [1,2,3,4] will result in [[1,2],[3,4]] in the shader)
  544. * @param uniformName Name of the variable.
  545. * @param array array to be set.
  546. * @returns this effect.
  547. */
  548. setUIntArray2(uniformName: string, array: Uint32Array): Effect;
  549. /**
  550. * Sets an unsigned int array 3 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6] will result in [[1,2,3],[4,5,6]] in the shader)
  551. * @param uniformName Name of the variable.
  552. * @param array array to be set.
  553. * @returns this effect.
  554. */
  555. setUIntArray3(uniformName: string, array: Uint32Array): Effect;
  556. /**
  557. * Sets an unsigned int array 4 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6,7,8] will result in [[1,2,3,4],[5,6,7,8]] in the shader)
  558. * @param uniformName Name of the variable.
  559. * @param array array to be set.
  560. * @returns this effect.
  561. */
  562. setUIntArray4(uniformName: string, array: Uint32Array): Effect;
  563. /**
  564. * Sets an float array on a uniform variable.
  565. * @param uniformName Name of the variable.
  566. * @param array array to be set.
  567. * @returns this effect.
  568. */
  569. setFloatArray(uniformName: string, array: FloatArray): Effect;
  570. /**
  571. * Sets an float array 2 on a uniform variable. (Array is specified as single array eg. [1,2,3,4] will result in [[1,2],[3,4]] in the shader)
  572. * @param uniformName Name of the variable.
  573. * @param array array to be set.
  574. * @returns this effect.
  575. */
  576. setFloatArray2(uniformName: string, array: FloatArray): Effect;
  577. /**
  578. * Sets an float array 3 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6] will result in [[1,2,3],[4,5,6]] in the shader)
  579. * @param uniformName Name of the variable.
  580. * @param array array to be set.
  581. * @returns this effect.
  582. */
  583. setFloatArray3(uniformName: string, array: FloatArray): Effect;
  584. /**
  585. * Sets an float array 4 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6,7,8] will result in [[1,2,3,4],[5,6,7,8]] in the shader)
  586. * @param uniformName Name of the variable.
  587. * @param array array to be set.
  588. * @returns this effect.
  589. */
  590. setFloatArray4(uniformName: string, array: FloatArray): Effect;
  591. /**
  592. * Sets an array on a uniform variable.
  593. * @param uniformName Name of the variable.
  594. * @param array array to be set.
  595. * @returns this effect.
  596. */
  597. setArray(uniformName: string, array: number[]): Effect;
  598. /**
  599. * Sets an array 2 on a uniform variable. (Array is specified as single array eg. [1,2,3,4] will result in [[1,2],[3,4]] in the shader)
  600. * @param uniformName Name of the variable.
  601. * @param array array to be set.
  602. * @returns this effect.
  603. */
  604. setArray2(uniformName: string, array: number[]): Effect;
  605. /**
  606. * Sets an array 3 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6] will result in [[1,2,3],[4,5,6]] in the shader)
  607. * @param uniformName Name of the variable.
  608. * @param array array to be set.
  609. * @returns this effect.
  610. */
  611. setArray3(uniformName: string, array: number[]): Effect;
  612. /**
  613. * Sets an array 4 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6,7,8] will result in [[1,2,3,4],[5,6,7,8]] in the shader)
  614. * @param uniformName Name of the variable.
  615. * @param array array to be set.
  616. * @returns this effect.
  617. */
  618. setArray4(uniformName: string, array: number[]): Effect;
  619. /**
  620. * Sets matrices on a uniform variable.
  621. * @param uniformName Name of the variable.
  622. * @param matrices matrices to be set.
  623. * @returns this effect.
  624. */
  625. setMatrices(uniformName: string, matrices: Float32Array | Array<number>): Effect;
  626. /**
  627. * Sets matrix on a uniform variable.
  628. * @param uniformName Name of the variable.
  629. * @param matrix matrix to be set.
  630. * @returns this effect.
  631. */
  632. setMatrix(uniformName: string, matrix: IMatrixLike): Effect;
  633. /**
  634. * Sets a 3x3 matrix on a uniform variable. (Specified as [1,2,3,4,5,6,7,8,9] will result in [1,2,3][4,5,6][7,8,9] matrix)
  635. * @param uniformName Name of the variable.
  636. * @param matrix matrix to be set.
  637. * @returns this effect.
  638. */
  639. setMatrix3x3(uniformName: string, matrix: Float32Array | Array<number>): Effect;
  640. /**
  641. * Sets a 2x2 matrix on a uniform variable. (Specified as [1,2,3,4] will result in [1,2][3,4] matrix)
  642. * @param uniformName Name of the variable.
  643. * @param matrix matrix to be set.
  644. * @returns this effect.
  645. */
  646. setMatrix2x2(uniformName: string, matrix: Float32Array | Array<number>): Effect;
  647. /**
  648. * Sets a float on a uniform variable.
  649. * @param uniformName Name of the variable.
  650. * @param value value to be set.
  651. * @returns this effect.
  652. */
  653. setFloat(uniformName: string, value: number): Effect;
  654. /**
  655. * Sets a boolean on a uniform variable.
  656. * @param uniformName Name of the variable.
  657. * @param bool value to be set.
  658. * @returns this effect.
  659. */
  660. setBool(uniformName: string, bool: boolean): Effect;
  661. /**
  662. * Sets a Vector2 on a uniform variable.
  663. * @param uniformName Name of the variable.
  664. * @param vector2 vector2 to be set.
  665. * @returns this effect.
  666. */
  667. setVector2(uniformName: string, vector2: IVector2Like): Effect;
  668. /**
  669. * Sets a float2 on a uniform variable.
  670. * @param uniformName Name of the variable.
  671. * @param x First float in float2.
  672. * @param y Second float in float2.
  673. * @returns this effect.
  674. */
  675. setFloat2(uniformName: string, x: number, y: number): Effect;
  676. /**
  677. * Sets a Vector3 on a uniform variable.
  678. * @param uniformName Name of the variable.
  679. * @param vector3 Value to be set.
  680. * @returns this effect.
  681. */
  682. setVector3(uniformName: string, vector3: IVector3Like): Effect;
  683. /**
  684. * Sets a float3 on a uniform variable.
  685. * @param uniformName Name of the variable.
  686. * @param x First float in float3.
  687. * @param y Second float in float3.
  688. * @param z Third float in float3.
  689. * @returns this effect.
  690. */
  691. setFloat3(uniformName: string, x: number, y: number, z: number): Effect;
  692. /**
  693. * Sets a Vector4 on a uniform variable.
  694. * @param uniformName Name of the variable.
  695. * @param vector4 Value to be set.
  696. * @returns this effect.
  697. */
  698. setVector4(uniformName: string, vector4: IVector4Like): Effect;
  699. /**
  700. * Sets a Quaternion on a uniform variable.
  701. * @param uniformName Name of the variable.
  702. * @param quaternion Value to be set.
  703. * @returns this effect.
  704. */
  705. setQuaternion(uniformName: string, quaternion: IQuaternionLike): Effect;
  706. /**
  707. * Sets a float4 on a uniform variable.
  708. * @param uniformName Name of the variable.
  709. * @param x First float in float4.
  710. * @param y Second float in float4.
  711. * @param z Third float in float4.
  712. * @param w Fourth float in float4.
  713. * @returns this effect.
  714. */
  715. setFloat4(uniformName: string, x: number, y: number, z: number, w: number): Effect;
  716. /**
  717. * Sets a Color3 on a uniform variable.
  718. * @param uniformName Name of the variable.
  719. * @param color3 Value to be set.
  720. * @returns this effect.
  721. */
  722. setColor3(uniformName: string, color3: IColor3Like): Effect;
  723. /**
  724. * Sets a Color4 on a uniform variable.
  725. * @param uniformName Name of the variable.
  726. * @param color3 Value to be set.
  727. * @param alpha Alpha value to be set.
  728. * @returns this effect.
  729. */
  730. setColor4(uniformName: string, color3: IColor3Like, alpha: number): Effect;
  731. /**
  732. * Sets a Color4 on a uniform variable
  733. * @param uniformName defines the name of the variable
  734. * @param color4 defines the value to be set
  735. * @returns this effect.
  736. */
  737. setDirectColor4(uniformName: string, color4: IColor4Like): Effect;
  738. /**
  739. * Release all associated resources.
  740. **/
  741. dispose(): void;
  742. /**
  743. * This function will add a new shader to the shader store
  744. * @param name the name of the shader
  745. * @param pixelShader optional pixel shader content
  746. * @param vertexShader optional vertex shader content
  747. * @param shaderLanguage the language the shader is written in (default: GLSL)
  748. */
  749. static RegisterShader(name: string, pixelShader?: string, vertexShader?: string, shaderLanguage?: ShaderLanguage): void;
  750. /**
  751. * Store of each shader (The can be looked up using effect.key)
  752. */
  753. static ShadersStore: {
  754. [key: string]: string;
  755. };
  756. /**
  757. * Store of each included file for a shader (The can be looked up using effect.key)
  758. */
  759. static IncludesShadersStore: {
  760. [key: string]: string;
  761. };
  762. /**
  763. * Resets the cache of effects.
  764. */
  765. static ResetCache(): void;
  766. }