Skip to content

Commit b58f882

Browse files
authored
Merge branch 'dev-patch' into fix-609
2 parents 9bd2580 + 8ce483f commit b58f882

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Change Log -- Ray Tracing in One Weekend
88

99
### _The Rest of Your Life_
1010
- Fix: Missing closing parenthesis in listing 10 (#603)
11+
- Fix: Tiny improvements to the lambertian::scatter() development (#604)
1112

1213

1314
----------------------------------------------------------------------------------------------------

books/RayTracingTheRestOfYourLife.html

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -854,8 +854,8 @@
854854
virtual bool scatter(
855855
const ray& r_in, const hit_record& rec, color& alb, ray& scattered, double& pdf
856856
) const {
857-
point3 target = rec.p + rec.normal + random_unit_vector();
858-
scattered = ray(rec.p, unit_vector(target-rec.p), r_in.time());
857+
auto direction = rec.normal + random_unit_vector();
858+
scattered = ray(rec.p, unit_vector(direction), r_in.time());
859859
alb = albedo->value(rec.u, rec.v, rec.p);
860860
pdf = dot(rec.normal, scattered.direction()) / pi;
861861
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
@@ -925,13 +925,17 @@
925925
randomly from the hemisphere above the surface. This would be $p(direction) = \frac{1}{2\pi}$.
926926

927927
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
928-
bool scatter(
928+
virtual bool scatter(
929929
const ray& r_in, const hit_record& rec, color& alb, ray& scattered, double& pdf
930930
) const {
931-
vec3 direction = random_in_hemisphere(rec.normal);
931+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
932+
auto direction = random_in_hemisphere(rec.normal);
933+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
932934
scattered = ray(rec.p, unit_vector(direction), r_in.time());
933935
alb = albedo->value(rec.u, rec.v, rec.p);
936+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
934937
pdf = 0.5 / pi;
938+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
935939
return true;
936940
}
937941
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -1287,13 +1291,13 @@
12871291
We can rewrite our Lambertian material using this to get:
12881292

12891293
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
1290-
bool scatter(
1294+
virtual bool scatter(
12911295
const ray& r_in, const hit_record& rec, color& alb, ray& scattered, double& pdf
12921296
) const {
12931297
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
12941298
onb uvw;
12951299
uvw.build_from_w(rec.normal);
1296-
vec3 direction = uvw.local(random_cosine_direction());
1300+
auto direction = uvw.local(random_cosine_direction());
12971301
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
12981302
scattered = ray(rec.p, unit_vector(direction), r_in.time());
12991303
alb = albedo->value(rec.u, rec.v, rec.p);
@@ -1944,7 +1948,9 @@
19441948
lambertian(shared_ptr<texture> a) : albedo(a) {}
19451949

19461950
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
1947-
bool scatter(const ray& r_in, const hit_record& rec, scatter_record& srec) const {
1951+
virtual bool scatter(
1952+
const ray& r_in, const hit_record& rec, scatter_record& srec
1953+
) const {
19481954
srec.is_specular = false;
19491955
srec.attenuation = albedo->value(rec.u, rec.v, rec.p);
19501956
srec.pdf_ptr = new cosine_pdf(rec.normal);

0 commit comments

Comments
 (0)