URP, Depth write, z-write, consistent problem of semitransparent objects

So, I have tried in so many ways to solve problems for semi transparent shaders, normally everything was solved in Standard by creating a copy of this shader with Zwrite on… simple as that. It would be nice if Unity team just creates a version of a shader called - Semitransparent UPR lit, that let us create instead of wasting time to find out a solution, or some tutorial, wich I would be so *** happy to do it myself.

I get it… technically is not cheap, but sometimes you need to do some fade in fade out at your company, like we needed to do on some Augmented reality… there we “solved” it by writing on Z, still on 2019.3

A lot of time to understand how Render queue works

I am an artist and I’ve been trying to solve some of this technical art issues for some time, but everything points to this document…

"Shader … Shader “Transparent/Diffuse ZWrite” { Properties { " at the link

Question:

Is this suppossed to work in URP? Because it is not… we are at this point where we think shaders are kind of black magic… and I guess that is why you created ShaderGraph… but still. I need a consistent solution, and I have been working with Unity everyday, since five years now…

We are trying to make an addressable of objects of a small scene, but with water, and this water does not work, of course. So I need to figure out what is going on, why it does not work, why… it does not work when I am calling the addressable but then when I open the material, it magically pops and start to work well. I guess thats a BUG

Please HELP!

I promise I would make a video explaining this… if its really sorted out. It would save me time to explain to the rest of artist who work with me why the hedgehog happens.

When you switch to Debug mode, ZWrite can be set to 1 on Lit shader. This setting should definitely be added to Universal.ShaderGUI.LitShader.

3 Likes

This shader will solve your transparent Zwrite problem for at least URP / Lit.

Edit : Unity 2020.1 URP 8.2 Lit shader.

6167375–674717–ZWriteLit.shader (9.38 KB)

9 Likes

Yes! Thats what we did last time on a project to solve it, I managed to tell my team about it, but then, something strange happenned, like, each time we clicked on the material it popped back into Zwrite = 0 so I guess it was a bug on the Unity version we were working with.

This shader solves it! Exactly what I was looking for. I wish I knew a bit more about shaders, I was the whole weekend trying to understand Unity shaders, I found a video, but when I looked on URP shaders and it looked far too more complicated than the previous pipeline. Ill check how it’s done comparing to the URP template

Thank you Aydin! Thank you so much! you rule!

1 Like

Glad I could help :slight_smile:
actually it would be better to add _ZWrite setting to the shader Editor. At the moment, more shaders will be compiled.

My changes to the URP / Lit Shader
Replacing “ZWrite [_ZWrite]” in line 74 with “ZWrite On”.
Line 121 #include “Packages / com.unity.render-pipelines.universal / Shaders / LitInput.hlsl”
Line 122 #include “Packages / com.unity.render-pipelines.universal / Shaders / LitForwardPass.hlsl”

4 Likes

Aydin you’re a legend, thank you

Thanks for sharing. Tried it on URP 12 but get this error:

Shader error in 'Universal Render Pipeline/ZWriteLit': 'UniversalFragmentMeta': input parameter 'metaInput' missing semantics at /Users/Romaha/Documents/Projects/2021/CatoScience/Library/PackageCache/com.unity.render-pipelines.universal@12.1.3/ShaderLibrary/UniversalMetaPass.hlsl(37) (on metal)
Compiling Fragment program
Platform defines: SHADER_API_MOBILE UNITY_ENABLE_REFLECTION_BUFFERS UNITY_LIGHTMAP_DLDR_ENCODING UNITY_NO_DXT5nm UNITY_NO_RGBM UNITY_NO_SCREENSPACE_SHADOWS UNITY_PASS_META UNITY_PBS_USE_BRDF2
Disabled keywords: SHADER_API_GLES30 UNITY_ASTC_NORMALMAP_ENCODING UNITY_COLORSPACE_GAMMA UNITY_ENABLE_DETAIL_NORMALMAP UNITY_ENABLE_NATIVE_SHADOW_LOOKUPS UNITY_FRAMEBUFFER_FETCH_AVAILABLE UNITY_HALF_PRECISION_FRAGMENT_SHADER_REGISTERS UNITY_HARDWARE_TIER1 UNITY_HARDWARE_TIER2 UNITY_HARDWARE_TIER3 UNITY_LIGHTMAP_FULL_HDR UNITY_LIGHTMAP_RGBM_ENCODING UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_METAL_SHADOWS_USE_POINT_FILTERING UNITY_NO_FULL_STANDARD_SHADER UNITY_PBS_USE_BRDF1 UNITY_PBS_USE_BRDF3 UNITY_PRETRANSFORM_TO_DISPLAY_ORIENTATION UNITY_SPECCUBE_BLENDING UNITY_SPECCUBE_BOX_PROJECTION UNITY_UNIFIED_SHADER_PRECISION_MODEL UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_VIRTUAL_TEXTURING _ALPHATEST_ON _EMISSION _METALLICSPECGLOSSMAP _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A _SPECGLOSSMAP _SPECULAR_SETUP

Is there a way to solver it?

1 Like

I don’t remember if it was added in URP 12. Added option to force depth write of shaders generated in shader graph.

7842258--994221--upload_2022-1-26_14-39-22.png

2 Likes

Added option to where? Initially you shared the shader, not shader graph. We can’t use it and adjust to URP 12 in Shader Graph editor as you show in this reply

It’s added to shader graph but in debug mode if you changed 0 to 1 in my unity (2022.2.15) turns back to 0

1 Like

Same here. Does anyone have any idea why?