I wanna to compare two ZDepth,one is rendered into a renderTexture,another is compute in Shader,the porblem is the previous rendered ZDepth texture seems dont have enough Accurate ,so is result like this:
It shouldnt be,I wanna something like this:
here is the shader code to render ZDepth to a texture:
SubShader {
Tags { "RenderType"="Opaque" }
Pass {
Fog { Mode Off }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 depth : TEXCOORD0;
};
v2f vert (appdata_base v) {
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.depth.xy=o.pos.zw;
return o;
}
float4 frag(v2f i) : COLOR {
float d=i.depth.x/i.depth.y;
float4 c=EncodeFloatRGBA(d);
return c;
}
ENDCG
}//endpass
}
here is the shader code to compare them in the same sapce:
SubShader {
Tags { "RenderType"="Opaque" }
pass{
//Zwrite off
//ZTest Always
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _myShadow;
float4x4 _litMVP;
struct vertOut {
float4 pos:SV_POSITION;
float4 litPos;
};
vertOut vert(appdata_base v)
{
vertOut o;
o.pos=mul(UNITY_MATRIX_MVP,v.vertex);
float4 wVertex=mul(_Object2World ,v.vertex);
o.litPos=mul(_litMVP,wVertex);
return o;
}
float4 frag(vertOut i):COLOR
{
float2 shadowTexc=0.5*i.litPos.xy/i.litPos.w+float2(0.5,0.5);
float litZ=i.litPos.z/i.litPos.w;
float4 c=tex2D(_myShadow,shadowTexc);
float t=DecodeFloatRGBA(c);
if(litZ>t)
return 0.3;
else
return 0.7;
}
ENDCG
}//endpass
}
what can i improve to access enough Accurate ZDepth

