mitsuba-renderer/mitsuba-tutorials

Python Path Integrator

andiac opened this issue · 5 comments

Hello! I am trying to replicate the path integrator in Python, here is my code.

I notice that Mitsuba 3 utilizes the dr::loop, may I know how to replicate it in Python?

I tried to replicate the C++ path integrator line by line, but the output of the Python version is still brighter than the C++ version. Could you please give me an example that the path integrator is written in Python?

In Python, the recorded loop will be

loop = mi.Loop("name", lambda: (var1, var2 ... ))
while loop(condition):
    body...

You can find more examples in test_loop.py.

For a Python example of the path integrator, it could be helpful to take a look at prb.py. If you ignore the logic in the if not primal: block, that's essentially a path integrator with standard MIS. A tiny difference is that the path-replay version inherits from the RBIntegrator, while the conventional path integrator can be built on an ADIntegrator.

Thanks!

Hi @ziyi-zhang ! I am reading prb.py and get a question: In line 135, the variable active_next is defined to be

active_next = (depth + 1 < self.max_depth) & si.is_valid()

However, this does not utilize the active calculated in the previous step. The following line seems more reasonable to me:

active_next = active & (depth + 1 < self.max_depth) & si.is_valid()

May I know why the active in the previous step is ignored here? Currently I guess it might be the mechanism of DrJIT's loop.

The active mask will already be accounted for in while loop(active) hence it isn't necessary to add it here. In other words, the loop condition behaves like a mask to every operation occuring in the loop body. This will be better explained in the upcoming Dr.JIT documentation.

@Speierers Thank you very much for the explanation!