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

creating ambient occlusion map

Started by DragonSpace Jul 2, 2009 at 12:24 PM 1 replies 900+ views
Original Post
DragonSpace
DragonSpace
I have a static ambient occlusion calculator that currently works per vertex. I want to be able to generate an ambient map as a preprocessing step. How would I do this? The mesh would already have texture coordinates defined if that helps.
Nik02
Nik02
Step 1: Ensure that there is no overlap of texture coordinates in the geometry. If there is overlap, the texels in the overlapped areas have no way to unambiguously resolve to one triangle and this will result in wrong values in wrong places.

Step 2: Create a texture map of desired size to hold the occlusion data.

Step 3: For each texel in the texture:

Step 3.1: Find the triangle in which said texel lies. This is a simple 2d point-in-triangle test. This particular step will fail in case of overlapping coordinates, since there would potentially be multiple triangles that contain the texel.

Step 3.2: Solve the barycentric coordinates of the texel on that triangle. You can optimize this step by combining it with step 3.1.

Step 3.3: Interpolate the triangle vertices' positions and normals using the barycentric coordinates as parameters. Now, you have the position and normal of the point where the current texel lies in model space.

Step 3.4: Apply the same algorithm that you would use per-vertex; write the resulting value to current texel.
Niko Suni
Nik02
Nik02
...and step 4: For each texel that didn't fall into any triangle, find the nearest texel that did and copy the value to the "empty" texel. This prevents seams that, while using the occlusion map, occur on open triangle edges due to sample filtering. Shared triangle edges end up using the adjacent triangle's nearest values, so this is not a problem in those.
Niko Suni

Topic Locked

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

Sign in to reply to this topic.