Search Unity

Performance drop when camera zoom out (camera rendering?)

Discussion in 'General Graphics' started by Xhitman, Mar 17, 2019.

  1. Xhitman

    Xhitman

    Joined:
    Oct 30, 2015
    Posts:
    452
    It is a RTS game,

    No problem in this camera view, FPS around 60, everything smooth.
    https://photos.app.goo.gl/B7JKCGCrqwVHjs7G9

    However, when I zoom out the camera, FPS drop to 30 something, everything lag
    https://photos.app.goo.gl/r2H48wLmcGzW8n2WA

    Because only the orthographic camera size change when zoom in/out (between 60 to 200 by mouse middle button),
    I think it is the camera rendering issue. I already set all objects are set to "no shadow cast" , "not receive shadow" to reduce the workload.

    How to solve this problem?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    The profiler is showing almost no change in rendering time, but a significant increase in script execution time. You need to look at what function(s) are taking so much time.
     
  3. Xhitman

    Xhitman

    Joined:
    Oct 30, 2015
    Posts:
    452
    the average rendering increase from 16ms to 33ms, the chart vertical scale is not the same, you need to zoom in to check.
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    You're looking at the CPU usage graph. Everything on that graph is CPU usage time.

    You're also rendering a lot more stuff when you zoom out, so it should be expected it takes longer to render, both on the CPU (which the "rendering" is the time it takes for the CPU to tell the GPU what to render) and the GPU (which isn't shown in the screenshots). However the script times are still all over the place, with the script execution taking more than 30ms by itself* meaning 60fps isn't going to happen regardless of how well you optimize the GPU. This assumes during those script spikes the profiler isn't showing GFX.WaitForPresent, which means the CPU is stalling waiting for the GPU to finish rendering the last frame. If that's the case, it really is the GPU (in combination with the CPU) in which case you're just going to have to render less stuff.

    You may need to use simplified skinned mesh LODs for units when you're far away, or potentially even unanimated meshes or sprites, or just generally look at the profiler details more to find out what is taking so long on the CPU and try turning off stuff to see what gives back the most in terms of the GPU time. Click on the "Stats" button on the game window's top bar to see the GPU stats.