Disable Z?

I want to draw a simple object (lets say, a cube) with relation to camera transformations that disregards the z buffer.

Putting it simply, I can use the DrawCube gizmo to draw a cube under my terrain, and still see it. I basically want to replicate this functionality, but I don’t see a way to do it. (outside of doing the entire thing manually using GL calls attached to the camera with Unity pro, and that seems pretty heavy handed to me)

Is there a way I could just disable the z buffer to allow me to draw ‘far’ objects, or objects below my terrain/objects and have them appear above?

Any advice would be well appreciated.

Modify whatever shader you’re using to include “Ztest always”.

–Eric

1 Like

of course! Right on, thanks man. I keep forgetting that Unity uses shaders for everything, including diffuse textures.

In an effort to keep this answer as complete as possible for the next person, here is what my simple diffuse pass through shader w/ z disabled looks like:

Shader "SelectorZ"
{
	Properties
	{
		_MainTex ("Base (RGB)", 2D) = "white" {}
	}
	
	SubShader
	{
		Tags { "RenderType"="Opaque" }
		Ztest always
		LOD 200
		
		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"
}

how do you render A after B but before C, and B+C are rendered together (with correct z) ?

1 Like