Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
2.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //===========================================================================//
  6. #include "tier0/platform.h"
  7. #include "tier0/progressbar.h"
  8. #include "bitmap/float_bm.h"
  9. #include "mathlib/mathlib.h"
  10. #include "tier2/tier2.h"
  11. #include "tier0/memdbgon.h"
  12. static void PrintArgSummaryAndExit( void )
  13. {
  14. printf( "format is 'height2ssbump filename.tga bumpscale'\n" );
  15. printf( "options:\n-r NUM\tSet the number of rays (default = 250. more rays take more time).\n");
  16. printf( "-n\tGenerate a conventional normal map\n" );
  17. printf( "-A\tGenerate ambient occlusion in the alpha channel\n" );
  18. printf( "-f NUM\tSet smoothing filter radius (0=no filter, default = 10)\n");
  19. printf( "-D\tWrite out the filtered result as filterd.tga\n");
  20. exit(1);
  21. }
  22. void main(int argc,char **argv)
  23. {
  24. InitCommandLineProgram( argc, argv );
  25. int nCurArg = 1;
  26. bool bNormalOnly = false;
  27. float flFilterRadius = 10.0;
  28. bool bWriteFiltered = false;
  29. uint32 nSSBumpFlags = 0;
  30. int nNumRays = 250;
  31. while ( ( nCurArg < argc ) && ( argv[nCurArg][0] == '-' ) )
  32. {
  33. switch( argv[nCurArg][1] )
  34. {
  35. case 'n': // lighting from normal only
  36. {
  37. bNormalOnly = true;
  38. }
  39. break;
  40. case 'r': // set # of rays
  41. {
  42. nNumRays = atoi( argv[++nCurArg] );
  43. }
  44. break;
  45. case 'f': // filter radius
  46. {
  47. flFilterRadius = atof( argv[++nCurArg] );
  48. }
  49. break;
  50. case 'd': // detail texture
  51. {
  52. nSSBumpFlags |= SSBUMP_MOD2X_DETAIL_TEXTURE;
  53. }
  54. break;
  55. case 'A': // ambeint occlusion
  56. {
  57. nSSBumpFlags |= SSBUMP_OPTION_NONDIRECTIONAL;
  58. }
  59. break;
  60. case 'D': // debug - write filtered output
  61. {
  62. bWriteFiltered = true;
  63. }
  64. break;
  65. case '?': // args
  66. {
  67. PrintArgSummaryAndExit();
  68. }
  69. break;
  70. default:
  71. printf("unrecogized option %s\n", argv[nCurArg] );
  72. PrintArgSummaryAndExit();
  73. }
  74. nCurArg++;
  75. }
  76. argc -= ( nCurArg - 1 );
  77. argv += ( nCurArg - 1 );
  78. if ( argc != 3 )
  79. {
  80. PrintArgSummaryAndExit();
  81. }
  82. ReportProgress( "reading src texture", 0, 0);
  83. FloatBitMap_t src_texture( argv[1] );
  84. src_texture.TileableBilateralFilter( flFilterRadius, 2.0 / 255.0 );
  85. if ( bWriteFiltered )
  86. src_texture.WriteTGAFile( "filtered.tga" );
  87. FloatBitMap_t * out;
  88. if ( bNormalOnly )
  89. out = src_texture.ComputeBumpmapFromHeightInAlphaChannel( atof( argv[2] ) );
  90. else
  91. out = src_texture.ComputeSelfShadowedBumpmapFromHeightInAlphaChannel(
  92. atof( argv[2] ), nNumRays, nSSBumpFlags );
  93. char oname[1024];
  94. strcpy( oname, argv[1] );
  95. char * dot = strchr( oname, '.' );
  96. if ( ! dot )
  97. dot = oname + strlen( oname );
  98. if ( bNormalOnly )
  99. strcpy( dot, "-bump.tga" );
  100. else
  101. strcpy( dot, "-ssbump.tga" );
  102. out->WriteTGAFile( oname );
  103. delete out;
  104. }