Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Render Every-other frame/ Camera Toggling Performance Hit in HDRP

Discussion in 'High Definition Render Pipeline' started by craftsmanbeck, Sep 24, 2023.

  1. craftsmanbeck

    craftsmanbeck

    Joined:
    Nov 20, 2010
    Posts:
    40
    TL;DR What's the preferred way to render a camera every other frame in HDRP?

    Long: In my game I've got several auxiliary cameras used for things like minimaps and the like. While they don't consume too much resources (~3% of render time each), there's enough of them that they start adding up. I thought it would be good to cycle through them and render only one each frame by disabling every other one. Unfortunately, it seems like there's a rather large performance hit each time you enable or disable, causing the GPU Profiler to report taking upwards of 10ms for the newly re-enabled camera. What's the preferred way to do this, or more simply have a camera render every other frame for example?
     
  2. Kabinet13

    Kabinet13

    Joined:
    Jun 13, 2019
    Posts:
    91
    Multiple cameras in HDRP is generally a bit of a no go, it can be done, but the overhead is a bit much. 95% of effects you might use a second camera for can be recreated with shaders and custom render passes, it might not be possible for everything, but getting rid of as many extra cameras as possible would help a ton, leaving enough performance budget left for the few effects that might truly need it.

    Could you go into more depth on what exactly these effects all are?
     
  3. craftsmanbeck

    craftsmanbeck

    Joined:
    Nov 20, 2010
    Posts:
    40
    For example, using a render texture to drive persistent foliage deformation based on character positoins, as well as using a Render Texture for a Fog-of-war-like effect, where units have a certain "vision range" that persists even after leaving the area in question.
    However, this is a bit of a red herring, as my question was how to render every other frame without incurring the cost from re-enabling the camera (toggling the cameras on and off each frame incurs a huge cost of unknown origin that exceeds just having everything rendering constantly by a large margin). With being able to toggle each frame without this overhead, it would be a cheap and quick fix to get reasonable performance gains on the order of 20% for just a few minutes of effort. Not to say there aren't other (more time intensive) ways of getting around it.
     
  4. Skiriki

    Skiriki

    Joined:
    Aug 30, 2013
    Posts:
    68
    If you have multiple effects like this, maybe they can just share the same camera on a rotation basis, swapping out the target RenderTexture and the camera position/settings.