A ray tracer written in Zig
-
Rays!
-
Spheres are the only supported primitives. (Can be expanded further)
-
Anti-aliasing
-
Materials:
- Lambertian (matte)
- Metal
- Glass or any transparent matrials that reflect and refract light
-
Camera:
- a camera that can be positioned anywhere
- we can control:
- vieport
- aspect ratio
- fov
- output resolution
- defocus blur (depth of field) - the book has a internal joke that I didn't get.
-
SIMD: some linear algebra have been converted into SIMD operstions using builtin functions like
muladd
. Note: This proejct can be further sped up using concurrency.
- Zig Showtime: Raytracing in a Weekend by Loris
- Ray Tracing in One Weekend
- Reference Repo: Krist-RTX
This was my first project in Zig. Coming from a background in gamedev, graphics have always fascinated me. I had been following ZigInDepth series on YouTube to learn Zig, but after some time it got a little boring since it does not have any projects. Jose teaches the concepts very well in the series.
I was able to follow the first video in raytracing series. This allowed me to pick up concepts which I didn't know and also showed me design choices to be made when working or translating object oriented code in C++ to Zig. This breaks many patterns from my time using Unity, and later python which I currently use at my AI Engg job.
I was able to pick up many concepts on my own after section 7.
Learning Approach:
- Try to follow the book.
- If I went wrong or get stuck follow the video series.
Overall it was pretty fun and enjoyable to make something like this. I look forward to continuing the books (there are 3) if I get free time. Thanks!
- I've checkpointed many small steps during the project so its easier to follow along than the reference repo which commits daywise progress.
- I've decided to keep
.ppm
files which also save the moments of progress - sentimental value, since I know I would not be able to recover those over time. - I've moved Colors to a seprate file
color.zig
, to keep the color related utility seprate. This required me to do.{ .data = {some_vector}}
to get a color but I've stuck to it. - FOV calculations: my renders do not have the save FOV as stated in book for some images, this might be due to inaccurate conversion of
deg
torad
. I've skipped correcting this since I continued past half the day-2 stream on my own. - Comments: This repo does not cover orignal books comments, but I've tried to have them where I can.
- that's probably it, hopefully this repo serves in your learning!