Search Unity

Question 3 HDRP Cameras Performance Optimization

Discussion in 'High Definition Render Pipeline' started by CleverAI, Nov 2, 2021.

  1. CleverAI

    CleverAI

    Joined:
    Jun 4, 2017
    Posts:
    38
    Hello Community,

    recently I participated at 2021 Unity x Humble Bundle Showcase with my game "Cursed Dungeon Raider" which you can see here:
    https://play.unity.com/mg/other/cursed-dungeon-raider-launcher



    There I used HDRP and 3 cameras for:
    1. Main Camera, which renders nearly everything except what camera 2 and 3 renders.
    2. Player Item Camera, as a child of the main camera, which renders only the player arms and items on top of the main camera to create the FPS effect that nothing get stuck in walls. (Culling Layer -> Player Item)
    3. Map Camera, which renders only map icons, which are simple quads on objects, to a render texture with a resolution of 1024x1024. Changing the resolution has nearly no performance benefits. (Culling Layer -> Map)
    The performance drops about 50% if all cameras are active compared to only main camera active. You can see it in the game. Just press "H" to hide the equipment and to see the full FPS in the top left corner. Then press and hold RMB, so that the map shows up and all cameras are active, to see the performance drop.

    Even though the other two cameras have only one layer to render, the performance drop is the same as they would render everything.

    My questions are:
    1. Do they still render everything and culling at the end the other stuff out?
    2. Is there a way to optimize it?

    The only thing I can think of is to let the Map Camera only update a few times per second instead per frame. But the Player Item Camera needs to be updated every frame.

    Thank you in advance for your help!
     
  2. PutridEx

    PutridEx

    Joined:
    Feb 3, 2021
    Posts:
    1,136
    HDRP struggles with multiple cameras. I don't think there's much you can do to optimize it, it's a known limitation/issue.
     
  3. BOXOPHOBIC

    BOXOPHOBIC

    Joined:
    Jul 17, 2015
    Posts:
    509
    Hi. A quick optimization you could try is to go to the camera's frame settings, and disable everything that is not needed:

    upload_2021-11-3_12-27-20.png
     
    olavrv, dexmex001 and CleverAI like this.
  4. CleverAI

    CleverAI

    Joined:
    Jun 4, 2017
    Posts:
    38
    That would be a pity.

    Ohh okay. Thanks I'll give it a try.
     
  5. CleverAI

    CleverAI

    Joined:
    Jun 4, 2017
    Posts:
    38
    I tested your advice. After I have removed all features which are not necessary for the Player Item and Map Camera I could improve the FPS from ~70 to ~83, so 18% more performance without losing any visuals. That's a good first improvement. Thanks.
     
    tmonestudio and olavrv like this.
  6. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    You can use custom pass specifically for this. Especially for the Map Camera you can use this with almost no performance impact. For the FPS effect sadly currently it's not perfect there's an issue with motion vector, so if you use motion blur and TAA there's will be a visual artifact like random motion blur on the FPS Pass. But if you are not using TAA or motion blur, it actually work nicely with minimum performance impact.
     
    CleverAI likes this.
  7. CleverAI

    CleverAI

    Joined:
    Jun 4, 2017
    Posts:
    38
    I don't use TAA nor motion blur. So I can give your idea a try.

    Unfortunately, I barely used custom pass. So I don't know yet how I can set one up for my map and one for my player item camera only. Is it enough to place a global "Custom Pass Volume" on a game object with the layer "Map" and one with the layer "Player Item" so that only the specific camera, which renders those layers, will use it?

    In addition to that, I think I need a proper tutorial on how to use them for my problem. This Unity one does other stuff:

    I really don't know how I can create a custom pass to achieve the effect that these cameras don't render other stuff for better performance.

    Also I think there is a bug for me right now with this "Custom Pass Volume" component. After I add with the "+" button a "DrawRendersCustom" or any other custom pass, I can't delete them with the "-" button. I have to delete the component completely to get rid of them. (Unity 2021.1.23f1, HDRP 11.0.0)
     
    Last edited: Nov 9, 2021
  8. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    https://github.com/alelievr/HDRP-Custom-Passes
    also there's several thread about custom pass especially FPS pass in HDRP subforum, try to search for them it's been a while ago i don't remember what was the thread title
     
    CleverAI likes this.
  9. CleverAI

    CleverAI

    Joined:
    Jun 4, 2017
    Posts:
    38
    Okay thanks. I'll give it a shot.
     
  10. CleverAI

    CleverAI

    Joined:
    Jun 4, 2017
    Posts:
    38
    With the help of this thread:
    https://www.intetic.com/blogs/unity-hdrp-render-object-on-top-of-everything/

    I was able to get rid of the second camera which was used to render the player arms and items always on top. The performance gain is huge. Unfortunately, those items don't casts shadows on themself anymore from other light sources. Here are two screenshots to show what I mean.

    With second camera as child of main camera everything is fine (left picture), whereas with custom pass there are no shadows anymore (right picture):

    To get the shadow back I needed to add the "Player Item" layer to the culling mask of the main camera.

    In addition to that, if the arm clips through a wall the custom pass will look very dark, whereas the second camera does the job as intended.


    Edit:
    It looks so dark, because the object behind the arm is still visible. So I think it has something to do with the depth?


    Moreover I got another shadow problem due clipping:


    So it seems I need to stick to a second camera to avoid those issues...
     
    Last edited: Nov 14, 2021
  11. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Hmm i don't remember about the shadow issue, i don't think i ever get that issue though.
    For the dark part that i think this is normal when rendering FPS objects as an additional pass. i also notice the same issue in frostbite games. I think it got dark because it's actually receiving shadows from the wall
     
    CleverAI likes this.
  12. CleverAI

    CleverAI

    Joined:
    Jun 4, 2017
    Posts:
    38
    The last two pictures confirm your assumption about the dark part due to the receiving shadows. But the one above must be another problem.

    Either way, thank you for the custom pass hint.
     
  13. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    No problem just mess around with custom pass, there's a lot of gotchas with it currently and from what i see it still being improved.
     
    CleverAI likes this.
  14. Nielot53

    Nielot53

    Joined:
    Oct 22, 2021
    Posts:
    1
    Hi, i had simillar problem i manage to make custom pass (fps pass) but i cant figure out how to use custom pass (minimap pass) to replace third camera which renders texture for my minimap. Do you have any more info that can help me with that?
     
  15. antoinel_unity

    antoinel_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    265
    For the minimap, you can try to take example on this script by replacing the depth rendering with a color rendering: https://github.com/alelievr/HDRP-Cu...s/Scenes/CameraDepthBaking/CameraDepthBake.cs

    It renders the scene from the point of view of another camera without the cost of it (under the hood it overrides the rendering matrices of the current camera and uses another culling list to draw objects that are not in the main camera view).
    The downside is that you can only render objects using a single pass, this means that the lighting will not work as the structures are not initialized for this view. Though it can still be useful if you override the material or the shader of all the objects you're rendering to be unlit.
     
  16. kripto289

    kripto289

    Joined:
    Feb 21, 2013
    Posts:
    505
    Also terrain with "draw instanced = true" doesn't work with this method.(And I other objects with instancing)
    So, with the broken instancing and incorrect lighting it's the useless feature in most cases.
     
    nehvaleem likes this.