More Efficient Depth Rendering


This is a bit of a cross post, but I've had no luck so far get any responses to help address the problem:

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.

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.


Hey Pete, did you try the com.unity.simulation.capture package from Unity? The Unity Simulation Capture SDK provides efficient ways perform (depth) data capture. Here is a link to the docs:

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.

Have you tried calling the RenderWithShader method, to render the scene with a trivial shader (e.g. Unlit/Color)?

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 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.

Just a follow up on this issue,

I have found* a solution to this issue, details can be found in this forum post:

*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.