Render object through terrain

Hey everyone, as I am no good at shader coding, I am compelled to turn to unity answers :smiley:
anyway, what I want is just a basic defuse shader that render behind everything except the terrain, which I want the shader to render in front of.

So if anyone could help me, ill be very greatful.

Thanks
Tz

Try this. I modified the default diffuse texture and added several tags to accomplish what you need I think. The queue order setting should cause rendering after the terrain and before any geometry, and along with the ZWrite Off tag should insure your normal geometry renders over anything with this shader. I added an Offset to help this shader render over the terrain, even when very close to the terrain surface.

Shader "DiffuseOverTerrain" {
Properties {
	_Color ("Main Color", Color) = (1,1,1,1)
	_MainTex ("Base (RGB)", 2D) = "white" {}
}

Category {
	Offset -2, -2
	ZWrite Off
	
SubShader {
	Tags { "RenderType"="Opaque" "Queue" = "Geometry-1" }
	LOD 200

CGPROGRAM
#pragma surface surf Lambert

sampler2D _MainTex;
fixed4 _Color;

struct Input {
	float2 uv_MainTex;
};

void surf (Input IN, inout SurfaceOutput o) {
	fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
	o.Albedo = c.rgb;
	o.Alpha = c.a;
}
ENDCG
}
}

Fallback "Diffuse"
}

Just use two cameras. One camera renders only the terrain’s layer, and the other camera renders the seen-through things. Give the cameras different depths and a ‘don’t clear’ background, and one will render on top of the other.