hey,

since blurring is quite important in many shaders I thought I could give you a little speedup. Cards can filter samples in a bilinear way, thus saving you half the samples when calculating something like a gaussian blur. so here
Code:
samples[width_] := Module[{t, p, l, w},
  w = Max[Round[width], 1];
  t = Table[
    N[PDF[NormalDistribution[0, w/2.2], x]], {x, -w - .5, w + .5}];
  p = Partition[t, 2];
  {#[[1]] + #[[2]], 1 - #[[1]]/(#1[[1]] + #1[[2]])} & /@ p
  ]


is the generating code for anyone who wants to use it and here are some sample kernels:
4
Code:
{{0.0653515, 0.833874}, {0.433296, 0.631295}, {0.433296, 
  0.368705}, {0.0653515, 0.166126}}


6
Code:
{{0.0341105, 0.724721}, {0.149481, 0.641251}, {0.312518, 
  0.548249}, {0.312518, 0.451751}, {0.149481, 0.358749}, {0.0341105, 
  0.275279}}


10
Code:
{{0.0178401, 0.631295}, {0.0457636, 0.60307}, {0.0927521, 
  0.574141}, {0.148539, 0.544695}, {0.187973, 0.514934}, {0.187973, 
  0.485066}, {0.148539, 0.455305}, {0.0927521, 0.425859}, {0.0457636, 
  0.39693}, {0.0178401, 0.368705}}


16
Code:
{{0.0105133, 0.579974}, {0.0191392, 0.569459}, {0.0319842, 
  0.558881}, {0.0490657, 0.548249}, {0.0690956, 0.537573}, {0.0893212,
   0.526863}, {0.105996, 0.516128}, {0.115467, 0.505378}, {0.115467, 
  0.494622}, {0.105996, 0.483872}, {0.0893212, 0.473137}, {0.0690956, 
  0.462427}, {0.0490657, 0.451751}, {0.0319842, 0.441119}, {0.0191392,
   0.430541}, {0.0105133, 0.420026}}



If you need any specific sizes you can ask me. Usage is as follows:
Code:
static const float2 kernel[NUM]=...; // here goes the sample output I posted above

for(int i = 0; i < NUM; i++)
{
	pixel = tex2D(mytex,texcoord0 + float2(kernel[i].y-NUM+2*i,0)/resolution_x)*kernel[i].x;
	color += pixel;
}



same goes for the y direction, so you need to do two passes. Could be that the kernel is off one pixel, I'm not sure atm, but the shader gurus (for whom this is intended) should be able to tell.

Joey

btw. you could replace the NormalDistribution by anything you like.



Last edited by Joey; 06/06/11 21:46. Reason: divide offset by resolution