A sincere prologue
Why am I creating this blog? Honestly, I’m asking myself the same thing. I think the honest answer is: I want to fall in love with coding and computer science again. For this journey, I told myself that I will not use AI assistants to write the code. I will even try not to use AI for the writing itself, so yes, you may see some broken grammar and weird flow here and there LOL. But I will keep one small exception: AI can be my proofreader, my unclear-writing detector, and sometimes just a friend reacting to the blog.
Important (Rule for this blog)
- No AI-generated code.
- AI can proofread or critique writing.
- I will write about mistakes, not only polished results.
- The goal is understanding, not speed.
I have also deleted my two CUDA blogs, I feel like they aren’t mine anymore, they are written by someone else, I want to feel proud and be happy for something that is mine.
I actually used AI but not that much, so that didn’t count 😉.
I remember the old days, around 2021 to 2024 (maybe), when I learned coding by reading books, watching YouTube videos, and following pure curiosity. It was all for the love of the game. When you write every line of code with your own hands, it feels special. You have to reason about what you are writing: why this line exists, why this function is used, why this design makes sense. And honestly, half of the journey is searching, researching, and “copying” from StackOverflow LOL.
Remember when learning Neovim meant watching ThePrimeagen or chris@machine , then spending even more time reading random dotfiles on Github (or r/unixporn on Reddit). Or when installing Arch (because I want to be cool) meant living inside the ArchWiki. Or when trying to clone Minecraft as jdh meant disappearing into Learn OpenGL and GitHub repositories for weeks.
I do not hate AI. Actually, I love AI. I still remember using ChatGPT for the first time in 2022 and feeling shocked and impressed at the same time that it could understand my request so naturally. AI has helped me learn many things I was too scared to try before. For example, I finally understood the proof that the square root of 2 is irrational from baby Rudin (I hate that book btw). And recently, I read I’m going back to writing code by hand by k10s devlog , and one quote really stayed with me:
AI writes features, not architecture. The longer you let it drive without constraints, the worse the wreckage gets. The velocity makes you think you’re winning right up until the moment everything collapses simultaneously.
We often say that humans should focus only on architecture, high-level systems, and good specifications, while AI handles the ugly low-level code. But if we understand the system well enough to specify it clearly, why should we skip the part where we actually build it?
So this series is my attempt to build something by hand again. And I think the introduction is really long right now. So basically, in this journey, I will try to build a Ray Tracer from scratch in Rust all by myself.
- Why do I use Rust? Just for the love of the game, I want to be fun. And also, Rust is slowly becoming a go-to language for AI (for example, @huggingface uses it a lot).
- Why build a Ray Tracer? I really want to build one for a long time.
This blog is also a love letter to my old self: the version of me who could spend a whole night reading docs, breaking things, fixing them, and feeling weirdly happy about it.
Why Rust?
Rust is still a young programming language with only 11 years old. Compared with C (54 years old) and C++ (47 years old), it feels like comparing a boomer to Gen Alpha LOL. The main promise of Rust is safety. Remember that word, because you will fight the compiler all the time when writing Rust. But “safe” can sound vague, Rust does not magically prevent every possible mistake, and you can still shoot yourself in the foot with the unsafe keyword, just like in C or C++.
What makes Rust interesting is how much safety it gives you by default. Ownership, borrowing, lifetimes, pattern matching, and the type system all push you to make invalid states harder to express. Sometimes this feels annoying. Sometimes it feels like the compiler is your enemy. But slowly, you start to realize that the compiler is forcing you to explain your program more clearly.
Also, Rust is funny right now because it somehow became the serious language. Every few months, another project announces that they are rewriting the core in Rust, and everyone claps because now the bugs will be memory safe bugs instead of normal bugs LOL. Bun is rewriting a lot of its internals in Rust, Hugging Face uses Rust for performance-critical tooling, and people keep talking about Rust like it is the language agents were born to write.
So I guess this is my rebellion: I will use the language of agents, but I will write it like a human. Slowly and painfully. With me staring at ownership errors and pretending I understand lifetimes. If AI is supposed to make programming effortless, then Rust is a funny place to go when I want programming to feel effortful again.
Okay, so if you also want to learn Rust with me, please start with the bible: The Rust Programming Language . People call it “the book,” which is very funny because Rust programmers really said: we have one book, and it is the book.
For the ray tracer part, I will mostly follow Ray Tracing in One Weekend . The original version uses C++, so half of the fun is translating the ideas into Rust and then asking myself why the compiler is mad this time. I do not want this blog to become “how to learn Rust perfectly or how to build a Ray Tracer perfectly”. I am also learning. So maybe the more honest title is: “watch me struggling while coding by hand again”.
Why ray tracer?
I think a big part of my love for programming came from computer graphics. There is something weirdly magical about it. You write numbers, vectors, loops, and suddenly there is an image on the screen. Not a button, not a CRUD app, not another dashboard, but an actual picture. Something you can look at.
One of the first computer graphics stories that really hooked me was the fast inverse square root from Quake III. The code looked cursed. There was this strange constant, 0x5f3759df, some bit-level trickery, and somehow it made lighting calculations faster. I did not fully understand it at first, but that was exactly why it felt so cool. It was math, hardware, performance, and black magic all living in the same function. The code is below, it is the original code.
float Q_rsqrt( float number ) { long i; float x2, y; const float threehalfs = 1.5F; x2 = number * 0.5F; y = number; i = * ( long * ) &y; // evil floating point bit level hacking i = 0x5f3759df - ( i >> 1 ); // what the fuck? y = * ( float * ) &i; y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration// y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed return y;}And if you go deeper into game engines, the rabbit hole becomes insane. You want to build a game engine? Cool. Have fun reading a 1000-page book like Game Engine Architecture , then opening the source code of an open-source engine and realizing there are hundreds of thousands of lines waiting for you. Rendering, physics, animation, assets, input, audio, scripting, memory, threading. A game engine is not a program. It is a small operating system pretending to be fun.
Rendering alone is already a whole universe. If you want to put something beautiful on the screen, you eventually meet the GPU pipeline, shaders, BRDFs (Bidirectional reflectance distribution function), PBR (Physically Based Rendering), shadow mapping, global illumination, denoising, sampling, color spaces, and many other words that sound “crazy” until you try to implement them. But that is also why I love it.
That is why a ray tracer feels like the perfect project for this journey. It is small enough that I can build it by hand, but deep enough that every line teaches me something. A ray has an origin and a direction. It hits objects. It bounces. It gathers color. From those tiny rules, an image slowly appears. So you basically “reimagine” a whole image with ray only.
Maybe I do not want to build a ray tracer only because I want to learn Rust. Maybe I want to build it because I miss the feeling of being confused by something beautiful.
The real result
Warning
This section is still under construction. I’m building the ray tracer now, and I hope to write about the first milestone soon 🏃