Skip to content

Commit 82796b2

Browse files
authored
Merge pull request #666 from RayTracing/flipface_issues
Completed the move to removing flipface from book 2, and added its so…
2 parents 95085e6 + 937814e commit 82796b2

File tree

7 files changed

+72
-51
lines changed

7 files changed

+72
-51
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Change Log -- Ray Tracing in One Weekend
1111

1212
### _The Next Week_
1313
- Removed: Deleted the section covering the old `flip_face` class, renumbered images as this
14-
eliminated the rendering with missing Cornell box faces (#482)
14+
eliminated the rendering with missing Cornell box faces (#482, #661)
1515
- Change: Renamed and explicitly numbered book images and figures (#495)
1616
- Fix: Reduced code duplication in dielectric::scatter() function
1717
- New: Added alternative constructors that take color arguments in addition to the constructors

books/RayTracingTheRestOfYourLife.html

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1493,7 +1493,56 @@
14931493
</div>
14941494

14951495
<div class='together'>
1496-
We also need to flip the light so its normals point in the -y direction. This gives us:
1496+
We also need to flip the light so its normals point in the $-y$ direction:
1497+
1498+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
1499+
class flip_face : public hittable {
1500+
public:
1501+
flip_face(shared_ptr<hittable> p) : ptr(p) {}
1502+
1503+
virtual bool hit(const ray& r, double t_min, double t_max, hit_record& rec) const {
1504+
if (!ptr->hit(r, t_min, t_max, rec))
1505+
return false;
1506+
1507+
rec.front_face = !rec.front_face;
1508+
return true;
1509+
}
1510+
1511+
virtual bool bounding_box(double t0, double t1, aabb& output_box) const {
1512+
return ptr->bounding_box(t0, t1, output_box);
1513+
}
1514+
1515+
public:
1516+
shared_ptr<hittable> ptr;
1517+
};
1518+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1519+
[Listing [flip-face]: <kbd>[hittable.h]</kbd> We use a hittable object to flip the light]
1520+
1521+
Making sure to call this in our world definition:
1522+
1523+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
1524+
hittable_list cornell_box() {
1525+
hittable_list world;
1526+
1527+
auto red = make_shared<lambertian>(color(.65, .05, .05));
1528+
auto white = make_shared<lambertian>(color(.73, .73, .73));
1529+
auto green = make_shared<lambertian>(color(.12, .45, .15));
1530+
auto light = make_shared<diffuse_light>(color(15, 15, 15));
1531+
1532+
world.add(make_shared<yz_rect>(0, 555, 0, 555, 555, green));
1533+
world.add(make_shared<yz_rect>(0, 555, 0, 555, 0, red));
1534+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
1535+
world.add(make_shared<flip_face>(make_shared<xz_rect>(213, 343, 227, 332, 554, light)));
1536+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
1537+
world.add(make_shared<xz_rect>(0, 555, 0, 555, 555, white));
1538+
world.add(make_shared<xz_rect>(0, 555, 0, 555, 0, white));
1539+
world.add(make_shared<xy_rect>(0, 555, 0, 555, 555, white));
1540+
1541+
...
1542+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1543+
[Listing [flipping-light]: <kbd>[main.cc]</kbd> Flip the light in our cornell box scene]
1544+
1545+
This gives us:
14971546

14981547
![Image 5: Cornell box, light emitted only in the downward direction
14991548
](../images/img-3.05-cornell-lightdown.jpg class=pixel)

src/TheNextWeek/box.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,13 @@ box::box(const point3& p0, const point3& p1, shared_ptr<material> ptr) {
4141
box_max = p1;
4242

4343
sides.add(make_shared<xy_rect>(p0.x(), p1.x(), p0.y(), p1.y(), p1.z(), ptr));
44-
sides.add(make_shared<flip_face>(
45-
make_shared<xy_rect>(p0.x(), p1.x(), p0.y(), p1.y(), p0.z(), ptr)));
44+
sides.add(make_shared<xy_rect>(p0.x(), p1.x(), p0.y(), p1.y(), p0.z(), ptr));
4645

4746
sides.add(make_shared<xz_rect>(p0.x(), p1.x(), p0.z(), p1.z(), p1.y(), ptr));
48-
sides.add(make_shared<flip_face>(
49-
make_shared<xz_rect>(p0.x(), p1.x(), p0.z(), p1.z(), p0.y(), ptr)));
47+
sides.add(make_shared<xz_rect>(p0.x(), p1.x(), p0.z(), p1.z(), p0.y(), ptr));
5048

5149
sides.add(make_shared<yz_rect>(p0.y(), p1.y(), p0.z(), p1.z(), p1.x(), ptr));
52-
sides.add(make_shared<flip_face>(
53-
make_shared<yz_rect>(p0.y(), p1.y(), p0.z(), p1.z(), p0.x(), ptr)));
50+
sides.add(make_shared<yz_rect>(p0.y(), p1.y(), p0.z(), p1.z(), p0.x(), ptr));
5451
}
5552

5653
bool box::hit(const ray& r, double t0, double t1, hit_record& rec) const {

src/TheNextWeek/hittable.h

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,28 +40,6 @@ class hittable {
4040
virtual bool bounding_box(double t0, double t1, aabb& output_box) const = 0;
4141
};
4242

43-
44-
class flip_face : public hittable {
45-
public:
46-
flip_face(shared_ptr<hittable> p) : ptr(p) {}
47-
48-
virtual bool hit(const ray& r, double t_min, double t_max, hit_record& rec) const {
49-
if (!ptr->hit(r, t_min, t_max, rec))
50-
return false;
51-
52-
rec.front_face = !rec.front_face;
53-
return true;
54-
}
55-
56-
virtual bool bounding_box(double t0, double t1, aabb& output_box) const {
57-
return ptr->bounding_box(t0, t1, output_box);
58-
}
59-
60-
public:
61-
shared_ptr<hittable> ptr;
62-
};
63-
64-
6543
class translate : public hittable {
6644
public:
6745
translate(shared_ptr<hittable> p, const vec3& displacement)

src/TheNextWeek/main.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,12 @@ hittable_list cornell_box() {
152152
auto green = make_shared<lambertian>(color(.12, .45, .15));
153153
auto light = make_shared<diffuse_light>(color(15,15,15));
154154

155-
objects.add(make_shared<flip_face>(make_shared<yz_rect>(0, 555, 0, 555, 555, green)));
155+
objects.add(make_shared<yz_rect>(0, 555, 0, 555, 555, green));
156156
objects.add(make_shared<yz_rect>(0, 555, 0, 555, 0, red));
157157
objects.add(make_shared<xz_rect>(213, 343, 227, 332, 554, light));
158-
objects.add(make_shared<flip_face>(make_shared<xz_rect>(0, 555, 0, 555, 555, white)));
158+
objects.add(make_shared<xz_rect>(0, 555, 0, 555, 555, white));
159159
objects.add(make_shared<xz_rect>(0, 555, 0, 555, 0, white));
160-
objects.add(make_shared<flip_face>(make_shared<xy_rect>(0, 555, 0, 555, 555, white)));
160+
objects.add(make_shared<xy_rect>(0, 555, 0, 555, 555, white));
161161

162162
shared_ptr<hittable> box1 = make_shared<box>(point3(0,0,0), point3(165,330,165), white);
163163
box1 = make_shared<rotate_y>(box1, 15);
@@ -181,12 +181,12 @@ hittable_list cornell_balls() {
181181
auto green = make_shared<lambertian>(color(.12, .45, .15));
182182
auto light = make_shared<diffuse_light>(color(5, 5, 5));
183183

184-
objects.add(make_shared<flip_face>(make_shared<yz_rect>(0, 555, 0, 555, 555, green)));
184+
objects.add(make_shared<yz_rect>(0, 555, 0, 555, 555, green));
185185
objects.add(make_shared<yz_rect>(0, 555, 0, 555, 0, red));
186186
objects.add(make_shared<xz_rect>(113, 443, 127, 432, 554, light));
187-
objects.add(make_shared<flip_face>(make_shared<xz_rect>(0, 555, 0, 555, 555, white)));
187+
objects.add(make_shared<xz_rect>(0, 555, 0, 555, 555, white));
188188
objects.add(make_shared<xz_rect>(0, 555, 0, 555, 0, white));
189-
objects.add(make_shared<flip_face>(make_shared<xy_rect>(0, 555, 0, 555, 555, white)));
189+
objects.add(make_shared<xy_rect>(0, 555, 0, 555, 555, white));
190190

191191
auto boundary = make_shared<sphere>(point3(160,100,145), 100, make_shared<dielectric>(1.5));
192192
objects.add(boundary);
@@ -209,12 +209,12 @@ hittable_list cornell_smoke() {
209209
auto green = make_shared<lambertian>(color(.12, .45, .15));
210210
auto light = make_shared<diffuse_light>(color(7, 7, 7));
211211

212-
objects.add(make_shared<flip_face>(make_shared<yz_rect>(0, 555, 0, 555, 555, green)));
212+
objects.add(make_shared<yz_rect>(0, 555, 0, 555, 555, green));
213213
objects.add(make_shared<yz_rect>(0, 555, 0, 555, 0, red));
214214
objects.add(make_shared<xz_rect>(113, 443, 127, 432, 554, light));
215-
objects.add(make_shared<flip_face>(make_shared<xz_rect>(0, 555, 0, 555, 555, white)));
215+
objects.add(make_shared<xz_rect>(0, 555, 0, 555, 555, white));
216216
objects.add(make_shared<xz_rect>(0, 555, 0, 555, 0, white));
217-
objects.add(make_shared<flip_face>(make_shared<xy_rect>(0, 555, 0, 555, 555, white)));
217+
objects.add(make_shared<xy_rect>(0, 555, 0, 555, 555, white));
218218

219219
shared_ptr<hittable> box1 = make_shared<box>(point3(0,0,0), point3(165,330,165), white);
220220
box1 = make_shared<rotate_y>(box1, 15);
@@ -243,12 +243,12 @@ hittable_list cornell_final() {
243243
auto green = make_shared<lambertian>(color(.12, .45, .15));
244244
auto light = make_shared<diffuse_light>(color(7, 7, 7));
245245

246-
objects.add(make_shared<flip_face>(make_shared<yz_rect>(0, 555, 0, 555, 555, green)));
246+
objects.add(make_shared<yz_rect>(0, 555, 0, 555, 555, green));
247247
objects.add(make_shared<yz_rect>(0, 555, 0, 555, 0, red));
248248
objects.add(make_shared<xz_rect>(123, 423, 147, 412, 554, light));
249-
objects.add(make_shared<flip_face>(make_shared<xz_rect>(0, 555, 0, 555, 555, white)));
249+
objects.add(make_shared<xz_rect>(0, 555, 0, 555, 555, white));
250250
objects.add(make_shared<xz_rect>(0, 555, 0, 555, 0, white));
251-
objects.add(make_shared<flip_face>(make_shared<xy_rect>(0, 555, 0, 555, 555, white)));
251+
objects.add(make_shared<xy_rect>(0, 555, 0, 555, 555, white));
252252

253253
shared_ptr<hittable> boundary2 =
254254
make_shared<box>(point3(0,0,0), point3(165,165,165), make_shared<dielectric>(1.5));

src/TheRestOfYourLife/box.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,13 @@ box::box(const point3& p0, const point3& p1, shared_ptr<material> ptr) {
4141
box_max = p1;
4242

4343
sides.add(make_shared<xy_rect>(p0.x(), p1.x(), p0.y(), p1.y(), p1.z(), ptr));
44-
sides.add(make_shared<flip_face>(
45-
make_shared<xy_rect>(p0.x(), p1.x(), p0.y(), p1.y(), p0.z(), ptr)));
44+
sides.add(make_shared<xy_rect>(p0.x(), p1.x(), p0.y(), p1.y(), p0.z(), ptr));
4645

4746
sides.add(make_shared<xz_rect>(p0.x(), p1.x(), p0.z(), p1.z(), p1.y(), ptr));
48-
sides.add(make_shared<flip_face>(
49-
make_shared<xz_rect>(p0.x(), p1.x(), p0.z(), p1.z(), p0.y(), ptr)));
47+
sides.add(make_shared<xz_rect>(p0.x(), p1.x(), p0.z(), p1.z(), p0.y(), ptr));
5048

5149
sides.add(make_shared<yz_rect>(p0.y(), p1.y(), p0.z(), p1.z(), p1.x(), ptr));
52-
sides.add(make_shared<flip_face>(
53-
make_shared<yz_rect>(p0.y(), p1.y(), p0.z(), p1.z(), p0.x(), ptr)));
50+
sides.add(make_shared<yz_rect>(p0.y(), p1.y(), p0.z(), p1.z(), p0.x(), ptr));
5451
}
5552

5653
bool box::hit(const ray& r, double t0, double t1, hit_record& rec) const {

src/TheRestOfYourLife/main.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ hittable_list cornell_box() {
7070
auto green = make_shared<lambertian>(color(.12, .45, .15));
7171
auto light = make_shared<diffuse_light>(color(15, 15, 15));
7272

73-
world.add(make_shared<flip_face>(make_shared<yz_rect>(0, 555, 0, 555, 555, green)));
73+
world.add(make_shared<yz_rect>(0, 555, 0, 555, 555, green));
7474
world.add(make_shared<yz_rect>(0, 555, 0, 555, 0, red));
7575
world.add(make_shared<flip_face>(make_shared<xz_rect>(213, 343, 227, 332, 554, light)));
76-
world.add(make_shared<flip_face>(make_shared<xz_rect>(0, 555, 0, 555, 555, white)));
76+
world.add(make_shared<xz_rect>(0, 555, 0, 555, 555, white));
7777
world.add(make_shared<xz_rect>(0, 555, 0, 555, 0, white));
78-
world.add(make_shared<flip_face>(make_shared<xy_rect>(0, 555, 0, 555, 555, white)));
78+
world.add(make_shared<xy_rect>(0, 555, 0, 555, 555, white));
7979

8080
shared_ptr<hittable> box1 = make_shared<box>(point3(0,0,0), point3(165,330,165), white);
8181
box1 = make_shared<rotate_y>(box1, 15);

0 commit comments

Comments
 (0)