Bounding Boxes and Big Meshes

Lately I’ve been taking a break from fractals and Gizmo Gears experiments to improve the ray tracing code under the hood.  I’ve made some nice improvements, taking the opportunity to learn about templates in C++ along the way.  Many of these things are low level and may seem boring, but they are forming a more solid foundation as I move forward.

  1.  I rewrote my vector class as a fully templated class.  Types across the renderer can now be set by changing a single preprocessor directive!  This was a large, deep change to the code.
  2. I removed the point class, which was redundant, and replaced it with the vector class in all cases.
  3. I also rewrote the matrix class as a templated class, adding improved support for operators.
  4. Mesh input for .X files and .OBJ files has been vastly improved.  Now there is support for multiple meshes with many variations and quirks in the structure of the input files allowed.  This was accomplished by downloading various model files and further improving the file input code to support all the samples.
  5. The .X and .OBJ file reader can now support multiple meshes.
  6. .X and .OBJ files are now specified as primitives in the input .SCN files.  The user can use the primitive declaration to override materials on the input file, set a mesh name, and/or declare whether two-sided polygons should be used.  In the image below, the dice are overriden with a red glass material, and the chrome ammonite and green barrel have also been given custom materials.
  7. The rtPolygon and rtTriangle classes have been merged into rtPolygon, and all instances rtTriangle was being used have been updated to use rtPolygon instead.  This should make supporting meshes much cleaner going forward.
  8. Treatment of mesh normals has been re-written.  Meshes have much more support for vertex normals coming in from the model source file instead of always being constructed from the polygon face.
  9. Bounding box support has finally been added for meshes, and the bounding box intersection code has been completed after sitting half-baked for 10 years!  Now bounding boxes are used to accelerate intersection tests on scenes with many large meshes.  In the image below, the meshes are simple looking, but are quite dense.  The barrel is 65,000 polygons, for example.

I know that may not be that much fun to read, and it may not sound that exciting, but it was crucial to improve my foundation before getting into more exotic acceleration structures like grids, BVH, and kd-trees.  In fact, there’s much more foundation work to be done going forward, like separating shading code into a separate set of classes, and improving the accuracy of my camera model and color science.  One thing at a time, it will get there!


A rendered test scene showing multiple meshes rendered together using bounding box acceleration.

Bounding boxes make possible the rendering of many dense meshes by speeding up intersection tests.

Leave a Reply

Your email address will not be published. Required fields are marked *