|
Assignment 5 – Bounding Volume Hierarchy |
||||||
|
When
wanting to draw many polygons it is not realistic to think of producing an
image in any short period of time by cycling through every object for every
ray. This is especially true when
wanting to do anti-aliasing and hence sampling multiple rays per pixel. |
||||||
|
A
way around this is by bounding groups of polygons into boxes and checking the
box first to see if the ray went through it.
When the ray misses that box completely then there is no need to check
any of the polygons bounded by that box.
This save huge amounts of time when you’re speaking of drawing scenes
with over a million polygons. |
||||||
|
For
example the Stanford Buddah contains 543,652 vertices and 1,087,716
triangles. I built bounding boxes
around groups of these polygons by dividing them along different axis on my
way down to having one polygon to check.
Somehow my times haven’t turned out great and running gprof shows that
the bounding box hitBox() function is what takes the most time. But it looks like what was discussed in class. So I think I must be taking a hit
somewhere else. double tmin, tmax, temp_min, temp_max; Vector3 eye = ray.origin(); Vector3 direction = ray.direction(); // dividing once here gets rid of extra
divides. double temp = 1 / direction.x(); // now just check against temp instead
of direction.x if( temp > 0 ) { tmin = ( min_.x() - eye.x() ) * temp; tmax = ( max_.x() - eye.x() ) * temp; } else { tmin = ( max_.x() - eye.x() ) * temp; tmax = ( min_.x() - eye.x() ) * temp; } // divide again for y temp = 1 / direction.y(); if( temp > 0 ) { temp_min = ( min_.y() - eye.y() ) *
temp; temp_max = ( max_.y() - eye.y() ) *
temp; } . . . |
||||||
|
Compiler |
Num Samples |
BVH build |
Ray-trace |
Total |
||
|
Visual
Studio 6.0 |
1 |
118.632
sec |
130.858
sec |
249.49
sec (4 min) |
||
|
Visual
Studio 6.0 |
25 |
115.868
sec |
3606.256
sec (1 hr) |
3722.124
sec |
||
|
g++
-O3 |
1 |
130.750
sec |
122.730
sec |
253.480
sec |
||
|
g++
-O3 |
25 |
204.820
sec |
3600.00+
sec |
3804.82+
sec |
||
|
1 sample per
pixel |
25 samples per pixel |
1 sample marble buddah |
||||