Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Shadows with custom projection matrix still broken in 5.4.0b1

Discussion in 'General Graphics' started by matpow2, Dec 8, 2015.

  1. matpow2

    matpow2

    Joined:
    Aug 12, 2013
    Posts:
    7
    (originally: Shadows with custom projection matrix still broken in 5.3.0f4)

    Hi everyone.

    Even though this issue was marked as fixed on the issue tracker, this issue still seems to be in 5.4.0b1:
    http://issuetracker.unity3d.com/iss...asts-it-when-using-a-custom-projection-matrix

    I've attached a demonstration of the issue. 2 seconds after you play the scene, CameraScript will do the following:

    Code (CSharp):
    1.         Matrix4x4 mat = GetComponent<Camera>().projectionMatrix;
    2.         mat.m31 = 0.0002f;
    3.         GetComponent<Camera>().projectionMatrix = mat;
    After this happens, the shadow for the cube object will get offset in some weird manner. Here's a GIF:



    This worked fine in Unity 4.6. Any ideas on how to fix this? Thanks!
     

    Attached Files:

    Last edited: Jan 15, 2016
    Zuntatos likes this.
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,482
    Hey.
    The milestone on the issue tracker is wrong.
    The fix is not in 5.3, it went into 5.4. I will speak to the dev and see if its ok to backport to a 5.3 patch release.

    Edit: Good news backport should be fine. Ill do it now :)
     
    Last edited: Dec 9, 2015
    theANMATOR2b likes this.
  3. matpow2

    matpow2

    Joined:
    Aug 12, 2013
    Posts:
    7
    Amazing! Thanks a lot for the quick help. Looking forward to the next patch.
     
    karl_jones likes this.
  4. matpow2

    matpow2

    Joined:
    Aug 12, 2013
    Posts:
    7
    Just a FYI, the fix is not present in 5.3.1p. Hopefully, it will be present in the next?
     
  5. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,482
    The fix went into 5.3.1, last weeks release. If it is still not working then there is something wrong with the fix. Its possible that there is some element of 5.4 that is needed along with the fix or the fix is missing something. I'll have to investigate next week.
     
    ksam2 likes this.
  6. matpow2

    matpow2

    Joined:
    Aug 12, 2013
    Posts:
    7
    Just a friendly reminder: this was not fixed in 5.3.1p2 either.
     
  7. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,482
    Yeah I am aware it still has issues. Its possible a part of the fix from 5.4 was not backported. I need to look into it.
     
  8. matpow2

    matpow2

    Joined:
    Aug 12, 2013
    Posts:
    7
    This issue is still present in 5.4.0b1. I guess the issue wasn't fixed after all?
    You should definitely consider reopening the issue on the issue tracker.
     
  9. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,482
  10. jpfranssen

    jpfranssen

    Joined:
    Apr 7, 2014
    Posts:
    12
    I'm experiencing a similar issue when setting a custom projection matrix. I was wondering if there is any news on this issue.

    I noticed that, at least in my case, the shadows break (completely, so no shadows whatsoever) when applying a keystone effect to the projectionmatrix.

    After digging and debugging around in the built-in shaders and mainly in the Internal-PrePassCollectShadows.shader (around line 355 / frag_hard) I found that there is no or wrong depth depth info.

    Code (csharp):
    1. float zdepth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, i.uv);
    2. fixed4 res = Linear01Depth(zdepth);
    Also, and maybe related, I found that when doing this keystone effect camera.actualRenderingPath changes mode from Deferred to Forward? While the camera component in the editor still shows Deferred.

    (Using Unity 5.3.1f1, but also briefly tested 5.4.0b3)
     
  11. jpfranssen

    jpfranssen

    Joined:
    Apr 7, 2014
    Posts:
    12
    Here's another test project which reproduces this issue. Just change the keystone settings on the script attached to MainCamera. You will see 1. the shadow is gone and 2. the RenderingPath of the camera switches to forward mode.
     

    Attached Files:

    deram_scholzara likes this.
  12. matpow2

    matpow2

    Joined:
    Aug 12, 2013
    Posts:
    7
    Any news on this? Is there a fix on the roadmap?
    Also, good to see I'm not alone with this bug :)
     
    deram_scholzara and jpfranssen like this.
  13. deram_scholzara

    deram_scholzara

    Joined:
    Aug 26, 2005
    Posts:
    1,043
    Seems like what's happening is that Unity is only fixing the issue for cases which modify specific projection matrix values, rather than fixing the issue for any modification of the projection matrix as a whole. This issue has been around, and complained about, since unity 4.6 (at best) - it's kind of disappointing, but I'm glad that now it seems to be getting significant attention. I REALLY hope that this gets fixed before 5.4.0f launch.
     
  14. jpfranssen

    jpfranssen

    Joined:
    Apr 7, 2014
    Posts:
    12
  15. matpow2

    matpow2

    Joined:
    Aug 12, 2013
    Posts:
    7
    I can confirm this is fixed finally!
    Thank you Karl and everyone else from the Unity team for working on this issue.
     
    jpfranssen likes this.
  16. deram_scholzara

    deram_scholzara

    Joined:
    Aug 26, 2005
    Posts:
    1,043
    I've tested this fix with Camera Perspective Editor in Unity 5.4.0b8, and it resolves the issue for all of my test cases. There seems to be some sort of issue that pops up causing CPE to occasionally stop working altogether while the fix script is being used, but I'm planning to integrate the patch directly into CPE, and hopefully resolve that issue as part of it.

    Thank you Unity!
     
    karl_jones likes this.
  17. sbsmith

    sbsmith

    Joined:
    Feb 7, 2013
    Posts:
    127
    I'm using 5.4.0b9 and the replacement shadow script from the issue tracker thread. It solved my problem where shadows were disappearing as soon as my projection matrix became oblique.

    I noticed some clipping issues

    shadow_map_problem.png

    so I cranked up the shadow distance in the Quality settings. But I still notice quite a bit of popping.

    shadow_map_problem_2.png

    Any suggestions on how to solve this problem would be appreciated. I'm still a bit of a Unity newbie.

    Also, I noticed that screen effects like DoF do not work with oblique matrices (even the new DoF from 5.4).

    Thanks for the help.
     
  18. deram_scholzara

    deram_scholzara

    Joined:
    Aug 26, 2005
    Posts:
    1,043
    Try adjusting your camera's clip planes.
     
  19. sbsmith

    sbsmith

    Joined:
    Feb 7, 2013
    Posts:
    127
    Will do. It may be a while before I get a chance to tackle this. I'll report back when I do.
     
    deram_scholzara likes this.