Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "Unlit/ScreenDepth"
- {
- SubShader
- {
- Pass
- {
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #include "UnityCG.cginc"
- sampler2D _CameraDepthTexture;
- struct v2f {
- float4 pos : SV_POSITION;
- float4 scrPos : TEXCOORD1;
- };
- v2f vert (appdata_base v)
- {
- v2f o;
- o.pos = UnityObjectToClipPos (v.vertex);
- o.scrPos = ComputeScreenPos(o.pos);
- o.scrPos.z = COMPUTE_DEPTH_01;
- #if defined (UNITY_UV_STARTS_AT_TOP)
- // For DirectX-like systems flip vertical
- //o.scrPos.y = 1 – o.scrPos.y;
- #else
- // For OpenGL-like systems do nothing
- #endif
- return o;
- }
- float4 frag (v2f i) : COLOR
- {
- float depthValue = Linear01Depth (tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.scrPos)).r);
- depthValue = i.scrPos.z;
- //depthValue *= 10;
- return float4( depthValue, depthValue, depthValue, 1 );
- }
- ENDCG
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement