LYGIA Shader Library

gain (lygia/v1.1.6/math/gain)

Remapping the unit interval into the unit interval by expanding the sides and compressing the center, and keeping 1/2 mapped to 1/2, that can be done with the gain() function. From https://iquilezles.org/articles/functions/

Use:

<float> gain(<float> x, <float> k)

Check it on Github


#ifndef FNC_GAIN
#define FNC_GAIN
float gain(float x, float k) {
    float a = 0.5 * pow(2.0*((x<0.5)? x : 1.0-x), k);
    return (x < 0.5) ? a : 1.0-a;
}
#endif

Use:

<float> gain(<float> x, <float> k)

Check it on Github


#ifndef FNC_GAIN
#define FNC_GAIN

float gain(float x, float k) {
    const float a = 0.5*pow(2.0*((x<0.5)?x:1.0-x), k);
    return (x<0.5)?a:1.0-a;
}

#endif

Dependencies:

Use:

<float> gain(<float> x, <float> k)

Check it on Github



#ifndef FNC_GAIN
#define FNC_GAIN

inline __host__ __device__ float gain(float x, float k) {
    const float a = 0.5f * pow(2.0f * ((x < 0.5f)? x : 1.0f - x), k);
    return (x < 0.5f)? a : 1.0f - a;
}

#endif

Examples

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