Unity3D Shader水波效果

Posted MrBlue

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Unity3D Shader水波效果相关的知识,希望对你有一定的参考价值。

水波效果

 

Shader "Custom/WaterWave" {
    Properties {
        _MainTex ("Base (RGB)", 2D) = "white" {}
        _WaveStrength("Wave Strength",Float) = 0.01
        _WaveFactor("Wave Factor",Float) = 50
        _TimeScale("Time Scale",Float) = 10
    }
    SubShader {
        
        Pass
        {
            CGPROGRAM

            #pragma vertex vert 
            #pragma fragment frag

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;

            };

            struct v2f {
                float4 vertex:SV_POSITION;
                float2 uv:TEXCOORD0;
            };

            sampler2D _MainTex;
            float _WaveStrength;
            float _WaveFactor;
            float _TimeScale;

            v2f vert (appdata v) 
            {
                v2f o;
                o.uv = v.uv;
                o.vertex = mul(UNITY_MATRIX_MVP,v.vertex);

                return o;
            }

            fixed4 frag(v2f IN):COLOR
            {                
                fixed2 uvDir = normalize(IN.uv-fixed2(0.5,0.5));
                fixed dis = distance(IN.uv,fixed2(0.5,0.5));

                fixed2 uv = IN.uv+_WaveStrength*uvDir*sin(_Time.y*_TimeScale+dis*_WaveFactor);
                return tex2D(_MainTex, uv);
            }

            ENDCG
        }

    } 
    FallBack "Diffuse"
}

 

以上是关于Unity3D Shader水波效果的主要内容,如果未能解决你的问题,请参考以下文章

Unity shader 水波 ,模拟雨滴落的水波

蛋哥的学习笔记之-基于Unity的Shader编程:X-1 音乐水波特效

水波shader

Unity3D Shader落雪效果

Unity3D Shader图像扭曲过场效果

Unity3D 2D Sprite描边效果Shader,可手动调整效果适配