Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question More Efficient Depth Rendering

Discussion in 'Robotics' started by PeterSmithQUT, Sep 28, 2021.

  1. PeterSmithQUT

    PeterSmithQUT

    Joined:
    Sep 22, 2021
    Posts:
    9
    Hi,

    This is a bit of a cross post, but I've had no luck so far get any responses to help address the problem:
    https://forum.unity.com/threads/rendering-a-depth-only-pass-on-a-seperate-camera.1172807/

    Essentially, I have implemented sonar simulation using a depth render and a compute shader to interpret the results but it is terribly inefficient as even though the camera is rendering into a depth only Render Texture, the entire colour HDRP render takes place.

    Anyhow, any help or pointers would be appreciated.
     
  2. mrpropellers

    mrpropellers

    Unity Technologies

    Joined:
    Jul 10, 2019
    Posts:
    13
    Hey Pete! This is a very good question that I don't have an answer for yet. I'm poking around those on the Computer Vision side of things to see if they have any suggestions. If that doesn't bear fruit I'll see if I can't find someone with a more direct relationship with the rendering pipeline, as I'd very much like to know the answer to this question as well.
     
    Ivan_br, Chootin and PeterSmithQUT like this.
  3. danielb_

    danielb_

    Unity Technologies

    Joined:
    Nov 22, 2016
    Posts:
    1
  4. PeterSmithQUT

    PeterSmithQUT

    Joined:
    Sep 22, 2021
    Posts:
    9
    Hi Daniel,

    Thanks for your response,
    I now have spent some time diving into the com.unity.simulation.capture package to see if It will help me out. However it doesn't help address my current issues. I found that this package will perform a full standard render and blit the depth buffer contents to a render texture that is then readback from the GPU to the CPU. It will perform a full render even if only a DepthGrab is attached, even if the camera component is disabled.

    Also for the sonar simulation in my project, the rendered texture is not read back from the GPU in it's entirety, instead the render texture is sent to a compute shader for further processing and only a small processed buffer of data is returned.

    What I'm ideally looking for is a way to disable components of the render pipeline that aren't required when only depth is required. So far I've found that you can set some per-camera Custom Frame Setting to reduce a significant amount of GPU load by disabling features such as Shadows, Fog & More. This has moved the problem to more of a CPU bottleneck which I've had only limited success reducing so far. The biggest components are the Cull step, I've started to manually disable distant terrain which has helped but maybe I could try disabling Occlusion Culling as well. Also the Inl_HDRenderPipeline::Render step is taking a lot of time and I'm wondering whether I could disable some features for depth only renders on a per-camera basis to help there as well.
     
  5. LaurieUnity

    LaurieUnity

    Unity Technologies

    Joined:
    Oct 23, 2020
    Posts:
    77
  6. PeterSmithQUT

    PeterSmithQUT

    Joined:
    Sep 22, 2021
    Posts:
    9
    Hey @LaurieUnity,

    Thanks for your response,
    Just gave it a go, but it doesn't seem to be working, I believe this is because I'm using HDRP.
    I also attempted disabling Occlusion Culling on a per-camera basis with
    Code (CSharp):
    1. camera.useOcclusionCulling = false
    but that didn't seem to make a noticeable difference either way, but to be fair after looking at the Window > Rendering > Occlusion Culling window, I've not done a bake before so I don't think it was enabled to begin with. Also as this scene is open ocean there's not much occlusion that can take place realistically.

    I think I'm at the point where the actual GPU load is acceptably small, but the CPU load per render is still higher than I'd like. One of the key CPU loading areas I think is related to the cull step of the terrain (ocean floor in this case). Most of the time, each camera can only see a small amount of the ocean floor, so I thought that disabling the out-of-view chunks would improve performance. The main issue I've found with this is that I can't selectively enable the terrain chunks for certain cameras when multiple cameras are rendering in the same scene. Instead, I've calculated the visible chunks for all cameras in LateUpdate and disabled the rest which I'm not super happy with yet.
     
  7. PeterSmithQUT

    PeterSmithQUT

    Joined:
    Sep 22, 2021
    Posts:
    9
    Just a follow up on this issue,

    I have found* a solution to this issue, details can be found in this forum post:
    https://forum.unity.com/threads/rendering-a-depth-only-pass-on-a-seperate-camera.1172807/

    *There's still some optimizations to be made on the culling step, but I think that's a different issue and the goal of reducing the GPU rendering operations down to a minimum has been achieved!

    Thanks for all who posted suggestions to try.