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.

272 lines
7.0 KiB

5 years ago
  1. // Upgrade NOTE: removed variant '__' where variant LOD_FADE_PERCENTAGE is used.
  2. // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
  3. Shader "Fog Volume/Nature/SpeedTree"
  4. {
  5. Properties
  6. {
  7. _Color ("Main Color", Color) = (1,1,1,1)
  8. _HueVariation ("Hue Variation", Color) = (1.0,0.5,0.0,0.1)
  9. _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
  10. _DetailTex ("Detail", 2D) = "black" {}
  11. _BumpMap ("Normal Map", 2D) = "bump" {}
  12. _Cutoff ("Alpha Cutoff", Range(0,1)) = 0.333
  13. [MaterialEnum(Off,0,Front,1,Back,2)] _Cull ("Cull", Int) = 2
  14. [MaterialEnum(None,0,Fastest,1,Fast,2,Better,3,Best,4,Palm,5)] _WindQuality ("Wind Quality", Range(0,5)) = 0
  15. }
  16. // targeting SM3.0+
  17. SubShader
  18. {
  19. Tags
  20. {
  21. "Queue"="Geometry"
  22. "IgnoreProjector"="True"
  23. "RenderType"="SpeedTree"
  24. "DisableBatching"="LODFading"
  25. }
  26. LOD 400
  27. Cull [_Cull]
  28. CGPROGRAM
  29. #pragma surface surf Lambert vertex:SpeedTreeVert nodirlightmap nodynlightmap
  30. #pragma target 3.0
  31. #pragma multi_compile LOD_FADE_PERCENTAGE LOD_FADE_CROSSFADE
  32. #pragma instancing_options assumeuniformscaling lodfade maxcount:50
  33. #pragma shader_feature GEOM_TYPE_BRANCH GEOM_TYPE_BRANCH_DETAIL GEOM_TYPE_FROND GEOM_TYPE_LEAF GEOM_TYPE_MESH
  34. #pragma shader_feature EFFECT_BUMP
  35. #pragma shader_feature EFFECT_HUE_VARIATION
  36. #define ENABLE_WIND
  37. #include "SpeedTreeCommon.cginc"
  38. void surf(Input IN, inout SurfaceOutput OUT)
  39. {
  40. SpeedTreeFragOut o;
  41. SpeedTreeFrag(IN, o);
  42. SPEEDTREE_COPY_FRAG(OUT, o)
  43. }
  44. ENDCG
  45. Pass
  46. {
  47. Tags { "LightMode" = "ShadowCaster" }
  48. CGPROGRAM
  49. #pragma vertex vert
  50. #pragma fragment frag
  51. #pragma target 3.0
  52. #pragma multi_compile LOD_FADE_PERCENTAGE LOD_FADE_CROSSFADE
  53. #pragma multi_compile_instancing
  54. #pragma instancing_options assumeuniformscaling lodfade maxcount:50
  55. #pragma shader_feature GEOM_TYPE_BRANCH GEOM_TYPE_BRANCH_DETAIL GEOM_TYPE_FROND GEOM_TYPE_LEAF GEOM_TYPE_MESH
  56. #pragma multi_compile_shadowcaster
  57. #define ENABLE_WIND
  58. #include "SpeedTreeCommon.cginc"
  59. struct v2f
  60. {
  61. V2F_SHADOW_CASTER;
  62. #ifdef SPEEDTREE_ALPHATEST
  63. float2 uv : TEXCOORD1;
  64. #endif
  65. UNITY_DITHER_CROSSFADE_COORDS_IDX(2)
  66. UNITY_VERTEX_INPUT_INSTANCE_ID
  67. UNITY_VERTEX_OUTPUT_STEREO
  68. };
  69. v2f vert(SpeedTreeVB v)
  70. {
  71. v2f o;
  72. UNITY_SETUP_INSTANCE_ID(v);
  73. UNITY_TRANSFER_INSTANCE_ID(v, o);
  74. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  75. #ifdef SPEEDTREE_ALPHATEST
  76. o.uv = v.texcoord.xy;
  77. #endif
  78. OffsetSpeedTreeVertex(v, unity_LODFade.x);
  79. TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)
  80. UNITY_TRANSFER_DITHER_CROSSFADE_HPOS(o, o.pos)
  81. return o;
  82. }
  83. float4 frag(v2f i) : SV_Target
  84. {
  85. UNITY_SETUP_INSTANCE_ID(i);
  86. #ifdef SPEEDTREE_ALPHATEST
  87. clip(tex2D(_MainTex, i.uv).a * _Color.a - _Cutoff);
  88. #endif
  89. UNITY_APPLY_DITHER_CROSSFADE(i)
  90. SHADOW_CASTER_FRAGMENT(i)
  91. }
  92. ENDCG
  93. }
  94. Pass
  95. {
  96. Tags { "LightMode" = "Vertex" }
  97. CGPROGRAM
  98. #pragma vertex vert
  99. #pragma fragment frag
  100. #pragma target 3.0
  101. #pragma multi_compile_fog
  102. #pragma multi_compile LOD_FADE_PERCENTAGE LOD_FADE_CROSSFADE
  103. #pragma multi_compile_instancing
  104. #pragma instancing_options assumeuniformscaling lodfade maxcount:50
  105. #pragma shader_feature GEOM_TYPE_BRANCH GEOM_TYPE_BRANCH_DETAIL GEOM_TYPE_FROND GEOM_TYPE_LEAF GEOM_TYPE_MESH
  106. #pragma shader_feature EFFECT_HUE_VARIATION
  107. #define ENABLE_WIND
  108. #include "SpeedTreeCommon.cginc"
  109. struct v2f
  110. {
  111. float4 vertex : SV_POSITION;
  112. UNITY_FOG_COORDS(0)
  113. Input data : TEXCOORD1;
  114. UNITY_VERTEX_INPUT_INSTANCE_ID
  115. UNITY_VERTEX_OUTPUT_STEREO
  116. };
  117. v2f vert(SpeedTreeVB v)
  118. {
  119. v2f o;
  120. UNITY_SETUP_INSTANCE_ID(v);
  121. UNITY_TRANSFER_INSTANCE_ID(v, o);
  122. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  123. SpeedTreeVert(v, o.data);
  124. o.data.color.rgb *= ShadeVertexLightsFull(v.vertex, v.normal, 4, true);
  125. o.vertex = UnityObjectToClipPos(v.vertex);
  126. UNITY_TRANSFER_FOG(o,o.vertex);
  127. return o;
  128. }
  129. fixed4 frag(v2f i) : SV_Target
  130. {
  131. UNITY_SETUP_INSTANCE_ID(i);
  132. SpeedTreeFragOut o;
  133. SpeedTreeFrag(i.data, o);
  134. fixed4 c = fixed4(o.Albedo, o.Alpha);
  135. UNITY_APPLY_FOG(i.fogCoord, c);
  136. return c;
  137. }
  138. ENDCG
  139. }
  140. }
  141. // targeting SM2.0: Cross-fading, Normal-mapping, Hue variation and Wind animation are turned off for less instructions
  142. SubShader
  143. {
  144. Tags
  145. {
  146. "Queue"="Geometry"
  147. "IgnoreProjector"="True"
  148. "RenderType"="SpeedTree"
  149. "DisableBatching"="LODFading"
  150. }
  151. LOD 400
  152. Cull [_Cull]
  153. CGPROGRAM
  154. #pragma surface surf Lambert vertex:SpeedTreeVert nodirlightmap nodynlightmap
  155. #pragma multi_compile LOD_FADE_PERCENTAGE
  156. #pragma shader_feature GEOM_TYPE_BRANCH GEOM_TYPE_BRANCH_DETAIL GEOM_TYPE_FROND GEOM_TYPE_LEAF GEOM_TYPE_MESH
  157. #include "SpeedTreeCommon.cginc"
  158. void surf(Input IN, inout SurfaceOutput OUT)
  159. {
  160. SpeedTreeFragOut o;
  161. SpeedTreeFrag(IN, o);
  162. SPEEDTREE_COPY_FRAG(OUT, o)
  163. }
  164. ENDCG
  165. Pass
  166. {
  167. Tags { "LightMode" = "ShadowCaster" }
  168. CGPROGRAM
  169. #pragma vertex vert
  170. #pragma fragment frag
  171. #pragma multi_compile LOD_FADE_PERCENTAGE
  172. #pragma shader_feature GEOM_TYPE_BRANCH GEOM_TYPE_BRANCH_DETAIL GEOM_TYPE_FROND GEOM_TYPE_LEAF GEOM_TYPE_MESH
  173. #pragma multi_compile_shadowcaster
  174. #include "SpeedTreeCommon.cginc"
  175. struct v2f
  176. {
  177. V2F_SHADOW_CASTER;
  178. #ifdef SPEEDTREE_ALPHATEST
  179. float2 uv : TEXCOORD1;
  180. #endif
  181. };
  182. v2f vert(SpeedTreeVB v)
  183. {
  184. v2f o;
  185. #ifdef SPEEDTREE_ALPHATEST
  186. o.uv = v.texcoord.xy;
  187. #endif
  188. OffsetSpeedTreeVertex(v, unity_LODFade.x);
  189. TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)
  190. return o;
  191. }
  192. float4 frag(v2f i) : SV_Target
  193. {
  194. #ifdef SPEEDTREE_ALPHATEST
  195. clip(tex2D(_MainTex, i.uv).a * _Color.a - _Cutoff);
  196. #endif
  197. SHADOW_CASTER_FRAGMENT(i)
  198. }
  199. ENDCG
  200. }
  201. Pass
  202. {
  203. Tags { "LightMode" = "Vertex" }
  204. CGPROGRAM
  205. #pragma vertex vert
  206. #pragma fragment frag
  207. #pragma multi_compile_fog
  208. #pragma multi_compile LOD_FADE_PERCENTAGE
  209. #pragma shader_feature GEOM_TYPE_BRANCH GEOM_TYPE_BRANCH_DETAIL GEOM_TYPE_FROND GEOM_TYPE_LEAF GEOM_TYPE_MESH
  210. #include "SpeedTreeCommon.cginc"
  211. struct v2f
  212. {
  213. float4 vertex : SV_POSITION;
  214. UNITY_FOG_COORDS(0)
  215. Input data : TEXCOORD1;
  216. UNITY_VERTEX_OUTPUT_STEREO
  217. };
  218. v2f vert(SpeedTreeVB v)
  219. {
  220. v2f o;
  221. UNITY_SETUP_INSTANCE_ID(v);
  222. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  223. SpeedTreeVert(v, o.data);
  224. o.data.color.rgb *= ShadeVertexLightsFull(v.vertex, v.normal, 2, false);
  225. o.vertex = UnityObjectToClipPos(v.vertex);
  226. UNITY_TRANSFER_FOG(o,o.vertex);
  227. return o;
  228. }
  229. fixed4 frag(v2f i) : SV_Target
  230. {
  231. SpeedTreeFragOut o;
  232. SpeedTreeFrag(i.data, o);
  233. fixed4 c = fixed4(o.Albedo, o.Alpha);
  234. UNITY_APPLY_FOG(i.fogCoord, c);
  235. return c;
  236. }
  237. ENDCG
  238. }
  239. }
  240. FallBack "Transparent/Cutout/VertexLit"
  241. CustomEditor "SpeedTreeMaterialInspector"
  242. }