summaryrefslogtreecommitdiffstats
path: root/DepthBlit.shader
blob: 04187c2eeafb49ff893f82b1c18d8cc79457fcff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
        }
    }
}