News for hackers. Stuff that matters.
Re:Writing a Raytracer in Rust – Part 1 by K0nserv on Thursday March 30, 2017 @05:22AM (#13993963)
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

1: https://raw.githubusercontent.com/k0nserv/rusttracer/master/...

Re:Writing a Raytracer in Rust – Part 1 by geokon on Thursday March 30, 2017 @11:04AM (#13995983)
"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

Re:Writing a Raytracer in Rust – Part 1 by ggambetta on Thursday March 30, 2017 @12:06PM (#13996585)
With 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 (functions dot and A_minus_Bk)

[1] http://gabrielgambetta.com/tiny_raytracer.html

Re:Writing a Raytracer in Rust – Part 1 by K0nserv on Thursday March 30, 2017 @12:18PM (#13996687)
That's really cool :) I love me some tiny programs
Re:Writing a Raytracer in Rust – Part 1 by K0nserv on Thursday March 30, 2017 @11:08AM (#13996010)
For 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.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.
Re:Writing a Raytracer in Rust – Part 1 by pasta on Thursday March 30, 2017 @09:04AM (#13994962)
I 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

Re:Writing a Raytracer in Rust – Part 1 by K0nserv on Thursday March 30, 2017 @09:28AM (#13995114)
Intersecting with an infinite plane is also pretty easy so you can build a Cornell box just using planes. However the massive sphere trick is neat, never thought of that before
Re:Writing a Raytracer in Rust – Part 1 by maxmcorp on Thursday March 30, 2017 @05:44PM (#13999150)
I wish people would learn new languages by writing new versions of winamp. That would be great.
Re:Writing a Raytracer in Rust – Part 1 by K0nserv on Thursday March 30, 2017 @09:06AM (#13994976)
Totally 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.
Re:Writing a Raytracer in Rust – Part 1 by pasta on Thursday March 30, 2017 @09:16AM (#13995037)
I 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.
Re:Writing a Raytracer in Rust – Part 1 by K0nserv on Thursday March 30, 2017 @09:27AM (#13995105)
From 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.

Re:Writing a Raytracer in Rust – Part 1 by alpaca128 on Thursday March 30, 2017 @05:28PM (#13999037)
Path tracing is just like ray tracing with randomized deviations of the rays and reflections, and this is repeated many times to reduce the noise. This can also be done with shadow rays to some extent, for soft shadows.

(But it seems like every person you ask knows a different meaning for terms like raycasting, path tracing and physical based rendering)

Re:Writing a Raytracer in Rust – Part 1 by pasta on Thursday March 30, 2017 @11:22AM (#13996143)
I'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.

Re:Writing a Raytracer in Rust – Part 1 by falcolas on Thursday March 30, 2017 @12:22PM (#13996719)
It'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).
Re:Writing a Raytracer in Rust – Part 1 by stefs on Thursday March 30, 2017 @06:54AM (#13994327)
true, the visual feedback helps with debugging (that doesn't look quite right!) and motivation!
Re:Writing a Raytracer in Rust – Part 1 by K0nserv on Thursday March 30, 2017 @07:45AM (#13994531)
Definitely, 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