BlueBear icon

Blur.cs

BlueBear | PRO | 12/25/13 04:14:53 PM UTC | 0 ⭐ | 409 👁️ | Never ⏰ | []
C# |

1.64 KB

|

None

|

0 👍

/

0 👎

using UnityEngine;
 
public static class Texture2DExpansion
{
    public static Texture2D Blur(this Texture2D image, int blurSize)
    {
            Texture2D blurred = new Texture2D(image.width, image.height);
            // foreach pixel
        for (int xx = 0; xx < image.width; xx++)
            {
                    for (int yy = 0; yy < image.height; yy++)
                    {
                        float avgR = 0, avgG = 0, avgB = 0, avgA = 0;
                        int blurPixelCount = 0;
                        // average the color
                        for (int x = xx; (x < xx + blurSize && x < image.width); x++)
                        {
                                for (int y = yy; (y < yy + blurSize && y < image.height); y++)
                                {
                                    Color pixel = image.GetPixel(x, y);
                                    avgR += pixel.r;
                                    avgG += pixel.g;
                                    avgB += pixel.b;
                                    avgA += pixel.a;
                                    blurPixelCount++;
                                }
                        }
                        avgR = avgR / blurPixelCount;
                        avgG = avgG / blurPixelCount;
                        avgB = avgB / blurPixelCount;
                avgA = avgA / blurPixelCount;
                // after averaging, set pixel to that color
 
                        for (int x = xx; x < xx + blurSize && x < image.width; x++)
                {
                                for (int y = yy; y < yy + blurSize && y < image.height; y++)
                        {
                                    blurred.SetPixel(x, y, new Color(avgR, avgG, avgB, avgA));
                        }
                }
                }
            }
            blurred.Apply();
            return blurred;
    }
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  • Syutrsz icon
    03/31/26 10:25:03 PM UTC
    text |

    0 B

    |

    0 👍

    /

    0 👎

    Best t33n active cpx link daily updates!
     Copy and paste the link in a new browser tab and then hit enter!
     https://crazyporn.@xxx/members/157354/?asgtbndr=1&play=true&spon=adworld&zone=400
     Remove the @ 
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎