Tuom L.
Tuom L.

Reputation: 182

Path tracing: scaling color

I'm trying to read the source of http://www.kevinbeason.com/smallpt/ and there is especially one thing I cannot grasp. On line #55 there it says f=f*(1/p).

What is it? What does it do? And more importantly, why it reads exactly like this? Is is some kind of heuristic to make the image converge faster?

In other words, in literature I saw:

function radiance
     ...
    return Le(x) + R(p) * radiance(rn)

The important thing is that R(p) - I don't really understand what it does but for 99% it is not that f from above..

Please, can someone shed a bit of light on this?

Upvotes: 1

Views: 415

Answers (1)

greeness
greeness

Reputation: 16104

I think your answer is in this slides, which contains line-by-line explanations of the explicit lighting version of smallpt, reformatted to be 75% longer.

In short, line #55 is inside the function radiance, in which the radiance estimate along ray is estimated.

if (++depth>5) 
    if (erand48(Xi)<p) f=f*(1/p); 
    else return obj.e;
  • first, this function radiance is a recursive function (calling itself)
  • When a ray hits a glass surface, the ray tracer must determine if it is entering or exiting glass to compute the refraction ray.
  • f is the color of the object.
  • p is the maximum component (r,g,b) of the surface color.
  • at line #55, we do Russian Roulette if recursion depth is greater than 5.
  • we stop the recursion randomly based on the surface reflectivity using p.
  • f=f*(1/p) is using p - the maximum component of f to do a normalization for each component,

so that,

f.x = f.x / (max(f.x, f.y, f.z))
f.y = f.y / (max(f.x, f.y, f.z))
f.z = f.z / (max(f.x, f.y, f.z))

The code defines an operator overloading for * but not for /, that's why f=f*(1/p) instead of f=f/p.

Upvotes: 1

Related Questions