Skip to content

Commit 8fe1845

Browse files
trevordblackhollasch
authored andcommitted
Removed albedo from source.h and made source more consistent
1 parent 719e579 commit 8fe1845

File tree

2 files changed

+44
-31
lines changed

2 files changed

+44
-31
lines changed

books/RayTracingTheRestOfYourLife.html

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,7 +1747,6 @@
17471747
color color_from_scatter =
17481748
(attenuation * scattering_pdf * ray_color(scattered, depth-1)) / pdf;
17491749

1750-
17511750
return color_from_emission + color_from_scatter;
17521751
}
17531752
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -2412,11 +2411,15 @@
24122411

24132412
ray scattered;
24142413
color attenuation;
2415-
color color_from_emission = rec.mat->emitted(rec.u, rec.v, rec.p);
2414+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
24162415
double pdf;
2417-
color albedo;
2416+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
2417+
color color_from_emission = rec.mat->emitted(rec.u, rec.v, rec.p);
24182418

2419-
if (!rec.mat->scatter(r, rec, albedo, scattered, pdf))
2419+
2420+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
2421+
if (!rec.mat->scatter(r, rec, attenuation, scattered, pdf))
2422+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
24202423
return color_from_emission;
24212424

24222425

@@ -2436,11 +2439,12 @@
24362439

24372440
pdf = distance_squared / (light_cosine * light_area);
24382441
scattered = ray(rec.p, to_light, r.time());
2442+
2443+
double scattering_pdf = rec.mat->scattering_pdf(r, rec, scattered);
24392444
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
24402445

24412446
color color_from_scatter =
2442-
albedo * rec.mat->scattering_pdf(r, rec, scattered)
2443-
* ray_color(scattered, depth-1) / pdf
2447+
(attenuation * scattering_pdf * ray_color(scattered, depth-1)) / pdf;
24442448

24452449
return color_from_emission + color_from_scatter;
24462450
}
@@ -2628,11 +2632,10 @@
26282632

26292633
ray scattered;
26302634
color attenuation;
2631-
color color_from_emission = rec.mat->emitted(r, rec, rec.u, rec.v, rec.p);
26322635
double pdf_val;
2633-
color albedo;
2636+
color color_from_emission = rec.mat->emitted(r, rec, rec.u, rec.v, rec.p);
26342637

2635-
if (!rec.mat->scatter(r, rec, albedo, scattered, pdf_val))
2638+
if (!rec.mat->scatter(r, rec, attenuation, scattered, pdf_val))
26362639
return color_from_emission;
26372640

26382641

@@ -2642,9 +2645,10 @@
26422645
pdf_val = surface_pdf.value(scattered.direction());
26432646
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
26442647

2645-
color color_from_scatter = albedo
2646-
* rec.mat->scattering_pdf(r, rec, scattered)
2647-
* ray_color(scattered, depth-1) / pdf_val;
2648+
double scattering_pdf = rec.mat->scattering_pdf(r, rec, scattered);
2649+
2650+
color color_from_scatter =
2651+
(attenuation * scattering_pdf * ray_color(scattered, depth-1)) / pdf_val;
26482652

26492653
return color_from_emission + color_from_scatter;
26502654
}
@@ -2806,11 +2810,10 @@
28062810

28072811
ray scattered;
28082812
color attenuation;
2809-
color color_from_emission = rec.mat->emitted(r, rec, rec.u, rec.v, rec.p);
28102813
double pdf_val;
2811-
color albedo;
2814+
color color_from_emission = rec.mat->emitted(r, rec, rec.u, rec.v, rec.p);
28122815

2813-
if (!rec.mat->scatter(r, rec, albedo, scattered, pdf_val))
2816+
if (!rec.mat->scatter(r, rec, attenuation, scattered, pdf_val))
28142817
return color_from_emission;
28152818

28162819

@@ -2820,9 +2823,10 @@
28202823
pdf_val = light_pdf.value(scattered.direction());
28212824
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
28222825

2823-
color color_from_scatter = albedo
2824-
* rec.mat->scattering_pdf(r, rec, scattered)
2825-
* ray_color(scattered, depth-1) / pdf_val;
2826+
double scattering_pdf = rec.mat->scattering_pdf(r, rec, scattered);
2827+
2828+
color color_from_scatter =
2829+
(attenuation * scattering_pdf * ray_color(scattered, depth-1)) / pdf_val;
28262830

28272831
return color_from_emission + color_from_scatter;
28282832
}
@@ -2941,11 +2945,10 @@
29412945

29422946
ray scattered;
29432947
color attenuation;
2944-
color color_from_emission = rec.mat->emitted(r, rec, rec.u, rec.v, rec.p);
29452948
double pdf_val;
2946-
color albedo;
2949+
color color_from_emission = rec.mat->emitted(r, rec, rec.u, rec.v, rec.p);
29472950

2948-
if (!rec.mat->scatter(r, rec, albedo, scattered, pdf_val))
2951+
if (!rec.mat->scatter(r, rec, attenuation, scattered, pdf_val))
29492952
return color_from_emission;
29502953

29512954

@@ -2958,9 +2961,10 @@
29582961
pdf_val = mixed_pdf.value(scattered.direction());
29592962
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
29602963

2961-
color color_from_scatter = albedo
2962-
* rec.mat->scattering_pdf(r, rec, scattered)
2963-
* ray_color(scattered, depth-1) / pdf_val;
2964+
double scattering_pdf = rec.mat->scattering_pdf(r, rec, scattered);
2965+
2966+
color color_from_scatter =
2967+
(attenuation * scattering_pdf * ray_color(scattered, depth-1)) / pdf_val;
29642968

29652969
return color_from_emission + color_from_scatter;
29662970
}
@@ -3169,23 +3173,30 @@
31693173

31703174
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
31713175
scatter_record srec;
3176+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
31723177
color color_from_emission = rec.mat->emitted(r, rec, rec.u, rec.v, rec.p);
31733178

3179+
3180+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
31743181
if (!rec.mat->scatter(r, rec, srec))
3182+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
31753183
return color_from_emission;
31763184

3185+
3186+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
31773187
auto light_ptr = make_shared<hittable_pdf>(lights, rec.p);
31783188
mixture_pdf p(light_ptr, srec.pdf_ptr);
31793189

31803190
ray scattered = ray(rec.p, p.generate(), r.time());
31813191
auto pdf_val = p.value(scattered.direction());
3192+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
31823193

3183-
color color_from_scatter = (srec.attenuation
3184-
* rec.mat->scattering_pdf(r, rec, scattered)
3185-
* ray_color(scattered, depth-1)) / pdf_val;
3194+
double scattering_pdf = rec.mat->scattering_pdf(r, rec, scattered);
3195+
3196+
color color_from_scatter =
3197+
(srec.attenuation * scattering_pdf * ray_color(scattered, depth-1)) / pdf_val;
31863198

31873199
return color_from_emission + color_from_scatter;
3188-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
31893200
}
31903201
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
31913202
[Listing [ray-color-mixture]: <kbd>[scene.h]</kbd> The ray_color function, using mixture PDF]

src/TheRestOfYourLife/scene.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,14 @@ class scene {
7676

7777
auto light_ptr = make_shared<hittable_pdf>(lights, rec.p);
7878
mixture_pdf p(light_ptr, srec.pdf_ptr);
79+
7980
ray scattered = ray(rec.p, p.generate(), r.time());
8081
auto pdf_val = p.value(scattered.direction());
8182

82-
color color_from_scatter = (srec.attenuation
83-
* rec.mat->scattering_pdf(r, rec, scattered)
84-
* ray_color(scattered, depth-1)) / pdf_val;
83+
double scattering_pdf = rec.mat->scattering_pdf(r, rec, scattered);
84+
85+
color color_from_scatter =
86+
(srec.attenuation * scattering_pdf * ray_color(scattered, depth-1)) / pdf_val;
8587

8688
return color_from_emission + color_from_scatter;
8789
}

0 commit comments

Comments
 (0)