Raytracing in Rust

preview_player
Показать описание
I spent an entire week digging into and implementing my own Raytracing renderer in Rust. In this video we talk about what crates I used and the approaches I took... as well as whether or not it was worth the time.

00:23 What is Raytracing?
01:17 PPM files
03:55 Showing progress with Indicatif
04:29 Introducing Glam: vec3
05:12 Rays
06:10 Sending Rays into the Scene Through a Viewport
07:36 Rendering a Sphere
08:51 Shading the Sphere with Normals
10:11 Simplifying the ray-sphere intersection
10:57 The Hittable Trait
13:40 Refactoring the Camera
15:03 What is a Pixel anyway?
17:49 Diffuse Materials
20:56 gamma correction
21:42 Metal Materials
23:43 clamp
24:11 dielectric (glass) materials
24:42 Camera positioning
26:14 Defocus Blur
27:05 Raytracing in one weekend final scene
27:36 Rayon
28:56 Refactoring
31:39 Raytracing in one Week
32:14 Motion Blur
33:30 Efficiency Structures: AABB and BVH
35:32 Textures
38:02 Perlin Noise
39:01 Quads
40:12 Translate and Rotate
41:23 Volumetric Materials
42:39 Final Scene: Raytracing the next week
43:40 Book 3?
Рекомендации по теме
Комментарии
Автор

This was my first project in rust a year ago, I struggled with it like hell, fun times.

igz
Автор

I wrote a cpu raytracer (similar to this one) as my first rust project but more realtime ish, running at 40 fps multi threaded

was a good learning experience with Rust

indradb
Автор

The timing of this video for me couldn't be better, I just finished doing book 1 in Rust a couple days ago, and it's really interesting to see your approach to translating the C++. Yours is definitely "rustier" than mine with more use of options and iterators, and at the same time some things turned out really similar, especially the use of traits. The whole point of doing this for me was to get more familiar with Rust, as I've done book 1 in the past in C++, and I think it was a really good exercise, but having yours to reference actually makes it even more valuable as I can see where I could have made more use of Rust's features. Thanks for sharing!

red_metal
Автор

PPM was common as an X Windows icon format in the 1990s. Using something like TGA or TIF is probably easier as a "trivial to output without a library" format.

jaysistar
Автор

Really great and honest walk through. I appreciated the Rust short cuts and comparisons with C++.

BrettWitty
Автор

This was an excellent walk through. Thanks for sharing!

MattBolt
Автор

I did this project for a super computing course. We implemented it in C++ with MPI for the cross-communication and did some empirical studies comparing our own message-passing methods to that of MPI's built-in methods (which are optimized and topologically aware). No surprise, we got beat by quite a lot by MPI's own implementation. At most we ran a render of a 5k image on 4096 cores, which took something like ~1 second - crazy. We did a lot of samples per pixel and bounces too, but I don't remember quite how many.

Hauntear
Автор

11:51 Yeah, this is why I want enums to be able to have trait bounds on the types they can store and obviate the need to have match expressions on methods every variant is guaranteed to have

Holobrine
Автор

Great video, throwback to the things I learned in my graphics course 🌎
cool to see how much the Rust ecosystem provides

TeamDman
Автор

I did this back in the day. Should probably revisit it some time. Fun project.

BrandonReinhart
Автор

damn, this is definitely a full blown course on making ray tracing in rust

nicklu
Автор

This seems to be running awfully slowly compared to other implementations. There is a video by The Cherno where he reviews an implementation of the code from the raytracing in a weekend book from a year ago that I have watched previously. I don't know how much of it you can apply to Rust, as it's obviously a C++ code review. Options in rust are close to zero cost from what I know so you can probably ignore that part. The most applicable part of the video would probably be removing the branching and making sure that everything is in contiguous memory. The video is called "I made it FASTER // Code Review". Another thing you might want to try is compiling with the "-C target-cpu=native" flag for SIMD optimizations from the rust compiler but you might already be doing that.

ferdynandkiepski
Автор

This honestly felt more like bashing c++, rather than focussing on RT. Nevertheless, nice to see a different implementation. It didn’t hinder me throughout the video.

Few points;
- the math optimization early on results in less assembly instructions and thus a faster raytracer. This is explained in the text around it ;)
- c++ and rust have a lot in common, but also a lot of differences. People use libraries a lot in c++, so there honestly is no reason to add certain functionality to the language if very decent libraries already exist. Rust didn’t have those so made it before there even was a good library. Apples and oranges. Neither one is better because of it.

nepp
Автор

i just bookmarked two books from Jamis Buck for a potential Rust driven run. One of them coincidently called 'The Ray Tracer Challenge' and the other one is called 'Mazes for Programmers'.

animanaut
Автор

This is impressive stuff. I once did a toy pathtracer in C++, then ported it to Digital Mars D. It was 10 times as slow. The culprit was dynamic allocation everywhere, and not knowing when that actually takes place. I'm sure your Rust tracer is just as fast as the C++ one?

earx
Автор

Hell yeah long form content lets goooo

aure
Автор

27:30 rayon (leaving this for my future self)

IgneousGorilla
Автор

This is very cool. I've done some coding train exercises in rust with sdl2. Perhaps I should try this. Thanks for sharing.

Codeaholic
Автор

Hi, what do you think about coding in web3?

andreylizin
Автор

Are you working furiously on a Bevy tutorial for ex-Unity devs?

Endelin