Sign in to follow this  
Sweenie

Ambient Occlusion sampling [SOLVED]

Recommended Posts

Sweenie    180
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.
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))



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]

Share this post


Link to post
Share on other sites
Dmytry    1151
This is correct result. The "Randomize" set the random seed to the clocks; so that if you call
Randomize();// time may be 12:03.456
i=Rnd();
Randomize();// computer is very fast, less than 1/1000 second passed and time is likely to be same
j=Rnd();

there's rather good chances that i and j will be equal because Randomize() would reset the seed .
Only if you call Randomize once, i and j will really be independent

You should only call Randomize() once when your application starts. Consequent calls to Randomize() won't make things more random and will infact make them less random.
[In graphics software, you may as well not call randomize ever if you don't care to get different noise pattern each time you render image.]
(btw it should actually go into math and physics coz Rnd is math related [smile])

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this