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

Commit bb07733

Browse files
committed
hemispheres
1 parent cec4299 commit bb07733

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

sources/modesConfiguration.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ namespace unnatural
5252
&sdfH2O,
5353
&sdfH3O,
5454
&sdfH4O,
55+
&sdfHemispheres,
5556
&sdfHexagon,
5657
&sdfHexagonalPrism,
5758
&sdfInsideCube,
@@ -89,6 +90,7 @@ namespace unnatural
8990
"h2o",
9091
"h3o",
9192
"h4o",
93+
"hemispheres",
9294
"hexagon",
9395
"hexagonalprism",
9496
"insidecube",
@@ -138,6 +140,8 @@ namespace unnatural
138140
return true;
139141
if (name == "bowl")
140142
return true;
143+
if (name == "hemispheres")
144+
return true;
141145
if (name == "hexagon")
142146
return true;
143147
if (name == "insidecube")

sources/sdf.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -379,4 +379,20 @@ namespace unnatural
379379
return sdfCylinder(Vec3(p[0], p[2], p[1]), 10000, Radius) * -1;
380380
return Radius - abs(p[2]);
381381
}
382+
383+
Real sdfHemispheres(const Vec3 &p_)
384+
{
385+
const Vec3 p = Vec3(abs(p_[0]), abs(p_[1]), p_[2]);
386+
const auto &rotate = [](Vec3 p) -> Vec3
387+
{
388+
static constexpr Real s = 0.707106781186547524400844362104; // sin(45)
389+
return Vec3((p[0] - p[1]) * s, (p[0] + p[1]) * s, p[2]);
390+
};
391+
const Vec3 q = rotate(p + Vec3(-2000, 0, 0));
392+
const Real c = sdfCylinder(Vec3(q[1], q[2], q[0]), 10000, 200);
393+
const Real s1 = sdfSphere(q, 1000);
394+
const Real s2 = sdfSphere(rotate(p + Vec3(0, -2000, 0)), 1000);
395+
const Real s = min(s1, s2);
396+
return smoothMin(c, s, 100);
397+
}
382398
}

sources/sdf.h

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ namespace unnatural
2121
Real sdfH2O(const Vec3 &pos);
2222
Real sdfH3O(const Vec3 &pos);
2323
Real sdfH4O(const Vec3 &pos);
24+
Real sdfHemispheres(const Vec3 &p);
2425
Real sdfHexagon(const Vec3 &pos);
2526
Real sdfHexagonalPrism(const Vec3 &pos);
2627
Real sdfInsideCube(const Vec3 &p);

0 commit comments

Comments
 (0)