Tedious bugs in my bidirectional path tracer.

Practical and theoretical implementation discussion.
shiqiu1105
Posts: 138
Joined: Sun May 27, 2012 4:42 pm

Tedious bugs in my bidirectional path tracer.

Post by shiqiu1105 » Thu Jul 05, 2012 5:04 am

Hi guys,

I have been trying to create my bidirectional path tracer for a long while.
But there were always bugs which I was having a hard time debugging!

The result image is down below.
My bidir path tracer generates noiser images than my path tracer when the same amount of samples are used :(

Bidir:
Image
Normal path tracer:
Image

Notice that not only is the bidir version noiser, they seem to converge to different colors too. Any idea how to debug?
Bidir path tracer is particularly noisy in the edges, as you can see.

Or can I put up the source code so that you guys can help?

spectral
Posts: 382
Joined: Wed Nov 30, 2011 2:27 pm
Contact:

Re: Tedious bugs in my bidirectional path tracer.

Post by spectral » Fri Jul 06, 2012 8:29 am

Hum,

There are plenty possible problems... I have a few ideas like floating point precision problems, probabilities computation error, wrong MIS computation, non uniform light sampling etc...

But without code it is difficult... if you share your code we will be able to take a closer look and debug !
Spectral
OMPF 2 global moderator

ingenious
Posts: 282
Joined: Mon Nov 28, 2011 11:11 pm
Location: London, UK
Contact:

Re: Tedious bugs in my bidirectional path tracer.

Post by ingenious » Fri Jul 06, 2012 9:06 am

If you're trying to do multiple importance sampling with balance/power heuristic weighting, then your weights are definitely wrong. Try first with uniform weights to see whether the path contributions are computed correctly. That is, set the weight for each path to 1 / number_of_possible_ways_to_generate_path. If contributions are computed correctly, then applying these weights will make the two images have the same overall brightness, but you'll still have the speckles around the corners. And at this point it will be clear how useless bidirectional path tracing is without multiple importance sampling. After that you can move on to MIS.
Image Click here. You'll thank me later.

shiqiu1105
Posts: 138
Joined: Sun May 27, 2012 4:42 pm

Re: Tedious bugs in my bidirectional path tracer.

Post by shiqiu1105 » Sat Jul 07, 2012 4:53 pm

ingenious wrote:If you're trying to do multiple importance sampling with balance/power heuristic weighting, then your weights are definitely wrong. Try first with uniform weights to see whether the path contributions are computed correctly. That is, set the weight for each path to 1 / number_of_possible_ways_to_generate_path. If contributions are computed correctly, then applying these weights will make the two images have the same overall brightness, but you'll still have the speckles around the corners. And at this point it will be clear how useless bidirectional path tracing is without multiple importance sampling. After that you can move on to MIS.
How do you know if two images have the same overall brightness?
I am now trying the unform-weighted bidir path tracing, and I am posting the result.

Uniform-weighted bidir path tracing with 36 samples per pixel, maximum path length 5
bidir.jpg
bidir.jpg (140.36 KiB) Viewed 8582 times
and regular path tracing with also 36 spp.
path.jpg
path.jpg (95.33 KiB) Viewed 8582 times
The bidirectional version has A LOT fireflies, and seems to be a little brighter, which I am not sure is caused by the uniform weights or bugs...

Do you know?

graphicsMan
Posts: 167
Joined: Mon Nov 28, 2011 7:28 pm

Re: Tedious bugs in my bidirectional path tracer.

Post by graphicsMan » Sat Jul 07, 2012 4:56 pm

just take a larger number of samples and then average all the samples in the image.

ingenious
Posts: 282
Joined: Mon Nov 28, 2011 11:11 pm
Location: London, UK
Contact:

Re: Tedious bugs in my bidirectional path tracer.

Post by ingenious » Sat Jul 07, 2012 10:38 pm

shiqiu1105 wrote:How do you know if two images have the same overall brightness?
I am now trying the unform-weighted bidir path tracing, and I am posting the result.

The bidirectional version has A LOT fireflies, and seems to be a little brighter, which I am not sure is caused by the uniform weights or bugs...

Do you know?
For checking the brightness, I use a very trivial and easy method, which has proven extremely useful to me. I just paste both images in Windows Paint one after the other in the same document and then flip between them many times with the undo/redo shortcut keys to get a visual comparison. Zooming out a bit before flipping often helps, as the averaging essentially performs oversampling (albeit lowering the resolution, obviously).

I just compared your images in the above way and yes, one is definitely brighter. But before any comparisons, you must be absolutely sure than the path lengths in both images are the same. Otherwise this comparison is useless.

The bidirectional version is normal to have a lot of fireflies, as we discussed already. This is due to a notorious singularity in the path contribution, which occurs around corners. MIS will solve this problem, don't worry for now.
graphicsMan wrote:just take a larger number of samples and then average all the samples in the image.
This is very sensitive to outliers. I recommend a visual comparison. If differences are not apparent in this way, you can save high dynamic range renderings, diff the two images, save the positive/negative difference as a file, and finally examine this file visually (with increased brightness).
Image Click here. You'll thank me later.

shiqiu1105
Posts: 138
Joined: Sun May 27, 2012 4:42 pm

Re: Tedious bugs in my bidirectional path tracer.

Post by shiqiu1105 » Sun Jul 08, 2012 6:30 am

ingenious wrote:
shiqiu1105 wrote:How do you know if two images have the same overall brightness?
I am now trying the unform-weighted bidir path tracing, and I am posting the result.

The bidirectional version has A LOT fireflies, and seems to be a little brighter, which I am not sure is caused by the uniform weights or bugs...

Do you know?
For checking the brightness, I use a very trivial and easy method, which has proven extremely useful to me. I just paste both images in Windows Paint one after the other in the same document and then flip between them many times with the undo/redo shortcut keys to get a visual comparison. Zooming out a bit before flipping often helps, as the averaging essentially performs oversampling (albeit lowering the resolution, obviously).

I just compared your images in the above way and yes, one is definitely brighter. But before any comparisons, you must be absolutely sure than the path lengths in both images are the same. Otherwise this comparison is useless.

The bidirectional version is normal to have a lot of fireflies, as we discussed already. This is due to a notorious singularity in the path contribution, which occurs around corners. MIS will solve this problem, don't worry for now.
graphicsMan wrote:just take a larger number of samples and then average all the samples in the image.
This is very sensitive to outliers. I recommend a visual comparison. If differences are not apparent in this way, you can save high dynamic range renderings, diff the two images, save the positive/negative difference as a file, and finally examine this file visually (with increased brightness).
Thanks a lot for your help.

I rendered 2 images with uniform-weighted bidirectional path tracing and regular path tracing with path length being 5 and no russian roultte. The result is still that the bidirection one is slightly brighter and with a lot more firefilies.

I made comparison with results from this site: http://graphics.ucsd.edu/~iman/BDPT/
It looks like his unform-weighted bidir path tracing is darker in general than path tracing. (though we don't know his path length or if RR is applied)
And he has much less fireflies than I do in uniform-weighted bidir path tracing.

So I am wondering if there is still bug, or just the MIS is lacking. If it's the later case, hopefully, then I can just add MIS now :)

ingenious
Posts: 282
Joined: Mon Nov 28, 2011 11:11 pm
Location: London, UK
Contact:

Re: Tedious bugs in my bidirectional path tracer.

Post by ingenious » Sun Jul 08, 2012 8:17 pm

Are you absolutely, 100 percent sure that the paths in both images have maximum length of 5 and that you don't miss some possible paths? When connecting eye and light sub-paths, you need to watch out for the length of the resulting full path!

And image without MIS can be slightly darker, but *only* around corners, where the fireflies converge very slowly. In the middle of the walls, the brightness should be the same.

And I have strong suspicion that the implementation from the web page you linked above is wrong. I've compared the images, and they have different brightnesses. Moreover, with proper MIS implementation, all fireflies in a diffuse Cornell box go away, so there's absolutely no need for special treatments of short paths as suggested there. So take the results with a grain of salt.
Image Click here. You'll thank me later.

shiqiu1105
Posts: 138
Joined: Sun May 27, 2012 4:42 pm

Re: Tedious bugs in my bidirectional path tracer.

Post by shiqiu1105 » Mon Jul 09, 2012 2:14 am

ingenious wrote:Are you absolutely, 100 percent sure that the paths in both images have maximum length of 5 and that you don't miss some possible paths? When connecting eye and light sub-paths, you need to watch out for the length of the resulting full path!

And image without MIS can be slightly darker, but *only* around corners, where the fireflies converge very slowly. In the middle of the walls, the brightness should be the same.

And I have strong suspicion that the implementation from the web page you linked above is wrong. I've compared the images, and they have different brightnesses. Moreover, with proper MIS implementation, all fireflies in a diffuse Cornell box go away, so there's absolutely no need for special treatments of short paths as suggested there. So take the results with a grain of salt.
Well, the scene I rendered was an open Cornell box, which means it's possible for rays to fly out of the scene. I guess I can make some adjustments and do the test again.

However, I did some other experiments last night. I made a closed scene, where all the boundaries are emitting objects with emitting power being 0.5. In this case, both my path tracer and my bidir path tracer(uniform-weighted) converge to 1.0, which I think is correct.
Does this render my bidir path tracer bugs-free?

shiqiu1105
Posts: 138
Joined: Sun May 27, 2012 4:42 pm

Re: Tedious bugs in my bidirectional path tracer.

Post by shiqiu1105 » Mon Jul 09, 2012 12:06 pm

ingenious wrote:Are you absolutely, 100 percent sure that the paths in both images have maximum length of 5 and that you don't miss some possible paths? When connecting eye and light sub-paths, you need to watch out for the length of the resulting full path!

And image without MIS can be slightly darker, but *only* around corners, where the fireflies converge very slowly. In the middle of the walls, the brightness should be the same.

And I have strong suspicion that the implementation from the web page you linked above is wrong. I've compared the images, and they have different brightnesses. Moreover, with proper MIS implementation, all fireflies in a diffuse Cornell box go away, so there's absolutely no need for special treatments of short paths as suggested there. So take the results with a grain of salt.
Thanks for your really helpful reply!

The thing is, I've tried implemented the MIS myself, but failed.
I was following Veach's thesis, http://graphics.stanford.edu/courses/cs ... pter10.pdf

But I didn't use the forward/backward ratio suggested in this paper.
Basically I pre-computed the exact probability of each light/eye vertex, using the equation: P(pi) = P(pi-1 to pi) * GeoTerm * P(pi-1), where P() stands for probability.
And then I sum all the weights for one sampling technique up to an array. And when connecting two paths, I just mutiply the two connecting-nodes' pre-computed weights and divided them by the sum to weight the current connection. So the sum of all weights should be one.

But this doesn't work, image is still noisy.

I have some specifics to mention though.
1. Since I used a pinhole camera(no way to sample on the camera lens), I assign the first eye vertex with probability 1.0
2. I assign the first light vertex with probability 1.0f / Area.

I don't know if I did those right.

Do you know where I can find some easy-to-read implementation of BDPT with MIS? I've been reading Lux, but it seems very complicated... :(

Post Reply