Camera frustum culling with custom projection matrix

Hi everyone,

For some reasons, we had to implement our own shadow mapping and could not use the build in shadows. Since we are sometimes rendering the shadows from gracing angles, we though our selves clever and decided to use an oblique projection matrix (only the sun casts shadows, thus an orthographic projection).

This was done, in order to make better use of the shadow map’s precision. Here’s some pictures:

This all works fine, and renders correctly, BUT, it seams that unity gets slightly confused by us doing non standard things.

1.) The camera frustum is display incorrectly in the editor. It still looks as if we had a standard projection
2.) Frustum culling is broken, with objects popping in/out when crossing the original frustum planes. How to fix it?

@ is this a bug or somehow intended behaviour? The docs mention that oblique matrices are used in water rendering, so someone internally must have solved that problem already…

Here’s a gif of the popping effect. The shpere clipps correctly at the top (in thus case the slanted near plane) but pops when crossing the old near plane.
2895753--213007--Eiel4TFFoT.gif (new frustum in red)

Since I wrote this post on the day before Christmas, I allow myself to push it over into the new year :smile:

I did not come across this issue when using adjusted perspective projection. (Shifted up or down, so also oblique in a way.) The frustum culling does seem to handle that case correctly.

When it comes to precision and sun shadows, I’ve done a similar approach before. I still used the standard projection, but I stored the height of the model instead of the depth. This has the same advantage of better precision on flat surfaces, but it’s slower because it can’t use hardware depth rendering.

Did you ever find out a fix for this? I’m having the same problem with custom matrices completely destroying Unity’s ability to apply occlusion culling.

not yet unfortunately. Smells a bit like a bug so it’s probably best to file a bug report. I haven’t had the time to create the reduced bug/test case project though

Just filed a bug report (case 872399), and here is the repro for everyone as a reference.

2928255–216470–FrustumCullingTest.zip (3.54 MB)

1 Like

Hitting the same wall when setting an oblique culling matrix. Unity added the tag “Wont Fix” in your post from 2017 :slight_smile: 5 years later there’s not really a workaround i can think of.