- Home /
Camera custom matrix, shadows not working anymore - Unity5
Hello, First time I have to ask people to help me with a problem, I usually try to find by myself but here I think it could take a lot of time.
Some months ago I made a custom matrix projection for my camera (Camera.projectionMatrix) and it always worked perfectly, no shadows filckering, no objects disappearing so near and far clip planes work finely. I just had to increase the values for the far plane and in Quality settings increase the value for max distance shadow to avoid having them flickering. I can't avoid to use my custom camera it's the "key" to play my game, the matrix is ajusted to give a specific view of the scene according to the position and orientation between the mobile screen and the user face.
The problem appeared with Unity 5, now I don't have shadows anymore whatever the values applied to far plane and max distance for shadows, when I switch back to the normal mode by deactivating my matrix modification in real time I can see the shadows but with my custom matrix I have no shadows. My objects are ~100 unity far from my camera, my near plan is 0.3 and far plane 1500 I found my shadows reappear when increasing the NEAR plane to ~20 but their behaviour is really strange, they rotate according to the camera orientation.
Do you know if there have been changes with the way shadows are computed between Unity 4 and 5? If so what had been changed or is there a way to go back to the way they acted in Unity4. If I find nothing I will have to go back to Unity 4 but Unity5 seems more interesting and next updates won't happen on 4 so it would really be better to find a way to make it work with u5.
I don't think it would be useful to let my code on this work with matrix projection since it's not simple at all to understand why I put this or that value here or there but I can at least give for an example my custom matrix and the original one but I don't think it will help.
29 fov, 27 near, 1500 far.
Here is my matrix with a normal behaviour :
2.17622 0.00000 0.00000 0.00000
0.00000 3.86671 0.00000 0.00000
0.00000 0.00000 -1.03666 -54.98982
0.00000 0.00000 -1.00000 0.00000
and here is the custom one with the same situation :
2.13346 0.00000 0.00000 0.00000
0.00000 3.79075 -0.00144 0.00000
0.00000 0.00000 -0.51833 -27.49491
0.00000 -0.00038 -1.00000 0.00000
As you can see no big differences but it seems like the way shadows are computed with the matrix projection changed between Unity 4 and 5.
I have the exact same issue and have not found a solution as of yet. I've posted in the forums here: http://forum.unity3d.com/threads/unity-5-shadows-do-not-render-in-game-view-with-custom-projection-matrix.307143/#post-2011336
As far as I know and read, there were indeed changes to the shaders and techniques used to render shadows in Unity 5, though there is not an exact reference on what or how to access them. Hopefully someone will figure out how to solve the issue. We could also send this to issue/bug tracker to Unity.
A year later and I am in the same boat. I have tried this on 5.3.2 and 5.4.0b9 and my shadows disappear as soon as my matrix becomes oblique. So, the custom calculated matrix works fine while the frustum is symmetrical, but once the camera shifts and forces it to become oblique, the shadows disappear.
Answer by monark · Nov 10, 2016 at 01:48 PM
See the fix here: https://issuetracker.unity3d.com/issues/shadow-moves-in-relation-to-the-object-that-casts-it-when-using-a-custom-projection-matrix
Only good though if you are on 5.4 or higher
Thanks for the update. Such answers are always welcome ^^.
Since the OP wasn't online since dec 2015 I'll accept this answer.
Another case closed :)
Your answer
Follow this Question
Related Questions
How to set the position of objects on the left and right of the screen 0 Answers
How do I render a scene's depth buffer when I have custom vertex shaders? 0 Answers
Shadows from culled objects 0 Answers
Need help for player rotation and camera rotation 0 Answers
What's going on with rendering? 1 Answer