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 filterObject 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()
-
Gets fragment shader source code. Must be overridden in derived classes for custom shading.
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 namestring 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 namestring Name of filter to remove
Fires:
-
setMode(mode)
-
Sets the current shader mode.
Parameters:
Name Type Description modestring 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 sizeArray.<number> [width, height] of tile in pixels
Fires:
-
setUniform(name, value)
-
Sets a uniform variable value.
Parameters:
Name Type Description namestring Uniform variable name
valuenumber | 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 glWebGL2RenderingContext WebGL2 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 idnumber Unique identifier for the sampler
namestring Sampler variable name in shader program (e.g., "kd" for diffuse texture)
labelstring Display label for UI/menus
samplersArray.<Object> Array of raster definitions
samplers[].idnumber Raster identifier
samplers[].typestring Raster type (e.g., 'color', 'normal')
samplers[].bindboolean <optional>
true Whether sampler should be bound in prepareGL
samplers[].loadboolean <optional>
true Whether sampler should load from raster
uniformsArray.<Object> Shader uniform variables
uniforms[].typestring Data type ('vec4'|'vec3'|'vec2'|'float'|'int')
uniforms[].needsUpdateboolean Whether uniform needs GPU update
uniforms[].valuenumber Uniform value or array of values