# Understanding ZWrite.

**URL:** https://discussions.unity.com/t/understanding-zwrite/874884
**Category:** Shaders & Materials
**Tags:** Shaders, Question
**Created:** [March 15, 2022, 10:57am UTC](https://discussions.unity.com/t/understanding-zwrite/874884 "2022-03-15T10:57:13Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![bgolus](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/bgolus/32/391570_2.png) [@bgolus](https://discussions.unity.com/u/bgolus)
#### Post date: [March 15, 2022, 10:17pm UTC](https://discussions.unity.com/t/understanding-zwrite/874884/2 "2022-03-15T22:17:26Z")

</div>

`ZWrite` controls if an object _writes_ to the depth buffer, not if it tests against it, which is what `ZTest` does. Testing against the depth buffer will cause pixels that fail the test to not be rendered, and thus appear occluded by that surface. Transparent materials still usually have `ZTest LEqual` enabled (that is the default if it’s not specified), meaning any opaque objects that have already rendered and _did_ write to the depth buffer can be used by the transparent materials to depth test against.

The depth buffer, along with depth testing, exist to ensure opaque objects sort correctly regardless of the order they render in. The reason transparent objects don’t (usually) render to the depth is because the depth buffer can only be used to ensure opaque surfaces are rendered correctly since there’s only one color & depth stored per pixel, you can only really choose to reject or _replace_ the current pixel’s color & depth, or blend on top of the existing color. If two transparent surfaces render out of order there’s no way to “place” a surface “behind” one that’s already been rendered without knowing the color of that previously rendered transparent surface. In the case of using `ZWrite On` on a transparent surface the best case scenario is the surfaces are already rendering in the correct order an `ZWrite` does absolutely nothing compared to having it off, and worst case the closer surfaces render first and cause the surface further away to get depth rejected potentially causing random “holes” in the mesh depending on the mesh’s triangle order.

---

_[View the full topic](https://discussions.unity.com/t/understanding-zwrite/874884)._
