Skip to content

PatD123/rusty-raytrace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 

Repository files navigation

Raytracer in Rust

Sphere Full (1000x562) Sphere + Pyramid Full (1000x562)
Screenshot 2025-01-17 181334 Screenshot 2025-01-18 132832
best.mp4

Still trying to learn Rust and thought this would be a great way to crate (pun intended) stuff using Rust but also learn a bit more about graphics programming. Good portion of the work learned from the classic Raytracing In A Weekend article.

Currently, it works pretty well, as you can see from the above photo. We have our Spheres with both diffuse and metallic material, as well as the shadows underneath each. I have implemented the Triangle class and in a couple of the animations below I have shown them being rotated around, however I want to also apply those materials to the triangle to see how it turns out.

On the interlaced_multithreading branch, it increases the speed by a ton. Changed from mpsc to crossbeam channels because it allows for multiple receivers (issue with mpsc). This enabled my program to use all 3 threads.

Outside libs: File, Write, Rand, Crossbeam,

TODO 😟:

  • Use BufWriter in Rust to write to .ppm file as it seems the best way to do it evidence.
  • Test current multithreading branch vs. Method where 3 threads interlace through the scanlines (non-chunks) ==> Make a Job Queue and have threads read off this channel to do work maybe? ✔️ Improves time by 2x
  • Implement some degree of SIMD (here) and Intel Intrinsics.
  • Reduce number of FLOPs (precompute some stuff for intersections).

Features

3d Vectors (Vec 3)

Support for basic vector implementations, including dot product, cross product, rotations (just used for camera animations). Additionally, I didn't feel like making Vectors any different than Points (could've done homegenous coordinates), but they were practically the same so for example, when defining rays, the origin of the ray is a Vec3 and the direction is also a Vec3.

Rays

I also provide a basic ray implementation, of course used in raytracing. At current moment of development, it is able to shoot rays out and render objects in our scene. As stated above, created from the Vec3 struct.

Camera

Supports camera animation and rendering.

output6.mp4
output4.mp4

For both above, the camera rotates around the sphere. There's not that many objects nor has the best lighting to provide an explicit perspective. But it is rotating around the sphere.

Shapes

  1. Spheres
  2. Triangles ray-triangle insided-ness
pyramid-full.mp4
  1. ..... (maybe I'll do more; we'll see)

For Converting Lump PPM to MP4

ffmpeg -framerate 30 -i output%03d.ppm -vf "scale=400:224" -c:v libx264 -pix_fmt yuv420p ../examples/output3.mp4

Updates

  1. Vecs and Rays
  2. Basic raytracing (no shaders)
  3. Camera animations + rotations
  4. Diffuse material + Higher Resolution (years to render) --> I could try and do some async programming.
scaled.mp4
  1. Colors + Lambertian Materials!
colored.mp4
  1. Metallica

Screenshot 2025-01-17 162626

  1. On the multithreading branch, there is a working multithreaded version of this raytracer!

Releases

No releases published

Packages

No packages published

Languages