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

26 lines
719 B
HLSL

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