Get the latest tech news
Hard Mode Rust (2022)
This post is a case study of writing a Rust application using only minimal, artificially constrained API (eg, no dynamic memory allocation). It assumes a fair bit of familiarity with the language.
This post is a case study of writing a Rust application using only minimal, artificially constrained API (eg, no dynamic memory allocation).It assumes a fair bit of familiarity with the language. This works rather intuitive conceptually.First, imagine the above scene, with an infinite fuchsia colored plane and a red Utah teapot hovering above that.Then, imagine a camera standing at 0,10,-50(in cartesian coordinates) and aiming at the origin.Now, draw an imaginary rectangular 80x60 screen at a focus distance of 50 from the camera along its line of sight.To get a 2D picture, we shoot a ray from the camera through each “pixel” on the screen, note which object on the scene is hit (plan, teapot, background), and color the pixel accordingly.See PBRT Book if you feel like falling further into this particular rabbit hole (warning: it is very deep) (I apologize for “little square pixels” simplification I use throughout the post :-) ). Ray tracing is an embarrassingly parallel task — the color of each output pixel can be computed independently.Usually, the excellent rayon library is used to take advantage of parallelism, but for our raytracer I want to show a significantly simpler API design for taking advantage of many cores.I’ve seen this design in Sorbet, a type checker for Ruby.
Or read this on Hacker News