jalberse / RayTracingInOneWeekendInRust

Ray Tracing In One Weekend, in Rust
1 stars 0 forks source link

Add Bounding Volume Hierarchies #14

Closed jalberse closed 1 year ago

jalberse commented 1 year ago

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.

jalberse commented 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/

jalberse commented 1 year ago

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.

jalberse commented 1 year ago

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.

jalberse commented 1 year ago

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.

jalberse commented 1 year ago

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.

jalberse commented 1 year ago

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.