evanw/webgl-path-tracing — pull request #1 by jonathanolson (2014-02-24 04:31:52+00:00)
Title: Gamma correction, quadratic light falloff, and randomness improvements.

Hello,

I saw your impressive demo and skimmed the code (I'm working on a 4D raytracing / global illumination personal project using a similar structure) and noticed a few improvements to make the rendered output more realistic. Please ignore this if they were creative liberties to achieve the current rendering!

First thing I noticed was the light falloff (putting the light next to a colored surface didn't impart more of that color to the box), and after that gamma correction was needed so samples could be blended linearly and map approximately to sRGB (I'm ignoring the sRGB details for dark colors that don't follow the power curve).

Additionally, it seemed to have a bit of banding in the noise on my GPU, and after leaving it open for a few days the large timeSinceStart caused rounding issues in the sin-random approximation seen here:
![webgl-path-tracing-randomness](https://f.cloud.github.com/assets/480878/2242662/560aa3dc-9d0b-11e3-9334-35b1cddf2acb.png)

The area around the light generally saturates fairly easily, and the falloff when the light sample box is placed near a surface causes some bounces to have an extremely high contribution to the image creating significant variance and slower convergence in those cases. Putting a ceiling on the contribution of a sample would fix that, but would introduce bias, so I didn't do that.