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

16 lines
No EOL
517 B
HLSL

/*
contributors: Inigo Quiles
description: generate the SDF of a torus
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