Unity3D 马赛克效果

文字显示过度,有点科技的效果,黑客帝国风???

Unity3D 马赛克效果_第1张图片
shader

v2f vert(appdata_t v)
{
    v2f OUT;
    UNITY_SETUP_INSTANCE_ID(v);
    UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
    OUT.worldPosition = v.vertex;
    OUT.vertex = UnityObjectToClipPos(OUT.worldPosition);

    OUT.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);

    OUT.color = v.color * _Color;
    return OUT;
}

fixed4 frag(v2f IN) : SV_Target
{
    IN.texcoord.x = floor(IN.texcoord.x/_TillSize) * _TillSize;
	IN.texcoord.y = floor(IN.texcoord.y/_TillSize) * _TillSize;
    half4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color;

    #ifdef UNITY_UI_CLIP_RECT
    color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
    #endif

    #ifdef UNITY_UI_ALPHACLIP
    clip (color.a - 0.001);
    #endif

    return color;
}

马赛克代码

public class MasaicUI : MonoBehaviour
{
    public float timeSince = 0f;
    public float endTime = 0f;

    public AnimationCurve alphaSpectrum = new AnimationCurve(new Keyframe(0f, 0.5f), new Keyframe(.15f, 0f));

    public float mocsaic;

    private Material matarial;

    private void OnEnable()
    {
        mocsaic = 0.1f;
        timeSince = 0;
    }

    // Use this for initialization
    void Start()
    {
        matarial = GetComponent<Text>().material;
        endTime = alphaSpectrum.keys[1].time;
        mocsaic = matarial.GetFloat("_TillSize");
    }

    // Update is called once per frame
    void Update()
    {
        if (mocsaic <= 0.0001)
        {
            mocsaic = 0.0001f;
        }

        timeSince += Time.deltaTime;
        mocsaic = alphaSpectrum.Evaluate(timeSince);
        matarial.SetFloat("_TillSize", mocsaic);
    }
}

你可能感兴趣的:(特效)