Occlusion Culling problem with Third Person Camera + Workaround

I’m sharing a solution to a problem that I had with occlusion culling for 3rd person games.

I have a room that is essentially a cube with the normal facing inside. The cube is an occluder. I also have a third person camera that is looking at a character in the room. Sometimes the camera gets very close to the wall or even goes through, just a little bit. Even with backface testing set up, the character still disappears sometimes. I haven’t put props inside the room yet, but I’m sure they’d probably disappear too.

Now, I found a solution that works for me (but I don’t know the performance costs of it).

I put the character into a layer named “Ignore OC.” Now, I have two cameras in the exact same position, with the same FOVs, clipping planes, etc. Camera 1 will have OC enabled and will render all visible layers except for the “Ignore OC” layer.
Camera 2 will not use OC and will render only the “Ignore OC” layer. In addition, the clear flags for Camera 2 will be set to “Don’t Clear.” To ensure that the character is displayed on the screen, Camera 2 has a depth greater than that of Camera 1.

Notes: I do not have Camera 2 clear by depth because that would overlay the character over everything else, which is not what I want. What I want is for certain objects to ignore OC, especially important objects.

I can see some downsides to this solution. First, having more active cameras will probably increase draw calls, but I don’t know how severe it is. Next, the “Ignore OC” layer can only be used for objects that have high render priority, such as a character. Putting too many objects into the layer will defeat the purpose of OC.

This solution works for now, but I am going to try to get more experience with OC so that I don’t get these problems in the future.

1 Like

To be fair, providing you don’t get any depth clearing issues, this is a good solution, and you shouldn’t actually see any additional draw calls because of it. Generally you’d never want to OC the character anyway, so it shouldn’t matter in that regard.
We’ve used something similar in the past, though for rendering issues rather than OC. Multiple cameras for different layers is a really nice setup that I’ve been meaning to play around with more, I’m sure there are lots of other uses for it.