Skip to content

Commit 145188a

Browse files
committed
Groom book 2 listings
1 parent 4350083 commit 145188a

File tree

1 file changed

+81
-28
lines changed

1 file changed

+81
-28
lines changed

books/RayTracingTheNextWeek.html

Lines changed: 81 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2608,8 +2608,8 @@
26082608
public:
26092609
...
26102610
aabb(const interval& x, const interval& y, const interval& z)
2611-
: x(x), y(y), z(z)
26122611
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
2612+
: x(x), y(y), z(z)
26132613
{
26142614
pad_to_minimums();
26152615
}
@@ -2624,6 +2624,7 @@
26242624
y = interval(fmin(a[1],b[1]), fmax(a[1],b[1]));
26252625
z = interval(fmin(a[2],b[2]), fmax(a[2],b[2]));
26262626

2627+
26272628
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
26282629
pad_to_minimums();
26292630
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
@@ -2825,6 +2826,7 @@
28252826
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
28262827
class quad : public hittable {
28272828
...
2829+
28282830
bool hit(const ray& r, interval ray_t, hit_record& rec) const override {
28292831
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
28302832
auto denom = dot(normal, r.direction());
@@ -2848,6 +2850,7 @@
28482850
return true;
28492851
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
28502852
}
2853+
28512854
...
28522855
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28532856
[Listing [quad-plane2]: <kbd>[quad.h]</kbd> hit() method for the infinite plane]
@@ -3036,11 +3039,6 @@
30363039
test method from the hit method.
30373040

30383041
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
3039-
...
3040-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
3041-
#include <cmath>
3042-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
3043-
30443042
class quad : public hittable {
30453043
public:
30463044
...
@@ -3060,7 +3058,9 @@
30603058

30613059
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
30623060
// Determine the hit point lies within the planar shape using its plane coordinates.
3061+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
30633062
auto intersection = r.at(t);
3063+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
30643064
vec3 planar_hitpt_vector = intersection - Q;
30653065
auto alpha = dot(w, cross(planar_hitpt_vector, v));
30663066
auto beta = dot(w, cross(u, planar_hitpt_vector));
@@ -3093,7 +3093,15 @@
30933093
return true;
30943094
}
30953095
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
3096-
...
3096+
3097+
private:
3098+
point3 Q;
3099+
vec3 u, v;
3100+
vec3 w;
3101+
shared_ptr<material> mat;
3102+
aabb bbox;
3103+
vec3 normal;
3104+
double D;
30973105
};
30983106

30993107
#endif
@@ -3103,12 +3111,23 @@
31033111
<div class='together'>
31043112
And now we add a new scene to demonstrate our new `quad` primitive:
31053113

3106-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
3107-
...
3114+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
3115+
#include "rtweekend.h"
3116+
3117+
#include "bvh.h"
3118+
#include "camera.h"
3119+
#include "color.h"
3120+
#include "hittable_list.h"
3121+
#include "material.h"
31083122
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
31093123
#include "quad.h"
31103124
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
3125+
#include "sphere.h"
3126+
#include "texture.h"
3127+
31113128
...
3129+
3130+
31123131
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
31133132
void quads() {
31143133
hittable_list world;
@@ -3199,6 +3218,12 @@
31993218
the ray what color it is and performs no reflection. It’s very simple:
32003219

32013220
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
3221+
class dielectric : public material {
3222+
...
3223+
}
3224+
3225+
3226+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
32023227
class diffuse_light : public material {
32033228
public:
32043229
diffuse_light(shared_ptr<texture> tex) : tex(tex) {}
@@ -3305,7 +3330,7 @@
33053330
cam.aspect_ratio = 16.0 / 9.0;
33063331
cam.image_width = 400;
33073332
cam.samples_per_pixel = 100;
3308-
cam.max_depth = 50;
3333+
cam.max_depth = 20;
33093334
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
33103335
cam.background = color(0.70, 0.80, 1.00);
33113336
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
@@ -3522,7 +3547,7 @@
35223547
![<span class='num'>Image 19:</span> Empty Cornell box
35233548
](../images/img-2.19-cornell-empty.png class='pixel')
35243549

3525-
This image is very noisy because the light is small.
3550+
This image is very noisy because the light is small, so most random rays don't hit the light source.
35263551

35273552
</div>
35283553

@@ -3534,9 +3559,18 @@
35343559
create a function that returns a box, by creating a `hittable_list` of six rectangles:
35353560

35363561
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
3537-
...
3562+
#include "rtweekend.h"
3563+
3564+
#include "hittable.h"
3565+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
35383566
#include "hittable_list.h"
3539-
...
3567+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
3568+
3569+
class quad : public hittable {
3570+
};
3571+
3572+
3573+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
35403574
inline shared_ptr<hittable_list> box(const point3& a, const point3& b, shared_ptr<material> mat)
35413575
{
35423576
// Returns the 3D box (six sides) that contains the two opposite vertices a & b.
@@ -3623,6 +3657,12 @@
36233657
make this happen.
36243658

36253659
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
3660+
class hittable {
3661+
...
3662+
};
3663+
3664+
3665+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
36263666
class translate : public hittable {
36273667
public:
36283668
bool hit(const ray& r, interval ray_t, hit_record& rec) const override {
@@ -3661,17 +3701,7 @@
36613701
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
36623702

36633703
bool hit(const ray& r, interval ray_t, hit_record& rec) const override {
3664-
// Move the ray backwards by the offset
3665-
ray offset_r(r.origin() - offset, r.direction(), r.time());
3666-
3667-
// Determine where (if any) an intersection occurs along the offset ray
3668-
if (!object->hit(offset_r, ray_t, rec))
3669-
return false;
3670-
3671-
// Move the intersection point forwards by the offset
3672-
rec.p += offset;
3673-
3674-
return true;
3704+
...
36753705
}
36763706

36773707

@@ -3807,6 +3837,12 @@
38073837
We can now create a class for y-rotation. Let's tackle the hit function first:
38083838

38093839
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
3840+
class translate : public hittable {
3841+
...
3842+
};
3843+
3844+
3845+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
38103846
class rotate_y : public hittable {
38113847
public:
38123848

@@ -4065,6 +4101,12 @@
40654101
The scattering function of isotropic picks a uniform random direction:
40664102

40674103
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
4104+
class diffuse_light : public material {
4105+
...
4106+
};
4107+
4108+
4109+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
40684110
class isotropic : public material {
40694111
public:
40704112
isotropic(const color& c) : tex(make_shared<solid_color>(c)) {}
@@ -4101,10 +4143,24 @@
41014143
If we replace the two blocks with smoke and fog (dark and light particles), and make the light
41024144
bigger (and dimmer so it doesn’t blow out the scene) for faster convergence:
41034145

4146+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
4147+
#include "rtweekend.h"
4148+
4149+
#include "bvh.h"
4150+
#include "camera.h"
4151+
#include "color.h"
41044152
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
41054153
#include "constant_medium.h"
41064154
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
4155+
#include "hittable_list.h"
4156+
#include "material.h"
4157+
#include "quad.h"
4158+
#include "sphere.h"
4159+
#include "texture.h"
4160+
41074161
...
4162+
4163+
41084164
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
41094165
void cornell_smoke() {
41104166
hittable_list world;
@@ -4190,9 +4246,6 @@
41904246
Also note that we'll parameterize this final scene to support a lower quality render for quick
41914247
testing.
41924248

4193-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
4194-
...
4195-
41964249
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
41974250
void final_scene(int image_width, int samples_per_pixel, int max_depth) {
41984251
hittable_list boxes1;
@@ -4276,7 +4329,7 @@
42764329

42774330
int main() {
42784331
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
4279-
switch (0) {
4332+
switch (9) {
42804333
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
42814334
case 1: bouncing_spheres(); break;
42824335
case 2: checkered_spheres(); break;

0 commit comments

Comments
 (0)