Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. Shader "Unlit/MapShader" {
  2.  
  3. Properties {
  4. _XTex ("Texture", 2D) = "white" {}
  5. _YTex ("Texture", 2D) = "white" {}
  6. _ZTex ("Texture", 2D) = "white" {}
  7. _FluidGradient ("Fluid Gradient Color", 2D) = "white" {}
  8. _FluidTex ("Fluid Detail", 2D) = "white" {}
  9. _FOWTex ("Fog of War Texture", 2D) = "white" {}
  10. _Oscillation ("Fluid Oscillation Level", Range(0, 1)) = 0
  11. _Detail ("Fluid Detail Weight", Range(0, 1)) = 0
  12. _Bias ("Fluid Level Bias", Range(-1, 1)) = 0
  13. _BaseIntensity ("Base Light Intensity", Range(0, 1)) = 0
  14. _Flow ("Fluid Flowing Speed", Range(0, 10)) = 1
  15. _Height ("Fluid height", Range(0, 25)) = 10
  16. _BaseLightColor ("Base Light Color", Color) = (1, 1, 1, 1)
  17. _MapWidthHeight ("Width and Height of the map", Vector) = (1, 1, 1, 1)
  18. }
  19.  
  20. SubShader {
  21.  
  22. Tags {"RenderType"="Opaque" "LightMode"="ForwardBase"}
  23.  
  24. Pass {
  25.  
  26. CGPROGRAM
  27. #pragma vertex vert
  28. #pragma fragment frag
  29.  
  30. #include "UnityCG.cginc"
  31. #include "UnityLightingCommon.cginc"
  32.  
  33. sampler2D _XTex;
  34. sampler2D _YTex;
  35. sampler2D _ZTex;
  36. sampler2D _FluidGradient;
  37. sampler2D _FluidTex;
  38. sampler2D _FOWTex;
  39. half _Oscillation;
  40. half _Detail;
  41. half _Bias;
  42. half _BaseIntensity;
  43. half _Flow;
  44. half _Height;
  45. float4 _BaseLightColor;
  46. float2 _MapWidthHeight;
  47.  
  48. struct i2v {
  49. float4 pos : POSITION;
  50. half3 normal : NORMAL;
  51. };
  52.  
  53. struct v2f {
  54. float4 pos : SV_POSITION;
  55. half3 normal : NORMAL;
  56. half3 world : TEXCOORD0;
  57. //UNITY_FOG_COORDS(3)
  58. };
  59.  
  60. float4 _XTex_ST;
  61. float4 _YTex_ST;
  62. float4 _ZTex_ST;
  63. float4 _FluidTex_ST;
  64. float4 _FluidGradient_ST;
  65. float4 _FOWTex_ST;
  66.  
  67. v2f vert (i2v v)
  68. {
  69. v2f o;
  70. o.world = v.pos.xyz;
  71. o.pos = UnityObjectToClipPos(v.pos);
  72. o.normal = v.normal;
  73.  
  74. return o;
  75. }
  76.  
  77. float4 frag (v2f i) : SV_Target
  78. {
  79. half detail = (tex2D(_FluidTex, (_Flow * (_Time[0] * half2(1, 1))) + TRANSFORM_TEX(i.world.xz, _FluidTex)).r - 0.5) * 2 * _Detail;
  80. half time_osc = _SinTime[3] * _Oscillation;
  81.  
  82. half height = abs(i.world.y / _Height);
  83. half weight = clamp(height + time_osc + detail + _Bias, 0.01, 0.99);
  84.  
  85. float4 grd_col = tex2D(_FluidGradient, half2(weight, 0));
  86.  
  87. float3 norm = abs(i.normal);
  88. norm = norm / (norm.x + norm.y + norm.z);
  89. float4 colX = tex2D(_XTex, TRANSFORM_TEX(i.world.zy, _XTex));
  90. float4 colY = tex2D(_YTex, TRANSFORM_TEX(i.world.xz, _YTex));
  91. float4 colZ = tex2D(_ZTex, TRANSFORM_TEX(i.world.xy, _ZTex));
  92. float4 tex_col = (colX * norm.x + colY * norm.y + colZ * norm.z);
  93.  
  94. float4 col = lerp(grd_col, tex_col * _BaseLightColor, 1 - (grd_col.a));
  95. col = lerp(float4(0, 0, 0, 0), col, tex2D(_FOWTex, i.world.xz / _MapWidthHeight.xy).a);
  96.  
  97. return col;
  98. }
  99. ENDCG
  100. }
  101. }
  102. FallBack "Diffuse"
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement