c programming

[Greg] implemented a simple ray tracer for Arduino as a fun exercise and a way to benchmark the processor. He started out with the Moller-Trumbore algorithm, a common ray-tracing algorithm that calculates the intersection of a ray with a triangular plane without doing any pre-calculation of the planes. His code supports one static light and one static camera, which is enough to render a simple scene.

[Greg] started out with a small scene composed of a few polygons, but just finished up a scene with 505 vertices, 901 faces, and reflective surfaces (shown above). He made the above render on his PC emulator, but estimates that it would take just over 4 days to render on the Arduino. [Greg]’s project supports multiple bounces of light, which differentiates his ray tracer from some we’ve covered before (and which explains why it takes so long to render).

The ray tracer is implemented entirely with double-precision floats. This translates to a ton of software float emulation instructions, since the Arduino doesn’t have a floating-point unit. While this ray tracer can’t render anything near real-time graphics due to the slowness of the microcontroller, it’s still a great proof of concept.

The title image for this post was rendered on a modern PC, taking 263 seconds to complete. The same scene, at 64×64 resolution, was rendered on the Arduino, taking 4008 seconds to complete. That render is below.

The International Obfuscated C Code Contest is back. The stated goals of the IOCCC are to, “Write the most obscure C program, show the importance of programming style (by doing the opposite), stress the preprocessor to the breaking point, and illustrate some subtleties of the C language.” If you think you’re up to the task of abusing your compiler, check out the rules and guidelines for the contest.

There’s nothing quite like having the code for a flight simulator look like a plane, or calculating pi by measuring the area of C code. The submissions to the IOCCC are classic hacks; very clever things that shouldn’t work, but do despite themselves.