Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

ARFoundation + Post Processing Stack = Tracking Drift

Discussion in 'AR' started by trakloz, Dec 6, 2018.

  1. trakloz

    trakloz

    Joined:
    Jul 23, 2017
    Posts:
    14
    I have been trying to introduce Post Processing Stack effect depending on the user's actions. I import the Post Process package (2.12) via Package manager, add components to the AR Camera and when I build the tracking is not stable anymore. Please find screencapture with slight Chromatic Aberration.

    If I disable PP Layer and Volume components on the camera, tracking comes back to normal.
    I'm using Unity 2018.2.18f1 and ARFoundation preview 20.
    Has anyone encountered this issue? Thanks!
     
  2. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    605
    The video looks like you have quite a low framerate; that could impact tracking quality. Is that the case, or is it just how it was captured?
     
  3. shaun_fuzzy_unity

    shaun_fuzzy_unity

    Joined:
    Oct 11, 2018
    Posts:
    2
    Was this problem solved, as I have the same issue.
    I did manage to determine that this drift only occurs when the device is in Landscape with any form of post-processing enabled. This drift did not occur when any of the devices were in portrait with post-processing enabled.

    I have replicated this issue on Android and iOS using the following unity versions and mobile devices.
    Unity versions: 2018.2.13f1 and 2018.3.0f2
    Mobile devices: Samsung S7 edge, IPhone 8, IPhone X
    Plugin versions Unity 2018.2.13f1: Post-Processing v2.1.2, ARFoundation 1.0.0-preview.17, ARCore XR Plugin 1.0.0-preview.18, ARKit XR Plugin 1.0.0-preview.14
    Plugin versions Unity 2018.3.0f2: Post-Processing v2.1.2, ARFoundation 1.0.0-preview.20, ARCore XR Plugin 1.0.0-preview.23, ARKit XR Plugin 1.0.0-preview.17

    Also note that three builds were done for each Unity and mobile pairing:
    first with auto rotation enable, second with the build locked to landscape, and third with the build locked to Portrait.
     
    Last edited: Jan 16, 2019
  4. shaun_fuzzy_unity

    shaun_fuzzy_unity

    Joined:
    Oct 11, 2018
    Posts:
    2
    I manage to find the following temporary solution.
    Set AR camera to depth 0.
    Add a second camera any where to the AR scene.
    SceneLayout.png

    For the second camera set Clear Flags to Don't Clear, Culling Mask to Nothing, and set Depth to 1 assuming your AR camera's depth is set to 0. Finally add the Post process layer to the second camera and remove the Post process layer from the AR camera
    CameraSetup.png
     
    cLick1338 and trakloz like this.
  5. Florian-

    Florian-

    Joined:
    Aug 20, 2017
    Posts:
    5
    I hit the same problem and got a (dirty) fix.

    While Shaun workaround above kinda worked, I'm doing something a bit more exotic using an alpha mask to not affect the AR background with post process.

    Drift was very clear on this setup as i could see my post process effect float around my meshes and bleed on the real world pixels around.

    Drift looked very similar to transformation matrix issues I had in the past using multiple cameras in ARFoundation..
    Turns out the post process layer script reset the transformation matrix multiple times while executed.
    It seems to be related to some temporal anti aliasing stuff.
    I just commented out all calls that affect the transform matrix in the script and no more drift with post process on !
     
    JoeGrainger, trakloz and ROBYER1 like this.
  6. ROBYER1

    ROBYER1

    Joined:
    Oct 9, 2015
    Posts:
    1,444
    Was this also related at all to the device struggling with post processing? Thus far my experience with mobile devices and post processing is to keep it minimal or none at all(!)
     
  7. KarolisO

    KarolisO

    Joined:
    Feb 2, 2014
    Posts:
    29
    I recently ran into this problem. Has anyone found any other solutions because the ones posted above do not seem to work.
     
  8. dnnkeeper

    dnnkeeper

    Joined:
    Jul 7, 2013
    Posts:
    82
    I guess this problem might be related to missmatch between expected field of view of the render camera and the actual field of view of the device camera. I encountered this issue before in arcore and fixed it by assigning fov values instead of changing camera projection matrix. Try changing
    ARCameraBackground.cs line 331:
    Code (CSharp):
    1. //camera.projectionMatrix = eventArgs.projectionMatrix.Value;
    2. camera.fieldOfView = Mathf.Atan(1 / eventArgs.projectionMatrix.Value[5]) * 2f * Mathf.Rad2Deg;
     
    J_P_, kh-liu, Cery_ and 2 others like this.
  9. yester30

    yester30

    Joined:
    Mar 4, 2015
    Posts:
    4
    Thanks @shaun_fuzzy_unity, the additional camera trick helped a lot (ARF 3.0.0 preview, 2019.2.2f1).
     
  10. MustaphaRedouane

    MustaphaRedouane

    Joined:
    Dec 5, 2019
    Posts:
    3
    Well dnnkeeper's solution worked just fine for me. In my case I had a Camera displaying a UI over an AR Camera Render Target, which is also displaying some UI elements.I needed the post processing stack attached to the AR camera, thus the tracking drift occurred, plus, the UI canvas was scaled up like crazy, editing the ARCameraBackground.cs as dnnkeeper suggested fixed both the issues, Thank you.
     
    Last edited: Dec 5, 2019
    dnnkeeper and ninjanosui like this.
  11. ninjanosui

    ninjanosui

    Joined:
    Jul 12, 2013
    Posts:
    54
    What version are you using? Becuase I cant seem the find it in the ARCameraBackground.cs (in the package) but it sounds like i have the same issue with my worldspace UI.

    edit: I updated to 3 and tried that setting without any effect :(
     
    Last edited: Dec 5, 2019
  12. MustaphaRedouane

    MustaphaRedouane

    Joined:
    Dec 5, 2019
    Posts:
    3
    I'm using ARFoundation 2.0.2 and Unity 2019.2.11f1
    Actually the UI was scaled before I add the the postprocessing, as a workaround I was using Canvas Scaler! But when I edited the ARCameraBackground The AR UI scale was fixed!
     
  13. Srokaaa

    Srokaaa

    Joined:
    Sep 18, 2018
    Posts:
    169
    Did anyone manage to disable PPv3 on URP for background texture only? The solution @shaun_fuzzy_unity provided no longer works
     
    unity_QUGTGnZdXtU2Gw likes this.
  14. Andrew_Zim

    Andrew_Zim

    Joined:
    Aug 30, 2017
    Posts:
    20
    Thanks, @dnnkeeper, the solution still works. (Unity 2019.3.12f). But sometimes
    ARCameraBackground script is reverting back to his base look. And the line in code, which we changed, goes back as it was: camera.projectionMatrix = eventArgs.projectionMatrix.Value;
    Can I somehow cancel this reverting?
     
    Last edited: Jul 10, 2020
  15. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,070
    All assets inside Packages folder are reverted to original values every Unity launch and every update of Package Manager. I ended up automatically applying needed changes from script.
     
    Andrew_Zim likes this.
  16. Andrew_Zim

    Andrew_Zim

    Joined:
    Aug 30, 2017
    Posts:
    20
    Thanks! Can you provide some example, please?
     
  17. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,070
    @Andrew_Zim I don't have a code for your case, but you can get the general idea from this script and modify it for your needs.
     

    Attached Files:

    Andrew_Zim likes this.
  18. Andrew_Zim

    Andrew_Zim

    Joined:
    Aug 30, 2017
    Posts:
    20
    Thank you!
     
  19. sbethge

    sbethge

    Joined:
    Mar 20, 2019
    Posts:
    16
    @tdmowrer Any chance this gets fixed properly in ARFoundation?
     
    Numa likes this.
  20. FelixLightshape

    FelixLightshape

    Joined:
    Nov 25, 2019
    Posts:
    9
    Still seems like this is an issue 2 years later. Would be nice to see this addressed.
     
  21. Numa

    Numa

    Joined:
    Oct 7, 2014
    Posts:
    100
    Yes please :)
     
  22. Anastasia-Devana

    Anastasia-Devana

    Joined:
    Aug 18, 2013
    Posts:
    20
    Ran across this recently as well, but also seems like more people should be having this issue.
    @sbethge / @FelixLightshape / @Numa did you by chance change the default FOV on the AR camera?
     
  23. Numa

    Numa

    Joined:
    Oct 7, 2014
    Posts:
    100
    I'm not doing anything special besides using the post processing stack. My current workaround was to copy paste the ARCameraBackground into a new script and use that instead of the one they provide. Hopefully it gets fixed in an update some day.
     
    Anastasia-Devana likes this.
  24. FelixLightshape

    FelixLightshape

    Joined:
    Nov 25, 2019
    Posts:
    9
    No, I did not. Worked around the issue by basically putting an orb around the camera that has a shader which does the post-processing effects I want. Quite a cumbersome way to solve the issue though.
     
    Anastasia-Devana likes this.
  25. GameArt

    GameArt

    Joined:
    Feb 24, 2013
    Posts:
    86
    Bump.
    Current post effect stack is incompatible with AR because of the field of view mismatch. Tracking drift happens with no custom code as long as you have a v2 stack enabled with one effect.
    Beyond the hacks suggested dose anyone have a workaround to feed the correct FOV to the stack?
    These hacks seem to suggest the FoV we are using it not the correct one for rendering, but consistent with the bad pp v2 stack FoV.
     
    Last edited: Oct 28, 2020
  26. cineconcerts

    cineconcerts

    Joined:
    Dec 18, 2019
    Posts:
    10
    I'm not a coder so I don't know how to adapt this to the Post Process Layer script. Is there any way you could spell out exactly what I need to do? When I tried duplicating the current script so that it would remain fixed even after re-opening Unity, it gave me public/private errors that I don't know how to fix. Thanks so much.
     
  27. Andrew_Zim

    Andrew_Zim

    Joined:
    Aug 30, 2017
    Posts:
    20
    for now, I just changing this script every time building the project
     
  28. FrankvHoof

    FrankvHoof

    Joined:
    Nov 3, 2014
    Posts:
    258
    @cineconcerts @Andrew_Zim If you add ARFoundation as a 'local package', it will not get overwritten by Unity. The automated overwrite is a 'feature' to ensure that your package is not corrupted. It works by checking the contents of your local copy against the repository for the package.

    Locate ARFoundation (in the package-cache), copy it to a separate folder (outside of assets), and add it using 'add from disk'. There is no need to 'delete' ARFoundation from the Package Manager before adding from disk, as it will simply override the reference when adding.
    If the package is 'on disk', it is not checked against its online counterpart, and will thus not be overwritten.
     
    KyryloKuzyk likes this.
  29. Srokaaa

    Srokaaa

    Joined:
    Sep 18, 2018
    Posts:
    169
    Isn't this fixed in last ArFoundation 4.1.3 release? In the changelog there is an entry saying that it was fixed:

    Code (CSharp):
    1. 4.1.3] - 2021-01-05
    2. Changes
    3.  
    4.     The ARCameraBackground component now sets the camera's field of view. Because the ARCameraBackground already overrides the camera's projection matrix, this has no effect on ARFoundation. However, any code that reads the camera's fieldOfView property will now read the correct value.
    https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@4.1/changelog/CHANGELOG.html