[SOLVED] depthWrite not working on text in 3D space

Hi there, we have name tags above players and want to apply a focal blur post-effect. If the text does not write its depth, then it will be blurred according to the depth of whatever is behind it, which is wrong. However, setting depthWrite on the text material does not work as expected. Am I doing something wrong, or is there a trick to get it working?
Thanks.

Are the name tags using elements in 3D space? If so, are they still on the UI layer? If so, change it to the world layer

Edit - Scratch that, sounds like you have a different issue. Can you post a public repro project please? I would have thought at least a custom material would work in this case :thinking:

Thanks yaustar, yes and yes to your questions, but setting it to World did not help.

Example:
image

Our setup is more complicated, but I’ve tried to make a simpler example scene here:
https://playcanvas.com/editor/scene/1630638

Hmm, can you try creating a custom layer, order it towards the end of your layers list. Then use the following property on your active camera to stop post effects rendering from that layer and on:

https://developer.playcanvas.com/api/pc.CameraComponent.html#disablePostEffectsLayer

Hopefully it should work :pray:

PS I may have misunderstood what you are looking for now that I ready again your initial post. Since you do want to apply a post effect on this layer.

Looking at this:

The Depth layer is handled after the World Opaque. However, the Element is rendered on the World Transparent sublayer.

If I move Depth to be after World Transparent

I get the following result:

Not sure why the element on the depth layer is just a large rect though on the Depth Buffer

@mvaligursky ?

I made a new layer as Leonidas suggested, and it works perfectly. No need to fiddle with the depthWrite now.
Thanks a lot!

Hmm, I think the post effects must be clearing the depth buffer, so when I delay the text layer to after post effects then depthTest no longer works on the text. Is there anything I can do about that?

@mvaligursky any idea here?

camera before posteffects renders to an internal render target … and last post-effect renders/copies the result directly to the framebuffer, so there is no depth available after that unfortunately. If you need depth test, you need to do this before posteffects.

1 Like

Ok, using yaustar’s way to have the depthWrite work on text (also good to know why that didn’t work before).
Thanks a lot everybody!

2 Likes