lygia
/sdf
/octogonPrismSDF
)generate the SDF of a octogon prism
Use:
<float> octogonPrismSDF( in <vec3> p, in <float> r, <float> h )
#ifndef FNC_OCTOGONPRISMSDF
#define FNC_OCTOGONPRISMSDF
float octogonPrismSDF( in vec3 p, in float r, float h ) {
vec3 k = vec3( -0.9238795325, // sqrt(2+sqrt(2))/2
0.3826834323, // sqrt(2-sqrt(2))/2
0.4142135623 ); // sqrt(2)-1
// reflections
p = abs(p);
p.xy -= 2.0*min(dot(vec2( k.x,k.y),p.xy),0.0)*vec2( k.x,k.y);
p.xy -= 2.0*min(dot(vec2(-k.x,k.y),p.xy),0.0)*vec2(-k.x,k.y);
// polygon side
p.xy -= vec2(clamp(p.x, -k.z*r, k.z*r), r);
vec2 d = vec2( length(p.xy)*sign(p.y), p.z-h );
return min(max(d.x,d.y),0.0) + length(max(d,0.0));
}
#endif
Use:
<float> octogonPrismSDF( in <float3> p, in <float> r, <float> h )
#ifndef FNC_OCTOGONPRISMSDF
#define FNC_OCTOGONPRISMSDF
float octogonPrismSDF( in float3 p, in float r, float h ) {
float3 k = float3(-0.9238795325, // sqrt(2+sqrt(2))/2
0.3826834323, // sqrt(2-sqrt(2))/2
0.4142135623 ); // sqrt(2)-1
// reflections
p = abs(p);
p.xy -= 2.0*min(dot(float2( k.x,k.y),p.xy),0.0)*float2( k.x,k.y);
p.xy -= 2.0*min(dot(float2(-k.x,k.y),p.xy),0.0)*float2(-k.x,k.y);
// polygon side
p.xy -= float2( clamp(p.x, -k.z*r, k.z*r), r);
float2 d = float2( length(p.xy)*sign(p.y), p.z-h );
return min(max(d.x,d.y),0.0) + length(max(d,0.0));
}
#endif
Use:
<float> octogonPrismSDF( <float3> p, <float> r, <float> h )
#ifndef FNC_OCTOGONPRISMSDF
#define FNC_OCTOGONPRISMSDF
float octogonPrismSDF( float3 p, float r, float h ) {
float3 k = float3( -0.9238795325, // sqrt(2+sqrt(2))/2
0.3826834323, // sqrt(2-sqrt(2))/2
0.4142135623 ); // sqrt(2)-1
// reflections
p = abs(p);
p.xy -= 2.0*min(dot(float2( k.x,k.y),p.xy),0.0)*float2( k.x,k.y);
p.xy -= 2.0*min(dot(float2(-k.x,k.y),p.xy),0.0)*float2(-k.x,k.y);
// polygon side
p.xy -= float2(clamp(p.x, -k.z*r, k.z*r), r);
float2 d = float2( length(p.xy)*sign(p.y), p.z-h );
return min(max(d.x,d.y),0.0) + length(max(d,0.0));
}
#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