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


All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Calculating Ambient Occlusion in PolyVox
PostPosted: Sat Jan 29, 2011 4:14 pm 
Developer
User avatar

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:

Image

Image

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
Offline Profile  
Reply with quote  
 Post subject: Re: Calculating Ambient Occlusion in PolyVox
PostPosted: Sat Jan 29, 2011 6:23 pm 

Joined: Sat Sep 18, 2010 9:45 pm
Posts: 189
That's awesome! downloading now.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Calculating Ambient Occlusion in PolyVox
PostPosted: Sat Jan 29, 2011 10:20 pm 
Developer
User avatar

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
Offline Profile  
Reply with quote  
 Post subject: Re: Calculating Ambient Occlusion in PolyVox
PostPosted: Mon Jan 31, 2011 10:29 pm 
Developer
User avatar

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
Offline Profile  
Reply with quote  
 Post subject: Re: Calculating Ambient Occlusion in PolyVox
PostPosted: 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
Offline Profile  
Reply with quote  
 Post subject: Re: Calculating Ambient Occlusion in PolyVox
PostPosted: Sat Feb 05, 2011 3:36 pm 
Developer
User avatar

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
Offline Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 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 forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created StylerBB.net