new ShaderLens( [options])
Creates a new lens shader
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
options |
ShaderLens~Options |
<optional> |
Configuration options |
- Source:
Example
```javascript // Create basic lens shader const lens = new ShaderLens({ label: 'MyLens', overlayLayerEnabled: false }); ```
Extends
Methods
-
addFilter(filter)
-
Adds a filter to the shader pipeline.
Parameters:
Name Type Description filter
Object Filter to add
- Inherited From:
- Overrides:
- 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.
- Inherited From:
- Overrides:
- Source:
Returns:
Combined uniform variables
- Type
- Object.<string, Object>
-
clearFilters()
-
Clears all filters from the shader pipeline.
- Inherited From:
- Overrides:
- Source:
Fires:
-
getUniform(name)
-
Gets a uniform variable by name. Searches both shader uniforms and filter uniforms.
Parameters:
Name Type Description name
string Uniform variable name
- Inherited From:
- Overrides:
- 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
- Inherited From:
- Overrides:
- Source:
Fires:
-
setLensUniforms(lensViewportCoords, windowWH, borderColor, borderEnable)
-
Updates lens parameters and appearance
Parameters:
Name Type Description lensViewportCoords
Array.<number> Lens parameters [centerX, centerY, radius, borderWidth]
windowWH
Array.<number> Viewport dimensions [width, height]
borderColor
Array.<number> RGBA border color
borderEnable
boolean Whether to show border
- Source:
-
setMode(mode)
-
Sets the current shader mode.
Parameters:
Name Type Description mode
string Mode identifier (must be in options.modes)
- Inherited From:
- Overrides:
- Source:
Throws:
-
If mode is not recognized
- Type
- Error
-
setOverlayLayerEnabled(enabled)
-
Enables or disables the overlay layer When enabled, adds a second texture layer with grayscale outside lens
Parameters:
Name Type Description enabled
boolean Whether to enable overlay
- Source:
-
setTileSize(size)
-
Sets tile dimensions for shader calculations.
Parameters:
Name Type Description size
Array.<number> [width, height] of tile
- Inherited From:
- Overrides:
- 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
- Inherited From:
- Overrides:
- Source:
Fires:
Throws:
-
If uniform doesn't exist
- Type
- Error
Type Definitions
-
Options
-
Configuration options for lens shader
Type:
- Object
- Source:
Properties:
Name Type Argument Default Description label
string <optional>
'ShaderLens' Display label
overlayLayerEnabled
boolean <optional>
false Enable overlay layer
uniforms
Object <optional>
Custom uniform values
-
Uniforms
-
Uniform definitions for lens shader
Type:
- Object
- Source:
Properties:
Name Type Description u_lens
Array.<number> Lens parameters [centerX, centerY, radius, borderWidth]
u_width_height
Array.<number> Viewport dimensions [width, height]
u_border_color
Array.<number> RGBA border color [r, g, b, a]
u_border_enable
boolean Whether to show lens border
Events
-
update
-
Fired when shader state changes (uniforms, filters, etc).
- Inherited From:
- Overrides:
- Source: