Orthographic Top Down Ambient Occlusion Problem

Hey guys, I am working on a top down project with an orthgraphic camera. It has some 3D and some Paper2D stuff in it.

The problem is, that none of the built in AO-techniques work and without AO the scene just does not look good. It is clear why SSAO won’t work but I thought that at least the light maps would bring some results. DFAO does not work either.

I made a little image to visualize what I actually want to achieve:

As you see in the picture, walls and most of the larger objects darken the area around them a little bit, simulating ambient occlusion in those 2D games.

Possible solutions I am not really happy with

Custom Depth Post Process

A really well working solution is to just render large objects to custom depth and blur the CustomDepth mask before applying it again as post process.
The reason I don’t like it, is because I would need to do that every frame and I would lose the powerful option to use Custom Depth for anything else.

Is there a way to have more than one CustomDepth channel?

Make it tile based

It is easy to find the edges for tile based games like described here:
http://codebin.co.uk/blog/fake-ambient-occlusion-part1/

But for the record, I really like to avoid the tile thing because that would limit the level editing a lot.

Any ideas from you guys?

Hi Denny,

Many depth based functions do not work in orthographic mode.

Can you try instead using a narrow FOV camera that is very far away? Normally this will cause bad z-precision errors but you should be able to increase the “Near Clipping Plane” under preferences in order to bring the precision back.

If you want to convert between a perspective and ortho camera, you can get the view area to match exactly using this formula:

Ortho_FOV_Convert.JPG

“sheet size” is your total ortho width, and the value you put into TANd should be 1/2 the FOV that you render (aka cone angle).

The return value is how far away the camera needs to be from the ground plane to see a view as large as “sheet size”.

The idea here would be to try the largest FOV that you can where the perspective is barely noticeable. Then tweak clipping plane after that.

Hey Ryan, thanks for your help.

I tried your approach, but unfortunately I don’t get a really good result. I actually can’t tell if there is any AO at all. I suspect it has some depth fade and since the camera is so far away, nothing appears on the screen.

In the meantime I threw together a quick CustomDepth solution. Here is what that looks like so far.

1786e5491e55facc566f1c71c5cdcb0f5c91d25f.jpeg

I used the Custom Material Expression to write a simple Box Blur with only 1 iteration. But it already brings a somewhat decent result. So I guess with a better blur applied, this solution could bring the desired result.

Only downside is that I really like to use CustomDepth for gameplay stuff, since it is a really powerful feature.

This need a 2D light shaders, and is there where the 2D light is needed, time ago i tried to make something similar but no way at the moment in the UE4 to archive that.
If you are using 3D & 2D no idea but you cant turn off the global light or change the brightness.

http://www.redblobgames.com/articles/visibility/https://youtube.com/watch?v=fsbECSpwtighttps://www.youtube.com/watch?v=AR5NhWqoVvo

Sorry me bad, you need only about the AO, you can try to change the global light to some dark ? and then place normal light over the map to give that effect ?
Or use a secondary texture for the walls and place in the bottom
Or make the top walls unlit with the final colors, then use a dark light for all scene and place point light where you need light and probably you got something good.

Thanks Hevedy, I have already tried the lighting approach, but I just can’t get it right this way. In addition to that I actually want an automated solution for productivity reasons.

Anyway, I think I settled with the CustomDepth approach for now. I still have a problem though. I want to give it a second blur pass, but I struggle with the Material Editor.

I achieved the first pass using the Material Editors Custom Expression which has access to CustomDepthTexture and CustomDepthTextureSampler. But I don’t really know how to access the output of the first pass to blur it again. I guess I have to render it to a texture to sample it again. Any ideas on that topic?