Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Flipping camera horizontally whilst using temporal anti-aliasing breaks stuff

Discussion in 'Image Effects' started by Wriggler, Mar 16, 2018.

  1. Wriggler

    Wriggler

    Joined:
    Jun 7, 2013
    Posts:
    83
    Hi all,

    I'm using some code that looks like this to flip the camera horizontally.

    Code (CSharp):
    1.  
    2. void OnPreCull()
    3.     {
    4.         cameraRef.ResetWorldToCameraMatrix();
    5.         cameraRef.ResetProjectionMatrix();
    6.  
    7.         //Handle image flipping
    8.         if (mirrorModeEnabled)
    9.         {
    10.             Matrix4x4 mat = cameraRef.projectionMatrix;
    11.             mat *= Matrix4x4.Scale(new Vector3(-1, 1, 1));
    12.             cameraRef.projectionMatrix = mat;
    13.         }
    14.     }
    15.  
    16.     void OnPreRender()
    17.     {
    18.         GL.invertCulling = isMirrorModeEnabled;
    19.     }
    20.  
    21.     void OnPostRender()
    22.     {
    23.         GL.invertCulling = false;
    24.     }
    ...but unfortunately when Temporal anti-aliasing is enabled everything gets broken (all the world's polys are inside out and everything is very blurry). It all works fine when temporal AA is disabled, or mirror mode is disabled. I can have either TAA or mirror mode, but not both.

    I presume I also need to flip some other stuff, like the motion vectors? Anybody have any ideas how I might accomplish a camera flip with TAA enabled? Are any Unity graphics folks able to chime in here please?

    Thank you!

    Ben
     
  2. Wriggler

    Wriggler

    Joined:
    Jun 7, 2013
    Posts:
    83
    Bumping this one. Does anybody have any advice on how to get TAA working with a mirrored screen? Or perhaps another method of mirroring which might not break TAA?

    Thanks!

    Ben
     
  3. Kumo-Kairo

    Kumo-Kairo

    Joined:
    Sep 2, 2013
    Posts:
    333
    How about mirroring it after everything is done? PP Stack is opensource, just flip the x UV coordinates of the screenspace quad in the final pass.
     
    Wriggler likes this.
  4. Wriggler

    Wriggler

    Joined:
    Jun 7, 2013
    Posts:
    83
    Great suggestion, this worked great. Thank you very much for the good idea!

    Ben
     
    Kumo-Kairo likes this.