Skip to content

Commit 05a5be5

Browse files
committed
Changes made per requests
1 parent dd5aba3 commit 05a5be5

File tree

1 file changed

+42
-45
lines changed

1 file changed

+42
-45
lines changed

books/RayTracingInOneWeekend.html

Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@
292292

293293
#endif
294294
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
295-
[Listing [vec3-class]: <kbd>[vec3.h]</kbd> `vec3` class]
295+
[Listing [vec3-class]: <kbd>[vec3.h]</kbd> vec3 class]
296296
</div>
297297

298298
We use `double` here, but some ray tracers use `float`. Either one is fine -- follow your own
@@ -350,7 +350,7 @@
350350
return v / v.length();
351351
}
352352
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
353-
[Listing [vec3-utility]: <kbd>[vec3.h]</kbd> `vec3` utility functions]
353+
[Listing [vec3-utility]: <kbd>[vec3.h]</kbd> vec3 utility functions]
354354

355355
<div class='together'>
356356
Now we can change our main to use this:
@@ -391,23 +391,20 @@
391391
--------------
392392
<div class='together'>
393393
The one thing that all ray tracers have is a ray class, and a computation of what color is seen
394-
along a ray. Let’s think of a ray as a function:
395-
396-
$$ \mathbf{p}(t) = \mathbf{a} + t \vec{\mathbf{b}} $$
397-
398-
Where $\mathbf{p}$ is a 3D position along a line in 3D, $\mathbf{a}$ is the ray origin, and
394+
along a ray. Let’s think of a ray as a function $\mathbf{p}(t) = \mathbf{a} + t \vec{\mathbf{b}}$.
395+
Here $\mathbf{p}$ is a 3D position along a line in 3D. $\mathbf{a}$ is the ray origin and
399396
$\vec{\mathbf{b}}$ is the ray direction. The ray parameter $t$ is a real number (`double` in the
400-
code). Plug in a different $t$ and $\mathbf{p}(t)$ moves the point along the ray. Add in negative
401-
$t$ and you can go anywhere on the 3D line. For positive $t$, you get only the parts in front of
402-
$\mathbf{a}$, and this is what is often called a half-line or ray. This is where the _ray_ in
397+
code). Plug in a different $t$ and $p(t)$ moves the point along the ray. Add in negative $t$ and you
398+
can go anywhere on the 3D line. For positive $t$, you get only the parts in front of $\mathbf{a}$,
399+
and this is what is often called a half-line or ray. This is where the _ray_ in
403400
_ray tracing_ comes from.
404401

405402
![Figure [lerp]: Linear interpolation](../images/fig.lerp.jpg)
406403

407404
</div>
408405

409406
<div class='together'>
410-
The function $\mathbf{p}(t)$ in more verbose code form I call `ray::at(t)`:
407+
The function $p(t)$ in more verbose code form I call `ray::at(t)`:
411408

412409
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
413410
#ifndef RAY_H
@@ -436,7 +433,7 @@
436433

437434
#endif
438435
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
439-
[Listing [ray-initial]: <kbd>[ray.h]</kbd> The `ray` class]
436+
[Listing [ray-initial]: <kbd>[ray.h]</kbd> The ray class]
440437
</div>
441438

442439

@@ -569,11 +566,11 @@
569566

570567
<div class='together'>
571568
We can read this as “any point $\mathbf{p}$ that satisfies this equation is on the sphere”. We want
572-
to know if our ray $\mathbf{p}(t) = \mathbf{a} + t\vec{\mathbf{b}}$ ever hits the sphere anywhere.
573-
If it does hit the sphere, there is some $t$ for which $\mathbf{p}(t)$ satisfies the sphere
574-
equation. So we are looking for any $t$ where this is true:
569+
to know if our ray $p(t) = \mathbf{a} + t\vec{\mathbf{b}}$ ever hits the sphere anywhere. If it does
570+
hit the sphere, there is some $t$ for which $p(t)$ satisfies the sphere equation. So we are looking
571+
for any $t$ where this is true:
575572

576-
$$ (\mathbf{p}(t) - \mathbf{c})\cdot(\mathbf{p}(t) - \mathbf{c}) = R^2 $$
573+
$$ (p(t) - \mathbf{c})\cdot(p(t) - \mathbf{c}) = R^2 $$
577574

578575
or expanding the full form of the ray $p(t)$:
579576

@@ -810,7 +807,7 @@
810807

811808
#endif
812809
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
813-
[Listing [hittable-initial]: <kbd>[hittable.h]</kbd> The `hittable` class]
810+
[Listing [hittable-initial]: <kbd>[hittable.h]</kbd> The hittable class]
814811
</div>
815812

816813
<div class='together'>
@@ -865,7 +862,7 @@
865862

866863
#endif
867864
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
868-
[Listing [sphere-initial]: <kbd>[sphere.h]</kbd> The `sphere` class]
865+
[Listing [sphere-initial]: <kbd>[sphere.h]</kbd> The sphere class]
869866

870867
</div>
871868

@@ -963,7 +960,7 @@
963960

964961
#endif
965962
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
966-
[Listing [hittable-time-side]: <kbd>[hittable.h]</kbd> The `hittable` class with time and side]
963+
[Listing [hittable-time-side]: <kbd>[hittable.h]</kbd> The hittable class with time and side]
967964

968965
<div class='together'>
969966
And then we add the surface side determination to the class:
@@ -1002,7 +999,7 @@
1002999
return false;
10031000
}
10041001
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1005-
[Listing [sphere-final]: <kbd>[sphere.h]</kbd> The `sphere` class with normal determination]
1002+
[Listing [sphere-final]: <kbd>[sphere.h]</kbd> The sphere class with normal determination]
10061003

10071004
</div>
10081005

@@ -1057,7 +1054,7 @@
10571054

10581055
#endif
10591056
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1060-
[Listing [hittable-list-initial]: <kbd>[hittable_list.h]</kbd> The `hittable_list` class]
1057+
[Listing [hittable-list-initial]: <kbd>[hittable_list.h]</kbd> The hittable_list class]
10611058
</div>
10621059

10631060

@@ -1092,7 +1089,7 @@
10921089
auto vec3_ptr = make_shared<vec3>(1.414214, 2.718281, 1.618034);
10931090
auto sphere_ptr = make_shared<sphere>(point3(0,0,0), 1.0);
10941091
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1095-
[Listing [shared-ptr-auto]: An example allocation using `shared_ptr` with `auto` type]
1092+
[Listing [shared-ptr-auto]: An example allocation using shared_ptr with auto type]
10961093

10971094
</div>
10981095

@@ -1159,7 +1156,7 @@
11591156

11601157
#endif
11611158
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1162-
[Listing [rtweekend-initial]: <kbd>[rtweekend.h]</kbd> The `rtweekend.h` common header]
1159+
[Listing [rtweekend-initial]: <kbd>[rtweekend.h]</kbd> The rtweekend.h common header]
11631160
</div>
11641161

11651162
<div class='together'>
@@ -1226,7 +1223,7 @@
12261223
std::cerr << "\nDone.\n";
12271224
}
12281225
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1229-
[Listing [main-with-rtweekend-h]: <kbd>[main.cc]</kbd> The new main with `hittables`]
1226+
[Listing [main-with-rtweekend-h]: <kbd>[main.cc]</kbd> The new main with hittables]
12301227
</div>
12311228

12321229
<div class='together'>
@@ -1279,7 +1276,7 @@
12791276
return min + (max-min)*random_double();
12801277
}
12811278
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1282-
[Listing [random-double]: <kbd>[rtweekend.h]</kbd> `random_double()` functions]
1279+
[Listing [random-double]: <kbd>[rtweekend.h]</kbd> random_double() functions]
12831280
</div>
12841281

12851282
<div class='together'>
@@ -1299,7 +1296,7 @@
12991296
return rand_generator();
13001297
}
13011298
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1302-
[Listing [random-double-alt]: <kbd>[rtweekend.h]</kbd> `random_double()`, alternate implemenation]
1299+
[Listing [random-double-alt]: <kbd>[rtweekend.h]</kbd> random_double(), alternate implemenation]
13031300
</div>
13041301

13051302

@@ -1344,7 +1341,7 @@
13441341
};
13451342
#endif
13461343
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1347-
[Listing [camera-initial]: <kbd>[camera.h]</kbd> The `camera` class]
1344+
[Listing [camera-initial]: <kbd>[camera.h]</kbd> The camera class]
13481345
</div>
13491346

13501347
To handle the multi-sampled color computation, we update the `vec3::write_color()` function. Rather
@@ -1360,7 +1357,7 @@
13601357
return x;
13611358
}
13621359
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1363-
[Listing [clamp]: <kbd>[rtweekend.h]</kbd> The `clamp()` utility function]
1360+
[Listing [clamp]: <kbd>[rtweekend.h]</kbd> The clamp() utility function]
13641361

13651362
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
13661363
void write_color(std::ostream &out, int samples_per_pixel) {
@@ -1376,7 +1373,7 @@
13761373
<< static_cast<int>(256 * clamp(b, 0.0, 0.999)) << '\n';
13771374
}
13781375
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1379-
[Listing [write-color-clamped]: <kbd>[vec3.h]</kbd> The `write_color()` function]
1376+
[Listing [write-color-clamped]: <kbd>[vec3.h]</kbd> The write_color() function]
13801377

13811378
<div class='together'>
13821379
Main is also changed:
@@ -1496,7 +1493,7 @@
14961493
return vec3(random_double(min,max), random_double(min,max), random_double(min,max));
14971494
}
14981495
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1499-
[Listing [vec-rand-util]: <kbd>[vec3.h]</kbd> `vec3` random utility functions]
1496+
[Listing [vec-rand-util]: <kbd>[vec3.h]</kbd> vec3 random utility functions]
15001497

15011498
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
15021499
vec3 random_in_unit_sphere() {
@@ -1507,7 +1504,7 @@
15071504
}
15081505
}
15091506
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1510-
[Listing [random-in-unit-sphere]: <kbd>[vec3.h]</kbd> The `random_in_unit_sphere()` function]
1507+
[Listing [random-in-unit-sphere]: <kbd>[vec3.h]</kbd> The random_in_unit_sphere() function]
15111508
</div>
15121509

15131510
<div class='together'>
@@ -1529,7 +1526,7 @@
15291526
return (1.0-t)*color(1.0, 1.0, 1.0) + t*color(0.5, 0.7, 1.0);
15301527
}
15311528
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1532-
[Listing [ray-color-random-unit]: <kbd>[main.cc]</kbd> `ray_color()` using a random ray direction]
1529+
[Listing [ray-color-random-unit]: <kbd>[main.cc]</kbd> ray_color() using a random ray direction]
15331530
</div>
15341531

15351532

@@ -1595,7 +1592,7 @@
15951592
std::cerr << "\nDone.\n";
15961593
}
15971594
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1598-
[Listing [ray-color-depth]: <kbd>[main.cc]</kbd> `ray_color()` with depth limiting]
1595+
[Listing [ray-color-depth]: <kbd>[main.cc]</kbd> ray_color() with depth limiting]
15991596
</div>
16001597

16011598
<div class='together'>
@@ -1639,7 +1636,7 @@
16391636
<< static_cast<int>(256 * clamp(b, 0.0, 0.999)) << '\n';
16401637
}
16411638
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1642-
[Listing [write-color-gamma]: <kbd>[vec3.h]</kbd> `write_color()`, with gamma correction]
1639+
[Listing [write-color-gamma]: <kbd>[vec3.h]</kbd> write_color(), with gamma correction]
16431640

16441641
</div>
16451642

@@ -1694,7 +1691,7 @@
16941691
return vec3(r*cos(a), r*sin(a), z);
16951692
}
16961693
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1697-
[Listing [random-unit-vector]: <kbd>[vec3.h]</kbd> The `random_unit_vector()` function]
1694+
[Listing [random-unit-vector]: <kbd>[vec3.h]</kbd> The random_unit_vector() function]
16981695

16991696
![Figure [rand-unit-vector]: Generating a random unit vector](../images/fig.rand-unitvector.png)
17001697

@@ -1724,7 +1721,7 @@
17241721
return (1.0-t)*color(1.0, 1.0, 1.0) + t*color(0.5, 0.7, 1.0);
17251722
}
17261723
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1727-
[Listing [ray-color-unit-sphere]: <kbd>[main.cc]</kbd> `ray_color()` with replacement diffuse]
1724+
[Listing [ray-color-unit-sphere]: <kbd>[main.cc]</kbd> ray_color() with replacement diffuse]
17281725
</div>
17291726

17301727
<div class='together'>
@@ -1782,7 +1779,7 @@
17821779
return -in_unit_sphere;
17831780
}
17841781
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1785-
[Listing [random-in-hemisphere]: <kbd>[vec3.h]</kbd> The `random_in_hemisphere(normal)` function]
1782+
[Listing [random-in-hemisphere]: <kbd>[vec3.h]</kbd> The random_in_hemisphere(normal) function]
17861783

17871784
</div>
17881785

@@ -1809,7 +1806,7 @@
18091806
return (1.0-t)*color(1.0, 1.0, 1.0) + t*color(0.5, 0.7, 1.0);
18101807
}
18111808
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1812-
[Listing [ray-color-hemisphere]: <kbd>[main.cc]</kbd> `ray_color()` with hemispherical scattering]
1809+
[Listing [ray-color-hemisphere]: <kbd>[main.cc]</kbd> ray_color() with hemispherical scattering]
18131810

18141811
Gives us the following image:
18151812

@@ -1860,7 +1857,7 @@
18601857

18611858
#endif
18621859
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1863-
[Listing [material-initial]: <kbd>[material.h]</kbd> The `material` class]
1860+
[Listing [material-initial]: <kbd>[material.h]</kbd> The material class]
18641861
</div>
18651862

18661863

@@ -2003,7 +2000,7 @@
20032000
color albedo;
20042001
};
20052002
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2006-
[Listing [lambertian-initial]: <kbd>[material.h]</kbd> The `lambertian` material class]
2003+
[Listing [lambertian-initial]: <kbd>[material.h]</kbd> The lambertian material class]
20072004
</div>
20082005

20092006
Note we could just as well only scatter with some probability $p$ and have attenuation be
@@ -2031,7 +2028,7 @@
20312028
return v - 2*dot(v,n)*n;
20322029
}
20332030
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2034-
[Listing [vec3-reflect]: <kbd>[vec3.h]</kbd> `vec3` reflection function]
2031+
[Listing [vec3-reflect]: <kbd>[vec3.h]</kbd> vec3 reflection function]
20352032
</div>
20362033

20372034
<div class='together'>
@@ -2351,7 +2348,7 @@
23512348

23522349
The value of $\sin\theta'$ cannot be greater than 1. So, if,
23532350

2354-
$$ \frac{1.5}{1.0} \cdot \sin\theta > 1.0 $$
2351+
$$ \frac{1.5}{1.0} \cdot \sin\theta > 1.0 $$,
23552352

23562353
<div class="together">
23572354
the equality between the two sides of the equation is broken and a solution cannot exist. If a
@@ -2655,9 +2652,9 @@
26552652
![Figure [cam-up]: Camera view up direction](../images/fig.cam-up.jpg)
26562653

26572654
Remember that `vup`, `v`, and `w` are all in the same plane. Note that, like before when our fixed
2658-
camera faced `-Z`, our arbitrary view camera faces `-w`. And keep in mind that we can -- but we
2659-
don’t have to -- use world up `(0,1,0)` to specify vup. This is convenient and will naturally keep
2660-
your camera horizontally level until you decide to experiment with crazy camera angles.
2655+
camera faced -Z, our arbitrary view camera faces -w. And keep in mind that we can -- but we don’t
2656+
have to -- use world up $(0,1,0)$ to specify vup. This is convenient and will naturally keep your
2657+
camera horizontally level until you decide to experiment with crazy camera angles.
26612658

26622659
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
26632660
class camera {

0 commit comments

Comments
 (0)