From 4329945e744204d9d77c76dd092c684a04ece02a Mon Sep 17 00:00:00 2001 From: ehofman Date: Sun, 14 Mar 2010 12:34:04 +0000 Subject: [PATCH 1/3] be a bit more helpful when the texture file could not be found --- utils/Modeller/normalmap.cxx | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/utils/Modeller/normalmap.cxx b/utils/Modeller/normalmap.cxx index 78daec4ba..d6763de53 100644 --- a/utils/Modeller/normalmap.cxx +++ b/utils/Modeller/normalmap.cxx @@ -35,11 +35,6 @@ int parse_option(char **args, int n) { } sz = strlen(opt); - if (!strncmp(opt, "-help", sz)) { - printf("usage:\n normalmap [-c=contrast] [-b=brightness]"); - printf(" --t=file [--o=file]\n"); - exit(0); - } if (!strncmp(opt, "-contrast", sz)) { contrast = atof(arg); return ret; @@ -58,6 +53,11 @@ int parse_option(char **args, int n) { normalmap_file = strdup(arg); return ret; } + if (!strncmp(opt, "-help", sz)) { + printf("usage:\n normalmap [-c=contrast] [-b=brightness]"); + printf(" --i=file [--o=file]\n\n"); + exit(0); + } return 1; } @@ -71,7 +71,9 @@ int main (int argc, char **argv) if ( !texture_file ) { - printf("Error: texture file not specified\n"); + printf("Error: texture file not specified.\n"); + printf("usage:\n normalmap [-c=contrast] [-b=brightness]"); + printf(" --i=file [--o=file]\n\n"); return -1; } @@ -79,7 +81,7 @@ int main (int argc, char **argv) if ( !texture.texture() ) { printf("Error: unable to process input file: %s\n", texture_file); - printf(" (%s)\n", texture.err_str()); + printf(" (%s)\n\n", texture.err_str()); return -2; } From 19b857d9bee99560695c125813d9382669068800 Mon Sep 17 00:00:00 2001 From: ehofman Date: Sun, 14 Mar 2010 13:41:56 +0000 Subject: [PATCH 2/3] 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; From ff7f8947543babf08a308bda7941a2cf85212e5f Mon Sep 17 00:00:00 2001 From: ehofman Date: Sun, 14 Mar 2010 14:05:14 +0000 Subject: [PATCH 3/3] better calculations. --- utils/Modeller/texture.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/utils/Modeller/texture.cxx b/utils/Modeller/texture.cxx index 297345ca5..3c747e60c 100644 --- a/utils/Modeller/texture.cxx +++ b/utils/Modeller/texture.cxx @@ -919,11 +919,11 @@ SGTexture::make_normalmap(float brightness, float contrast) { map[mpos+3] = a; } - fx = asin(((c-cx1)/256.0)-0.5)+0,785398163; - fy = asin(((cy1-c)/256.0)-0.5)+0,785398163; + fx = asin((c/256.0-cx1/256.0))/1.57079633; + fy = asin((cy1/256.0-c/256.0))/1.57079633; - map[mpos+0] = (GLuint)(fx*256.0); - map[mpos+1] = (GLuint)(fy*256.0); + map[mpos+0] = (GLuint)(fx*256.0)-128; + map[mpos+1] = (GLuint)(fy*256.0)-128; map[mpos+2] = 127+int(brightness*128); // 255-c/2; mpos += colors;