URP deferred rendering: can I force ZWrite On for transparent render queue?
I'm rendering a spherical ocean with various other geometry around, a terrain and some objects. I've implemented the ocean rendering using three materials, each with a Shader Graph shader I've authored, as follows.
The OceanSurfaceUnderside is in queue 2900, is semi-transparent, and provides the appearance of the underside of the water.
The OceanVolume is in queue 2901, is semi-transparent, and provides a simple fog based on the depth buffer (for the actual target of each pixel's viewline) but primarily using the known geometry of the spherical ocean to determine the underwater path length and thereby the fog density.
The OceanSurfaceTopside is in queue 2902, is semi-transparent, and provides the appearance of the topside of the water.
These three elements work nicely together, and I'm happy with them. Yay. It's required that the volume shader is interleaved, in its render order, between the other two - that's intrinsic to the function, and a consequence of the spherical ocean.
Now, I also apply fog to the whole thing using the Lighting dialog (so, I guess, a post-processing step). This keys off the depth buffer. Trouble is, my materials at 2900-2902 are not writing the depth buffer, so they don't get fogged correctly.
So, I thought, I'd change "Depth Write" to "Force Enabled" in each of the two surface shaders. That way, I'd have the depth buffer set correctly, and fog would work. But changing this setting does nothing.
After much searching, I saw a hint that render queue value might matter too, and I moved these three materials to 2490-2492. Voila, the fog now renders correctly, if I disable the volume shader. But, it appears that the interposed OceanVolume material also writes the z-buffer now, even though I have set its "Depth Write" to "Force Disabled", and that screws up more than just the fog.
So, my question is, is it possible - in URP, using deferred rendering, Unity 2021.2 - to have materials at queue <= 2500 not write Z, and/or materials at queue > 2500 that do write Z? Because on this evidence, it seems not, but I can't find any documentation to this effect.
Whilst searching, I've noted that the documentation seems pretty sparse around render queues, render order, and how they play out on different configurations. Am I missing something? Many posts talk about "the render queues" and specify the known ones such as 2000, 2450, etc, and a few posts mention going +1 or -1 to force the rendering order. Does this force the rendering order? Are all operations of a shader in queue 2900 always performed before any operations of a shader in queue 2901? Because my volume shader seems to - I'm far from sure - write the z-buffer before my first shader, OceanSurfaceUnderside, writes anything. I don't know how to debug this, so I'd much appreciate a steer towards the documentation, or debug tools, I might be searching for. More generally, where do I look for an understanding of what gets done in what order, specifically in the URP but I guess in Unity more generally. Like, when does the fog in the Lighting dialog get computed? Where would I look to find that out?
With thanks for any help.
Your answer
![](https://koobas.hobune.stream/wayback/20220613050818im_/https://answers.unity.com/themes/thub/images/avi.jpg)