Search Unity

Question Optimizing for VR.

Discussion in 'VR' started by PenProd, Jan 11, 2023.

  1. PenProd

    PenProd

    Joined:
    Dec 17, 2022
    Posts:
    171
    I've been playing with Unity for over a week now. My goal is to make a simple escape room type game just to get to grips with the workings of Unity. I have my Oculus Quest (1) connected to my computer through Quest Link. Whenever I click the play button, the scene looks great. So I know that is what the Oculus Quest is capable off resolution wise. I also realize the scene is being rendered by my GTX 1070 on my PC and simply streamed to my Quest so I expected a really low frame rate once I deploy it to the Quest itself.

    Well, unsurprisingly, I was right about the frame rate. But what I did not expect was that the quality was so much lower than the previews through Quest Link. It looked like it was running at half the resolution of the preview. Even at 8x AA, edges look terrible. Also, the color clarity is nowhere near that of the preview. I have some dark furniture in my scene which look great in the preview, but are almost black when I run the scene standalone. Also I get specular aliasing everywhere...

    I had to brighten the entire scene to get the furniture to not be almost black. The quality still isn't nowhere near what I see when I preview the scene, but I wanted to tackle another problem first. The terribly low framerate.

    At first, I only used dynamic lighting. Nothing was baked. So I got like 5-10 fps. Most of the gameobjects are static, but there also quite a few dynamic objects (like drawers). So I can't set my lights to "baked" otherwise the dynamic gameobjects get no lighting. So I set the only two point lights in my scene to "mixed". Made all objects static except for the drawers.

    But still I only get 17fps. Now the "statistics" window tells me there are at most around 800k Tris. According to the Meta specs, as long as you stay under 1M tris, you should be fine. I wonder if the number the Unity stats window gives me are correct since looking at a wall (with nothing behind it) and it tells me I'm looking at 80k tris (while if I switch to wireframe, I see 60 tris at max). But I've already created another post about that here.

    I don't think it's the complexity of my objects that's causing the low fps. Since it only rises to about 20fps if I look at a blank wall (which is nothing more than a textured box). I think it's the lighting. But I can't think of anything else I can do.

    I've done a whole bunch of optimizations:

    General Optimizations
    Using URP
    Texture compression set to ASTC
    Max Texure Size set to 2048
    Color Space set to Linear
    Scripting Backend set to IL2CPP (ARM64 target)
    Optimize Mesh Data enabled
    Stereo Rendering Mode set to Multiview
    Low Overhead Mode (GLES) enabled
    Set VSync Count to Don't Sync
    Post-Processing disabled in the URP renderer
    SSAO removed from the URP renderer (it wasn't there in the first place)
    Terrain Holes disabled
    HDR disabled

    Graphics/Lighting Optimizations
    All static gameobjects are marked as Static
    All (two) point lights are set to Mixed
    Lighting Mode set to Baked Indirect
    Set Walls, Floor and Ceiling to not cast shadows

    Optimizations I didn't do:
    Since the play area is small (6 x 12), I don't use Mipmapping or LODs, and Anisotropic Textures are Forced On.

    So anyone have more tips for me?
     
  2. PenProd

    PenProd

    Joined:
    Dec 17, 2022
    Posts:
    171
    To make sure it was not the number of objects causing the low fps, I deleted most of the objects in the room until only two closets with drawers were left, bringing the number of triangles to about 1/4th of what it was. That made no difference in fps whatsoever. It stayed at 17fps. So something really weird is going on here...
     
  3. AdrielCodeops

    AdrielCodeops

    Joined:
    Jul 25, 2017
    Posts:
    54
  4. PenProd

    PenProd

    Joined:
    Dec 17, 2022
    Posts:
    171
    Did some more testing. I progressively took more and more away (deleted, not set to inactive) from my scene to see what the impact was on my FPS. Just to get an idea of the scene, it's a closed room (no windows) of 12 x 6.

    1. Removed all objects, leaving only 4 walls, ceiling, floor, 3 point lights and a spot light. All mixed.
      FPS went from 17 to 23
    2. Removed one of the 3 point lights.
      FPS went from 23 to 35
    3. Removed the single spot light.
      FPS went from 35 to 44
    4. Removed one of the two remaining point lights.
      FPS went from 44 to 53
    So now I'm left with the most basic scene you can imagine. A room with 4 walls, a ceiling and a floor and a single (mixed mode) point light. And even then I'm only getting 53 FPS.

    So what's going on here?
     
  5. AdrielCodeops

    AdrielCodeops

    Joined:
    Jul 25, 2017
    Posts:
    54
    Use the Profiler to find out what is going on. No one is going to magically guess the cause.
     
  6. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,057
    Use the profiler and frame debugger, bake lighting, use Simple Lit, baked lit or even unlit materials, and follow other optimization guides.
    Not much to help for us without access to the project, so profile as much as you can.

    Q1 is really hard to get working properly
     
  7. PenProd

    PenProd

    Joined:
    Dec 17, 2022
    Posts:
    171
    That's disappointing. ;)

    (I was writing my reply when you posted yours, so I hadn't seen your link to the profiler page yet)
     
  8. PenProd

    PenProd

    Joined:
    Dec 17, 2022
    Posts:
    171
    I've run the profiler and I see that it spends 40ms(!) per frame on "OculusRuntime.WaitToBeginFrame". I also see that GI and Rendering hardly make a dent in it's overall performance so I guess that's the good news.

    upload_2023-1-11_15-14-14.png

    Now waiting 40ms for a frame sync is very, very odd since in those 40ms, at least 3 frame syncs should have passed (if I understand correctly what frame sync is).

    So my question remains: what's going on here? :D
     
  9. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,057
    That basically means a GPU bottleneck. It's vsync + waiting for the GPU
     
  10. AdrielCodeops

    AdrielCodeops

    Joined:
    Jul 25, 2017
    Posts:
    54
    Check also your drawcalls. Transparencies are also a killer on mobile.
     
  11. PenProd

    PenProd

    Joined:
    Dec 17, 2022
    Posts:
    171
    This was profiled on the Quest, so you mean the Quest's GPU?

    A vsync wait should never last longer than ~14ms...
     
  12. PenProd

    PenProd

    Joined:
    Dec 17, 2022
    Posts:
    171
    But that would mean it would have gone away when I deleted all objects from the scene (and left an empty room). It didn't.

    I think this might be related to this bug?
     
  13. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,057
    I said and waiting for the GPU.

    No, it's probably not. Check the frame debugger as mentioned
     
  14. PenProd

    PenProd

    Joined:
    Dec 17, 2022
    Posts:
    171
    Before I continue, let me repeat that I've only been working with Unity for about a week now and this is the first time I've worked with a game engine. Any game engine. So up until a week ago, any game development related terminology was unknown to me. I mean, a week ago, I thought dynamic occlusion had to do with teeth. :D So I'm trying to digest a lot of information. And I mean a lot. So if I ask dumb questions, it's because I've never done game programming (well, I did like 30 years ago. But that was in 8086 assembler) let alone 3D game programming.

    So I've been looking at the frame debugger, read its documentation, saw the youtube video, but I still have no idea how that can help me find out what's causing the low fps. All I can tell is that it makes between 40-60 draw calls (that's the number to the right of the slider, right?). Other than that, I have no idea what I'm looking at.
     
  15. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,057
    You could hire me for it as tutor, but without project access you're on your own.
    The quest 1 is just very slow.
    60 draw calls is high for just a few boxes tho
     
  16. PenProd

    PenProd

    Joined:
    Dec 17, 2022
    Posts:
    171
    I don't need a tutor, I need a solution. ;)

    I understand it's slower than a Quest 2. But 50 fps for an empty room with a single point light? 30 fps for the same room with two mixed mode point lights? Something else is going on than just the Quest being slow.
     
  17. AdrielCodeops

    AdrielCodeops

    Joined:
    Jul 25, 2017
    Posts:
    54
    You could try to make an empty project on a safe LTS version of Unity or with the builtin renderer. But i think you have something wrong configured.
     
    DevDunk likes this.
  18. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,057
    If you dont bake lighting mixed is just realtime.
    A point light probably is the heaviest light there is as well (tripple that if shadows are enabled), and there probably are some settings you can tweak. Also make sure you edit the urp asset for android
    Maybe this helps a bit as well: https://www.youtube.com/playlist?list=PLjnZTAR0BuTDNeDPy44G4bUpYRHGzy_xh
     
  19. PenProd

    PenProd

    Joined:
    Dec 17, 2022
    Posts:
    171
    I'm using 2021.3.16f1 LTS with the VR Builder plug-in.

    I just created a new project, imported VR Builder, created a single plane and four boxes as walls. Only one directional light. Nothing is textured. Getting 23 FPS.

    I'll try one more project without VR Builder, see if that makes any difference.
     
  20. PenProd

    PenProd

    Joined:
    Dec 17, 2022
    Posts:
    171
    Build settings:
    upload_2023-1-12_12-32-44.png

    Player settings:
    upload_2023-1-12_12-33-49.png
    upload_2023-1-12_12-34-50.png
    upload_2023-1-12_12-36-19.png
    upload_2023-1-12_12-37-12.png
     
  21. PenProd

    PenProd

    Joined:
    Dec 17, 2022
    Posts:
    171
    Quality Settings:
    upload_2023-1-12_12-39-25.png

    Oculus XR-Plugin Management settings:
    upload_2023-1-12_12-40-40.png
     
  22. PenProd

    PenProd

    Joined:
    Dec 17, 2022
    Posts:
    171
    Made the exact same scene (a floor and four walls) but instead of using VR Builder, I just added "XR Plug-in Management" in the Project Settings, dropped in an XR Rig and built it for the Quest.

    Now I got 17 fps.
     
  23. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,057
    1. Id say start without post processing (v2 is in the defines, so remove it)
    2. Remove vr builder stuff for now, just simply only use hmd output
    3. You use both input systems, use the new one for VR
    4. Is the balanced prefab green for android in the quality matrix? Otherwise another might be used
    5. In the player settings for android you can also disable stencil and depth and disable 32bit something, might help
    6. Fixed foveated rendering might help with performance as well, application spacewarp could be used as last resort.

    Can't help more than this. There might be some settings in the balanced urp asset as well.
     
  24. PenProd

    PenProd

    Joined:
    Dec 17, 2022
    Posts:
    171
    Just wanted to add that although I apprently made a screenshot of the wrong Quality Settings, since I'm not using the "URP Balanced" render pipeline asset, but one I added myself. Everything is the same except "VSync Count" which is actually set to "Don't Sync" and Anisotropic Textures" is set to "Forced On".

    And yes, post processing was already disabled.
     
  25. PenProd

    PenProd

    Joined:
    Dec 17, 2022
    Posts:
    171
    I was able to test my "game" on a Quest 2, and I get 50% higher frame rates.
     
  26. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,057
    1. Vsync is always on on quest
    2. Aniso does cost more performance
    3. If using urp screenshot the urp asset for your performance settings

    Seems about right
     
  27. PenProd

    PenProd

    Joined:
    Dec 17, 2022
    Posts:
    171
    upload_2023-1-12_21-7-9.png
     
  28. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,057
    You use 4k shadows for additional lights, big cookie atlas, soft shadows, both reflection probe things, 4x msaa, and depth texture....
    and did not put on fast linear conversion
     
  29. Hobodi

    Hobodi

    Joined:
    Dec 30, 2017
    Posts:
    101
    Well. If the profiler does not show any problems with the CPU, then you should use the RenderDoc for Oculus that comes with Meta Quest Developer Hub to see the bottlenecks of the GPU.
     
    AdrielCodeops likes this.
  30. AdrielCodeops

    AdrielCodeops

    Joined:
    Jul 25, 2017
    Posts:
    54
    An empty scene should run at a solid 90fps Quest2 (depending on your headset hz).
     
  31. PenProd

    PenProd

    Joined:
    Dec 17, 2022
    Posts:
    171
    I was able to find a lot of fps by changing the walls and floor from "Lit" to "Baked Lit". On the Quest 1, that made frame rates vary between 25 fps (when standing in the corner and looking at all objects in the room) to 55 fps (standing in the middle of the room). On the Quest 2, fps varied between 50 and 72 fps. In both devices that made walking around in the room perfectly acceptable.

    It does make the walls and floor look a lot darker which fortunately in my case was a good thing (because I was meaning to make them darker anyway).

    I don't understand why this makes such a huge impact (since the walls are boxes and the floor is a plane). When I changed objects with 4k tris to "Baked Lit", that hardly made an impact at all...
     
  32. PenProd

    PenProd

    Joined:
    Dec 17, 2022
    Posts:
    171
    And yet it doesn't. I could change the walls and floor to static objects, make the directional light baked but frame rates would hardly increase. The only thing that made my frame rates shoot up, was when I changed the shader on the wall/floor's material from Lit to Baked Lit. Even Simple Lit wouldn't make much of a difference.
     
  33. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,057
    I already said to used baked. Then there is no realtime lighting processed


    How much you geting? WIthout explicitely stating it q2 will default to 72hz
     
  34. PenProd

    PenProd

    Joined:
    Dec 17, 2022
    Posts:
    171
    Yes, you said to use baked lighting, which I did. I had checked many a tutorial on YT, read the Unity documentation, but nowhere did it say you should change the shader as well. It is logical, because I always thought it didn't make any sense that a static object that received a lightmapping from mixed lights, would still receive realtime lighting from the very same lights. So now it makes perfect sense that I should have changed the shader as well.

    I didn't test it yet on the Q2 but I'm pretty sure I would now get 72fps (Q2 hasn't been set to 90Hz) since I'm hitting 72fps as well in my fully furnished room with two light sources.
     
    DevDunk likes this.