I can’t view the depth of objects no matter what I try, they just appear black.
I’ve been grabbing code from forums to access depth data, both via camera render targets and material shaders, including this code directly from the manual
Shader "Render Depth 1" {
SubShader{
Tags { "RenderType" = "Opaque" }
Pass {
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 = UnityObjectToClipPos(v.vertex);
UNITY_TRANSFER_DEPTH(o.depth);
return o;
}
half4 frag(v2f i) : SV_Target {
//UNITY_OUTPUT_DEPTH(i.depth)*10000000;
half d = i.depth.x / i.depth.y;
return half4(d * 10, d * 10, d * 10, 1);
}
ENDCG
}
}
}
It’s always just black, even messing with camera render path settings, or mainCamera.depthTextureMode = DepthTextureMode.Depth;
, or multiplying in case the values are just dark.