The project needs to add a water reflection effect, and my current project is 2D. 2D reflection is much better than 3D. Just use grabpass to grab the screen, reverse the uv, add an offset value, and finally use a Just use the trigonometric function to offset the uv coordinates
The effect is as follows
(gif is a bit blurry)
parameter panel
full code
Shader "LX/postDistortion"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_DistortionScale ("DistortionScale", float) = 0.1
_WaveLength ("WaveLength", float) = 1
_Offset ("Offset", float) = 0
}
SubShader
{
Tags
{
"Queue"="Transparent"
"RenderType"="Opaque"
}
LOD 200
GrabPass
{
"_GrabTex"
}
CGPROGRAM
#pragma surface surf Standard fullforwardshadows
#pragma target 3.0
sampler2D _GrabTex;
float4 _GrabTex_TexelSize;
float _DistortionScale;
float _WaveLength;
float _Offset;
struct Input
{
float4 screenPos;
};
fixed4 _Color;
void surf(Input IN, inout SurfaceOutputStandard o)
{
IN.screenPos.xy /= IN.screenPos.w;
IN.screenPos.y = -IN.screenPos.y + _Offset;
IN.screenPos.x += _DistortionScale * sin(_Time.y + IN.screenPos.y * _WaveLength)*0.01;
fixed4 c = tex2D(_GrabTex, IN.screenPos) * _Color;
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
In addition, the code has also been passed to the github warehouse, you can also pay attention to it~
my github