Render to SceneDepth only

I have a Blueprint with a static mesh component that is translucent. I understand that translucent meshes don’t render to the scene depth, so I followed the advice in this post, but it doesn’t work.

The idea is to duplicate the static mesh, and then turn of Render in Main Pass and turn on Render CustomDepth pass on this duplicate mesh. That way you don’t see the duplicate mesh in game, but it will still render to the scene depth. However this appears to no longer work. The duplicate static mesh does not render into the scene depth buffer at all.

Is this a bug or is there a new way to do it now, considering that post was from 4 years ago.

You do not need to duplicate the mesh. Translucent objects can write to custom depth. There is a checkbox in material settings.

I’ve seen that and already tried it too, but it doesn’t work. I have the feeling that both Render to CustomDepth Pass on the static mesh and Allow Custom Depth Writes on the material is for writing to the custom depth buffer. However it doesn’t write to the actual scene depth buffer.

So either it is not meant to write to the scene depth buffer and there is another way to do it, or it is a bug that should be reported.

I think the idea is to write to the actual depth buffer, rather than custom depth. As far as I know, effects like depth of field can only function based on the scene depth buffer, so if the goal is to apply depth of field to a translucent object (rather than whatever is behind it), this won’t work.

It is likely intended. If such functionality ever existed in past, it was and is undesired.

There are workarounds to get mesh to render only in depth buffer, but I have no idea how one could apply that, especially considering that it would happen during pre/base pass.

Thanks anyway guys… surely someone knows how to do this. I can’t be the first person that needed to render only to the scene depth buffer.

If I understand what you want, this definitely still works in 4.22. We use it for highlighting fully or partially translucent objects.

  • attach dupe static mesh with default world grid material (UStaticMeshComponent* proxy)
  • proxy->SetRenderInMainPass(false);
  • proxy->SetCastShadow(false);
  • proxy->SetCollisionEnabled(ECollisionEnabled::NoCollision);
  • proxy->SetRenderCustomDepth(true);

One thing you might have forgot is swapping the material of the proxy to a non-translucent? We use the Unreal default world grid.

Below is example of a translucent cube highlighted via CustomRenderDepth method.

Ohh hmm you want scene depth not custom depth. Will leave the above anyway in case someone searches this topic. :frowning:

Well I sent a bug report in about it just in case, but turns out, no it is not a bug. I was told to post to answer hub, which I’ve done now.

Hopefully someone has done this before and notices my post.

Thanks guys. I managed to solve the problem. It is actually possible to do what I wanted to do, just took a bit of experimentation and thinking outside the box.

Can you post the solution for future google searches? Also just wondering but what is the use case for this? :eek:

Writing that you “solved it” and not posting the solution is a grave sin in the question/answer community :slight_smile: Please update the thread with the solution or point others in the right direction. Thanks!

I found this thread while trying to find a way to get DoF to work with a translucent plane. My thought process was that if I had a second plane, rendering only to the scene depth, and put that plane beneath my translucent plane, I would be able to force the DoF code to use that second plane’s depth for the the translucency plane. It doesn’t work though because there’s no way to render to just the depth buffer that the DoF shader uses.

I did however get something working, but I’m not proud of it. Below is a screenshot. It’s a partially translucent plane (opaque on the white squares, translucent on the black), with some cubes underneath and above it. If you notice, depth of field appears to be working… the translucent plane blurs correctly, and also reveals the cubes underneath.

How is it done? A scene capture component on the pawn. And a hidden plane just underneath the translucent plane. The scene capture component ignores both planes. Then the render texture of the scene capture component gets projection-mapped onto the hidden plane. Like I said, not proud of it, but it seems to work ok. I’ve attached the scene files for anyone interested. (561 KB)

Hey Guys, i want to write my mesh to scene Depth so i can use GPU emitters collision which works on scene depth
i tried using the above technique but that does not work.
if wilberolive can post his solution that would be great.

Hey sorry guys. From memory the solution ended up being specific to my use case scenario, which is why I didn’t bother going into detail. However, I’ll go back and check what I did and see if I can revise it into a more general solution. Just give me some time.

Ok, so I’ve looked back over my blueprints and here is what I did.

  1. Create a material with Allow Custom Depth Writes set and assign it to your static mesh.
  2. Set that static mesh to Render CustomDepth Pass.
  3. Create a post process material that takes the Min of the R value of both the SceneDepth and the CustomDepth.
  4. Then use that post process material with a scene capture to capture both the scene depth and the custom depth in the same texture.

You can then use this texture however you wish in other materials for example.