From 19b857d9bee99560695c125813d9382669068800 Mon Sep 17 00:00:00 2001 From: ehofman Date: Sun, 14 Mar 2010 13:41:56 +0000 Subject: [PATCH] improved normal map calculation --- utils/Modeller/texture.cxx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/utils/Modeller/texture.cxx b/utils/Modeller/texture.cxx index 6f744c35d..297345ca5 100644 --- a/utils/Modeller/texture.cxx +++ b/utils/Modeller/texture.cxx @@ -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; -- 2.39.5