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.

142 lines
2.8 KiB

5 years ago
  1. // Upgrade NOTE: removed variant '__' where variant LOD_FADE_PERCENTAGE is used.
  2. Shader "Hidden/Fog Volume/Depth"
  3. {
  4. Properties
  5. {
  6. _MainTex("Main Texture", 2D) = "white" {}
  7. _Cutoff("Alpha cutoff", Range(0,1)) = 0.5
  8. _Color("Color", Color) = (1,1,1,1)
  9. [MaterialEnum(Off,0,Front,1,Back,2)] _Cull("Cull", Int) = 2
  10. [MaterialEnum(None,0,Fastest,1,Fast,2,Better,3,Best,4,Palm,5)] _WindQuality("Wind Quality", Range(0,5)) = 0
  11. }
  12. CGINCLUDE
  13. #pragma target 3.0
  14. #include "UnityCG.cginc"
  15. sampler2D _CameraDepthTexture;
  16. uniform float _Cutoff;
  17. uniform sampler2D _MainTex;
  18. float4 _Color;
  19. int _Cull;
  20. struct v2f
  21. {
  22. float4 vertex : SV_POSITION;
  23. float2 uv : TEXCOORD0;
  24. half depth:TEXCOORD1;
  25. UNITY_VERTEX_OUTPUT_STEREO
  26. };
  27. v2f vert(appdata_full v)
  28. {
  29. v2f o;
  30. UNITY_SETUP_INSTANCE_ID(v);
  31. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  32. o.vertex = UnityObjectToClipPos(v.vertex);
  33. o.uv = v.texcoord.xy;
  34. //o.depth = COMPUTE_DEPTH_01;
  35. //3.2.1
  36. o.depth = -(UnityObjectToViewPos(v.vertex).z)/** _ProjectionParams.w*/;
  37. return o;
  38. }
  39. half4 fragOpaque(v2f i) : COLOR
  40. {
  41. float d =1.0/(i.depth);
  42. //float d = Linear01Depth(i.depth);
  43. //float d= 1.0 / (_ZBufferParams.x * i.depth + _ZBufferParams.y);
  44. //#if defined(UNITY_REVERSED_Z)
  45. //d = 1.0f - d;
  46. //#endif
  47. return d;
  48. }
  49. half4 fragTransparentCutout(v2f i) : COLOR
  50. {
  51. half4 c = tex2D(_MainTex, i.uv)*_Color;
  52. clip(c.a - _Cutoff);
  53. float d = 1.0/(i.depth);
  54. // #if defined(UNITY_REVERSED_Z)
  55. // i.depth = 1.0f - i.depth;
  56. // #endif
  57. return (d);
  58. }
  59. ENDCG
  60. SubShader
  61. {
  62. Tags{ "RenderType" = "Opaque" }
  63. Pass
  64. {
  65. Fog{ Mode Off }
  66. CGPROGRAM
  67. #pragma vertex vert
  68. #pragma fragment fragOpaque
  69. ENDCG
  70. }
  71. }
  72. SubShader
  73. {
  74. Tags{ "RenderType" = "TransparentCutout" }
  75. Pass
  76. {
  77. Fog{ Mode Off }
  78. CGPROGRAM
  79. #pragma vertex vert
  80. #pragma fragment fragTransparentCutout
  81. ENDCG
  82. }
  83. }
  84. SubShader
  85. {
  86. Tags{ "RenderType" = "TreeLeaf" }
  87. Pass
  88. {
  89. Fog{ Mode Off }
  90. CGPROGRAM
  91. #pragma vertex vert
  92. #pragma fragment fragTransparentCutout
  93. ENDCG
  94. }
  95. }
  96. SubShader
  97. {
  98. Tags
  99. {
  100. "Queue" = "Geometry"
  101. "IgnoreProjector" = "True"
  102. "RenderType" = "SpeedTree"
  103. "DisableBatching" = "LODFading"
  104. }
  105. //Pass{
  106. Cull[_Cull]
  107. Fog{ Mode Off }
  108. CGPROGRAM
  109. #pragma surface surf Lambert vertex:SpeedTreeVert nolightmap
  110. #pragma target 3.0
  111. #pragma multi_compile LOD_FADE_PERCENTAGE LOD_FADE_CROSSFADE
  112. #pragma shader_feature GEOM_TYPE_BRANCH GEOM_TYPE_BRANCH_DETAIL GEOM_TYPE_FROND GEOM_TYPE_LEAF GEOM_TYPE_MESH
  113. #define ENABLE_WIND
  114. #define SPEEDTREE_ALPHATEST
  115. #include "SpeedTreeCommonDepth.cginc"
  116. void surf(Input IN, inout SurfaceOutput OUT)
  117. {
  118. float d= 1.0 / (IN.depth);
  119. // /*#if defined(UNITY_REVERSED_Z)
  120. // d = 1.0f - d;
  121. // #endif*/
  122. OUT.Emission = d;
  123. SpeedTreeFragOut o;
  124. SpeedTreeFrag(IN, o);
  125. SPEEDTREE_COPY_FRAG(OUT, o)
  126. }
  127. ENDCG
  128. //}
  129. }
  130. }