Unity shader The Gaussian blur of post-processing effects on the learning screen

Source: Internet
Author: User
Tags abs

Gaussian Blur, see Baidu Encyclopedia.

Convolution is also used to achieve the formula for each convolution element:

Where Bldg is the standard variance, the general value is 1.

The x and y correspond to the integer distance from the current position to the convolution center, respectively.

Because the weights in the Gaussian kernel need to be normalized, even if the ownership is added to 1, the coefficients in front of e will not actually have any effect on the result.

In summary, the formula is simplified to:

G (x, y) = e (x*x+y*y)/2

A 5 * 5 Gaussian kernel Calculation code is as follows:

1 usingSystem;2 3 namespaceTestshell4 {5     class Program6     {7         Static voidMain (string[] args)8         {9             Double[,] r = Calcgaussianblur (5);Ten              for(inti =0; I < R.getlonglength (0); i++) One             { A                  for(intj =0; J < R.getlonglength (1); J + +) -                 { -Console.Write ("{0:f4}\t", R[i, J]); the                 } - Console.WriteLine (); -             } - Console.readkey (); +         } -  +         Static Double[,] Calcgaussianblur (intsize) A         { at             Double[,] r =New Double[size, size]; -             intCenter = (int) Math.floor (Size/2f); -             Doublesum =0; -  -              for(inti =0; i < size; i++) -             { in                  for(intj =0; J < size; J + +) -                 { to                     intx = Math.Abs (i-center); +                     inty = Math.Abs (J-center); -                     DoubleD =Calcitem (x, y); theR[i, J] =D; *Sum + =D; $                 }Panax Notoginseng             } -  the              for(inti =0; i < size; i++) +             { A                  for(intj =0; J < size; J + +) the                 { +R[i, J]/=sum; -                 } $             } $  -             returnR; -         } the  -         Static DoubleCalcitem (intXinty)Wuyi         { the             returnMath.pow (MATH.E,-(x * x + y * y)/2d); -         } Wu     } -}
View Code

The results are as follows:

Unity shader The Gaussian blur of post-processing effects on the learning screen

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.