Skip to content

Instantly share code, notes, and snippets.

@jhorikawa
Created February 19, 2020 19:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhorikawa/5f9368ca5bce35192589ad5293a86108 to your computer and use it in GitHub Desktop.
Save jhorikawa/5f9368ca5bce35192589ad5293a86108 to your computer and use it in GitHub Desktop.
2D Gaussian Blur for Houdini using VEX
float sigma = chf("sigma");
int res = chi("res");
int resx = chi("resx");
int resy = chi("resy");
int resn = floor(res / 2.0);
float weightTotal = 0;
float valTotal = 0;
for(int i=-resn; i<=resn; i++){
for(int n=-resn; n<=resn; n++){
float ix = @ptnum % resx + i;
float iy = floor(@ptnum / float(resx)) + n;
ix = min(max(0, ix), resx-1);
iy = min(max(0, iy), resy-1);
float nu = 1.0 / (2 * $PI * sigma * sigma);
float weight = exp(-(i * i + n * n) / (2 * sigma * sigma)) * nu;
weightTotal += weight;
int ptnum = int(iy * resx + ix);
float val = point(0, "val", ptnum);
val *= weight;
valTotal += val;
}
}
valTotal /= weightTotal;
f@val = valTotal;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment