# Chart swaps and path inversion in bidirectional path tracing

I've got a hard time to understand how we would implement the following in practice. I'd be great if someone could explain the details for the example below.

Assume we're generating a path $${\rm x}=(\rm x_0,\rm x_1,\rm x_2)$$ of length $$2$$ using the $$(s,t)$$-strategy in bidirectional path tracing (see picture below). Assume that there is no participating media in the scene and we're using a pinhole camera.

Now assume $$s=0$$ and $$t=3$$. Since we're using a pinhole camera, $$\rm x_0$$ is deterministically fixed at the eye. A raster point is determined by drawing random numbers $$u_1,u_2\in(0,1)$$ and mapping them uniformly to the raster space. The raster point determines a ray $$r_1=(\rm x_0,\omega_1)$$ with origin $$\rm x_0$$ and direction $$\omega_1$$. Assume that $$r_1$$ hits a surface point $${\rm x_1}$$. Now another pair of random numbers $$u_3,u_4\in(0,1)$$ are drawn and mapped to a direction $$\omega_2$$ by the$$^1$$ bidirectional scattering distribution function at $$\rm x_1$$ and thereby giving rise to the next ray $$r_2=(\rm x_1,\omega_2)$$. $$r_2$$ might either hit another point $$\rm x_2$$ (located on a surface or a light source) or escape the scene. In the last case, we assume that $$\rm x_2$$ is located on an infinite light.

In summary, we've used the random numbers $$u_1,u_2,u_3,u_4$$ to sample $$\rm x=(\rm x_0,\rm x_1,\rm x_2)$$. Now assume we're switching to the strategy. How can we determine random numbers $$v_1,v_2,\ldots$$ which would have produced the same path $$\rm x$$ under the $$(1,2)$$-strategy?

We should clearly be able to reuse $$u_1,u_2$$, since $$(\rm x_0,\rm x_1)$$ is still part of the truncated camera subpath of the $$(1,2)$$-strategy.

The abstract process is described in Section 6.1 of the paper Charted Metropolis Light Transport.

$$^1$$ It might actually be a composition of multiple BSDFs and $$u_3$$ is used to select one of it.

EDIT: I'm actually trying to implement this in PBRT. So, if necessary, feel free to assume that each BSDF has only a single component and that this component is of type (pbrt::BSDF_REFLECTION | pbrt::BSDF_DIFFUSE). Thus, you can assume that there is a single Lambertian BSDF at each surface point.