Home Technical Talk

Newbie question about ambient occlusion

jayrabbit
polycounter lvl 17
Offline / Send Message
jayrabbit polycounter lvl 17
I've been hearing a lot about ambient occlusion lately and I kinda understand what it is and how to make an AO map, but I don't know how to use it.

I understand the idea of adding the AO map to the diffuse map in order to make the diffuse map look prettier, but I've also seen meshes having a separate AO map and that's the part I don't get.

How do game engines use these AO maps? Can you use them for animated models and dynamic props or only for static objects? What engines support AO maps?

Any help is appreciated smile.gif

Replies

  • MoP
    Options
    Offline / Send Message
    MoP polycounter lvl 18
    What meshes have you seen that have separate AO maps that are used in game? I'd be interested in seeing which games are using this, and what their assets look like - any links?

    Generally I just use AO maps as multiply layers over the diffuse and specular maps, but they can also be good when used as masks for other layers (to make dirt appear in cracks etc).
  • jayrabbit
    Options
    Offline / Send Message
    jayrabbit polycounter lvl 17
    There's a recent thread at mapcore where the guy used an AO map for his model: http://mapcore.net/forums/viewtopic.php?t=7544&postdays=0&postorder=asc&start=0

    There's also a shader by Ben Cloward that makes use of AO maps: http://www.bencloward.com/shaders_globalIllum.shtml

    I'm wondering if there are any game engines that use AO maps and how they do it.
  • jayrabbit
    Options
    Offline / Send Message
    jayrabbit polycounter lvl 17
    I just found 2 engines that apparently support some sort of real-time AO lighting.

    check out this crysis video: http://www.gametrailers.com/gamepage.php?fs=1&id=2509

    and also the features of the C4 engine: http://www.terathon.com/c4engine/features.php

    does anybody know how that stuff works?


    // I just noticed that the crysis video doesn't open. Just look for the "GDC 2006 Trailer" at Gametrailers.com
  • MoP
    Options
    Offline / Send Message
    MoP polycounter lvl 18
    I'm still not entirely sure how Crysis' system works.
    I recall hearing a while back (although this may not be how they're doing it), that their ambient occluded lighting for environments is all precalculated (basically just lightmaps) and several frames of shadow information is saved in lightmap form if the indoor lights need to move. So I'd imagine they won't be using it much, since it sounds like a fairly expensive solution.
    However, I might be wrong about that (I googled for more info on it, but couldn't find out any more frown.gif ), if someone else has a better idea or a solid link to an article explaining the process, that'd be cool.

    As for the Mapcore link you posted, I'm not sure why that guy had a separate AO map - he says he had to individually unwrap the whole mesh for a unique texture, so in that case, why didn't he just use the AO map as a layer multiplied over his diffuse/specular maps, it would have the same effect. Unless there is some kind of calculation used at render time which changes how the AO map is used (ie. it fades out when lit directly or something).

    Sorry to just add more questions to this thread, but I'm interested too, and would like to read any articles on how or why AO maps are being implemented in realtime.
  • Daz
    Options
    Offline / Send Message
    Daz polycounter lvl 18
    There's an nVidia GDC paper here on realtime AO: http://download.nvidia.com/developer/presentations/GDC_2004/GDC_2004_Ambient_Occlusion.pdf
    There's also an executable somewhere on the nvidia site (cant find it right now) that shows off realtime VERTEX AO.
    The paper talks about the use of them in shadowmap form as being for lighting modulation.

    The paper is talking about GPU generated maps of course, and they would need to be If you wanted them to be dynamic. Which negates any need to user generate them. Therefore I can only assume that what you were driving at is correct Paul: There is little use for user created AO maps other than to bake into your colour maps.

    *edit* the pdf format is the devil itself. They always seem to completely lock up my machine.
  • ZEROrhythm
    Options
    Offline / Send Message
    Well my only reason to have the map separated, is to save texture memory, specially if you have a scene with a lot of repeating patterns a small ambient occlusion map would work well in a different UV channel which can overlay your diffuse channel. which in terms would work something like a dirt map or a light map and so forth. It was something similar which I've done in building a level. It does bring more life into the scene to break up your pattern maps.
  • MoP
    Options
    Offline / Send Message
    MoP polycounter lvl 18
    ZEROrhythm: I think you just described lightmaps (as in the sort that have been used since Quake 2!). An AO map in the situation you just described is just a lightmap except maybe rendered with a fancier lighting system to get bounced light and such. But I'm pretty sure the Q3 map compiler has had radiosity lightmap baking in for years. I don't see how that's different to stsatic ambient occlusion.

    As I said earlier too, even if you're baking many frames of lightmaps to get a fake "moving radiosity/AO" solution, that still doesn't really answer any questions about how AO maps are used in games.

    I think Daz is onto it though, GPU-generated AO maps sounds like what we should be discussing, since that doesn't involve manually baking a lightmap from your 3d modelling app or level editor. Thanks for the link Daz.
  • jayrabbit
    Options
    Offline / Send Message
    jayrabbit polycounter lvl 17
    I'm gonna use this thread for another AO question:

    I just baked an AO map for the first time and noticed that every polygon that is facing away from the "sun" is darkened. Does that mean, that AO maps (added to the diffuse map) are useless for dynamic objects like physics props?

    Another issue I got is that the AO map I baked had an awful lot of missing rays (red spots) while the normal map that I rendered in the same process had none. How is that possible?
  • EarthQuake
    Options
    Offline / Send Message
    I'm going to go ahead and assume what crysis is doing is actually Pre-computer Radiance Transfer(PRT). Reality engine does this as well and its quite expensive indeed.... I'm sure someone a bit more technical than me can try to explain what that is.
  • EarthQuake
    Options
    Offline / Send Message
    [ QUOTE ]
    I'm gonna use this thread for another AO question:

    I just baked an AO map for the first time and noticed that every polygon that is facing away from the "sun" is darkened. Does that mean, that AO maps (added to the diffuse map) are useless for dynamic objects like physics props?

    Another issue I got is that the AO map I baked had an awful lot of missing rays (red spots) while the normal map that I rendered in the same process had none. How is that possible?

    [/ QUOTE ]

    Having some ambient shadows is never a bad thing, if you're talking about actual directional lighting then yeah, you dont really want any of that in your ambocc map. But ambient shadows help to add a lot of depth to your normals mapped objects.

    Also dont be afraid to tweak the ambient maps in photoshop either, adding some color can sometimes help a lot, especially on characters. Just like you wouldnt shade some materials to black with old school texturing you shouldnt multiply a grey ambient map on top of them.
  • jayrabbit
    Options
    Offline / Send Message
    jayrabbit polycounter lvl 17
    [ QUOTE ]
    [ QUOTE ]
    I'm gonna use this thread for another AO question:

    I just baked an AO map for the first time and noticed that every polygon that is facing away from the "sun" is darkened. Does that mean, that AO maps (added to the diffuse map) are useless for dynamic objects like physics props?

    Another issue I got is that the AO map I baked had an awful lot of missing rays (red spots) while the normal map that I rendered in the same process had none. How is that possible?

    [/ QUOTE ]

    Having some ambient shadows is never a bad thing, if you're talking about actual directional lighting then yeah, you dont really want any of that in your ambocc map. But ambient shadows help to add a lot of depth to your normals mapped objects.

    Also dont be afraid to tweak the ambient maps in photoshop either, adding some color can sometimes help a lot, especially on characters. Just like you wouldnt shade some materials to black with old school texturing you shouldnt multiply a grey ambient map on top of them.

    [/ QUOTE ]

    The problem is that these polygons facing away from the sun get really dark and it would rather look awkward ingame if the objects gets turned upside down due physical interaction.

    Is there any way to render AO maps with light coming from all sides, even from below?
  • EarthQuake
    Options
    Offline / Send Message
    Well first off lets start out with what program you're using to render ambient maps. If you're just doing some sort of global illumination with nothing else in the scene you shouldnt be getting directional lighting in your ambocc maps. For example in max, just throw in a skylight, and set your advanced lighting to lightracer and bam, ambocc.

    Also some screenshots would probablly be useful.
  • jayrabbit
    Options
    Offline / Send Message
    jayrabbit polycounter lvl 17
    I'm using 3ds Max 9. All I did is to set the renderer to Mentalray and chose Normalmap and AO map from a list in the render-to-texture dialog.

    By the way I've just seen that baking a normalmap in mentalray gives me the same odd missed rays (red spots). Does it have something to do with this: http://boards.polycount.net/showflat.php?Cat=0&Number=117131&an=0&page=0#Post117131 ?

    /edit: I just tried the skylight+raytracer approach and it worked very well. is there any disadvantage of this method over the mentalray AO?
  • CrazyButcher
    Options
    Offline / Send Message
    CrazyButcher polycounter lvl 18
    in the normalmap sample for luxinia I used the AO map for the "unlit" side, which makes sense imo as the simple "flat ambient" color isnt natural. That is where I see best run-time use possibility, and would require a separate texture (or stored into diffuse alpha).



    the technique where multiple lightmaps are generated and then packed to a new representation (such has spherical harmonics or spherical radial basis vectors), is called relighting. That new representation costs much less memory but can still regenerate lighting conditions for all possible light directions (spherical), though at cost of precision of course. Those "lightmaps" which are packed, are user generated. You must generate lots of lightmaps to represent different incoming light directions, lots of raw rendering power needed.

    Real-Time, basically similar as above but simplified. Some precomputation finds out how the object interacts with itself. Lighting of multiple lights (or sky) is turned into a series of vectors/matrices which are evaluated on vertex/pixel level combined with the precomputed values. To generate good vectors you would do some lighting on CPU on special points around the object. There you can also take shadows into account. Or render a lowres cubemap from the object's place to get incident light of enviro.
    Another factor is neighbor interaction, so that other objects influence the light of shadow receivers.
    I a just scrimmed over some tech docs myself, so I probably overlooked some issue for the latter wink.gif It is very costly effect, hence I am not sure if it makes much use yet. I am more of a fan of oldschool precomputation and fast run-time evaluation, like the first two offer.

    edit:
    removed the image, as it was misleading
  • MoP
    Options
    Offline / Send Message
    MoP polycounter lvl 18
    Crazybutcher: Wow, thanks for the writeup.. that's kinda what I was thinking anyway, but that helps smile.gif

    Jayrabbit: No downsides that I know of to using the skylight + advanced lighting. It's how I bake all my AO maps.
  • Joao Sapiro
    Options
    Online / Send Message
    Joao Sapiro sublime tool
    wow , that sure is interesting, is it "expensive" realtime wise ?


    P.S - hey mop , for some reason my AO now decided to come only one color, i set everything as i did before it gets fooked up , but now only renders one colour frown.gif ( grey )
  • CrazyButcher
    Options
    Offline / Send Message
    CrazyButcher polycounter lvl 18
    AO should be grey, it's only "how much light from sky can hit me"

    mixin the AO map isnt very expensive, the only costs come from a texel lookup, some lerping and one more texture in memory. which of course might be an issue with so many textures already in use...
  • Joao Sapiro
    Options
    Online / Send Message
    Joao Sapiro sublime tool
    thanks crazybutcher ! so the ao map in the ambient slot ?
  • EarthQuake
    Options
    Offline / Send Message
    CB: Are you using the ambient to actually shade the model in the screenshot? Because that would look very wrong in a low-light situation wouldnt it?

    IMO The best use of ambient maps is to actually add subtle occluded shadows that you would even see when lit to your texture, of course tweaking the colors so they are more natural. What you're doing there looks more like you're using the ambient occlusion map to give you ambient lighting, which seems sort of backwards to me.

    Really the best use i see of ambient maps as a seperate texture is for tiling enviro stuff that you cant bake into the diffuse, and i know for things like that you definately do what to have that little bit of ambient shadow when its lit or else it will just look really flat and fake.
  • CrazyButcher
    Options
    Offline / Send Message
    CrazyButcher polycounter lvl 18
    the tiling stuff is a good point (and actually the same as good old lightmaps), for unique you are right it makes more sense to bake into diffuse.

    In that sample I purely use the AO, which is wrong as all color and texture is lost in ambient, which wouldnt be the "right" thing, as you mentioned. Purely using the diffuse alone, however didnt look that good either, I guess one could mix the AO in more cleverly for the ambient side combined with original diffuse. I didnt invest a lot of time into it, as we dont have normalmapping and alike for our stuff. But I do think that having a separate AO gives you more tweakables to play around with, which might result into giving stuff more shape.
    Making use of it in "large-scale" as for every model and so on, is probably not feasable.
    Per's colormap already made use of the AO, as you suggested. It probably would be sufficient to simply desaturate the ambient side, to achieve a similar look (with more color left and texture).

    edit:
    just experimented with simply desaturating the ambient side a bit, and it basically is better than the simple model before. I removed the image, as it was misleading about the actual useage of AO.
  • MoP
    Options
    Offline / Send Message
    MoP polycounter lvl 18
    [ QUOTE ]
    Really the best use i see of ambient maps as a seperate texture is for tiling enviro stuff that you cant bake into the diffuse, and i know for things like that you definately do what to have that little bit of ambient shadow when its lit or else it will just look really flat and fake.

    [/ QUOTE ]

    I find that for environment stuff, you don't even need an AO map, you can just make really small gradient textures (radial and linear) and use them as decals in places where it will be most noticeable. Looks very effective, and means you don't have to bake tons of textures on different UV channels to make everything unique.
  • EarthQuake
    Options
    Offline / Send Message
    Wouldnt creating multiple textures that need to be alpha sorted end up being much more expensive in most cases? And really not very useful for getting specific shapes, maybe for simple objects but really that seems like even more effort to me to go in and place all of that extra stuff when you can just do some auto-generated uvs and render a lightmap that gets multiplied onto your object....

    Also do you have any examples of this that you can show?
  • Black_Dog
    Options
    Offline / Send Message
    Black_Dog polycounter lvl 17
    Decals typically don't need to be sorted as they are close enough to geometry to assume nothing transparent will need to render behind them. They usually just go in a late sort bucket afaik.
  • Whargoul
    Options
    Offline / Send Message
    Whargoul polycounter lvl 18
    AO maps are meant to block ambient light only - hence the name "ambient" occlusion. Some original uses were in the movies, where they would scale back the HDR light sphere (probe mapping). Regular lighing is still applied as usual.

    In the tests I've been doing, I've been using it similarly. We are using SH to represent our ambient lights, and I scale that against AO. I then bias the AO towards white (to lessen it's affect greatly) and scale the rest of the real lights (points, spots, directionals) against that (both the diffuse and specular contribution).
  • EarthQuake
    Options
    Offline / Send Message
    Whargoul: I'm pretty sure that we're doing that too, using image based lighting and basicly using the ambient to mask off areas so they're using the same colors as the shadows generated from our hdr skyboxes, plus multiplying it a little bit so they're a tad darker and show up even with low lighting.
  • Daz
    Options
    Offline / Send Message
    Daz polycounter lvl 18
    Interesting info thanks all.

    [ QUOTE ]

    Is there any way to render AO maps with light coming from all sides, even from below?

    [/ QUOTE ]

    Well, technically a default AO map should 'light from all sides'. Which reminds me, this might seem obvious to most, but for baking AO maps for character work, I usually put in a ground plane in the scene, thus making the lighting somewhat more directional from above, which is probably more like what you'd want for most situations:

    ao.jpg
  • EarthQuake
    Options
    Offline / Send Message
    Baked radiosity onto auto generated 2nd uvs + next next next gen lighting, oh em gees
    balls.jpg
  • Eric Chadwick
    Options
    Offline / Send Message
    Are those tits or testicles?
  • onehundredfeet
    Throwing a ground plane in makes sense if the ground is part of the 'occluding' geometry.

    Ambient occlusion is just a measure, from zero to one, of how much the near-by area lets light in to a point (where zero is no light and one is full light). It's a poor representation of higher frequency direct lighting, and should only be used to impact the ambient light typically, and for dramatic effect, impact the diffuse (and possibly specular) channels slightly (40-60% works well).

    If your ground plane is actually a 'light source', i.e. bounce, then putting an occluding ground plane in doesn't make sense. Once your model gets lit, you'll see the top being brighter than the bottom anyway.

    I find people use ambient occlusion too much to replace good direct lighting, everything starts to look dingy. Ground bounce is really well represented by imaged based (or harmonic) lighitng.


    Good to see people talking about it.
  • Daz
    Options
    Offline / Send Message
    Daz polycounter lvl 18
    [ QUOTE ]
    Throwing a ground plane in makes sense if the ground is part of the 'occluding' geometry.

    Ambient occlusion is just a measure, from zero to one, of how much the near-by area lets light in to a point (where zero is no light and one is full light). It's a poor representation of higher frequency direct lighting, and should only be used to impact the ambient light typically, and for dramatic effect, impact the diffuse (and possibly specular) channels slightly (40-60% works well).

    If your ground plane is actually a 'light source', i.e. bounce, then putting an occluding ground plane in doesn't make sense. Once your model gets lit, you'll see the top being brighter than the bottom anyway.

    I find people use ambient occlusion too much to replace good direct lighting, everything starts to look dingy. Ground bounce is really well represented by imaged based (or harmonic) lighitng.


    Good to see people talking about it.

    [/ QUOTE ]

    I rarely get too bogged down with the math behind stuff. I just go with my gut about the best look for what I want to achieve. If we are talking about a baked AO map for a characters face, generally I throw in a ground plane to block any rays from below. Which creates a more impactful and less blown out to white AO map generated from rays coming from every which way.
Sign In or Register to comment.