Skip to content

Commit 96b0899

Browse files
committed
Remove class flip_face
With the changes made to handle surface intersection from either side (refer to #270), we no longer have need for the `flip_face` class. This change removes the class and the associated text in the books. Resolves #482 Resolves #588
1 parent f0bac7a commit 96b0899

8 files changed

+20
-96
lines changed

books/RayTracingTheNextWeek.html

Lines changed: 12 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -2202,82 +2202,9 @@
22022202
<div class='together'>
22032203
We get:
22042204

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

2207+
This image is very noisy because the light is small.
22812208
</div>
22822209

22832210

@@ -2312,16 +2239,13 @@
23122239
box_max = p1;
23132240

23142241
sides.add(make_shared<xy_rect>(p0.x(), p1.x(), p0.y(), p1.y(), p1.z(), ptr));
2315-
sides.add(make_shared<flip_face>(
2316-
make_shared<xy_rect>(p0.x(), p1.x(), p0.y(), p1.y(), p0.z(), ptr)));
2242+
sides.add(make_shared<xy_rect>(p0.x(), p1.x(), p0.y(), p1.y(), p0.z(), ptr));
23172243

23182244
sides.add(make_shared<xz_rect>(p0.x(), p1.x(), p0.z(), p1.z(), p1.y(), ptr));
2319-
sides.add(make_shared<flip_face>(
2320-
make_shared<xz_rect>(p0.x(), p1.x(), p0.z(), p1.z(), p0.y(), ptr)));
2245+
sides.add(make_shared<xz_rect>(p0.x(), p1.x(), p0.z(), p1.z(), p0.y(), ptr));
23212246

23222247
sides.add(make_shared<yz_rect>(p0.y(), p1.y(), p0.z(), p1.z(), p1.x(), ptr));
2323-
sides.add(make_shared<flip_face>(
2324-
make_shared<yz_rect>(p0.y(), p1.y(), p0.z(), p1.z(), p0.x(), ptr)));
2248+
sides.add(make_shared<yz_rect>(p0.y(), p1.y(), p0.z(), p1.z(), p0.x(), ptr));
23252249
}
23262250

23272251
bool box::hit(const ray& r, double t0, double t1, hit_record& rec) const {
@@ -2344,7 +2268,7 @@
23442268
<div class='together'>
23452269
This gives:
23462270

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

23492273
</div>
23502274

@@ -2572,7 +2496,7 @@
25722496
<div class='together'>
25732497
Which yields:
25742498

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

25772501
</div>
25782502

@@ -2739,12 +2663,12 @@
27392663
auto green = make_shared<lambertian>(make_shared<solid_color>(.12, .45, .15));
27402664
auto light = make_shared<diffuse_light>(make_shared<solid_color>(7, 7, 7));
27412665

2742-
objects.add(make_shared<flip_face>(make_shared<yz_rect>(0, 555, 0, 555, 555, green)));
2666+
objects.add(make_shared<yz_rect>(0, 555, 0, 555, 555, green));
27432667
objects.add(make_shared<yz_rect>(0, 555, 0, 555, 0, red));
27442668
objects.add(make_shared<xz_rect>(113, 443, 127, 432, 554, light));
2745-
objects.add(make_shared<flip_face>(make_shared<xz_rect>(0, 555, 0, 555, 555, white)));
2669+
objects.add(make_shared<xz_rect>(0, 555, 0, 555, 555, white));
27462670
objects.add(make_shared<xz_rect>(0, 555, 0, 555, 0, white));
2747-
objects.add(make_shared<flip_face>(make_shared<xy_rect>(0, 555, 0, 555, 555, white)));
2671+
objects.add(make_shared<xy_rect>(0, 555, 0, 555, 555, white));
27482672

27492673
shared_ptr<hittable> box1 = make_shared<box>(point3(0,0,0), point3(165,330,165), white);
27502674
box1 = make_shared<rotate_y>(box1, 15);
@@ -2766,7 +2690,7 @@
27662690
<div class='together'>
27672691
We get:
27682692

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

27712695
</div>
27722696

@@ -2854,7 +2778,7 @@
28542778
<div class='together'>
28552779
Running it with 10,000 rays per pixel yields:
28562780

2857-
![Image 23: Final scene](../images/img-2.23-book2-final.jpg)
2781+
![Image 22: Final scene](../images/img-2.22-book2-final.jpg)
28582782

28592783
</div>
28602784

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>(make_shared<solid_color>(.12, .45, .15));
764764
auto light = make_shared<diffuse_light>(make_shared<solid_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);
@@ -2113,12 +2113,12 @@
21132113
auto green = make_shared<lambertian>(make_shared<solid_color>(.12, .45, .15));
21142114
auto light = make_shared<diffuse_light>(make_shared<solid_color>(15, 15, 15));
21152115

2116-
world.add(make_shared<flip_face>(make_shared<yz_rect>(0, 555, 0, 555, 555, green)));
2116+
world.add(make_shared<yz_rect>(0, 555, 0, 555, 555, green));
21172117
world.add(make_shared<yz_rect>(0, 555, 0, 555, 0, red));
2118-
world.add(make_shared<flip_face>(make_shared<xz_rect>(213, 343, 227, 332, 554, light)));
2119-
world.add(make_shared<flip_face>(make_shared<xz_rect>(0, 555, 0, 555, 555, white)));
2118+
world.add(make_shared<xz_rect>(213, 343, 227, 332, 554, light));
2119+
world.add(make_shared<xz_rect>(0, 555, 0, 555, 555, white));
21202120
world.add(make_shared<xz_rect>(0, 555, 0, 555, 0, white));
2121-
world.add(make_shared<flip_face>(make_shared<xy_rect>(0, 555, 0, 555, 555, white)));
2121+
world.add(make_shared<xy_rect>(0, 555, 0, 555, 555, white));
21222122

21232123

21242124
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 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)