<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Finite Improbability &#187; raytracing</title>
	<atom:link href="http://blog.finiteimprobability.com/category/graphics/raytracing/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.finiteimprobability.com</link>
	<description>Just programming and math, no spontaneously jumping undergarments</description>
	<lastBuildDate>Wed, 10 Mar 2010 17:56:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Moving to bitbucket&#8230;</title>
		<link>http://blog.finiteimprobability.com/2010/03/10/moving-to-bitbucket/</link>
		<comments>http://blog.finiteimprobability.com/2010/03/10/moving-to-bitbucket/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 17:56:28 +0000</pubDate>
		<dc:creator>Adam Jones</dc:creator>
				<category><![CDATA[compiler]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[raytracing]]></category>

		<guid isPermaLink="false">http://blog.finiteimprobability.com/?p=82</guid>
		<description><![CDATA[I&#8217;m moving my projects (yes, all two of them) to bitbucket. You&#8217;ll find them here
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m moving my projects (yes, all two of them) to bitbucket. You&#8217;ll find them <a href="http://bitbucket.org/awj/">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.finiteimprobability.com/2010/03/10/moving-to-bitbucket/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Experience writing a ray tracer in Haskell</title>
		<link>http://blog.finiteimprobability.com/2009/06/18/experience-writing-a-ray-tracer-in-haskell/</link>
		<comments>http://blog.finiteimprobability.com/2009/06/18/experience-writing-a-ray-tracer-in-haskell/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 02:25:53 +0000</pubDate>
		<dc:creator>Adam Jones</dc:creator>
				<category><![CDATA[haskell]]></category>
		<category><![CDATA[raytracing]]></category>

		<guid isPermaLink="false">http://blog.finiteimprobability.com/2009/06/18/experience-writing-a-ray-tracer-in-haskell/</guid>
		<description><![CDATA[I promised I would give a bit more in the way of details on the ray tracer. Here they are.

During the last three weeks of the term we were directed to come up with a &#8220;term project&#8221; for the functional programming course. [1] We needed to come up with something that was interesting and exercised [...]]]></description>
			<content:encoded><![CDATA[<p>I promised I would give a bit more in the way of details on the ray tracer. Here they are.</p>

<p>During the last three weeks of the term we were directed to come up with a &#8220;term project&#8221; for the functional programming course. [1] We needed to come up with something that was interesting and exercised the features we&#8217;d been learning about all term. I&#8217;ve wanted to write a ray tracer for a while now, so I picked that. The assignment, as I gave it to myself, was to write a minimal but complete ray tracer and report on the experience of profiling and parallelizing it.</p>

<p>The ray tracer itself took around 30 hours of work. Partially this was me struggling with the language, partially me struggling with the topic, and partially me being picky and/or making and fixing bad design decision. When I turned it in it would only do spheres in flat colors and reflection (or a combination) with specular and diffuse lighting. I&#8217;ve been working on transparency and diffraction, but that code isn&#8217;t really worth showing off yet. I&#8217;ll eventually do some more complicated shapes and may explore more interesting materials.</p>

<p>Writing a ray tracer in Haskell was a &#8230; luxurious experience. The heart of a ray tracer is almost entirely math, and Haskell represents that <em>very</em> well. The only real difference between my Haskell code and the math behind it was some additional let bindings I introduced while profiling. I enjoyed being able to avoid unnecessary computations implicitly through laziness, instead of explicitly through conditionals, as I would have needed to do in other languages.</p>

<p>I originally planned to spend a few hours working on parallelization. I started playing around with it for fun while I was waking up with coffee one morning. Half an hour and 53 characters later I had around a 40% speedup on two cores. In this, Haskell kind of ruined the project for me. It was too easy to introduce parallelization into the program and have it <em>just work</em>. A very helpful co-worker ran some benchmarks for me on a few systems. Here&#8217;s the performance chart.</p>

<p><a href="/wp-content/uploads/2009/06/performance-chart.png"><img src="/wp-content/uploads/2009/06/performance-chart.png" width=450 height=300>Performance chart</img></a></p>

<p>These results are rather informal, but you can see the impressive increases from parallel execution. I&#8217;m not entirely sure what is going on at the eight core mark, but I think it has something to do with an issue with (GHC only?) multicore support on Linux.</p>

<p>If you&#8217;d like to point and laugh at my code, you can find it <a href="/wp-content/uploads/2009/06/project.zip">here</a>. I compile it on ghc with &#8220;ghc -O -threaded -o ray &#8211;make Main.lhs&#8221;. Comments are very welcome.</p>

<p>[1] Taught by <a href="http://web.cecs.pdx.edu/~mpj/">Mark Jones</a> (the initial author of Hugs) and <a href="http://web.cecs.pdx.edu/~sheard/">Tim Sheard</a> (who is just FP brilliant) <em>amazing</em> class.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.finiteimprobability.com/2009/06/18/experience-writing-a-ray-tracer-in-haskell/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
