LYGIA Shader Library

gamma2linear (lygia/color/space/gamma2linear)

Convert from gamma to linear color space.

Use:

gamma2linear(<float|vec3|vec4> color)

Check it on Github


#if !defined(GAMMA) && !defined(TARGET_MOBILE) && !defined(PLATFORM_RPI) && !defined(PLATFORM_WEBGL)
#define GAMMA 2.2
#endif

#ifndef FNC_GAMMA2LINEAR
#define FNC_GAMMA2LINEAR
float gamma2linear(const in float v) {
#ifdef GAMMA
    return pow(v, GAMMA);
#else
    // assume gamma 2.0
    return v * v;
#endif
}

vec3 gamma2linear(const in vec3 v) {
#ifdef GAMMA
    return pow(v, vec3(GAMMA));
#else
    // assume gamma 2.0
    return v * v;
#endif
}

vec4 gamma2linear(const in vec4 v) {
    return vec4(gamma2linear(v.rgb), v.a);
}
#endif

Use:

gamma2linear(<float|float3|float4> color)

Check it on Github


#if !defined(GAMMA) && !defined(TARGET_MOBILE) && !defined(PLATFORM_RPI) && !defined(PLATFORM_WEBGL)
#define GAMMA 2.2
#endif

#ifndef FNC_GAMMA2LINEAR
#define FNC_GAMMA2LINEAR
float gamma2linear(in float v) {
#ifdef GAMMA
    return pow(v, GAMMA);
#else
    // assume gamma 2.0
    return v * v;
#endif
}

float3 gamma2linear(in float3 v) {
#ifdef GAMMA
    return pow(v, float3(GAMMA, GAMMA, GAMMA));
#else
    // assume gamma 2.0
    return v * v;
#endif
}

float4 gamma2linear(in float4 v) {
    return float4(gamma2linear(v.rgb), v.a);
}
#endif

Use:

gamma2linear(<float|float3|float4> color)

Check it on Github


#if !defined(GAMMA) && !defined(TARGET_MOBILE) && !defined(PLATFORM_RPI) && !defined(PLATFORM_WEBGL)
#define GAMMA 2.2
#endif

#ifndef FNC_GAMMA2LINEAR
#define FNC_GAMMA2LINEAR
float gamma2linear( float v) {
#ifdef GAMMA
    return pow(v, GAMMA);
#else
    // assume gamma 2.0
    return v * v;
#endif
}

float3 gamma2linear( float3 v) {
#ifdef GAMMA
    return pow(v, float3(GAMMA));
#else
    // assume gamma 2.0
    return v * v;
#endif
}

float4 gamma2linear( float4 v) {
    return float4(gamma2linear(v.rgb), v.a);
}
#endif

Check it on Github


fn gamma2linear(gamma: vec3f) -> vec3f {
    return pow(gamma, vec3(2.2));
}

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