Fixed a bug in BVH implementation
This commit is contained in:
parent
18bb6a250b
commit
e873ddac40
|
@ -20,8 +20,6 @@ impl<T: Hitable + Clone> BvhNode<T> {
|
||||||
.choose(rng)
|
.choose(rng)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
objects.sort_by(comparator);
|
|
||||||
|
|
||||||
let (left, right) = match objects.len() {
|
let (left, right) = match objects.len() {
|
||||||
1 => (
|
1 => (
|
||||||
HitNode::Direct(objects[0].clone()),
|
HitNode::Direct(objects[0].clone()),
|
||||||
|
@ -39,6 +37,7 @@ impl<T: Hitable + Clone> BvhNode<T> {
|
||||||
},
|
},
|
||||||
|
|
||||||
n => {
|
n => {
|
||||||
|
objects.sort_by(comparator);
|
||||||
let (l, r) = objects.split_at_mut(n / 2);
|
let (l, r) = objects.split_at_mut(n / 2);
|
||||||
(
|
(
|
||||||
HitNode::Bvh(Box::new(BvhNode::new(rng, l, t0, t1))),
|
HitNode::Bvh(Box::new(BvhNode::new(rng, l, t0, t1))),
|
||||||
|
@ -94,7 +93,9 @@ impl<T: Hitable + Clone> BvhNode<T> {
|
||||||
|
|
||||||
impl<T: Hitable> Hitable for BvhNode<T> {
|
impl<T: Hitable> Hitable for BvhNode<T> {
|
||||||
fn hit(&self, ray: &Ray, t_min: f64, t_max: f64) -> Option<HitRecord> {
|
fn hit(&self, ray: &Ray, t_min: f64, t_max: f64) -> Option<HitRecord> {
|
||||||
self.bounding_box(t_min, t_max)?;
|
if !self.bounding_box.hit(ray, t_min, t_max) {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
let hbox_left = self.left.hit(ray, t_min, t_max);
|
let hbox_left = self.left.hit(ray, t_min, t_max);
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
use crate::BvhNode;
|
|
||||||
|
|
||||||
use {
|
use {
|
||||||
crate::{
|
crate::{
|
||||||
types::{
|
types::{
|
||||||
material::{Dielectric, Lambertian, Metal},
|
material::{Dielectric, Lambertian, Metal},
|
||||||
MovingSphere, Ray, Sphere, Vec3,
|
MovingSphere, Ray, Sphere, Vec3,
|
||||||
},
|
},
|
||||||
Camera, Hitable, HORIZONTAL_PARTITION, VERTICAL_PARTITION,
|
BvhNode, Camera, Hitable, HORIZONTAL_PARTITION, VERTICAL_PARTITION,
|
||||||
},
|
},
|
||||||
rand::{rngs::SmallRng, Rng, SeedableRng},
|
rand::{rngs::SmallRng, Rng, SeedableRng},
|
||||||
rayon::prelude::*,
|
rayon::prelude::*,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user