Options
All
  • Public
  • Public/Protected
  • All
Menu

Effect containing vertex and fragment shader that can be executed on an object.

Hierarchy

  • Effect

Implements

Index

Constructors

  • Instantiates an effect. An effect can be used to create/manage/execute vertex and fragment shaders.

    Parameters

    • baseName: any

      Name of the effect.

    • attributesNamesOrOptions: string[] | IEffectCreationOptions

      List of attribute names that will be passed to the shader or set of all options to create the effect.

    • uniformsNamesOrEngine: string[] | ThinEngine

      List of uniform variable names that will be passed to the shader or the engine that will be used to render effect.

    • Optional samplers: Nullable<string[]>

      List of sampler variables that will be passed to the shader.

    • Optional engine: ThinEngine

      Engine to be used to render the effect

    • Optional defines: Nullable<string>

      Define statements to be added to the shader.

    • Optional fallbacks: Nullable<IEffectFallbacks>

      Possible fallbacks for this effect to improve performance when needed.

    • Optional onCompiled: Nullable<((effect: Effect) => void)>

      Callback that will be called when the shader is compiled.

    • Optional onError: Nullable<((effect: Effect, errors: string) => void)>

      Callback that will be called if an error occurs during shader compilation.

    • Optional indexParameters: any

      Parameters to be used with Babylons include syntax to iterate over an array (eg. {lights: 10})

    • Optional key: string

      Effect Key identifying uniquely compiled shader variants

    • Optional shaderLanguage: ShaderLanguage

      the language the shader is written in (default: GLSL)

    Returns Effect

Properties

defines: string

String container all the define statements that should be set on the shader.

name: any

Name of the effect.

onBind: Nullable<((effect: Effect) => void)>

Callback that will be called when effect is bound.

onCompileObservable: Observable<Effect>

Observable that will be called when the shader is compiled. It is recommended to use executeWhenCompile() or to make sure that scene.isReady() is called to get this observable raised.

onCompiled: Nullable<((effect: Effect) => void)>

Callback that will be called when the shader is compiled.

onError: Nullable<((effect: Effect, errors: string) => void)>

Callback that will be called if an error occurs during shader compilation.

onErrorObservable: Observable<Effect>

Observable that will be called if an error occurs during shader compilation.

setArray: ((uniformName: string, array: number[]) => Effect)

Type declaration

    • (uniformName: string, array: number[]): Effect
    • Sets an array on a uniform variable.

      Parameters

      • uniformName: string

        Name of the variable.

      • array: number[]

        array to be set.

      Returns Effect

      this effect.

setArray2: ((uniformName: string, array: number[]) => Effect)

Type declaration

    • (uniformName: string, array: number[]): Effect
    • 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)

      Parameters

      • uniformName: string

        Name of the variable.

      • array: number[]

        array to be set.

      Returns Effect

      this effect.

setArray3: ((uniformName: string, array: number[]) => Effect)

Type declaration

    • (uniformName: string, array: number[]): Effect
    • 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)

      Parameters

      • uniformName: string

        Name of the variable.

      • array: number[]

        array to be set.

      Returns Effect

      this effect.

setArray4: ((uniformName: string, array: number[]) => Effect)

Type declaration

    • (uniformName: string, array: number[]): Effect
    • 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)

      Parameters

      • uniformName: string

        Name of the variable.

      • array: number[]

        array to be set.

      Returns Effect

      this effect.

setColor3: ((uniformName: string, color3: IColor3Like) => Effect)

Type declaration

    • (uniformName: string, color3: IColor3Like): Effect
    • Sets a Color3 on a uniform variable.

      Parameters

      • uniformName: string

        Name of the variable.

      • color3: IColor3Like

        Value to be set.

      Returns Effect

      this effect.

setColor4: ((uniformName: string, color3: IColor3Like, alpha: number) => Effect)

Type declaration

    • (uniformName: string, color3: IColor3Like, alpha: number): Effect
    • Sets a Color4 on a uniform variable.

      Parameters

      • uniformName: string

        Name of the variable.

      • color3: IColor3Like

        Value to be set.

      • alpha: number

        Alpha value to be set.

      Returns Effect

      this effect.

setDirectColor4: ((uniformName: string, color4: IColor4Like) => Effect)

Type declaration

    • (uniformName: string, color4: IColor4Like): Effect
    • Sets a Color4 on a uniform variable

      Parameters

      • uniformName: string

        defines the name of the variable

      • color4: IColor4Like

        defines the value to be set

      Returns Effect

      this effect.

setFloat: ((uniformName: string, value: number) => Effect)

Type declaration

    • (uniformName: string, value: number): Effect
    • Sets a float on a uniform variable.

      Parameters

      • uniformName: string

        Name of the variable.

      • value: number

        value to be set.

      Returns Effect

      this effect.

setFloat2: ((uniformName: string, x: number, y: number) => Effect)

Type declaration

    • (uniformName: string, x: number, y: number): Effect
    • Sets a float2 on a uniform variable.

      Parameters

      • uniformName: string

        Name of the variable.

      • x: number

        First float in float2.

      • y: number

        Second float in float2.

      Returns Effect

      this effect.

setFloat3: ((uniformName: string, x: number, y: number, z: number) => Effect)

Type declaration

    • (uniformName: string, x: number, y: number, z: number): Effect
    • Sets a float3 on a uniform variable.

      Parameters

      • uniformName: string

        Name of the variable.

      • x: number

        First float in float3.

      • y: number

        Second float in float3.

      • z: number

        Third float in float3.

      Returns Effect

      this effect.

setFloat4: ((uniformName: string, x: number, y: number, z: number, w: number) => Effect)

Type declaration

    • (uniformName: string, x: number, y: number, z: number, w: number): Effect
    • Sets a float4 on a uniform variable.

      Parameters

      • uniformName: string

        Name of the variable.

      • x: number

        First float in float4.

      • y: number

        Second float in float4.

      • z: number

        Third float in float4.

      • w: number

        Fourth float in float4.

      Returns Effect

      this effect.

setInt: ((uniformName: string, value: number) => Effect)

Type declaration

    • (uniformName: string, value: number): Effect
    • Sets an integer value on a uniform variable.

      Parameters

      • uniformName: string

        Name of the variable.

      • value: number

        Value to be set.

      Returns Effect

      this effect.

setInt2: ((uniformName: string, x: number, y: number) => Effect)

Type declaration

    • (uniformName: string, x: number, y: number): Effect
    • Sets an int2 value on a uniform variable.

      Parameters

      • uniformName: string

        Name of the variable.

      • x: number

        First int in int2.

      • y: number

        Second int in int2.

      Returns Effect

      this effect.

setInt3: ((uniformName: string, x: number, y: number, z: number) => Effect)

Type declaration

    • (uniformName: string, x: number, y: number, z: number): Effect
    • Sets an int3 value on a uniform variable.

      Parameters

      • uniformName: string

        Name of the variable.

      • x: number

        First int in int3.

      • y: number

        Second int in int3.

      • z: number

        Third int in int3.

      Returns Effect

      this effect.

setInt4: ((uniformName: string, x: number, y: number, z: number, w: number) => Effect)

Type declaration

    • (uniformName: string, x: number, y: number, z: number, w: number): Effect
    • Sets an int4 value on a uniform variable.

      Parameters

      • uniformName: string

        Name of the variable.

      • x: number

        First int in int4.

      • y: number

        Second int in int4.

      • z: number

        Third int in int4.

      • w: number

        Fourth int in int4.

      Returns Effect

      this effect.

setIntArray: ((uniformName: string, array: Int32Array) => Effect)

Type declaration

    • (uniformName: string, array: Int32Array): Effect
    • Sets an int array on a uniform variable.

      Parameters

      • uniformName: string

        Name of the variable.

      • array: Int32Array

        array to be set.

      Returns Effect

      this effect.

setIntArray2: ((uniformName: string, array: Int32Array) => Effect)

Type declaration

    • (uniformName: string, array: Int32Array): Effect
    • 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)

      Parameters

      • uniformName: string

        Name of the variable.

      • array: Int32Array

        array to be set.

      Returns Effect

      this effect.

setIntArray3: ((uniformName: string, array: Int32Array) => Effect)

Type declaration

    • (uniformName: string, array: Int32Array): Effect
    • 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)

      Parameters

      • uniformName: string

        Name of the variable.

      • array: Int32Array

        array to be set.

      Returns Effect

      this effect.

setIntArray4: ((uniformName: string, array: Int32Array) => Effect)

Type declaration

    • (uniformName: string, array: Int32Array): Effect
    • 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)

      Parameters

      • uniformName: string

        Name of the variable.

      • array: Int32Array

        array to be set.

      Returns Effect

      this effect.

setMatrices: ((uniformName: string, matrices: number[] | Float32Array) => Effect)

Type declaration

    • (uniformName: string, matrices: number[] | Float32Array): Effect
    • Sets matrices on a uniform variable.

      Parameters

      • uniformName: string

        Name of the variable.

      • matrices: number[] | Float32Array

        matrices to be set.

      Returns Effect

      this effect.

setMatrix: ((uniformName: string, matrix: IMatrixLike) => Effect)

Type declaration

    • (uniformName: string, matrix: IMatrixLike): Effect
    • Sets matrix on a uniform variable.

      Parameters

      • uniformName: string

        Name of the variable.

      • matrix: IMatrixLike

        matrix to be set.

      Returns Effect

      this effect.

setMatrix2x2: ((uniformName: string, matrix: number[] | Float32Array) => Effect)

Type declaration

    • (uniformName: string, matrix: number[] | Float32Array): Effect
    • Sets a 2x2 matrix on a uniform variable. (Specified as [1,2,3,4] will result in [1,2][3,4] matrix)

      Parameters

      • uniformName: string

        Name of the variable.

      • matrix: number[] | Float32Array

        matrix to be set.

      Returns Effect

      this effect.

setMatrix3x3: ((uniformName: string, matrix: number[] | Float32Array) => Effect)

Type declaration

    • (uniformName: string, matrix: number[] | Float32Array): Effect
    • 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)

      Parameters

      • uniformName: string

        Name of the variable.

      • matrix: number[] | Float32Array

        matrix to be set.

      Returns Effect

      this effect.

setQuaternion: ((uniformName: string, quaternion: IQuaternionLike) => Effect)

Type declaration

    • Sets a Quaternion on a uniform variable.

      Parameters

      • uniformName: string

        Name of the variable.

      • quaternion: IQuaternionLike

        Value to be set.

      Returns Effect

      this effect.

setVector2: ((uniformName: string, vector2: IVector2Like) => Effect)

Type declaration

    • (uniformName: string, vector2: IVector2Like): Effect
    • Sets a Vector2 on a uniform variable.

      Parameters

      • uniformName: string

        Name of the variable.

      • vector2: IVector2Like

        vector2 to be set.

      Returns Effect

      this effect.

setVector3: ((uniformName: string, vector3: IVector3Like) => Effect)

Type declaration

    • (uniformName: string, vector3: IVector3Like): Effect
    • Sets a Vector3 on a uniform variable.

      Parameters

      • uniformName: string

        Name of the variable.

      • vector3: IVector3Like

        Value to be set.

      Returns Effect

      this effect.

setVector4: ((uniformName: string, vector4: IVector4Like) => Effect)

Type declaration

    • (uniformName: string, vector4: IVector4Like): Effect
    • Sets a Vector4 on a uniform variable.

      Parameters

      • uniformName: string

        Name of the variable.

      • vector4: IVector4Like

        Value to be set.

      Returns Effect

      this effect.

uniqueId: number

Unique ID of the effect.

IncludesShadersStore: {}

Store of each included file for a shader (The can be looked up using effect.key)

Type declaration

  • [key: string]: string
LogShaderCodeOnCompilationError: boolean

Enable logging of the shader code when a compilation error occurs

ShadersStore: {}

Store of each shader (The can be looked up using effect.key)

Type declaration

  • [key: string]: string

Accessors

  • get fragmentSourceCode(): string
  • Gets the fragment shader source code of this effect

    Returns string

  • get isSupported(): boolean
  • Checks if the effect is supported. (Must be called after compilation)

    Returns boolean

  • get key(): string
  • Unique key for this effect

    Returns string

  • Observable that will be called when effect is bound.

    Returns Observable<Effect>

  • get rawFragmentSourceCode(): string
  • Gets the fragment shader source code before it has been processed by the preprocessor

    Returns string

  • get rawVertexSourceCode(): string
  • Gets the vertex shader source code before it has been processed by the preprocessor

    Returns string

  • get vertexSourceCode(): string
  • Gets the vertex shader source code of this effect

    Returns string

  • get ShadersRepository(): string
  • set ShadersRepository(repo: string): void
  • Gets or sets the relative url used to load shaders if using the engine in non-minified mode

    Returns string

  • Gets or sets the relative url used to load shaders if using the engine in non-minified mode

    Parameters

    • repo: string

    Returns void

Methods

  • allFallbacksProcessed(): boolean
  • Gets a boolean indicating that all fallbacks were used during compilation

    Returns boolean

    true if all fallbacks were used

  • bindUniformBlock(blockName: string, index: number): void
  • Binds block to a uniform.

    Parameters

    • blockName: string

      Name of the block to bind.

    • index: number

      Index to bind.

    Returns void

  • bindUniformBuffer(buffer: DataBuffer, name: string): void
  • Binds a buffer to a uniform.

    Parameters

    • buffer: DataBuffer

      Buffer to bind.

    • name: string

      Name of the uniform variable to bind to.

    Returns void

  • dispose(): void
  • Release all associated resources.

    Returns void

  • executeWhenCompiled(func: ((effect: Effect) => void)): void
  • Adds a callback to the onCompiled observable and call the callback immediately if already ready.

    Parameters

    • func: ((effect: Effect) => void)

      The callback to be used.

    Returns void

  • getAttributeLocation(index: number): number
  • Returns the attribute at the given index.

    Parameters

    • index: number

      The index of the attribute.

    Returns number

    The location of the attribute.

  • getAttributeLocationByName(name: string): number
  • Returns the attribute based on the name of the variable.

    Parameters

    • name: string

      of the attribute to look up.

    Returns number

    the attribute location.

  • getAttributesCount(): number
  • The number of attributes.

    Returns number

    the number of attributes.

  • getAttributesNames(): string[]
  • The set of names of attribute variables for the shader.

    Returns string[]

    An array of attribute names.

  • getCompilationError(): string
  • The error from the last compilation.

    Returns string

    the error string.

  • The engine the effect was initialized with.

    Returns Engine

    the engine.

  • getIndexParameters(): any
  • Returns the index parameters used to create the effect

    Returns any

    The index parameters object

  • The pipeline context for this effect

    Returns Nullable<IPipelineContext>

    the associated pipeline context

  • getSamplers(): string[]
  • Returns an array of sampler variable names

    Returns string[]

    The array of sampler variable names.

  • getUniform(uniformName: string): Nullable<WebGLUniformLocation>
  • Returns the attribute based on the name of the variable.

    Parameters

    • uniformName: string

      of the uniform to look up.

    Returns Nullable<WebGLUniformLocation>

    the location of the uniform.

  • getUniformBuffersNames(): string[]
  • Returns an array of uniform buffer variable names

    Returns string[]

    The array of uniform buffer variable names.

  • getUniformIndex(uniformName: string): number
  • Gets the index of a uniform variable.

    Parameters

    • uniformName: string

      of the uniform to look up.

    Returns number

    the index.

  • getUniformNames(): string[]
  • Returns an array of uniform variable names

    Returns string[]

    The array of uniform variable names.

  • isReady(): boolean
  • If the effect has been compiled and prepared.

    Returns boolean

    if the effect is compiled and prepared.

  • setBool(uniformName: string, bool: boolean): Effect
  • Sets a boolean on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • bool: boolean

      value to be set.

    Returns Effect

    this effect.

  • Sets a depth stencil texture from a render target on the engine to be used in the shader.

    Parameters

    Returns void

  • Sets an external texture on the engine to be used in the shader.

    Parameters

    Returns void

  • Sets an float array on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • array: FloatArray

      array to be set.

    Returns Effect

    this effect.

  • 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)

    Parameters

    • uniformName: string

      Name of the variable.

    • array: FloatArray

      array to be set.

    Returns Effect

    this effect.

  • 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)

    Parameters

    • uniformName: string

      Name of the variable.

    • array: FloatArray

      array to be set.

    Returns Effect

    this effect.

  • 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)

    Parameters

    • uniformName: string

      Name of the variable.

    • array: FloatArray

      array to be set.

    Returns Effect

    this effect.

  • Sets a storage buffer on the engine to be used in the shader.

    Parameters

    • name: string

      Name of the storage buffer variable.

    • buffer: Nullable<StorageBuffer>

      Storage buffer to set.

    Returns void

  • Sets a texture on the engine to be used in the shader.

    Parameters

    Returns void

  • setTextureArray(channel: string, textures: ThinTexture[]): void
  • Sets an array of textures on the engine to be used in the shader.

    Parameters

    • channel: string

      Name of the variable.

    • textures: ThinTexture[]

      Textures to set.

    Returns void

  • 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)

    Parameters

    • channel: string

      Name of the sampler variable.

    • postProcess: Nullable<PostProcess>

      Post process to get the input texture from.

    Returns void

  • (Warning! setTextureFromPostProcessOutput may be desired instead) 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)

    Parameters

    • channel: string

      Name of the sampler variable.

    • postProcess: Nullable<PostProcess>

      Post process to get the output texture from.

    Returns void

  • Sets a sampler on the engine to be used in the shader.

    Parameters

    Returns void

  • RegisterShader(name: string, pixelShader?: string, vertexShader?: string, shaderLanguage?: ShaderLanguage): void
  • This function will add a new shader to the shader store

    Parameters

    • name: string

      the name of the shader

    • Optional pixelShader: string

      optional pixel shader content

    • Optional vertexShader: string

      optional vertex shader content

    • Optional shaderLanguage: ShaderLanguage

      the language the shader is written in (default: GLSL)

    Returns void

  • ResetCache(): void
  • Resets the cache of effects.

    Returns void

Legend

  • Constructor
  • Property
  • Method
  • Property
  • Method
  • Static property
  • Static method
  • Inherited constructor

Settings

Theme