I wanted holes in my terrain, so I modified the terrain shader (firstpass shader) to allow this, I simply made 1 of the splats be used for clipping. Then I added a ShadowCaster subshader so it would render shadows correctly (I do the same clipping there).
It all seemed to work, until I used screen space ambient occlusion or obscurance, these effects behave as if the terrain is still completely opaque (no holes).
So it seems to me as if the depthbuffer or normalbuffer is somehow incorrect, which I find strange as everything (apart from these post effects) is all still correctly rendered.
I’m using deferred in Unity5
any ideas?
//added this in the surface shader
clip (0.2-splat_control.a);
//added this at the end to get correct shadows:
SubShader
{
// Pass to render object as a shadow caster
Pass
{
Name "ShadowCaster"
Tags { "LightMode" = "ShadowCaster" }
Fog {Mode Off}
ZWrite On ZTest LEqual //Cull Off
//Offset 1, 1
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_shadowcaster
#include "UnityCG.cginc"
struct v2f
{
V2F_SHADOW_CASTER;
float2 tc_Control : TEXCOORD4;
};
sampler2D _Control;
float4 _Control_ST;
v2f vert( appdata_base v )
{
v2f o;
o.tc_Control = TRANSFORM_TEX(v.texcoord, _Control);
TRANSFER_SHADOW_CASTER(o)
return o;
}
float4 frag( v2f i ) : COLOR
{
half4 splat_control = tex2D(_Control, i.tc_Control);
clip (0.2-splat_control.a);
SHADOW_CASTER_FRAGMENT(i)
}
ENDCG
}
}