How can I access the camera depth texture in an image effect shader? I’ve tried setting up my image effect script like so:
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
public class ImageEffect : ImageEffectBase
{
protected override void Start()
{
base.Start();
camera.depthTextureMode |= DepthTextureMode.DepthNormals;
}
void OnRenderImage(RenderTexture source, RenderTexture destination)
{
Graphics.Blit(source, destination, material);
}
}
And my shader code:
Shader "Custom/DepthNormal" {
Properties {
_MainTex ("Render Input", 2D) = "white" {}
}
SubShader {
ZTest Always Cull Off ZWrite Off Fog { Mode Off }
Pass
{
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
sampler2D _CameraDepthNormalTexture;
float4 frag(v2f_img IN) : COLOR
{
half4 depthNormal = tex2D(_CameraDepthNormalTexture, IN.uv.xy);
float depth = DecodeFloatRG(depthNormal.zw);
return half4(depth, depth, depth, 1);
}
ENDCG
}
}
}
I’ve set the camera to use deferred rendering but I’m not getting any output on my screen, just a blank grey image. Am I setting up the camera depth texture wrongly?