Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ray Tracing: Only use single ray instead of both reflection & refraction rays

I am currently trying to understand the ray tracer developed by Kevin Beason (smallpt: http://www.kevinbeason.com/smallpt/) and if I understand the code correctly he randomly chooses to either reflect or refract the ray (if the surface is both reflective and refractive).

Line 71-73:

return obj.e + f.mult(depth>2 ? (erand48(Xi)<P ?   // Russian roulette
radiance(reflRay,depth,Xi)*RP:radiance(Ray(x,tdir),depth,Xi)*TP) :
radiance(reflRay,depth,Xi)*Re+radiance(Ray(x,tdir),depth,Xi)*Tr);

Can anybody please explain the disadvantages of only casting a single ray instead of both of them? I had never heard of this technique and I am curious what the trade-off is, given that it results in a huge complexity reduction.

like image 381
crapper Avatar asked Mar 28 '12 10:03

crapper


1 Answers

This is a monte-carlo ray tracer. Its advantages are that you don't spawn an exponentially increasing number of rays - which can occur in some simple geometries.. The down side is that you need to average over a large number of samples. Typically you sample until the expected deviation from the true value is "low enough". Working out how many samples is required requires some stats - or you just take a lot of samples.

like image 125
Michael Anderson Avatar answered Oct 12 '22 07:10

Michael Anderson