Custom

Use Custom to create a custom node using GLSL code.

Inputs and Controls

Connection Type

Connection Name

Function

Input

src0

The image to apply the custom effects to.

Control (UI)

Knob (Scripting)

Default Value

Function

Type name

TypeName

Custom

The node type.

Enabled Enabled ticked If unchecked, this node will be omitted from the compiled image processing graph. Any incoming connections will be forwarded to the first output port, if any.
Label Label N/A An optional label to display on the node.
Parameters

Reset parameters to default value using the reset icon:

Source code SourceCode void main() { dst0 = src0(); } The GLSL source code used by the shader.
Input ports InputPorts 1 The number of input ports required by the node. An input can be accessed in the custom shader source using srcX(, where X is the zero-based index of the input.
Output ports OutputPorts 1 The number of output ports required by the node. An output can be accessed in the custom shader source using dstX0, where X is the zero-based index of the output.

Custom Node Examples

The Custom node uses standard GLSL with particular naming conventions for getting and setting pixels. The number of inputs or outputs can be set via the Custom node parameters.

The main components used in the Custom node script are:

src0() - vec4 pixel access to the first input. src1() would be the second input, etc.

dst0 - vec4 container for setting the first output. dst1 would be the second output etc.

offset_src0(vec2 offset) - vec4 pixel access to the first input with a user described pixel offset. e.g. the offset parameters could be vec2(1,1) to get the pixel offset of one on both the x and y uv coordinates. src0 here can be replaced by any other input name.

absolute_src0(vec2 uv) - vec4 pixel access to uv coordinates within the texture. src0 here can be replaced by any other input name.

size_src0() -Fetch vec2 size of src0 texture. size_src0().x or size_src0().y could then be used to get width and height. src0 here can be replaced by any other input name.

The following are simple examples of how you can use the Custom node:

Grayscale

One input, one output:

void main()

{

float average = src0().x + src0().y + src0().z / 3.0;

dst0 = vec4(average, average, average, src0().w);

}

Average of two images

Two inputs, one output:

void main()

{

dst0 = (src0() + src1()) / 2;

}

Sobel edge detection

One input, one output, uv offset access:

float intensity(vec4 color){

return sqrt((color.x*color.x)+(color.y*color.y)+(color.z*color.z));

}

void main()

{

int stepx = 1;

int stepy = 1;

float topLeft = intensity(offset_src0(vec2(-stepx, stepy)));

float left = intensity(offset_src0(vec2(-stepx, 0)));

float bottomLeft = intensity(offset_src0(vec2(-stepx, -stepy)));

float top = intensity(offset_src0(vec2(0, stepy)));

float bottom = intensity(offset_src0(vec2(0, -stepy)));

float topRight = intensity(offset_src0(vec2(stepx, stepy)));

float right = intensity(offset_src0(vec2(stepx, 0)));

float bottomRight = intensity(offset_src0(vec2(stepx, -stepy)));

float x = topLeft + 2.0 * left + bottomLeft - topRight - 2.0 * right - bottomRight;

float y = -topLeft - 2.0 * top - topRight + bottomLeft + 2.0 * bottom + bottomRight;

float colour = sqrt(x*x + y*y);

dst0 = vec4(colour, colour, colour, 1.0);

}