Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "Custom/ZBuffer"
- {
- SubShader
- {
- Tags { "RenderType"="Opaque" }
- Pass
- {
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #include "UnityCG.cginc"
- struct v2f
- {
- float4 pos : SV_POSITION;
- float4 screenuv : TEXCOORD1;
- };
- v2f vert (appdata_base v)
- {
- v2f o;
- o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
- o.screenuv = ComputeScreenPos(o.pos);
- return o;
- }
- sampler2D _CameraDepthTexture;
- fixed4 frag (v2f i) : SV_Target
- {
- float2 uv = i.screenuv.xy / i.screenuv.w;
- float depth = 1 - Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv));
- return fixed4(depth, depth, depth, 1);
- }
- ENDCG
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement