|
Just when you thought ray tracing was
easy...you find that you can't render anything of any significance
in your lifetime with a naive, brute force, ray tracer.
Here, I implement a hierarchal data structure based on bounding
volumes to shorten render time of a large number of primitives.
After this code change, I can render a million spheres in under
one minute where a brute force method would've taken hours to complete. The images shown below
are rendering of 100, 1000, 10,000, 100,000, and one million
random spheres, respectively. All spheres fit within the
viewing space. Lighting and shadows are still turned on.
All tests were done on a Dell desktop with an Intel Pentium 4 1.8
GHz processor with 1.0GB of RDRAM running Microsoft Windows XP.
Compilation was done with Microsoft Visual C++ Standard, Version
6.0 and the new Microsoft Visual C++ .NET Professional**. Output size for each was 500x500 pixels.
For my classmates: I'm using STL's nth_element() to sort objects
based on varying axes and only minor modifications to Pete's code.
Profiled code from VS.NET says that I spend 57% of runtime in
box::hitbox() and 32% in bvhNode:hit. Interestingly enough,
the next most used function is fscanf() at 3.5%.
**Note: The standard version of VC++6 has no or little compiler
optimizations. At the time of this writing, I've just
obtained Visual Studio .NET. VS.NET not only has an
optimized compiler, but it can also optimize across .obj files for
global optimization. Note that the VC++.NET code is 38%
faster than the VC++6 code for one million spheres. |