Grass 1.shader 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. Shader "Custom/DistortSelf"
  2. {
  3. Properties
  4. {
  5. [Header(Flag)]
  6. _MainTex("Texture", 2D) = "white" {}
  7. _Noise ("Noise", 2D) = "white" {}
  8. _distortFactorTime("FactorTime",Range(0,5)) = 0.5
  9. _distortFactor("factor",Range(0.04,1)) = 0
  10. [Space(20)]
  11. [Header(MainBackGround)]
  12. _2edTex ("Main Tex", 2D) = "white" {}
  13. //_Specular ("Specular", Color) = (1, 1, 1, 1)
  14. //_Gloss ("Gloss", Range(8.0, 256)) = 20
  15. [Space(20)]
  16. [Header(Cloud)]
  17. _3rdTex ("3edTexture", 2D) = "white" {}
  18. _Speed("Rotate Speed",Float)=1
  19. [Space(20)]
  20. [Header(Grass)]
  21. _4thTex ("Texture", 2D) = "white" {}
  22. _Noise2("Noise", 2D) = "black" {}
  23. _WindControl("WindControl(x:XSpeed y:YSpeed z:ZSpeed w:windMagnitude)",vector) = (1,0,1,0.5)
  24. //前面几个分量表示在各个轴向上自身摆动的速度, w表示摆动的强度
  25. _WaveControl("WaveControl(x:XSpeed y:YSpeed z:ZSpeed w:worldSize)",vector) = (1,0,1,1)
  26. //前面几个分量表示在各个轴向上风浪的速度, w用来模拟地图的大小,值越小草摆动的越凌乱,越大摆动的越整体
  27. [HDR]_Color("Color",Color) = (1,1,1,1)
  28. _XSpeed("XSpeed",Range(-1,1)) = 0
  29. _YSpeed("YSpeed",Range(-1,1)) = 0
  30. _AlphaScale("Alpha",Range(0,1)) =1
  31. [Space(10)]
  32. [Header(Water)]
  33. _WaterCol ("Color", Color) = (1,1,1,1)
  34. _WaterCol_ROOT ("Color ROOT", Color) = (1,1,1,1)
  35. _WaterCol_image5 ("Color image5", Color) = (1,1,1,1)
  36. _WaterCol_image5copy ("Color image5copy", Color) = (1,1,1,1)
  37. _WaterCol_image8 ("Color image8", Color) = (1,1,1,1)
  38. _WaterCol_image8copy ("Color image8copy", Color) = (1,1,1,1)
  39. _WaterCol_image15 ("Color image15", Color) = (1,1,1,1)
  40. _5thTex ("_5thTex", 2D) = "white" { }
  41. _wave ("_wave", 2D) = "white" { }
  42. _view_mask0 ("_view_mask0", 2D) = "white" { }
  43. _smoke ("_smoke", 2D) = "white" { }
  44. _viewWaterfall ("_viewWaterfall", 2D) = "white" { }
  45. _view2 ("_view2", 2D) = "white" { }
  46. _view_mask1 ("_view_mask1", 2D) = "white" { }
  47. _Speed2("Speed2",Float) = 1
  48. _Alpha("Alpha",Range(0,1))=1
  49. [MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
  50. }
  51. SubShader
  52. {
  53. Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" "CanUseSpriteAtlas"="True"}
  54. LOD 100
  55. Blend SrcAlpha OneMinusSrcAlpha
  56. Cull Off Lighting Off ZWrite Off
  57. Pass
  58. {
  59. ZWrite Off
  60. CGPROGRAM
  61. #pragma vertex vert
  62. #pragma fragment frag
  63. #include "Lighting.cginc"
  64. fixed4 _Color;
  65. sampler2D _2edTex;
  66. float4 _2edTex_ST;
  67. fixed4 _Specular;
  68. float _Gloss;
  69. struct a2v {
  70. float4 vertex : POSITION;
  71. float3 normal : NORMAL;
  72. float4 texcoord : TEXCOORD0;
  73. };
  74. struct v2f {
  75. float4 pos : SV_POSITION;
  76. float3 worldNormal : TEXCOORD0;
  77. float3 worldPos : TEXCOORD1;
  78. float2 uv : TEXCOORD2;
  79. };
  80. v2f vert(a2v v) {
  81. v2f o;
  82. o.pos = UnityObjectToClipPos(v.vertex);
  83. o.worldNormal = UnityObjectToWorldNormal(v.normal);
  84. o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
  85. o.uv = v.texcoord.xy * _2edTex_ST.xy + _2edTex_ST.zw;
  86. // Or just call the built-in function
  87. // o.uv = TRANSFORM_TEX(v.texcoord, _2edTex);
  88. return o;
  89. }
  90. fixed4 frag(v2f i) : SV_Target {
  91. //fixed3 worldNormal = normalize(i.worldNormal);
  92. //fixed3 worldLightDir = normalize(UnityWorldSpaceLightDir(i.worldPos));
  93. // Use the texture to sample the diffuse color
  94. fixed4 albedo = tex2D(_2edTex, i.uv);
  95. return albedo;
  96. }
  97. ENDCG
  98. }
  99. Pass
  100. {
  101. Blend SrcAlpha OneMinusSrcAlpha
  102. CGPROGRAM
  103. #pragma vertex vert
  104. #pragma fragment frag
  105. #include "UnityCG.cginc"
  106. sampler2D _3rdTex;
  107. float4 _3rdTex_ST;
  108. float _Speed;
  109. struct a2v{
  110. float4 vertex:POSITION;
  111. float4 texcoord:TEXCOORD;
  112. };
  113. struct v2f{
  114. float4 pos:POSITION;
  115. float4 uv:texcoord;
  116. };
  117. v2f vert(a2v v){
  118. v2f o;
  119. o.pos=UnityObjectToClipPos(v.vertex);
  120. o.uv=v.texcoord;
  121. return o;
  122. }
  123. fixed4 frag(v2f i):SV_Target{
  124. /*//扭曲效果
  125. fixed2 uv = i.uv - fixed2(0.5,0.5);
  126. float angle = _Speed * 0.1745/(length(uv) + 0.1);//加0.1是放置length(uv)为0
  127. float angle2 = angle * _Time.y;
  128. uv = float2(uv.x*cos(angle2)-uv.y*sin(angle2),uv.y*cos(angle2)+uv.x*sin(angle2));
  129. uv+=fixed2(0.5,0.5);
  130. fixed4 c = tex2D(_3rdTex,uv);
  131. return c;
  132. */
  133. //缩放
  134. //float4 uv = i.uv;
  135. //uv.x*=_Speed;
  136. //uv.w=0.5;
  137. //return tex2D(_3rdTex,uv);
  138. //旋转
  139. //float2 uv=i.uv.xy-float2(0.5,0.5);
  140. //uv=float2(uv.x*cos(_Speed*_Time.y)-uv.y*sin(_Speed*_Time.y),uv.y*cos(_Speed*_Time.y) + uv.x*sin(_Speed*_Time.y));
  141. //uv+=float2(0.5,0.5);
  142. //fixed4 lateUV = tex2D(_3rdTex,uv);
  143. //return lateUV;
  144. //平移
  145. return tex2D(_3rdTex,i.uv - _Time.x*fixed2(2,0)* _Speed);
  146. }
  147. ENDCG
  148. }
  149. Pass
  150. {
  151. ZWrite off
  152. CGPROGRAM
  153. #pragma vertex vert
  154. #pragma fragment frag
  155. #include "UnityCG.cginc"
  156. struct appdata
  157. {
  158. float4 vertex : POSITION;
  159. float2 uv : TEXCOORD0;
  160. };
  161. struct v2f
  162. {
  163. float2 uv : TEXCOORD0;
  164. float4 vertex : SV_POSITION;
  165. };
  166. sampler2D _MainTex;
  167. float4 _MainTex_ST;
  168. sampler2D _Noise;
  169. fixed _distortFactorTime;
  170. fixed _distortFactor;
  171. fixed4 _Color;
  172. float _XSpeed;
  173. float _YSpeed;
  174. v2f vert (appdata v)
  175. {
  176. v2f o;
  177. o.vertex = UnityObjectToClipPos(v.vertex);
  178. o.uv = TRANSFORM_TEX(v.uv, _MainTex);
  179. o.uv += float2(_XSpeed, _YSpeed)*_Time.y;
  180. return o;
  181. }
  182. fixed4 frag (v2f i) : SV_Target
  183. {
  184. // sample the texture
  185. fixed4 bias = tex2D(_Noise, i.uv+_Time.xy*_distortFactorTime);
  186. half4 color = tex2D(_MainTex, i.uv+bias.xy*_distortFactor);
  187. return color*_Color;
  188. }
  189. ENDCG
  190. }
  191. }
  192. }