|
Finally. I got it right.
My class notes for this project have a picture
of a ray hitting an "instanced" object. The ray is labeled "free lunch".
Now realize, I did find when doing this implementation that these
inverse transformed rays flying around and hitting virtual objects
was sorta magical; there wasn't much that I had to do to get that
particular part to work. However, the
time I spent on
everything that had to happen around the basic instancing code
nullified any free lunch that might've been available. Free
lunches don't exist.
Special thanks goes to Brian Budge who
straightened me out and helped me fix what I was doing wrong.
Also, thanks to Nate Robins who let me modify his OBJ reader for
my ray tracer.
Looking back, the concepts are easy enough to
understand. I just had a total breakdown when it came to
what I was actually supposed to instance. I didn't even
think to instance the efficiency structure. Maybe I missed
that part of the lecture. I was instancing triangles and
throwing all of them (possibly all 1 billion of them) into my
bounding volume hierarchy (BVH) and my computer just decided that
that wasn't such a good idea. I ran out of physical RAM when
trying to instance over about 2-3 million triangles.
The key (as Brian pointed out) is to pack all
of the to-be-instanced triangles into one BVH and then instance
the BVH. Just throw the BVH pointer into your main object
list, fumble around with the bounding box of the instance, bake
it, and presto-magico, you're done! Doing this meant that I
didn't have to do a lot of the lower level things that I had been
trying to get right the last few days.
The great news is that instead of 3 million
triangles wanting to live in 1.5 GB, now I can get a billion of
them in just over 100 MB.
|