Next up: I need to add hittables, textures, ray sampling, and rays bouncing. Eventually it needs optimization. 0.3s per frame is TRASH
Obviously, this bad boy: https://raytracing.github.io/books/RayTracingInOneWeekend.html
This was the guide I went through. It's in C, and I learned a lot by trying to do everything in Zig instead. I feel like if I did it in C I wouldn't have learned as much.
Zig docs: https://ziglang.org/documentation/master/
Zig.guide: https://zig.guide/language-basics/structs/
By far the most useful, though, was the Zig source code: https://github.com/ziglang/
It's surprisingly readable. It helped me answer questions that I couldn't find info about in either the docs, google, or chatgpt.
If you want to understand how to use certain functions or types or any of that, you can just find what you're working with in here and see all of its code laid out.
https://www.youtube.com/watch?v=pPStdjuYzSI
Here's an example of how to use zig as a wrapper for CUDA, so you can use GPU-acceleration in zig: https://github.com/dnbt777/zig-cuda-utils/
I wrote the cuda kernel with an LLM and used the zig source code to figure out how to link the compiled cuda library in the build.zig.
I am only mid-way through developing the GPU ray tracer, but being able to go back and reference this simple example has been EXTREMELY useful.
in order to get the GPU to run first, run
sudo prime-select nvidia
cause: spheres have a pointer to a material. I kept overwriting the memory at the pointer. so they all had the same material. lol
for (0..n) {
const mat = [material];
sphere.smat = &mat;
}
I thought it was a buggy random number generator for the longest time
// the fix was something like this
for (0..n) {
sphere.smat = &[material];
}