LYGIA Shader Library

opRepeat (lygia/sdf/opRepeat)

repeat operation for 2D/3D SDFs

Use:

<vec4> opElongate( in <vec3> p, in <vec3> h )

Check it on Github


#ifndef FNC_OPREPEAT
#define FNC_OPREPEAT

vec2 opRepeat( in vec2 p, in float s ) {
    return mod(p+s*0.5,s)-s*0.5;
}

vec3 opRepeat( in vec3 p, in vec3 c ) {
    return mod(p+0.5*c,c)-0.5*c;
}

vec2 opRepeat( in vec2 p, in vec2 lima, in vec2 limb, in float s ) {
    return p-s*clamp(floor(p/s),lima,limb);
}

vec3 opRepeat( in vec3 p, in vec3 lima, in vec3 limb, in float s ) {
    return p-s*clamp(floor(p/s),lima,limb);
}

#endif


Dependencies:

Use:

<float4> opElongate( in <float3> p, in <float3> h )

Check it on Github



#ifndef FNC_OPREPEAT
#define FNC_OPREPEAT

float2 opRepeat( in float2 p, in float s ) {
    return mod(p+s*0.5,s)-s*0.5;
}

float3 opRepeat( in float3 p, in float3 c ) {
    return mod(p+0.5*c,c)-0.5*c;
}

float2 opRepeat( in float2 p, in float2 lima, in float2 limb, in float s ) {
    return p-s*clamp(floor(p/s), lima, limb);
}

float3 opRepeat( in float3 p, in float3 lima, in float3 limb, in float s ) {
    return p-s*clamp(floor(p/s), lima, limb);
}

#endif


Use:

<float4> opElongate( <float3> p, <float3> h )

Check it on Github


#ifndef FNC_OPREPEAT
#define FNC_OPREPEAT

float2 opRepeat( float2 p, float s ) {
    return mod(p+s*0.5,s)-s*0.5;
}

float3 opRepeat( float3 p, float3 c ) {
    return mod(p+0.5*c,c)-0.5*c;
}

float2 opRepeat( float2 p, float2 lima, float2 limb, float s ) {
    return p-s*clamp(floor(p/s),lima,limb);
}

float3 opRepeat( float3 p, float3 lima, float3 limb, float s ) {
    return p-s*clamp(floor(p/s),lima,limb);
}

#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