Structured light path tracer (StructuredLightPathTracerInline)¶
This render pass renders a structured light measurement: a projector shows a pattern on the scene, and a light path contributes according to the pattern value at the projector coordinates through which its last vertex is lit. Each pixel estimates
where \(f\) is the path contribution, \(\xi \in [0, 1]^2\) the projector coordinates of the path’s last
vertex (the one connected to the projector) and \(P\) the pattern. Patterns are signed, in \([-1, 1]\),
with zero mean for the periodic and binary codes; with unsignedModulation, the projector shows
\(0.5\,P + 0.5\), in \([0, 1]\), instead. The zero-mean part is the one that antithetic sampling
targets: the constant part of the unsigned pattern is an ordinary, uniformly lit image. The output is
the estimate itself; it is not divided by anything.
Camera paths start at the primary hits from VBufferRT, and every vertex is connected to the
projector.
Projector¶
The projector is a pinhole with a rectangular field of view, after Mitsuba’s projector emitter.
Its image coordinates \(\xi = (u, v)\) run over \([0, 1]\) across the field of view: \(u\) along the
projector’s right and \(v\) along its up. It emits \(I_0\,P(\xi) / \cos^3\theta\) toward the point with
coordinates \(\xi\), where \(\theta\) is the angle to its axis and \(I_0\) is projectorIntensity, so that
the image plane is lit uniformly.
By default the projector sits at the camera and looks along its view (projectorCollocated), which
lights what the camera sees but carries no depth information. Giving projectorPosition,
projectorDirection or projectorUp places it there instead, unless projectorCollocated is also
given.
Parameter |
Type |
Description |
|---|---|---|
|
boolean |
Place the projector at the camera, every frame: its position, view direction and up. (Default:
|
|
float3 |
Projector center, in world space, without |
|
float3 |
Viewing direction (normalized when used), without |
|
float3 |
Up hint: \(v\) runs along it, made orthogonal to the direction; without |
|
float2 |
Full field of view along \(u\) and \(v\), in degrees. (Default: |
|
float3 |
Radiant intensity \(I_0\) along the axis, per color channel. (Default: |
Patterns¶
Parameter |
Type |
Description |
|---|---|---|
|
string |
|
|
string |
Projector coordinate the 1D patterns vary along: |
|
boolean |
Negate the pattern. (Default: |
|
boolean |
Show \(0.5\,P + 0.5\) instead of \(P\). (Default: |
|
string |
|
|
float |
|
|
float |
|
|
integer |
|
|
integer |
|
|
integer |
|
|
uint2 |
|
|
integer |
|
The patterns and their antithetic maps (see Antithetic sampling):
|
\(P(\xi)\) |
Antithetic map |
|---|---|---|
|
\(1\) (uniform light). |
None (the vertex itself). |
|
The waveform along the axis. |
Mirror image within the period. |
|
One bit of the Gray code of the column, \(\pm 1\). |
Swap the halves of each block of \(2^{\text{bit}+1}\) columns. |
|
A Gray bit XORed with the base bit (Gupta et al. 2011); the Gray bit alone when |
Swap the halves of each block of \(2^{\text{base}+1}\) columns. |
|
Binary checkerboard. |
One cell left, right, down or up, with equal probability, wrapping around. |
|
A binary code set from Python, one value per column. |
A column matching or interval mapping set with it. |
An arbitrary pattern is set from Python on the pass:
tracer = graph.create_pass("Tracer", "StructuredLightPathTracerInline", {"pattern": "arbitrary"})
tracer.set_pattern_data(values, antithetic_index=matching)
tracer.set_pattern_data(values, interval_ids=ids, intervals=intervals)
values:0or1per column (alongpatternAxis), shown as \(-1\) and \(+1\); other values raise an error.antithetic_index: for each column, the column it is paired with, of the opposite value (for example the optimal-transport matching of the 0s and 1s). The pairing must be symmetric.interval_idsandintervals: for each column, the interval it belongs to, and for each interval(srcStart, srcEnd, dstStart, dstEnd), in columns: the interval is mapped linearly onto another one, which must map back onto it.
Give the matching or the intervals (interval_ids and intervals together), or neither (no
antithetic map), not both. It raises an error when an entry is out of range: a partner or interval
id past the last column or interval, an interval with start >= end or past the last column, or a
column outside its interval’s source range or not assigned to the interval whose source contains it
(the source ranges must partition the columns). It warns when the matching is not symmetric or does not pair opposite values, or when the intervals do
not map back onto themselves, which makes antithetic sampling biased or ineffective. Rendering with
pattern = arbitrary before set_pattern_data is called raises an error.
Sampling¶
Parameter |
Type |
Description |
|---|---|---|
|
integer |
Camera paths traced per pixel in each frame. (Default: |
|
integer |
Maximum number of surface vertices on a camera path, counting the primary hit.
|
|
string |
How the vertex lit by the projector is reached from the camera path: |
|
boolean |
Importance-sample the BSDF when extending the camera path; otherwise use the material’s
reference sampler (cosine-weighted for standard materials). (Default: |
With either method, a vertex is lit by the projector only on the side its path arrived from: the projector never lights a surface through it, so it does not light the inside of glass or other transmissive objects (they still transmit the light that reflects off other surfaces).
Antithetic sampling¶
With a fine pattern, the pattern changes sign many times across the vertices a pixel’s paths light,
so independent samples mostly cancel and the estimate is noisy. With samplingMethod = antithetic,
every BSDF-sampled vertex \(y\) (after the primary hit, and not sampled from a delta lobe) gets an
antithetic vertex \(y'\): the pattern’s antithetic map sends \(y\)’s projector coordinates \(\xi\) to \(\xi'\), where
the pattern has the opposite sign, and \(y'\) is where the projector ray through \(\xi'\) hits the
scene. The two contributions are combined with multiple importance sampling (balance heuristic),
with the Jacobian
where \(\omega\) is the direction from the previous vertex \(x\), \(o\) the projector center, and \(\theta_{y,x}\), \(\theta_{y,o}\) the angles at \(y\) to \(x\) and to \(o\). \(|\mathrm{d}\xi'/\mathrm{d}\xi|\) is 1 for every map but the interval mapping. The maps are their own inverses or come in inverse pairs chosen with equal probability (the checkerboard’s left/right and down/up), so the weights need the density of only these two points: no extra map is evaluated. A pair is used only if both vertices are lit by the projector and seen directly from \(x\), which holds for both points of a pair or for neither; otherwise the primal sample is used alone, which keeps the estimate unbiased.
Inputs and outputs¶
Channel |
Description |
|---|---|
|
Primary hits, from |
|
Primary ray directions, from |
|
Structured-light measurement \(I\), RGBA32Float. With the signed pattern it can be negative. Pixels without a primary hit are black: the environment map is not part of the measurement. |
The output options computeDirect (default true here), useSingleChannel, singleChannel and
useAlphaTest are the same as for CWToFPathTracerInline.
Example¶
testbed.load_scene("cornell-box/scene-v4-nolight.pbrt", falcor.SceneBuilderFlags.DontMergeMaterials)
graph = testbed.create_render_graph("StructuredLight")
graph.create_pass("VBuffer", "VBufferRT", {"samplePattern": "Center", "sampleCount": 1})
graph.create_pass("Tracer", "StructuredLightPathTracerInline", {
"samplesPerPixel": 8, "maxBounces": 3, "computeDirect": False,
"projectorPosition": [0.4, 1.0, 6.8], "projectorDirection": [0.0, 0.0, -1.0],
"projectorFov": [30.0, 30.0],
"pattern": "periodic", "waveform": "cos", "patternAxis": "u", "patternWavelength": 0.01,
})
graph.add_edge("VBuffer.vbuffer", "Tracer.vbuffer")
graph.add_edge("VBuffer.viewW", "Tracer.viewW")
graph.mark_output("Tracer.color")
testbed.render_graph = graph
See the structured light tutorial for a complete script.