Compute ambient occlusion

Started by
4 comments, last by GaryPolter 12 years, 10 months ago
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 w to be the variable of integration and what values would I actually pass in? The same with dw.

Thanks!
Advertisement
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 GPU Gems.

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 GPU Gems.


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 (http://en.wikipedia....dering_equation), 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?

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?

Yes, using that direction as ?.


How do I choose where my ambient occlusion hemisphere goes in the scene? Does it go on all points on all objects?

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.
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. This paper 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.

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.


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.

This topic is closed to new replies.

Advertisement