- Home /
Ambient occlusion stops at certain camera angles/positions
I'm running Unity 2020.1.15f1, using the built-in renderer and the Post-Processing package. When I run the game, both in Play mode and when I build it, the ambient occlusion sometimes stops when I face certain directions/move to certain positions. I noticed that if I add a directional light to the scene, the problem goes away, but since the game takes place underground, I don't want directional lights. As a workaround, right now I have a directional light with an intensity set to 0.001, but I don't understand why the light is needed anyway. Is there something about how the ambient occlusion works that I'm missing?
Here's a video of what I'm talking about. I turned the intensity up to the extreme to make it easier to see. There's also a problem with the actual edges not being darkened, so if you happen to have a solution to that, that would also be great!)
Answer by Namey5 · Dec 08, 2020 at 11:16 AM
My guess is that the depth texture isn't being generated properly (even though it really should be created automatically by the post-process renderer if using effects that rely on it, so maybe you have a script somewhere that is overriding it?). I would try adding a script to your camera, something along the lines of the following;
private Camera m_Camera;
private void OnPreCull ()
{
if (m_Camera == null)
m_Camera = GetComponent<Camera>();
m_Camera.depthTextureMode |= DepthTextureMode.Depth;
}
Thanks for the answer. I tried this out and got no change. I forgot to mention that I do have Next-Gen Soft Shadows installed. That's the only thing I can think of that might be overriding any camera settings, because none of my scripts are. Do you think NGSS could be the culprit? If so, I'll go digging into it when I have more time to see if it is messing with the depth texture mode.
It's possible, but I wouldn't think so (I've only used NGSS 1 but it never caused any issues). The only way to check what's going on is to use the frame debugger and take a look at what is and isn't being drawn when that happens (pay attention to shadows and the depth buffer, also check that the effect is being drawn at all or just skipped entirely).