Constructor
(abstract) new VisualizationLayer(id, privateOptions)
Global supported options
Parameters:
Name | Type | Description |
---|---|---|
id |
string | unique ID among all webgl instances and shaders |
privateOptions |
object | options that should not be touched, necessary for linking the layer to the core |
Members
customParams :any
Declare custom parameters for documentation purposes.
Can set default values to provide sensible defaults.
Requires only 'usage' parameter describing the use.
Unlike controls, these values are not processed in any way.
Of course you don't have to define your custom parameters,
but then these won't be documented in any nice way. Note that
the value can be an object, or a different value (e.g., an array)
{
customParamId: {
default: {myItem: 1, myValue: "string" ...}, [OPTIONAL]
usage: "This parameter can be used like this and that.",
required: {type: <> ...} [OPTIONAL]
}, ...
}
Type:
anydefaultControls :object
Declare supported controls by a particular shader
each controls is automatically created for the shader
and this[controlId] instance set
structure:
{
controlId: {
default: {type: <>, title: <>, interactive: true|false...},
accepts: (type, instance) => <>,
required: {type: <> ...} [OPTIONAL]
}, ...
}
use [controlId]: false to disable a specific control (e.g. all shaders
support opacity by default - use to remove this feature)
Additionally, use_[...] value can be specified, such controls enable shader
to specify default or required values for built-in use_[...] params. example:
{
use_channel0: {
default: "bg"
},
use_channel1: {
required: "rg"
},
use_gamma: {
default: 0.5
}
}
reads by default for texture 1 channels 'bg', second texture is always forced to read 'rg',
textures apply gamma filter with 0.5 by default if not overridden
todo: allow also custom object without structure being specified (use in custom manner,
but limited in automated docs --> require field that summarises its usage)
Type:
objectfilterNames :Object
Available filters (use_[name])
Type:
Objectmode
Get the mode we operate in
modes :Object
Available use_mode modes
Type:
ObjecttexturesCount
Returns number of textures available to this shader
Methods
addControl(name, controlOptions, buildContext)
Parameters:
Name | Type | Description |
---|---|---|
name |
the control named ID which will be attached to the control | |
controlOptions |
object | control options defined by the underlying control, must have at least 'type' property |
buildContext |
object | item with the same properties as static.defaultControls |
construct(options, dataReferences)
Manual constructor, must call super.construct(...) if overridden, but unlike
constructor the call can be adjusted (e.g. adjust option values)
Parameters:
Name | Type | Description |
---|---|---|
options |
WebGLModule.ShaderLayerParams | options.use_channel[X]: "r", "g" or "b" channel to sample index X, default "r" options.use_mode: blending mode - default alpha ("show"), custom blending ("mask") and clipping mask blend ("mask_clip") options.use_[*]: filtering, gamma/exposure/logscale with a float filter parameter (e.g. "use_gamma" : 1.5) |
dataReferences |
Array.<number> | indexes of data being requested for this shader |
dataSourcesCount() → {number}
For error detection, how many textures are available
Returns:
number of textures available
filter(value) → {string}
Apply global filters on value
Parameters:
Name | Type | Description |
---|---|---|
value |
string | GLSL code string, value to filter |
Returns:
filtered value (GLSL oneliner without ';')
getFilterValue(filter, defaultValue) → {string}
Get the filter value (alias for loadProperty(...)
Parameters:
Name | Type | Description |
---|---|---|
filter |
string | filter to read the value of |
defaultValue |
string |
Returns:
stored filter value or defaultValue if no value available
getFragmentShaderDefinition() → {string}
Code placed outside fragment shader's main(...).
By default, it includes all definitions of
controls you defined in defaultControls
NOTE THAT ANY VARIABLE NAME
WITHIN THE GLOBAL SPACE MUST BE
ESCAPED WITH UNIQUE ID: this.uid
DO NOT SAMPLE TEXTURE MANUALLY: use this.sampleChannel(...) to generate the code
WHEN OVERRIDING, INCLUDE THE OUTPUT OF THIS METHOD AT THE BEGINNING OF THE NEW OUTPUT.
Returns:
getFragmentShaderExecution() → {string}
Code executed to create the output color. The code
must always return a vec4 value, otherwise the visualization
will fail to compile (this code actually runs inside a vec4 function).
DO NOT SAMPLE TEXTURE MANUALLY: use this.sampleChannel(...) to generate the code
Returns:
glDrawing(program, dimension, gl)
Called when an image is rendered
Parameters:
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
program |
WebGLProgram | WebglProgram instance | |||||||||
dimension |
object | canvas dimension
Properties
|
|||||||||
gl |
WebGLRenderingContext | WebGL2RenderingContext |
glLoaded(program, gl)
Called when associated webgl program is switched to
Parameters:
Name | Type | Description |
---|---|---|
program |
WebGLProgram | WebglProgram instance |
gl |
WebGLRenderingContext | WebGL2RenderingContext | WebGL Context |
htmlControls() → {string}
Get the shader UI controls
Returns:
HTML controls for the particular shader
includeGlobalCode(key, code)
Include GLSL shader code on global scope
(e.g. define function that is repeatedly used)
does not have to use unique ID extended names as this code is included only once
Parameters:
Name | Type | Description |
---|---|---|
key |
string | a key under which is the code stored, so that the same key is not loaded twice |
code |
string | GLSL code to add to the shader |
init()
This function is called once at
the beginning of the layer use
(might be multiple times), after htmlControls()
initialized() → {boolean}
Check if shader is initialized.
Returns:
isFlag(value) → {boolean}
Evaluates option flag, e.g. any value that indicates boolean 'true'
Parameters:
Name | Type | Description |
---|---|---|
value |
* | value to interpret |
Returns:
true if the value is considered boolean 'true'
loadProperty(name, defaultValue) → {string}
Load value, useful for controls value caching
Parameters:
Name | Type | Description |
---|---|---|
name |
string | value name |
defaultValue |
string | default value if no stored value available |
Returns:
stored value or default value
removeControl(id)
Parameters:
Name | Type | Description |
---|---|---|
id |
control id to delete |
resetChannel(options)
Set sampling channel
Parameters:
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
options |
object |
Properties
|
resetFilters(options)
Can be used to re-set filters for a shader
Parameters:
Name | Type | Description |
---|---|---|
options |
object | filters configuration, currently supported are 'use_gamma', 'use_exposure', 'use_logscale' |
resetMode(options)
Set blending mode
Parameters:
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
options |
object |
Properties
|
sampleChannel(textureCoords, otherDataIndex, raw) → {string}
Sample only one channel (which is defined in options)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
textureCoords |
string | valid GLSL vec2 object as string | |
otherDataIndex |
number | 0 | index of the data in self.dataReference JSON array |
raw |
boolean | false | whether to output raw value from the texture (do not apply filters) |
Returns:
code for appropriate texture sampling within the shader,
where only one channel is extracted or float with zero value if
the reference is not valid
setFilterValue(filter, value)
Set filter value
Parameters:
Name | Type | Description |
---|---|---|
filter |
filter name | |
value |
value of the filter |
storeProperty(name, value)
Store value, useful for controls value caching
Parameters:
Name | Type | Description |
---|---|---|
name |
string | value name |
value |
* | value |
textureSize(index) → {string}
Get texture size
Parameters:
Name | Type | Default | Description |
---|---|---|---|
index |
number | 0 | index of the data in self.dataReference JSON array |
Returns:
vec2 GLSL value with width and height of the texture
toShaderFloatString(value, defaultValue, precisionLen) → {string}
Parses value to a float string representation with given precision (length after decimal)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
value |
number | value to convert | |
defaultValue |
number | default value on failure | |
precisionLen |
number | 5 | number of decimals |
Returns:
(static) description() → {string}
Provide description
Returns:
optional description
(static) name() → {string}
Override **static** name definition
Returns:
name of the shader (user-friendly)
(static) preview()
Default preview image URL getter,
override if your image is not stored in webgl/shaders/[id].png
Remove XOpatModule.ROOT reference if you do not use XOpat API
(static) sources() → {Array.<Object>}
Declare the number of data sources it reads from (how many dataSources indexes should the shader contain)
Returns:
array of source specifications:
acceptsChannelCount: predicate that evaluates whether given number of channels (argument) is acceptable
[optional] description: the description of the source - what it is being used for
(static) toShaderFloatString(value, defaultValue, precisionLen) → {string}
Parses value to a float string representation with given precision (length after decimal)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
value |
number | value to convert | |
defaultValue |
number | default value on failure | |
precisionLen |
number | 5 | number of decimals |
Returns:
(static) type() → {string}
Override **static** type definition
The class must be registered using the type
Returns:
unique id under which is the shader registered