You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.0 KiB

5 years ago
  1. Shader "Fog Volume/RT viewers/RT_Depth"
  2. {
  3. Properties{
  4. [Toggle(RightEye)] _RightEye ("Right Eye?", Float) = 0
  5. [hideininspector]_MainTex("Base", 2D) = "" {}
  6. _Intensity("Intensity", Range(1, 20)) = 1
  7. }
  8. SubShader
  9. {
  10. Tags { "RenderType" = "Opaque" }
  11. LOD 100
  12. Pass
  13. {
  14. CGPROGRAM
  15. #pragma multi_compile _ _FOG_LOWRES_RENDERER
  16. #pragma vertex vert
  17. #pragma fragment frag
  18. #pragma multi_compile _ RightEye
  19. #include "UnityCG.cginc"
  20. float _Intensity;
  21. struct appdata
  22. {
  23. float4 vertex : POSITION;
  24. float2 uv : TEXCOORD0;
  25. };
  26. struct v2f
  27. {
  28. float2 uv : TEXCOORD0;
  29. float4 vertex : SV_POSITION;
  30. };
  31. sampler2D RT_Depth, _MainTex;
  32. sampler2D RT_DepthR;
  33. float4 RT_Depth_ST, _MainTex_TexelSize, _MainTex_ST;
  34. sampler2D _CameraDepthTexture;
  35. v2f vert (appdata v)
  36. {
  37. v2f o;
  38. o.vertex = UnityObjectToClipPos(v.vertex);
  39. o.uv = v.uv;
  40. return o;
  41. }
  42. fixed4 frag (v2f i) : SV_Target
  43. {
  44. // sample the texture
  45. float Depth = 0;
  46. #ifdef RightEye
  47. Depth = tex2D(RT_DepthR, i.uv).r;
  48. #else
  49. Depth = tex2D(RT_Depth, i.uv).r;
  50. #endif
  51. Depth *= 1000;
  52. return 1/Depth*_Intensity;
  53. //#if UNITY_REVERSED_Z!=1
  54. // return float4(1, 0, 0, 1);
  55. //#else
  56. // return float4(0, 1, 0, 1);
  57. //#endif
  58. //Depth = LinearEyeDepth(Depth);
  59. // Depth = 1.0 / (_ZBufferParams.z * Depth + _ZBufferParams.w);
  60. //Depth = max(.001, Depth);
  61. //
  62. //if (Depth < .0001)Depth = 1;
  63. //Depth /= _ProjectionParams.w;
  64. //Depth *= 1000;
  65. //https://docs.unity3d.com/Manual/SL-UnityShaderVariables.html
  66. //_ZBufferParams float4 Used to linearize Z buffer values. x is (1-far/near), y is (far/near), z is (x/far) and w is (y/far).
  67. half far = 1000;
  68. half near = .01;
  69. float x, y, z, w;
  70. x = 1 - far / near;
  71. y = far / near;
  72. z = x / far;
  73. w = y / far;
  74. //Depth = 1/ (z * Depth + w);
  75. //if (Depth < .0000001)Depth = 1000;
  76. return (1/Depth*_Intensity);
  77. //return DecodeFloatRGBA(z)*50;
  78. }
  79. ENDCG
  80. }
  81. }
  82. }