1
$\begingroup$

I've noticed that I consistently get worse results in path-tracing when I try to do monte-carlo correctly compared to when I don't, and I think this might be because of a fundamental misunderstanding.

My assumption has been that you apply MC in path-tracing by calculating PDFs for each vertex and dividing the bounce contributions by their probability, then dividing the complete path by the number of bounces. This feels wrong, since it isn't what happens in e.g. the Scratchapixel tutorial.

The correct method seems like multisampling the scattering function at each vertex, and integrating those samples using MC. So path contributions from each vertex are multiplied together normally, but each vertex computes sum(samples / pdfs) / num_samples.

In pseudocode, my current understanding is this:

for each bounce
    color *= BRDF(origin, direction, etc) / pdf;
color / num_bounces;

But I think it's really more like:

for each bounce
    for each sample
        contribution += BRDF(origin, direction, etc) / pdf;
    color *= contribution / num_samples;

Am I on the right track? I've been driving myself crazy with this and the algorithm being per-bounce instead of per-path feels like the only way everything would make sense.

$\endgroup$
3
  • $\begingroup$ Why would you want to divide by the number of bounces? You are sampling one vertex after the other sequentially, therefore the PDF of the light path should be the joint conditional probability along vertices $\mathbf{x}_i$ (i.e. $p(\mathbf{x}_0)\prod_{i=1}^{N-1}p(\mathbf{x}_{i}\,|\,\mathbf{x}_{i-1})$.) $\endgroup$
    – Hubble
    Jul 18, 2022 at 17:01
  • 1
    $\begingroup$ What you should have is color += emission * throughput and throughput *= brdf * cos / pdf at each bounce. If you have multiple samples you divide by num_samples. What you are integrating with MC are actually the terms $T^kL_e$ where $T$ is the light transport operator and $L_e$ is the emission function. $\endgroup$
    – lightxbulb
    Jul 18, 2022 at 18:16
  • $\begingroup$ @Hubble cargo cult math 😅. I saw the 1/N and I was already applying the PDF to each bounce so I thought "maybe N is the number of bounces". You're right it doesn't make sense at all, I realized last night after I'd posted the question. $\endgroup$
    – Kate
    Jul 19, 2022 at 3:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.