Sign in to follow this  
GaryPolter

Compute ambient occlusion

Recommended Posts

I'm a bit confused on how I can calculate ambient occlusion. The Wikipedia page (http://en.wikipedia.org/wiki/Ambient_occlusion) shows the formula where you integrate over a hemisphere to get your occlusion value. I understand the theory that we sweep over the hemisphere and then sum up the occlusion values to get our final value, but I don't understand how to do this in practice.

I think what I don't really understand is how to turn that integral into something that can be calculated on a computer. First, I understand that the integral is actually a double integral, but again, how do I actually calculate the integral? What does it mean in my calculation for [i]w[/i] to be the variable of integration and what values would I actually pass in? The same with [i]dw[/i].

Thanks!

Share this post


Link to post
Share on other sites
Have you read about Screen-space Ambient Occlusion? Its faster, easy to implement and produces "good results". (Most AAA games use this technique)

Anyway if you really want regular AO theres a article about it in [url="http://http.developer.nvidia.com/GPUGems/gpugems_ch17.html"]GPU Gems[/url].

Share this post


Link to post
Share on other sites
[quote name='TiagoCosta' timestamp='1307635145' post='4821361']
Have you read about Screen-space Ambient Occlusion? Its faster, easy to implement and produces "good results". (Most AAA games use this technique)

Anyway if you really want regular AO theres a article about it in [url="http://http.developer.nvidia.com/GPUGems/gpugems_ch17.html"]GPU Gems[/url].
[/quote]

Thanks for the link, TiagoCosta. I've actually been struggling trying to build an intuition regarding using integral equations in a practice. The ambient occlusion integral equation is almost like a simplified rendering equation ([url="http://en.wikipedia.org/wiki/Rendering_equation"]http://en.wikipedia....dering_equation[/url]), so I thought I would start there.

I'd like to be able to figure out how to implement the ambient occlusion equation. First I know I would need something like Monte Carlo integration and choose n random directions. Do I then apply the ambient occlusion visibility function to each of those directions? How do I choose where my ambient occlusion hemisphere goes in the scene? Does it go on all points on all objects?

Share this post


Link to post
Share on other sites
[quote name='GaryPolter' timestamp='1307643398' post='4821410']
First I know I would need something like Monte Carlo integration and choose n random directions. Do I then apply the ambient occlusion visibility function to each of those directions?
[/quote]
Yes, using that direction as ?.

[quote name='GaryPolter' timestamp='1307643398' post='4821410']
How do I choose where my ambient occlusion hemisphere goes in the scene? Does it go on all points on all objects?
[/quote]
Anywhere you want to calculate ambient occlusion. If you're doing screen-space ambient occlusion you might do it per-pixel. If you're doing it to calculate an ambient occlusion texture, you'd do it for each texel of the texture, with whatever resolution you want. If your mesh is very high poly, maybe you calculate ambient occlusion per vertex and pass it in as vertex colors. Basically you calculate it wherever you want it, and where you want it is dictated by how you're going to use it.

Share this post


Link to post
Share on other sites
If you haven't taken any Calculus courses yet (or it's been a while), I'd suggest brushing up a bit by finding some online resources. In particular you'll want to read up on numerical integration, since that's the family of techniques most often employed in computer graphics. Monte Carlo integration is a very useful means of estimating an integral numerically, so you're on the right track by looking into that.

When you're calculating AO for a single point, what you're essentially calculating is what percentage of the hemisphere around that point has visibility to the sky. So when you're integrating about the hemisphere, the question you're asking for each direction is "can I see the sky if I look in this direction?". This is really simple for a ray-tracer: just shoot a ray in that direction, if you don't intersect with any geometry than you have sky visibility (result of 1.0). If you do intersect, then you don't have visibility and you use a result 0.0. This can be combined with Monte Carlo very easily, by generating random ray directions and determining visibility in those directions by casting rays. You just have to be careful to generate your rays with an unbiased distribution, so that each sample has the same PDF. [url="http://www.cs.columbia.edu/%7Ecs4162/slides/spherical-harmonic-lighting.pdf"]This paper[/url] has an introduction to hemispherical integration and Monte Carlo...the end goal is generating spherical harmonics lighting coefficients but the principles behind the numeric integration are the same.

It's also possible to generate AO through rasterization. Generally you rasterize to half of a cubemap (a hemicube), with the visibility for that pixel rendered to the cube map. Then you use standard numeric integration to sum the value in each texel, weighted by differential of that texel (basically the area of the square texel projected onto the hemisphere).

I don't think I would recommend simply skipping to SSAO and copying and pasting some shader code that you downloaded, because you won't totally understand what's going on which makes it very difficult to fix errors or tweak it for better results.

Share this post


Link to post
Share on other sites
[quote name='MJP' timestamp='1307663340' post='4821529']
If you haven't taken any Calculus courses yet (or it's been a while), I'd suggest brushing up a bit by finding some online resources. In particular you'll want to read up on numerical integration, since that's the family of techniques most often employed in computer graphics. Monte Carlo integration is a very useful means of estimating an integral numerically, so you're on the right track by looking into that.

I don't think I would recommend simply skipping to SSAO and copying and pasting some shader code that you downloaded, because you won't totally understand what's going on which makes it very difficult to fix errors or tweak it for better results.
[/quote]

Thanks for the information, MJP. I did take calculus in university (and did well), but since moving into computer graphics I struggle to actually apply any of that knowledge. My professors cared more showing off how smart they were than actually showing how we can use calculus to make money. In fact, I never even heard of Monte Carlo integration until very recently, and it seems like a great tool.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this