Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. Shader "Unlit/ScreenDepth"
  2. {
  3. SubShader
  4. {
  5. Pass
  6.     {
  7.     CGPROGRAM
  8.     #pragma vertex vert
  9.     #pragma fragment frag
  10.     #include "UnityCG.cginc"
  11.    
  12.     sampler2D _CameraDepthTexture;
  13.    
  14.     struct v2f {
  15.         float4 pos : SV_POSITION;
  16.         float4 scrPos : TEXCOORD1;
  17.     };
  18.    
  19.     v2f vert (appdata_base v)
  20.     {
  21.         v2f o;
  22.         o.pos = UnityObjectToClipPos (v.vertex);
  23.         o.scrPos = ComputeScreenPos(o.pos);
  24.                
  25.         o.scrPos.z = COMPUTE_DEPTH_01;
  26.        
  27.         #if defined (UNITY_UV_STARTS_AT_TOP)
  28.         // For DirectX-like systems flip vertical
  29.         //o.scrPos.y = 1 – o.scrPos.y;
  30.         #else
  31.         // For OpenGL-like systems do nothing
  32.         #endif
  33.         return o;
  34.     }
  35.        
  36.     float4 frag (v2f i) : COLOR
  37.     {
  38.         float depthValue = Linear01Depth (tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.scrPos)).r);
  39.         depthValue = i.scrPos.z;
  40.         //depthValue *= 10;
  41.         return float4( depthValue, depthValue, depthValue, 1 );
  42.     }
  43.    
  44.     ENDCG
  45.     }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement