在Unity中实现了一个简单的屏幕扭曲Shader,对材质纹理进行采样后再与原图像进行混合,效果如下:

Shader屏幕扭曲效果 随笔 第1张

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

Shader屏幕扭曲效果 随笔 第2张

关键代码:

float4 frag(v2f i) : SV_TARGET{
    float2 noise = tex2D(_NoiseTex, i.uv).xy;
    noise = ((noise * 2) - 1) * _Magnitude;
    float4 col = tex2D(_MainTex, i.uv + noise) * _Color;
    return col;
}

完整项目放到了github上,地址:https://github.com/gitctrls/ScreenDistortionShader

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄