Skip to content

Commit b66de94

Browse files
committed
Add clarification for book 1 inverted spheres
Resolves #977
1 parent 6633596 commit b66de94

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

books/RayTracingInOneWeekend.html

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3442,8 +3442,31 @@
34423442
Modeling a Hollow Glass Sphere
34433443
-------------------------------
34443444
An interesting and easy trick with dielectric spheres is to note that if you use a negative radius,
3445-
the geometry is unaffected, but the surface normal points inward. This can be used as a bubble to
3446-
make a hollow glass sphere:
3445+
the geometry is unaffected, but the surface normal points inward.
3446+
3447+
However, properly handling negative radii can be tricky. Recall the line from `sphere::hit()` in
3448+
listing [sphere-material] that calculates the outward normal:
3449+
3450+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
3451+
vec3 outward_normal = (rec.p - center) / radius;
3452+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3453+
[Listing [proper-invert-sphere-normal]: Proper normal handling for spheres with negative radii]
3454+
3455+
In your own implementation, you might have been tempted to instead do something like this:
3456+
3457+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
3458+
vec3 outward_normal = (rec.p - center).unit_vector();
3459+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3460+
[Listing [improper-invert-sphere-normal]:
3461+
Problematic normal calculation for spheres with negative radii]
3462+
3463+
If you do that, spheres with negative radii won't work properly. Since a sphere with a negative
3464+
radius is a _bubble_, its interior is the infinite space outside the sphere. Its exterior is the
3465+
finite bubble inside the sphere, so the outward normal needs to point toward the sphere center.
3466+
Dividing by the (negative) radius flips the normal as we want. If you implmented your code like the
3467+
second example above, you'll want to fix that now.
3468+
3469+
Let's use this hollow sphere hack to model a sphere with a given thickness:
34473470

34483471
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
34493472
...

0 commit comments

Comments
 (0)