• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
dvds414

Ambient Occlusion from Depth Map?

12 posts in this topic

Hello, does anyone here have any suggestions on how to do Ambient Occlusion from a depth map? I have been trying for a very long time to figure out an equation, but have not been able to. Currently I am using:

 

Occlusion = 255 + ((LeftSample + RightSample + UpSample + DownSample) / 4) - CurrentPixel

 

It does this for every pixel on the screen being displayed. I am not currently looking for a language specific answer more of just some sort of equation I could use on every pixel of a depth map to get the ambient occlusion. Perhaps someone could just get me headed in the right direction?

0

Share this post


Link to post
Share on other sites

Thank you both those are pretty good answers. Do you think you could fine one though for SSAO that just gives a simple equation for getting occlusion from an image? I made a program that loads a depth map image and runs an algorythm on each pixel. What should the equation per pixel be?

0

Share this post


Link to post
Share on other sites

Thank you both those are pretty good answers. Do you think you could fine one though for SSAO that just gives a simple equation for getting occlusion from an image? I made a program that loads a depth map image and runs an algorythm on each pixel. What should the equation per pixel be?

 

The reason there's no simple (at least, simpler than what's already been posted) equation is that the "equation per pixel" needs to, at a minimum, take into account a bunch of neighboring pixels as it needs to know not just the absolute depth but the depth relative to some localized area.

 

There's a perfectly good reason for this: it's called ambient occlusion precisely because you need to figure out how much light is prevented from reaching the target pixel (that is, how much is occluded); there's simply no way to know what light will be occluded unless you have some information about the neighboring geometry, as it's the neighboring geometry that's actually doing the occlusion.

 

Any additional complexity you perceive in the methods posted is probably a result of one or two things:

 

a) naively sampling all neighboring pixels at a wide enough radius is too slow for real-time performance, so the algorithms need some way to determine which pixels to sample to get a result that looks appealing. Usually this means picking some fairly arbitrary sample kernel and then changing it for each pixel so that any sampling error appears as high frequency noise.

 

b) to get something that even sort of looks like ambient occlusion, it's extremely valuable to think of it in terms of normals as well as just depth information. It takes a bit of additional calculation (derivatives) to reconstruct normals from just a depth map.

1

Share this post


Link to post
Share on other sites

Thanks! That made it a little more clear to me and the equation I am currently using does take into account the neighboring pixels of the depth map image. Do you know a way to do ambient occlusion with a normal buffer? Some more information from you would be nice.

0

Share this post


Link to post
Share on other sites

Thanks! That made it a little more clear to me and the equation I am currently using does take into account the neighboring pixels of the depth map image. Do you know a way to do ambient occlusion with a normal buffer? Some more information from you would be nice.

 

This is a pretty solid article, but I'm not sure how much overlap there is with the two articles already posted as I only skimmed them.

I've found that the most straightforward way to think about it is that each occluding pixel works roughly like a "negative" point light that removes lighting instead of adding it. The key point (and I'm quoting directly from the article I linked above) is then:

 

 


  • Distance “d” to the occludee.
  • Angle between the occludee´s normal “N” and the vector between occluder and occludee “V”.

With these two factors in mind, a simple formula to calculate occlusion is: Occlusion = max( 0.0, dot( N, V) ) * ( 1.0 / ( 1.0 + d ) )



The nice thing is that, if you also want to fake some indirect lighting in screen space, you can use a similar idea except treat the occluders as actual point lights, although this is most useful in a deferred rendering situation (intuitively it requires at minimum a color buffer in addition to normal and depth).

Edited by cowsarenotevil
0

Share this post


Link to post
Share on other sites

It's a bit hard to tell what I'm looking at; is that just the ambient occlusion multiplied with an unshaded white material? If so it looks like you're probably need to tweak some of the values you're using for attenuation, etc. so that it's a bit less extreme. When the contrast is that high it'll make sampling errors/noise more visible. You might also want to decrease the sampling radius a bit so that the sampling artifacts are less pronounced (I'm assuming you're already adjusting the sample radius with distance?).

 

Additionally, for the sake of physical plausibility, it should roughly be never the case that the total occlusion for a pixel should go to completely black; remember, the assumption is that light is coming from all directions, so the only way you'd really get solid black is if light were occluded from all directions, and the fact that this is happening in screen space basically prevents this from happening, as something blocked from all directions also wouldn't be visible to the camera. The only "exception" would be if the occluders were behind the camera, but then you wouldn't be taking them into account anyway.

 

In general, because SSAO makes so many assumptions (which are not usually true in practice), the less "obvious" the effect is, the better.

0

Share this post


Link to post
Share on other sites

Hmm, well now it seems like it goes to solid gray instead of solid black which I think is still wrong; it looks like you're possibly clamping the occlusion to solid black and then bringing it back up after the fact, after the data in the "too dark" regions is already gone. You should probably be decreasing the influence of each occluder before summing them together, both to avoid this and because you might want to play with the distance attenuation function, etc. for each occluder rather than just decreasing the influence by a constant factor; this will give you more control to tune it to look the way you want. Even with all that in mind, it still seems like progress, especially if you're not going to rely on SSAO as your only shading.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0