Advertisement
Guest User

worldSpaceWave

a guest
Oct 13th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
  2.  
  3. Shader "Unlit/SimpleWater"
  4. {
  5.     Properties
  6.     {
  7.         _Tint("Tint", Color) = (1, 1, 1, .5)
  8.         _MainTex ("Main Texture", 2D) = "white" {}
  9.         _NoiseTex("Extra Wave Noise", 2D) = "white" {}
  10.         _Speed("Wave Speed", Range(0,1)) = 0.5
  11.         _Amount("Wave Amount", Range(0,1)) = 0.5
  12.         _Height("Wave Height", Range(0,1)) = 0.5
  13.         _Foam("Foamline Thickness", Range(0,3)) = 0.5
  14.        
  15.     }
  16.     SubShader
  17.     {
  18.         Tags { "RenderType"="Opaque"  "Queue" = "Transparent" }
  19.         LOD 100
  20.         Blend SrcAlpha OneMinusSrcAlpha
  21.  
  22.         Pass
  23.         {
  24.             CGPROGRAM
  25.             #pragma vertex vert
  26.             #pragma fragment frag
  27.             // make fog work
  28.             #pragma multi_compile_fog
  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.                 worldPos = mul (unity_ObjectToWorld, v.vertex);
  56.                 v.vertex.y += sin(_Time.z * _Speed + (worldPos.x * worldPos.z *_Amount)) * _Height;//movement
  57.                 o.vertex = UnityObjectToClipPos(v.vertex);
  58.                 o.uv = TRANSFORM_TEX(v.uv, _MainTex);
  59.                 o.scrPos = ComputeScreenPos(o.vertex); // grab position on screen
  60.                 UNITY_TRANSFER_FOG(o,o.vertex);
  61.                
  62.                 return o;
  63.             }
  64.            
  65.             fixed4 frag (v2f i) : SV_Target
  66.             {
  67.                 // sample the texture
  68.            
  69.                 half4 col = tex2D(_MainTex, i.uv) * _Tint;// texture times tint;
  70.                 half depth = LinearEyeDepth(SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.scrPos))); // depth
  71.                 half4 foamLine =1 - saturate(_Foam * (depth - i.scrPos.w));// foam line by comparing depth and screenposition
  72.                 col += foamLine * _Tint; // add the foam line and tint to the texture
  73.                 return col ;
  74.             }
  75.             ENDCG
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement