unity shader简单流体效果

代码部分 

创建一个表面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添加至该材质中,再将该材质添加到任意物体即可

效果:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值