Skip to content

Commit

Permalink
Merge pull request #602 from RayTracing/remove-flip
Browse files Browse the repository at this point in the history
Remove class `flip_face`
  • Loading branch information
hollasch committed May 23, 2020
2 parents 134b8d4 + 07eaa1f commit 1e844f5
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 96 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Change Log -- Ray Tracing in One Weekend
# v3.2.0 (in progress)

### Common
- Removed: now that the code handles ray-surface intersection from either side, we no longer need
the `flip_face` class, so we've deleted it from the text and from the code (#482, #270)

### _The Next Week_
- Removed: Deleted the section covering the old `flip_face` class, renumbered images as this
eliminated the rendering with missing Cornell box faces (#482)
- Change: Renamed and explicitly numbered book images and figures (#495)
- New: Added alternative constructors that take color arguments in addition to the constructors
that take `shared_ptr<texture>` arguments, simplifying calling code. This applies to the
Expand Down
100 changes: 12 additions & 88 deletions books/RayTracingTheNextWeek.html
Original file line number Diff line number Diff line change
Expand Up @@ -2185,82 +2185,9 @@
<div class='together'>
We get:

![Image 18: Initial empty Cornell box](../images/img-2.18-cornell-initial.jpg class=pixel)

</div>


Flipped Objects
----------------
<div class='together'>
This is very noisy because the light is small. But we have a problem: some of the walls are facing
the wrong way. We haven't specified that a diffuse material should behave differently on different
faces of the object, but what if the Cornell box had a different pattern on the inside and outside
walls? The rectangle objects are described such that their front faces are always in the directions
$(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
hittable that does nothing but hold another hittable, and flips the face:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
class flip_face : public hittable {
public:
flip_face(shared_ptr<hittable> p) : ptr(p) {}

virtual bool hit(const ray& r, double t_min, double t_max, hit_record& rec) const {
if (!ptr->hit(r, t_min, t_max, rec))
return false;

rec.front_face = !rec.front_face;
return true;
}

virtual bool bounding_box(double t0, double t1, aabb& output_box) const {
return ptr->bounding_box(t0, t1, output_box);
}

public:
shared_ptr<hittable> ptr;
};
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[Listing [flip-face]: <kbd>[hittable.h]</kbd> Flip-Face function]
</div>

<div class='together'>
This makes Cornell:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
hittable_list cornell_box() {
hittable_list objects;

auto red = make_shared<lambertian>(color(.65, .05, .05));
auto white = make_shared<lambertian>(color(.73, .73, .73));
auto green = make_shared<lambertian>(color(.12, .45, .15));
auto light = make_shared<diffuse_light>(color(15, 15, 15));


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
objects.add(make_shared<flip_face>(make_shared<yz_rect>(0, 555, 0, 555, 555, green)));
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
objects.add(make_shared<yz_rect>(0, 555, 0, 555, 0, red));
objects.add(make_shared<xz_rect>(213, 343, 227, 332, 554, light));
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
objects.add(make_shared<flip_face>(make_shared<xz_rect>(0, 555, 0, 555, 555, white)));
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
objects.add(make_shared<xz_rect>(0, 555, 0, 555, 0, white));
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
objects.add(make_shared<flip_face>(make_shared<xy_rect>(0, 555, 0, 555, 555, white)));
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++

return objects;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[Listing [cornell-box-flipped]: <kbd>[main.cc]</kbd> Empty Cornell box with flipped rectangles]
</div>

<div class='together'>
And voila:

![Image 19: Empty Cornell box with fixed walls](../images/img-2.19-cornell-empty.jpg class=pixel)
![Image 18: Empty Cornell box](../images/img-2.18-cornell-empty.jpg class=pixel)

This image is very noisy because the light is small.
</div>


Expand Down Expand Up @@ -2295,16 +2222,13 @@
box_max = p1;

sides.add(make_shared<xy_rect>(p0.x(), p1.x(), p0.y(), p1.y(), p1.z(), ptr));
sides.add(make_shared<flip_face>(
make_shared<xy_rect>(p0.x(), p1.x(), p0.y(), p1.y(), p0.z(), ptr)));
sides.add(make_shared<xy_rect>(p0.x(), p1.x(), p0.y(), p1.y(), p0.z(), ptr));

sides.add(make_shared<xz_rect>(p0.x(), p1.x(), p0.z(), p1.z(), p1.y(), ptr));
sides.add(make_shared<flip_face>(
make_shared<xz_rect>(p0.x(), p1.x(), p0.z(), p1.z(), p0.y(), ptr)));
sides.add(make_shared<xz_rect>(p0.x(), p1.x(), p0.z(), p1.z(), p0.y(), ptr));

sides.add(make_shared<yz_rect>(p0.y(), p1.y(), p0.z(), p1.z(), p1.x(), ptr));
sides.add(make_shared<flip_face>(
make_shared<yz_rect>(p0.y(), p1.y(), p0.z(), p1.z(), p0.x(), ptr)));
sides.add(make_shared<yz_rect>(p0.y(), p1.y(), p0.z(), p1.z(), p0.x(), ptr));
}

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

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

</div>

Expand Down Expand Up @@ -2555,7 +2479,7 @@
<div class='together'>
Which yields:

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

</div>

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

objects.add(make_shared<flip_face>(make_shared<yz_rect>(0, 555, 0, 555, 555, green)));
objects.add(make_shared<yz_rect>(0, 555, 0, 555, 555, green));
objects.add(make_shared<yz_rect>(0, 555, 0, 555, 0, red));
objects.add(make_shared<xz_rect>(113, 443, 127, 432, 554, light));
objects.add(make_shared<flip_face>(make_shared<xz_rect>(0, 555, 0, 555, 555, white)));
objects.add(make_shared<xz_rect>(0, 555, 0, 555, 555, white));
objects.add(make_shared<xz_rect>(0, 555, 0, 555, 0, white));
objects.add(make_shared<flip_face>(make_shared<xy_rect>(0, 555, 0, 555, 555, white)));
objects.add(make_shared<xy_rect>(0, 555, 0, 555, 555, white));

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

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

</div>

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

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

</div>

Expand Down
16 changes: 8 additions & 8 deletions books/RayTracingTheRestOfYourLife.html
Original file line number Diff line number Diff line change
Expand Up @@ -763,12 +763,12 @@
auto green = make_shared<lambertian>(color(.12, .45, .15));
auto light = make_shared<diffuse_light>(color(15, 15, 15));

world.add(make_shared<flip_face>(make_shared<yz_rect>(0, 555, 0, 555, 555, green)));
world.add(make_shared<yz_rect>(0, 555, 0, 555, 555, green));
world.add(make_shared<yz_rect>(0, 555, 0, 555, 0, red));
world.add(make_shared<flip_face>(make_shared<xz_rect>(213, 343, 227, 332, 554, light)));
world.add(make_shared<flip_face>(make_shared<xz_rect>(0, 555, 0, 555, 555, white)));
world.add(make_shared<xz_rect>(213, 343, 227, 332, 554, light));
world.add(make_shared<xz_rect>(0, 555, 0, 555, 555, white));
world.add(make_shared<xz_rect>(0, 555, 0, 555, 0, white));
world.add(make_shared<flip_face>(make_shared<xy_rect>(0, 555, 0, 555, 555, white)));
world.add(make_shared<xy_rect>(0, 555, 0, 555, 555, white));

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

world.add(make_shared<flip_face>(make_shared<yz_rect>(0, 555, 0, 555, 555, green)));
world.add(make_shared<yz_rect>(0, 555, 0, 555, 555, green));
world.add(make_shared<yz_rect>(0, 555, 0, 555, 0, red));
world.add(make_shared<flip_face>(make_shared<xz_rect>(213, 343, 227, 332, 554, light)));
world.add(make_shared<flip_face>(make_shared<xz_rect>(0, 555, 0, 555, 555, white)));
world.add(make_shared<xz_rect>(213, 343, 227, 332, 554, light));
world.add(make_shared<xz_rect>(0, 555, 0, 555, 555, white));
world.add(make_shared<xz_rect>(0, 555, 0, 555, 0, white));
world.add(make_shared<flip_face>(make_shared<xy_rect>(0, 555, 0, 555, 555, white)));
world.add(make_shared<xy_rect>(0, 555, 0, 555, 555, white));


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
Expand Down
File renamed without changes
Binary file removed images/img-2.18-cornell-initial.jpg
Binary file not shown.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes

0 comments on commit 1e844f5

Please sign in to comment.