Structured light: antithetic sampling and the pattern wavelength

This tutorial compares naive and antithetic sampling of a structured-light measurement at equal time for three wavelengths of a cos stripe pattern. It builds on Structured light rendering (offline), which explains the projector and the render graph.

Naive and antithetic structured-light rendering at equal time for the pattern wavelengths 0.01, 0.05 and 0.2, with references

The antithetic path

StructuredLightPathTracerInline weights each path by the projector’s pattern \(P(\xi)\) at the projector coordinate \(\xi\) of the vertex the projector lights. With samplingMethod = antithetic, every BSDF-sampled vertex \(y\) gets an antithetic vertex \(y'\): the pattern’s antithetic map sends \(\xi\) to \(\xi'\), where the pattern has the opposite sign, and \(y'\) is where the projector ray through \(\xi'\) hits the scene. For a periodic pattern, \(\xi'\) is the mirror image of \(\xi\) within the period: about a quarter or three quarters of the period for a cos, so that \(\cos(2\pi\,\xi' / \lambda) = -\cos(2\pi\,\xi / \lambda)\). Unlike CW-ToF, no equation has to be solved: the map is explicit, and the projector ray gives the antithetic vertex (see Antithetic sampling).

The script

The script is that of the CW-ToF tutorial, with the structured-light pass in place of the CW-ToF pass. The projector sits 0.4 to the right of the camera and covers the whole box.

STRUCTURED_LIGHT = {
    "samplesPerPixel": 1, "maxBounces": 4,
    "computeDirect": False,  # indirect light only
    # A projector 0.4 to the right of the camera, covering the whole box.
    "projectorPosition": [0.4, 1.0, 6.8], "projectorDirection": [0.0, 0.0, -1.0],
    "projectorFov": [30.0, 30.0], "projectorIntensity": [10.0, 10.0, 10.0],
    # Vertical cos stripes.
    "pattern": "periodic", "waveform": "cos", "patternAxis": "u",
    "useSingleChannel": True, "singleChannel": "luminance",
}
NAIVE = {"samplingMethod": "naive"}
# Each sampled vertex is paired with the point the projector lights through the
# mirror image of its projector coordinate within the period, where the cos has
# the opposite sign.
ANTITHETIC = {"samplingMethod": "antithetic"}


Results

Wavelength

Naive (0.3 s)

Antithetic (0.3 s)

Naive relMSE

Antithetic relMSE

0.01

524 spp

331 spp

1.07

0.0639

0.05

523 spp

332 spp

0.147

0.0422

0.2

462 spp

366 spp

0.0308

0.0195

The wavelength is in projector coordinates, which span \([0, 1]\) across the projector’s field of view: 0.01 gives 100 periods. As for CW-ToF, the finer the pattern, the more the indirect light cancels and the more antithetic sampling helps: 17 times lower error at the finest pattern. Here it stays ahead even at the coarsest pattern: the mirror image is less than one period away, and the projector ray keeps it on nearby geometry.

The full script: structured_light_antithetic.py. It takes about two minutes, most of it for the references.