DenseSpatialMapDepth.shader 1.48 KB
Newer Older
BlackAngle233's avatar
BlackAngle233 committed
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
//================================================================================================================================
//
//  Copyright (c) 2015-2021 VisionStar Information Technology (Shanghai) Co., Ltd. All Rights Reserved.
//  EasyAR is the registered trademark or trademark of VisionStar Information Technology (Shanghai) Co., Ltd in China
//  and other countries for the augmented reality technology developed by VisionStar Information Technology (Shanghai) Co., Ltd.
//
//================================================================================================================================

Shader "EasyAR/DenseSpatialMapDepth" {

    SubShader
    {
        Tags { "Tag" = "DenseSpatialMap" }

        Pass {

            CGPROGRAM

            #pragma vertex vert
            #pragma fragment frag
            #include "UnityCG.cginc"

            struct v2f
            {
                float4 pos : SV_POSITION;
                float4 depthPos : TEXCOORD0;
            };

           v2f vert(appdata_base v)
            {
                v2f o;
                o.depthPos.xyz = UnityObjectToViewPos(v.vertex);
                o.depthPos.w = 1.0;
                o.pos = mul(UNITY_MATRIX_P, o.depthPos);
                return o;
            }

            float4 frag(v2f i) : SV_Target {
                float depth = length(i.depthPos.xyz);
                depth = depth * 0.000001;
                return EncodeFloatRGBA(depth);
            }
            ENDCG
        }
    }
}