Skip to content

Commit 06f1c7e

Browse files
committed
vrad: Use original vrad static props lighting mode instead of too dark SteamPipe one
See ValveSoftware/source-sdk-2013#1345
1 parent 1dfb759 commit 06f1c7e

File tree

3 files changed

+133
-59
lines changed

3 files changed

+133
-59
lines changed

utils/vrad/vrad.cpp

Lines changed: 81 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ bool g_bStaticPropLighting = false;
126126
bool g_bStaticPropPolys = false;
127127
bool g_bTextureShadows = false;
128128
bool g_bDisablePropSelfShadowing = false;
129+
// dimhotepus: Use CS:GO mode by default instead of SteamPipe one.
130+
IndirectPropLightingMode g_nIndirectPropLightingMode = IndirectPropLightingMode::CsGo;
129131

130132

131133
CUtlVector<byte> g_FacesVisibleToLights;
@@ -2402,6 +2404,29 @@ static int ParseCommandLine( int argc, char **argv, bool *onlydetail )
24022404
Msg( "--no-self-shadow-props: true\n");
24032405
g_bDisablePropSelfShadowing = true;
24042406
}
2407+
else if ( !Q_stricmp( argv[i], "-StaticPropIndirectMode" ) )
2408+
{
2409+
if ( ++i < argc )
2410+
{
2411+
int lightingMode = atoi( argv[i] );
2412+
if ( lightingMode < to_underlying(IndirectPropLightingMode::LowestValue) ||
2413+
lightingMode > to_underlying(IndirectPropLightingMode::MaxValue) )
2414+
{
2415+
Error( "Expected a value in range [%d...%d] after '-StaticPropIndirectMode', got %d.\n",
2416+
to_underlying(IndirectPropLightingMode::LowestValue),
2417+
to_underlying(IndirectPropLightingMode::MaxValue),
2418+
lightingMode );
2419+
return -1;
2420+
}
2421+
g_nIndirectPropLightingMode = static_cast<IndirectPropLightingMode>( lightingMode );
2422+
Msg( "--static-props-indirect-mode: %d\n", lightingMode );
2423+
}
2424+
else
2425+
{
2426+
Error( "Expected a value after '-StaticPropIndirectMode'\n" );
2427+
return -1;
2428+
}
2429+
}
24052430
else if ( !Q_stricmp( argv[i], "-textureshadows" ) )
24062431
{
24072432
Msg( "--texture-shadows: true\n");
@@ -2900,69 +2925,70 @@ void PrintUsage( int argc, char **argv )
29002925
"\n"
29012926
"Common options:\n"
29022927
"\n"
2903-
" -v (or -verbose) : Turn on verbose output (also shows more command\n"
2904-
" -bounce # : Set max number of bounces (default: 100).\n"
2905-
" -fast : Quick and dirty lighting.\n"
2906-
" -fastambient : Per-leaf ambient sampling is lower quality to save compute time.\n"
2907-
" -final : High quality processing. equivalent to -extrasky 16.\n"
2908-
" -extrasky n : trace N times as many rays for indirect light and sky ambient.\n"
2909-
" -low : Run as an idle-priority process.\n"
2910-
" -mpi : Use VMPI to distribute computations.\n"
2911-
" -rederror : Show errors in red.\n"
2928+
" -v (or -verbose) : Turn on verbose output (also shows more command).\n"
2929+
" -bounce # : Set max number of bounces (default: 100).\n"
2930+
" -fast : Quick and dirty lighting.\n"
2931+
" -fastambient : Per-leaf ambient sampling is lower quality to save compute time.\n"
2932+
" -final : High quality processing. equivalent to -extrasky 16.\n"
2933+
" -extrasky n : Trace N times as many rays for indirect light and sky ambient.\n"
2934+
" -low : Run as an idle-priority process.\n"
2935+
" -mpi : Use VMPI to distribute computations.\n"
2936+
" -rederror : Show errors in red.\n"
29122937
"\n"
2913-
" -vproject <directory> : Override the VPROJECT environment variable.\n"
2914-
" -game <directory> : Same as -vproject.\n"
2938+
" -vproject <directory> : Override the VPROJECT environment variable.\n"
2939+
" -game <directory> : Same as -vproject.\n"
29152940
"\n"
29162941
"Other options:\n"
2917-
" -novconfig : Don't bring up graphical UI on vproject errors.\n"
2918-
" -dump : Write debugging .txt files.\n"
2919-
" -dumpnormals : Write normals to debug files.\n"
2920-
" -dumptrace : Write ray-tracing environment to debug files.\n"
2921-
" -threads : Control the number of threads vbsp uses (defaults to the #\n"
2922-
" or processors on your machine).\n"
2923-
" -lights <file> : Load a lights file in addition to lights.rad and the\n"
2924-
" level lights file.\n"
2925-
" -noextra : Disable supersampling.\n"
2926-
" -debugextra : Places debugging data in lightmaps to visualize\n"
2927-
" supersampling.\n"
2928-
" -extrapasses # : How many extra passes supersampling passes to do (default 6), differences above this value are minimal.\n"
2929-
" -smooth # : Set the threshold for smoothing groups, in degrees\n"
2930-
" (default 45).\n"
2931-
" -dlightmap : Force direct lighting into different lightmap than\n"
2932-
" radiosity.\n"
2933-
" -stoponexit : Wait for a keypress on exit.\n"
2934-
" -mpi_pw <pw> : Use a password to choose a specific set of VMPI workers.\n"
2935-
" -nodetaillight : Don't light detail props.\n"
2936-
" -centersamples : Move sample centers.\n"
2937-
" -luxeldensity # : Rescale all luxels by the specified amount (default: 1.0).\n"
2938-
" The number specified must be less than 1.0 or it will be\n"
2939-
" ignored.\n"
2940-
" -loghash : Log the sample hash table to samplehash.txt.\n"
2941-
" -onlydetail : Only light detail props and per-leaf lighting.\n"
2942-
" -maxdispsamplesize # : Set max displacement sample size (default: 512).\n"
2943-
" -softsun <n> : Treat the sun as an area light source of size <n> degrees."
2944-
" Produces soft shadows.\n"
2945-
" Recommended values are between 0 and 5 (default: 0).\n"
2946-
" -sunSamplesAreaLight # : Set max number of samples from the light_enviroment (default: 1024).\n"
2947-
" -FullMinidumps : Write large minidumps on crash.\n"
2948-
" -chop : Smallest number of luxel widths for a bounce patch, used on edges\n"
2949-
" -maxchop : Coarsest allowed number of luxel widths for a patch, used in face interiors\n"
2942+
" -novconfig : Don't bring up graphical UI on vproject errors.\n"
2943+
" -dump : Write debugging .txt files.\n"
2944+
" -dumpnormals : Write normals to debug files.\n"
2945+
" -dumptrace : Write ray-tracing environment to debug files.\n"
2946+
" -threads : Control the number of threads vbsp uses (defaults to the #\n"
2947+
" or processors on your machine).\n"
2948+
" -lights <file> : Load a lights file in addition to lights.rad and the\n"
2949+
" level lights file.\n"
2950+
" -noextra : Disable supersampling.\n"
2951+
" -debugextra : Places debugging data in lightmaps to visualize\n"
2952+
" supersampling.\n"
2953+
" -extrapasses # : How many extra passes supersampling passes to do (default 6), differences above this value are minimal.\n"
2954+
" -smooth # : Set the threshold for smoothing groups, in degrees\n"
2955+
" (default 45).\n"
2956+
" -dlightmap : Force direct lighting into different lightmap than\n"
2957+
" radiosity.\n"
2958+
" -stoponexit : Wait for a keypress on exit.\n"
2959+
" -mpi_pw <pw> : Use a password to choose a specific set of VMPI workers.\n"
2960+
" -nodetaillight : Don't light detail props.\n"
2961+
" -centersamples : Move sample centers.\n"
2962+
" -luxeldensity # : Rescale all luxels by the specified amount (default: 1.0).\n"
2963+
" The number specified must be less than 1.0 or it will be\n"
2964+
" ignored.\n"
2965+
" -loghash : Log the sample hash table to samplehash.txt.\n"
2966+
" -onlydetail : Only light detail props and per-leaf lighting.\n"
2967+
" -maxdispsamplesize # : Set max displacement sample size (default: 512).\n"
2968+
" -softsun <n> : Treat the sun as an area light source of size <n> degrees."
2969+
" Produces soft shadows.\n"
2970+
" Recommended values are between 0 and 5 (default: 0).\n"
2971+
" -sunSamplesAreaLight # : Set max number of samples from the light_enviroment (default: 1024).\n"
2972+
" -FullMinidumps : Write large minidumps on crash.\n"
2973+
" -chop : Smallest number of luxel widths for a bounce patch, used on edges.\n"
2974+
" -maxchop : Coarsest allowed number of luxel widths for a patch, used in face interiors.\n"
29502975
"\n"
2951-
" -LargeDispSampleRadius : This can be used if there are splotches of bounced light\n"
2952-
" on terrain. The compile will take longer, but it will gather\n"
2953-
" light across a wider area.\n"
2954-
" -StaticPropLighting : generate backed static prop vertex lighting\n"
2955-
" -StaticPropPolys : Perform shadow tests of static props at polygon precision\n"
2956-
" -OnlyStaticProps : Only perform direct static prop lighting (vrad debug option)\n"
2957-
" -StaticPropNormals : when lighting static props, just show their normal vector\n"
2958-
" -textureshadows : Allows texture alpha channels to block light - rays intersecting alpha surfaces will sample the texture\n"
2959-
" -noskyboxrecurse : Turn off recursion into 3d skybox (skybox shadows on world)\n"
2960-
" -nossprops : Globally disable self-shadowing on static props\n"
2976+
" -LargeDispSampleRadius : This can be used if there are splotches of bounced light\n"
2977+
" on terrain. The compile will take longer, but it will gather\n"
2978+
" light across a wider area.\n"
2979+
" -StaticPropLighting : Generate backed static prop vertex lighting.\n"
2980+
" -StaticPropPolys : Perform shadow tests of static props at polygon precision.\n"
2981+
" -StaticPropIndirectMode : Override prop indirect lighting algorithm (0 - Balanced [CS:GO], 1 - Dark [SteamPipe], 2 - Bright [Orangebox]).\n"
2982+
" -OnlyStaticProps : Only perform direct static prop lighting (vrad debug option).\n"
2983+
" -StaticPropNormals : When lighting static props, just show their normal vector.\n"
2984+
" -textureshadows : Allows texture alpha channels to block light - rays intersecting alpha surfaces will sample the texture.\n"
2985+
" -noskyboxrecurse : Turn off recursion into 3d skybox (skybox shadows on world).\n"
2986+
" -nossprops : Globally disable self-shadowing on static props.\n"
29612987
"\n"
29622988
#if 1 // Disabled for the initial SDK release with VMPI so we can get feedback from selected users.
29632989
);
29642990
#else
2965-
" -mpi_ListParams : Show a list of VMPI parameters.\n"
2991+
" -mpi_ListParams : Show a list of VMPI parameters.\n"
29662992
"\n"
29672993
);
29682994

utils/vrad/vrad.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,23 @@ extern bool g_bTextureShadows;
285285
extern bool g_bShowStaticPropNormals;
286286
extern bool g_bDisablePropSelfShadowing;
287287

288+
enum class IndirectPropLightingMode
289+
{
290+
LowestValue = 0,
291+
292+
// Uses dot, best results.
293+
CsGo = LowestValue,
294+
// SteamPipe Half-Life 2 / Team Fortress 2 lighting.
295+
// Uses inverse square law causing lights to be too dark.
296+
SteamPipe = 1,
297+
// Orange box. Just reflectivity, too bright.
298+
OrangeBox = 2,
299+
300+
MaxValue = OrangeBox
301+
};
302+
303+
extern IndirectPropLightingMode g_nIndirectPropLightingMode;
304+
288305
extern CUtlVector<char const *> g_NonShadowCastingMaterialStrings;
289306
extern void ForceTextureShadowsOnModel( const char *pModelName );
290307
extern bool IsModelTextureShadowsForced( const char *pModelName );

utils/vrad/vraddetailprops.cpp

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -737,10 +737,41 @@ void ComputeIndirectLightingAtPoint( Vector &position, Vector &normal, Vector &o
737737
ColorRGBExp32ToVector( *pLightmap, lightmapColor );
738738
}
739739

740-
float invLengthSqr = 1.0f / (1.0f + ((vEnd - position) * surfEnum.m_HitFrac / 128.0).LengthSqr());
741-
// Include falloff using invsqrlaw.
742-
VectorMultiply( lightmapColor, invLengthSqr * dtexdata[pTex->texdata].reflectivity, lightmapColor );
743-
VectorAdd( outColor, lightmapColor, outColor );
740+
// The calculation for indirect prop lighting has went through a handful of iterations
741+
// For the sake of compatibility with maps that may be calibrated against the incorrect forms of indirect lightings,
742+
// the user may optionally switch to the old methods of indirect prop lighting
743+
switch ( g_nIndirectPropLightingMode )
744+
{
745+
// Mode 0: CSGO
746+
// This mode factors in only the dot.
747+
// The practical result is this ends up being a middleground of Orangebox and TF2 lighting,
748+
// and most closely matches indirect lighting on brush lightmaps
749+
case IndirectPropLightingMode::CsGo:
750+
{
751+
VectorMultiply( lightmapColor, dot * dtexdata[pTex->texdata].reflectivity, lightmapColor );
752+
break;
753+
}
754+
// Mode 1: SteamPipe
755+
// TF2 attempted to include falloff using inverse square law.
756+
// Unfortunately, this leads to pretty harsh and unnatural bounced light on props
757+
case IndirectPropLightingMode::SteamPipe:
758+
{
759+
float invLengthSqr = 1.0f / ( 1.0f + ( ( vEnd - position ) * surfEnum.m_HitFrac / 128.0f ).LengthSqr() );
760+
VectorMultiply( lightmapColor, invLengthSqr * dtexdata[pTex->texdata].reflectivity, lightmapColor );
761+
break;
762+
}
763+
// Mode 2: Orangebox (and earlier)
764+
// Here, indirect lighting simply took the reflectivity and did not factor in falloff or dot.
765+
// This created an unnaturally bright result, but this is what TF2 shipped with on release.
766+
case IndirectPropLightingMode::OrangeBox:
767+
{
768+
VectorMultiply( lightmapColor, dtexdata[pTex->texdata].reflectivity, lightmapColor );
769+
break;
770+
}
771+
772+
default:
773+
Error( "Unknown indirect lighting mode %d.\n", to_underlying(g_nIndirectPropLightingMode) );
774+
}
744775
}
745776

746777
if ( totalDot )

0 commit comments

Comments
 (0)