# Trouble with ZWrite

**URL:** https://discussions.unity.com/t/trouble-with-zwrite/490774
**Category:** Shaders & Materials
**Tags:** Shaders
**Created:** [November 20, 2012, 11:00am UTC](https://discussions.unity.com/t/trouble-with-zwrite/490774 "2012-11-20T11:00:18Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![MikeyMyk](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@MikeyMyk](https://discussions.unity.com/u/MikeyMyk)
#### Post date: [November 20, 2012, 11:00am UTC](https://discussions.unity.com/t/trouble-with-zwrite/490774/1 "2012-11-20T11:00:18Z")

</div>

Hi,

I’m trying to create a simple shader that draws its geometry on top of everything else. Here’s where I am.

```auto
Shader "Custom/Unlit ZtestAlways" {
	Properties {
		_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
	}
	SubShader {
		Tags { "Queue"="Overlay" "IgnoreProjector"="True" "RenderType"="Transparent"}
		LOD 200
		ZTest Always
		
		CGPROGRAM
		#pragma surface surf Lambert

		sampler2D _MainTex;

		struct Input {
			float2 uv_MainTex;
		};

		void surf (Input IN, inout SurfaceOutput o) {
			half4 c = tex2D (_MainTex, IN.uv_MainTex);
			o.Albedo = c.rgb;
			o.Alpha = c.a;
		}
		ENDCG
	} 
	FallBack "Diffuse"
}

```

I have it in the overlay queue, so the rest of the scene (terrain) should be rendered already, I would have though. ZTest is set to Always. The geometry using this shader still gets obscured by the landscape. Note that i’ve not put any Alpha blending in yet as I am just testing the ztest.

Must be something dead obvious, does anyone have any thoughts?

Thanks,

/Mike

---

<div class="post-metadata">

### Author: ![Farfarer](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/farfarer/32/378541_2.png) [@Farfarer](https://discussions.unity.com/u/Farfarer)
#### Post date: [November 20, 2012, 11:43am UTC](https://discussions.unity.com/t/trouble-with-zwrite/490774/2 "2012-11-20T11:43:06Z")

</div>

Surely you want ZTest Off? Otherwise it will ZTest it and then occlude your geo by what’s already in the ZBuffer?

---

<div class="post-metadata">

### Author: ![MikeyMyk](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@MikeyMyk](https://discussions.unity.com/u/MikeyMyk)
#### Post date: [November 20, 2012, 11:46am UTC](https://discussions.unity.com/t/trouble-with-zwrite/490774/3 "2012-11-20T11:46:24Z")

</div>

Hehe, yes, you are correct - I was thinking that “Always” always passed the test.

Thanks:)

---

<div class="post-metadata">

### Author: ![Jessy](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/jessy/32/465975_2.png) [@Jessy](https://discussions.unity.com/u/Jessy)
#### Post date: [November 20, 2012, 5:07pm UTC](https://discussions.unity.com/t/trouble-with-zwrite/490774/4 "2012-11-20T17:07:09Z")

</div>

> [@Farfarer](#):
>
> Surely you want ZTest Off?

That doesn’t exist.

> [@MikeyMyk](#):
>
> Hehe, yes, you are correct - I was thinking that “Always” always passed the test.

No. Always does always pass the test.

Your shader is not “unlit”. I can’t tell you why it’s failing, unless the landscape is also in the overlay queue and this mesh is behind the landscape.

---

<div class="post-metadata">

### Author: ![Farfarer](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/farfarer/32/378541_2.png) [@Farfarer](https://discussions.unity.com/u/Farfarer)
#### Post date: [November 20, 2012, 5:12pm UTC](https://discussions.unity.com/t/trouble-with-zwrite/490774/5 "2012-11-20T17:12:09Z")

</div>

Ah, my bad 😛
