tonynogo

Demo 10 - Water distortion

Jul 6th, 2017
9,699
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/WaterDistortion" {
  2.     Properties {
  3.         _MainTex ("Main texture", 2D) = "white" {}
  4.         _NoiseTex ("Noise texture", 2D) = "grey" {}
  5.  
  6.         _Mitigation ("Distortion mitigation", Range(1, 30)) = 1
  7.         _SpeedX("Speed along X", Range(0, 5)) = 1
  8.         _SpeedY("Speed along Y", Range(0, 5)) = 1
  9.     }
  10.  
  11.     SubShader {
  12.         Tags { "RenderType"="opaque" }
  13.  
  14.         Pass {
  15.             CGPROGRAM
  16.             #pragma vertex vert
  17.             #pragma fragment frag
  18.             #include "UnityCG.cginc"
  19.  
  20.             sampler2D _MainTex;
  21.             sampler2D _NoiseTex;
  22.             float _SpeedX;
  23.             float _SpeedY;
  24.             float _Mitigation;
  25.  
  26.             struct v2f {
  27.                 half4 pos : SV_POSITION;
  28.                 half2 uv : TEXCOORD0;
  29.             };
  30.  
  31.             fixed4 _MainTex_ST;
  32.  
  33.             v2f vert(appdata_base v) {
  34.                 v2f o;
  35.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
  36.                 o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
  37.                 return o;
  38.             }
  39.  
  40.             half4 frag(v2f i) : COLOR {
  41.                 half2 uv = i.uv;
  42.                 half noiseVal = tex2D(_NoiseTex, uv).r;
  43.                 uv.x = uv.x + noiseVal * sin(_Time.y * _SpeedX) / _Mitigation;
  44.                 uv.y = uv.y + noiseVal * sin(_Time.y * _SpeedY) / _Mitigation;
  45.                 return tex2D(_MainTex, uv);
  46.             }
  47.  
  48.             ENDCG
  49.         }
  50.     }
  51.     FallBack "Diffuse"
  52. }
Advertisement
Add Comment
Please, Sign In to add comment