# Ray Tracing in One Weekend

**URL:** https://discourse.haskell.org/t/ray-tracing-in-one-weekend/10078
**Category:** Show and Tell
**Created:** [August 2, 2024, 11:12am UTC](https://discourse.haskell.org/t/ray-tracing-in-one-weekend/10078 "2024-08-02T11:12:37Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![wiz](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/wiz/32/2408_2.png) [@wiz](https://discourse.haskell.org/u/wiz)
#### Post date: [August 2, 2024, 11:12am UTC](https://discourse.haskell.org/t/ray-tracing-in-one-weekend/10078/1 "2024-08-02T11:12:37Z")

</div>

I’ve wanted to do this particular [kata](https://raytracing.github.io/books/RayTracingInOneWeekend.html) for a long time and finally got to it.

> **[IC Rainbow / rtow · GitLab](https://gitlab.com/dpwiz/rtow/)**
>
> Ray Tracing in One Weekend

There are some post hoc [notes](https://gitlab.com/dpwiz/rtow/-/blob/main/notes/week-1.md) I’ve written down if you’re interested in reading stream of grumpy remarks (with the pictures of the intermediate steps!).

---

<div class="post-metadata">

### Author: ![waivio](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/waivio/32/1354_2.png) [@waivio](https://discourse.haskell.org/u/waivio)
#### Post date: [August 2, 2024, 7:32pm UTC](https://discourse.haskell.org/t/ray-tracing-in-one-weekend/10078/2 "2024-08-02T19:32:01Z")

</div>

Thank you for your contribution. I enjoyed it completely. I love that you used `massiv` I think that it is a awesome library that demonstrates Haskell’s laziness allowing fusion and control over evaluation for parallel and concurrent programming. I’m not gonna lie `geomancy` is really giving me some SIMD envy. This is a good example of Haskell’s numerical strengths. I hope to contribute in this way more in the future. I also hope to see more contributions from you.

---

<div class="post-metadata">

### Author: ![Bodigrim](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/bodigrim/32/1457_2.png) [@Bodigrim](https://discourse.haskell.org/u/Bodigrim)
#### Post date: [August 2, 2024, 8:15pm UTC](https://discourse.haskell.org/t/ray-tracing-in-one-weekend/10078/3 "2024-08-02T20:15:12Z")

</div>

> Found out there’s a gotcha then adding multiple `-with-rtsopts` args in a package. Had to collect them into one pile of `- '"-with-rtsopts=-s -N -A64m"'` to avoid the repeated overwriting of it. Gotta check the rest of my packages for this…

This is [#18117: It's not possible to specify multiple `-with-rtsopts` flags · Issues · Glasgow Haskell Compiler / GHC · GitLab](https://gitlab.haskell.org/ghc/ghc/-/issues/18117), it might be helpful to chime in there.

---

<div class="post-metadata">

### Author: ![Bodigrim](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/bodigrim/32/1457_2.png) [@Bodigrim](https://discourse.haskell.org/u/Bodigrim)
#### Post date: [August 2, 2024, 8:17pm UTC](https://discourse.haskell.org/t/ray-tracing-in-one-weekend/10078/4 "2024-08-02T20:17:44Z")

</div>

> The `interval` class is just a pair of numbers, with extra functions. I briefly dived into Hackage archives, but the solutions are way to complex for the task.

There is indeed a zoo of libraries for intervals on Hackage. As a maintainer of [data-interval: Interval datatype, interval arithmetic and interval-based containers](https://hackage.haskell.org/package/data-interval), I’m curious if you can identify any possible improvements.

---

<div class="post-metadata">

### Author: ![wiz](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/wiz/32/2408_2.png) [@wiz](https://discourse.haskell.org/u/wiz)
#### Post date: [August 3, 2024, 3:30pm UTC](https://discourse.haskell.org/t/ray-tracing-in-one-weekend/10078/5 "2024-08-03T15:30:51Z")

</div>

I ended up removing the `Interval` entirely. It was only needed to find the closest positive hit (if any).  
The next book has BVH building chapter and I’m going to take `data-interval` for a walk.

---

<div class="post-metadata">

### Author: ![romes](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/romes/32/2912_2.png) [@romes](https://discourse.haskell.org/u/romes)
#### Post date: [August 3, 2024, 10:14pm UTC](https://discourse.haskell.org/t/ray-tracing-in-one-weekend/10078/6 "2024-08-03T22:14:19Z")

</div>

What’s the next book?

---

<div class="post-metadata">

### Author: ![wiz](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/wiz/32/2408_2.png) [@wiz](https://discourse.haskell.org/u/wiz)
#### Post date: [August 4, 2024, 8:23am UTC](https://discourse.haskell.org/t/ray-tracing-in-one-weekend/10078/7 "2024-08-04T08:23:41Z")

</div>

Next two books, actually…

- RTOW - the basics
- [The Next Week](https://raytracing.github.io/books/RayTracingTheNextWeek.html) - optimization and advanced materials
- [The Rest of Your Life](https://raytracing.github.io/books/RayTracingTheRestOfYourLife.html) - sampling intricacies

---

<div class="post-metadata">

### Author: ![wiz](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/wiz/32/2408_2.png) [@wiz](https://discourse.haskell.org/u/wiz)
#### Post date: [August 14, 2024, 5:49pm UTC](https://discourse.haskell.org/t/ray-tracing-in-one-weekend/10078/8 "2024-08-14T17:49:36Z")

</div>

“The Next Week” is finished too and [the notes](https://gitlab.com/dpwiz/rtow/-/blob/main/notes/week-2.md) are up.

 ![telegram-cloud-photo-size-2-5319145227925183173-x](https://us1.discourse-cdn.com/flex002/uploads/haskell/original/2X/a/ab39c93d5e882b9464ca2a6ceb4c4ac1c564c25e.jpeg)

I’ll have some rest now and think if I want to do the final book in the series, delve into [PBR book](https://www.pbr-book.org/) instead, or… do something else entirely (like generating that SPIR-V disassembler from the specs).

---

<div class="post-metadata">

### Author: ![wiz](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/wiz/32/2408_2.png) [@wiz](https://discourse.haskell.org/u/wiz)
#### Post date: [March 30, 2026, 10:52pm UTC](https://discourse.haskell.org/t/ray-tracing-in-one-weekend/10078/9 "2026-03-30T22:52:23Z")

</div>

> Use SIMD, do ssssttttuuuuppppiiiidddd tttthhhhiiiinnnnggggssss faster, with more energy efficiency ☕

A long-delayed post-Zurihac update. The only primops used so far are the basics that the NCG got in 9.12. No special layouts and fancy primops as they will only appear in 9.16 (and then I’ll need some more). Just do the regular thing four lanes at once. It’s a good start… oh wai~

 ![Screenshot From 2026-03-30 22-51-19](https://us1.discourse-cdn.com/flex002/uploads/haskell/original/2X/9/94b9d19a217b511819eaede081625801fdaf0551.png)

It got better since then. The models took a repo with half-staged commits and made it running without segfaults. They also told me that I was absolutely right, but my BVH code is stupid and could be much simpler and faster. And also cooked benchmark harness which I was procrastinated since the very beginning. I love getting faster, but hate writing benchmarks 😅

But one scene was quite resistant to the improvements, the `finalSceneHigh` from the 2nd book.  
I wasn’t sure why and had to guess until I implemented a tiled scheduler. The abysmally slow tile was not where I expected it to be, but it persisted through most of the run at just 1/40 of the mean pixel rate. And also broke the tiled scheduler by leaving the last job working full steam, while the remaining 15 cores were idle.

 ![slow-bunch](https://us1.discourse-cdn.com/flex002/uploads/haskell/original/2X/1/1e4b843e76ad728d218d67d79dadcbd671266b89.jpeg)

I took a low-SPP run to measure the tiles and put the slowest first. Then subdivide the slowest half. Then subdivide the slowest quarter again. This mostly solved the idling cores, but the solution wasn’t satisfactory.  
And the code was a mess. While refactoring it around I thought that I can skip the tile/subtile distinction and the grid itself and just work with arbitrary rectangles. That also served one of the long-standing project’s goals - binding the renderer to UI where I can select regions and get them rendered for debugging.  
I still have no UI (or a job server to distribute the load over all of the household appliances around my house and my parents’ too), and no debugging. But after a few iterations the round limit and most of the manual size tweaking were gone as the system was optimizing itself by measuring and subdividing until the tiles are fast enough or too small.  
The slow bunch is still slow, but the system now crushes it first and fills the scheduling gap at the end with the easier tiles.

I even got back and recorded the historical renders to make a timeline mini-site: [https://dpwiz.gitlab.io/rtow/](https://dpwiz.gitlab.io/rtow/)

This is far from over, but I’m not dead-inside wrt this codebase anymore.

---

<div class="post-metadata">

### Author: ![wiz](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/wiz/32/2408_2.png) [@wiz](https://discourse.haskell.org/u/wiz)
#### Post date: [April 1, 2026, 1:55pm UTC](https://discourse.haskell.org/t/ray-tracing-in-one-weekend/10078/10 "2026-04-01T13:55:58Z")

</div>

Give that package a prize or something [lucid-svg: DSL for SVG using lucid for HTML](https://hackage.haskell.org/package/lucid-svg)

Seriously underrated for debugging stuff for cheap.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/haskell/original/2X/6/6ee447953a04512c32ccdf1f1b7118323e85ff64.png)
