Scene Depth with Transparent vs Opaque ShaderGraph

Hi, I am trying to sample depth using the Scene Depth node but this is not working with opaque shaders. Even if I set the Render Queue to something like 2100 (Geometry+100) I am still unable to get the scene depth. When I set the Queue to 3000 (Transparent) I can get the scene depth but I also get a sort of shadow that appears for objects in the back.

To show you what I mean, here is a render queue of 2000:

Here is using the same shader with render queue 3000:

And for reference here is the shader I am using:

It may be hard to notice the shadows in the above pictures so here is how it looks with a shadergraph of only the PBR Master node and no inputs:

Might anyone be able to explain why this may be happening? Can I only access the scene depth in the transparent queue? Is there a way around this? If not, can anybody explain why these shadows are appearing?

it could be by design that depth reads only opaque textures… on transparent shaders…

check this link it has more insight: Scene Color & Depth Nodes – Cyan

Thanks, but I am not sure what you mean by that. According to that blog post, depth values are stored in _CameraDepthTexture and can be accessed via the scene depth node. Cyan suggests using transparent shaders to not write to the depth buffer but in theory, I would assume this can be accessed via both transparent and opaque shaders.

With a opaque shader / rendering queue, I can’t access depth values.
With a transparent shader / rendering queue, I get that strange “see-through” shadow artifact even with a plain PBR material for the floor.

I still don’t know what’s going on but when I disable “Cast Shadows” on the floor’s Mesh Renderer, I get this instead:
5165108--512354--upload_2019-11-11_22-23-17.png

i have same matter, assuming you are using LWRP or URP… in frame debugger (if i remember correctly) there is a frame that says write depth or something… this happens after opaque rendering… i tried before you many times with shader graph, and depth node always work on transparent shaders reading the depth of opaque shaders only…

its like this>>
render opaque shaders (no depth data available) → write depth → render transparent shaders (depth node has data!)

that’s why i said it could be by design, if it’s not , then its a bug…

the other things you are asking about regarding how your shaders look, is because of the way you are handling the depth node it self… for what you are using the depth node for??? why are you multiplying depth with camera far clip??

1 Like

I get it now @mangax , that makes sense. I can’t access the depth shader for opaque materials because they are rendered before the full depth texture is complete. And because of how rendering opaque objects works, I wouldn’t want to since objects that are in front may not have been rendered yet.

Also to answer your question, I multiplied the depth with far clip space to increase the range of the depth effect I guess. But this is the same as setting the sampling of the Scene Depth node to “Eye”.

I saw in this thread: ( https://discussions.unity.com/t/736653 ) that the issue I am having with transparent and shadows is because shadow cascades were enabled. So after disabling, everything looks fine for the in the transparent render queue.

@Jonathan_L its not impossible to find away to get depth node working on opaque shader…

in shader graph you can set shader as opaque (so you don’t get see through artifacts), but for render queue you can set it as 2900 (just before other transparent shaders) this way you shader will be postponed to be rendered along side transparent shaders… then your depth node would work in your opaque shader!

there are two issues on this… one could be solved…

  1. it’s an opaque shader, so if you want to have a fading effect its not possible… to solve this… you can apply the fading on the colors themselves using the scene color node, which contains the colors from opaque shaders… in away this gives the illusion of fading effect, but it would work well on Unlit master node, since you have full control over colors… PBR master node apply some extra ambient effects which appear on top of the fading color effect…

  2. since it’s on transparent render stage, other transparent shaders would not be able to detect it’s depth… so if you have a water shader with depth effects, it won’t work well with this shader …

to be explored
there is also the potential usage of post-processing effects/shaders… new unity scriptable pipeline allows you to add effect on top of all other shaders after being rendered… you can set it to be applied on any gameobject layer, which is very interesting!.. i haven’t explored it yet in depth, but there is huge potential for many effects and things…

1 Like