Color blending functions in VEX

calendar_today

28.11.2022

label

VEX, Texturing

mouse

Houdini 19.5

Description

Functions for blending colors and image layers.

1 Functions

Functions for blending two color vectors 'target' and 'blend'. Original code by ridhojeftha: https://www.shadertoy.com/view/4tSGWV

CPP
        //Darken
vector darken(vector target, blend){
    return min(target, blend);   
}

//Multiply
vector multiply(vector target, blend){
    return target * blend;
}

//Color Burn
vector color_burn(vector target, blend){
    return 1.0 - (1.0 - target)/ blend;
}

//Linear Burn
vector linear_burn(vector target, blend){
    return target + blend - 1.0;
}

//Lighten
vector lighten(vector target, blend){
    return max (target, blend);
}

//Screen
vector screen(vector target, blend){
    return 1.0 - (1.0 - target) * (1.0 - blend);
}

//Color Dodge
vector color_dodge(vector target, blend){
    return target / (1.0 - blend);
}

//Linear Dodge
vector linear_dodge(vector target, blend){
    return target + blend;
}

//Overlay
vector overlay(vector target, blend){
    vector temp;
    temp.x = (target.x > 0.5) ? (1.0-(1.0-2.0*(target.x-0.5))*(1.0-blend.x)) : (2.0*target.x)*blend.x;
    temp.y = (target.y > 0.5) ? (1.0-(1.0-2.0*(target.y-0.5))*(1.0-blend.y)) : (2.0*target.y)*blend.y;
    temp.z = (target.z > 0.5) ? (1.0-(1.0-2.0*(target.z-0.5))*(1.0-blend.z)) : (2.0*target.z)*blend.z;
    return temp;
}

//Soft Light
vector soft_light(vector target, blend){
    vector temp;
    temp.x = (blend.x > 0.5) ? (1.0-(1.0-target.x)*(1.0-(blend.x-0.5))) : (target.x * (blend.x + 0.5));
    temp.y = (blend.y > 0.5) ? (1.0-(1.0-target.y)*(1.0-(blend.y-0.5))) : (target.y * (blend.y + 0.5));
    temp.z = (blend.z > 0.5) ? (1.0-(1.0-target.z)*(1.0-(blend.z-0.5))) : (target.z * (blend.z + 0.5));
    return temp;   
}

//Hard Light
vector hard_light(vector target, blend){
    vector temp;
    temp.x = (blend.x > 0.5) ? (1.0-(1.0-target.x)*(1.0-2.0*(blend.x-0.5))) : (target.x * (2.0*blend.x));
    temp.y = (blend.y > 0.5) ? (1.0-(1.0-target.y)*(1.0-2.0*(blend.y-0.5))) : (target.y * (2.0*blend.y));
    temp.z = (blend.z > 0.5) ? (1.0-(1.0-target.z)*(1.0-2.0*(blend.z-0.5))) : (target.z * (2.0*blend.z));
    return temp;
}

//Vivid Light
vector vivid_light(vector target, blend){
    vector temp;
    temp.x = (blend.x > 0.5) ? (1.0-(1.0-target.x)/(2.0*(blend.x-0.5))) : (target.x / (1.0-2.0*blend.x));
    temp.y = (blend.y > 0.5) ? (1.0-(1.0-target.y)/(2.0*(blend.y-0.5))) : (target.y / (1.0-2.0*blend.y));
    temp.z = (blend.z > 0.5) ? (1.0-(1.0-target.z)/(2.0*(blend.z-0.5))) : (target.z / (1.0-2.0*blend.z));
    return temp;
}

//Linear Light
vector linear_light(vector target, blend){
    vector temp;
    temp.x = (blend.x > 0.5) ? (target.x)+(2.0*(blend.x-0.5)) : (target.x +(2.0*blend.x-1.0));
    temp.y = (blend.y > 0.5) ? (target.y)+(2.0*(blend.y-0.5)) : (target.y +(2.0*blend.y-1.0));
    temp.z = (blend.z > 0.5) ? (target.z)+(2.0*(blend.z-0.5)) : (target.z +(2.0*blend.z-1.0));
    return temp;
}

//Pin Light
vector pin_light(vector target, blend){
    vector temp;
    temp.x = (blend.x > 0.5) ? (max (target.x, 2.0*(blend.x-0.5))) : (min(target.x, 2.0*blend.x));
    temp.y = (blend.y > 0.5) ? (max (target.y, 2.0*(blend.y-0.5))) : (min(target.y, 2.0*blend.y));
    temp.z = (blend.z > 0.5) ? (max (target.z, 2.0*(blend.z-0.5))) : (min(target.z, 2.0*blend.z));
    return temp;
}

//Difference
vector difference(vector target, blend){
    return abs(target - blend);  
}

//Exclusion
vector exclusion(vector target, blend){
    return 0.5 - 2.0*(target-0.5)*(blend-0.5);
}

//Subtract
vector subtract(vector target, blend){
    return target - blend;
}

//Divide
vector divide(vector target, blend){
    return target / blend;   
}
    
download

Downloads

link

Related articles

favorite

354

label

VEX

Attribute to match across inputs

favorite

238

label

VEX

Sphere Packing / Dart Throwing Algorithm

favorite

266

label

VEX

Deintersecting spheres with Voronoi

favorite

299

label

VEX

Fitting Planes to Point Clouds

favorite

307

label

VEX

How to Analyze VEX Code

favorite

143

label

VEX

Monte Carlo Geometry Processing