Advertisement
luluco250

Separable Gaussian

Feb 1st, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. static const int iBlurSamples = 21;
  2.  
  3. inline float GetGaussAccum() {
  4.     int n = iBlurSamples;
  5.     for (int i = 0; i < iBlurSamples; ++i) {
  6.         n += i + i;
  7.     }
  8.     return 1.0 / float(n);
  9. }
  10.  
  11. float3 Gauss(sampler sp, float2 uv, float2 dir) {
  12.     float3 col = tex2D(sp, uv).rgb * float(iBlurSamples);
  13.     static const float accum = GetGaussAccum();
  14.     for (int i = 1; i < iBlurSamples; ++i) {
  15.         float weight = float(iBlurSamples - i);
  16.         col += tex2D(sp, uv + PixelSize * dir * float(i)).rgb * weight;
  17.         col += tex2D(sp, uv - PixelSize * dir * float(i)).rgb * weight;
  18.     }
  19.     return col * accum;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement