Effect

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

Hierarchy

  • Effect

Index

Constructors

constructor

  • 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[] | EffectCreationOptions

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

    • uniformsNamesOrEngine: string[] | Engine

      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: Engine

      Engine to be used to render the effect

    • Optional defines: Nullable<string>

      Define statements to be added to the shader.

    • Optional fallbacks: Nullable<EffectFallbacks>

      Possible fallbacks for this effect to improve performance when needed.

    • Optional onCompiled: Nullable<function>

      Callback that will be called when the shader is compiled.

    • Optional onError: Nullable<function>

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

    Returns Effect

Properties

defines

defines: string

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

isSupported

isSupported: boolean

Checks if the effect is supported. (Must be called after compilation)

key

key: string

Unique key for this effect

name

name: any

Name of the effect.

onBind

onBind: Nullable<function>

Callback that will be called when effect is bound.

onBindObservable

onBindObservable: Observable<Effect>

Observable that will be called when effect is bound.

onCompileObservable

onCompileObservable: Observable<Effect>

Observable that will be called when the shader is compiled.

onCompiled

onCompiled: Nullable<function>

Callback that will be called when the shader is compiled.

onError

onError: Nullable<function>

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

onErrorObservable

onErrorObservable: Observable<Effect>

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

uniqueId

uniqueId: number

Unique ID of the effect.

Static IncludesShadersStore

IncludesShadersStore: object

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

Type declaration

  • [key: string]: string

Static ShadersStore

ShadersStore: object

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

Type declaration

  • [key: string]: string

Methods

bindUniformBlock

  • 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

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

    Parameters

    • buffer: WebGLBuffer

      Buffer to bind.

    • name: string

      Name of the uniform variable to bind to.

    Returns void

executeWhenCompiled

  • executeWhenCompiled(func: function): void
  • Adds a callback to the onCompiled observable and call the callback imediatly if already ready.

    Parameters

    • func: function

      The callback to be used.

        • Parameters

          Returns void

    Returns void

getAttributeLocation

  • 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

  • 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

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

    Returns number

    the numnber of attributes.

getAttributesNames

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

    Returns string[]

    An array of attribute names.

getCompilationError

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

    Returns string

    the error string.

getEngine

  • The engine the effect was initialized with.

    Returns Engine

    the engine.

getProgram

  • getProgram(): WebGLProgram
  • The compiled webGL program for the effect

    Returns WebGLProgram

    the webGL program.

getSamplers

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

    Returns string[]

    The array of sampler variable neames.

getSpecificUniformLocations

  • getSpecificUniformLocations(names: string[]): Nullable<WebGLUniformLocation>[]
  • Gets the uniform locations of the the specified variable names

    Parameters

    • names: string[]

      THe names of the variables to lookup.

    Returns Nullable<WebGLUniformLocation>[]

    Array of locations in the same order as variable names.

getUniform

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

getUniformIndex

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

    Parameters

    • uniformName: string

      of the uniform to look up.

    Returns number

    the index.

isReady

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

    Returns boolean

    if the effect is compiled and prepared.

setArray

  • setArray(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

  • setArray2(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

  • setArray3(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

  • setArray4(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.

setBool

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

setColor3

  • Sets a Color3 on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • color3: Color3

      Value to be set.

    Returns Effect

    this effect.

setColor4

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

    Parameters

    • uniformName: string

      Name of the variable.

    • color3: Color3

      Value to be set.

    • alpha: number

      Alpha value to be set.

    Returns Effect

    this effect.

setDepthStencilTexture

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

    Parameters

    Returns void

setDirectColor4

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

    Parameters

    • uniformName: string

      defines the name of the variable

    • color4: Color4

      defines the value to be set

    Returns Effect

    this effect.

setFloat

  • setFloat(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

  • setFloat2(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

  • setFloat3(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

  • setFloat4(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.

setFloatArray

  • setFloatArray(uniformName: string, array: Float32Array): Effect
  • Sets an float array on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • array: Float32Array

      array to be set.

    Returns Effect

    this effect.

setFloatArray2

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

      array to be set.

    Returns Effect

    this effect.

setFloatArray3

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

      array to be set.

    Returns Effect

    this effect.

setFloatArray4

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

      array to be set.

    Returns Effect

    this effect.

setInt

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

    Parameters

    • uniformName: string

      Name of the variable.

    • value: number

      Value to be set.

    Returns Effect

    this effect.

setIntArray

  • setIntArray(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

  • setIntArray2(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

  • setIntArray3(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

  • setIntArray4(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

  • setMatrices(uniformName: string, matrices: Float32Array): Effect
  • Sets matrices on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • matrices: Float32Array

      matrices to be set.

    Returns Effect

    this effect.

setMatrix

  • Sets matrix on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • matrix: Matrix

      matrix to be set.

    Returns Effect

    this effect.

setMatrix2x2

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

    Parameters

    • uniformName: string

      Name of the variable.

    • matrix: Float32Array

      matrix to be set.

    Returns Effect

    this effect.

setMatrix3x3

  • setMatrix3x3(uniformName: string, matrix: Float32Array): Effect
  • Sets a 3x3 matrix on a uniform variable. (Speicified 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: Float32Array

      matrix to be set.

    Returns Effect

    this effect.

setTexture

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

    Parameters

    Returns void

setTextureArray

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

    Parameters

    • channel: string

      Name of the variable.

    • textures: BaseTexture[]

      Textures to set.

    Returns void

setTextureFromPostProcess

  • 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

setTextureFromPostProcessOutput

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

setVector2

  • Sets a Vector2 on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • vector2: Vector2

      vector2 to be set.

    Returns Effect

    this effect.

setVector3

  • Sets a Vector3 on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • vector3: Vector3

      Value to be set.

    Returns Effect

    this effect.

setVector4

  • Sets a Vector4 on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • vector4: Vector4

      Value to be set.

    Returns Effect

    this effect.

Static RegisterShader

  • RegisterShader(name: string, pixelShader?: string, vertexShader?: string): 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

    Returns void

Static ResetCache

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

    Returns void

Generated using TypeDoc