|
3442 | 3442 | Modeling a Hollow Glass Sphere
|
3443 | 3443 | -------------------------------
|
3444 | 3444 | 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: |
3447 | 3470 |
|
3448 | 3471 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
3449 | 3472 | ...
|
|
0 commit comments