• Advertisement
Sign in to follow this  

A "reference" software-only 3D renderer (GPL)

This topic is 3024 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, everyone. One of my hobbies that has persisted over the years, is working on a real-time software-only 3D renderer that I began writing in the days of Hercules and CGA cards. "Working" in this context, means trying to make it (a) clearer in terms of code, and (b) faster in terms of execution. Oh, and enjoying the process :-) The complete source code is available here: http://users.softlab.ece.ntua.gr/~ttsiod/renderer.html It has evolved to a pretty nice state, with the following features: - 3D transformations (object => world => camera coordinates) - Point rendering (vertex-based or triangle-based) - Gouraud shading (complete Phong equation calculated per vertex) - Phong shading (complete Phong equation calculated per pixel) - Z-Buffer - Shadow mapping (with/without soft shadows) - Display and keyboard handling (concurrent keypresses) through libSDL - Extensive use of C++ templates ("metaprogramming") to avoid code duplication (e.g. one scan converter drives ALL rendering modes) - Uses OpenMP or Intel Thread Building Blocks to take advantage of multi-cores. - Extremely portable: runs on Linux, Windows, Free/Net/OpenBSD, Mac OS/X, etc - For Unix-based OSes (as well as Windows/MinGW), uses autoconf/automake. - Includes MSVC solution with all dependencies pre-packaged (made with the free Visual C++ Express). I have been hacking on it, on and off, for more than a decade, and I admit I find it very rewarding as a hobby, so I thought I'd just share it here, as a "reference" implementation of many basic 3D algorithms. Hope you'll like it... I definitely enjoyed (and still enjoy) developing it. Thanassis Tsiodras, Dr.-Ing. ttsiodras at removeMe gmail dot com

Share this post


Link to post
Share on other sites
Advertisement
This is nice. I've been working on a software renderer engine for many years. At the end, I had a ASM renderer with occlusion culling that was powering a Quake2-like game. Cool. But it was kinda slow without any per pixel calculation.

How do you expect to implement shadow mapping and phong shading ?

you're crazy :-P

Share this post


Link to post
Share on other sites
This is a nice gesture for the community, and I suspect it will be quite useful in the years to come. There have been several high level interviews that discuss eventually moving to software driven architectures for rendering, so it is always nice to have clean and easy to understand implementations to draw from. I have bookmarked your page, and look forward to reading through more of the code!

Share this post


Link to post
Share on other sites
Thanks for your kind words, guys.

I got some nice mail responses, too, which drove me to cleanup the code some more. Runs faster, too :-)

And speaking of speed, and why I may not be as crazy... the top report I got from a user of a 4-core AMD Phenom machine at 3.2GHz was more than 50fps for a 65K triangles obejct, i.e. 3.2Mtris/sec - doing per-pixel phong and soft shadow maps. Nice, no?

Oh, I so want to see what will happen when Larabee comes :-)

Thanassis.

Share this post


Link to post
Share on other sites
Quote:
Original post by ttsiodras
And speaking of speed, and why I may not be as crazy... the top report I got from a user of a 4-core AMD Phenom machine at 3.2GHz was more than 50fps for a 65K triangles obejct, i.e. 3.2Mtris/sec - doing per-pixel phong and soft shadow maps. Nice, no?
You default model clocks over 50 fps with soft shadowing on my AMD quad 3.0GHz machine - kudos!

Share this post


Link to post
Share on other sites

Wow, this guy's code really rocks, look:

void Scene::renderPhongAndSoftShadowed(const Camera& eye, Screen& canvas)
{
RenderInParallel<
true,
FatPointPhongAndShadowed,
TriangleInfoPhongAndShadowed,
FillerPhongAndShadowed>(
*this,
eye,
canvas,
_objects);
}


He uses C++ templates like a configurable code generator, passing different types for different render modes... Excellent!

Share this post


Link to post
Share on other sites
... and as I opened the page, I realized this has been in my bookmarks for a long time. Same university, too. :)

Great code and awesome platform support - two thumbs up!

Share this post


Link to post
Share on other sites

Thanks :-)

Responding to xtaledo: C++ templates have amazing power that is not visible at first sight - it took me years to realize what one can do with them. "Modern C++ Design" by Andrei Alexandrescu was an eye-opener - if you code in C++ you simply *have* to read this book. It will change the way you think about things... just allocate enough brain power (and time) to let it sink in.

Share this post


Link to post
Share on other sites

New version uploaded - now uses dynamic scheduling (for both OpenMP and TBB) and thus achieves much better utilization of available CPUs/cores (the train object rendering speed jumped by a whopping 40%). The speedup is much more pronounced for lower tesselations, and truth be told, all but vanishes for large meshes (since the thread load is balanced anyway).

Available in GPL, as ever, from here:

http://users.softlab.ntua.gr/~ttsiod/renderer.html

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement