I’m using frag shader for show depth texture and it works. When I,m trying do the same in the surface shader I’m seeing black screen. Why?))
void OnRenderImage(RenderTexture src, RenderTexture dest)
{
Material mat = Resources.Load("materials/TestBuffer", typeof(Material)) as Material;
Graphics.Blit(src, dest, mat);
}
working shader
Shader "Custom/ZBufTest" {
SubShader{
Tags{ "RenderType" = "Opaque" }
Pass{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _CameraDepthTexture;
struct v2f {
float4 pos : SV_POSITION;
float4 scrPos:TEXCOORD1;
};
v2f vert(appdata_base v) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.scrPos = ComputeScreenPos(o.pos);
return o;
}
half4 frag(v2f i) : COLOR
{
float depthValue = Linear01Depth(tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.scrPos)).r);
depth.r = depthValue;
depth.g = depthValue;
depth.b = depthValue;
depth.a = 1;
return depth;
}
ENDCG
}
}
FallBack "Diffuse"
}
notworking shader
Shader "Custom/ZBufTest"
{
Properties
{
}
SubShader
{
CGPROGRAM
#include "UnityCG.cginc"
#pragma surface surf Lambert vertex:vert alpha addshadow
#pragma target 3.0
sampler2D _CameraDepthTexture;
struct Input
{
float2 uv_MainTex;
float4 screenPos;
float eyeDepth;
};
void vert(inout appdata_full v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input, o);
float4 vpos = mul(UNITY_MATRIX_MVP, v.vertex);
o.screenPos = ComputeScreenPos(vpos);
}
void surf (Input IN, inout SurfaceOutput o)
{
float depthValue = Linear01Depth(tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(IN.screenPos)).r);
half4 depth;
depth.r = depthValue;
depth.g = depthValue;
depth.b = depthValue;
depth.a = 1;
o.Albedo = depth;
}
ENDCG
}
FallBack "Diffuse"
}