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.

140 lines
2.9 KiB

  1. Shader "FX/Water (simple)" {
  2. Properties {
  3. _horizonColor ("Horizon color", COLOR) = ( .172 , .463 , .435 , 0)
  4. _WaveScale ("Wave scale", Range (0.02,0.15)) = .07
  5. _ColorControl ("Reflective color (RGB) fresnel (A) ", 2D) = "" { }
  6. _ColorControlCube ("Reflective color cube (RGB) fresnel (A) ", Cube) = "" { TexGen CubeReflect }
  7. _BumpMap ("Waves Normalmap ", 2D) = "" { }
  8. WaveSpeed ("Wave speed (map1 x,y; map2 x,y)", Vector) = (19,9,-16,-7)
  9. _MainTex ("Fallback texture", 2D) = "" { }
  10. }
  11. CGINCLUDE
  12. // -----------------------------------------------------------
  13. // This section is included in all program sections below
  14. #include "UnityCG.cginc"
  15. uniform float4 _horizonColor;
  16. uniform float4 WaveSpeed;
  17. uniform float _WaveScale;
  18. uniform float4 _WaveOffset;
  19. struct appdata {
  20. float4 vertex : POSITION;
  21. float3 normal : NORMAL;
  22. };
  23. struct v2f {
  24. float4 pos : SV_POSITION;
  25. float2 bumpuv[2] : TEXCOORD0;
  26. float3 viewDir : TEXCOORD2;
  27. };
  28. v2f vert(appdata v)
  29. {
  30. v2f o;
  31. float4 s;
  32. o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
  33. // scroll bump waves
  34. float4 temp;
  35. temp.xyzw = v.vertex.xzxz * _WaveScale / unity_Scale.w + _WaveOffset;
  36. o.bumpuv[0] = temp.xy * float2(.4, .45);
  37. o.bumpuv[1] = temp.wz;
  38. // object space view direction
  39. o.viewDir.xzy = normalize( ObjSpaceViewDir(v.vertex) );
  40. return o;
  41. }
  42. ENDCG
  43. // -----------------------------------------------------------
  44. // Fragment program
  45. Subshader {
  46. Tags { "RenderType"="Opaque" }
  47. Pass {
  48. CGPROGRAM
  49. #pragma vertex vert
  50. #pragma fragment frag
  51. #pragma fragmentoption ARB_precision_hint_fastest
  52. sampler2D _BumpMap;
  53. sampler2D _ColorControl;
  54. half4 frag( v2f i ) : COLOR
  55. {
  56. half3 bump1 = UnpackNormal(tex2D( _BumpMap, i.bumpuv[0] )).rgb;
  57. half3 bump2 = UnpackNormal(tex2D( _BumpMap, i.bumpuv[1] )).rgb;
  58. half3 bump = (bump1 + bump2) * 0.5;
  59. half fresnel = dot( i.viewDir, bump );
  60. half4 water = tex2D( _ColorControl, float2(fresnel,fresnel) );
  61. half4 col;
  62. col.rgb = lerp( water.rgb, _horizonColor.rgb, water.a );
  63. col.a = _horizonColor.a;
  64. return col;
  65. }
  66. ENDCG
  67. }
  68. }
  69. // -----------------------------------------------------------
  70. // Old cards
  71. // three texture, cubemaps
  72. Subshader {
  73. Tags { "RenderType"="Opaque" }
  74. Pass {
  75. Color (0.5,0.5,0.5,0.5)
  76. SetTexture [_MainTex] {
  77. Matrix [_WaveMatrix]
  78. combine texture * primary
  79. }
  80. SetTexture [_MainTex] {
  81. Matrix [_WaveMatrix2]
  82. combine texture * primary + previous
  83. }
  84. SetTexture [_ColorControlCube] {
  85. combine texture +- previous, primary
  86. Matrix [_Reflection]
  87. }
  88. }
  89. }
  90. // dual texture, cubemaps
  91. Subshader {
  92. Tags { "RenderType"="Opaque" }
  93. Pass {
  94. Color (0.5,0.5,0.5,0.5)
  95. SetTexture [_MainTex] {
  96. Matrix [_WaveMatrix]
  97. combine texture
  98. }
  99. SetTexture [_ColorControlCube] {
  100. combine texture +- previous, primary
  101. Matrix [_Reflection]
  102. }
  103. }
  104. }
  105. // single texture
  106. Subshader {
  107. Tags { "RenderType"="Opaque" }
  108. Pass {
  109. Color (0.5,0.5,0.5,0)
  110. SetTexture [_MainTex] {
  111. Matrix [_WaveMatrix]
  112. combine texture, primary
  113. }
  114. }
  115. }
  116. }