GetDepthTexture.shader 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // jave.lin 2020.03.09
  2. Shader "Custom/GetDepthTexture" {
  3. Properties
  4. {
  5. _MainTex("Texture", 2D) = "white" {}
  6. //_ExampleName("Example vector", Vector) = (0.0, 0.0, 0.0, 0.0)
  7. }
  8. SubShader{
  9. Cull Off ZWrite Off ZTest Always
  10. Pass {
  11. CGPROGRAM
  12. #pragma vertex vert
  13. #pragma fragment frag
  14. #include "UnityCG.cginc"
  15. struct appdata {
  16. float4 vertex : POSITION;
  17. float2 uv : TEXCOORD0;
  18. };
  19. struct v2f {
  20. float2 uv : TEXCOORD0;
  21. float4 vertex : SV_POSITION;
  22. };
  23. float3 _ExampleName;
  24. sampler2D _CameraDepthTexture;
  25. v2f vert(appdata v) {
  26. v2f o;
  27. o.vertex = UnityObjectToClipPos(v.vertex);
  28. o.uv = v.uv;
  29. return o;
  30. }
  31. fixed4 frag(v2f i) : SV_Target{
  32. //return Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, i.uv));
  33. // return LinearEyeDepth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, i.uv));
  34. return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, i.uv);
  35. }
  36. ENDCG
  37. }
  38. }
  39. }