Advertisement
Guest User

SimpleWater.shader

a guest
Jan 12th, 2019
4,737
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. Shader "Unlit/Simple Water"
  2. {
  3. Properties
  4. {
  5. _Color("Tint", Color) = (1, 1, 1, .5)
  6. _FoamC("Foam", Color) = (1, 1, 1, .5)
  7. _MainTex ("Main Texture", 2D) = "white" {}
  8. _TextureDistort("Texture Wobble", range(0,1)) = 0.1
  9. _NoiseTex("Extra Wave Noise", 2D) = "white" {}
  10. _Speed("Wave Speed", Range(0,1)) = 0.5
  11. _Amount("Wave Amount", Range(0,1)) = 0.6
  12. _Scale("Scale", Range(0,1)) = 0.5
  13. _Height("Wave Height", Range(0,1)) = 0.1
  14. _Foam("Foamline Thickness", Range(0,10)) = 8
  15. }
  16. SubShader
  17. {
  18. Tags { "RenderType"="Opaque" "Queue" = "Transparent" }
  19. LOD 100
  20. Blend OneMinusDstColor One
  21. Cull Off
  22.  
  23. GrabPass{
  24. Name "BASE"
  25. Tags{ "LightMode" = "Always" }
  26. }
  27. Pass
  28. {
  29. CGPROGRAM
  30. #pragma vertex vert
  31. #pragma fragment frag
  32. // make fog work
  33. #pragma multi_compile_fog
  34.  
  35. #include "UnityCG.cginc"
  36.  
  37. struct appdata
  38. {
  39. float4 vertex : POSITION;
  40. float2 uv : TEXCOORD0;
  41. };
  42.  
  43. struct v2f
  44. {
  45. float2 uv : TEXCOORD3;
  46. UNITY_FOG_COORDS(1)
  47. float4 vertex : SV_POSITION;
  48. float4 scrPos : TEXCOORD2;//
  49. float4 worldPos : TEXCOORD4;//
  50. };
  51. float _TextureDistort;
  52. float4 _Color;
  53. sampler2D _CameraDepthTexture; //Depth Texture
  54. sampler2D _MainTex, _NoiseTex;//
  55. float4 _MainTex_ST;
  56. float _Speed, _Amount, _Height, _Foam, _Scale;//
  57. float4 _FoamC;
  58.  
  59. v2f vert (appdata v)
  60. {
  61. v2f o;
  62. UNITY_INITIALIZE_OUTPUT(v2f, o);
  63. float4 tex = tex2Dlod(_NoiseTex, float4(v.uv.xy, 0, 0));//extra noise tex
  64. v.vertex.y += sin(_Time.z * _Speed + (v.vertex.x * v.vertex.z * _Amount * tex)) * _Height;//movement
  65. o.vertex = UnityObjectToClipPos(v.vertex);
  66. o.worldPos = mul(unity_ObjectToWorld, v.vertex);
  67.  
  68. o.uv = TRANSFORM_TEX(v.uv, _MainTex);
  69. o.scrPos = ComputeScreenPos(o.vertex);
  70. UNITY_TRANSFER_FOG(o,o.vertex);
  71. return o;
  72. }
  73.  
  74. fixed4 frag (v2f i) : SV_Target
  75. {
  76. // sample the texture
  77. fixed distortx = tex2D(_NoiseTex, (i.worldPos.xz * _Scale) + (_Time.x * 2)).r;// distortion alpha
  78.  
  79. half4 col = tex2D(_MainTex, (i.worldPos.xz * _Scale) - (distortx * _TextureDistort));// texture times tint;
  80. half depth = LinearEyeDepth(SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.scrPos ))); // depth
  81. half4 foamLine =1 - saturate(_Foam* (depth - i.scrPos.w ) ) ;// foam line by comparing depth and screenposition
  82. col *= _Color;
  83. col += (step(0.4 * distortx,foamLine) * _FoamC); // add the foam line and tint to the texture
  84. col = saturate(col) * col.a ;
  85.  
  86. return col;
  87. }
  88. ENDCG
  89. }
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement