Meta-Programming Raytracer (3/3)

This is my last post about how I developed a compile-time raytracer based on Boost::MPL and on custom classes (source code available at the bottom of the post).

During the process, I learned a lot about MPL, which I only knew basically. To sum up, I learned how to:

  • use almost all MPL classes
  • add new basic types, and make them compatible with standard mpl operators like mpl::plus, mpl::times
  • workaround the compiler limitations by deriving classes to separate code
  • develop my own classes compatible with the Forward Sequence concept
  • develop my own iterators compatible with the Forward Iterator concept

Complete code source is available here. Enjoy!

The version of the source code available for download doesn’t contain my latest changes. At run-time, the image is written tile by tile, but the put() method used to write pixel to the images is actually sequential, so it should be used line by line, not tile by tile. The raytracer is therefore not fully functional, but my idea of putting the source here is more to give insights on the meta programming part, and the run-time part is not of great interest, so I didn’t think it really matters if the image is written in the correct order.

3 Responses

  1. phresnel Says:

    Good exercise :)

    Have I understood the sourcecode right, that it renders a single, green but otherwise unshaded sphere?

  2. phresnel Says:

    Have I grasped it right, that your scene supports exactly one hardcoded sphere?

    Then, is it right that you basically draw green pixels where the sphere is hit, and black pixels where not, so no shading and shadow tracing?

    Greets,

    phresnel

  3. Ben Says:

    Thanks for the comments, and for reading the source code! I hope you found it useful!

    You’re right, it renders a single sphere..and only an orthographic projection is performed. So if you “render” a 32×32 image, you’ll get a different image from a 64×64 for instance.

    Shading is left as an exercise for the reader ;) It’s of course possible, and would be interesting to try, but..yeah, as you spotted it was more an exercise, just to see what was capable with MPL, and to get used to it. I can’t really see a real-world use for this…

    I stopped at some point because it was getting more and more difficult to cope with the compiler limitations…and I got busy with some other stuff!

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.