LYGIA Shader Library

hue (lygia/color/palette/hue)

Physical Hue.

Ratio: * 1/3 = neon * 1/4 = refracted * 1/5+ = approximate white

Use:

<vec3> hue(<float> hue[, <float> ratio])

Check it on Github


#ifndef FNC_PALETTE_HUE
#define FNC_PALETTE_HUE
vec3 hue(float x, float r) { 
    vec3 v = abs( mod(fract(1.0-x) + vec3(0.0,1.0,2.0) * r, 1.0) * 2.0 - 1.0); 
    return v*v*(3.0-2.0*v);
}
vec3 hue(float x) { return hue(x, 0.33333); }
#endif

Dependencies:

Use:

<float3> hue(<float> hue[, <float> ratio])

Check it on Github



#ifndef FNC_PALETTE_HUE
#define FNC_PALETTE_HUE

float3 hue(float x, float r) {
    float3 v = abs(mod(frac(1.0 - x) + float3(0.0, 1.0, 2.0) * r, 1.0) * 2.0 - 1.0);
    return v * v * (3.0 - 2.0 * v);
}

#endif

Dependencies:

Check it on Github



fn hue(x: f32, r: f32) -> vec3f { 
    let v = abs( mod3(x + vec3f(0.0,1.0,2.0) * r, vec3f(1.0)) * 2.0 - 1.0); 
    return v * v * (3.0 - 2.0 * v);
}

Dependencies:

Use:

<float3> hue(<float> hue[, <float> ratio])

Check it on Github



#ifndef FNC_PALETTE_HUE
#define FNC_PALETTE_HUE

inline __host__ __device__ float3 hue(float _hue, float _ratio) {
    return smoothstep(  make_float3(0.0f), make_float3(1.0f), 
                        abs( mod( _hue + make_float3(0.0f, 1.0f, 2.0f) * _ratio, 1.0f) * 2.0f - 1.0f));
}

inline __host__ __device__ float3 hue(float _hue) { return hue(_hue, 0.33333f); }

#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