代码部分
创建一个表面shader
Shader "Custom/DistortionShader"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_DistortionAmount ("Distortion Amount", Range(0, 1)) = 0.1
_DistortionSpeed ("Distortion Speed", Range(0, 1)) = 0.5
}
SubShader
{
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
LOD 200
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma surface surf Standard alpha:fade
sampler2D _MainTex;
float _DistortionAmount;
float _DistortionSpeed;
struct Input
{
float2 uv_MainTex;
float3 worldPos;
};
void surf (Input IN, inout SurfaceOutputStandard o)
{
// 计算扭曲效果
float distortion = sin(_Time.y * _DistortionSpeed + IN.worldPos.x) * _DistortionAmount;
float2 distortionUV = IN.uv_MainTex + float2(distortion, 0);
// 获取扭曲后的颜色
float4 distortedColor = tex2D(_MainTex, distortionUV);
// 设置表面颜色和透明度
o.Albedo = distortedColor.rgb;
o.Alpha = distortedColor.a;
}
ENDCG
}
FallBack "Transparent/Specular"
}
点击该shader,将一张基础图片添加至该shader
创建一个材质,将shader添加至该材质中,再将该材质添加到任意物体即可
效果: