]> git.xonotic.org Git - xonotic/xonotic.git/commitdiff
simplify normalization
authorRudolf Polzer <divverent@alientrap.org>
Sat, 16 Apr 2011 18:12:47 +0000 (20:12 +0200)
committerRudolf Polzer <divverent@alientrap.org>
Sat, 16 Apr 2011 18:12:47 +0000 (20:12 +0200)
misc/tools/fft-normalmap-to-heightmap.c

index c936867434ac3e4d2b0f7a496d033972c9c63eea..c5b5ea5f8a2a8ff88b849cbe78ca52c0087060e5 100644 (file)
@@ -85,10 +85,10 @@ void nmap_to_hmap(unsigned char *map, const unsigned char *refmap, int w, int h,
                        double v = nx * nx + ny * ny + nz * nz;
                        if(v > 0)
                        {
-                               v = sqrt(v);
-                               nx /= v;
-                               ny /= v;
-                               nz /= v;
+                               v = 1/sqrt(v);
+                               nx *= v;
+                               ny *= v;
+                               nz *= v;
                                map[(w*y+x)*4+2] = floor(nx * 127.5 + 128);
                                map[(w*y+x)*4+1] = floor(ny * 127.5 + 128);
                                map[(w*y+x)*4+0] = floor(nz * 127.5 + 128);