erichlof / THREE.js-PathTracing-Renderer

Real-time PathTracing with global illumination and progressive rendering, all on top of the Three.js WebGL framework. Click here for Live Demo: https://erichlof.github.io/THREE.js-PathTracing-Renderer/Geometry_Showcase.html
Creative Commons Zero v1.0 Universal
1.88k stars 171 forks source link

Aperture sampling is wrong! #36

Closed GijsBellaard closed 4 years ago

GijsBellaard commented 4 years ago

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!

erichlof commented 4 years ago

@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