Water.shader 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. Shader "Real World Terrain Water"
  2. {
  3. Properties
  4. {
  5. _Color("Color", Color) = (1,1,1,1)
  6. _Texture1("Texture1", 2D) = "black" {}
  7. _Texture2("Texture2", 2D) = "black" {}
  8. _MainTexSpeed("MainTexSpeed", Float) = 0
  9. _Texture2Speed("Texture2Speed", Float) = 0
  10. _DistortionMap("DistortionMap", 2D) = "black" {}
  11. _DistortionSpeed("DistortionSpeed", Float) = 0
  12. _DistortionPower("DistortionPower", Range(0,0.04) ) = 0
  13. _Specular("Specular", Range(0,7) ) = 1
  14. _Gloss("Gloss", Range(0.1,2) ) = 0.3
  15. }
  16. SubShader
  17. {
  18. Tags
  19. {
  20. "Queue"="Transparent"
  21. "IgnoreProjector"="False"
  22. "RenderType"="Overlay"
  23. }
  24. Cull Back
  25. ZWrite On
  26. ZTest LEqual
  27. ColorMask RGBA
  28. Blend SrcAlpha OneMinusSrcAlpha
  29. Fog{}
  30. CGPROGRAM
  31. #pragma surface surf BlinnPhongEditor noforwardadd
  32. #pragma target 3.0
  33. fixed4 _Color;
  34. uniform sampler2D _Texture1;
  35. uniform sampler2D _Texture2;
  36. half _MainTexSpeed;
  37. half _Texture2Speed;
  38. uniform sampler2D _DistortionMap;
  39. half _DistortionSpeed;
  40. half _DistortionPower;
  41. fixed _Specular;
  42. fixed _Gloss;
  43. struct EditorSurfaceOutput
  44. {
  45. half3 Albedo;
  46. half3 Normal;
  47. half3 Emission;
  48. half3 Gloss;
  49. half Specular;
  50. half Alpha;
  51. half4 Custom;
  52. };
  53. inline half4 LightingBlinnPhongEditor_PrePass (EditorSurfaceOutput s, half4 light)
  54. {
  55. half3 spec = light.a * s.Gloss;
  56. half4 c;
  57. c.rgb = (s.Albedo * light.rgb + light.rgb * spec);
  58. c.a = s.Alpha;
  59. return c;
  60. }
  61. inline half4 LightingBlinnPhongEditor (EditorSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
  62. {
  63. half3 h = normalize (lightDir + viewDir);
  64. half diff = max (0, dot ( lightDir, s.Normal ));
  65. float nh = max (0, dot (s.Normal, h));
  66. float spec = pow (nh, s.Specular*128.0);
  67. half4 res;
  68. res.rgb = _LightColor0.rgb * diff;
  69. res.w = spec * Luminance (_LightColor0.rgb);
  70. res *= atten * 2.0;
  71. return LightingBlinnPhongEditor_PrePass( s, res );
  72. }
  73. struct Input
  74. {
  75. float3 viewDir;
  76. float2 uv_DistortionMap;
  77. float2 uv_Texture1;
  78. float2 uv_Texture2;
  79. };
  80. void surf (Input IN, inout EditorSurfaceOutput o)
  81. {
  82. o.Normal = float3(0.0,0.0,1.0);
  83. o.Alpha = 1.0;
  84. o.Albedo = 0.0;
  85. o.Emission = 0.0;
  86. o.Gloss = 0.0;
  87. o.Specular = 0.0;
  88. o.Custom = 0.0;
  89. float DistortSpeed=_DistortionSpeed * _Time;
  90. float2 DistortUV=(IN.uv_DistortionMap.xy) + DistortSpeed;
  91. float4 DistortNormal = float4(UnpackNormal( tex2D(_DistortionMap,DistortUV)).xyz, 1.0 );
  92. float2 FinalDistortion = DistortNormal.xy * _DistortionPower;
  93. float Multiply2=_Time * _MainTexSpeed;
  94. float2 MainTexUV=(IN.uv_Texture1.xy) + Multiply2;
  95. float4 Tex2D0=tex2D(_Texture1,MainTexUV + FinalDistortion);
  96. float Multiply3=_Time * _Texture2Speed;
  97. float2 Tex2UV=(IN.uv_Texture2.xy) + Multiply3;
  98. float4 Tex2D1=tex2D(_Texture2,Tex2UV + FinalDistortion);
  99. float4 TextureMix=Tex2D0 * Tex2D1;
  100. float4 FinalDiffuse=_Color * TextureMix;
  101. o.Albedo = FinalDiffuse;
  102. o.Emission = FinalDiffuse;
  103. o.Specular = _Gloss;
  104. o.Gloss = _Specular;
  105. o.Normal = normalize(o.Normal);
  106. }
  107. ENDCG
  108. }
  109. Fallback "Diffuse"
  110. }