Hi,
I could use some help with a shadow+transparency related problem.
I’m working on a water shader graph with the universal render pipeline in unity 2019.3.0b3.
Since I wan’t the water to be partly transparent I have set the surface property of the PBR Master to transparent.
This however seems to disable zwrite for the water layer (in my case a sphere).
Is there a way I can enable zwrite, but still have the transparency? Or is there a way to render the water layer after the shadows?
At least not yet when using the LWRP / URP. Your shader can be Opaque and ZWrite, or Transparent and not have ZWrite. There’s no way to directly control the render state to choose something like opaque w/o zwrite or transparent w/ zwrite.
However it looks like they’ve added this to some versions of the HDRP, so I suspect this will come to the URP at some point in the future.
That said I don’t think what you’re seeing isn’t shadows, it’s SSAO. The ZWrite being on or off is a red herring. Changing between opaque and transparent does a couple other things on top of setting the blend mode and zwrite. Mainly it also sets the render queue, which in turn enables and disables the rendering of the depth only pass for the camera depth texture depending on if it’s in the opaque or transparent queue range. That depth texture is what the SSAO (and the directional shadows) use. You might get better results by modifying the queue on your material manually to be 2499 (which is at the end of the opaque queue, before the transparent queue).
I can’t tell you for sure what the problem or the fix is. I haven’t kept up with the URP lately to know where things stand there. But to me it looks like the SSAO is being applied after the water has been rendered, which to me suggests there’s a bug with the URP and it’s applying the SSAO after the transparent queue rather than before. I know there’s also been a long time bug (several months now) in which transparent lit Shader Graph shaders aren’t properly handling shadow receiving and the shadows appear transparent on them. This is also a bug that Unity needs to fix.
Yes, it looks like SSAO, but I can’t find any setting for SSAO and switch form soft shadows to hard shadows makes it look like actual old-school hard shadows. Is there some default for SSAO in the URP?
Changing the order in the queue did not fix it - it’s easier no underwater scene at all or the shadow-transparency problem.
Guess I will just have to wait and hope this get’s fixed.
Thanks for the hint to on the shader graph subforum - I somehow managed to not find it.
Ah. If it really is shadows, then it’s a long time bug with lit transparency. I’m not sure there’s a fix for that still. But basically transparent objects are reading from the opaque screen space shadows instead of sampling the shadow maps directly (which they used to in some early versions of the LWRP) or not showing shadows at all (which is what the built in rendering paths do).
It might be fixable if you turn off screen space shadows, but I don’t know where that option is, if it exists at all, for the LWRP/URP.
In the pipeline asset, set Shadows > Cascades to “No Cascades”. That’ll disable screen space shadows, but also mean shadows look worse in general. It does mean the water & transparencies will properly receive shadows though.
Otherwise the same issue appears with the built-in LWRP/Lit shader, and is still broken in the latest URP. This is on Unity to fix as it’s been broken for over a year now.
Yeah. I should have specified, this is broken and unfixable by users when using Shader Graph straight. It’s totally, and somewhat trivially, solvable by modifying the generated shader. That’s nice because this was much more difficult for the built in rendering paths, but frustrating because it is so “easy” it’s weird they’ve left it broken for a year…
a way to at least get rid of the false shadows might be writing a custom shader gui where you disable the keyword _MAIN_LIGHT_SHADOWS – i haven’t tested it tho.
@boglus YES, that helped. Thanks for letting me know.
Is there a bug/issue report for this problem? I had a look into the issue tracker but could not find it.
Also thanks a lot for pointing out the advanced workaround. We are currently porting our game, so I need to go with the quick fixes for now, but will surely come back later!
I’ve also been playing around with transparent water receiving shadows. The suggestion to turn off shadow cascades was a good one—especially with soft shadows enabled, it doesn’t look bad at all.
However, I’m struggling to get depth effects (shoreline foam) going with the Universal Render pipeline. I made a separate post for it (would appreciate any ideas/answers, as I haven’t gotten any :)), but basically my water plane appears to be writing to the depth texture, which results in the “foam” rendering across the entire plane, not just in areas close to an intersection with another object.
My understanding is that transparent objects shouldn’t be writing to the depth texture, so I’m assuming I screwed something up while attempting to convert my built-in RP shader to work with URP.
An AR transparent shadow receiver is a bit different than a shadow receiving transparency. The former doesn’t require the later to exist (though it does make it a little easier). And having shadow receiving transparency, which is what URP 7.2.0 should have working, does not mean there’ll be an out of the box solution for the AR case either as they’re quite different in actual usage.
There are a ton of examples of different transparent shadow receivers, from alpha tested ones with solid opaque colored shadows, to semi transparent ones that require careful manipulation of when it and the AR projection gets rendered. And these all work with the built in forward rendering path which does not have support for shadow receiving transparency. Most of them should be possible to recreate in the current URP, but will need hand written custom shaders. I’m not sure any of them are possible with Shader Graph, and I’ve not seen anyone release one yet either. Doesn’t mean someone hasn’t, I just haven’t seen one.
Well, it does not (7.2.1), neither in 7.1.8. I can have a transparent plane that is receiving shadows, however, the shadow intensity follows the alpha value. If I create a completely transparent ground plane just to receive shadows, setting alpha to zero also means the shadow disappears.
Well, I have spent 2 days looking after a working one with no luck at all, this thread was the closeset to the topic. Anyways, thank you for the insight guys!