Skip to main content
GameDev.net gamedev.net
🔒 Locked

Ambient Occlusion sampling [SOLVED]

Started by Sweenie May 17, 2006 at 2:23 AM 1 replies 1.5k views
Original Post
Sweenie
Sweenie
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]
<-Sweenie->
Dmytry
Dmytry
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])
Sweenie
Sweenie
Aha!, that makes sense. :)

Thank you very much Dmytry.
<-Sweenie->

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.