Class: Shader

Shader

Shader module provides WebGL shader program management for OpenLIME. Supports both WebGL 1.0 and 2.0/3.0 GLSL specifications with automatic version detection.

Shader class manages WebGL shader programs. Features:

  • GLSL/ES 2.0 and 3.0 support
  • Automatic uniform management
  • Multiple shader modes
  • Filter pipeline
  • Automatic version selection

new Shader( [options])

Creates a new Shader instance.

Parameters:
Name Type Argument Description
options Object <optional>

Configuration options

Properties
Name Type Argument Default Description
samplers Array.<Shader~Sampler> <optional>
[]

Texture sampler definitions

uniforms Object.<string, Object> <optional>
{}

Shader uniform variables

label string <optional>
null

Display label for the shader

modes Array.<string> <optional>
[]

Available shader modes

version number <optional>
100

GLSL version (100 for WebGL1, 300 for WebGL2)

debug boolean <optional>
false

Enable debug output

Source:
Fires:

Methods


addFilter(filter)

Adds a filter to the shader pipeline.

Parameters:
Name Type Description
filter Object

Filter to add

Source:
Fires:

allUniforms()

Returns all uniform variables associated with the shader and its filters. Combines uniforms from both the base shader and all active filters into a single object.

Source:
Returns:

Combined uniform variables

Type
Object.<string, Object>

clearFilters()

Clears all filters from the shader pipeline.

Source:
Fires:

<abstract> fragShaderSrc(gl)

Gets fragment shader source code. Must be overridden in derived classes for custom shading.

Parameters:
Name Type Description
gl WebGLRenderingContext

WebGL context

Source:
Returns:

Fragment shader source code

Type
string

getUniform(name)

Gets a uniform variable by name. Searches both shader uniforms and filter uniforms.

Parameters:
Name Type Description
name string

Uniform variable name

Source:
Returns:

Uniform object if found

Type
Object | undefined

removeFilter(name)

Removes a filter from the pipeline by name.

Parameters:
Name Type Description
name string

Name of filter to remove

Source:
Fires:

setMode(mode)

Sets the current shader mode.

Parameters:
Name Type Description
mode string

Mode identifier (must be in options.modes)

Source:
Throws:

If mode is not recognized

Type
Error

setTileSize(size)

Sets tile dimensions for shader calculations.

Parameters:
Name Type Description
size Array.<number>

[width, height] of tile

Source:

setUniform(name, value)

Sets a uniform variable value.

Parameters:
Name Type Description
name string

Uniform variable name

value number | boolean | Array

Value to set

Source:
Fires:
Throws:

If uniform doesn't exist

Type
Error

vertShaderSrc(gl)

Gets vertex shader source code. Default implementation provides basic vertex transformation and texture coordinate passing.

Parameters:
Name Type Description
gl WebGLRenderingContext

WebGL context

Source:
Returns:

Vertex shader source code

Type
string

Type Definitions


Sampler

A reference to a 2D texture used in the shader.

Type:
  • Object
Properties:
Name Type Argument Default Description
id number

Unique identifier for the sampler

name string

Sampler variable name in shader program (e.g., "kd" for diffuse texture)

label string

Display label for UI/menus

samplers Array.<Object>

Array of raster definitions

samplers[].id number

Raster identifier

samplers[].type string

Raster type (e.g., 'color', 'normal')

samplers[].bind boolean <optional>
true

Whether sampler should be bound in prepareGL

samplers[].load boolean <optional>
true

Whether sampler should load from raster

uniforms Array.<Object>

Shader uniform variables

uniforms[].type string

Data type ('vec4'|'vec3'|'vec2'|'float'|'int')

uniforms[].needsUpdate boolean

Whether uniform needs GPU update

uniforms[].value number

Uniform value or array of values

Source:

Events


update

Fired when shader state changes (uniforms, filters, etc).

Source: