LYGIA Shader Library

colorChecker (lygia/draw/colorChecker)

Draw a color checker (Macbeth or Spyder)

Dependencies:

Use:

colorChecker(<vec2> uv)
colorCheckerMacbeth(<vec2> uv)
colorCheckerSpyder(<vec2> uv)

Check it on Github



#ifndef COLORCHECKER_FNC
#define COLORCHECKER_FNC(UV) colorCheckerMacbeth(UV)
#endif

#ifndef COLOR_CHECKER
#define COLOR_CHECKER

vec4 colorCheckerTile(vec2 uv) {
    vec2 st = scale(uv, vec2(1.0,1.5)) * vec2(6.0, 4.0);
    return vec4(fract(st), floor(st));
}

vec4 colorCheckerMacbeth (vec2 uv) {
    vec4 t = colorCheckerTile(vec2(uv.x, 1.0-uv.y));
    int index = 6 * int(t.w) + int(t.z);
    vec3 color = macbeth(index) * 
                rect(t.xy, 0.8) +
                fill(crossSDF(uv, 2.), .015) + 
                saturate(
                    stroke(rectSDF(uv, vec2(1.015, 0.68)), 1., 0.01) -
                    rect(uv, vec2(.966, 1.)) - rect(uv, vec2(1.1, .63))
                );
    float alpha = rect(uv, vec2(1.03,0.69));
    return vec4(saturate(color) * alpha, alpha);
}

vec4 colorCheckerMacbethXYZ(vec2 uv) {
    vec4 t = colorCheckerTile(vec2(uv.x, 1.0-uv.y));
    int index = 6 * int(t.w) + int(t.z);
    vec3 xyz = macbethXYZ(index) * 
                rect(t.xy, 0.8);
    float alpha = rect(uv, vec2(1.03,0.69));
    return vec4(xyz * alpha, alpha);
}

vec4 colorCheckerMacbethLAB(vec2 uv) {
    vec4 t = colorCheckerTile(vec2(uv.x, 1.0-uv.y));
    int index = 6 * int(t.w) + int(t.z);
    vec3 lab = macbethLAB(index) * 
                rect(t.xy, 0.8);
    float alpha = rect(uv, vec2(1.03,0.69));
    return vec4(lab * alpha, alpha);
}

vec4 colorCheckerMacbethLCH(vec2 uv) {
    vec4 t = colorCheckerTile(vec2(uv.x, 1.0-uv.y));
    int index = 6 * int(t.w) + int(t.z);
    vec3 lch = macbethLCH(index) *
                rect(t.xy, 0.8);
    float alpha = rect(uv, vec2(1.03,0.69));
    return vec4(lch * alpha, alpha);
}

vec4 colorCheckerMacbethXYY(vec2 uv) {
    vec4 t = colorCheckerTile(vec2(uv.x, 1.0-uv.y));
    int index = 6 * int(t.w) + int(t.z);
    vec3 xyY = macbethXYY(index) *
        rect(t.xy, 0.8);
    float alpha = saturate(rect(uv, vec2(1.03,0.69)));
    return vec4(xyY, alpha);
}

vec4 colorCheckerSpyderA(vec2 uv) {
    vec4 t = colorCheckerTile(uv);

    int index = 6 * int(t.w) + int(t.z);
    vec3 color = spyderA(index) * 
                rect(t.xy, 0.8) +
                fill(crossSDF(uv, 2.), .015) +
                saturate(
                    stroke(rectSDF(uv, vec2(1.015, 0.68)), 1., 0.01) -
                    rect(uv, vec2(.966, 1.)) - rect(uv, vec2(1.1, .63))
                );
    float alpha = rect(uv, vec2(1.03,0.69));
    return vec4(saturate(color) * alpha, alpha);
}

vec4 colorCheckerSpyderALAB(vec2 uv) {
    vec4 t = colorCheckerTile(uv);
    int index = 6 * int(t.w) + int(t.z);
    vec3 color = spyderALAB(index) * 
                rect(t.xy, 0.8);
    float alpha = rect(uv, vec2(1.03,0.69));
    return vec4(color * alpha, alpha);
}

vec4 colorCheckerSpyderB(vec2 uv) {
    vec4 t = colorCheckerTile(vec2(uv.x, 1.0-uv.y));
    int index = 6 * int(t.w) + int(t.z);
    vec3 color = spyderB(index) *
                rect(t.xy, 0.8) +
                fill(crossSDF(uv, 2.), .015) +
                saturate(
                    stroke(rectSDF(uv, vec2(1.015, 0.68)), 1., 0.01) -
                    rect(uv, vec2(.966, 1.)) - rect(uv, vec2(1.1, .63))
                );
    float alpha = rect(uv, vec2(1.03,0.69));
    return vec4(saturate(color) * alpha, alpha);
}

vec4 colorCheckerSpyderBLAB(vec2 uv) {
    vec4 t = colorCheckerTile(vec2(uv.x, 1.0-uv.y));
    int index = 6 * int(t.w) + int(t.z);
    vec3 color = spyderBLAB(index) * 
                rect(t.xy, 0.8);
    float alpha = rect(uv, vec2(1.03,0.69));
    return vec4(color * alpha, alpha);
}

vec4 colorCheckerSpyder(vec2 uv) { return colorCheckerSpyderB(uv); }
vec4 colorChecker (vec2 uv){ return COLORCHECKER_FNC(uv); }

#endif

Dependencies:

Use:

colorChecker(<float2> uv)
colorCheckerMacbeth(<float2> uv)
colorCheckerSpyder(<float2> uv)

Check it on Github



#ifndef COLORCHECKER_FNC
#define COLORCHECKER_FNC(UV) colorCheckerMacbeth(UV)
#endif

#ifndef COLOR_CHECKER
#define COLOR_CHECKER

float4 colorCheckerTile(float2 uv) {
    float2 st = scale(uv, float2(1.0,1.5)) * float2(6.0, 4.0);
    return float4(fract(st), floor(st));
}

float4 colorCheckerMacbeth (float2 uv) {
    float4 t = colorCheckerTile(float2(uv.x, 1.0-uv.y));
    int index = 6 * int(t.w) + int(t.z);
    float3 color = macbeth(index) * 
                rect(t.xy, 0.8) +
                fill(crossSDF(uv, 2.), .015) + 
                saturate(
                    stroke(rectSDF(uv, float2(1.015, 0.68)), 1., 0.01) -
                    rect(uv, float2(.966, 1.)) - rect(uv, float2(1.1, .63))
                );
    float alpha = rect(uv, float2(1.03,0.69));
    return float4(saturate(color) * alpha, alpha);
}

float4 colorCheckerMacbethXYZ(float2 uv) {
    float4 t = colorCheckerTile(float2(uv.x, 1.0-uv.y));
    int index = 6 * int(t.w) + int(t.z);
    float3 xyz = macbethXYZ(index) * 
                rect(t.xy, 0.8);
    float alpha = rect(uv, float2(1.03,0.69));
    return float4(xyz * alpha, alpha);
}

float4 colorCheckerMacbethLAB(float2 uv) {
    float4 t = colorCheckerTile(float2(uv.x, 1.0-uv.y));
    int index = 6 * int(t.w) + int(t.z);
    float3 lab = macbethLAB(index) * 
                rect(t.xy, 0.8);
    float alpha = rect(uv, float2(1.03,0.69));
    return float4(lab * alpha, alpha);
}

float4 colorCheckerMacbethLCH(float2 uv) {
    float4 t = colorCheckerTile(float2(uv.x, 1.0-uv.y));
    int index = 6 * int(t.w) + int(t.z);
    float3 lch = macbethLCH(index) *
                rect(t.xy, 0.8);
    float alpha = rect(uv, float2(1.03,0.69));
    return float4(lch * alpha, alpha);
}

float4 colorCheckerMacbethXYY(float2 uv) {
    float4 t = colorCheckerTile(float2(uv.x, 1.0-uv.y));
    int index = 6 * int(t.w) + int(t.z);
    float3 xyY = macbethXYY(index) *
        rect(t.xy, 0.8);
    float alpha = saturate(rect(uv, float2(1.03,0.69)));
    return float4(xyY, alpha);
}

float4 colorCheckerSpyderA(float2 uv) {
    float4 t = colorCheckerTile(uv);

    int index = 6 * int(t.w) + int(t.z);
    float3 color = spyderA(index) * 
                rect(t.xy, 0.8) +
                fill(crossSDF(uv, 2.), .015) +
                saturate(
                    stroke(rectSDF(uv, float2(1.015, 0.68)), 1., 0.01) -
                    rect(uv, float2(.966, 1.)) - rect(uv, float2(1.1, .63))
                );
    float alpha = rect(uv, float2(1.03,0.69));
    return float4(saturate(color) * alpha, alpha);
}

float4 colorCheckerSpyderALAB(float2 uv) {
    float4 t = colorCheckerTile(uv);
    int index = 6 * int(t.w) + int(t.z);
    float3 color = spyderALAB(index) * 
                rect(t.xy, 0.8);
    float alpha = rect(uv, float2(1.03,0.69));
    return float4(color * alpha, alpha);
}

float4 colorCheckerSpyderB(float2 uv) {
    float4 t = colorCheckerTile(float2(uv.x, 1.0-uv.y));
    int index = 6 * int(t.w) + int(t.z);
    float3 color = spyderB(index) *
                rect(t.xy, 0.8) +
                fill(crossSDF(uv, 2.), .015) +
                saturate(
                    stroke(rectSDF(uv, float2(1.015, 0.68)), 1., 0.01) -
                    rect(uv, float2(.966, 1.)) - rect(uv, float2(1.1, .63))
                );
    float alpha = rect(uv, float2(1.03,0.69));
    return float4(saturate(color) * alpha, alpha);
}

float4 colorCheckerSpyderBLAB(float2 uv) {
    float4 t = colorCheckerTile(float2(uv.x, 1.0-uv.y));
    int index = 6 * int(t.w) + int(t.z);
    float3 color = spyderBLAB(index) * 
                rect(t.xy, 0.8);
    float alpha = rect(uv, float2(1.03,0.69));
    return float4(color * alpha, alpha);
}

float4 colorCheckerSpyder(float2 uv) { return colorCheckerSpyderB(uv); }
float4 colorChecker (float2 uv){ return COLORCHECKER_FNC(uv); }

#endif

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