Search Unity

Why is my frame rate dropping when viewing mesh from up close

Discussion in 'General Graphics' started by martinasenovdev, Dec 8, 2018.

  1. martinasenovdev

    martinasenovdev

    Joined:
    May 7, 2017
    Posts:
    67
    Dear Unity fellas,
    I've come out of options and I really can't figure out what the problem is.
    This is a custom generated mesh out of some terrain data - this is because I want to reduce the amount of triangles and vertices as much as possible. Material using Standard shader, Albedo texture only, no normal maps. There are physics enabled, probably 200 box colliders on the scene + 1 RigidBody (the player).

    Tested on an Android - Samsung Galaxy J5 (2015). Our goal is to be able to pull off 60+ FPS even on low end devices like this one. Mostly everything goes well, but..... it drops to 20 FPS when standing in the middle of the stage.
    (this is a sample scene of course)

    As I said custom generated mesh, separated in chunks (different meshes) (mostly in order to use frustum culling and also because any given submesh can't have more than 900 vertex attributes), dynamic batching is enabled, static batching is disabled as we don't use it:
    Screenshot (46).png

    This is the how the mesh of some random chunk looks like:
    (as you can see only the visible faces are drawn)
    Screenshot (47).png

    overdraw of the scene (not much I think):
    Screenshot (45).png


    Interestingly enough, I noticed viewing the mesh from farther away doubles the performance ??? (26 FPS vs 55 FPS)
    (here I've jumped with the character and gravity is disabled on the rigid body)
    Screenshot_20181208-233932.jpg
    and yet the tris/verts/draw calls are roughly the same (captured in Editor)
    Screenshot (49).png

    I thought it has something to do with texture quality or the alpha in the texture. So I lowered the texture import size as well as removed alpha, no result. I also tried setting the texture quality to "Eighth res" in the Quality settings.
    Quality settings are "very low", I tried absolutely everything, playing with lighting settings, changing texture quality, anisotropic textures are disabled, shadows are disabled, anti aliasing is disabled, 0 pixel lights are allowed, vsync is off, nothing yielded any result!
    Removing any box colliders/rigid bodies from the scene didn't change anything as well (as I thought it may have something to do with the physics simulation)

    Linking the profiler to the device showed the time is mostly spent on Gfx.WaitForPresent. That makes me think the CPU has finished its work and waits for the GPU to render the scene. (VSync is disabled, so it is not the reason). Unfortunately the GPU profiler cannot be linked to the device.

    I can't really figure out what is going on and why the FPS rate is increased when viewing those mesh chunks from far away. I am really keen to get to the bottom of this and achieve 60+ FPS on this sample project!! But I am really out of ideas now.

    I am really thankful for any help!
     
    Last edited: Dec 8, 2018
  2. I don't know too much about mobile optimization, so I can't be really helpful with that. I have no experience if your 200 boxes are a lot or a few for a device from 2015. But:

    AFAIK you can't turn it off on mobile OSes. You can turn it off in Unity but in reality it will never will be disabled. So your device still will drop frames when it go below the target frame rate.

    Because your GPU has less work with them (less pixels are changing on the screen, less pixels are redrawn other than the initial color fill). This is true for the editor too (I mean on desktop as well)
     
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,350
    Mobile GPUs are much more limited in performance vs desktop GPUs, especially when it comes to dealing with shader complexity, and the number of pixels they can render. For a desktop GPU having the entire screen covered with geometry using the standard shader isn't a big issue, there's a lot of extra perf left for rendering those pixels, so it won't be a significant part of the overall frame time. Looking at your stats, you're either CPU or vertex / object limited, so when you're close and more objects are being culled you have a higher frame rate.

    But for mobile a single full screen quad using the same standard shader takes a big chunk of the frame time. So any savings you might get from culling are being offset by the GPU struggling to render everything.

    The standard shader is automatically simplified when it runs on mobile hardware, but it's still more complex than the old mobile diffuse shader. You might try using that instead.
     
    martinasenovdev likes this.
  4. martinasenovdev

    martinasenovdev

    Joined:
    May 7, 2017
    Posts:
    67
    It is the opposite - the frame rate is low when I'm on the ground, close to the objects but they take my entire screen.
    If I jump into space and I see the entire stage I see more triangles/verts, but I see the level smaller - that's when the FPS are much higher.

    Switched to the Mobile/Diffuse and OMG - suddenly 60 fps! What a drastic difference!
    Unfortunately seems like it does not have Specular Highlights and Reflections but I guess if I am in need of these I can extend that shader and add them manually.
    Now I read the Standard shader is some kind of monster - even on mobile, where it is replaced with a more lightweight version. Now I can see that completely proven - from 20 FPS to 60 FPS in one click!