# Ambient Occlusion sampling [SOLVED]

## Recommended Posts

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

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 on other sites
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 on other sites
Aha!, that makes sense. :)

Thank you very much Dmytry.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628307
• Total Posts
2981972

• 9
• 13
• 11
• 12
• 11