It is currently Mon Feb 24, 2020 5:47 pm

 All times are UTC

 Page 1 of 1 [ 6 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Calculating Ambient Occlusion in PolyVoxPosted: Sat Jan 29, 2011 4:14 pm
 Developer

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Hey all,

I wanted to share some work I've been doing on computing ambient occlusion in voxel based environments. I actually added this to PolyVox SVN a couple of weeks ago but didn't get a chance to post about it yet.

Ambient occlusion is basically a measure of how much ambient light can reach a given point in the scene. It's simply a scale factor which you can multiply by the ambient light in your scene in order to make it darker inside caves, creavices, etc.

In order to compute the ambient occlusion for a given point, you can cast a large number of rays in different directions from the point in question. Then you simply count how many of these rays hit solid geometry. The percentage of rays which do not hit geometry gives a measure for how visible the point is to ambient light. The actul casting of rays can be performed using the Raycast class which was recently added to PolyVox.

The results can look something like the following. Note that there are no lights in the scene shown below - the variation in shading is completely due the ambient occlusion:

There is also the question of how this ambient oclcusion data should be stored. The new AmbientOcclusionCalculator class stores the results in a 3D array which I upload to the GPU as a volume texture. I'm using an ambient occlusion volume which is 1/4 the size of the main volume along each axis (so 1/64 the memory), but this still won't be appropriate for very large volumes. In that case, you'll probably want to investigate storing the data in the vertices instead. I can give more information if people are interested in this, you'll need to do some implementation yourself but you can still build on the Raycast class and use the existing work as an example.

The example scene above is 256x256x64, and the ambient occusion volume texture is 64x64x16. For each element in the ambient occlusion texture I cast 256 rays meaning a total of 16 million rays were cast. This took about 10 seconds on my machine. However, it's worth noting that ambient occlusion is a local effect, so that when the volume changes you only need to update the ambient occlusion for parts of the volume which are nearby. In Thermite it's close to realtime - I think that the flashes from explosions, etc will cover up any artifacts during the fraction of a second it will take to recompute.

Anyway, I hope this is interesting/useful to someone

Top

 Post subject: Re: Calculating Ambient Occlusion in PolyVoxPosted: Sat Jan 29, 2011 6:23 pm

Joined: Sat Sep 18, 2010 9:45 pm
Posts: 189

Top

 Post subject: Re: Calculating Ambient Occlusion in PolyVoxPosted: Sat Jan 29, 2011 10:20 pm
 Developer

Joined: Sun May 11, 2008 4:29 pm
Posts: 198
Location: UK
Looks very good Dave. Seeing things like that and the mesh decimation which are both sort of non-core 'addons' makes me think that it would be a good idea to make sure we're including things like this in the PolyVox documentation; maybe on a sort of 'how do I ...' page. Thinking about the docs, we currently/should have:
• API docs in the form on Doxygen
• a tutorial for the basics
• conceptual descriptions about voxels/regions/blocks etc
• a How-to section including code snippets (for AO and decimation)
I'll try to have a go at adding at least a skeleton for this when I get a chance.

_________________
Matt Williams
Linux/CMake guy

Top

 Post subject: Re: Calculating Ambient Occlusion in PolyVoxPosted: Mon Jan 31, 2011 10:29 pm
 Developer

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Sorry, for the slow reply, I was away for a couple of days.

Regarding the documentation, I just added some API docs for the Raycast class. I'll try to do the AmbientOcclusionCalculator as well. Not sure how much I've told you but I have plans for a new website in the next six months or so... let's try to improve the docmentation for then

Well, we can follow this up in the existing 'documentation' thread, but for now I've also added an 'API docs' link to the main webpage here

Top

 Post subject: Re: Calculating Ambient Occlusion in PolyVoxPosted: Sat Feb 05, 2011 1:53 pm

Joined: Sun Oct 03, 2010 10:13 pm
Posts: 73
This sounds interesting. I'm no expert regarding ambient occlusion but from what I understand I could use it to partly substitute shadows for example in caves. I will probably look more into this when my game is more finished.

Top

 Post subject: Re: Calculating Ambient Occlusion in PolyVoxPosted: Sat Feb 05, 2011 3:36 pm
 Developer

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Yes, that basically correct. It doesn't need any particualr light source, it simply an estimate of how much ambient light will reach a given point. It will be useful for caves, overhangs, underground areas, that sort of thing. You can also have your characters sample the same ambient occlusion texture so they fit in better with the environment.

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 6 posts ]

 All times are UTC

#### Who is online

Users browsing this forum: No registered users and 1 guest

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ General Discussion Forums    General Discussion PolyVox Forums    PolyVox Discussion    PolyVox Bugs    Showcase Cubiquity Forums    Cubiquity Discussion Voxeliens Forums    Voxeliens Discussion    Voxeliens Support