lygia
/v1.1.6
/sdf
/torusSDF
)generate the SDF of a torus
Use:
<float> torusSDF( in <vec3> pos, in <vec2> h [, in <float> ra, in <float> rb] )
#ifndef FNC_TORUSSDF
#define FNC_TORUSSDF
float torusSDF( vec3 p, vec2 t ) { return length( vec2(length(p.xz)-t.x,p.y) )-t.y; }
float torusSDF(in vec3 p, in vec2 sc, in float ra, in float rb) {
p.x = abs(p.x);
float k = (sc.y*p.x>sc.x*p.y) ? dot(p.xy,sc) : length(p.xy);
return sqrt( dot(p,p) + ra*ra - 2.0*ra*k ) - rb;
}
#endif
Use:
<float> torusSDF( in <float3> pos, in <float2> h [, in <float> ra, in <float> rb] )
#ifndef FNC_TORUSSDF
#define FNC_TORUSSDF
float torusSDF( float3 p, float2 t ) { return length( float2(length(p.xz)-t.x,p.y) )-t.y; }
float torusSDF(in float3 p, in float2 sc, in float ra, in float rb) {
p.x = abs(p.x);
float k = (sc.y*p.x>sc.x*p.y) ? dot(p.xy,sc) : length(p.xy);
return sqrt( dot(p,p) + ra*ra - 2.0*ra*k ) - rb;
}
#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.
Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository