Unity - A.unity - New Unity Project 14 - PC, Mac & Linux Standalone DX11_4  

using UnityEngine;
using System.Collections;

public class Test : MonoBehaviour {

    public Texture2D t;

    [Range(0, 15)]
    public int intensity = 2;

    Texture2D tt;

    void Start () {
        transform.localScale = new Vector3 ((float)t.width/(float)t.height, 1);
        InvokeRepeating ("MyUpdate", 0, 3);
    }

    void MyUpdate () {
        if(tt != null){
            Destroy(tt);
        }
        tt = new Texture2D (t.width, t.height);
        for(int y = 1; y < t.height-1; y++){
            for(int x = 1; x < t.width-1; x++){
                Color c = t.GetPixel(x, y);
                if(intensity > 0){
                    for(int i = 0; i < intensity-1; i++){
                        for(int k = 0; k < intensity-1; k++){
                            c += t.GetPixel(x + i, y + k);
                        }
                    }
                    c = c / Mathf.Pow(intensity, 2) * 1.2f;
                }
                tt.SetPixel(x, y, c);
            }
        }
        tt.Apply ();
        renderer.material.mainTexture = tt;
    }
}




arrow
arrow
    全站熱搜

    黃彥霖 發表在 痞客邦 留言(0) 人氣()