]> git.xonotic.org Git - xonotic/xonotic.git/commitdiff
add a highpass feature too
authorRudolf Polzer <divverent@alientrap.org>
Sat, 16 Apr 2011 18:04:05 +0000 (20:04 +0200)
committerRudolf Polzer <divverent@alientrap.org>
Sat, 16 Apr 2011 18:04:05 +0000 (20:04 +0200)
misc/tools/fft-normalmap-to-heightmap.c

index 78e7e020f0f295f5cdedb4af98ee740437ad6f62..c936867434ac3e4d2b0f7a496d033972c9c63eea 100644 (file)
@@ -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))
        {