Closed jalberse closed 1 year ago
If we're building a BVH, we might want to look at implementing it differently than common C++ examples to avoid lifetime issues.
A similar problem dealing with graphs in a different way: https://rust-school.io/writing/overcoming-lifetimes/
We might also just use a BVH crate:
https://docs.rs/bvh/latest/bvh/bvh/struct.BVH.html
https://github.com/svenstaro/bvh
This is probably ideal, since I doubt I get optimization up to that standard.
But, it might be a bit annoying to hook up that BVH representation with my architecture, where a BVH node should be Hittable. And, well, this can be a learning exercise.
Before merging this, I would really like to see a benchmark comparison of the before/after to get an idea of the performance increase we see.
A test render with Bvh in did work. I will do some small improvements and benchmarking then merge.
Right now, I'm implementing the Bvh via a single BvhNode class with Rc references to the left and right child.
I don't think that's very idiomatic Rust. We may want to change it to a flatter structure without smart pointers, maybe arena-based. But for now, we'll say this is good unless benchmarking shows issues.
For the same scene:
So, for this scene, we have a 7x speed-up. I'm sure that could be improved further, but for now I think it is a good idea to merge and resolve this for now.
We'll follow https://raytracing.github.io/books/RayTracingTheNextWeek.html#boundingvolumehierarchies
I'd like to get this done early, since it should speed up iteration during development.