Created
February 19, 2020 19:45
-
-
Save jhorikawa/5f9368ca5bce35192589ad5293a86108 to your computer and use it in GitHub Desktop.
2D Gaussian Blur for Houdini using VEX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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