+1

"Write to Depth buffer" unchecks itself when Opacity is set.

Clement 7 years ago 0

Hi,
First, thanks for the great tool, we are having a blast experimenting with it.
I have noticed a behavior in ShaderForge that I don't understand. When my shader is alpha blended and I set the opacity, the "Write to Depth Buffer" option unchecks itself when reopening the shader.


Steps to reproduce:

1. Create a new "Lit (Basic)" shader.

2. Add a Slider node, set it to 1 by default and connect it to the "Opacity" output.

3. Fix the console warning about the opacity by setting the Blend mode to Alpha Blended.

// Notice that if your geometry is concave, some faces that should be hidden are visible. My guess is because by default we are not writing to the Depth buffer so the front triangles don't hide the back ones.

4. Uncheck "Autosort" and check "Write to Depth buffer". Notice that now all is nice whether the opacity is set to 1 or 0.

5. This is where the issue happen. In the Unity inspector, select your shader and click "Open shader in Shader Forge". The shader recompiles but the "Write to Depth Buffer" setting is now unchecked and our concave object doesn't render properly.


Image 863

Our concave object renders properly since "Write to Depth buffer" is checked. It doesn't look super accurate when there is transparency (as you can't see the inside of the object as it becomes transparent)


Image 862

This screen shot was taken right after reopening the shader in Shader Forge. Notice how "Write to Depth buffer" is automatically unchecked.

Is there a reason I am missing for forbidding to write to the depth buffer when an object is transparent? I could understand the issue if it would mean that it would hide opaque geometry behind it but doesn't the Render queue setting of "Transparent" guarantees that all opaque geometry has been rendered and that transparent geometry is rendered back to front?


Is there another way in ShaderForge to render a transparent concave object so it looks correct if the transparency is set to 0?


Thanks! :)