Aperture sampling is wrong!
GijsBellaard opened this issue · 1 comments
the following gives a uniform sampling on the aperture:
randomAperturePos = (cos(randomAngle)*cameraRight + sin(randomAngle)*cameraUp)*sqrt(randomRadius)
currently in the code the sqaure root is missing!
@gijsbel
Hi, thank you for bringing this error to my attention! A couple of years back I learned how to do depth of field and different apertures from this old project .
They indeed have the randomRadius square rooted. Now that I have most of the components for a path tracer working, I'm going back and studying books and papers like Peter Shirley's classic "Realistic Ray tracing, 2nd edition", and the online "GI Compendium" in pdf format. I'm trying to learn all the intricacies of Monte Carlo integration, sampling and reconstruction, and why they all work inside path tracers. One of the things I recently learned is that sampling a disk with uniform random variables (0.0 - 1.0) does not give a uniform sampling of the disk or sphere (as you pointed out), but square rooting the radius' random number helps push the samples out from the middle where they would get too clumped if not square rooted.
I have updated the pathtracingCommon.js file and all the animated demos that use their own main function that contains the aperture code. I'll go ahead and close this issue out now that it has been fixed repo-wide. Thanks again!
-Erich