Skip to main content
GameDev.net gamedev.net
🔒 Locked

precomputing ambient occlusion

Started by DragonSpace Jun 30, 2009 at 5:28 PM 3 replies 1.6k views
Original Post
DragonSpace
DragonSpace
For precomputing ambient occlusion for an object, is the algorithm just: For each polygon in the object 1. Pick the center point and cast N random rays over the hemisphere and test if the ray intersects the object 2. Then AmbientFactor = number of ray misses / total number of rays cast Then I would have an occlusion factor for each polygon, and would I just do an averaging process (similar to normal averaging) to get it at each vertex? To build an ambient occlusion texture map, you would have to unwrap the mesh, but do the same algorithm per texel?
Nik02
Nik02
Yes.


The distribution of the random rays can be tricky, but in general I've found that the best results are achieved if you use polar coordinates (that is, rotate the vector using random angles) instead of cartesian coordinates (moving the vector endpoint linearly with random components and normalizing it). The reason for this is that when you compress a "box space" to a "sphere space" by normalizing 3d cartesian coordinates, the edges and corners of the box weigh more than the centers.
Niko Suni
DragonSpace
DragonSpace
Quote:

The distribution of the random rays can be tricky, but in general I've found that the best results are achieved if you use polar coordinates (that is, rotate the vector using random angles) instead of cartesian coordinates (moving the vector endpoint linearly with random components and normalizing it). The reason for this is that when you compress a "box space" to a "sphere space" by normalizing 3d cartesian coordinates, the edges and corners of the box weigh more than the centers.


Don't spherical coordinates have a similar problem in that points bunch of near the poles? I thought that is what this addressed:

http://mathworld.wolfram.com/SpherePointPicking.html

Also, I think if you generate random points in the cube [-1,1]^3, but discard points outside the unit sphere, then it generates an even distribution.
Nik02
Nik02
You are right in the fact that if you want a perfect spherical distribution, the Mathworld approach is more correct than polar rotation.

However, we had a long discussion with the GDNet DirectX guys in the past about which distribution is actually correct for the specific case of modulating ambient light.

There are two options:

1: Perfect hemisphere distribution
2: Perfect hemisphere, but weighed towards center with cosine

Option 1 would seem intuitive, and it is indeed the correct way to calculate the total occlusion of given geometry at given point. However, due to the fact that we are specifically talking about light concentration (or lack of it), it may actually be more correct to apply cosine weighting (option 2) to the distribution in order to statistically model the reflection percentage of the light. Remember, ambient and directional light have no difference in real life.

I'm a proponent of option 2 because it more accurately seems to emulate the actual end result. If someone, someday can actually prove otherwise, I'll take their word for it.

I admit that the method of polar rotations does not result in exactly either of these options - however, it does give nice visual results.
Niko Suni
Schrompf
Schrompf
Alternatively you can simply render the environment into a cubemap or paraboloid map and then accumulate all pixels weighted by the area they cover when projected on a sphere. Works fine for me, it's alot quicker than raycasting for most scenes, and you can use your working engine instead of implementing raytracing on top of the current rendering :-)
----------
Gonna try that "Indie" stuff I keep hearing about. Let's start with Splatter.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.