Flow Map

Shader "may/FlowMap"
{
    Properties
    {
        _ColorTint ("Color Tint",       Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)",       2D) = "white" {}

        _FlowMap("Flow Map",            2D) = "black"{}
        _FlowSpeed ("Flow Speed",       Range(0,10)) = 0.5
        _FlowStrength("Flow Strength",  Range(0.001, 10)) = 1

        [Toggle] _reverse_flow ("inverse flow dir ", Int) = 0
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        pass
        {
            Name "FlowMap"
            Tags{"LightMode" = "ForwardBase"}
            CGPROGRAM
            #include "UnityCG.cginc"
            #include "Lighting.cginc"
            #include "AutoLight.cginc"
            #pragma vertex vert
            #pragma fragment frag 
            #pragma multi_compile_fwdbase
            #pragma shader_feature _REVERSE_FLOW_ON
            fixed4 _ColorTint;
            sampler2D _MainTex;
            float4 _MainTex_ST;
            sampler2D _FlowMap;
            float4 _FlowMap_ST;
            half _FlowSpeed;
            half _FlowStrength;

            struct a2v 
            {
                float4 vertex:POSITION;
                float2 uv:TEXCOORD;
            };
            struct v2f 
            {
                float4 pos:SV_POSITION;
                float4 uv:TEXCOORD;
            };
            v2f vert(a2v v)
            {
                v2f o;
                o.pos = UnityObjectToClipPos(v.vertex);
                o.uv.xy = TRANSFORM_TEX(v.uv, _MainTex);
                o.uv.zw = TRANSFORM_TEX(v.uv, _FlowMap);
                return o;
            }
            fixed4 frag(v2f i):SV_TARGET0
            {
                half2 uvoffset = tex2D(_FlowMap, i.uv.zw) *2 - half2(1, 1);
                #ifdef _REVERSE_FLOW_ON
                uvoffset*=-1;
                #endif
                uvoffset *= _FlowStrength;
                fixed function1 = frac(_Time.y * _FlowSpeed );                      //偏移程度1
                fixed function2 = frac(_Time.y * _FlowSpeed + 0.5);              //偏移程度2
                fixed3 texColor1 = tex2D(_MainTex, i.uv.xy + uvoffset * function1);    
                fixed3 texColor2 = tex2D(_MainTex, i.uv.xy + uvoffset * function2);
                fixed3 baseColorTex = lerp(texColor1, texColor2, abs(function1 - 0.5) * 2 );

                return fixed4( baseColorTex , 1);
            }
            ENDCG
        }
    }
    FallBack "Diffuse"
}

周期性的 从 i.uv 向 i.uv + uvoffsetTex偏移,并采样_MainTex
但是这样会造成突变,
所以,相差半个相位两次采样_MainTex,并且混合采样结果时,相位接近 PI 权重高。

视频资料 图形 Flowmap实现

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值