Search Unity

Bug URP unexpected camera behavior with AR Camera Background

Discussion in 'AR' started by justindpnt, Sep 5, 2022.

  1. justindpnt

    justindpnt

    Joined:
    Feb 21, 2019
    Posts:
    18
    Hello! I am posting here because I think this might be a problem related to an AR script, and not with URP.

    So I am trying to layer cameras with URP, but world text appears in different locations on the cameras I am trying to stack (I am trying to make a UI camera to render on top of special effects).

    Result attached.

    The result is when both cameras are on, you can see the difference between the two layers, which as you can imagine makes layering any cameras with any degree of accuracy near impossible because they don't line up with each other.

    I set up the UI camera as a child to the main camera, set it to overlay, added it to the main camera stack, the FoV is the same (by script), so I'm stuck on what could be making it different.

    I tried going through and toggling every bool/setting, and I think I narrowed it down to AR Camera Background Script. When not enabled, the text lines up in play mode, but when enabled, the text renders in two different locations.

    Any help or insight would be greatly appreciated! Thanks!
     

    Attached Files:

  2. Stents

    Stents

    Joined:
    Jan 23, 2014
    Posts:
    18
    I would recommend overriding the sub camera's projectionMatrix, rather than fov in order to ensure the cameras match. Or you could also use Camera.CopyFrom, and then set the layers etc that you want to be different after the settings have been copied.
    Also, how are you ensuring the FoV is the same on both Cameras? In most cases it is updated after Start / Awake, so you may want to put your code in LateUpdate if you are not doing it there already.
     
  3. justindpnt

    justindpnt

    Joined:
    Feb 21, 2019
    Posts:
    18
    I tried setting the sub camera's projectionMatrix, and got the same displacement result.

    Code (CSharp):
    1. selfCam.projectionMatrix = mainCam.previousViewProjectionMatrix
    I also tried using copyFrom, which ended up with the same result.

    To update Fov, I just have a simple script that is basically:

    Code (CSharp):
    1. Update(){
    2.    selfCam.fieldOfView = mainCam.fieldOfView;
    3. }
    And I tried both update and lateupdate for this, with the same result.

    One thing I noticed is the frame of the camera is slightly different in the editor (picture attached). I'm not sure how this is possible when I am constantly setting the FoV to be the same.
     

    Attached Files:

  4. justindpnt

    justindpnt

    Joined:
    Feb 21, 2019
    Posts:
    18
    Oh, instead I used

    Code (CSharp):
    1. selfCam.projectionMatrix = mainCam.projectionMatrix;
    To set the projection matrix, and that seems to have fixed the problem. Thank you for the help!
     
    agpatel0007 and andyb-unity like this.