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

17 lines
No EOL
409 B
GLSL

#include "../math/saturate.glsl"
/*
contributors: Inigo Quiles
description: generate a SDF of a capsule
use: <float> capusleSDF( in <vec3> pos, in <vec3> a, <vec3> b, <float> r )
*/
#ifndef FNC_CAPSULESDF
#define FNC_CAPSULESDF
float capsuleSDF( vec3 p, vec3 a, vec3 b, float r ) {
vec3 pa = p-a, ba = b-a;
float h = saturate( dot(pa,ba)/dot(ba,ba) );
return length( pa - ba*h ) - r;
}
#endif