LYGIA Shader Library

linear2gamma (lygia/v1.1.6/color/space/linear2gamma)

convert from linear to gamma color space.

Use:

linear2gamma(<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_LINEAR2GAMMA
#define FNC_LINEAR2GAMMA
vec3 linear2gamma(in vec3 v) {
#ifdef GAMMA
    return pow(v, vec3(1. / GAMMA));
#else
    // assume gamma 2.0
    return sqrt(v);
#endif
}

vec4 linear2gamma(in vec4 v) {
    return vec4(linear2gamma(v.rgb), v.a);
}

float linear2gamma(in float v) {
#ifdef GAMMA
    return pow(v, 1. / GAMMA);
#else
    // assume gamma 2.0
    return sqrt(v);
#endif
}
#endif

Use:

linear2gamma(<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_LINEAR2GAMMA
#define FNC_LINEAR2GAMMA
float3 linear2gamma(in float3 v) {
#ifdef GAMMA
    float f = 1. / GAMMA;
    return pow(v, float3(f,f,f));
#else
    // assume gamma 2.0
    return sqrt(v);
#endif
}

float4 linear2gamma(in float4 v) {
    return float4(linear2gamma(v.rgb), v.a);
}

float linear2gamma(in float v) {
#ifdef GAMMA
    return pow(v, 1. / GAMMA);
#else
    // assume gamma 2.0
    return sqrt(v);
#endif
}
#endif

Check it on Github

fn linear2gamma(v : vec3<f32>) -> vec3<f32> {
    return pow(v, vec3<f32>(1. / 2.2));
}

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