Volumes Of Fun
http://www.volumesoffun.com/phpBB3/

Calculating Ambient Occlusion in PolyVox
http://www.volumesoffun.com/phpBB3/viewtopic.php?f=2&t=131
Page 1 of 1

Author:  David Williams [ Sat Jan 29, 2011 4:14 pm ]
Post subject:  Calculating Ambient Occlusion in PolyVox

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 :-)

Author:  beyzend [ Sat Jan 29, 2011 6:23 pm ]
Post subject:  Re: Calculating Ambient Occlusion in PolyVox

That's awesome! downloading now.

Author:  milliams [ Sat Jan 29, 2011 10:20 pm ]
Post subject:  Re: Calculating Ambient Occlusion in PolyVox

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.

Author:  David Williams [ Mon Jan 31, 2011 10:29 pm ]
Post subject:  Re: Calculating Ambient Occlusion in PolyVox

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

Author:  AndiNo [ Sat Feb 05, 2011 1:53 pm ]
Post subject:  Re: Calculating Ambient Occlusion in PolyVox

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.

Author:  David Williams [ Sat Feb 05, 2011 3:36 pm ]
Post subject:  Re: Calculating Ambient Occlusion in PolyVox

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.

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/