Guest User

SimpleWater.shader

a guest
Oct 30th, 2017
11,828
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. Shader "Unlit/SimpleWater"
  2. {
  3. Properties
  4. {
  5. _Tint("Tint", Color) = (1, 1, 1, .5)
  6. _MainTex ("Main Texture", 2D) = "white" {}
  7. _NoiseTex("Extra Wave Noise", 2D) = "white" {}
  8. _Speed("Wave Speed", Range(0,1)) = 0.5
  9. _Amount("Wave Amount", Range(0,1)) = 0.5
  10. _Height("Wave Height", Range(0,1)) = 0.5
  11. _Foam("Foamline Thickness", Range(0,3)) = 0.5
  12.  
  13. }
  14. SubShader
  15. {
  16. Tags { "RenderType"="Opaque" "Queue" = "Transparent" }
  17. LOD 100
  18. Blend SrcAlpha OneMinusSrcAlpha
  19.  
  20. Pass
  21. {
  22. CGPROGRAM
  23. #pragma vertex vert
  24. #pragma fragment frag
  25. // make fog work
  26. #pragma multi_compile_fog
  27.  
  28. #include "UnityCG.cginc"
  29.  
  30. struct appdata
  31. {
  32. float4 vertex : POSITION;
  33. float2 uv : TEXCOORD0;
  34. };
  35.  
  36. struct v2f
  37. {
  38. float2 uv : TEXCOORD0;
  39. UNITY_FOG_COORDS(1)
  40. float4 vertex : SV_POSITION;
  41. float4 scrPos : TEXCOORD1;//
  42. };
  43.  
  44. float4 _Tint;
  45. uniform sampler2D _CameraDepthTexture; //Depth Texture
  46. sampler2D _MainTex, _NoiseTex;//
  47. float4 _MainTex_ST;
  48. float _Speed, _Amount, _Height, _Foam;//
  49.  
  50. v2f vert (appdata v)
  51. {
  52. v2f o;
  53. float4 tex = tex2Dlod(_NoiseTex, float4(v.uv.xy, 0, 0));//extra noise tex
  54. v.vertex.y += sin(_Time.z * _Speed + (v.vertex.x * v.vertex.z * _Amount * tex)) * _Height;//movement
  55. o.vertex = UnityObjectToClipPos(v.vertex);
  56. o.uv = TRANSFORM_TEX(v.uv, _MainTex);
  57. o.scrPos = ComputeScreenPos(o.vertex); // grab position on screen
  58. UNITY_TRANSFER_FOG(o,o.vertex);
  59.  
  60. return o;
  61. }
  62.  
  63. fixed4 frag (v2f i) : SV_Target
  64. {
  65. // sample the texture
  66.  
  67. half4 col = tex2D(_MainTex, i.uv) * _Tint;// texture times tint;
  68. half depth = LinearEyeDepth(SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.scrPos))); // depth
  69. half4 foamLine =1 - saturate(_Foam * (depth - i.scrPos.w));// foam line by comparing depth and screenposition
  70. col += foamLine * _Tint; // add the foam line and tint to the texture
  71. return col ;
  72. }
  73. ENDCG
  74. }
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment