Search Unity

Question Camera.targetTexture lags behind main camera?

Discussion in 'General Graphics' started by JustinAHS, Feb 19, 2022.

  1. JustinAHS

    JustinAHS

    Joined:
    Feb 18, 2013
    Posts:
    33
    I have a main camera controlled by a TrackedPoseDriver. And a secondary camera that follows the position and rotation of the main camera, but with an offset in position.

    The secondary camera has a targetTexture, and I render the targetTexture on a Quad.
    For some reason, the targetTexture makes it look like the secondary camera is always "lagging behind" the main camera.

    When I don't move the main camera, the image is exactly what I expect to see.
    When I do move the main camera, the image is updated a few frames behind, effectively lagging or having a delayed response.

    I've hacked the TrackedPoseDriver script to make it so it updates the transforms of BOTH the main camera and secondary camera AT THE SAME TIME. But this does not seem to help at all.

    I thought that the problem might then be that maybe the secondary camera does not render as often as the main camera. So, I did Debug.Log() every time the main and secondary camera rendered (OnPostRender). They had roughly the same counts. The secondary camera actually had OnPostRender called more often by a bit but it also seems to render when the game is paused with the editor.

    So, I'm left thinking that it's possible the secondary camera's OnPostRender is called but the targetTexture isn't actually being drawn to every time OnPostRender is called.

    I tried making the main camera render both before and after the secondary camera by modifying the depth but neither helped at all.

    I'm running out of ideas here. Can someone please explain what is going on?

    -----

    [EDIT]

    Oh, S***. I only just realized this is happening with the Quest 2.
    So, I looked at both the Quest 2 screen and the editor's Game screen.
    The Game screen rendered properly. The Quest 2 made the renderTexture lag behind.

    I built an apk file and ran it on the Quest 2 and the flickering happens there, too.

    Now I'm confused why the Quest 2 has problems with Camera.targetTexture.
    The main camera responds just fine to the head movement and renders fine. So, it's not like the game itself is lagging. It's just the secondary camera having issues with Camera.targetTexture.
     
    Last edited: Feb 19, 2022