1.代码
Shader "Custom/WaveScreen"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_NoiseTex("Noise 1",2D) = "white" {}
_Magnitude("magnitue",range(-1,1)) = 0.0
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
sampler2D _NoiseTex;
float _Magnitude;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float2 distuv = float2(i.uv.x + _Time.x * 2, i.uv.y + _Time.x * 2);
float2 disp = tex2D(_NoiseTex, distuv).xy;
disp = ((disp * 2) - 1) * _Magnitude;
float4 col = tex2D(_MainTex, i.uv + disp);
return col;
}
ENDCG
}
}
}
2.噪声图
3.原图,_Magnitude值为0时
4.效果图