From 7de098e11d6c04812fcc0e8b4ace3f8f921c7c96 Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Sat, 16 Apr 2011 20:04:05 +0200 Subject: [PATCH] add a highpass feature too --- misc/tools/fft-normalmap-to-heightmap.c | 31 ++++++++++++++++++++----- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/misc/tools/fft-normalmap-to-heightmap.c b/misc/tools/fft-normalmap-to-heightmap.c index 78e7e020..c9368674 100644 --- a/misc/tools/fft-normalmap-to-heightmap.c +++ b/misc/tools/fft-normalmap-to-heightmap.c @@ -35,7 +35,7 @@ #define TWO_PI (4*atan2(1,1) * 2) -void nmap_to_hmap(unsigned char *map, const unsigned char *refmap, int w, int h, double scale, double offset, const double *filter, int filterw, int filterh, int renormalize) +void nmap_to_hmap(unsigned char *map, const unsigned char *refmap, int w, int h, double scale, double offset, const double *filter, int filterw, int filterh, int renormalize, double highpass) { int x, y; int i, j; @@ -106,6 +106,10 @@ void nmap_to_hmap(unsigned char *map, const unsigned char *refmap, int w, int h, { fx = x * 1.0 / w; fy = y * 1.0 / h; + if(fx > 0.5) + fx -= 1; + if(fy > 0.5) + fy -= 1; if(filter) { // discontinous case @@ -168,10 +172,6 @@ void nmap_to_hmap(unsigned char *map, const unsigned char *refmap, int w, int h, else { // continuous integration case - if(fx > 0.5) - fx -= 1; - if(fy > 0.5) - fy -= 1; /* these must have the same sign as fx and fy (so ffx*fx + ffy*fy is nonzero), otherwise do not matter */ /* it basically decides how artifacts are distributed */ ffx = fx; @@ -193,6 +193,22 @@ void nmap_to_hmap(unsigned char *map, const unsigned char *refmap, int w, int h, freqspace1[(w*y+x)][0] = 0; freqspace1[(w*y+x)][1] = 0; } +#endif + } + if(highpass > 0) + { + double f1 = (fabs(fx)*highpass); + double f2 = (fabs(fy)*highpass); + // if either of them is < 1, phase out (min at 0.5) + double f = + (f1 <= 0.5 ? 0 : (f1 >= 1 ? 1 : ((f1 - 0.5) * 2.0))) + * + (f2 <= 0.5 ? 0 : (f2 >= 1 ? 1 : ((f2 - 0.5) * 2.0))); +#ifdef C99 + freqspace1[(w*y+x)] *= f; +#else + freqspace1[(w*y+x)][0] *= f; + freqspace1[(w*y+x)][1] *= f; #endif } } @@ -1034,6 +1050,7 @@ int main(int argc, char **argv) double scale, offset; int nmaplen, w, h; int renormalize = 0; + double highpass = 0; unsigned char *nmapdata, *nmap, *refmap; const char *filtertype; const double *filter = NULL; @@ -1079,6 +1096,8 @@ int main(int argc, char **argv) if(getenv("FFT_NORMALMAP_TO_HEIGHTMAP_RENORMALIZE")) renormalize = atoi(getenv("FFT_NORMALMAP_TO_HEIGHTMAP_RENORMALIZE")); + if(getenv("FFT_NORMALMAP_TO_HEIGHTMAP_HIGHPASS")) + highpass = atof(getenv("FFT_NORMALMAP_TO_HEIGHTMAP_HIGHPASS")); nmapdata = FS_LoadFile(infile, &nmaplen); if(!nmapdata) @@ -1141,7 +1160,7 @@ int main(int argc, char **argv) hmap_to_nmap(nmap, image_width, image_height, -scale-1, offset); } else - nmap_to_hmap(nmap, refmap, image_width, image_height, scale, offset, filter, filterw, filterh, renormalize); + nmap_to_hmap(nmap, refmap, image_width, image_height, scale, offset, filter, filterw, filterh, renormalize, highpass); if(!Image_WriteTGABGRA(outfile, image_width, image_height, nmap)) { -- 2.39.2