lygia
/sdf
/icosahedronSDF
)generate the SDF of a icosahedron
Dependencies:
Use:
<float> icosahedronSDF( in <vec3> pos, in <float> size )
#ifndef FNC_ICOSAHEDRONSDF
#define FNC_ICOSAHEDRONSDF
float icosahedronSDF(vec3 p, float radius) {
float q = 2.61803398875; // Golden Ratio + 1 = (sqrt(5)+3)/2;
vec3 n1 = normalize(vec3(q, 1,0));
vec3 n2 = vec3(0.57735026919); // = sqrt(3)/3);
p = abs(p / radius);
float a = dot(p, n1.xyz);
float b = dot(p, n1.zxy);
float c = dot(p, n1.yzx);
float d = dot(p, n2) - n1.x;
return max(max(max(a,b),c)-n1.x,d) * radius;
}
#endif
Dependencies:
Use:
<float> icosahedronSDF( in <float3> pos, in <float> size )
#ifndef FNC_ICOSAHEDRONSDF
#define FNC_ICOSAHEDRONSDF
float icosahedronSDF(float3 p, float radius) {
float q = 2.61803398875; // Golden Ratio + 1 = (sqrt(5)+3)/2;
float3 n1 = normalize(float3(q, 1,0));
float3 n2 = float3(0.57735026919, 0.57735026919, 0.57735026919); // = sqrt(3)/3);
p = abs(p / radius);
float a = dot(p, n1.xyz);
float b = dot(p, n1.zxy);
float c = dot(p, n1.yzx);
float d = dot(p, n2) - n1.x;
return max(max(max(a,b),c)-n1.x,d) * radius;
}
#endif
Dependencies:
Use:
<float> icosahedronSDF( <float3> pos, <float> size )
#ifndef FNC_ICOSAHEDRONSDF
#define FNC_ICOSAHEDRONSDF
float icosahedronSDF(float3 p, float radius) {
float q = 2.61803398875; // Golden Ratio + 1 = (sqrt(5)+3)/2;
float3 n1 = normalize(float3(q, 1,0));
float3 n2 = float3(0.57735026919); // = sqrt(3)/3);
p = abs(p / radius);
float a = dot(p, n1.xyz);
float b = dot(p, n1.zxy);
float c = dot(p, n1.yzx);
float d = dot(p, n2) - n1.x;
return max(max(max(a,b),c)-n1.x,d) * radius;
}
#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