daily pastebin goal
74%
SHARE
TWEET

Demo 50 - Grayscale depending ZBuffer

tonynogo Jul 6th, 2017 2,138 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/ZBuffer"
  2. {
  3.     SubShader
  4.     {
  5.         Tags { "RenderType"="Opaque" }
  6.        
  7.         Pass
  8.         {
  9.             CGPROGRAM
  10.             #pragma vertex vert
  11.             #pragma fragment frag
  12.             #include "UnityCG.cginc"
  13.  
  14.             struct v2f
  15.             {
  16.                 float4 pos : SV_POSITION;
  17.                 float4 screenuv : TEXCOORD1;
  18.             };
  19.            
  20.             v2f vert (appdata_base v)
  21.             {
  22.                 v2f o;
  23.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
  24.                 o.screenuv = ComputeScreenPos(o.pos);
  25.                 return o;
  26.             }
  27.            
  28.             sampler2D _CameraDepthTexture;
  29.  
  30.             fixed4 frag (v2f i) : SV_Target
  31.             {
  32.                 float2 uv = i.screenuv.xy / i.screenuv.w;
  33.                 float depth = 1 - Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv));
  34.                 return fixed4(depth, depth, depth, 1);
  35.             }
  36.             ENDCG
  37.         }
  38.     }
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top