]> git.mxchange.org Git - flightgear.git/commitdiff
improved normal map calculation
authorehofman <ehofman>
Sun, 14 Mar 2010 13:41:56 +0000 (13:41 +0000)
committerTim Moore <timoore33@gmail.com>
Tue, 16 Mar 2010 14:14:55 +0000 (15:14 +0100)
utils/Modeller/texture.cxx

index 6f744c35dda23fece90a776141333658d6849c97..297345ca537f6df06f476b8490c78e2038607b01 100644 (file)
@@ -901,6 +901,7 @@ SGTexture::make_normalmap(float brightness, float contrast) {
          int yp1 = (y < (texture_height-1)) ? y+1 : 0;
          int posxp1 = (xp1 + ytw)*num_colors;
          int posyp1 = (x + yp1*texture_width)*num_colors;
+         float fx,fy;
 
          GLubyte c = texture_data[dpos];
          GLubyte cx1 = texture_data[posxp1];
@@ -918,8 +919,11 @@ SGTexture::make_normalmap(float brightness, float contrast) {
             map[mpos+3] = a;
          }
 
-         map[mpos+0] = (128+(cx1-c)/2);
-         map[mpos+1] = (128+(cy1-c)/2);
+         fx = asin(((c-cx1)/256.0)-0.5)+0,785398163;
+         fy = asin(((cy1-c)/256.0)-0.5)+0,785398163;
+
+         map[mpos+0] = (GLuint)(fx*256.0);
+         map[mpos+1] = (GLuint)(fy*256.0);
          map[mpos+2] = 127+int(brightness*128); // 255-c/2;
 
          mpos += colors;