Skip to content

bvh_node is broken with negative-radius spheres #733

@define-private-public

Description

@define-private-public

I wanted to create some "Matryoshka hollow glass spheres", so I setup this scene:

    hittable_list world;

    const color ground_yellow(0.8, 0.8, 0);
    const color gold(0.8, 0.6, 0.2);
    const color blue(0.1, 0.2, 2);
    const color green(0.1, 0.9, 0.3);
    const double glass_refractive_index = 1.5;
    const auto ground_mat = make_shared<lambertian>(ground_yellow);
    const auto blue_mat   = make_shared<lambertian>(blue);
    const auto left_mat   = make_shared<dielectric>(glass_refractive_index);
    const auto center_mat = make_shared<lambertian>(green);
    const auto right_mat  = make_shared<metal>(gold, 1);
    const double tiny_y = 0.005;

    world.add(make_shared<sphere>(point3(-1,  tiny_y, -1),  0.5,  left_mat));
    world.add(make_shared<sphere>(point3(-1,  tiny_y, -1), -0.35, left_mat));
    world.add(make_shared<sphere>(point3(-1,  tiny_y, -1),  0.3,  left_mat));
    world.add(make_shared<sphere>(point3(-1,  tiny_y, -1), -0.2,  left_mat));
    world.add(make_shared<sphere>(point3(-1,  tiny_y, -1),  0.15, left_mat));
    world.add(make_shared<sphere>(point3(-1,  tiny_y, -1),  0.1,  blue_mat));
    world.add(make_shared<sphere>(point3( 0,  0.15 , -1),   .5,  center_mat));
    world.add(make_shared<sphere>(point3( 1,  tiny_y, -1),  0.5,  right_mat));
    world.add(make_shared<sphere>(point3( 0, -100.5, -1),   100,  ground_mat));   // The ground (Big boi)

    const bvh_node world_bvh(world, 0, 1); 

    point3 lookfrom(0, 0.25, 3.25);
    point3 lookat(0, 0, -1);
    auto vfov = 25.0;
    auto aperture = 0.0;
    color background = color(0.70, 0.80, 1.00);

    // Camera

    const vec3 vup(0,1,0);
    const auto dist_to_focus = (lookfrom - lookat).length();
    const int image_height = static_cast<int>(image_width / aspect_ratio);

    camera cam(lookfrom, lookat, vup, vfov, aspect_ratio, aperture, dist_to_focus, 0.0, 1.0);

When rendering on world, I get this, which is correct:
three_spheres_no_bvh

But when I render with world_bvh, this is the result:
three_spheres_bvh

I don't think that's right.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions