new Shader( [options])
Creates a new Shader instance.
Parameters:
Name | Type | Argument | Description | |||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
Configuration options Properties
|
Fires:
Methods
-
addFilter(filter)
-
Adds a filter to the shader pipeline.
Parameters:
Name Type Description filter
Object Filter to add
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.
Returns:
Combined uniform variables
- Type
- Object.<string, Object>
-
clearFilters()
-
Clears all filters from the shader pipeline.
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
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
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
Fires:
-
setMode(mode)
-
Sets the current shader mode.
Parameters:
Name Type Description mode
string Mode identifier (must be in options.modes)
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
-
setUniform(name, value)
-
Sets a uniform variable value.
Parameters:
Name Type Description name
string Uniform variable name
value
number | boolean | Array Value to set
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
Returns:
Vertex shader source code
- Type
- string
Type Definitions
-
Sampler
-
A reference to a 2D texture used in the shader.
Type:
- Object
- Source:
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