Path Tracing - Bidirectional Path Tracing

Bidirectional Path Tracing

Sampling the integral for a point can be done by solely gathering from the surface, or by solely shooting rays from light sources. (1) Shooting rays from the light sources and creating paths in the scene. The path is cut off at a random number of bouncing steps and the resulting light is sent through the projected pixel on the output image. During rendering, billions of paths are created, and the output image is the mean of every pixel that received some contribution. (2) Gathering rays from a point on a surface. A ray is projected from the surface to the scene in a bouncing path that terminates when a light source is intersected. The light is then sent backwards through the path and to the output pixel. The creation of a single path is called a "sample". For a single point on a surface, approximately 800 samples (up to as many as 3 thousand samples) are taken. The final output of the pixel is the arithmetic mean of all those samples, not the sum.

Bidirectional Path Tracing combines both Shooting and Gathering in the same algorithm to obtain faster convergence of the integral. A shooting path and a gathering path are traced independently, and then the head of the shooting path is connected to the tail of the gathering path. The light is then attenuated at every bounce and back out into the pixel. This technique at first seems paradoxically slower, since for every gathering sample we additionally trace a whole shooting path. In practice however, the extra speed of convergence far outweighs any performance loss from the extra ray casts on the shooting side.

The following pseudocode is a procedure for performing naive path tracing. This function calculates a single sample of a pixel, where only the Gathering Path is considered.

Color TracePath(Ray r, depth) { if (depth == MaxDepth) { return Black; // Bounced enough times. } r.FindNearestObject; if (r.hitSomething == false) { return Black; // Nothing was hit. } Material m = r.thingHit->material; Color emittance = m.emittance; // Pick a random direction from here and keep going. Ray newRay; newRay.origin = r.pointWhereObjWasHit; newRay.direction = RandomUnitVectorInHemisphereOf(r.normalWhereObjWasHit); // This is NOT a cosine-weighted distribution! // Compute the BRDF for this ray (assuming Lambertian reflection) float cos_theta = DotProduct(newRay.direction, r.normalWhereObjWasHit); Color BDRF = m.reflectance * cos_theta; Color reflected = TracePath(newRay, depth + 1); // Apply the Rendering Equation here. return emittance + (BDRF * reflected); }

All these samples must then be averaged to obtain the output color. Note this method of always sampling a random ray in the normal's hemisphere only works well for perfectly diffuse surfaces. For other materials, one generally has to use importance-sampling, i.e. probabilistically select a new ray according to the BRDF's distribution. For instance, a perfectly specular (mirror) material would not work with the method above, as the probability of the new ray being the correct reflected ray - which is the only ray through which any radiance will be reflected - is zero. In these situations, one must divide the reflectance by the probability density function of the sampling scheme, as per Monte-Carlo integration (in the naive case above, there is no particular sampling scheme, so the PDF turns out to be 1).

There are other considerations to take into account to ensure conservation of energy. In particular, in the naive case, the reflectance of a diffuse BRDF must not exceed or the object will reflect more light than it receives (this however depends on the sampling scheme used, and can be difficult to get right).

Read more about this topic:  Path Tracing

Famous quotes containing the words path and/or tracing:

    Often on bare rocky carries the trail was so indistinct that I repeatedly lost it, but when I walked behind him I observed that he could keep it almost like a hound, and rarely hesitated, or, if he paused a moment on a bare rock, his eye immediately detected some sign which would have escaped me. Frequently we found no path at all at these places, and were to him unaccountably delayed. He would only say it was “ver strange.”
    Henry David Thoreau (1817–1862)

    And if anyone should think I am tracing this matter too curiously, I, who have considered it in various shapes, can only answer with Hamlet ... “Not a jot”; it being no more than the natural result of examining and considering the subject.
    Sarah Fielding (1710–1768)