Brush engine standard procedures

Color computation

vec3 getStandardColor(vec2 uv, float alpha)


This procedure calculates the color of the buffer, taking into account the brush parameters (color, hardness, opacity and all other parameters). the calculated color is not pre-multiplied, the red, green, blue components are given in the return variable vec3.


Note on the absorption of the color present on the layer by the brush. The absorption mechanism works by taking a regular sample of the color of the layer at the position of the brush marks and using the absorption rate of the brush. This step is not done in the shader of the brush engine but in a shader dedicated to this which is executed upstream. However, this sample is available in the shader of the brush engine with the texture variable f_colorTexture.

Blending computation

vec4 getStandardComposition(vec3 sourceColor, float alpha)

This procedure calculates the brush composition according to the SVG standard specifications (available at https://www.w3.org/TR/SVGCompositing/). The source color before composition must be provided in the non-pre-multiplied sourceColor variable and the transparency of the fragment in the alpha variable.

Transparency computation

float getStandardAlpha(vec2 uv)


this procedure calculates the standard transparency of the fragment taking into account brush parameters such as shape, brush texture, or brush hardness. The uv variable must contain the buffer's texture coordinates, (provided by v_texCoords0).

Selection mask

float getStandardClipping(float alpha)


This procedure calculates the restriction to the selection buffer from the input transparency: if the fragment is contained in the selection area, the transparency is returned otherwise the returned transparency is zero.


Effects standard procedures

bool inRect(float x, float y)


This procedure tests the inclusion of coordinates in the painted rectangle. If coordinates are included returns true, otherwise false. The x and y coordinates must be provided in the canvas coordinate system.


To calculate these coordinates from texture coordinates, apply the following formulas:


float x = (v_texCoords0.x * f_textureSize + f_texturePos.x - f_paintedRectPos.x) / f_paintedRectWidth;

float y = (v_texCoords0.y * f_textureSize + f_texturePos.y - f_paintedRectPos.y) / f_paintedRectHeight;