diff options
Diffstat (limited to 'DepthBlit.shader')
| -rw-r--r-- | DepthBlit.shader | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/DepthBlit.shader b/DepthBlit.shader new file mode 100644 index 0000000..04187c2 --- /dev/null +++ b/DepthBlit.shader @@ -0,0 +1,52 @@ +Shader "Hidden/yum_food/DepthBlit" +{ + // Reads from depth texture and outputs linearized depth to color + Properties + { + _MainTex ("", 2D) = "white" {} + } + + SubShader + { + Cull Off ZWrite Off ZTest Always + + Pass + { + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + + #include "UnityCG.cginc" + + sampler2D _DepthTex; + + struct v2f + { + float4 pos : SV_POSITION; + float2 uv : TEXCOORD0; + }; + + v2f vert(float4 vertex : POSITION, float2 uv : TEXCOORD0) + { + v2f o; + o.pos = UnityObjectToClipPos(vertex); + o.uv = uv; + return o; + } + + float4 frag(v2f i) : SV_Target + { + float rawDepth = tex2D(_DepthTex, i.uv).r; + + // Orthographic depth is already linear. + // We just need to handle the platform-specific Z-buffer direction. + #if defined(UNITY_REVERSED_Z) + return 1.0 - rawDepth; + #else + return rawDepth; + #endif + } + ENDCG + } + } +} |
