Original Post
Hi. I'm trying to add ambient occlusion to my lightmaps but I'm having some problems when it comes to the sampling part. The web is full of papers explaining how to do cosine-weighted hemisphere sampling but sadly they only show the algorithms which I'm having a hard time converting to code. Anyway, I've managed to find this piece of code... I'm coding this in VB.NET but will move to c++ when I got it working. This almost works but I'm getting weird streaks in the resulting image.
However when I remove the Randomize() function I get a better result
But that makes me confused since I thought Randomize() would make Rnd() produce more random numbers since it used the timer as seed. Am I doing things right or have I only managed to produce something that looks somewhat like the right solution. I'm doing 256 samples by the way, Is the last image too noisy for being 256 samples? [Edited by - Sweenie on May 17, 2006 3:11:03 AM]
Randomize()
E1 = Rnd()
E2 = Rnd()
Theta = 2.0 * PI * E1
Radius = Sqrt(E2)
a = Sin(Theta) * Radius
b = Cos(Theta) * Radius
c = Sqrt(1.0 - (a * a + b * b))
However when I remove the Randomize() function I get a better result
But that makes me confused since I thought Randomize() would make Rnd() produce more random numbers since it used the timer as seed. Am I doing things right or have I only managed to produce something that looks somewhat like the right solution. I'm doing 256 samples by the way, Is the last image too noisy for being 256 samples? [Edited by - Sweenie on May 17, 2006 3:11:03 AM]