Live data from Hacker News

Photorealistic Path Tracer

thume.ca

31–40 of 98 posts

Re: Photorealistic Path Tracer

#31
This is cool. I want to start learning this. What programming language would you suggest to write my code while I learn this? Is C++ pretty much necessary for performance reasons or other languages would be okay too? Any specific recommendation?

Re: Photorealistic Path Tracer

#32
The path tracer is impressive, doing it in a month's worth of work is impressive too :) I took a ray tracing course in second grade, and had to leave everything else and write ray tracers during the term.

And, as an item of nostalgia, here is some of my glossy mirror code:

  if(matl->t == M_GLOSSMIRROR){
      double θ0 = acos(cosθ), Δθ = M_PI * matl->rough / 2, lθ, dθ = 2*Δθ/ray->w, dφ = 2*dθ, θ, φ;
      lθ = (θ0 - Δθ) n, x = norv4(subv4(ray->p, scv4(dotv4(ray->p, z), z))), y = crv4(x, z);
      ...

Re: Photorealistic Path Tracer

#33
post #31

This is cool. I want to start learning this. What programming language would you suggest to write my code while I learn this? Is C++ pretty much necessary for performance reasons or other languages would be okay too? Any specific recommendation?

Check out Peter Shirley's book series, starting with Ray Tracing in One Weekend. It's about ray tracing, not path tracing, but it's a fun introduction to the broader topic.

As for languages, I guess that depends on how long you are willing to wait for results. You might be able to use Go or something on the JVM without driving yourself insane.

Re: Photorealistic Path Tracer

#34
post #32

The path tracer is impressive, doing it in a month's worth of work is impressive too :) I took a ray tracing course in second grade, and had to leave everything else and write ray tracers during the term. And, as an item of nostalgia, here is some of my glossy mirror code: if(matl->t == M_GLOSSMIRROR){ double θ0 = acos(cosθ), Δθ = M_PI * matl->rough / 2, lθ, dθ = 2*Δθ/ray->w, dφ = 2*dθ, θ, φ; lθ = (θ0 - Δθ) n, x = no…

Now that is impressive. When I was in second grade I was still wrapping my head around addition and subtraction.

Re: Photorealistic Path Tracer

#35

I just wonder why author named ray tracing as path tracing..

> I just wonder why author named ray tracing as path tracing..

Ray casting (1968) was simply casting rays from camera, one per each image pixel, until the ray hits the closest object. Then the pixel gets the color from the object.

Ray tracing (1979) made ray casting recursive for three cases:

1. Reflection: The object surface is a perfect mirror, so we calculate the reflection angle from the incoming ray angle, and continue the process.

2. Refraction: The object is transparent, like glass. The Fresnel equations give the refraction (transmission) and reflection angles and the distribution of energy between them. For some angles, one of these can be 0.

3. Shadow ray: Shadow rays are traced towards each light source. If the shadow ray is blocked by any other object, we're in shadow in respect of that light source. If a light source is visible, both the light source color and the object surface color contribute to the color of this pixel. The object surface can also have a reflectance model (BRDF) so it doesn't need to be a matte Lambertian surface, but the BRDF is only applied to light coming directly from the light sources.

An object can have partially reflective surface (like glossy plastic), and it can also be partially transparent (like colored glass). So at each intersection, we may generate up to all 3 types of rays.

What we miss here, is that all surfaces diffusely reflect light to some amount, and that the colors in all diffuse incoming light from every direction contributes to the color of a surface, not just direct light from visible light sources. (We also miss caustics. Most notably, a transparent glass ball between the surface and a light source will only give a shadow in ray tracing.)

Historically, there was a time when computers were too slow for sampling, even statistically weighted importance sampling, of diffuse light coming from all directions to all surfaces. So the above model of handling only 3 types of rays (mirror reflection, transparent object refraction, light directly from a light source) became both popular, and established as ray tracing.

Then later, advances towards including all kinds of physically possible light rays, adopted names other than ray tracing. They are still tracing rays, but they are not called tray tracing, because the name ray tracing is understood to mean only the first method that got widely popular, with all its limitations.

Re: Photorealistic Path Tracer

#36

One of the best books I've read on the subject is https://www.pbrt.org/ (which the article also mentions). It manages to tackle both the math and the gritty details of implementing the math. Blew me away the first time I read it.

Yah PBRT was my most important resource for completing this project, way more important than anything I learned in course lectures. I read it cover to cover before doing much, but then made sure I wrote things how I wanted without referencing the book except for a few bits of formula-heavy code I mention in the credits. Definitely the best technical book I've ever read.

How did you read it without falling asleep?

Re: Photorealistic Path Tracer

#37

I recognized the final project structure of CS488. Great class, though quite time-consuming. The author links to past year galleries: https://www.student.cs.uwaterloo.ca/~cs488/gallery-A5.html I'm not sure if this was done in all the years, but one of the interesting (and slightly unfair) aspects of the final project was that you were not only graded on the quality of the final render, but also how closely you aligne…

That seems like quite the wrong incentive for learning. A lot of ambitious plans fail. To be graded only on the final delivery gives adequate incentive to execute. I perhaps get the education signal that executing successfully on a plan is a worthwhile skill, but isn't learning also experimenting?

Re: Photorealistic Path Tracer

#38
post #31

This is cool. I want to start learning this. What programming language would you suggest to write my code while I learn this? Is C++ pretty much necessary for performance reasons or other languages would be okay too? Any specific recommendation?

There are many recent languages that seem suitable. Like Julia and such.

Re: Photorealistic Path Tracer

#40
post #2

Well I hoped to be on HN today for my high-effort blog post on generics and metaprogramming ( http://thume.ca/2019/07/14/a-tour-of-metaprogramming-models-... ) but at least I'm on HN for something :P Edit: And at least right before I go to bed my post technically made it on the front page in the very last slot :) I'm also glad people like my ray tracer, it was super satisfying to build, and nice to have a project tha…

hii
Post reply on HN