ConvertDepth.shader 980 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. Shader "Hidden/ConvertDepth" {
  3. Properties {
  4. _MainTex ("Base (RGB)", 2D) = "" {}
  5. }
  6. // Shader code pasted into all further CGPROGRAM blocks
  7. CGINCLUDE
  8. #include "UnityCG.cginc"
  9. struct v2f {
  10. float4 pos : POSITION;
  11. float2 uv : TEXCOORD0;
  12. };
  13. sampler2D _MainTex;
  14. sampler2D _CameraDepthTexture;
  15. v2f vert( appdata_img v )
  16. {
  17. v2f o;
  18. o.pos = UnityObjectToClipPos(v.vertex);
  19. o.uv = v.texcoord.xy;
  20. return o;
  21. }
  22. half4 frag(v2f i) : COLOR
  23. {
  24. float d = tex2D(_CameraDepthTexture, i.uv.xy);
  25. d = Linear01Depth(d);
  26. if(d>0.99999)
  27. return half4(1,1,1,1);
  28. else
  29. return EncodeFloatRGBA(d);
  30. }
  31. ENDCG
  32. Subshader {
  33. Pass {
  34. ZTest Always Cull Off ZWrite Off
  35. Fog { Mode off }
  36. CGPROGRAM
  37. #pragma fragmentoption ARB_precision_hint_fastest
  38. #pragma vertex vert
  39. #pragma fragment frag
  40. ENDCG
  41. }
  42. }
  43. Fallback off
  44. } // shader