UnityShader 学习笔记 17 顶点动画之水流

本文详细介绍了一种使用Unity Shader实现水面波动效果的方法。通过调整Distortion Magnitude、Frequency、Inverse Wave Length和Speed等参数,可以创建逼真的水波纹动画。此Shader支持透明渲染,适用于游戏开发中各种水体效果的制作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



Shader "_MyShader/8_Animation/2_Water"

{

    Properties

    {

        _MainTex ("MainTex", 2D) = "white" {}

            _Color ("Color", COLOR) = (1,1,1,1)

            _Magnitude ("Distortion Magnitude", float) = 1.0

            _Frequency ("Distortion Frequency", float) = 1.0

            _InvWaveLength ("Inverse Wave Length", float) = 10

            _Speed ("Speed", float) = 0.5

    }

    SubShader

    {

        Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RendererType"="Transparent" "DisableBatching"="True"}

        Pass

        {

            Tags { "LightMode"="ForwardBase" }

            ZWrite off

            Blend SrcAlpha OneMinusSrcAlpha

            Cull off



            CGPROGRAM

            #pragma vertex vert

            #pragma fragment frag



            #include "UnityCG.cginc"





            sampler2D _MainTex;

            float4 _MainTex_ST;

            fixed4 _Color;

            float _Magnitude;

            float _Frequency;

            float _InvWaveLength;

            float _Speed;





            struct a2v {

                float4 vertex:POSITION;

                float4 texcoord:TEXCOORD;

            };



            struct v2f {

                float4 pos:SV_POSITION;

                float2 uv:TEXCOORD1;

            };





            v2f vert(a2v v){

                v2f o;

                float4 offset;

                offset.yzw=float3(0,0,0);

                offset.x = sin(_Frequency * _Time.y + v.vertex.x * _InvWaveLength + v.vertex.y * _InvWaveLength + v.vertex.z * _InvWaveLength) * _Magnitude;



                o.pos=mul(UNITY_MATRIX_MVP, v.vertex + offset);



                o.uv=TRANSFORM_TEX(v.texcoord,_MainTex);

                o.uv += float2(0, _Time.y * _Speed);



                return o;

            }





            fixed4 frag(v2f i):SV_Target{

                fixed4 col = tex2D(_MainTex,i.uv);

                col.rgb *= _Color.rgb;

                return col;

            }





            ENDCG

        }

    }



    FallBack "Transparent/VertexLit"

}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值