diff options
Diffstat (limited to 'DepthBlit.shader')
| -rw-r--r-- | DepthBlit.shader | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/DepthBlit.shader b/DepthBlit.shader index 4094fe5..b2a512f 100644 --- a/DepthBlit.shader +++ b/DepthBlit.shader @@ -20,7 +20,7 @@ Shader "Hidden/yum_food/DepthBlit" #include "UnityCG.cginc" - sampler2D _DepthTex; + UNITY_DECLARE_DEPTH_TEXTURE(_DepthTex); float _Near; float _Far; @@ -41,7 +41,14 @@ Shader "Hidden/yum_food/DepthBlit" float4 frag(v2f i) : SV_Target { // 0 = near clip plane, 1 = far clip plane. - return tex2D(_DepthTex, i.uv).r; + float rawDepth = SAMPLE_DEPTH_TEXTURE(_DepthTex, i.uv); + // Unity uses reversed-Z on most platforms: 1 at near, 0 at far. + // Flip to get linear 0-1 (0=near, 1=far) for orthographic cameras. + #if defined(UNITY_REVERSED_Z) + return 1.0 - rawDepth; + #else + return rawDepth; + #endif } ENDCG } |
