Exemplo n.º 1
0
    public void Start()
    {
        KZTexture texture = new KZTexture(32, 32);
        int edge = 4;
        Color transparent = new Color(0, 0, 0, 0);
        for(int y=0; y<texture.height; y++) {
            for(int x=0; x<texture.width; x++) {
                texture.SetPixel(x, y, transparent);
            }
        }
        for(int y=edge; y<texture.height-edge; y++) {
            for(int x=edge; x<texture.width-edge; x++) {
                texture.SetPixel(x, y, Color.white);
            }
        }
        //for(int y=0; y<texture.height / 2; y++) {
        //    for(int x=0; x<texture.width / 2; x++) {
        //        texture.SetPixel(x, y, Color.black);
        //    }
        //}

        for(int i=0;i<1;i++) {
            texture = KZTexture.BoxBlur(texture);
        }

        Material material = new Material(Shader.Find(DEFAULT_SHADER));
        material.mainTexture = texture.ToTexture2D();
        GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Quad);
        obj.GetComponent<MeshRenderer>().material = material;
    }
Exemplo n.º 2
0
    private static void BlurPixel(
            KZTexture src, KZTexture dest, 
            int x, int y, float[,] kernel)
    {
        Color color = new Color(0, 0, 0, 0);
        Color defaultColor = KZColor.GetColor(src.GetPixel(x, y), 0);
        int index = 0;
        int row = kernel.GetLength(0);
        int col = kernel.GetLength(1);
        int halfRow = row / 2;
        int halfCol = col / 2;

        for(int i=0; i<row; i++) {
            for(int j=0; j<col; j++) {
                Color c = KZColor.Mul(
                        src.GetPixel(x - halfCol + j,
                                     y - halfRow + i, defaultColor),
                        kernel[i, j]);
                color.r += c.r;
                color.g += c.g;
                color.b += c.b;
                color.a += c.a;
            }
        }
        //Debug.Log(color);
        dest.SetPixel(x, y, color);
    }
Exemplo n.º 3
0
    public static KZTexture GetCircle(int radius, Color color)
    {
        int length = 2 * radius;
        KZTexture texture = new KZTexture(length, length);
        float middle = (length - 1) * .5f;
        Vector2 center = new Vector2(middle, middle);
        float sqrRadius = radius * radius;
        Color transparent = new Color(color.r, color.g, color.b, 0);

        for(int i=0; i<texture.width; i++) {
            for(int j=0; j<texture.height; j++) {
                if((new Vector2(i, j) - center).sqrMagnitude < sqrRadius) {
                    texture.SetPixel(i, j, color);
                } else {
                    texture.SetPixel(i, j, transparent);
                    //texture.SetPixel(i, j, Color.black);
                }
            }
        }
        return texture;
    }
Exemplo n.º 4
0
 public static KZTexture GetChequeredTexture(
         int w, int h, 
         Color colorA, 
         Color colorB)
 {
     KZTexture texture = new KZTexture(w, h);
     for(int i=0; i<texture.width; i++) {
         for(int j=0; j<texture.height; j++) {
             Color color = colorA;
             if(Even(i) && Odd(j) || Odd(i) && Even(j)) {
                 color = colorB;
             }
             texture.SetPixel(i, j, color);
         }
     }
     return texture;
 }
Exemplo n.º 5
0
 private static void ApplyPerlin(
         KZTexture texture, float perlinStart, float perlinScale)
 {
     for(int x=0; x<texture.width; x++) {
         float perlin = Mathf.PerlinNoise(
                     perlinStart +
                     (float)x / texture.width * perlinScale, 0);
         for(int y=0; y<texture.height; y++) {
             //Debug.Log(perlin);
             Color c = texture.GetPixel(x, y);
             texture.SetPixel(x, y, new Color(
                     c.r, c.g, c.b, Mathf.Min(1, perlin * c.a)));
         }
     }
 }
Exemplo n.º 6
0
 private static void ApplyNoise(KZTexture texture, float intensity)
 {
     if(intensity == 0) return;
     for(int y=0; y<texture.height; y++) {
         for(int x=0; x<texture.width; x++) {
             Color c = texture.GetPixel(x, y);
             texture.SetPixel(x, y, new Color(
                     c.r, c.g, c.b, c.a + Random.Range(-intensity, intensity)));
         }
     }
 }
Exemplo n.º 7
0
 private static void ApplyGradient(KZTexture texture, 
         float maxAlpha)
 {
     for(int y=0; y<texture.height; y++) {
         float a = maxAlpha - ((float)y/(texture.height-1) * maxAlpha);
         for(int x=0; x<texture.width; x++) {
             Color c = texture.GetPixel(x, y);
             texture.SetPixel(x, y, new Color(c.r, c.g, c.b, c.a * a));
         }
     }
 }
Exemplo n.º 8
0
 private static void ApplyColorWithTint(
         KZTexture texture, Color c, Color tint, float alphaScale)
 {
     for(int y=0; y<texture.height; y++) {
         Color t = KZColor.GetTint(
                 c, tint, (float)y / (texture.height-1));
         for(int x=0; x<texture.width; x++) {
             texture.SetPixel(x, y,
                     new Color(t.r, t.g, t.b, t.a * alphaScale));
         }
     }
 }
Exemplo n.º 9
0
 public void Start()
 {
     KZTexture kzt = new KZTexture(1, 1);
     kzt.SetPixel(0, 0, color);
     GetComponent<Renderer>().material.mainTexture = kzt.ToTexture2D();
 }