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.

163 lines
3.9 KiB

5 years ago
  1. // Upgrade NOTE: removed variant '__' where variant LOD_FADE_PERCENTAGE is used.
  2. Shader "Hidden/FogVolumeDirectionalLight"
  3. {
  4. Properties
  5. {
  6. _Cutoff("Alpha cutoff", Range(0,1)) = 0.5
  7. _MainTex("Base (RGB)", 2D) = "white" {}
  8. _Color("Color", Color) = (1,1,1,1)
  9. //_FogVolumeShadowMapEdgeSoftness("Edge size", Range(1, 100))=100
  10. }
  11. SubShader
  12. {
  13. Tags{ "RenderType" = "Opaque" }
  14. Pass
  15. {
  16. CGPROGRAM
  17. #define EDGE_FIX
  18. #pragma vertex vert
  19. #pragma fragment frag
  20. #include "UnityCG.cginc"
  21. uniform sampler2D _MainTex;
  22. float4 _ShadowCameraPosition;
  23. uniform float _Cutoff = 1, _FogVolumeShadowMapEdgeSoftness;
  24. struct v2f
  25. {
  26. float4 pos : SV_POSITION;
  27. float depth : DEPTH;
  28. float2 uv : TEXCOORD0;
  29. float4 screenUV : TEXCOORD1;
  30. };
  31. v2f vert(appdata_base v)
  32. {
  33. v2f o;
  34. o.pos = UnityObjectToClipPos(v.vertex);
  35. o.depth = length(mul(unity_ObjectToWorld, v.vertex).xyz - _ShadowCameraPosition.xyz);
  36. o.uv = v.texcoord.xy;
  37. o.screenUV = ComputeScreenPos(o.pos);
  38. return o;
  39. }
  40. float4 frag(v2f i) : COLOR
  41. {
  42. float2 uv = i.screenUV.xy / i.screenUV.w;
  43. float d = i.depth;
  44. #ifdef EDGE_FIX
  45. half edges = saturate(dot(1-uv.r, 1-uv.g) * dot(uv.r, uv.g)*600);
  46. d = lerp(10000, d, edges);
  47. #endif
  48. half fade = saturate(dot(1 - uv.r, 1 - uv.g) * dot(uv.r, uv.g)*_FogVolumeShadowMapEdgeSoftness);
  49. fade *= fade*fade;
  50. return float4(d, fade, 0.0f, 1);
  51. }
  52. ENDCG
  53. }
  54. }
  55. SubShader
  56. {
  57. Tags{ "RenderType" = "TransparentCutout" }
  58. Pass
  59. {
  60. CGPROGRAM
  61. #define EDGE_FIX
  62. #pragma vertex vert
  63. #pragma fragment frag
  64. #include "UnityCG.cginc"
  65. uniform sampler2D _MainTex;
  66. float4 _ShadowCameraPosition;
  67. uniform float _Cutoff = 1, _FogVolumeShadowMapEdgeSoftness;
  68. float4 _Color;
  69. struct v2f
  70. {
  71. float4 pos : SV_POSITION;
  72. float depth : DEPTH;
  73. float2 uv : TEXCOORD0;
  74. float4 screenUV : TEXCOORD1;
  75. };
  76. v2f vert(appdata_base v)
  77. {
  78. v2f o;
  79. o.pos = UnityObjectToClipPos(v.vertex);
  80. o.depth = length(mul(unity_ObjectToWorld, v.vertex).xyz - _ShadowCameraPosition.xyz);
  81. o.uv = v.texcoord.xy;
  82. o.screenUV = ComputeScreenPos(o.pos);
  83. return o;
  84. }
  85. float4 frag(v2f i) : COLOR
  86. {
  87. half4 c = tex2D(_MainTex, i.uv)*_Color;
  88. float2 uv = i.screenUV.xy / i.screenUV.w;
  89. clip(c.a - _Cutoff);
  90. float d = i.depth;
  91. #ifdef EDGE_FIX
  92. half edges = saturate(dot(1 - uv.r, 1 - uv.g) * dot(uv.r, uv.g) * 600);
  93. d = lerp(10000, d, edges);
  94. #endif
  95. half fade = saturate(dot(1 - uv.r, 1 - uv.g) * dot(uv.r, uv.g)*_FogVolumeShadowMapEdgeSoftness);
  96. fade *= fade*fade;
  97. return float4(d, fade, 0.0f, 1);
  98. }
  99. ENDCG
  100. }
  101. }
  102. SubShader
  103. {
  104. Tags
  105. {
  106. "Queue" = "Geometry"
  107. "IgnoreProjector" = "True"
  108. "RenderType" = "SpeedTree"
  109. "DisableBatching" = "LODFading"
  110. }
  111. Cull[_Cull]
  112. Fog{ Mode Off }
  113. CGPROGRAM
  114. uniform sampler2D _MainTex;
  115. float4 /*_ShadowCameraPosition,*/ _Color;
  116. uniform float _Cutoff = 1, _FogVolumeShadowMapEdgeSoftness;
  117. #pragma surface surf Lambert vertex:SpeedTreeVert nolightmap
  118. #pragma target 3.0
  119. #pragma multi_compile LOD_FADE_PERCENTAGE LOD_FADE_CROSSFADE
  120. #pragma shader_feature GEOM_TYPE_BRANCH GEOM_TYPE_BRANCH_DETAIL GEOM_TYPE_FROND GEOM_TYPE_LEAF GEOM_TYPE_MESH
  121. #define ENABLE_WIND
  122. #define SPEEDTREE_ALPHATEST
  123. #define EDGE_FIX
  124. #include "SpeedTreeCommonDepth.cginc"
  125. void surf(Input i, inout SurfaceOutput OUT)
  126. {
  127. float2 uv = i.screenUV.xy / i.screenUV.w;
  128. float d = i.ShadowDepth;
  129. #ifdef EDGE_FIX
  130. half edges = saturate(dot(1 - uv.r, 1 - uv.g) * dot(uv.r, uv.g) * 600);
  131. d = lerp(10000, d, edges);
  132. #endif
  133. half fade = saturate(dot(1 - uv.r, 1 - uv.g) * dot(uv.r, uv.g)*_FogVolumeShadowMapEdgeSoftness);
  134. fade *= fade*fade;
  135. OUT.Emission = float3(d, fade, 0.0f);
  136. SpeedTreeFragOut o;
  137. SpeedTreeFrag(i, o);
  138. SPEEDTREE_COPY_FRAG(OUT, o)
  139. }
  140. ENDCG
  141. }
  142. }