LYGIA Shader Library

capsuleSDF (lygia/sdf/capsuleSDF)

generate a SDF of a capsule

Dependencies:

Use:

<float> capusleSDF( in <vec3> pos, in <vec3> a, <vec3> b, <float> r )

Check it on Github


#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

Use:

<float> capusleSDF( in <float3> pos, in <float3> a, <float3> b, <float> r )

Check it on Github


#ifndef FNC_CAPSULESDF
#define FNC_CAPSULESDF

float capsuleSDF( float3 p, float3 a, float3 b, float r ) {
    float3 pa = p-a, ba = b-a;
    float h = saturate( dot(pa,ba)/dot(ba,ba) );
    return length( pa - ba*h ) - r;
}

#endif

License

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.

Get the latest news and releases

Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository