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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question FPS Drop with second camera rendering on Render Texture

Discussion in 'Universal Render Pipeline' started by AjejeBrazorfUnity, Feb 27, 2023.

  1. AjejeBrazorfUnity

    AjejeBrazorfUnity

    Joined:
    Aug 23, 2022
    Posts:
    4
    Hi everyone,
    I'm currently facing an odd issue with my game, I can't seem to figure out what's going on.
    I set up the following cameras on my scene: first one is the main camera, the second one is used to display a minimap with output on a texture renderer. I disabled basically every effect on minimap camera to keep it at bare minimum. Main camera works in Perspective mode, Minimap in Ortographic mode.

    If I play the game at 1080p everything works fine, game runs above 100fps.

    upload_2023-2-27_17-10-36.png

    As soon as I get to a slightly higer resolution, the game crawls to an alt (less than 20fps).

    upload_2023-2-27_17-32-34.png

    When I try to debug the issue with profile, I can see huge spikes on CPU on resolutions higher than 1080p.

    upload_2023-2-27_17-24-52.png

    upload_2023-2-27_17-27-32.png

    Even weirder, if I enable GPU profiling, frame rate jumps up to 60fps so it doesn't give me any more insights on why CPU sits idle waiting for a signal to come.

    I tried tweaking texture render texture and camera settings without any luck. Even disabling the UI game object that shows the raw texture image for the minimap does not affect performance at all: the only thing that works is disabling the minimap camera game object, which boost the resolution again over 100fps.

    I checked resource consumpion from explorer task manager to see what the game consumes outside editor (I ran a game build): on 1080p memory allocation is around 700mb, on 4k jumps up to 4GB. If I disable the secondary camera, memory usage stays within 700mb in 4k as showed below.

    stats.png


    Does anyone know what could cause this issue or suggest any further steps for the investigation? It's driving me insane...
     
    Last edited: Feb 27, 2023
  2. IIporpammep

    IIporpammep

    Joined:
    Aug 16, 2015
    Posts:
    38
    I've encountered the same problem and the only solution that worked for me is using the same UniversalRendererData for both the main and the minimap camera.

    To prevent unneeded features from injecting into the minimap rendering, I’m checking if rendering camera has post processing enabled before adding render pass.
     
  3. AjejeBrazorfUnity

    AjejeBrazorfUnity

    Joined:
    Aug 23, 2022
    Posts:
    4
    Thanks for your suggestion IIporpammep. I tried to look at Camera component but I could not find a method to set objects of type UniversalRendererData nor and exposed property. Can you point me to any documentation or explain how could I set UniversalRenderData?

    I opened a bug as well but it seems like they are not going to fix it, event though was recognized as a bug.
    https://issuetracker.unity3d.com/is...mera-is-enabled-with-output-texture-rendering
     
    dencesar37 likes this.
  4. Gisle

    Gisle

    Joined:
    Mar 25, 2014
    Posts:
    26
    I have a very similar problem, but I have not been able to confirm it has anything to do with second cameras. I'll look into it tomorrow.

    My project worked great in 4k (editor) until about 4 weeks ago when I upgraded from 2022.1.24 to 2022.2.8. After that I have been unable to play the game in editor in _any_ resolution above 1080p. The memory consumption jumps to 99% immediately. Closing the scene view seems to help alot, but it's still pretty bad. Builds seems to run the same, although I have not looked at any difference in memory impact.

    I have a main camera stack with 4 different renderers, and a different renderer for scene view. Additionally I have a different camera + renderer that renders to a RenderTexture at some points.

    This issue also happens to me on a completely empty URP project. I have not tried any other render pipeline.
     
  5. KimmoFactor

    KimmoFactor

    Joined:
    Dec 29, 2020
    Posts:
    38
  6. Gisle

    Gisle

    Joined:
    Mar 25, 2014
    Posts:
    26
  7. AjejeBrazorfUnity

    AjejeBrazorfUnity

    Joined:
    Aug 23, 2022
    Posts:
    4
  8. Viva-La-Baz

    Viva-La-Baz

    Joined:
    Jun 21, 2014
    Posts:
    37
    Same issue still persists in 2022.3.5f. Any time frame on when this will finally be resolved?
     
  9. ZOMGbies

    ZOMGbies

    Joined:
    Sep 6, 2015
    Posts:
    6
    Oh dang so this is still a thing eh?

    I'm trying to find the cause or solution too. Currently fiddling with:

    1) Second camera set to overlay, cull mask to only show the object to render on UI, and the UI layer
    2) Main camera adding the second cam as a "stack"
    3) UI Canvas set to Screen Space - Camera
    4) Add the second camera to the UI canvas Render Camera field

    Everything works smoothly. But the existence of this extra camera is entirely preventing MouseDown/Up on 3d colliders in the scene while it's active.

    i.e.
    Code (CSharp):
    1. if(objCollider.Raycast(_mainCamera.ScreenPointToRay(Input.mousePosition), out hit, 200.0F))
    is no longer true. Maybe I need WorldPointToRay now or something
     
  10. Zoodinger

    Zoodinger

    Joined:
    Jul 1, 2013
    Posts:
    43
    On my main computer it works fine so I thought everything was working great until I got a complaint when I released the first demo version. I verified the problem persists on another PC of mine but only on the released version, it works ok in the editor. This is such a basic feature that it's unthinkable something as important as this has been so problematic for so long. Is there any update on this? I have clients and deadlines to deal with and I don't want to have to wait for Unity for an indeterminate amount of time to fix the problems they created.

    All I'm doing is render with another camera to a render target texture that is then displayed on an in-game monitor. The scene isn't even big with either camera so even if I rendered the whole thing twice there shouldn't have been a problem.

    Edit: I upgraded to 2022.3.7f and then tried 2023.1.9f and the problem still persists
     
    Last edited: Aug 21, 2023
  11. Rukai_K

    Rukai_K

    Joined:
    Jul 14, 2019
    Posts:
    7
    I have a same problem. My project worked well in 2021.3.19f1, And when I tried to migrate it for 2022.3.9f1, it was happened in completely same code and settings.
    What's going on? This is defenitely degradation.
     
  12. Zoodinger

    Zoodinger

    Joined:
    Jul 1, 2013
    Posts:
    43
    It was fixed for me in 2022.3.8f1 but it's possible they broke it again in 2022.3.9f1. This is Unity for you.
     
    sirshelley likes this.