Leave a comment

Ambient occlusion for dynamic objects

In this previous post, I described how I implemented a primitive form of ambient occlusion for static objects. The gist of it is that I perform an offline rendering step that creates a texture describing the occlusion at each point in the world, at various heights above the terrain.

The thing lacking here is occlusion for moving objects such as the player or other NPCs. Here’s an example under cloudy skies (no directional light):

 

The character and the ground are muddled together. Contrast that to the static rock in the background, which "casts" an occlusion area around it.

The character and the ground are muddled together and it looks like the man is floating. Contrast that to the static rock in the background, which “casts” an occlusion area around it and appears more “grounded”.

 

My offline-generated static occlusion map is (currently) a large 1024 x 1024 texture. To accomplish occlusion for dynamic objects, I need to add their occlusion effect into that texture each frame.

What I actually do is create a much smaller occlusion map (at runtime) that just covers the area seen by the camera. Each frame, we first copy the relevant portion of the static occlusion map into this much smaller runtime occlusion map. Then, we blend in the occlusion effect of dynamic objects. Then we use this texture in our ambient lighting term, instead of the original large static occlusion map. There is obviously an extra performance cost, but it is negligible.

The effect is subtle (as it should be), but now our character appears much more “grounded”:

 

CharacterWithAO

 

Currently the dynamic occlusion is just a circular disc with a size and strength, but I could change it to other shapes if I needed. I made an Occluder component which can be added to any entity to cause it to “generate occlusion”.

When I first implemented this, I found that the resolution of my occlusion map was not sufficient for moving objects (the underlying occlusion was jittery as the object moved). Here’s the grid resolution:

 

Grid

 

So I just doubled the resolution of the runtime occlusion map (but not the original static map). Now the dynamic occlusion disks are drawn at twice the resolution, which is enough to look good.

It also had the nice effect of smoothing out the static part of the occlusion map (since it undergoes some filtering during the upscaling operation):

 

The griddy pattern in the occlusion map has been smoothed somewhat in the bottom image.

The coarse resolution of the static occlusion map has been smoothed somewhat in the bottom image.

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Just another WordPress site

Just another WordPress.com site

The Space Quest Historian

Adventure game blogs, Let's Plays, live streams, and more

Harebrained Schemes

Developer's blog for IceFall Games

kosmonaut's blog

3d GFX and more

Halogenica

Turn up the rez!

bitsquid: development blog

Developer's blog for IceFall Games

Game Development by Sean

Developer's blog for IceFall Games

Lost Garden

Developer's blog for IceFall Games

Memories

Developer's blog for IceFall Games

Casey's Blog

Developer's blog for IceFall Games

Blog

Developer's blog for IceFall Games

Rendering Evolution

Developer's blog for IceFall Games

Simon schreibt.

Developer's blog for IceFall Games

Dev & Techno-phage

Do Computers Dream of Electric Developper?

- Woolfe -

Developer's blog for IceFall Games

Fabio Ferrara

Game Developer

Clone of Duty: Stonehenge

First Person Shooter coming soon to the XBOX 360

Low Tide Productions

Games and other artsy stuff...

BadCorporateLogo

Just another WordPress.com site

Sipty's Writing

Take a look inside the mind of a game developer.

%d bloggers like this: