SHARE
TWEET

Untitled

a guest Nov 19th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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,10)) = 0.5
  10.         _Height("Wave Height", Range(0,10)) = 0.5
  11.         _Foam("Foamline Thickness", Range(0,3)) = 0.5
  12.             [Toggle(SATURATE)] _SATURATE("Saturate", Float) = 1
  13.  
  14.     }
  15.         SubShader
  16.         {
  17.             Tags { "RenderType" = "Opaque"  "Queue" = "Transparent" }
  18.             LOD 100
  19.             Blend SrcAlpha OneMinusSrcAlpha
  20.  
  21.             Pass
  22.             {
  23.                 CGPROGRAM
  24.                 #pragma vertex vert
  25.                 #pragma fragment frag
  26.                 // make fog work
  27.                 #pragma multi_compile_fog
  28.             #pragma shader_feature SATURATE
  29.  
  30.                 #include "UnityCG.cginc"
  31.  
  32.                 struct appdata
  33.                 {
  34.                     float4 vertex : POSITION;
  35.                     float2 uv : TEXCOORD0;
  36.                 };
  37.  
  38.                 struct v2f
  39.                 {
  40.                     float2 uv : TEXCOORD0;
  41.                     UNITY_FOG_COORDS(1)
  42.                     float4 vertex : SV_POSITION;
  43.                     float4 scrPos : TEXCOORD1;//
  44.                 };
  45.  
  46.                 float4 _Tint;
  47.                 uniform sampler2D _CameraDepthTexture; //Depth Texture
  48.                 sampler2D _MainTex, _NoiseTex;//
  49.                 float4 _MainTex_ST;
  50.                 float _Speed, _Amount, _Height, _Foam;//
  51.  
  52.                 v2f vert(appdata v)
  53.                 {
  54.                     v2f o;
  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 = (_Foam * (depth - i.scrPos.w));// foam line by comparing depth and screenposition
  70. #if SATURATE
  71.                      foamLine = saturate(_Foam * (depth - i.scrPos.w));// foam line by comparing depth and screenposition
  72. #endif
  73.  
  74.                     col = (foamLine * _Amount) * _Tint; // add the foam line and tint to the texture
  75.  
  76.                     return col;
  77.                 }
  78.                 ENDCG
  79.             }
  80.         }
  81. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top