raytracing.github.io icon indicating copy to clipboard operation
raytracing.github.io copied to clipboard

[Suggestion] [Book 2] Add an example for Chapter 3

Open rongguodong opened this issue 5 years ago • 1 comments

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 image to image 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.

rongguodong avatar Aug 27 '20 21:08 rongguodong

[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.

hollasch avatar Sep 15 '20 07:09 hollasch

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));

```

Srikrishna31 avatar Feb 15 '23 17:02 Srikrishna31

For anyone reading the book from top to bottom would be confused and would have to look for this issue.

Srikrishna31 avatar Feb 15 '23 17:02 Srikrishna31

It turns out that this was fixed in 49c1e1ea1c1f3fcaaa39ec2babdb54ed901987d0, PR #855. It's currently in branch dev-major.

hollasch avatar May 10 '23 23:05 hollasch