Optimize Scene Capture depth rendering

I am doing custom shadow mapping using depth map generated by scene capture. Using render doc I noticed that scene capture is rendering everything and when I set its output to depth in R. It is absolutely unnecessary to render everything when I need only depth buffer. With simple “if(ViewFamily.SceneCaptureSource == SCS_SceneDepth) { … return; }” after prepass in core Render() function I could save dozens of ms and make scene capture depth rendering actually usable (tested in custom engine build). Other scene capture modes could be probably optimized too.

Epic Staff, could you please enter feature request for this, so it will not get lost?
@RyanB
By custom shadow mapping I mean something similar to this Ryan’s blog: http://shaderbits.com/blog/custom-pe…ing-blueprints

For high resolution scene capture and rich scenes difference can be even more than 10ms -> 0.5ms

Since its just one line of code, you should definitely create a pull request for that, simple ones like that are most likely to get merged by epic:

https://github.com/EpicGames/UnrealEngine/pulls

And even if they don’t merge it, it makes it very easy for anyone to just quickly cherry pick that improvement, when needed.

I do need to use scene capture rendering with depth only, and I was not aware of this yet, so thanks very much for mentioning that here! Will definitely help my performance :slight_smile:

Definetly make PR.

I don’t think it is proper™ solution, however I will probably do that PR, so other devs can cherry pick it.

I am not really sure, what you are referring to as

The controls, what to render, are on scene capture itself.
When capture is set to SCS_SceneDepth, the rendering will be done with simplified depth shader.

But yeah, if you feel like it could be an improvement, definitely submit a PR.

Yes, many features can be toggled with flags however there is no full control. There is great performance improvement with forced full depth prepass only for scene capture in SCS_SceneDepth mode. Base pass is the bottleneck.
I just did quick test:

Very simple scene, All rendering flags disabled (except static meshes), SCS_SceneDepth, 4096x4096 (launcher 4.18)
vs
Very simple scene, All rendering flags disabled (except static meshes), SCS_SceneDepth, 4096x4096, Depth prepass only (custom build, 4.18)

Depth pre-pass is run for a depth only capture? Boo. :eek:
Your PR will be very helpful.

Very nice gains indeed.

I’m just wondering, will this still work if the game doesn’t actually do a depth prepass for the regular camera? It’s expensive, so I made sure that I don’t use any features that require that. So can the depth prepass be disabled for all normal cameras and be enabled for one scene capture individually?

If scene capture is in SCS_SceneDepth mode, then I am forcing it for scene captures only in code and I am also forcing full prepass, so no objects are ignored. However, I am not sure how good is this for different platforms, that’s why I was a bit sceptic when It comes to PR. I will do some improvements, tweaking and then do the PR.

Even if it isn’t beautiful enough to get integrated into the engine, the PR can be used by others in their own projects if they happen to have the same need as you did.

Please, would you provide this custom build for download? It would be hugely appreciated.

Sure, here is the PR, so you can cherry-pick it: https://github.com/EpicGames/UnrealEngine/pull/5489
Tested in 4.18

r.SceneCapture.DepthPrepassOptimization 1 can optimize SceneCapture “SceneDepth in R” rendering