Skip to content
This repository has been archived by the owner on Aug 20, 2024. It is now read-only.

Commit

Permalink
hemispheres
Browse files Browse the repository at this point in the history
  • Loading branch information
malytomas committed Jan 27, 2024
1 parent cec4299 commit bb07733
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sources/modesConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ namespace unnatural
&sdfH2O,
&sdfH3O,
&sdfH4O,
&sdfHemispheres,
&sdfHexagon,
&sdfHexagonalPrism,
&sdfInsideCube,
Expand Down Expand Up @@ -89,6 +90,7 @@ namespace unnatural
"h2o",
"h3o",
"h4o",
"hemispheres",
"hexagon",
"hexagonalprism",
"insidecube",
Expand Down Expand Up @@ -138,6 +140,8 @@ namespace unnatural
return true;
if (name == "bowl")
return true;
if (name == "hemispheres")
return true;
if (name == "hexagon")
return true;
if (name == "insidecube")
Expand Down
16 changes: 16 additions & 0 deletions sources/sdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,4 +379,20 @@ namespace unnatural
return sdfCylinder(Vec3(p[0], p[2], p[1]), 10000, Radius) * -1;
return Radius - abs(p[2]);
}

Real sdfHemispheres(const Vec3 &p_)
{
const Vec3 p = Vec3(abs(p_[0]), abs(p_[1]), p_[2]);
const auto &rotate = [](Vec3 p) -> Vec3
{
static constexpr Real s = 0.707106781186547524400844362104; // sin(45)
return Vec3((p[0] - p[1]) * s, (p[0] + p[1]) * s, p[2]);
};
const Vec3 q = rotate(p + Vec3(-2000, 0, 0));
const Real c = sdfCylinder(Vec3(q[1], q[2], q[0]), 10000, 200);
const Real s1 = sdfSphere(q, 1000);
const Real s2 = sdfSphere(rotate(p + Vec3(0, -2000, 0)), 1000);
const Real s = min(s1, s2);
return smoothMin(c, s, 100);
}
}
1 change: 1 addition & 0 deletions sources/sdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace unnatural
Real sdfH2O(const Vec3 &pos);
Real sdfH3O(const Vec3 &pos);
Real sdfH4O(const Vec3 &pos);
Real sdfHemispheres(const Vec3 &p);
Real sdfHexagon(const Vec3 &pos);
Real sdfHexagonalPrism(const Vec3 &pos);
Real sdfInsideCube(const Vec3 &p);
Expand Down

0 comments on commit bb07733

Please sign in to comment.