Vuo  2.3.2
Functions
VuoImageBlend.c File Reference

Description

VuoImageBlend implementation.

Definition in file VuoImageBlend.c.

Go to the source code of this file.

Functions

VuoImageBlend VuoImageBlend_make (VuoBlendMode blendMode)
 Creates state data for the image Blendr. More...
 
VuoImage VuoImageBlend_blend (VuoImageBlend blend, VuoImage background, VuoImage foreground, VuoReal foregroundOpacity, VuoBoolean replaceOpacity)
 Blends multiple images together into a single image. More...
 
#define FilterSource   "\ \n#include \"VuoGlslAlpha.glsl\"\ uniform sampler2D background;\ uniform sampler2D foreground;\ uniform float foregroundOpacity;\ uniform bool replaceOpacity;\ varying vec2 fragmentTextureCoordinate;\ \ float BlendLinearDodgef(float base, float blend) { return min(base + blend, 1.0); }\ float BlendLinearBurnf(float base, float blend) { return max(base + blend - 1.0, 0.0); }\ float BlendDividef(float base, float blend) { return (blend == 0.0) ? blend : base/blend; }\ \ float BlendLightenf(float base, float blend) { return max(blend, base); }\ float BlendDarkenf(float base, float blend) { return min(blend, base); }\ float BlendLinearLightf(float base, float blend) { return (blend < 0.5 ? BlendLinearBurnf(base, (2.0 * blend)) : BlendLinearDodgef(base, (2.0 * (blend - 0.5)))); }\ \ float BlendScreenf(float base, float blend) { return (1.0 - ((1.0 - base) * (1.0 - blend))); }\ float BlendOverlayf(float base, float blend) { return (base < 0.5 ? (2.0 * base * blend) : (1.0 - 2.0 * (1.0 - base) * (1.0 - blend))); }\ float BlendSoftLightf(float base, float blend) { return ((blend < 0.5) ? (2.0 * base * blend + base * base * (1.0 - 2.0 * blend)) : (sqrt(base) * (2.0 * blend - 1.0) + 2.0 * base * (1.0 - blend))); }\ float BlendHardLightf(float base, float blend) { return BlendOverlayf(blend, base); }\ float BlendColorDodgef(float base, float blend) { return ((blend == 1.0) ? blend : min(base / (1.0 - blend), 1.0)); }\ float BlendColorBurnf(float base, float blend) { return (blend == 0.0) ? blend : max((1.0 - ((1.0 - base) / blend)), 0.0); }\ \ float BlendVividLightf(float base, float blend) { return ((blend < 0.5) ? BlendColorBurnf(base, (2.0 * blend)) : BlendColorDodgef(base, (2.0 * (blend - 0.5)))); }\ float BlendPinLightf(float base, float blend) { return ((blend < 0.5) ? BlendDarkenf(base, (2.0 * blend)) : BlendLightenf(base, (2.0 *(blend - 0.5)))); }\ float BlendHardMixf(float base, float blend) { return ((BlendVividLightf(base, blend) < 0.5) ? 0.0 : 1.0); }\ \ \n#include \"VuoGlslHsl.glsl\"\ \ vec3 blendColors(vec4 bg, vec4 fg);\ \ void main() \ { \ vec4 backgroundColor = VuoGlsl_sample(background, fragmentTextureCoordinate); \ backgroundColor.rgb /= backgroundColor.a > 0. ? backgroundColor.a : 1.; \ vec4 foregroundColor = VuoGlsl_sample(foreground, fragmentTextureCoordinate); \ foregroundColor.rgb /= foregroundColor.a > 0. ? foregroundColor.a : 1.; \ foregroundColor.a *= foregroundOpacity; \ \ vec3 blendedColors = clamp(blendColors(backgroundColor, foregroundColor), 0., 1.); \ if (replaceOpacity) \ blendedColors = mix(foregroundColor.rgb, blendedColors, backgroundColor.a); \ \ vec4 mixed = replaceOpacity \ ? vec4(blendedColors*foregroundColor.a + backgroundColor.rgb*backgroundColor.a*(1.-foregroundColor.a), \ foregroundColor.a + backgroundColor.a*(1.-foregroundColor.a)) \ : vec4(blendedColors*foregroundColor.a*backgroundColor.a + backgroundColor.rgb*backgroundColor.a*(1.-foregroundColor.a), \ backgroundColor.a); \ \ gl_FragColor = mixed; \ } \ "
 
#define BLEND_FILTERS(source)   "#version 120\n" FilterSource "\n" #source
 
static const char * fragmentShaderSource_blendNormal
 
static const char * fragmentShaderSource_blendMultiply
 
static const char * fragmentShaderSource_blendLinearDodge
 
static const char * fragmentShaderSource_blendDarkerComponent
 
static const char * fragmentShaderSource_blendDarkerColor
 
static const char * fragmentShaderSource_blendLighterComponent
 
static const char * fragmentShaderSource_blendLighterColor
 
static const char * fragmentShaderSource_blendLinearBurn
 
static const char * fragmentShaderSource_blendColorBurn
 
static const char * fragmentShaderSource_blendColorDodge
 
static const char * fragmentShaderSource_blendScreen
 
static const char * fragmentShaderSource_blendOverlay
 
static const char * fragmentShaderSource_blendSoftLight
 
static const char * fragmentShaderSource_blendHardLight
 
static const char * fragmentShaderSource_blendVividLight
 
static const char * fragmentShaderSource_blendLinearLight
 
static const char * fragmentShaderSource_blendPinLight
 
static const char * fragmentShaderSource_blendHardMix
 
static const char * fragmentShaderSource_blendDifference
 
static const char * fragmentShaderSource_blendExclusion
 
static const char * fragmentShaderSource_blendSubtract
 
static const char * fragmentShaderSource_blendDivide
 
static const char * fragmentShaderSource_blendHue
 
static const char * fragmentShaderSource_blendSaturation
 
static const char * fragmentShaderSource_blendColor
 
static const char * fragmentShaderSource_blendLuminosity
 
static const char * fragmentShaderSource_blendPower
 

Macro Definition Documentation

◆ BLEND_FILTERS

#define BLEND_FILTERS (   source)    "#version 120\n" FilterSource "\n" #source

Source code for GLSL blend modes.

Definition at line 81 of file VuoImageBlend.c.

◆ FilterSource

#define FilterSource   "\ \n#include \"VuoGlslAlpha.glsl\"\ uniform sampler2D background;\ uniform sampler2D foreground;\ uniform float foregroundOpacity;\ uniform bool replaceOpacity;\ varying vec2 fragmentTextureCoordinate;\ \ float BlendLinearDodgef(float base, float blend) { return min(base + blend, 1.0); }\ float BlendLinearBurnf(float base, float blend) { return max(base + blend - 1.0, 0.0); }\ float BlendDividef(float base, float blend) { return (blend == 0.0) ? blend : base/blend; }\ \ float BlendLightenf(float base, float blend) { return max(blend, base); }\ float BlendDarkenf(float base, float blend) { return min(blend, base); }\ float BlendLinearLightf(float base, float blend) { return (blend < 0.5 ? BlendLinearBurnf(base, (2.0 * blend)) : BlendLinearDodgef(base, (2.0 * (blend - 0.5)))); }\ \ float BlendScreenf(float base, float blend) { return (1.0 - ((1.0 - base) * (1.0 - blend))); }\ float BlendOverlayf(float base, float blend) { return (base < 0.5 ? (2.0 * base * blend) : (1.0 - 2.0 * (1.0 - base) * (1.0 - blend))); }\ float BlendSoftLightf(float base, float blend) { return ((blend < 0.5) ? (2.0 * base * blend + base * base * (1.0 - 2.0 * blend)) : (sqrt(base) * (2.0 * blend - 1.0) + 2.0 * base * (1.0 - blend))); }\ float BlendHardLightf(float base, float blend) { return BlendOverlayf(blend, base); }\ float BlendColorDodgef(float base, float blend) { return ((blend == 1.0) ? blend : min(base / (1.0 - blend), 1.0)); }\ float BlendColorBurnf(float base, float blend) { return (blend == 0.0) ? blend : max((1.0 - ((1.0 - base) / blend)), 0.0); }\ \ float BlendVividLightf(float base, float blend) { return ((blend < 0.5) ? BlendColorBurnf(base, (2.0 * blend)) : BlendColorDodgef(base, (2.0 * (blend - 0.5)))); }\ float BlendPinLightf(float base, float blend) { return ((blend < 0.5) ? BlendDarkenf(base, (2.0 * blend)) : BlendLightenf(base, (2.0 *(blend - 0.5)))); }\ float BlendHardMixf(float base, float blend) { return ((BlendVividLightf(base, blend) < 0.5) ? 0.0 : 1.0); }\ \ \n#include \"VuoGlslHsl.glsl\"\ \ vec3 blendColors(vec4 bg, vec4 fg);\ \ void main() \ { \ vec4 backgroundColor = VuoGlsl_sample(background, fragmentTextureCoordinate); \ backgroundColor.rgb /= backgroundColor.a > 0. ? backgroundColor.a : 1.; \ vec4 foregroundColor = VuoGlsl_sample(foreground, fragmentTextureCoordinate); \ foregroundColor.rgb /= foregroundColor.a > 0. ? foregroundColor.a : 1.; \ foregroundColor.a *= foregroundOpacity; \ \ vec3 blendedColors = clamp(blendColors(backgroundColor, foregroundColor), 0., 1.); \ if (replaceOpacity) \ blendedColors = mix(foregroundColor.rgb, blendedColors, backgroundColor.a); \ \ vec4 mixed = replaceOpacity \ ? vec4(blendedColors*foregroundColor.a + backgroundColor.rgb*backgroundColor.a*(1.-foregroundColor.a), \ foregroundColor.a + backgroundColor.a*(1.-foregroundColor.a)) \ : vec4(blendedColors*foregroundColor.a*backgroundColor.a + backgroundColor.rgb*backgroundColor.a*(1.-foregroundColor.a), \ backgroundColor.a); \ \ gl_FragColor = mixed; \ } \ "

Source code for GLSL blend modes.

Definition at line 28 of file VuoImageBlend.c.

Function Documentation

◆ VuoImageBlend_blend()

VuoImage VuoImageBlend_blend ( VuoImageBlend  blend,
VuoImage  background,
VuoImage  foreground,
VuoReal  foregroundOpacity,
VuoBoolean  replaceOpacity 
)

Blends multiple images together into a single image.

Definition at line 404 of file VuoImageBlend.c.

◆ VuoImageBlend_make()

VuoImageBlend VuoImageBlend_make ( VuoBlendMode  blendMode)

Creates state data for the image Blendr.

Definition at line 304 of file VuoImageBlend.c.

Variable Documentation

◆ fragmentShaderSource_blendColor

const char* fragmentShaderSource_blendColor
static
Initial value:
vec3 blendColors(vec4 bg, vec4 fg)
{
vec3 blendHSL = VuoGlsl_rgbToHsl(fg.rgb);
return VuoGlsl_hslToRgb(vec3(blendHSL.r, blendHSL.g, VuoGlsl_rgbToHsl(bg.rgb).b));
}
)

Source code for GLSL blend modes.

Definition at line 277 of file VuoImageBlend.c.

◆ fragmentShaderSource_blendColorBurn

const char* fragmentShaderSource_blendColorBurn
static
Initial value:
vec3 blendColors(vec4 bg, vec4 fg)
{
return vec3(BlendColorBurnf(bg.r, fg.r),
BlendColorBurnf(bg.g, fg.g),
BlendColorBurnf(bg.b, fg.b));
}
)

Source code for GLSL blend modes.

Definition at line 143 of file VuoImageBlend.c.

◆ fragmentShaderSource_blendColorDodge

const char* fragmentShaderSource_blendColorDodge
static
Initial value:
vec3 blendColors(vec4 bg, vec4 fg)
{
return bg.rgb / (1. - fg.rgb*fg.a);
}
)

Source code for GLSL blend modes.

Definition at line 152 of file VuoImageBlend.c.

◆ fragmentShaderSource_blendDarkerColor

const char* fragmentShaderSource_blendDarkerColor
static
Initial value:
vec3 blendColors(vec4 bg, vec4 fg)
{
float bgLum = VuoGlsl_rgbToHsl(bg.rgb).b;
float fgLum = VuoGlsl_rgbToHsl(fg.rgb).b;
return bgLum < fgLum ? bg.rgb : fg.rgb;
}
)

Source code for GLSL blend modes.

Definition at line 111 of file VuoImageBlend.c.

◆ fragmentShaderSource_blendDarkerComponent

const char* fragmentShaderSource_blendDarkerComponent
static
Initial value:
vec3 blendColors(vec4 bg, vec4 fg)
{
return min(bg.rgb, fg.rgb);
}
)

Source code for GLSL blend modes.

Definition at line 104 of file VuoImageBlend.c.

◆ fragmentShaderSource_blendDifference

const char* fragmentShaderSource_blendDifference
static
Initial value:
vec3 blendColors(vec4 bg, vec4 fg)
{
return abs(bg.rgb - fg.rgb);
}
)

Source code for GLSL blend modes.

Definition at line 231 of file VuoImageBlend.c.

◆ fragmentShaderSource_blendDivide

const char* fragmentShaderSource_blendDivide
static
Initial value:
vec3 blendColors(vec4 bg, vec4 fg)
{
return vec3(BlendDividef(bg.r, fg.r),
BlendDividef(bg.g, fg.g),
BlendDividef(bg.b, fg.b));
}
)

Source code for GLSL blend modes.

Definition at line 252 of file VuoImageBlend.c.

◆ fragmentShaderSource_blendExclusion

const char* fragmentShaderSource_blendExclusion
static
Initial value:
vec3 blendColors(vec4 bg, vec4 fg)
{
return bg.rgb + fg.rgb - 2.*bg.rgb*fg.rgb;
}
)

Source code for GLSL blend modes.

Definition at line 238 of file VuoImageBlend.c.

◆ fragmentShaderSource_blendHardLight

const char* fragmentShaderSource_blendHardLight
static
Initial value:
vec3 blendColors(vec4 bg, vec4 fg)
{
return vec3(BlendHardLightf(bg.r, fg.r),
BlendHardLightf(bg.g, fg.g),
BlendHardLightf(bg.b, fg.b));
}
)

Source code for GLSL blend modes.

Definition at line 186 of file VuoImageBlend.c.

◆ fragmentShaderSource_blendHardMix

const char* fragmentShaderSource_blendHardMix
static
Initial value:
vec3 blendColors(vec4 bg, vec4 fg)
{
return vec3(BlendHardMixf(bg.r, fg.r),
BlendHardMixf(bg.g, fg.g),
BlendHardMixf(bg.b, fg.b));
}
)

Source code for GLSL blend modes.

Definition at line 222 of file VuoImageBlend.c.

◆ fragmentShaderSource_blendHue

const char* fragmentShaderSource_blendHue
static
Initial value:
vec3 blendColors(vec4 bg, vec4 fg)
{
vec3 baseHSL = VuoGlsl_rgbToHsl(bg.rgb);
return VuoGlsl_hslToRgb(vec3(VuoGlsl_rgbToHsl(fg.rgb).r, baseHSL.g, baseHSL.b));
}
)

Source code for GLSL blend modes.

Definition at line 261 of file VuoImageBlend.c.

◆ fragmentShaderSource_blendLighterColor

const char* fragmentShaderSource_blendLighterColor
static
Initial value:
vec3 blendColors(vec4 bg, vec4 fg)
{
float bgLum = VuoGlsl_rgbToHsl(bg.rgb).b;
float fgLum = VuoGlsl_rgbToHsl(fg.rgb).b;
return bgLum > fgLum ? bg.rgb : fg.rgb;
}
)

Source code for GLSL blend modes.

Definition at line 127 of file VuoImageBlend.c.

◆ fragmentShaderSource_blendLighterComponent

const char* fragmentShaderSource_blendLighterComponent
static
Initial value:
vec3 blendColors(vec4 bg, vec4 fg)
{
return max(bg.rgb, fg.rgb);
}
)

Source code for GLSL blend modes.

Definition at line 120 of file VuoImageBlend.c.

◆ fragmentShaderSource_blendLinearBurn

const char* fragmentShaderSource_blendLinearBurn
static
Initial value:
vec3 blendColors(vec4 bg, vec4 fg)
{
return bg.rgb + fg.rgb - 1.;
}
)

Source code for GLSL blend modes.

Definition at line 136 of file VuoImageBlend.c.

◆ fragmentShaderSource_blendLinearDodge

const char* fragmentShaderSource_blendLinearDodge
static
Initial value:
vec3 blendColors(vec4 bg, vec4 fg)
{
return bg.rgb + fg.rgb;
}
)

Source code for GLSL blend modes.

Definition at line 97 of file VuoImageBlend.c.

◆ fragmentShaderSource_blendLinearLight

const char* fragmentShaderSource_blendLinearLight
static
Initial value:
vec3 blendColors(vec4 bg, vec4 fg)
{
return vec3(BlendLinearLightf(bg.r, fg.r),
BlendLinearLightf(bg.g, fg.g),
BlendLinearLightf(bg.b, fg.b));
}
)

Source code for GLSL blend modes.

Definition at line 204 of file VuoImageBlend.c.

◆ fragmentShaderSource_blendLuminosity

const char* fragmentShaderSource_blendLuminosity
static
Initial value:
vec3 blendColors(vec4 bg, vec4 fg)
{
vec3 baseHSL = VuoGlsl_rgbToHsl(bg.rgb);
return VuoGlsl_hslToRgb(vec3(baseHSL.r, baseHSL.g, VuoGlsl_rgbToHsl(fg.rgb).b));
}
)

Source code for GLSL blend modes.

Definition at line 285 of file VuoImageBlend.c.

◆ fragmentShaderSource_blendMultiply

const char* fragmentShaderSource_blendMultiply
static
Initial value:
vec3 blendColors(vec4 bg, vec4 fg)
{
return bg.rgb * fg.rgb;
}
)

Source code for GLSL blend modes.

Definition at line 90 of file VuoImageBlend.c.

◆ fragmentShaderSource_blendNormal

const char* fragmentShaderSource_blendNormal
static
Initial value:
vec3 blendColors(vec4 bg, vec4 fg)
{
return fg.rgb;
}
)

Source code for GLSL blend modes.

Definition at line 83 of file VuoImageBlend.c.

◆ fragmentShaderSource_blendOverlay

const char* fragmentShaderSource_blendOverlay
static
Initial value:
vec3 blendColors(vec4 bg, vec4 fg)
{
return vec3(BlendOverlayf(bg.r, fg.r),
BlendOverlayf(bg.g, fg.g),
BlendOverlayf(bg.b, fg.b));
}
)

Source code for GLSL blend modes.

Definition at line 168 of file VuoImageBlend.c.

◆ fragmentShaderSource_blendPinLight

const char* fragmentShaderSource_blendPinLight
static
Initial value:
vec3 blendColors(vec4 bg, vec4 fg)
{
return vec3(BlendPinLightf(bg.r, fg.r),
BlendPinLightf(bg.g, fg.g),
BlendPinLightf(bg.b, fg.b));
}
)

Source code for GLSL blend modes.

Definition at line 213 of file VuoImageBlend.c.

◆ fragmentShaderSource_blendPower

const char* fragmentShaderSource_blendPower
static
Initial value:
vec3 blendColors(vec4 bg, vec4 fg)
{
return pow(bg.rgb, fg.rgb);
}
)

Source code for GLSL blend modes.

Definition at line 293 of file VuoImageBlend.c.

◆ fragmentShaderSource_blendSaturation

const char* fragmentShaderSource_blendSaturation
static
Initial value:
vec3 blendColors(vec4 bg, vec4 fg)
{
vec3 baseHSL = VuoGlsl_rgbToHsl(bg.rgb);
return VuoGlsl_hslToRgb(vec3(baseHSL.r, VuoGlsl_rgbToHsl(fg.rgb).g, baseHSL.b));
}
)

Source code for GLSL blend modes.

Definition at line 269 of file VuoImageBlend.c.

◆ fragmentShaderSource_blendScreen

const char* fragmentShaderSource_blendScreen
static
Initial value:
vec3 blendColors(vec4 bg, vec4 fg)
{
return vec3(BlendScreenf(bg.r, fg.r),
BlendScreenf(bg.g, fg.g),
BlendScreenf(bg.b, fg.b));
}
)

Source code for GLSL blend modes.

Definition at line 159 of file VuoImageBlend.c.

◆ fragmentShaderSource_blendSoftLight

const char* fragmentShaderSource_blendSoftLight
static
Initial value:
vec3 blendColors(vec4 bg, vec4 fg)
{
return vec3(BlendSoftLightf(bg.r, fg.r),
BlendSoftLightf(bg.g, fg.g),
BlendSoftLightf(bg.b, fg.b));
}
)

Source code for GLSL blend modes.

Definition at line 177 of file VuoImageBlend.c.

◆ fragmentShaderSource_blendSubtract

const char* fragmentShaderSource_blendSubtract
static
Initial value:
vec3 blendColors(vec4 bg, vec4 fg)
{
return bg.rgb - fg.rgb;
}
)

Source code for GLSL blend modes.

Definition at line 245 of file VuoImageBlend.c.

◆ fragmentShaderSource_blendVividLight

const char* fragmentShaderSource_blendVividLight
static
Initial value:
vec3 blendColors(vec4 bg, vec4 fg)
{
return vec3(BlendVividLightf(bg.r, fg.r),
BlendVividLightf(bg.g, fg.g),
BlendVividLightf(bg.b, fg.b));
}
)

Source code for GLSL blend modes.

Definition at line 195 of file VuoImageBlend.c.