📄 normalmapper.cpp
字号:
if (strstr (args, "X") != NULL)
{
gNormalRules = NORM_RULE_FRONT_BEST_FURTHEST;
}
}
if (strstr (args, "d") != NULL)
{
gNormalRules = NORM_RULE_MIXED;
}
if (strstr (args, "D") != NULL)
{
gNormalRules = NORM_RULE_BEST_MIXED;
}
if (strstr (args, "b") != NULL)
{
gNormalRules = NORM_RULE_BEST;
}
// Misc flags
if (strstr (args, "m") != NULL)
{
gComputeMipLevels = MIP_RECOMPUTE;
}
if (strstr (args, "M") != NULL)
{
gComputeMipLevels = MIP_BOX;
}
if ((strstr (args, "w") != NULL) ||
(strstr (args, "W") != NULL))
{
gInTangentSpace = false;
}
if ((strstr (args, "e") != NULL) ||
(strstr (args, "E") != NULL))
{
gExpandTexels = false;
}
if (strstr (args, "t") != NULL)
{
gEpsilon = EPSILON;
}
if (strstr (args, "T") != NULL)
{
gEpsilon = 0.0;
}
if (strstr (args, "h") != NULL)
{
gOutput = NORM_OUTPUT_16_16_ARG;
}
if (strstr (args, "H") != NULL)
{
gOutput = NORM_OUTPUT_16_16_16_16_ARG;
}
if (strstr (args, "i") != NULL)
{
gOutput = NORM_OUTPUT_10_10_10_2_ARG;
}
if (strstr (args, "s") != NULL)
{
gOutput = NORM_OUTPUT_10_10_10_2_ARG_MS;
}
if (strstr (args, "S") != NULL)
{
gOutput = NORM_OUTPUT_11_11_10_ARG_MS;
}
if (strstr (args, "B") != NULL)
{
gBoxFilter = true;
}
}
//////////////////////////////////////////////////////////////////////////
// Entry point
//////////////////////////////////////////////////////////////////////////
void
main (int argc, char **argv)
{
NmPrint ("NormalMapper v01.05.01\n");
// Get the arguments.
char* lowName;
char* highName;
char* bumpName = NULL;
double bumpScale;
char* outName;
// Print out verbose message if 0 or 1 arguments given.
if ((argc == 1) || (argc == 2))
{
NmPrint ("Usage: NormalMapper [-12345bBcCdDefFhHimsStTvwX] lowres highres Width Height [value] [heightmap heightscale] outputname\n");
NmPrint (" h - Output 16x16 .arg texture\n");
NmPrint (" H - Output 16x16x16x16 .arg texture\n");
NmPrint (" i - Output 10x10x10x2 .arg texture\n");
NmPrint (" w - Use worldspace normals\n");
NmPrint (" m - Create mip chain (remap)\n");
NmPrint (" M - Create mip chain (box filter)\n");
NmPrint (" B - Box filter final image\n");
NmPrint (" e - Don't expand border texels\n");
NmPrint (" t - smaller tolerance on compare\n");
NmPrint (" T - no tolerance on compare\n");
NmPrint (" X - only normals in front\n");
NmPrint (" v - value is the maximum distance\n");
NmPrint (" 1 - Single sample per texel\n");
NmPrint (" 2 - Two samples per texel\n");
NmPrint (" 3 - Three samples per texel\n");
NmPrint (" 4 - Four samples per texel\n");
NmPrint (" 5 - Five samples per texel\n");
NmPrint (" 6 - Nine samples per texel\n");
NmPrint (" 7 - Thirteen samples per texel\n");
NmPrint (" 8 - Twenty one samples per texel\n");
NmPrint (" 9 - Thrity seven samples per texel\n");
NmPrint (" 0 - Fifty seven samples per texel\n");
NmPrint (" c - Pick closest intersection,\n");
NmPrint (" first if equidistant\n");
NmPrint (" C - Pick closest intersection,\n");
NmPrint (" normal closer to low res if equidistant\n");
NmPrint (" f - Pick furthest intersection,\n");
NmPrint (" first if equidistant\n");
NmPrint (" F - Pick furthest intersection,\n");
NmPrint (" normal closer to low res if equidistant\n");
NmPrint (" d - Pick furthest intersection in front,\n");
NmPrint (" closest intersection behind,\n");
NmPrint (" first if equidistant\n");
NmPrint (" D - Pick Pick furthest intersection in front,\n");
NmPrint (" normal closer to low res if equidistant,\n");
NmPrint (" closest intersection behind,\n");
NmPrint (" b - normal closest to low res\n");
NmPrint (" s - Microsoft 10x10x10x2 test (16x16x16x16\n");
NmPrint (" S - Microsoft 11x11x10 test (16x16x16x16\n");
exit (-1);
}
// Make sure the right number of arguments are present.
if ((argc != 6) && (argc != 7) && (argc != 8) && (argc != 9) && (argc != 10))
{
NmPrint ("Usage: NormalMapper [-12345bcCdDfFmtTvwXhH] lowres highres Width Height [value] [heightmap heightscale] outputname\n");
exit (-1);
}
// No heightmap, no arguments.
gEpsilon = 0.1;
if (argc == 6)
{
lowName = argv[1];
highName = argv[2];
gWidth = atoi (argv[3]);
gHeight = atoi (argv[4]);
outName = argv[5];
}
// Command line arguments
if (argc == 7)
{
lowName = argv[2];
highName = argv[3];
gWidth = atoi (argv[4]);
gHeight = atoi (argv[5]);
outName = argv[6];
TestArgs (argv[1]);
}
// Height map no command line args, or distance with arguments.
if (argc == 8)
{
if (strstr (argv[1], "-") != NULL)
{
if (strstr (argv[1], "v") == NULL)
{
NmPrint ("Usage: NormalMapper [-12345bcCdDfFmtTvwXhH] lowres highres Width Height [value] [heightmap heightscale] outputname\n");
exit (-1);
}
lowName = argv[2];
highName = argv[3];
gWidth = atoi (argv[4]);
gHeight = atoi (argv[5]);
gDistance = atof (argv[6]);
outName = argv[7];
TestArgs (argv[1]);
}
else
{
gNormalRules = NORM_RULE_CLOSEST;
lowName = argv[1];
highName = argv[2];
gWidth = atoi (argv[3]);
gHeight = atoi (argv[4]);
bumpName = argv[5];
bumpScale = atof (argv[6]);
outName = argv[7];
}
}
// Commandline arguments and heightmap
if (argc == 9)
{
gNormalRules = NORM_RULE_CLOSEST;
lowName = argv[2];
highName = argv[3];
gWidth = atoi (argv[4]);
gHeight = atoi (argv[5]);
bumpName = argv[6];
bumpScale = atof (argv[7]);
outName = argv[8];
TestArgs (argv[1]);
}
// Commandline arguments, heightmap, and distance
if (argc == 10)
{
if (strstr (argv[1], "v") == NULL)
{
NmPrint ("Usage: NormalMapper [-12345bcCdDfFmtTvwXhH] lowres highres Width Height [value] [heightmap heightscale] outputname\n");
exit (-1);
}
gNormalRules = NORM_RULE_CLOSEST;
lowName = argv[2];
highName = argv[3];
gWidth = atoi (argv[4]);
gHeight = atoi (argv[5]);
gDistance = atof (argv[6]);
bumpName = argv[7];
bumpScale = atof (argv[8]);
outName = argv[9];
TestArgs (argv[1]);
}
// Check width and height
if ((gWidth % 2) != 0)
{
NmPrint ("ERROR: Width must be a power of two!\n");
exit (-1);
}
if ((gHeight % 2) != 0)
{
NmPrint ("ERROR: Height must be a power of two!\n");
exit (-1);
}
if (gWidth < 1)
{
NmPrint ("ERROR: Width must be greater than 0\n");
exit (-1);
}
if (gHeight < 1)
{
NmPrint ("ERROR: Height must be greater than 0\n");
exit (-1);
}
// Print out options
NmPrint ("Width: %d Height: %d\n", gWidth, gHeight);
NmPrint ("%d samples per texel\n", gNumSamples);
switch (gNormalRules)
{
case NORM_RULE_CLOSEST:
NmPrint ("Normal Rule: Closest\n");
break;
case NORM_RULE_BEST_CLOSEST:
NmPrint ("Normal Rule: Best Closest\n");
break;
case NORM_RULE_BEST_FARTHEST:
NmPrint ("Normal Rule: Best Furthest\n");
break;
case NORM_RULE_FARTHEST:
NmPrint ("Normal Rule: Furthest\n");
break;
case NORM_RULE_MIXED:
NmPrint ("Normal Rule: Mixed\n");
break;
case NORM_RULE_BEST_MIXED:
NmPrint ("Normal Rule: Best Mixed\n");
break;
case NORM_RULE_BEST:
NmPrint ("Normal Rule: Best\n");
break;
case NORM_RULE_FRONT_FURTHEST:
NmPrint ("Normal Rule: Front Furthest\n");
break;
case NORM_RULE_FRONT_BEST_FURTHEST:
NmPrint ("Normal Rule: Front Best Furthest\n");
break;
case NORM_RULE_FRONT_CLOSEST:
NmPrint ("Normal Rule: Front Closest\n");
break;
case NORM_RULE_FRONT_BEST_CLOSEST:
NmPrint ("Normal Rule: Front Best Closest\n");
break;
default:
NmPrint ("Normal Rule: UKNOWN!\n");
break;
}
if (gDistance != FLT_MAX)
{
NmPrint ("Max distance: %4.12\n", gDistance);
}
switch (gComputeMipLevels)
{
case MIP_NONE:
NmPrint ("No mipmap generation\n");
break;
case MIP_RECOMPUTE:
NmPrint ("Re-cast mipmap generation.\n");
break;
case MIP_BOX:
NmPrint ("Box filter mip map generation.\n");
break;
default:
NmPrint ("Unknown mip map generation\n");
break;
}
NmPrint ("Epsilon: %1.10f\n", gEpsilon);
if (gInTangentSpace)
{
NmPrint ("Normals in tangent space\n");
}
else
{
NmPrint ("Normals in world space\n");
}
if (gExpandTexels)
{
NmPrint ("Expand border texels\n");
}
else
{
NmPrint ("Don't Expand border texels\n");
}
if (gBoxFilter)
{
NmPrint ("Postprocess box filter\n");
}
else
{
NmPrint ("No postprocess filter\n");
}
// Get bump map from height map.
float* bumpMap = NULL;
int bumpWidth = 0;
int bumpHeight = 0;
if (bumpName != NULL)
{
NmPrint ("Bump Scale: %2.4f\n", bumpScale);
NmPrint ("Reading in height map: %s\n", bumpName);
GetBumpMapFromHeightMap (bumpName, &bumpWidth, &bumpHeight, &bumpMap,
(float)bumpScale);
}
// Read in the low res model
// FILE* fp = fopen (lowName, "rb");
FILE* fp = fopen (lowName, "r");
if (fp == NULL)
{
NmPrint ("ERROR: Unable to open %s\n", lowName);
exit (-1);
}
int lowNumTris;
NmRawTriangle* lowTris;
// if (NmReadTriangles (fp, &lowNumTris, &lowTris) == false)
if (SMDReadTriangles (fp, &lowNumTris, &lowTris) == false)
{
NmPrint ("ERROR: Unable to read %s\n", lowName);
fclose (fp);
exit (-1);
}
fclose (fp);
NmPrint ("Found %d triangles in low res model\n", lowNumTris);
// Check low res model to make sure it's textures are in range
double loBbox[6];
loBbox[0] = FLT_MAX; // X min
loBbox[1] = FLT_MAX; // Y min
loBbox[2] = FLT_MAX; // Z min
loBbox[3] = -FLT_MAX; // X max
loBbox[4] = -FLT_MAX; // Y max
loBbox[5] = -FLT_MAX; // Z max
for (int i = 0; i < lowNumTris; i++)
{
for (int j = 0; j < 3; j++)
{
// Find bounding box.
for (int k = 0; k < 3; k++)
{
if (lowTris[i].vert[j].v[k] < loBbox[k])
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -