lygia
/sdf
/starSDF
)Returns a star-shaped sdf with V branches
Dependencies:
Use:
starSDF(<vec2> st, <int> V, <float> scale)
#ifndef FNC_STARSDF
#define FNC_STARSDF
float starSDF(in vec2 st, in int V, in float s) {
#ifdef CENTER_2D
st -= CENTER_2D;
#else
st -= 0.5;
#endif
st *= 2.0;
float a = atan(st.y, st.x) / TAU;
float seg = a * float(V);
a = ((floor(seg) + 0.5) / float(V) +
mix(s, -s, step(0.5, fract(seg))))
* TAU;
return abs(dot(vec2(cos(a), sin(a)),
st));
}
float starSDF(in vec2 st, in int V) {
return starSDF( scale(st, 12.0/float(V)), V, 0.1);
}
#endif
Dependencies:
Use:
starSDF(<float2> st, <int> V, <float> scale)
#ifndef FNC_STARSDF
#define FNC_STARSDF
float starSDF(in float2 st, in int V, in float s) {
#ifdef CENTER_2D
st -= CENTER_2D;
#else
st -= 0.5;
#endif
st *= 2.0;
float a = atan2(st.y, st.x) / TAU;
float seg = a * float(V);
a = ((floor(seg) + 0.5) / float(V) +
lerp(s, -s, step(0.5, frac(seg))))
* TAU;
return abs(dot(float2(cos(a), sin(a)),
st));
}
float starSDF(in float2 st, in int V) {
return starSDF( scale(st, 12.0/float(V)), V, 0.1);
}
#endif
Dependencies:
Use:
starSDF(<float2> st, <int> V, <float> scale)
#ifndef FNC_STARSDF
#define FNC_STARSDF
float starSDF(float2 st, int V, float s) {
#ifdef CENTER_2D
st -= CENTER_2D;
#else
st -= 0.5;
#endif
st *= 2.0;
float a = atan(st.y, st.x) / TAU;
float seg = a * float(V);
a = ((floor(seg) + 0.5) / float(V) +
mix(s, -s, step(0.5, fract(seg))))
* TAU;
return abs(dot(float2(cos(a), sin(a)),
st));
}
float starSDF(float2 st, int V) {
return starSDF( scale(st, 12.0/float(V)), V, 0.1);
}
#endif
precision mediump float;
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
// By default all 2D shapes and space functions asume
// the center is at vec2(0.5, 0.5), this can be overloaded
// by defining CENTER_2D to be something else, like vec2(0.0)
// before the functions are include
// #define CENTER_2D vec2(0.0)
void main(void) {
vec4 color = vec4(vec3(0.0), 1.0);
vec2 pixel = 1.0/u_resolution.xy;
vec2 st = gl_FragCoord.xy * pixel;
// Option 1
st = ratio(st, u_resolution.xy);
// // Option 2
// st = center(st);
// st = aspect(st, u_resolution.xy);
// st = uncenter(st);
float cols = 4.0;
st *= cols;
vec2 st_i = floor(st);
vec2 st_f = fract(st);
// st_f = center(st_f);
st_f = rotate(st_f, u_time * 0.4);
float sdf = 0.0;
float index = ( st_i.x + (cols-st_i.y - 1.0) * cols);
if (index == 0.0)
sdf = circleSDF( st_f );
else if (index == 1.0)
sdf = vesicaSDF( st_f, 0.25 );
else if (index == 2.0)
sdf = rhombSDF(st_f);
else if (index == 3.0)
sdf = triSDF( st_f );
else if (index == 4.0)
sdf = rectSDF( st_f, vec2(1.0) );
else if (index == 5.0)
sdf = polySDF( st_f, 5);
else if (index == 6.0)
sdf = hexSDF( st_f );
else if (index == 7.0)
sdf = starSDF(st_f, 5);
else if (index == 8.0)
sdf = flowerSDF(st_f, 5);
else if (index == 9.0)
sdf = crossSDF(st_f, 1.0);
else if (index == 10.0)
sdf = gearSDF(st_f, 10.0, 10);
else if (index == 11.0)
sdf = heartSDF(st_f);
else if (index == 12.0)
sdf = raysSDF(st_f, 14);
else if (index == 13.0)
sdf = spiralSDF(st_f, 0.1);
else
sdf = 1.0;
color.rgb += fill(sdf, 0.5);
gl_FragColor = color;
}
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.
Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository