LYGIA Shader Library

mod2 (lygia/math/mod2)

Two dimensional modulus, returns the remainder of a division of two vectors. Found at in Mercury's library https://mercury.sexy/hg_sdf/

Use:

<vec2> mod2(<vec2> x, <vec2> size)

Check it on Github


#ifndef FNC_MOD2
#define FNC_MOD2
vec2 mod2(inout vec2 p, float s) {
    vec2 c = floor((p + s*0.5)/s);
    p = mod(p + s*0.5,s) - s*0.5;
    return c;
}

vec2 mod2(inout vec2 p, vec2 s) {
    vec2 c = floor((p + s*0.5)/s);
    p = mod(p + s*0.5,s) - s*0.5;
    return c;
}
#endif

Dependencies:

Use:

<float2> mod2(<float2> x, <float2> size)

Check it on Github



#ifndef FNC_MOD2
#define FNC_MOD2
float2 mod2(inout float2 p, float s) {
    float2 c = floor((p + s * 0.5) / s);
    p = mod(p + s*0.5,s) - s*0.5;
    return c;
}

float2 mod2(inout float2 p, float2 s) {
    float2 c = floor((p + s * 0.5) / s);
    p = mod(p + s*0.5,s) - s*0.5;
    return c;
}
#endif

Use:

<float2> mod2(<float2> x, <float2> size)

Check it on Github


#ifndef FNC_MOD2
#define FNC_MOD2
float2 mod2(thread float2& p, float s) {
    float2 c = floor((p + s*0.5)/s);
    p = mod(p + s*0.5,s) - s*0.5;
    return c;
}

float2 mod2(thread float2& p, float2 s) {
    float2 c = floor((p + s*0.5)/s);
    p = mod(p + s*0.5,s) - s*0.5;
    return c;
}
#endif

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