summaryrefslogtreecommitdiff
path: root/utils/height2ssbump
diff options
context:
space:
mode:
Diffstat (limited to 'utils/height2ssbump')
-rw-r--r--utils/height2ssbump/height2ssbump.cpp123
-rw-r--r--utils/height2ssbump/height2ssbump.vpc48
2 files changed, 171 insertions, 0 deletions
diff --git a/utils/height2ssbump/height2ssbump.cpp b/utils/height2ssbump/height2ssbump.cpp
new file mode 100644
index 0000000..4e580a3
--- /dev/null
+++ b/utils/height2ssbump/height2ssbump.cpp
@@ -0,0 +1,123 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+//===========================================================================//
+
+#include "tier0/platform.h"
+#include "tier0/progressbar.h"
+#include "bitmap/float_bm.h"
+#include "mathlib/mathlib.h"
+#include "tier2/tier2.h"
+#include "tier0/memdbgon.h"
+
+static void PrintArgSummaryAndExit( void )
+{
+ printf( "format is 'height2ssbump filename.tga bumpscale'\n" );
+ printf( "options:\n-r NUM\tSet the number of rays (default = 250. more rays take more time).\n");
+ printf( "-n\tGenerate a conventional normal map\n" );
+ printf( "-A\tGenerate ambient occlusion in the alpha channel\n" );
+ printf( "-f NUM\tSet smoothing filter radius (0=no filter, default = 10)\n");
+ printf( "-D\tWrite out the filtered result as filterd.tga\n");
+ exit(1);
+}
+
+void main(int argc,char **argv)
+{
+ InitCommandLineProgram( argc, argv );
+ int nCurArg = 1;
+
+ bool bNormalOnly = false;
+ float flFilterRadius = 10.0;
+ bool bWriteFiltered = false;
+
+ uint32 nSSBumpFlags = 0;
+
+ int nNumRays = 250;
+
+ while ( ( nCurArg < argc ) && ( argv[nCurArg][0] == '-' ) )
+ {
+ switch( argv[nCurArg][1] )
+ {
+ case 'n': // lighting from normal only
+ {
+ bNormalOnly = true;
+ }
+ break;
+
+ case 'r': // set # of rays
+ {
+ nNumRays = atoi( argv[++nCurArg] );
+ }
+ break;
+
+ case 'f': // filter radius
+ {
+ flFilterRadius = atof( argv[++nCurArg] );
+ }
+ break;
+
+ case 'd': // detail texture
+ {
+ nSSBumpFlags |= SSBUMP_MOD2X_DETAIL_TEXTURE;
+ }
+ break;
+
+ case 'A': // ambeint occlusion
+ {
+ nSSBumpFlags |= SSBUMP_OPTION_NONDIRECTIONAL;
+ }
+ break;
+
+ case 'D': // debug - write filtered output
+ {
+ bWriteFiltered = true;
+ }
+ break;
+
+ case '?': // args
+ {
+ PrintArgSummaryAndExit();
+ }
+ break;
+
+ default:
+ printf("unrecogized option %s\n", argv[nCurArg] );
+ PrintArgSummaryAndExit();
+ }
+ nCurArg++;
+
+ }
+ argc -= ( nCurArg - 1 );
+ argv += ( nCurArg - 1 );
+
+ if ( argc != 3 )
+ {
+ PrintArgSummaryAndExit();
+ }
+ ReportProgress( "reading src texture", 0, 0);
+ FloatBitMap_t src_texture( argv[1] );
+ src_texture.TileableBilateralFilter( flFilterRadius, 2.0 / 255.0 );
+ if ( bWriteFiltered )
+ src_texture.WriteTGAFile( "filtered.tga" );
+
+ FloatBitMap_t * out;
+
+ if ( bNormalOnly )
+ out = src_texture.ComputeBumpmapFromHeightInAlphaChannel( atof( argv[2] ) );
+ else
+ out = src_texture.ComputeSelfShadowedBumpmapFromHeightInAlphaChannel(
+ atof( argv[2] ), nNumRays, nSSBumpFlags );
+
+ char oname[1024];
+ strcpy( oname, argv[1] );
+ char * dot = strchr( oname, '.' );
+ if ( ! dot )
+ dot = oname + strlen( oname );
+ if ( bNormalOnly )
+ strcpy( dot, "-bump.tga" );
+ else
+ strcpy( dot, "-ssbump.tga" );
+ out->WriteTGAFile( oname );
+ delete out;
+}
diff --git a/utils/height2ssbump/height2ssbump.vpc b/utils/height2ssbump/height2ssbump.vpc
new file mode 100644
index 0000000..46e41a0
--- /dev/null
+++ b/utils/height2ssbump/height2ssbump.vpc
@@ -0,0 +1,48 @@
+//-----------------------------------------------------------------------------
+// HEIGHT2SSBUMP.VPC
+//
+// Project Script
+//-----------------------------------------------------------------------------
+
+$Macro SRCDIR "..\.."
+$Macro OUTBINDIR "$SRCDIR\..\game\bin"
+
+$Include "$SRCDIR\vpc_scripts\source_exe_con_base.vpc"
+
+$Configuration "Debug"
+{
+ $Compiler
+ {
+ $AdditionalIncludeDirectories "$BASE,..\common"
+ }
+
+ $Linker
+ {
+ $DebuggableAssembly "Runtime tracking and disable optimizations (/ASSEMBLYDEBUG)"
+ }
+}
+
+$Configuration "Release"
+{
+ $Compiler
+ {
+ $AdditionalIncludeDirectories "$BASE,..\common"
+ }
+}
+
+$Project "Height2ssbump"
+{
+ $Folder "Source Files"
+ {
+ -$File "$SRCDIR\public\tier0\memoverride.cpp"
+ $File "height2ssbump.cpp"
+ }
+
+ $Folder "Link Libraries"
+ {
+ $Lib bitmap
+ $Lib mathlib
+ $Lib raytrace
+ $Lib tier2
+ }
+}