My first Haskell program and how easily I optimized it from 33m to 17s.

Image for post
Image for post
1800x1012 scene generated containing 533 objects rendered with 500 samples and 50,000 rays per pixel.

Background

Few weeks back, my colleague at work, Eyal Kalerdon, shared his implementation of ray-tracing-in-one-weekend in Rust, which inspired me to try this as well. I, however, chose Haskell for this, thinking I’ll not only learn ray tracing techniques but a new language as well. Haskell has been one of my favorite language for many years, as I often read about it but I never got any opportunity to actually write code in it.

Anyway, the implementation is pretty straightforward, as my only job was to port the C++ implementation from the article (which we both followed) to Haskell. …

Sarfaraz Nawaz

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store