PBRT 7.2.2 illustrates an example on requests sample dimensions in the same order:
sampler->StartPixel(p);
do {
Float v = a(sampler->Get1D());
if (v > 0)
v += b(sampler->Get1D());
v += c(sampler->Get1D());
} while (sampler->StartNextSample());
In this case, the first dimension of the sample vector will always be passed to the function a(); when the code path that calls b() is executed, b() will receive the second dimension. However, if the if test isn’t always true or false, then c() will sometimes receive a sample from the second dimension of the sample vector and otherwise receive a sample from the third dimension. Thus, efforts by the sampler to provide well-distributed sample points in each dimension being evaluated have been thwarted.
So I'm trying to understand this concept by fixing the code: to keep samples always in the same order, we can always prepare a sample for b(), use it when the if test returns true and discard it otherwise:
sampler->StartPixel(p);
do {
Float v = a(sampler->Get1D());
auto second_sample = sampler->Get1D();
if (v > 0)
v += b(second_sample);
v += c(sampler->Get1D());
} while (sampler->StartNextSample());
After fixing, the 1st sample always go to a(), 2nd goes to b() and 3rd goes to c() thus the order is maintained.
Do I understand it correctly? Is my fix correct?