Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

ScreenSpaceReflection and Panning issue

Discussion in 'Image Effects' started by Diomede, May 23, 2017.

  1. Diomede

    Diomede

    Joined:
    Mar 10, 2015
    Posts:
    31
    Hi all ,

    I' m trying to use ScreecSpaceReflection with camera pan, but seems that panning doesn't affect SpaceScreenReflection

    This is my panning Script that change current camera projection matrix.

    Code (CSharp):
    1.  
    2.     public static Matrix4x4 CalcDefautPanMatrix(Camera cam, Vector2 offset, float horizontal, float vertical)
    3.     {
    4.         float left = (offset.x - horizontal) * cam.nearClipPlane;
    5.         float right = (offset.x + horizontal) * cam.nearClipPlane;
    6.         float top = (offset.y + vertical) * cam.nearClipPlane;
    7.         float bottom = (offset.y - vertical) * cam.nearClipPlane;
    8.         return PerspectiveOffCenter(left, right, bottom, top, cam.nearClipPlane, cam.farClipPlane);  
    9.     }
    10.     static Matrix4x4 PerspectiveOffCenter(float left, float right, float bottom, float top, float near, float far)
    11.     {
    12.         var x = (2.0f * near) / (right - left);
    13.         var y = (2.0f * near) / (top - bottom);
    14.         var a = (right + left) / (right - left);
    15.         var b = (top + bottom) / (top - bottom);
    16.         var c = -(far + near) / (far - near);
    17.         var d = -(2.0f * far * near) / (far - near);
    18.         var e = -1.0f;
    19.  
    20.         Matrix4x4 m = Matrix4x4.identity;
    21.         m[0, 0] = x;
    22.         m[0, 1] = 0.0f;
    23.         m[0, 2] = a;
    24.         m[0, 3] = 0.0f;
    25.         m[1, 0] = 0.0f;
    26.         m[1, 1] = y;
    27.         m[1, 2] = b;
    28.         m[1, 3] = 0.0f;
    29.         m[2, 0] = 0.0f;
    30.         m[2, 1] = 0.0f;
    31.         m[2, 2] = c;
    32.         m[2, 3] = d;
    33.         m[3, 0] = 0.0f;
    34.         m[3, 1] = 0.0f;
    35.         m[3, 2] = e;
    36.         m[3, 3] = 0.0f;
    37.         return m;
    38.     }
    39.  
    When pan is zero the Reflection is correctly applied

    noPanning.png

    otherwise Reflection are wrong
    panning.png


    Any Ideas?
    Thanks
     
    kenshin likes this.
  2. kenshin

    kenshin

    Joined:
    Apr 21, 2010
    Posts:
    923
    @Chman, @Tim-C this is a big issue for us and I am wondering if nobody has the same problem?

    Nobody do a camera panningh with cinematic effects?

    Any feedback is very appreciated! :)
     
    Diomede likes this.
unityunity