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); }
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))); } } }
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))); } } }
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)); } } }