raytracing.github.io
raytracing.github.io copied to clipboard
[Suggestion] [Book 2] Add an example for Chapter 3
I really like the style of Book 1, where in each chapter we have some code to test the content of that chapter and see some concrete results. However, when I finished Chapter 3 of Book 2 (Bounding Volume Hierarchies), I realized that although we have lots of new codes, they are NOT used in the main program. So I tried to change the main program a little bit to use the codes in Chapter 3, and it turns out very simple changes can greatly improve the performance, which is the reason why we use BVH.
We only need to change the world part from
to
This simple change demonstrated the contents in Chapter 3 very well. Although the generated image is the same as before, the speed is much faster.
[Also from the original email:]
Replace the second argument of function call to "ray_color", i.e. changing this line
pixel_color += ray_color(r, world, max_depth);
to
pixel_color += ray_color(r, *world_bvh, max_depth);
These simple changes demonstrated the contents in Chapter 3 very well. Although the generated image is the same as before, the speed is much faster.
Just doing the final rendering scene of the book, and here it is shown how to use it:
hittable_list final_scene() {
hittable_list boxes1;
auto ground = make_shared<lambertian>(color(0.48, 0.83, 0.53));
const int boxes_per_side = 20;
for (int i = 0; i < boxes_per_side; i++) {
for (int j = 0; j < boxes_per_side; j++) {
auto w = 100.0;
auto x0 = -1000.0 + i*w;
auto z0 = -1000.0 + j*w;
auto y0 = 0.0;
auto x1 = x0 + w;
auto y1 = random_double(1,101);
auto z1 = z0 + w;
boxes1.add(make_shared<box>(point3(x0,y0,z0), point3(x1,y1,z1), ground));
}
}
hittable_list objects;
objects.add(make_shared<bvh_node>(boxes1, 0, 1));
```
For anyone reading the book from top to bottom would be confused and would have to look for this issue.
It turns out that this was fixed in 49c1e1ea1c1f3fcaaa39ec2babdb54ed901987d0, PR #855. It's currently in branch dev-major.