fuckingtech/public/assets/glsl/lygia/sdf/starSDF.msl
Elias Rhouzlane bf76c6b086 fix: code
2025-04-06 17:23:52 +02:00

36 lines
1 KiB
Text

#include "../math/const.msl"
#include "../space/scale.msl"
/*
contributors: Patricio Gonzalez Vivo
description: Returns a star-shaped sdf with V branches
use: starSDF(<float2> st, <int> V, <float> scale)
examples:
- https://raw.githubusercontent.com/patriciogonzalezvivo/lygia_examples/main/draw_shapes.frag
license:
- Copyright (c) 2021 Patricio Gonzalez Vivo under Prosperity License - https://prosperitylicense.com/versions/3.0.0
- Copyright (c) 2021 Patricio Gonzalez Vivo under Patron License - https://lygia.xyz/license
*/
#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