Skip to content

Commit 1e844f5

Browse files
authored
Merge pull request #602 from RayTracing/remove-flip
Remove class `flip_face`
2 parents 134b8d4 + 07eaa1f commit 1e844f5

9 files changed

+26
-96
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ Change Log -- Ray Tracing in One Weekend
44
# v3.2.0 (in progress)
55

66
### Common
7+
- Removed: now that the code handles ray-surface intersection from either side, we no longer need
8+
the `flip_face` class, so we've deleted it from the text and from the code (#482, #270)
9+
10+
### _The Next Week_
11+
- Removed: Deleted the section covering the old `flip_face` class, renumbered images as this
12+
eliminated the rendering with missing Cornell box faces (#482)
713
- Change: Renamed and explicitly numbered book images and figures (#495)
814
- New: Added alternative constructors that take color arguments in addition to the constructors
915
that take `shared_ptr<texture>` arguments, simplifying calling code. This applies to the

books/RayTracingTheNextWeek.html

Lines changed: 12 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -2185,82 +2185,9 @@
21852185
<div class='together'>
21862186
We get:
21872187

2188-
![Image 18: Initial empty Cornell box](../images/img-2.18-cornell-initial.jpg class=pixel)
2189-
2190-
</div>
2191-
2192-
2193-
Flipped Objects
2194-
----------------
2195-
<div class='together'>
2196-
This is very noisy because the light is small. But we have a problem: some of the walls are facing
2197-
the wrong way. We haven't specified that a diffuse material should behave differently on different
2198-
faces of the object, but what if the Cornell box had a different pattern on the inside and outside
2199-
walls? The rectangle objects are described such that their front faces are always in the directions
2200-
$(1,0,0)$, $(0,1,0)$, or $(0,0,1)$. We need a way to switch the faces of an object. Let’s make a
2201-
hittable that does nothing but hold another hittable, and flips the face:
2202-
2203-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
2204-
class flip_face : public hittable {
2205-
public:
2206-
flip_face(shared_ptr<hittable> p) : ptr(p) {}
2207-
2208-
virtual bool hit(const ray& r, double t_min, double t_max, hit_record& rec) const {
2209-
if (!ptr->hit(r, t_min, t_max, rec))
2210-
return false;
2211-
2212-
rec.front_face = !rec.front_face;
2213-
return true;
2214-
}
2215-
2216-
virtual bool bounding_box(double t0, double t1, aabb& output_box) const {
2217-
return ptr->bounding_box(t0, t1, output_box);
2218-
}
2219-
2220-
public:
2221-
shared_ptr<hittable> ptr;
2222-
};
2223-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2224-
[Listing [flip-face]: <kbd>[hittable.h]</kbd> Flip-Face function]
2225-
</div>
2226-
2227-
<div class='together'>
2228-
This makes Cornell:
2229-
2230-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
2231-
hittable_list cornell_box() {
2232-
hittable_list objects;
2233-
2234-
auto red = make_shared<lambertian>(color(.65, .05, .05));
2235-
auto white = make_shared<lambertian>(color(.73, .73, .73));
2236-
auto green = make_shared<lambertian>(color(.12, .45, .15));
2237-
auto light = make_shared<diffuse_light>(color(15, 15, 15));
2238-
2239-
2240-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
2241-
objects.add(make_shared<flip_face>(make_shared<yz_rect>(0, 555, 0, 555, 555, green)));
2242-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
2243-
objects.add(make_shared<yz_rect>(0, 555, 0, 555, 0, red));
2244-
objects.add(make_shared<xz_rect>(213, 343, 227, 332, 554, light));
2245-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
2246-
objects.add(make_shared<flip_face>(make_shared<xz_rect>(0, 555, 0, 555, 555, white)));
2247-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
2248-
objects.add(make_shared<xz_rect>(0, 555, 0, 555, 0, white));
2249-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
2250-
objects.add(make_shared<flip_face>(make_shared<xy_rect>(0, 555, 0, 555, 555, white)));
2251-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
2252-
2253-
return objects;
2254-
}
2255-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2256-
[Listing [cornell-box-flipped]: <kbd>[main.cc]</kbd> Empty Cornell box with flipped rectangles]
2257-
</div>
2258-
2259-
<div class='together'>
2260-
And voila:
2261-
2262-
![Image 19: Empty Cornell box with fixed walls](../images/img-2.19-cornell-empty.jpg class=pixel)
2188+
![Image 18: Empty Cornell box](../images/img-2.18-cornell-empty.jpg class=pixel)
22632189

2190+
This image is very noisy because the light is small.
22642191
</div>
22652192

22662193

@@ -2295,16 +2222,13 @@
22952222
box_max = p1;
22962223

22972224
sides.add(make_shared<xy_rect>(p0.x(), p1.x(), p0.y(), p1.y(), p1.z(), ptr));
2298-
sides.add(make_shared<flip_face>(
2299-
make_shared<xy_rect>(p0.x(), p1.x(), p0.y(), p1.y(), p0.z(), ptr)));
2225+
sides.add(make_shared<xy_rect>(p0.x(), p1.x(), p0.y(), p1.y(), p0.z(), ptr));
23002226

23012227
sides.add(make_shared<xz_rect>(p0.x(), p1.x(), p0.z(), p1.z(), p1.y(), ptr));
2302-
sides.add(make_shared<flip_face>(
2303-
make_shared<xz_rect>(p0.x(), p1.x(), p0.z(), p1.z(), p0.y(), ptr)));
2228+
sides.add(make_shared<xz_rect>(p0.x(), p1.x(), p0.z(), p1.z(), p0.y(), ptr));
23042229

23052230
sides.add(make_shared<yz_rect>(p0.y(), p1.y(), p0.z(), p1.z(), p1.x(), ptr));
2306-
sides.add(make_shared<flip_face>(
2307-
make_shared<yz_rect>(p0.y(), p1.y(), p0.z(), p1.z(), p0.x(), ptr)));
2231+
sides.add(make_shared<yz_rect>(p0.y(), p1.y(), p0.z(), p1.z(), p0.x(), ptr));
23082232
}
23092233

23102234
bool box::hit(const ray& r, double t0, double t1, hit_record& rec) const {
@@ -2327,7 +2251,7 @@
23272251
<div class='together'>
23282252
This gives:
23292253

2330-
![Image 20: Cornell box with two blocks](../images/img-2.20-cornell-blocks.jpg class=pixel)
2254+
![Image 19: Cornell box with two blocks](../images/img-2.19-cornell-blocks.jpg class=pixel)
23312255

23322256
</div>
23332257

@@ -2555,7 +2479,7 @@
25552479
<div class='together'>
25562480
Which yields:
25572481

2558-
![Image 21: Standard Cornell box scene](../images/img-2.21-cornell-standard.jpg class=pixel)
2482+
![Image 20: Standard Cornell box scene](../images/img-2.20-cornell-standard.jpg class=pixel)
25592483

25602484
</div>
25612485

@@ -2728,12 +2652,12 @@
27282652
auto green = make_shared<lambertian>(color(.12, .45, .15));
27292653
auto light = make_shared<diffuse_light>(color(7, 7, 7));
27302654

2731-
objects.add(make_shared<flip_face>(make_shared<yz_rect>(0, 555, 0, 555, 555, green)));
2655+
objects.add(make_shared<yz_rect>(0, 555, 0, 555, 555, green));
27322656
objects.add(make_shared<yz_rect>(0, 555, 0, 555, 0, red));
27332657
objects.add(make_shared<xz_rect>(113, 443, 127, 432, 554, light));
2734-
objects.add(make_shared<flip_face>(make_shared<xz_rect>(0, 555, 0, 555, 555, white)));
2658+
objects.add(make_shared<xz_rect>(0, 555, 0, 555, 555, white));
27352659
objects.add(make_shared<xz_rect>(0, 555, 0, 555, 0, white));
2736-
objects.add(make_shared<flip_face>(make_shared<xy_rect>(0, 555, 0, 555, 555, white)));
2660+
objects.add(make_shared<xy_rect>(0, 555, 0, 555, 555, white));
27372661

27382662
shared_ptr<hittable> box1 = make_shared<box>(point3(0,0,0), point3(165,330,165), white);
27392663
box1 = make_shared<rotate_y>(box1, 15);
@@ -2755,7 +2679,7 @@
27552679
<div class='together'>
27562680
We get:
27572681

2758-
![Image 22: Cornell box with blocks of smoke](../images/img-2.22-cornell-smoke.jpg class=pixel)
2682+
![Image 21: Cornell box with blocks of smoke](../images/img-2.21-cornell-smoke.jpg class=pixel)
27592683

27602684
</div>
27612685

@@ -2839,7 +2763,7 @@
28392763
<div class='together'>
28402764
Running it with 10,000 rays per pixel yields:
28412765

2842-
![Image 23: Final scene](../images/img-2.23-book2-final.jpg)
2766+
![Image 22: Final scene](../images/img-2.22-book2-final.jpg)
28432767

28442768
</div>
28452769

books/RayTracingTheRestOfYourLife.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -763,12 +763,12 @@
763763
auto green = make_shared<lambertian>(color(.12, .45, .15));
764764
auto light = make_shared<diffuse_light>(color(15, 15, 15));
765765

766-
world.add(make_shared<flip_face>(make_shared<yz_rect>(0, 555, 0, 555, 555, green)));
766+
world.add(make_shared<yz_rect>(0, 555, 0, 555, 555, green));
767767
world.add(make_shared<yz_rect>(0, 555, 0, 555, 0, red));
768-
world.add(make_shared<flip_face>(make_shared<xz_rect>(213, 343, 227, 332, 554, light)));
769-
world.add(make_shared<flip_face>(make_shared<xz_rect>(0, 555, 0, 555, 555, white)));
768+
world.add(make_shared<xz_rect>(213, 343, 227, 332, 554, light));
769+
world.add(make_shared<xz_rect>(0, 555, 0, 555, 555, white));
770770
world.add(make_shared<xz_rect>(0, 555, 0, 555, 0, white));
771-
world.add(make_shared<flip_face>(make_shared<xy_rect>(0, 555, 0, 555, 555, white)));
771+
world.add(make_shared<xy_rect>(0, 555, 0, 555, 555, white));
772772

773773
shared_ptr<hittable> box1 = make_shared<box>(point3(0,0,0), point3(165,330,165), white);
774774
box1 = make_shared<rotate_y>(box1, 15);
@@ -2121,12 +2121,12 @@
21212121
auto green = make_shared<lambertian>(color(.12, .45, .15));
21222122
auto light = make_shared<diffuse_light>(color(15, 15, 15));
21232123

2124-
world.add(make_shared<flip_face>(make_shared<yz_rect>(0, 555, 0, 555, 555, green)));
2124+
world.add(make_shared<yz_rect>(0, 555, 0, 555, 555, green));
21252125
world.add(make_shared<yz_rect>(0, 555, 0, 555, 0, red));
2126-
world.add(make_shared<flip_face>(make_shared<xz_rect>(213, 343, 227, 332, 554, light)));
2127-
world.add(make_shared<flip_face>(make_shared<xz_rect>(0, 555, 0, 555, 555, white)));
2126+
world.add(make_shared<xz_rect>(213, 343, 227, 332, 554, light));
2127+
world.add(make_shared<xz_rect>(0, 555, 0, 555, 555, white));
21282128
world.add(make_shared<xz_rect>(0, 555, 0, 555, 0, white));
2129-
world.add(make_shared<flip_face>(make_shared<xy_rect>(0, 555, 0, 555, 555, white)));
2129+
world.add(make_shared<xy_rect>(0, 555, 0, 555, 555, white));
21302130

21312131

21322132
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
File renamed without changes.

images/img-2.18-cornell-initial.jpg

-13 KB
Binary file not shown.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)