暗夜之枪水面shader

Shader "MADFINGER/FX/Anim texture" {
Properties {
    _MainTex ("Base (RGB)", 2D) = "white" {}
    _NumTexTiles("Num tex tiles",    Vector) = (4,4,0,0)
    _ReplaySpeed("Replay speed - FPS",float) = 4
    _Color("Color", Color) = (1,1,1,1)
}

SubShader {

    Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
    
    Blend One One
    Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) }

    CGINCLUDE
    #include "UnityCG.cginc"
    sampler2D _MainTex;
    
    float4    _Color;
    float4    _NumTexTiles;
    float        _ReplaySpeed;
    float        _Randomize;
    
    struct v2f {
        float4 pos : SV_POSITION;
        float4 uv : TEXCOORD0;
        fixed4 col: COLOR;
    };


    float2 Rand(float2 ij)
    {
        const float4 a = float4(97.409091034f,54.598150033f,56.205410758f,44.687805943f);
        float4 result  = float4(ij,ij);

        for(int i = 0; i < 2; i++)
        {
            result.x = frac(dot(result, a));
            result.y = frac(dot(result, a));
            result.z = frac(dot(result, a));
            result.w = frac(dot(result, a));
        }

        return result.xy;
    }

    
    v2f vert (appdata_full v)
    {
        v2f o;
        
        float        time            = (v.color.a * 60 + _Time.y) * _ReplaySpeed;
        float        itime            = floor(time);
        float        ntime        = itime + 1;
        float        ftime            = time - itime;
        
        float2    texTileSize = 1.f / _NumTexTiles.xy;        
        float4    tile;

#if 0
        if (_Randomize > 0)
        {
            itime = floor(Rand(itime) * 1000);
            ntime= floor(Rand(ntime) * 1000);
        }
#endif

        #if 1
        tile.xy = float2(itime,floor(itime /_NumTexTiles.x));
        tile.zw= float2(ntime,floor(ntime /_NumTexTiles.x));
        #endif
        
        
        tile = fmod(tile,_NumTexTiles.xyxy);
        
        o.pos= mul(UNITY_MATRIX_MVP, v.vertex);
        o.uv    = (v.texcoord.xyxy + tile) * texTileSize.xyxy;
        o.col    = float4(_Color.xyz * v.color.xyz,ftime);
        
        
        return o;
    }
    ENDCG


    Pass {
        CGPROGRAM
        #pragma vertex vert
        #pragma fragment frag
        #pragma fragmentoption ARB_precision_hint_fastest        
        //fragmentoption is OpenGL Only
        fixed4 frag (v2f i) : COLOR
        {
            return lerp(tex2D (_MainTex, i.uv.xy),tex2D (_MainTex, i.uv.zw),i.col.a) * i.col;
        }
        ENDCG
    }    
}
}

设置参数:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值