Skip to main content

Shader

Index

Constructors

constructor

  • Create a shader program in excalibur


    Parameters

    • optionaloptions: ShaderOptions

      specify shader vertex and fragment source

    Returns Shader

Properties

publicattributes

attributes: {} = {}

Type declaration

publicreadonlyfragmentSource

fragmentSource: string

publicprogram

program: WebGLProgram

publicuniforms

uniforms: {} = {}

Type declaration

publicreadonlyvertexSource

vertexSource: string

Accessors

publiccompiled

  • get compiled(): boolean
  • Returns boolean

Methods

compile

  • compile(): WebGLProgram
  • Compile the current shader against a webgl context


    Returns WebGLProgram

dispose

  • dispose(): void
  • Returns void

getAttributes

getUniforms

isCurrentlyBound

  • isCurrentlyBound(): boolean
  • Returns boolean

setTexture

  • setTexture(slotNumber: number, texture: WebGLTexture): void
  • Set a texture in a gpu texture slot


    Parameters

    • slotNumber: number
    • texture: WebGLTexture

    Returns void

setUniform

  • setUniform<TUniformType>(uniformType: TUniformType, name: string, ...value: RemoveFirstFromTuple<Parameters<WebGLRenderingContext[TUniformType]>>): void
  • Set any available uniform type in webgl

    For example setUniform('uniformMatrix2fv', 'u_my2x2_mat`, ...);


    Type parameters

    Parameters

    • uniformType: TUniformType
    • name: string
    • rest...value: RemoveFirstFromTuple<Parameters<WebGLRenderingContext[TUniformType]>>

    Returns void

setUniformBoolean

  • setUniformBoolean(name: string, value: boolean): void
  • Set a boolean uniform for the current shader

    Important Must call ex.Shader.use() before setting a uniform!


    Parameters

    • name: string
    • value: boolean

    Returns void

setUniformFloat

  • setUniformFloat(name: string, value: number): void
  • Set a float uniform for the current shader

    Important Must call ex.Shader.use() before setting a uniform!


    Parameters

    • name: string
    • value: number

    Returns void

setUniformFloatArray

  • setUniformFloatArray(name: string, value: number[]): void
  • Set a float array uniform for the current shader

    Important Must call ex.Shader.use() before setting a uniform!


    Parameters

    • name: string
    • value: number[]

    Returns void

setUniformFloatColor

  • setUniformFloatColor(name: string, value: Color): void
  • Set a [[Color]] uniform for the current shader

    Important Must call ex.Shader.use() before setting a uniform!


    Parameters

    Returns void

setUniformFloatVector

  • setUniformFloatVector(name: string, value: Vector): void
  • Set a [[Vector]] uniform for the current shader

    Important Must call ex.Shader.use() before setting a uniform!


    Parameters

    Returns void

setUniformInt

  • setUniformInt(name: string, value: number): void
  • Set an integer uniform for the current shader

    Important Must call ex.Shader.use() before setting a uniform!


    Parameters

    • name: string
    • value: number

    Returns void

setUniformIntArray

  • setUniformIntArray(name: string, value: number[]): void
  • Set an integer array uniform for the current shader

    Important Must call ex.Shader.use() before setting a uniform!


    Parameters

    • name: string
    • value: number[]

    Returns void

setUniformMatrix

  • setUniformMatrix(name: string, value: Matrix): void
  • Set an [[Matrix]] uniform for the current shader

    Important Must call ex.Shader.use() before setting a uniform!


    Parameters

    Returns void

trySetUniform

  • trySetUniform<TUniformType>(uniformType: TUniformType, name: string, ...value: RemoveFirstFromTuple<Parameters<WebGLRenderingContext[TUniformType]>>): boolean
  • Set any available uniform type in webgl. Will try to set the uniform, will return false if the uniform didn't exist, true if it was set.

    WILL NOT THROW on error

    For example setUniform('uniformMatrix2fv', 'u_my2x2_mat`, ...);


    Type parameters

    Parameters

    • uniformType: TUniformType
    • name: string
    • rest...value: RemoveFirstFromTuple<Parameters<WebGLRenderingContext[TUniformType]>>

    Returns boolean

trySetUniformBoolean

  • trySetUniformBoolean(name: string, value: boolean): boolean
  • Set a boolean uniform for the current shader, WILL NOT THROW on error.

    Important Must call ex.Shader.use() before setting a uniform!


    Parameters

    • name: string
    • value: boolean

    Returns boolean

trySetUniformFloat

  • trySetUniformFloat(name: string, value: number): boolean
  • Set a float uniform for the current shader, WILL NOT THROW on error.

    Important Must call ex.Shader.use() before setting a uniform!


    Parameters

    • name: string
    • value: number

    Returns boolean

trySetUniformFloatArray

  • trySetUniformFloatArray(name: string, value: number[]): boolean
  • Set a float array uniform for the current shader, WILL NOT THROW on error.

    Important Must call ex.Shader.use() before setting a uniform!


    Parameters

    • name: string
    • value: number[]

    Returns boolean

trySetUniformFloatColor

  • trySetUniformFloatColor(name: string, value: Color): boolean
  • Set a [[Color]] uniform for the current shader, WILL NOT THROW on error.

    Important Must call ex.Shader.use() before setting a uniform!


    Parameters

    Returns boolean

trySetUniformFloatVector

  • trySetUniformFloatVector(name: string, value: Vector): boolean
  • Set a [[Vector]] uniform for the current shader, WILL NOT THROW on error.

    Important Must call ex.Shader.use() before setting a uniform!


    Parameters

    Returns boolean

trySetUniformInt

  • trySetUniformInt(name: string, value: number): boolean
  • Set an integer uniform for the current shader, WILL NOT THROW on error.

    Important Must call ex.Shader.use() before setting a uniform!


    Parameters

    • name: string
    • value: number

    Returns boolean

trySetUniformIntArray

  • trySetUniformIntArray(name: string, value: number[]): boolean
  • Set an integer array uniform for the current shader, WILL NOT THROW on error.

    Important Must call ex.Shader.use() before setting a uniform!


    Parameters

    • name: string
    • value: number[]

    Returns boolean

trySetUniformMatrix

  • trySetUniformMatrix(name: string, value: Matrix): boolean
  • Set an [[Matrix]] uniform for the current shader, WILL NOT THROW on error.

    Important Must call ex.Shader.use() before setting a uniform!


    Parameters

    Returns boolean

use

  • use(): void
  • Binds the shader program


    Returns void