Direct and global separation¶
Nayar et al. (2006) separate the light a camera sees into a direct part, light that reached the surface straight
from the source, and a global part, all the rest (interreflections, light through glass, …), with high-frequency
illumination. This page renders the separation scene, a glass dragon, a white armadillo and a rough gold bunny in a
Cornell box, with StructuredLightPathTracerInline and shifted checkerboards, and compares naive and antithetic
sampling of the indirect light.
Setup¶
Projector: collocated with the camera (at its position, looking the same way), with a field of view a little wider than the camera’s (the tangent of its half angle is 0.2). It lights everything the camera sees, without shadows.
Patterns: a binary checkerboard of 1024 x 1024 cells, about one pixel each, shifted over a 5 x 5 grid of fifths of a cell, and the inverse of each: 50 images.
Images: 1024 x 1024, with primary rays jittered over each pixel (
VBufferRTwith 32 Halton positions). The direct light of each pattern is rendered first, once (128 samples per pixel); only its indirect light, the noisy part, is rendered with each method: 64 samples per pixel for naive sampling, 32 for antithetic sampling, whose samples each also trace their antithetic path.Glass: the projector lights a surface only on the side its path arrives from, so it does not light the inside of the glass dragon through its surface; the dragon’s global light is the light of the walls and the other objects, seen through the glass.
# The projector is collocated with the camera: at its position, looking the same way,
# with a field of view a little wider than the camera's (tan of the half angle 0.2). It
# then lights everything the camera sees, without shadows.
PROJECTOR = {
"projectorPosition": [0.0, 1.0, 6.8], "projectorDirection": [0.0, 0.0, -1.0],
"projectorFov": [2 * np.degrees(np.arctan(0.2))] * 2,
"projectorIntensity": [10.0, 10.0, 10.0],
}
# A checkerboard of 1024 x 1024 cells: each cell is about one pixel.
TRACER = {"maxBounces": 6, "checkerCells": [1024, 1024], **PROJECTOR}
Separation¶
The pass renders the signed pattern \(P = \pm 1\), so the image under the binary checkerboard, 1 where \(P = 1\) and 0 elsewhere, is half the sum of the white image and the signed one:
# The pass renders the signed pattern P = +-1. The image under the binary checkerboard
# (1 where P = 1, 0 elsewhere) is (white + signed) / 2. The direct light of each pattern
# is rendered first, once (it is easy to converge); only the indirect light, the hard
# part, is rendered with each method.
patterns = [{"pattern": "checkerboard", "checkerShift": shift, "invertPattern": inverse}
for shift in range(SHIFTS) for inverse in [False, True]]
direct_images = [render({**pattern, "maxBounces": 1}, CONVERGED_SPP // 16) for pattern in patterns]
def capture(method):
images = []
for pattern, direct in zip(patterns, direct_images):
indirect = render({**pattern, "computeDirect": False, "samplingMethod": method}, SPP[method])
images.append(0.5 * (white + direct + indirect))
return np.stack(images)
Under a fine pattern that lights half the scene, a lit point receives its direct light and half its global light, a dark one only half its global light. Over the 50 images every point is lit in some and dark in others, so the brightest image minus the darkest is the direct light, and twice the darkest is the global light:
# gets its direct light and half its global light; dark, only half its global light.
def separate(images):
brightest, darkest = images.max(axis=0), images.min(axis=0)
return brightest - darkest, np.maximum(2.0 * darkest, 0.0)
Results¶
Indirect light |
Samples per pixel per image |
Direct MSE |
Global MSE |
|---|---|---|---|
Naive |
64 |
3.0e-6 |
3.7e-6 |
Antithetic |
32 |
1.5e-6 |
1.4e-6 |
The maximum and the minimum over 50 images pick up the noise of the indirect light: with naive sampling, the noise raises the brightest image and lowers the darkest one, so the direct light comes out too bright and the global light too dark, most of all on the glass dragon and on the floor under it, where the global light is strong. Antithetic sampling pairs each sampled vertex with the vertex lit by the neighboring cell, of the opposite sign, so the indirect light cancels pair by pair; with half the samples, the error drops 2 times for the direct light and almost 3 times for the global light. The error maps show the squared error of the luminance, from 0 (black) to \(10^{-4}\) (yellow); the images are shown filtered, at a third of their resolution.
The full script: direct_global_separation.py. Run it next to the
unzipped cornell-box-separation folder; it takes a few minutes.