{"id":295,"date":"2014-11-23T21:45:54","date_gmt":"2014-11-23T21:45:54","guid":{"rendered":"http:\/\/greg-kennedy.com\/wordpress\/?p=295"},"modified":"2014-11-23T21:45:54","modified_gmt":"2014-11-23T21:45:54","slug":"arduino-raytracer","status":"publish","type":"post","link":"https:\/\/greg-kennedy.com\/wordpress\/2014\/11\/23\/arduino-raytracer\/","title":{"rendered":"Arduino Raytracer"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/farm8.staticflickr.com\/7054\/13898704895_72c6b8a604_o.png\" width=\"640\" height=\"640\" class=\"alignleft\" \/> Every programmer worth his salt has written a raytracer of some sort.  It&#8217;s one of the classic &#8220;recursion exercises&#8221;, with a fair amount of math to wrap your head around.  I&#8217;m not interested in writing one to run on the PC &#8211; there are already far more capable ones that can run on pretty much any hardware, complete with optimizations and features I couldn&#8217;t hope to implement in my lifetime.<\/p>\n<p>Instead, I decided to write a raytracer which targets the Atmega 328 microcontroller in my Arduino!  In the end, I succeeded in banging one together that calculates ray-triangle intersection, and each triangle can have a material attached with ambient \/ diffuse \/ transparent \/ reflective values and an RGB color.  The scene is compiled in with a .h file (stored in PROGMEM), and outputs a PPM image pixel-by-pixel over the serial port.<\/p>\n<p>The same engine can be used on the PC with a few modifications, so I was able to benchmark the performance of the Arduino in comparison with a modern laptop.  The &#8220;detailed scene&#8221; rendered a 640&#215;640 image in 263 seconds on the laptop.  The same scene, scaled to only 64&#215;64, still took 4008.471 seconds&#8230; in other words, the PC outperformed the Arduino by a factor of ~1500.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/farm8.staticflickr.com\/7546\/15675208668_6f9797004e_o.png\" width=\"640\" height=\"640\" class=\"alignright\" \/> I posted the code, and further write-up, on the Arduino.cc message board at this link: <a href=\"http:\/\/forum.arduino.cc\/index.php?topic=281076.0\">http:\/\/forum.arduino.cc\/index.php?topic=281076.0<\/a>.  There are a lot of features that COULD be added here, but none that I actually intend to do.  If I need a raytracer in the future, I&#8217;m just downloading POVRay : )<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Every programmer worth his salt has written a raytracer of some sort. It&#8217;s one of the classic &#8220;recursion exercises&#8221;, with a fair amount of math to wrap your head around. I&#8217;m not interested in writing one to run on the PC &#8211; there are already far more capable ones that can run on pretty much [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-295","post","type-post","status-publish","format-standard","hentry","category-software"],"_links":{"self":[{"href":"https:\/\/greg-kennedy.com\/wordpress\/wp-json\/wp\/v2\/posts\/295","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/greg-kennedy.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/greg-kennedy.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/greg-kennedy.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/greg-kennedy.com\/wordpress\/wp-json\/wp\/v2\/comments?post=295"}],"version-history":[{"count":2,"href":"https:\/\/greg-kennedy.com\/wordpress\/wp-json\/wp\/v2\/posts\/295\/revisions"}],"predecessor-version":[{"id":298,"href":"https:\/\/greg-kennedy.com\/wordpress\/wp-json\/wp\/v2\/posts\/295\/revisions\/298"}],"wp:attachment":[{"href":"https:\/\/greg-kennedy.com\/wordpress\/wp-json\/wp\/v2\/media?parent=295"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/greg-kennedy.com\/wordpress\/wp-json\/wp\/v2\/categories?post=295"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/greg-kennedy.com\/wordpress\/wp-json\/wp\/v2\/tags?post=295"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}