Webring Prev - Roscoe | Next - Elle >> My Git >> My Github

Trend: A C++ software ray-marching renderer

I wrote this software renderer when I was taking linear algebra in college to make sure I understood what was happening in terms of spacial intuition. It uses SDL and can render wavefront objects with simple UV mapped textures. The source code is on github.

The code is pretty small and in fairly basic C++ without much external library use. I use SDL to make windows and draw pixels, but I limited myself to only drawing single pixels at a time to ensure I actually understood what is going on. I’m sure many of the subroutines I wrote myself are woe-fully inefficient compared to more hardware-aware implementations, but it’s optimized enough to be workable. There is a somewhat naive thread pool implementation for rendering polygons in parallel.

More interestingly, it includes an algorithm for drawing triangles based on dividing them to have flat horizontal faces, and matrix inversion by Gausian elimination with some alterations to reduce floating point errors.

Were I to do this project again from scratch I think I would eshew all thread-level parallelism. I find now looking back that the design is unacceptably cluttered, and while it does speed things up, I’m confident I could achieve similar effects from more careful algorithmic tuning and higher level design changes. Rendering textures requires a lot of projecting back and forth, and some amount of fixed point arithmetic could be worth considering. Obviously this is all dust in the wind compared to a proper GPU render, but that’s hardly the spirit of the project. A slightly more efficient choice of primitives might be fruitful in this hypothetical redo. Either move the primitive operation provided by the backend up to rendering a single triangle, or choose a backend that has faster single pixel rendering. Also frankly C++ was never my favorite and has fallen considerably in my evaluation since writing this, so I would likely chose a different language were I to return. I don’t think the general design is that affected by language choice however.