5 ms·
I too have been writing a raytracer in Rust[0] recently. I tend to use raytracers as my go to project when learning a new language, especially those that are OO
by K0nserv 10y ago
I too have been writing a raytracer in Rust[0] recently. I tend to use raytracers as my go to project when learning a new language, especially those that are OOP, since it touches a few different areas that are commo such as:
+ Protocols/traits/interfaces and using that for polymorphishm, think intersectable/primitve types.
+ It typicall involves both understanding heap and stack allocated memory in the language as well as understanding the general memory model to build scene graphs etc
+ Building a small linear algebra library usually touches things like low level operations and performance operations
as well as operator overloading if the language supports it.
+ Writing images to disks via pixel buffers
Primarily though I think raytracers are very fun projects because you can produce nice looking results quickly which I find helps with motivation and passion for the project. I'm pretty pleased with some of my renders already[1]
0: https://github.com/k0nserv/rusttracer https://github.com/k0nserv/rusttracer
1: https://raw.githubusercontent.com/k0nserv/rusttracer/master/docs/bit-later-render.png https://raw.githubusercontent.com/k0nserv/rusttracer/master/...
- stefs 10y agotrue, the visual feedback helps with debugging (that doesn't look quite right!) and motivation!
- K0nserv 10y agoDefinitely, but I find it can also be massively difficult to figure out why something is wrong. It's not as clear as for example backend web programming. For example this is a progression of me implementing a camera that can move https://twitter.com/K0nserv/status/846488675794014208 https://twitter.com/K0nserv/status/846488675794014208
- pasta 10y agoI also agree. Learning a new language by building a raytracer is a lot of fun. What also helps a lot is that you can use only spheres to create a Cornell box (use very large spheres for the walls). And ray-sphere intersection is 'easy'. Then the next step is path tracing. This will help you to learn a lot about handling recursion (with or without recursion). Other areas that you learn: + How scope is handled + (In dynamic languages) how the conversion between floats and ints work. + Multi threading
- K0nserv 10y agoTotally forgot about recursion. The recursive steps for reflection and refraction aren't strictly speaking path tracing are they? I honestly don't know that distinction well. Multi threading was definitely a lot easier in Rust than when I gave it a shot in my Swift version.
- pasta 10y agoI think path tracing is just a form of ray tracing. The only difference is that you continue another path at a point where the ray hits an object and collect all the light energy back to the pixel.
- K0nserv 10y agoFrom a quick Google. Path tracing doesn't trace towards light sources for shadow rays and instead just sends several rays in different directions and accumelates the resulting colors of those rays.
- pasta 10y agoI'm not sure this is true. The shadow ray pass is used to determine how much light is returned to the pixel. So something like: * shoot a ray from the pixel * when the ray hits an object check how much light that point receives * bounce the ray according to the hit material properties * repeat the bounces X times and gather how much light the pixel will receive. Because most bounes are in a random direction it's best to sample a pixel multiple times. And ofcourse more bounces give a more realistic global illumination result.
- falcolas 10y agoIt's going to depend on the material of your object. If it's perfectly reflective, you'll want to trace different rays than if it's perfectly diffuse, and if it's a rough surface (and how rough).
- alpaca128 10y ago
- geokon 10y ago"Building a small linear algebra library" That's the mega tedious part that's no-fun to debug. It's usually where my raytracer projects end haha
- K0nserv 10y agoFor where I'm at currently you don't need that much. This is it at the moment https://github.com/k0nserv/rusttracer/blob/master/src/math.rs https://github.com/k0nserv/rusttracer/blob/master/src/math.r.... I learned about rust macros, operator overloading, traits, derive, tests, the difference between copy and clone in the process. It was a good first step in rust for sure. It's also one of those things that lends them self to TDD very nicely and that cuts down the need to debug anything.
- ggambetta 10y agoWith a big emphasis in "small"... for a raytracer you don't need much more than a 3D vector with addition, multiplication, and dot product. For reference, the "linear algebra library" in my tiny raytracer [1] is 6 lines of code (and two are method closing braces): http://gabrielgambetta.com/tiny_raytracer_full.js http://gabrielgambetta.com/tiny_raytracer_full.js (functions dot and A_minus_Bk) [1] http://gabrielgambetta.com/tiny_raytracer.html http://gabrielgambetta.com/tiny_raytracer.html
- K0nserv 10y agoThat's really cool :) I love me some tiny programs