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

30 lines
876 B
Text

#include "../math/const.msl"
/*
contributors: Patricio Gonzalez Vivo
description: Returns a sdf for a regular polygon with V sides.
use: polySDF(<float2> st, int V)
options:
- CENTER_2D: float2, defaults to float2(.5)
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_POLYSDF
#define FNC_POLYSDF
float polySDF(float2 st, int V) {
#ifdef CENTER_2D
st -= CENTER_2D;
st *= 2.0;
#else
st = st * 2.0 - 1.0;
#endif
float a = atan(st.x, st.y) + PI;
float r = length(st);
float v = TAU / float(V);
return cos(floor(.5 + a / v) * v - a ) * r;
}
#endif