LYGIA Shader Library

mixOklab (lygia/color/mixOklab)

Mix function by Inigo Quiles (https://www.shadertoy.com/view/ttcyRS) utilizing Bjorn Ottosso's OkLab color space, which is provide smooth stransitions Learn more about it his article

Dependencies:

Use:

<vec3\vec4> mixOklab(<vec3|vec4> colorA, <vec3|vec4> colorB, float pct)

Check it on Github




#ifndef FNC_MIXOKLAB
#define FNC_MIXOKLAB
vec3 mixOklab( vec3 colA, vec3 colB, float h ) {

    #ifdef MIXOKLAB_SRGB
    colA = srgb2rgb(colA);
    colB = srgb2rgb(colB);
    #endif

    vec3 lmsA = pow( RGB2OKLAB_B * colA, vec3(0.33333) );
    vec3 lmsB = pow( RGB2OKLAB_B * colB, vec3(0.33333) );

    // lerp
    vec3 lms = mix( lmsA, lmsB, h );

    // cone to rgb
    vec3 rgb = OKLAB2RGB_B*(lms*lms*lms);

    #ifdef MIXOKLAB_SRGB
    return rgb2srgb(rgb);
    #else
    return rgb;
    #endif
}

vec4 mixOklab( vec4 colA, vec4 colB, float h ) {
    return vec4( mixOklab(colA.rgb, colB.rgb, h), mix(colA.a, colB.a, h) );
}
#endif

Dependencies:

Use:

<float3\float4> mixOklab(<float3|float4> colorA, <float3|float4> colorB, float pct)

Check it on Github




#ifndef FNC_MIXOKLAB
#define FNC_MIXOKLAB
float3 mixOklab( float3 colA, float3 colB, float h ) {

    #ifdef MIXOKLAB_SRGB
    colA = srgb2rgb(colA);
    colB = srgb2rgb(colB);
    #endif

    float3 lmsA = pow(mul(RGB2OKLAB_B, colA), float3(0.33333, 0.33333, 0.33333));
    float3 lmsB = pow(mul(RGB2OKLAB_B, colB), float3(0.33333, 0.33333, 0.33333));
    float3 lms = lerp( lmsA, lmsB, h );

    // cone to rgb
    float3 rgb = mul(OKLAB2RGB_B, lms*lms*lms);

    #ifdef MIXOKLAB_SRGB
    return rgb2srgb(rgb);
    #else
    return rgb;
    #endif
}

float4 mixOklab( float4 colA, float4 colB, float h ) {
    return float4( mixOklab(colA.rgb, colB.rgb, h), lerp(colA.a, colB.a, h) );
}
#endif

Dependencies:

Use:

<float3\float4> mixOklab(<float3|float4> colorA, <float3|float4> colorB, float pct)

Check it on Github




#ifndef FNC_MIXOKLAB
#define FNC_MIXOKLAB
float3 mixOklab( float3 colA, float3 colB, float h ) {

    #ifdef MIXOKLAB_SRGB
    colA = srgb2rgb(colA);
    colB = srgb2rgb(colB);
    #endif

    float3 lmsA = pow( RGB2OKLAB_B * colA, float3(0.33333) );
    float3 lmsB = pow( RGB2OKLAB_B * colB, float3(0.33333) );

    // lerp
    float3 lms = mix( lmsA, lmsB, h );

    // cone to rgb
    float3 rgb = OKLAB2RGB_B*(lms*lms*lms);

    #ifdef MIXOKLAB_SRGB
    return rgb2srgb(rgb);
    #else
    return rgb;
    #endif
}

float4 mixOklab( float4 colA, float4 colB, float h ) {
    return float4( mixOklab(colA.rgb, colB.rgb, h), mix(colA.a, colB.a, h) );
}
#endif

Dependencies:

Check it on Github






fn mixOklab( colA: vec3f, colB: vec3f, h: f32 ) -> vec3f {

    // rgb to cone (arg of pow can't be negative)
    let lmsA = pow( RGB2OKLAB_B*colA, vec3f(0.33333) );
    let lmsB = pow( RGB2OKLAB_B*colB, vec3f(0.33333) );

    let lms = mix( lmsA, lmsB, h );

    // cone to rgb
    return OKLAB2RGB_B*(lms*lms*lms);
}

Examples

Licenses

LYGIA is dual-licensed under the Prosperity License and the Patron License for sponsors and contributors.

Sponsors and contributors are automatically added to the Patron License and they can ignore the any non-commercial rule of the Prosperity Licensed software (please take a look to the exception).

It's also possible to get a permanent comercial license hook to a single and specific version of LYGIA.

Get the latest news and releases

Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository