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.

130 lines
3.3 KiB

5 years ago
  1. // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
  2. #ifndef SPEEDTREE_COMMON_INCLUDED
  3. #define SPEEDTREE_COMMON_INCLUDED
  4. #include "UnityCG.cginc"
  5. #define SPEEDTREE_Y_UP
  6. #ifdef GEOM_TYPE_BRANCH_DETAIL
  7. #define GEOM_TYPE_BRANCH
  8. #endif
  9. #include "SpeedTreeVertexDepth.cginc"
  10. // Define Input structure
  11. struct Input
  12. {
  13. fixed4 color;
  14. half3 interpolator1;
  15. #ifdef GEOM_TYPE_BRANCH_DETAIL
  16. half3 interpolator2;
  17. #endif
  18. UNITY_DITHER_CROSSFADE_COORDS
  19. half depth;
  20. half ShadowDepth;
  21. float4 screenUV;
  22. };
  23. // Define uniforms
  24. float4 _ShadowCameraPosition;
  25. #define mainTexUV interpolator1.xy
  26. //sampler2D _MainTex;
  27. #ifdef GEOM_TYPE_BRANCH_DETAIL
  28. #define Detail interpolator2
  29. sampler2D _DetailTex;
  30. #endif
  31. //#if defined(GEOM_TYPE_FROND) || defined(GEOM_TYPE_LEAF) || defined(GEOM_TYPE_FACING_LEAF)
  32. // #define SPEEDTREE_ALPHATEST
  33. // fixed _Cutoff;
  34. //#endif
  35. #ifdef EFFECT_HUE_VARIATION
  36. #define HueVariationAmount interpolator1.z
  37. half4 _HueVariation;
  38. #endif
  39. #if defined(EFFECT_BUMP) && !defined(LIGHTMAP_ON)
  40. sampler2D _BumpMap;
  41. #endif
  42. //fixed4 _Color;
  43. // Vertex processing
  44. void SpeedTreeVert(inout SpeedTreeVB IN, out Input OUT)
  45. {
  46. UNITY_INITIALIZE_OUTPUT(Input, OUT);
  47. OUT.depth = -(UnityObjectToViewPos(IN.vertex).z/* * _ProjectionParams.w*/);
  48. float4 pos = UnityObjectToClipPos(IN.vertex);
  49. OUT.screenUV = ComputeScreenPos(pos);
  50. OUT.ShadowDepth = length(mul(unity_ObjectToWorld, IN.vertex).xyz - _ShadowCameraPosition.xyz);
  51. OUT.mainTexUV = IN.texcoord.xy;
  52. //OUT.color = _Color;
  53. // OUT.color.rgb *= IN.color.r; // ambient occlusion factor
  54. #ifdef EFFECT_HUE_VARIATION
  55. float hueVariationAmount = frac(unity_ObjectToWorld[0].w + unity_ObjectToWorld[1].w + unity_ObjectToWorld[2].w);
  56. hueVariationAmount += frac(IN.vertex.x + IN.normal.y + IN.normal.x) * 0.5 - 0.3;
  57. OUT.HueVariationAmount = saturate(hueVariationAmount * _HueVariation.a);
  58. #endif
  59. #ifdef GEOM_TYPE_BRANCH_DETAIL
  60. // The two types are always in different sub-range of the mesh so no interpolation (between detail and blend) problem.
  61. OUT.Detail.xy = IN.texcoord2.xy;
  62. if (IN.color.a == 0) // Blend
  63. OUT.Detail.z = IN.texcoord2.z;
  64. else // Detail texture
  65. OUT.Detail.z = 2.5f; // stay out of Blend's .z range
  66. #endif
  67. OffsetSpeedTreeVertex(IN, unity_LODFade.x);
  68. UNITY_TRANSFER_DITHER_CROSSFADE(OUT, IN.vertex)
  69. }
  70. // Fragment processing
  71. #if defined(EFFECT_BUMP) && !defined(LIGHTMAP_ON)
  72. #define SPEEDTREE_DATA_NORMAL fixed3 Normal;
  73. #define SPEEDTREE_COPY_NORMAL(to, from) to.Normal = from.Normal;
  74. #else
  75. #define SPEEDTREE_DATA_NORMAL
  76. #define SPEEDTREE_COPY_NORMAL(to, from)
  77. #endif
  78. #define SPEEDTREE_COPY_FRAG(to, from) \
  79. to.Alpha = from.Alpha; \
  80. SPEEDTREE_COPY_NORMAL(to, from)
  81. struct SpeedTreeFragOut
  82. {
  83. // fixed3 Albedo;
  84. fixed Alpha;
  85. SPEEDTREE_DATA_NORMAL
  86. };
  87. void SpeedTreeFrag(Input IN, out SpeedTreeFragOut OUT)
  88. {
  89. half4 diffuseColor = tex2D(_MainTex, IN.mainTexUV);
  90. OUT.Alpha = diffuseColor.a * _Color.a;
  91. #ifdef SPEEDTREE_ALPHATEST
  92. clip(OUT.Alpha - _Cutoff);
  93. #endif
  94. // UNITY_APPLY_DITHER_CROSSFADE(IN)
  95. //OUT.Normal = float3(0, 0, 1);
  96. // OUT.Albedo = 0;
  97. }
  98. #endif // SPEEDTREE_COMMON_INCLUDED