码迷,mamicode.com
首页 > 编程语言 > 详细

Unity3D Shader水波效果

时间:2017-10-11 18:14:04      阅读:456      评论:0      收藏:0      [点我收藏+]

标签:png   image   unit   com   div   ges   matrix   fixed   ret   

水波效果

技术分享

 

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水波效果

标签:png   image   unit   com   div   ges   matrix   fixed   ret   

原文地址:http://www.cnblogs.com/mrblue/p/7651714.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!