Jump to content
  • Advertisement
Sign in to follow this  

Ambient Occlusion sampling [SOLVED]

This topic is 4422 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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.
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
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
Randomize();// computer is very fast, less than 1/1000 second passed and time is likely to be same

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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!