diff --git a/devtools/bin/ShaderCompile.exe b/devtools/bin/ShaderCompile.exe new file mode 100644 index 0000000000..7dd64e661b Binary files /dev/null and b/devtools/bin/ShaderCompile.exe differ diff --git a/devtools/bin/process_shaders.ps1 b/devtools/bin/process_shaders.ps1 new file mode 100644 index 0000000000..9fdaf9c867 --- /dev/null +++ b/devtools/bin/process_shaders.ps1 @@ -0,0 +1,31 @@ +[CmdletBinding()] +param ( + [Parameter(Mandatory=$true, ValueFromPipeline=$true)][System.IO.FileInfo]$File, + [Parameter(Mandatory=$true)][string]$Version, + [Parameter(Mandatory=$false)][switch]$Dynamic, + [Parameter(Mandatory=$false)][System.UInt32]$Threads +) + +if ($Version -notin @("20b", "30", "40", "41", "50", "51")) { + return +} + +$fileList = $File.OpenText() +while ($null -ne ($line = $fileList.ReadLine())) { + if ($line -match '^\s*$' -or $line -match '^\s*//') { + continue + } + + if ($Dynamic) { + & "$PSScriptRoot\ShaderCompile" "-dynamic" "-ver" $Version "-shaderpath" $File.DirectoryName $line + continue + } + + if ($Threads -ne 0) { + & "$PSScriptRoot\ShaderCompile" "-threads" $Threads "-ver" $Version "-shaderpath" $File.DirectoryName $line + continue + } + + & "$PSScriptRoot\ShaderCompile" "-ver" $Version "-shaderpath" $File.DirectoryName $line +} +$fileList.Close() \ No newline at end of file diff --git a/engine/host.cpp b/engine/host.cpp index 182245fd6b..cd5f09ff88 100644 --- a/engine/host.cpp +++ b/engine/host.cpp @@ -590,7 +590,7 @@ jmp_buf host_enddemo; static ConVar host_profile( "host_profile","0" ); ConVar host_limitlocal( "host_limitlocal", "0", 0, "Apply cl_cmdrate and cl_updaterate to loopback connection" ); -ConVar host_framerate( "host_framerate","0", FCVAR_REPLICATED, "Set to lock per-frame time elapse." ); +ConVar host_framerate( "host_framerate","0", 0, "Set to lock per-frame time elapse." ); ConVar host_timescale( "host_timescale","1.0", FCVAR_REPLICATED, "Prescale the clock by this amount." ); ConVar host_speeds( "host_speeds","0", 0, "Show general system running times." ); // set for running times diff --git a/game/client/fx_impact.cpp b/game/client/fx_impact.cpp index 682d5435d2..90132c55e9 100644 --- a/game/client/fx_impact.cpp +++ b/game/client/fx_impact.cpp @@ -207,7 +207,7 @@ char const *GetImpactDecal( C_BaseEntity *pEntity, int iMaterial, int iDamageTyp //----------------------------------------------------------------------------- // Purpose: Perform custom effects based on the Decal index //----------------------------------------------------------------------------- -static ConVar cl_new_impact_effects( "cl_new_impact_effects", "0" ); +static ConVar cl_new_impact_effects( "cl_new_impact_effects", "1" ); struct ImpactEffect_t { diff --git a/materialsystem/stdshaders/ShaderCompile.exe b/materialsystem/stdshaders/ShaderCompile.exe new file mode 100644 index 0000000000..eaeeb629a4 Binary files /dev/null and b/materialsystem/stdshaders/ShaderCompile.exe differ diff --git a/materialsystem/stdshaders/buildallshaders.bat b/materialsystem/stdshaders/buildallshaders.bat index 66970d9982..d43b228ab4 100644 --- a/materialsystem/stdshaders/buildallshaders.bat +++ b/materialsystem/stdshaders/buildallshaders.bat @@ -44,8 +44,8 @@ REM PC SHADERS REM **************** if /i "%ALLSHADERS_CONFIG%" == "pc" ( %BUILD_SHADER% stdshader_dx9_20b - %BUILD_SHADER% stdshader_dx9_20b_new -dx9_30 - %BUILD_SHADER% stdshader_dx9_30 -dx9_30 -force30 + %BUILD_SHADER% stdshader_dx9_20b_new + %BUILD_SHADER% stdshader_dx9_30 -force30 rem %BUILD_SHADER% stdshader_dx10 -dx10 ) diff --git a/materialsystem/stdshaders/buildshaders.bat b/materialsystem/stdshaders/buildshaders.bat index cc1bc6baf7..e300b832ce 100644 --- a/materialsystem/stdshaders/buildshaders.bat +++ b/materialsystem/stdshaders/buildshaders.bat @@ -9,62 +9,37 @@ set TTEXE=time /t :no_ttexe_end echo. -rem echo ==================== buildshaders %* ================== +echo ==================== buildshaders %* ================== %TTEXE% -cur-Q set tt_start=%ERRORLEVEL% set tt_chkpt=%tt_start% REM **************** -REM usage: buildshaders [-x360] +REM usage: buildshaders REM **************** setlocal set arg_filename=%1 -rem set shadercompilecommand=echo shadercompile.exe -mpi_graphics -mpi_TrackEvents -set shadercompilecommand=shadercompile.exe -set shadercompileworkers=128 -set x360_args= -set targetdir=..\..\..\game\hl2\shaders +set shadercompilecommand=ShaderCompile.exe +set targetdir=shaders set SrcDirBase=..\.. -set ChangeToDir=../../../game/bin set shaderDir=shaders -set SDKArgs= -set SHADERINCPATH=vshtmp9/... fxctmp9/... - - -set DIRECTX_SDK_VER=pc09.00 -set DIRECTX_SDK_BIN_DIR=dx9sdk\utilities - -if /i "%2" == "-x360" goto dx_sdk_x360 -if /i "%2" == "-dx9_30" goto dx_sdk_dx9_30 -if /i "%2" == "-dx10" goto dx_sdk_dx10 -goto dx_sdk_end -:dx_sdk_x360 - set DIRECTX_SDK_VER=x360.00 - set DIRECTX_SDK_BIN_DIR=x360xdk\bin\win32 - goto dx_sdk_end -:dx_sdk_dx9_30 - set DIRECTX_SDK_VER=pc09.30 - set DIRECTX_SDK_BIN_DIR=dx10sdk\utilities\dx9_30 - goto dx_sdk_end -:dx_sdk_dx10 - set DIRECTX_SDK_VER=pc10.00 - set DIRECTX_SDK_BIN_DIR=dx10sdk\utilities\dx10_40 - goto dx_sdk_end -:dx_sdk_end +set SDKArgs=-local if "%1" == "" goto usage set inputbase=%1 -if /i "%3" == "-force30" goto set_force30_arg +REM ignore -dx9_30 +if /i "%6" == "-dx9_30" shift /6 + +if /i "%6" == "-force30" goto set_force30_arg goto set_force_end :set_force30_arg - set DIRECTX_FORCE_MODEL=30 + set IS30=1 goto set_force_end :set_force_end -if /i "%2" == "-x360" goto set_x360_args if /i "%2" == "-game" goto set_mod_args goto build_shaders @@ -73,47 +48,43 @@ REM USAGE REM **************** :usage echo. -echo "usage: buildshaders [-x360 or -dx10 or -game] [gameDir if -game was specified] [-source sourceDir]" +echo "usage: buildshaders [-game] [gameDir if -game was specified] [-source sourceDir]" echo " gameDir is where gameinfo.txt is (where it will store the compiled shaders)." echo " sourceDir is where the source code is (where it will find scripts and compilers)." echo "ex : buildshaders myshaders" echo "ex : buildshaders myshaders -game c:\steam\steamapps\sourcemods\mymod -source c:\mymod\src" goto :end -REM **************** -REM X360 ARGS -REM **************** -:set_x360_args -set x360_args=-x360 -set SHADERINCPATH=vshtmp9_360/... fxctmp9_360/... -goto build_shaders - REM **************** REM MOD ARGS - look for -game or the vproject environment variable REM **************** :set_mod_args -if not exist %sourcesdk%\bin\shadercompile.exe goto NoShaderCompile -set ChangeToDir=%sourcesdk%\bin +if not exist "..\..\devtools\bin\ShaderCompile.exe" goto NoShaderCompile +set ChangeToDir=%SrcDirBase%\devtools\bin\ if /i "%4" NEQ "-source" goto NoSourceDirSpecified set SrcDirBase=%~5 REM ** use the -game parameter to tell us where to put the files set targetdir=%~3\shaders -set SDKArgs=-nompi -game "%~3" if not exist "%~3\gameinfo.txt" goto InvalidGameDirectory + +if not exist "%inputbase%.txt" goto InvalidInputFile + goto build_shaders REM **************** REM ERRORS REM **************** :InvalidGameDirectory -echo - echo Error: "%~3" is not a valid game directory. echo (The -game directory must have a gameinfo.txt file) -echo - +goto end + +:InvalidInputFile +echo Error: "%inputbase%.txt" is not a valid file. goto end :NoSourceDirSpecified @@ -122,9 +93,7 @@ goto usage goto end :NoShaderCompile -echo - -echo - ERROR: shadercompile.exe doesn't exist in %sourcesdk%\bin -echo - +echo - ERROR: ShaderCompile.exe doesn't exist in devtools\bin goto end REM **************** @@ -137,115 +106,35 @@ rem echo %inputbase% rem echo -------------------------------- REM make sure that target dirs exist REM files will be built in these targets and copied to their final destination +if not exist include mkdir include if not exist %shaderDir% mkdir %shaderDir% if not exist %shaderDir%\fxc mkdir %shaderDir%\fxc -if not exist %shaderDir%\vsh mkdir %shaderDir%\vsh -if not exist %shaderDir%\psh mkdir %shaderDir%\psh REM Nuke some files that we will add to later. -if exist filelist.txt del /f /q filelist.txt -if exist filestocopy.txt del /f /q filestocopy.txt -if exist filelistgen.txt del /f /q filelistgen.txt -if exist inclist.txt del /f /q inclist.txt -if exist vcslist.txt del /f /q vcslist.txt - -REM **************** -REM Revert any targets (vcs or inc) that are opened for integrate. -REM **************** -perl "%SrcDirBase%\devtools\bin\p4revertshadertargets.pl" %x360_args% -source "%SrcDirBase%" %inputbase% - -REM **************** -REM Generate a makefile for the shader project -REM **************** -perl "%SrcDirBase%\devtools\bin\updateshaders.pl" %x360_args% -source "%SrcDirBase%" %inputbase% - - -REM **************** -REM Run the makefile, generating minimal work/build list for fxc files, go ahead and compile vsh and psh files. -REM **************** -rem nmake /S /C -f makefile.%inputbase% clean > clean.txt 2>&1 -echo Building inc files, asm vcs files, and VMPI worklist for %inputbase%... -nmake /S /C -f makefile.%inputbase% - -REM **************** -REM Copy the inc files to their target -REM **************** -if exist "inclist.txt" ( - echo Publishing shader inc files to target... - perl %SrcDirBase%\devtools\bin\copyshaderincfiles.pl inclist.txt %x360_args% +set SHVER=20b +if defined IS30 ( + set SHVER=30 ) -REM **************** -REM Deal with perforce operations for inc files -REM **************** -if exist inclist.txt if not "%VALVE_NO_AUTO_P4_SHADERS%" == "1" ( - echo Executing perforce operations on .inc files. - perl ..\..\devtools\bin\p4autocheckout.pl inclist.txt "Shader Auto Checkout INC" . %SHADERINCPATH% -) +title %1 %SHVER% + +echo Building inc files and worklist for %inputbase%... + +set DYNAMIC= +if "%dynamic_shaders%" == "1" set DYNAMIC=-Dynamic +powershell -NoLogo -ExecutionPolicy Bypass -Command "%SrcDirBase%\devtools\bin\process_shaders.ps1 %DYNAMIC% -Version %SHVER% '%inputbase%.txt'" REM **************** -REM Add the executables to the worklist. -REM **************** -if /i "%DIRECTX_SDK_VER%" == "pc09.00" ( - rem echo "Copy extra files for dx 9 std -) -if /i "%DIRECTX_SDK_VER%" == "pc09.30" ( - echo %SrcDirBase%\devtools\bin\d3dx9_33.dll >> filestocopy.txt -) -if /i "%DIRECTX_SDK_VER%" == "pc10.00" ( - echo %SrcDirBase%\devtools\bin\d3dx10_33.dll >> filestocopy.txt -) -if /i "%DIRECTX_SDK_VER%" == "x360.00" ( - rem echo "Copy extra files for xbox360 -) - -echo %SrcDirBase%\%DIRECTX_SDK_BIN_DIR%\dx_proxy.dll >> filestocopy.txt - -echo %SrcDirBase%\..\game\bin\shadercompile.exe >> filestocopy.txt -echo %SrcDirBase%\..\game\bin\shadercompile_dll.dll >> filestocopy.txt -echo %SrcDirBase%\..\game\bin\vstdlib.dll >> filestocopy.txt -echo %SrcDirBase%\..\game\bin\tier0.dll >> filestocopy.txt - -REM **************** -REM Cull duplicate entries in work/build list -REM **************** -if exist filestocopy.txt type filestocopy.txt | perl "%SrcDirBase%\devtools\bin\uniqifylist.pl" > uniquefilestocopy.txt -if exist filelistgen.txt if not "%dynamic_shaders%" == "1" ( - echo Generating action list... - copy filelistgen.txt filelist.txt >nul - rem %SrcDirBase%\devtools\bin\fxccombogen.exe nul 2>filelist.txt -) - -REM **************** -REM Execute distributed process on work/build list -REM **************** - -set shader_path_cd=%cd% -if exist "filelist.txt" if exist "uniquefilestocopy.txt" if not "%dynamic_shaders%" == "1" ( - echo Running distributed shader compilation... - cd %ChangeToDir% - %shadercompilecommand% -mpi_workercount %shadercompileworkers% -allowdebug -shaderpath "%shader_path_cd:/=\%" %x360_args% %SDKArgs% - cd %shader_path_cd% -) - - -REM **************** -REM PC and 360 Shader copy -REM Publish the generated files to the output dir using ROBOCOPY (smart copy) or XCOPY +REM PC Shader copy +REM Publish the generated files to the output dir using XCOPY REM This batch file may have been invoked standalone or slaved (master does final smart mirror copy) REM **************** +:DoXCopy if not "%dynamic_shaders%" == "1" ( - if exist makefile.%inputbase%.copy echo Publishing shaders to target... - if exist makefile.%inputbase%.copy perl %SrcDirBase%\devtools\bin\copyshaders.pl makefile.%inputbase%.copy %x360_args% -) - -REM **************** -REM Deal with perforce operations for vcs files -REM **************** -if not "%dynamic_shaders%" == "1" if exist vcslist.txt if not "%VALVE_NO_AUTO_P4_SHADERS%" == "1" ( - echo Executing perforce operations on .vcs files. - perl ..\..\devtools\bin\p4autocheckout.pl vcslist.txt "Shader Auto Checkout VCS" ../../../game/hl2/shaders ../../../game/hl2/shaders/... +if not exist "%targetdir%" md "%targetdir%" +if not "%targetdir%"=="%shaderDir%" xcopy %shaderDir%\*.* "%targetdir%" /e /y ) +goto end REM **************** REM END @@ -254,5 +143,4 @@ REM **************** %TTEXE% -diff %tt_start% -echo. - +echo. \ No newline at end of file diff --git a/materialsystem/stdshaders/fxctmp9/lightmappedgeneric_ps20b.inc b/materialsystem/stdshaders/fxctmp9/lightmappedgeneric_ps20b.inc index 7ecfcbdcc4..b1b3006fa1 100644 --- a/materialsystem/stdshaders/fxctmp9/lightmappedgeneric_ps20b.inc +++ b/materialsystem/stdshaders/fxctmp9/lightmappedgeneric_ps20b.inc @@ -1,11 +1,115 @@ +// ALL SKIP STATEMENTS THAT AFFECT THIS SHADER!!! +// $SEAMLESS && $RELIEF_MAPPING +// (! $DETAILTEXTURE) && ( $DETAIL_BLEND_MODE != 0 ) +// $SEAMLESS && ( $OUTLINE || $SOFTEDGES) +// $BASETEXTURE2 && ( $OUTLINE || $SOFTEDGES) +// $BUMPMAP2 && ( $OUTLINE || $SOFTEDGES) +// $SELFILLUM && ( $OUTLINE || $SOFTEDGES) +// $MASKEDBLENDING && ( $OUTLINE || $SOFTEDGES) +// $FANCY_BLENDING && ( $OUTLINE || $SOFTEDGES) +// $LIGHTING_PREVIEW && ( $OUTLINE || $SOFTEDGES) +// ($FASTPATH == 0) && ( $OUTLINE || $SOFTEDGES) +// ($DETAILTEXTURE && $BUMPMAP) && ( $OUTLINE || $SOFTEDGES) +// ($WARPLIGHTING) && ( $OUTLINE || $SOFTEDGES) +// ($BUMPMAP) && ( $OUTLINE || $SOFTEDGES) +// ($DETAIL_BLEND_MODE == 2 ) || ($DETAIL_BLEND_MODE == 3 ) || ($DETAIL_BLEND_MODE == 4 ) +// ($DETAIL_BLEND_MODE == 5 ) || ($DETAIL_BLEND_MODE == 6 ) || ($DETAIL_BLEND_MODE == 7 ) +// ($DETAIL_BLEND_MODE == 8 ) || ($DETAIL_BLEND_MODE == 9 ) +// $PARALLAXCORRECT && !$CUBEMAP +// $BUMPMAP2 && $WARPLIGHTING +// $WARPLIGHTING && $DETAILTEXTURE +// $ENVMAPMASK && $BUMPMAP +// $NORMALMAPALPHAENVMAPMASK && $BASEALPHAENVMAPMASK +// $NORMALMAPALPHAENVMAPMASK && $ENVMAPMASK +// $BASEALPHAENVMAPMASK && $ENVMAPMASK +// $BASEALPHAENVMAPMASK && $SELFILLUM +// !$FASTPATH && $FASTPATHENVMAPCONTRAST +// !$FASTPATH && $FASTPATHENVMAPTINT +// !$BUMPMAP && $DIFFUSEBUMPMAP +// !$BUMPMAP && $BUMPMAP2 +// $ENVMAPMASK && $BUMPMAP2 +// $BASETEXTURENOENVMAP && ( !$BASETEXTURE2 || !$CUBEMAP ) +// $BASETEXTURE2NOENVMAP && ( !$BASETEXTURE2 || !$CUBEMAP ) +// $BASEALPHAENVMAPMASK && $BUMPMAP +// $PARALLAXMAP && $DETAILTEXTURE +// $SEAMLESS && $RELIEF_MAPPING +// $SEAMLESS && $DETAILTEXTURE +// $SEAMLESS && $MASKEDBLENDING +// $BUMPMASK && ( $SEAMLESS || $DETAILTEXTURE || $SELFILLUM || $BASETEXTURENOENVMAP || $BASETEXTURE2 ) +// !$BUMPMAP && ($NORMAL_DECODE_MODE == 1) +// !$BUMPMAP && ($NORMAL_DECODE_MODE == 2) +// !$BUMPMAP && ($NORMALMASK_DECODE_MODE == 1) +// !$BUMPMAP && ($NORMALMASK_DECODE_MODE == 2) +// defined $HDRTYPE && defined $HDRENABLED && !$HDRTYPE && $HDRENABLED +// defined $PIXELFOGTYPE && defined $WRITEWATERFOGTODESTALPHA && ( $PIXELFOGTYPE != 1 ) && $WRITEWATERFOGTODESTALPHA +// defined $LIGHTING_PREVIEW && defined $HDRTYPE && $LIGHTING_PREVIEW && $HDRTYPE != 0 +// defined $LIGHTING_PREVIEW && defined $FASTPATHENVMAPTINT && $LIGHTING_PREVIEW && $FASTPATHENVMAPTINT +// defined $LIGHTING_PREVIEW && defined $FASTPATHENVMAPCONTRAST && $LIGHTING_PREVIEW && $FASTPATHENVMAPCONTRAST +// defined $LIGHTING_PREVIEW && defined $FASTPATH && $LIGHTING_PREVIEW && $FASTPATH +// ($FLASHLIGHT || $FLASHLIGHTSHADOWS) && $LIGHTING_PREVIEW +// defined $HDRTYPE && defined $HDRENABLED && !$HDRTYPE && $HDRENABLED +// defined $PIXELFOGTYPE && defined $WRITEWATERFOGTODESTALPHA && ( $PIXELFOGTYPE != 1 ) && $WRITEWATERFOGTODESTALPHA +// defined $LIGHTING_PREVIEW && defined $HDRTYPE && $LIGHTING_PREVIEW && $HDRTYPE != 0 +// defined $LIGHTING_PREVIEW && defined $FASTPATHENVMAPTINT && $LIGHTING_PREVIEW && $FASTPATHENVMAPTINT +// defined $LIGHTING_PREVIEW && defined $FASTPATHENVMAPCONTRAST && $LIGHTING_PREVIEW && $FASTPATHENVMAPCONTRAST +// defined $LIGHTING_PREVIEW && defined $FASTPATH && $LIGHTING_PREVIEW && $FASTPATH +// ($FLASHLIGHT || $FLASHLIGHTSHADOWS) && $LIGHTING_PREVIEW + +#pragma once +#define NEW_SHADER_COMPILE #include "shaderlib/cshader.h" class lightmappedgeneric_ps20b_Static_Index { -private: - int m_nMASKEDBLENDING; + unsigned int m_nMASKEDBLENDING : 2; + unsigned int m_nBASETEXTURE2 : 2; + unsigned int m_nDETAILTEXTURE : 2; + unsigned int m_nBUMPMAP : 2; + unsigned int m_nBUMPMAP2 : 2; + unsigned int m_nCUBEMAP : 2; + unsigned int m_nENVMAPMASK : 2; + unsigned int m_nBASEALPHAENVMAPMASK : 2; + unsigned int m_nSELFILLUM : 2; + unsigned int m_nNORMALMAPALPHAENVMAPMASK : 2; + unsigned int m_nDIFFUSEBUMPMAP : 2; + unsigned int m_nBASETEXTURENOENVMAP : 2; + unsigned int m_nBASETEXTURE2NOENVMAP : 2; + unsigned int m_nWARPLIGHTING : 2; + unsigned int m_nFANCY_BLENDING : 2; + unsigned int m_nRELIEF_MAPPING : 1; + unsigned int m_nSEAMLESS : 2; + unsigned int m_nOUTLINE : 2; + unsigned int m_nSOFTEDGES : 2; + unsigned int m_nBUMPMASK : 2; + unsigned int m_nNORMAL_DECODE_MODE : 1; + unsigned int m_nNORMALMASK_DECODE_MODE : 1; + unsigned int m_nDETAIL_BLEND_MODE : 4; + unsigned int m_nPARALLAXCORRECT : 2; #ifdef _DEBUG - bool m_bMASKEDBLENDING; -#endif + bool m_bMASKEDBLENDING : 1; + bool m_bBASETEXTURE2 : 1; + bool m_bDETAILTEXTURE : 1; + bool m_bBUMPMAP : 1; + bool m_bBUMPMAP2 : 1; + bool m_bCUBEMAP : 1; + bool m_bENVMAPMASK : 1; + bool m_bBASEALPHAENVMAPMASK : 1; + bool m_bSELFILLUM : 1; + bool m_bNORMALMAPALPHAENVMAPMASK : 1; + bool m_bDIFFUSEBUMPMAP : 1; + bool m_bBASETEXTURENOENVMAP : 1; + bool m_bBASETEXTURE2NOENVMAP : 1; + bool m_bWARPLIGHTING : 1; + bool m_bFANCY_BLENDING : 1; + bool m_bRELIEF_MAPPING : 1; + bool m_bSEAMLESS : 1; + bool m_bOUTLINE : 1; + bool m_bSOFTEDGES : 1; + bool m_bBUMPMASK : 1; + bool m_bNORMAL_DECODE_MODE : 1; + bool m_bNORMALMASK_DECODE_MODE : 1; + bool m_bDETAIL_BLEND_MODE : 1; + bool m_bPARALLAXCORRECT : 1; +#endif // _DEBUG public: void SetMASKEDBLENDING( int i ) { @@ -13,592 +117,332 @@ public: m_nMASKEDBLENDING = i; #ifdef _DEBUG m_bMASKEDBLENDING = true; -#endif +#endif // _DEBUG } - void SetMASKEDBLENDING( bool i ) - { - m_nMASKEDBLENDING = i ? 1 : 0; -#ifdef _DEBUG - m_bMASKEDBLENDING = true; -#endif - } -private: - int m_nBASETEXTURE2; -#ifdef _DEBUG - bool m_bBASETEXTURE2; -#endif -public: + void SetBASETEXTURE2( int i ) { Assert( i >= 0 && i <= 1 ); m_nBASETEXTURE2 = i; #ifdef _DEBUG m_bBASETEXTURE2 = true; -#endif +#endif // _DEBUG } - void SetBASETEXTURE2( bool i ) - { - m_nBASETEXTURE2 = i ? 1 : 0; -#ifdef _DEBUG - m_bBASETEXTURE2 = true; -#endif - } -private: - int m_nDETAILTEXTURE; -#ifdef _DEBUG - bool m_bDETAILTEXTURE; -#endif -public: + void SetDETAILTEXTURE( int i ) { Assert( i >= 0 && i <= 1 ); m_nDETAILTEXTURE = i; #ifdef _DEBUG m_bDETAILTEXTURE = true; -#endif +#endif // _DEBUG } - void SetDETAILTEXTURE( bool i ) - { - m_nDETAILTEXTURE = i ? 1 : 0; -#ifdef _DEBUG - m_bDETAILTEXTURE = true; -#endif - } -private: - int m_nBUMPMAP; -#ifdef _DEBUG - bool m_bBUMPMAP; -#endif -public: + void SetBUMPMAP( int i ) { Assert( i >= 0 && i <= 2 ); m_nBUMPMAP = i; #ifdef _DEBUG m_bBUMPMAP = true; -#endif +#endif // _DEBUG } - void SetBUMPMAP( bool i ) - { - m_nBUMPMAP = i ? 1 : 0; -#ifdef _DEBUG - m_bBUMPMAP = true; -#endif - } -private: - int m_nBUMPMAP2; -#ifdef _DEBUG - bool m_bBUMPMAP2; -#endif -public: + void SetBUMPMAP2( int i ) { Assert( i >= 0 && i <= 1 ); m_nBUMPMAP2 = i; #ifdef _DEBUG m_bBUMPMAP2 = true; -#endif +#endif // _DEBUG } - void SetBUMPMAP2( bool i ) - { - m_nBUMPMAP2 = i ? 1 : 0; -#ifdef _DEBUG - m_bBUMPMAP2 = true; -#endif - } -private: - int m_nCUBEMAP; -#ifdef _DEBUG - bool m_bCUBEMAP; -#endif -public: + void SetCUBEMAP( int i ) { Assert( i >= 0 && i <= 1 ); m_nCUBEMAP = i; #ifdef _DEBUG m_bCUBEMAP = true; -#endif +#endif // _DEBUG } - void SetCUBEMAP( bool i ) - { - m_nCUBEMAP = i ? 1 : 0; -#ifdef _DEBUG - m_bCUBEMAP = true; -#endif - } -private: - int m_nENVMAPMASK; -#ifdef _DEBUG - bool m_bENVMAPMASK; -#endif -public: + void SetENVMAPMASK( int i ) { Assert( i >= 0 && i <= 1 ); m_nENVMAPMASK = i; #ifdef _DEBUG m_bENVMAPMASK = true; -#endif +#endif // _DEBUG } - void SetENVMAPMASK( bool i ) - { - m_nENVMAPMASK = i ? 1 : 0; -#ifdef _DEBUG - m_bENVMAPMASK = true; -#endif - } -private: - int m_nBASEALPHAENVMAPMASK; -#ifdef _DEBUG - bool m_bBASEALPHAENVMAPMASK; -#endif -public: + void SetBASEALPHAENVMAPMASK( int i ) { Assert( i >= 0 && i <= 1 ); m_nBASEALPHAENVMAPMASK = i; #ifdef _DEBUG m_bBASEALPHAENVMAPMASK = true; -#endif +#endif // _DEBUG } - void SetBASEALPHAENVMAPMASK( bool i ) - { - m_nBASEALPHAENVMAPMASK = i ? 1 : 0; -#ifdef _DEBUG - m_bBASEALPHAENVMAPMASK = true; -#endif - } -private: - int m_nSELFILLUM; -#ifdef _DEBUG - bool m_bSELFILLUM; -#endif -public: + void SetSELFILLUM( int i ) { Assert( i >= 0 && i <= 1 ); m_nSELFILLUM = i; #ifdef _DEBUG m_bSELFILLUM = true; -#endif +#endif // _DEBUG } - void SetSELFILLUM( bool i ) - { - m_nSELFILLUM = i ? 1 : 0; -#ifdef _DEBUG - m_bSELFILLUM = true; -#endif - } -private: - int m_nNORMALMAPALPHAENVMAPMASK; -#ifdef _DEBUG - bool m_bNORMALMAPALPHAENVMAPMASK; -#endif -public: + void SetNORMALMAPALPHAENVMAPMASK( int i ) { Assert( i >= 0 && i <= 1 ); m_nNORMALMAPALPHAENVMAPMASK = i; #ifdef _DEBUG m_bNORMALMAPALPHAENVMAPMASK = true; -#endif +#endif // _DEBUG } - void SetNORMALMAPALPHAENVMAPMASK( bool i ) - { - m_nNORMALMAPALPHAENVMAPMASK = i ? 1 : 0; -#ifdef _DEBUG - m_bNORMALMAPALPHAENVMAPMASK = true; -#endif - } -private: - int m_nDIFFUSEBUMPMAP; -#ifdef _DEBUG - bool m_bDIFFUSEBUMPMAP; -#endif -public: + void SetDIFFUSEBUMPMAP( int i ) { Assert( i >= 0 && i <= 1 ); m_nDIFFUSEBUMPMAP = i; #ifdef _DEBUG m_bDIFFUSEBUMPMAP = true; -#endif +#endif // _DEBUG } - void SetDIFFUSEBUMPMAP( bool i ) - { - m_nDIFFUSEBUMPMAP = i ? 1 : 0; -#ifdef _DEBUG - m_bDIFFUSEBUMPMAP = true; -#endif - } -private: - int m_nBASETEXTURENOENVMAP; -#ifdef _DEBUG - bool m_bBASETEXTURENOENVMAP; -#endif -public: + void SetBASETEXTURENOENVMAP( int i ) { Assert( i >= 0 && i <= 1 ); m_nBASETEXTURENOENVMAP = i; #ifdef _DEBUG m_bBASETEXTURENOENVMAP = true; -#endif +#endif // _DEBUG } - void SetBASETEXTURENOENVMAP( bool i ) - { - m_nBASETEXTURENOENVMAP = i ? 1 : 0; -#ifdef _DEBUG - m_bBASETEXTURENOENVMAP = true; -#endif - } -private: - int m_nBASETEXTURE2NOENVMAP; -#ifdef _DEBUG - bool m_bBASETEXTURE2NOENVMAP; -#endif -public: + void SetBASETEXTURE2NOENVMAP( int i ) { Assert( i >= 0 && i <= 1 ); m_nBASETEXTURE2NOENVMAP = i; #ifdef _DEBUG m_bBASETEXTURE2NOENVMAP = true; -#endif +#endif // _DEBUG } - void SetBASETEXTURE2NOENVMAP( bool i ) - { - m_nBASETEXTURE2NOENVMAP = i ? 1 : 0; -#ifdef _DEBUG - m_bBASETEXTURE2NOENVMAP = true; -#endif - } -private: - int m_nWARPLIGHTING; -#ifdef _DEBUG - bool m_bWARPLIGHTING; -#endif -public: + void SetWARPLIGHTING( int i ) { Assert( i >= 0 && i <= 1 ); m_nWARPLIGHTING = i; #ifdef _DEBUG m_bWARPLIGHTING = true; -#endif +#endif // _DEBUG } - void SetWARPLIGHTING( bool i ) - { - m_nWARPLIGHTING = i ? 1 : 0; -#ifdef _DEBUG - m_bWARPLIGHTING = true; -#endif - } -private: - int m_nFANCY_BLENDING; -#ifdef _DEBUG - bool m_bFANCY_BLENDING; -#endif -public: + void SetFANCY_BLENDING( int i ) { Assert( i >= 0 && i <= 1 ); m_nFANCY_BLENDING = i; #ifdef _DEBUG m_bFANCY_BLENDING = true; -#endif +#endif // _DEBUG } - void SetFANCY_BLENDING( bool i ) - { - m_nFANCY_BLENDING = i ? 1 : 0; -#ifdef _DEBUG - m_bFANCY_BLENDING = true; -#endif - } -private: - int m_nRELIEF_MAPPING; -#ifdef _DEBUG - bool m_bRELIEF_MAPPING; -#endif -public: + void SetRELIEF_MAPPING( int i ) { Assert( i >= 0 && i <= 0 ); m_nRELIEF_MAPPING = i; #ifdef _DEBUG m_bRELIEF_MAPPING = true; -#endif +#endif // _DEBUG } - void SetRELIEF_MAPPING( bool i ) - { - m_nRELIEF_MAPPING = i ? 1 : 0; -#ifdef _DEBUG - m_bRELIEF_MAPPING = true; -#endif - } -private: - int m_nSEAMLESS; -#ifdef _DEBUG - bool m_bSEAMLESS; -#endif -public: + void SetSEAMLESS( int i ) { Assert( i >= 0 && i <= 1 ); m_nSEAMLESS = i; #ifdef _DEBUG m_bSEAMLESS = true; -#endif +#endif // _DEBUG } - void SetSEAMLESS( bool i ) - { - m_nSEAMLESS = i ? 1 : 0; -#ifdef _DEBUG - m_bSEAMLESS = true; -#endif - } -private: - int m_nOUTLINE; -#ifdef _DEBUG - bool m_bOUTLINE; -#endif -public: + void SetOUTLINE( int i ) { Assert( i >= 0 && i <= 1 ); m_nOUTLINE = i; #ifdef _DEBUG m_bOUTLINE = true; -#endif +#endif // _DEBUG } - void SetOUTLINE( bool i ) - { - m_nOUTLINE = i ? 1 : 0; -#ifdef _DEBUG - m_bOUTLINE = true; -#endif - } -private: - int m_nSOFTEDGES; -#ifdef _DEBUG - bool m_bSOFTEDGES; -#endif -public: + void SetSOFTEDGES( int i ) { Assert( i >= 0 && i <= 1 ); m_nSOFTEDGES = i; #ifdef _DEBUG m_bSOFTEDGES = true; -#endif +#endif // _DEBUG } - void SetSOFTEDGES( bool i ) - { - m_nSOFTEDGES = i ? 1 : 0; -#ifdef _DEBUG - m_bSOFTEDGES = true; -#endif - } -private: - int m_nBUMPMASK; -#ifdef _DEBUG - bool m_bBUMPMASK; -#endif -public: + void SetBUMPMASK( int i ) { Assert( i >= 0 && i <= 1 ); m_nBUMPMASK = i; #ifdef _DEBUG m_bBUMPMASK = true; -#endif +#endif // _DEBUG } - void SetBUMPMASK( bool i ) - { - m_nBUMPMASK = i ? 1 : 0; -#ifdef _DEBUG - m_bBUMPMASK = true; -#endif - } -private: - int m_nNORMAL_DECODE_MODE; -#ifdef _DEBUG - bool m_bNORMAL_DECODE_MODE; -#endif -public: + void SetNORMAL_DECODE_MODE( int i ) { Assert( i >= 0 && i <= 0 ); m_nNORMAL_DECODE_MODE = i; #ifdef _DEBUG m_bNORMAL_DECODE_MODE = true; -#endif +#endif // _DEBUG } - void SetNORMAL_DECODE_MODE( bool i ) - { - m_nNORMAL_DECODE_MODE = i ? 1 : 0; -#ifdef _DEBUG - m_bNORMAL_DECODE_MODE = true; -#endif - } -private: - int m_nNORMALMASK_DECODE_MODE; -#ifdef _DEBUG - bool m_bNORMALMASK_DECODE_MODE; -#endif -public: + void SetNORMALMASK_DECODE_MODE( int i ) { Assert( i >= 0 && i <= 0 ); m_nNORMALMASK_DECODE_MODE = i; #ifdef _DEBUG m_bNORMALMASK_DECODE_MODE = true; -#endif +#endif // _DEBUG } - void SetNORMALMASK_DECODE_MODE( bool i ) - { - m_nNORMALMASK_DECODE_MODE = i ? 1 : 0; -#ifdef _DEBUG - m_bNORMALMASK_DECODE_MODE = true; -#endif - } -private: - int m_nDETAIL_BLEND_MODE; -#ifdef _DEBUG - bool m_bDETAIL_BLEND_MODE; -#endif -public: + void SetDETAIL_BLEND_MODE( int i ) { Assert( i >= 0 && i <= 11 ); m_nDETAIL_BLEND_MODE = i; #ifdef _DEBUG m_bDETAIL_BLEND_MODE = true; -#endif +#endif // _DEBUG } - void SetDETAIL_BLEND_MODE( bool i ) + + void SetPARALLAXCORRECT( int i ) { - m_nDETAIL_BLEND_MODE = i ? 1 : 0; + Assert( i >= 0 && i <= 1 ); + m_nPARALLAXCORRECT = i; #ifdef _DEBUG - m_bDETAIL_BLEND_MODE = true; -#endif + m_bPARALLAXCORRECT = true; +#endif // _DEBUG } -public: - lightmappedgeneric_ps20b_Static_Index( ) + + lightmappedgeneric_ps20b_Static_Index( IShaderShadow* pShaderShadow, IMaterialVar** params ) { + m_nMASKEDBLENDING = 0; + m_nBASETEXTURE2 = 0; + m_nDETAILTEXTURE = 0; + m_nBUMPMAP = 0; + m_nBUMPMAP2 = 0; + m_nCUBEMAP = 0; + m_nENVMAPMASK = 0; + m_nBASEALPHAENVMAPMASK = 0; + m_nSELFILLUM = 0; + m_nNORMALMAPALPHAENVMAPMASK = 0; + m_nDIFFUSEBUMPMAP = 0; + m_nBASETEXTURENOENVMAP = 0; + m_nBASETEXTURE2NOENVMAP = 0; + m_nWARPLIGHTING = 0; + m_nFANCY_BLENDING = 0; + m_nRELIEF_MAPPING = 0; + m_nSEAMLESS = 0; + m_nOUTLINE = 0; + m_nSOFTEDGES = 0; + m_nBUMPMASK = 0; + m_nNORMAL_DECODE_MODE = 0; + m_nNORMALMASK_DECODE_MODE = 0; + m_nDETAIL_BLEND_MODE = 0; + m_nPARALLAXCORRECT = 0; #ifdef _DEBUG m_bMASKEDBLENDING = false; -#endif // _DEBUG - m_nMASKEDBLENDING = 0; -#ifdef _DEBUG m_bBASETEXTURE2 = false; -#endif // _DEBUG - m_nBASETEXTURE2 = 0; -#ifdef _DEBUG m_bDETAILTEXTURE = false; -#endif // _DEBUG - m_nDETAILTEXTURE = 0; -#ifdef _DEBUG m_bBUMPMAP = false; -#endif // _DEBUG - m_nBUMPMAP = 0; -#ifdef _DEBUG m_bBUMPMAP2 = false; -#endif // _DEBUG - m_nBUMPMAP2 = 0; -#ifdef _DEBUG m_bCUBEMAP = false; -#endif // _DEBUG - m_nCUBEMAP = 0; -#ifdef _DEBUG m_bENVMAPMASK = false; -#endif // _DEBUG - m_nENVMAPMASK = 0; -#ifdef _DEBUG m_bBASEALPHAENVMAPMASK = false; -#endif // _DEBUG - m_nBASEALPHAENVMAPMASK = 0; -#ifdef _DEBUG m_bSELFILLUM = false; -#endif // _DEBUG - m_nSELFILLUM = 0; -#ifdef _DEBUG m_bNORMALMAPALPHAENVMAPMASK = false; -#endif // _DEBUG - m_nNORMALMAPALPHAENVMAPMASK = 0; -#ifdef _DEBUG m_bDIFFUSEBUMPMAP = false; -#endif // _DEBUG - m_nDIFFUSEBUMPMAP = 0; -#ifdef _DEBUG m_bBASETEXTURENOENVMAP = false; -#endif // _DEBUG - m_nBASETEXTURENOENVMAP = 0; -#ifdef _DEBUG m_bBASETEXTURE2NOENVMAP = false; -#endif // _DEBUG - m_nBASETEXTURE2NOENVMAP = 0; -#ifdef _DEBUG m_bWARPLIGHTING = false; -#endif // _DEBUG - m_nWARPLIGHTING = 0; -#ifdef _DEBUG m_bFANCY_BLENDING = false; -#endif // _DEBUG - m_nFANCY_BLENDING = 0; -#ifdef _DEBUG m_bRELIEF_MAPPING = false; -#endif // _DEBUG - m_nRELIEF_MAPPING = 0; -#ifdef _DEBUG m_bSEAMLESS = false; -#endif // _DEBUG - m_nSEAMLESS = 0; -#ifdef _DEBUG m_bOUTLINE = false; -#endif // _DEBUG - m_nOUTLINE = 0; -#ifdef _DEBUG m_bSOFTEDGES = false; -#endif // _DEBUG - m_nSOFTEDGES = 0; -#ifdef _DEBUG m_bBUMPMASK = false; -#endif // _DEBUG - m_nBUMPMASK = 0; -#ifdef _DEBUG m_bNORMAL_DECODE_MODE = false; -#endif // _DEBUG - m_nNORMAL_DECODE_MODE = 0; -#ifdef _DEBUG m_bNORMALMASK_DECODE_MODE = false; -#endif // _DEBUG - m_nNORMALMASK_DECODE_MODE = 0; -#ifdef _DEBUG m_bDETAIL_BLEND_MODE = false; -#endif // _DEBUG - m_nDETAIL_BLEND_MODE = 0; + m_bPARALLAXCORRECT = false; +#endif // _DEBUG } - int GetIndex() + + int GetIndex() const { - // Asserts to make sure that we aren't using any skipped combinations. - // Asserts to make sure that we are setting all of the combination vars. -#ifdef _DEBUG - bool bAllStaticVarsDefined = m_bMASKEDBLENDING && m_bBASETEXTURE2 && m_bDETAILTEXTURE && m_bBUMPMAP && m_bBUMPMAP2 && m_bCUBEMAP && m_bENVMAPMASK && m_bBASEALPHAENVMAPMASK && m_bSELFILLUM && m_bNORMALMAPALPHAENVMAPMASK && m_bDIFFUSEBUMPMAP && m_bBASETEXTURENOENVMAP && m_bBASETEXTURE2NOENVMAP && m_bWARPLIGHTING && m_bFANCY_BLENDING && m_bRELIEF_MAPPING && m_bSEAMLESS && m_bOUTLINE && m_bSOFTEDGES && m_bBUMPMASK && m_bNORMAL_DECODE_MODE && m_bNORMALMASK_DECODE_MODE && m_bDETAIL_BLEND_MODE; - Assert( bAllStaticVarsDefined ); -#endif // _DEBUG - return ( 96 * m_nMASKEDBLENDING ) + ( 192 * m_nBASETEXTURE2 ) + ( 384 * m_nDETAILTEXTURE ) + ( 768 * m_nBUMPMAP ) + ( 2304 * m_nBUMPMAP2 ) + ( 4608 * m_nCUBEMAP ) + ( 9216 * m_nENVMAPMASK ) + ( 18432 * m_nBASEALPHAENVMAPMASK ) + ( 36864 * m_nSELFILLUM ) + ( 73728 * m_nNORMALMAPALPHAENVMAPMASK ) + ( 147456 * m_nDIFFUSEBUMPMAP ) + ( 294912 * m_nBASETEXTURENOENVMAP ) + ( 589824 * m_nBASETEXTURE2NOENVMAP ) + ( 1179648 * m_nWARPLIGHTING ) + ( 2359296 * m_nFANCY_BLENDING ) + ( 4718592 * m_nRELIEF_MAPPING ) + ( 4718592 * m_nSEAMLESS ) + ( 9437184 * m_nOUTLINE ) + ( 18874368 * m_nSOFTEDGES ) + ( 37748736 * m_nBUMPMASK ) + ( 75497472 * m_nNORMAL_DECODE_MODE ) + ( 75497472 * m_nNORMALMASK_DECODE_MODE ) + ( 75497472 * m_nDETAIL_BLEND_MODE ) + 0; + Assert( m_bMASKEDBLENDING && m_bBASETEXTURE2 && m_bDETAILTEXTURE && m_bBUMPMAP && m_bBUMPMAP2 && m_bCUBEMAP && m_bENVMAPMASK && m_bBASEALPHAENVMAPMASK && m_bSELFILLUM && m_bNORMALMAPALPHAENVMAPMASK && m_bDIFFUSEBUMPMAP && m_bBASETEXTURENOENVMAP && m_bBASETEXTURE2NOENVMAP && m_bWARPLIGHTING && m_bFANCY_BLENDING && m_bRELIEF_MAPPING && m_bSEAMLESS && m_bOUTLINE && m_bSOFTEDGES && m_bBUMPMASK && m_bNORMAL_DECODE_MODE && m_bNORMALMASK_DECODE_MODE && m_bDETAIL_BLEND_MODE && m_bPARALLAXCORRECT ); + AssertMsg( !( m_nSEAMLESS && m_nRELIEF_MAPPING ), "Invalid combo combination ( SEAMLESS && RELIEF_MAPPING )" ); + AssertMsg( !( !m_nDETAILTEXTURE && ( m_nDETAIL_BLEND_MODE != 0 ) ), "Invalid combo combination ( !DETAILTEXTURE && ( DETAIL_BLEND_MODE != 0 ) )" ); + AssertMsg( !( m_nSEAMLESS && ( m_nOUTLINE || m_nSOFTEDGES ) ), "Invalid combo combination ( SEAMLESS && ( OUTLINE || SOFTEDGES ) )" ); + AssertMsg( !( m_nBASETEXTURE2 && ( m_nOUTLINE || m_nSOFTEDGES ) ), "Invalid combo combination ( BASETEXTURE2 && ( OUTLINE || SOFTEDGES ) )" ); + AssertMsg( !( m_nBUMPMAP2 && ( m_nOUTLINE || m_nSOFTEDGES ) ), "Invalid combo combination ( BUMPMAP2 && ( OUTLINE || SOFTEDGES ) )" ); + AssertMsg( !( m_nSELFILLUM && ( m_nOUTLINE || m_nSOFTEDGES ) ), "Invalid combo combination ( SELFILLUM && ( OUTLINE || SOFTEDGES ) )" ); + AssertMsg( !( m_nMASKEDBLENDING && ( m_nOUTLINE || m_nSOFTEDGES ) ), "Invalid combo combination ( MASKEDBLENDING && ( OUTLINE || SOFTEDGES ) )" ); + AssertMsg( !( m_nFANCY_BLENDING && ( m_nOUTLINE || m_nSOFTEDGES ) ), "Invalid combo combination ( FANCY_BLENDING && ( OUTLINE || SOFTEDGES ) )" ); + AssertMsg( !( ( m_nDETAILTEXTURE && m_nBUMPMAP ) && ( m_nOUTLINE || m_nSOFTEDGES ) ), "Invalid combo combination ( ( DETAILTEXTURE && BUMPMAP ) && ( OUTLINE || SOFTEDGES ) )" ); + AssertMsg( !( m_nWARPLIGHTING && ( m_nOUTLINE || m_nSOFTEDGES ) ), "Invalid combo combination ( WARPLIGHTING && ( OUTLINE || SOFTEDGES ) )" ); + AssertMsg( !( m_nBUMPMAP && ( m_nOUTLINE || m_nSOFTEDGES ) ), "Invalid combo combination ( BUMPMAP && ( OUTLINE || SOFTEDGES ) )" ); + AssertMsg( !( ( m_nDETAIL_BLEND_MODE == 2 ) || ( ( m_nDETAIL_BLEND_MODE == 3 ) || ( m_nDETAIL_BLEND_MODE == 4 ) ) ), "Invalid combo combination ( ( DETAIL_BLEND_MODE == 2 ) || ( ( DETAIL_BLEND_MODE == 3 ) || ( DETAIL_BLEND_MODE == 4 ) ) )" ); + AssertMsg( !( ( m_nDETAIL_BLEND_MODE == 5 ) || ( ( m_nDETAIL_BLEND_MODE == 6 ) || ( m_nDETAIL_BLEND_MODE == 7 ) ) ), "Invalid combo combination ( ( DETAIL_BLEND_MODE == 5 ) || ( ( DETAIL_BLEND_MODE == 6 ) || ( DETAIL_BLEND_MODE == 7 ) ) )" ); + AssertMsg( !( ( m_nDETAIL_BLEND_MODE == 8 ) || ( m_nDETAIL_BLEND_MODE == 9 ) ), "Invalid combo combination ( ( DETAIL_BLEND_MODE == 8 ) || ( DETAIL_BLEND_MODE == 9 ) )" ); + AssertMsg( !( m_nPARALLAXCORRECT && !m_nCUBEMAP ), "Invalid combo combination ( PARALLAXCORRECT && !CUBEMAP )" ); + AssertMsg( !( m_nBUMPMAP2 && m_nWARPLIGHTING ), "Invalid combo combination ( BUMPMAP2 && WARPLIGHTING )" ); + AssertMsg( !( m_nWARPLIGHTING && m_nDETAILTEXTURE ), "Invalid combo combination ( WARPLIGHTING && DETAILTEXTURE )" ); + AssertMsg( !( m_nENVMAPMASK && m_nBUMPMAP ), "Invalid combo combination ( ENVMAPMASK && BUMPMAP )" ); + AssertMsg( !( m_nNORMALMAPALPHAENVMAPMASK && m_nBASEALPHAENVMAPMASK ), "Invalid combo combination ( NORMALMAPALPHAENVMAPMASK && BASEALPHAENVMAPMASK )" ); + AssertMsg( !( m_nNORMALMAPALPHAENVMAPMASK && m_nENVMAPMASK ), "Invalid combo combination ( NORMALMAPALPHAENVMAPMASK && ENVMAPMASK )" ); + AssertMsg( !( m_nBASEALPHAENVMAPMASK && m_nENVMAPMASK ), "Invalid combo combination ( BASEALPHAENVMAPMASK && ENVMAPMASK )" ); + AssertMsg( !( m_nBASEALPHAENVMAPMASK && m_nSELFILLUM ), "Invalid combo combination ( BASEALPHAENVMAPMASK && SELFILLUM )" ); + AssertMsg( !( !m_nBUMPMAP && m_nDIFFUSEBUMPMAP ), "Invalid combo combination ( !BUMPMAP && DIFFUSEBUMPMAP )" ); + AssertMsg( !( !m_nBUMPMAP && m_nBUMPMAP2 ), "Invalid combo combination ( !BUMPMAP && BUMPMAP2 )" ); + AssertMsg( !( m_nENVMAPMASK && m_nBUMPMAP2 ), "Invalid combo combination ( ENVMAPMASK && BUMPMAP2 )" ); + AssertMsg( !( m_nBASETEXTURENOENVMAP && ( !m_nBASETEXTURE2 || !m_nCUBEMAP ) ), "Invalid combo combination ( BASETEXTURENOENVMAP && ( !BASETEXTURE2 || !CUBEMAP ) )" ); + AssertMsg( !( m_nBASETEXTURE2NOENVMAP && ( !m_nBASETEXTURE2 || !m_nCUBEMAP ) ), "Invalid combo combination ( BASETEXTURE2NOENVMAP && ( !BASETEXTURE2 || !CUBEMAP ) )" ); + AssertMsg( !( m_nBASEALPHAENVMAPMASK && m_nBUMPMAP ), "Invalid combo combination ( BASEALPHAENVMAPMASK && BUMPMAP )" ); + AssertMsg( !( m_nSEAMLESS && m_nRELIEF_MAPPING ), "Invalid combo combination ( SEAMLESS && RELIEF_MAPPING )" ); + AssertMsg( !( m_nSEAMLESS && m_nDETAILTEXTURE ), "Invalid combo combination ( SEAMLESS && DETAILTEXTURE )" ); + AssertMsg( !( m_nSEAMLESS && m_nMASKEDBLENDING ), "Invalid combo combination ( SEAMLESS && MASKEDBLENDING )" ); + AssertMsg( !( m_nBUMPMASK && ( m_nSEAMLESS || ( m_nDETAILTEXTURE || ( m_nSELFILLUM || ( m_nBASETEXTURENOENVMAP || m_nBASETEXTURE2 ) ) ) ) ), "Invalid combo combination ( BUMPMASK && ( SEAMLESS || ( DETAILTEXTURE || ( SELFILLUM || ( BASETEXTURENOENVMAP || BASETEXTURE2 ) ) ) ) )" ); + AssertMsg( !( !m_nBUMPMAP && ( m_nNORMAL_DECODE_MODE == 1 ) ), "Invalid combo combination ( !BUMPMAP && ( NORMAL_DECODE_MODE == 1 ) )" ); + AssertMsg( !( !m_nBUMPMAP && ( m_nNORMAL_DECODE_MODE == 2 ) ), "Invalid combo combination ( !BUMPMAP && ( NORMAL_DECODE_MODE == 2 ) )" ); + AssertMsg( !( !m_nBUMPMAP && ( m_nNORMALMASK_DECODE_MODE == 1 ) ), "Invalid combo combination ( !BUMPMAP && ( NORMALMASK_DECODE_MODE == 1 ) )" ); + AssertMsg( !( !m_nBUMPMAP && ( m_nNORMALMASK_DECODE_MODE == 2 ) ), "Invalid combo combination ( !BUMPMAP && ( NORMALMASK_DECODE_MODE == 2 ) )" ); + return ( 96 * m_nMASKEDBLENDING ) + ( 192 * m_nBASETEXTURE2 ) + ( 384 * m_nDETAILTEXTURE ) + ( 768 * m_nBUMPMAP ) + ( 2304 * m_nBUMPMAP2 ) + ( 4608 * m_nCUBEMAP ) + ( 9216 * m_nENVMAPMASK ) + ( 18432 * m_nBASEALPHAENVMAPMASK ) + ( 36864 * m_nSELFILLUM ) + ( 73728 * m_nNORMALMAPALPHAENVMAPMASK ) + ( 147456 * m_nDIFFUSEBUMPMAP ) + ( 294912 * m_nBASETEXTURENOENVMAP ) + ( 589824 * m_nBASETEXTURE2NOENVMAP ) + ( 1179648 * m_nWARPLIGHTING ) + ( 2359296 * m_nFANCY_BLENDING ) + ( 4718592 * m_nRELIEF_MAPPING ) + ( 4718592 * m_nSEAMLESS ) + ( 9437184 * m_nOUTLINE ) + ( 18874368 * m_nSOFTEDGES ) + ( 37748736 * m_nBUMPMASK ) + ( 75497472 * m_nNORMAL_DECODE_MODE ) + ( 75497472 * m_nNORMALMASK_DECODE_MODE ) + ( 75497472 * m_nDETAIL_BLEND_MODE ) + ( 905969664 * m_nPARALLAXCORRECT ) + 0; } }; -#define shaderStaticTest_lightmappedgeneric_ps20b psh_forgot_to_set_static_MASKEDBLENDING + psh_forgot_to_set_static_BASETEXTURE2 + psh_forgot_to_set_static_DETAILTEXTURE + psh_forgot_to_set_static_BUMPMAP + psh_forgot_to_set_static_BUMPMAP2 + psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_ENVMAPMASK + psh_forgot_to_set_static_BASEALPHAENVMAPMASK + psh_forgot_to_set_static_SELFILLUM + psh_forgot_to_set_static_NORMALMAPALPHAENVMAPMASK + psh_forgot_to_set_static_DIFFUSEBUMPMAP + psh_forgot_to_set_static_BASETEXTURENOENVMAP + psh_forgot_to_set_static_BASETEXTURE2NOENVMAP + psh_forgot_to_set_static_WARPLIGHTING + psh_forgot_to_set_static_FANCY_BLENDING + psh_forgot_to_set_static_RELIEF_MAPPING + psh_forgot_to_set_static_SEAMLESS + psh_forgot_to_set_static_OUTLINE + psh_forgot_to_set_static_SOFTEDGES + psh_forgot_to_set_static_BUMPMASK + psh_forgot_to_set_static_NORMAL_DECODE_MODE + psh_forgot_to_set_static_NORMALMASK_DECODE_MODE + psh_forgot_to_set_static_DETAIL_BLEND_MODE + 0 + +#define shaderStaticTest_lightmappedgeneric_ps20b psh_forgot_to_set_static_MASKEDBLENDING + psh_forgot_to_set_static_BASETEXTURE2 + psh_forgot_to_set_static_DETAILTEXTURE + psh_forgot_to_set_static_BUMPMAP + psh_forgot_to_set_static_BUMPMAP2 + psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_ENVMAPMASK + psh_forgot_to_set_static_BASEALPHAENVMAPMASK + psh_forgot_to_set_static_SELFILLUM + psh_forgot_to_set_static_NORMALMAPALPHAENVMAPMASK + psh_forgot_to_set_static_DIFFUSEBUMPMAP + psh_forgot_to_set_static_BASETEXTURENOENVMAP + psh_forgot_to_set_static_BASETEXTURE2NOENVMAP + psh_forgot_to_set_static_WARPLIGHTING + psh_forgot_to_set_static_FANCY_BLENDING + psh_forgot_to_set_static_RELIEF_MAPPING + psh_forgot_to_set_static_SEAMLESS + psh_forgot_to_set_static_OUTLINE + psh_forgot_to_set_static_SOFTEDGES + psh_forgot_to_set_static_BUMPMASK + psh_forgot_to_set_static_NORMAL_DECODE_MODE + psh_forgot_to_set_static_NORMALMASK_DECODE_MODE + psh_forgot_to_set_static_DETAIL_BLEND_MODE + psh_forgot_to_set_static_PARALLAXCORRECT + + class lightmappedgeneric_ps20b_Dynamic_Index { -private: - int m_nFASTPATHENVMAPCONTRAST; + unsigned int m_nFASTPATHENVMAPCONTRAST : 2; + unsigned int m_nFASTPATH : 2; + unsigned int m_nWRITEWATERFOGTODESTALPHA : 2; + unsigned int m_nPIXELFOGTYPE : 2; + unsigned int m_nLIGHTING_PREVIEW : 2; + unsigned int m_nWRITE_DEPTH_TO_DESTALPHA : 2; #ifdef _DEBUG - bool m_bFASTPATHENVMAPCONTRAST; -#endif + bool m_bFASTPATHENVMAPCONTRAST : 1; + bool m_bFASTPATH : 1; + bool m_bWRITEWATERFOGTODESTALPHA : 1; + bool m_bPIXELFOGTYPE : 1; + bool m_bLIGHTING_PREVIEW : 1; + bool m_bWRITE_DEPTH_TO_DESTALPHA : 1; +#endif // _DEBUG public: void SetFASTPATHENVMAPCONTRAST( int i ) { @@ -606,157 +450,85 @@ public: m_nFASTPATHENVMAPCONTRAST = i; #ifdef _DEBUG m_bFASTPATHENVMAPCONTRAST = true; -#endif +#endif // _DEBUG } - void SetFASTPATHENVMAPCONTRAST( bool i ) - { - m_nFASTPATHENVMAPCONTRAST = i ? 1 : 0; -#ifdef _DEBUG - m_bFASTPATHENVMAPCONTRAST = true; -#endif - } -private: - int m_nFASTPATH; -#ifdef _DEBUG - bool m_bFASTPATH; -#endif -public: + void SetFASTPATH( int i ) { Assert( i >= 0 && i <= 1 ); m_nFASTPATH = i; #ifdef _DEBUG m_bFASTPATH = true; -#endif +#endif // _DEBUG } - void SetFASTPATH( bool i ) - { - m_nFASTPATH = i ? 1 : 0; -#ifdef _DEBUG - m_bFASTPATH = true; -#endif - } -private: - int m_nWRITEWATERFOGTODESTALPHA; -#ifdef _DEBUG - bool m_bWRITEWATERFOGTODESTALPHA; -#endif -public: + void SetWRITEWATERFOGTODESTALPHA( int i ) { Assert( i >= 0 && i <= 1 ); m_nWRITEWATERFOGTODESTALPHA = i; #ifdef _DEBUG m_bWRITEWATERFOGTODESTALPHA = true; -#endif +#endif // _DEBUG } - void SetWRITEWATERFOGTODESTALPHA( bool i ) - { - m_nWRITEWATERFOGTODESTALPHA = i ? 1 : 0; -#ifdef _DEBUG - m_bWRITEWATERFOGTODESTALPHA = true; -#endif - } -private: - int m_nPIXELFOGTYPE; -#ifdef _DEBUG - bool m_bPIXELFOGTYPE; -#endif -public: + void SetPIXELFOGTYPE( int i ) { Assert( i >= 0 && i <= 1 ); m_nPIXELFOGTYPE = i; #ifdef _DEBUG m_bPIXELFOGTYPE = true; -#endif +#endif // _DEBUG } - void SetPIXELFOGTYPE( bool i ) - { - m_nPIXELFOGTYPE = i ? 1 : 0; -#ifdef _DEBUG - m_bPIXELFOGTYPE = true; -#endif - } -private: - int m_nLIGHTING_PREVIEW; -#ifdef _DEBUG - bool m_bLIGHTING_PREVIEW; -#endif -public: + void SetLIGHTING_PREVIEW( int i ) { Assert( i >= 0 && i <= 2 ); m_nLIGHTING_PREVIEW = i; #ifdef _DEBUG m_bLIGHTING_PREVIEW = true; -#endif +#endif // _DEBUG } - void SetLIGHTING_PREVIEW( bool i ) - { - m_nLIGHTING_PREVIEW = i ? 1 : 0; -#ifdef _DEBUG - m_bLIGHTING_PREVIEW = true; -#endif - } -private: - int m_nWRITE_DEPTH_TO_DESTALPHA; -#ifdef _DEBUG - bool m_bWRITE_DEPTH_TO_DESTALPHA; -#endif -public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) { Assert( i >= 0 && i <= 1 ); m_nWRITE_DEPTH_TO_DESTALPHA = i; #ifdef _DEBUG m_bWRITE_DEPTH_TO_DESTALPHA = true; -#endif +#endif // _DEBUG } - void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) - { - m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; -#ifdef _DEBUG - m_bWRITE_DEPTH_TO_DESTALPHA = true; -#endif - } -public: - lightmappedgeneric_ps20b_Dynamic_Index() + + lightmappedgeneric_ps20b_Dynamic_Index( IShaderDynamicAPI* pShaderAPI ) { + m_nFASTPATHENVMAPCONTRAST = 0; + m_nFASTPATH = 0; + m_nWRITEWATERFOGTODESTALPHA = 0; + m_nPIXELFOGTYPE = 0; + m_nLIGHTING_PREVIEW = 0; + m_nWRITE_DEPTH_TO_DESTALPHA = 0; #ifdef _DEBUG m_bFASTPATHENVMAPCONTRAST = false; -#endif // _DEBUG - m_nFASTPATHENVMAPCONTRAST = 0; -#ifdef _DEBUG m_bFASTPATH = false; -#endif // _DEBUG - m_nFASTPATH = 0; -#ifdef _DEBUG m_bWRITEWATERFOGTODESTALPHA = false; -#endif // _DEBUG - m_nWRITEWATERFOGTODESTALPHA = 0; -#ifdef _DEBUG m_bPIXELFOGTYPE = false; -#endif // _DEBUG - m_nPIXELFOGTYPE = 0; -#ifdef _DEBUG m_bLIGHTING_PREVIEW = false; -#endif // _DEBUG - m_nLIGHTING_PREVIEW = 0; -#ifdef _DEBUG m_bWRITE_DEPTH_TO_DESTALPHA = false; -#endif // _DEBUG - m_nWRITE_DEPTH_TO_DESTALPHA = 0; +#endif // _DEBUG } - int GetIndex() + + int GetIndex() const { - // Asserts to make sure that we aren't using any skipped combinations. - // Asserts to make sure that we are setting all of the combination vars. -#ifdef _DEBUG - bool bAllDynamicVarsDefined = m_bFASTPATHENVMAPCONTRAST && m_bFASTPATH && m_bWRITEWATERFOGTODESTALPHA && m_bPIXELFOGTYPE && m_bLIGHTING_PREVIEW && m_bWRITE_DEPTH_TO_DESTALPHA; - Assert( bAllDynamicVarsDefined ); -#endif // _DEBUG + Assert( m_bFASTPATHENVMAPCONTRAST && m_bFASTPATH && m_bWRITEWATERFOGTODESTALPHA && m_bPIXELFOGTYPE && m_bLIGHTING_PREVIEW && m_bWRITE_DEPTH_TO_DESTALPHA ); + AssertMsg( !( !m_nFASTPATH && m_nFASTPATHENVMAPCONTRAST ), "Invalid combo combination ( !FASTPATH && FASTPATHENVMAPCONTRAST )" ); + AssertMsg( !( 1 && ( 1 && ( ( m_nPIXELFOGTYPE != 1 ) && m_nWRITEWATERFOGTODESTALPHA ) ) ), "Invalid combo combination ( 1 && ( 1 && ( ( PIXELFOGTYPE != 1 ) && WRITEWATERFOGTODESTALPHA ) ) )" ); + AssertMsg( !( 1 && ( 1 && ( m_nLIGHTING_PREVIEW && m_nFASTPATHENVMAPCONTRAST ) ) ), "Invalid combo combination ( 1 && ( 1 && ( LIGHTING_PREVIEW && FASTPATHENVMAPCONTRAST ) ) )" ); + AssertMsg( !( 1 && ( 1 && ( m_nLIGHTING_PREVIEW && m_nFASTPATH ) ) ), "Invalid combo combination ( 1 && ( 1 && ( LIGHTING_PREVIEW && FASTPATH ) ) )" ); + AssertMsg( !( 1 && ( 1 && ( ( m_nPIXELFOGTYPE != 1 ) && m_nWRITEWATERFOGTODESTALPHA ) ) ), "Invalid combo combination ( 1 && ( 1 && ( ( PIXELFOGTYPE != 1 ) && WRITEWATERFOGTODESTALPHA ) ) )" ); + AssertMsg( !( 1 && ( 1 && ( m_nLIGHTING_PREVIEW && m_nFASTPATHENVMAPCONTRAST ) ) ), "Invalid combo combination ( 1 && ( 1 && ( LIGHTING_PREVIEW && FASTPATHENVMAPCONTRAST ) ) )" ); + AssertMsg( !( 1 && ( 1 && ( m_nLIGHTING_PREVIEW && m_nFASTPATH ) ) ), "Invalid combo combination ( 1 && ( 1 && ( LIGHTING_PREVIEW && FASTPATH ) ) )" ); return ( 1 * m_nFASTPATHENVMAPCONTRAST ) + ( 2 * m_nFASTPATH ) + ( 4 * m_nWRITEWATERFOGTODESTALPHA ) + ( 8 * m_nPIXELFOGTYPE ) + ( 16 * m_nLIGHTING_PREVIEW ) + ( 48 * m_nWRITE_DEPTH_TO_DESTALPHA ) + 0; } }; -#define shaderDynamicTest_lightmappedgeneric_ps20b psh_forgot_to_set_dynamic_FASTPATHENVMAPCONTRAST + psh_forgot_to_set_dynamic_FASTPATH + psh_forgot_to_set_dynamic_WRITEWATERFOGTODESTALPHA + psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_LIGHTING_PREVIEW + psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + 0 + +#define shaderDynamicTest_lightmappedgeneric_ps20b psh_forgot_to_set_dynamic_FASTPATHENVMAPCONTRAST + psh_forgot_to_set_dynamic_FASTPATH + psh_forgot_to_set_dynamic_WRITEWATERFOGTODESTALPHA + psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_LIGHTING_PREVIEW + psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + diff --git a/materialsystem/stdshaders/lightmappedgeneric_dx9.cpp b/materialsystem/stdshaders/lightmappedgeneric_dx9.cpp index bac124a83a..2a190b9db8 100644 --- a/materialsystem/stdshaders/lightmappedgeneric_dx9.cpp +++ b/materialsystem/stdshaders/lightmappedgeneric_dx9.cpp @@ -73,6 +73,12 @@ BEGIN_VS_SHADER( LightmappedGeneric, SHADER_PARAM( OUTLINESTART1, SHADER_PARAM_TYPE_FLOAT, "0.0", "inner start value for outline") SHADER_PARAM( OUTLINEEND0, SHADER_PARAM_TYPE_FLOAT, "0.0", "inner end value for outline") SHADER_PARAM( OUTLINEEND1, SHADER_PARAM_TYPE_FLOAT, "0.0", "outer end value for outline") + // Parallax cubemaps + SHADER_PARAM( ENVMAPPARALLAXENABLED, SHADER_PARAM_TYPE_BOOL, "0", "Enables parallax cubemaps") + SHADER_PARAM( ENVMAPPARALLAXOBB1, SHADER_PARAM_TYPE_VEC4, "[1 0 0 0]", "The first line of the parallax correction OBB matrix" ) + SHADER_PARAM( ENVMAPPARALLAXOBB2, SHADER_PARAM_TYPE_VEC4, "[0 1 0 0]", "The second line of the parallax correction OBB matrix" ) + SHADER_PARAM( ENVMAPPARALLAXOBB3, SHADER_PARAM_TYPE_VEC4, "[0 0 1 0]", "The third line of the parallax correction OBB matrix" ) + SHADER_PARAM( ENVMAPORIGIN, SHADER_PARAM_TYPE_VEC3, "[0 0 0]", "The world space position of the env_cubemap being corrected" ) END_SHADER_PARAMS void SetupVars( LightmappedGeneric_DX9_Vars_t& info ) @@ -134,6 +140,13 @@ END_SHADER_PARAMS info.m_nOutlineStart1 = OUTLINESTART1; info.m_nOutlineEnd0 = OUTLINEEND0; info.m_nOutlineEnd1 = OUTLINEEND1; + + // Parallax cubemaps + info.m_bEnableParallaxCubemaps = ENVMAPPARALLAXENABLED; + info.m_nEnvmapParallaxObb1 = ENVMAPPARALLAXOBB1; + info.m_nEnvmapParallaxObb2 = ENVMAPPARALLAXOBB2; + info.m_nEnvmapParallaxObb3 = ENVMAPPARALLAXOBB3; + info.m_nEnvmapOrigin = ENVMAPORIGIN; } SHADER_FALLBACK diff --git a/materialsystem/stdshaders/lightmappedgeneric_dx9_helper.cpp b/materialsystem/stdshaders/lightmappedgeneric_dx9_helper.cpp index 6f9c95ac1c..cc02255c27 100644 --- a/materialsystem/stdshaders/lightmappedgeneric_dx9_helper.cpp +++ b/materialsystem/stdshaders/lightmappedgeneric_dx9_helper.cpp @@ -14,6 +14,7 @@ #include "lightmappedgeneric_vs20.inc" #include "lightmappedgeneric_ps20b.inc" +#include "shaderlib/cshader.h" #include "tier0/memdbgon.h" ConVar mat_disable_lightwarp( "mat_disable_lightwarp", "0" ); @@ -58,6 +59,13 @@ public: void InitParamsLightmappedGeneric_DX9( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, LightmappedGeneric_DX9_Vars_t &info ) { + // Parallax cubemaps + // Cubemap parallax correction requires all 4 lines (if the 2nd, 3rd, or 4th are undef, undef the first one (checking done on first var) + if ( info.m_bEnableParallaxCubemaps && !( params[info.m_nEnvmapParallaxObb2]->IsDefined() && params[info.m_nEnvmapParallaxObb3]->IsDefined() && params[info.m_nEnvmapOrigin]->IsDefined() ) ) + { + params[info.m_nEnvmapParallaxObb1]->SetUndefined(); + } + if ( g_pHardwareConfig->SupportsBorderColor() ) { params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight_border" ); @@ -313,6 +321,13 @@ void DrawLightmappedGeneric_DX9_Internal(CBaseVSShader *pShader, IMaterialVar** (info.m_nBlendModulateTexture != -1) && (params[info.m_nBlendModulateTexture]->IsTexture() ); bool hasNormalMapAlphaEnvmapMask = IS_FLAG_SET( MATERIAL_VAR_NORMALMAPALPHAENVMAPMASK ); + // Parallax cubemaps, enable only if explicit. + bool hasParallaxCorrection = info.m_bEnableParallaxCubemaps; + + if ( hasParallaxCorrection ) + { + hasParallaxCorrection = params[info.m_nEnvmapParallaxObb1]->IsDefined(); + } if ( hasFlashlight && !IsX360() ) { @@ -547,34 +562,36 @@ void DrawLightmappedGeneric_DX9_Internal(CBaseVSShader *pShader, IMaterialVar** if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) { - DECLARE_STATIC_PIXEL_SHADER( lightmappedgeneric_ps20b ); - SET_STATIC_PIXEL_SHADER_COMBO( BASETEXTURE2, hasBaseTexture2 ); - SET_STATIC_PIXEL_SHADER_COMBO( DETAILTEXTURE, hasDetailTexture ); - SET_STATIC_PIXEL_SHADER_COMBO( BUMPMAP, bumpmap_variant ); - SET_STATIC_PIXEL_SHADER_COMBO( BUMPMAP2, hasBump2 ); - SET_STATIC_PIXEL_SHADER_COMBO( BUMPMASK, hasBumpMask ); - SET_STATIC_PIXEL_SHADER_COMBO( DIFFUSEBUMPMAP, hasDiffuseBumpmap ); - SET_STATIC_PIXEL_SHADER_COMBO( CUBEMAP, hasEnvmap ); - SET_STATIC_PIXEL_SHADER_COMBO( ENVMAPMASK, hasEnvmapMask ); - SET_STATIC_PIXEL_SHADER_COMBO( BASEALPHAENVMAPMASK, hasBaseAlphaEnvmapMask ); - SET_STATIC_PIXEL_SHADER_COMBO( SELFILLUM, hasSelfIllum ); - SET_STATIC_PIXEL_SHADER_COMBO( NORMALMAPALPHAENVMAPMASK, hasNormalMapAlphaEnvmapMask ); - SET_STATIC_PIXEL_SHADER_COMBO( BASETEXTURENOENVMAP, params[info.m_nBaseTextureNoEnvmap]->GetIntValue() ); - SET_STATIC_PIXEL_SHADER_COMBO( BASETEXTURE2NOENVMAP, params[info.m_nBaseTexture2NoEnvmap]->GetIntValue() ); - SET_STATIC_PIXEL_SHADER_COMBO( WARPLIGHTING, hasLightWarpTexture ); - SET_STATIC_PIXEL_SHADER_COMBO( FANCY_BLENDING, bHasBlendModulateTexture ); - SET_STATIC_PIXEL_SHADER_COMBO( MASKEDBLENDING, bMaskedBlending); - SET_STATIC_PIXEL_SHADER_COMBO( RELIEF_MAPPING, bReliefMapping ); - SET_STATIC_PIXEL_SHADER_COMBO( SEAMLESS, bSeamlessMapping ); - SET_STATIC_PIXEL_SHADER_COMBO( OUTLINE, bHasOutline ); - SET_STATIC_PIXEL_SHADER_COMBO( SOFTEDGES, bHasSoftEdges ); - SET_STATIC_PIXEL_SHADER_COMBO( DETAIL_BLEND_MODE, nDetailBlendMode ); - SET_STATIC_PIXEL_SHADER_COMBO( NORMAL_DECODE_MODE, (int) NORMAL_DECODE_NONE ); - SET_STATIC_PIXEL_SHADER_COMBO( NORMALMASK_DECODE_MODE, (int) NORMAL_DECODE_NONE ); + DECLARE_STATIC_PIXEL_SHADER_NEW( lightmappedgeneric_ps20b ); + SET_STATIC_PIXEL_SHADER_NEW_COMBO( BASETEXTURE2, hasBaseTexture2 ); + SET_STATIC_PIXEL_SHADER_NEW_COMBO( DETAILTEXTURE, hasDetailTexture ); + SET_STATIC_PIXEL_SHADER_NEW_COMBO( BUMPMAP, bumpmap_variant ); + SET_STATIC_PIXEL_SHADER_NEW_COMBO( BUMPMAP2, hasBump2 ); + SET_STATIC_PIXEL_SHADER_NEW_COMBO( BUMPMASK, hasBumpMask ); + SET_STATIC_PIXEL_SHADER_NEW_COMBO( DIFFUSEBUMPMAP, hasDiffuseBumpmap ); + SET_STATIC_PIXEL_SHADER_NEW_COMBO( CUBEMAP, hasEnvmap ); + SET_STATIC_PIXEL_SHADER_NEW_COMBO( ENVMAPMASK, hasEnvmapMask ); + SET_STATIC_PIXEL_SHADER_NEW_COMBO( BASEALPHAENVMAPMASK, hasBaseAlphaEnvmapMask ); + SET_STATIC_PIXEL_SHADER_NEW_COMBO( SELFILLUM, hasSelfIllum ); + SET_STATIC_PIXEL_SHADER_NEW_COMBO( NORMALMAPALPHAENVMAPMASK, hasNormalMapAlphaEnvmapMask ); + SET_STATIC_PIXEL_SHADER_NEW_COMBO( BASETEXTURENOENVMAP, params[info.m_nBaseTextureNoEnvmap]->GetIntValue() ); + SET_STATIC_PIXEL_SHADER_NEW_COMBO( BASETEXTURE2NOENVMAP, params[info.m_nBaseTexture2NoEnvmap]->GetIntValue() ); + SET_STATIC_PIXEL_SHADER_NEW_COMBO( WARPLIGHTING, hasLightWarpTexture ); + SET_STATIC_PIXEL_SHADER_NEW_COMBO( FANCY_BLENDING, bHasBlendModulateTexture ); + SET_STATIC_PIXEL_SHADER_NEW_COMBO( MASKEDBLENDING, bMaskedBlending); + SET_STATIC_PIXEL_SHADER_NEW_COMBO( RELIEF_MAPPING, bReliefMapping ); + SET_STATIC_PIXEL_SHADER_NEW_COMBO( SEAMLESS, bSeamlessMapping ); + SET_STATIC_PIXEL_SHADER_NEW_COMBO( OUTLINE, bHasOutline ); + SET_STATIC_PIXEL_SHADER_NEW_COMBO( SOFTEDGES, bHasSoftEdges ); + SET_STATIC_PIXEL_SHADER_NEW_COMBO( DETAIL_BLEND_MODE, nDetailBlendMode ); + SET_STATIC_PIXEL_SHADER_NEW_COMBO( NORMAL_DECODE_MODE, (int) NORMAL_DECODE_NONE ); + SET_STATIC_PIXEL_SHADER_NEW_COMBO( NORMALMASK_DECODE_MODE, (int) NORMAL_DECODE_NONE ); #ifdef _X360 - SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, hasFlashlight); + SET_STATIC_PIXEL_SHADER_NEW_COMBO( FLASHLIGHT, hasFlashlight); #endif - SET_STATIC_PIXEL_SHADER( lightmappedgeneric_ps20b ); + // Parallax cubemaps enabled for 2_0b and onwards + SET_STATIC_PIXEL_SHADER_NEW_COMBO( PARALLAXCORRECT, hasParallaxCorrection ); + SET_STATIC_PIXEL_SHADER_NEW( lightmappedgeneric_ps20b ); } else { @@ -602,6 +619,7 @@ void DrawLightmappedGeneric_DX9_Internal(CBaseVSShader *pShader, IMaterialVar** SET_STATIC_PIXEL_SHADER_COMBO( NORMAL_DECODE_MODE, 0 ); // No normal compression with ps_2_0 (yikes!) SET_STATIC_PIXEL_SHADER_COMBO( NORMALMASK_DECODE_MODE, 0 ); // No normal compression with ps_2_0 SET_STATIC_PIXEL_SHADER( lightmappedgeneric_ps20 ); + printf("sucks\n"); } // HACK HACK HACK - enable alpha writes all the time so that we have them for // underwater stuff and writing depth to dest alpha @@ -857,6 +875,28 @@ void DrawLightmappedGeneric_DX9_Internal(CBaseVSShader *pShader, IMaterialVar** pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER3, info.m_nBlendModulateTexture, -1 ); } + // Parallax cubemaps + if ( hasParallaxCorrection ) + { + pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 21, params[info.m_nEnvmapOrigin]->GetVecValue() ); + + float *vecs[3]; + vecs[0] = const_cast( params[info.m_nEnvmapParallaxObb1]->GetVecValue() ); + vecs[1] = const_cast( params[info.m_nEnvmapParallaxObb2]->GetVecValue() ); + vecs[2] = const_cast( params[info.m_nEnvmapParallaxObb3]->GetVecValue() ); + float matrix[4][4]; + for ( int i = 0; i < 3; i++ ) + { + for ( int j = 0; j < 4; j++ ) + { + matrix[i][j] = vecs[i][j]; + } + } + matrix[3][0] = matrix[3][1] = matrix[3][2] = 0; + matrix[3][3] = 1; + pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 22, &matrix[0][0], 4 ); + } + pContextData->m_SemiStaticCmdsOut.End(); } } @@ -917,17 +957,17 @@ void DrawLightmappedGeneric_DX9_Internal(CBaseVSShader *pShader, IMaterialVar** float envmapContrast = params[info.m_nEnvmapContrast]->GetFloatValue(); if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) { - DECLARE_DYNAMIC_PIXEL_SHADER( lightmappedgeneric_ps20b ); - SET_DYNAMIC_PIXEL_SHADER_COMBO( FASTPATH, bPixelShaderFastPath || pContextData->m_bPixelShaderForceFastPathBecauseOutline ); - SET_DYNAMIC_PIXEL_SHADER_COMBO( FASTPATHENVMAPCONTRAST, bPixelShaderFastPath && envmapContrast == 1.0f ); - SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + DECLARE_DYNAMIC_PIXEL_SHADER_NEW( lightmappedgeneric_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_NEW_COMBO( FASTPATH, bPixelShaderFastPath || pContextData->m_bPixelShaderForceFastPathBecauseOutline ); + SET_DYNAMIC_PIXEL_SHADER_NEW_COMBO( FASTPATHENVMAPCONTRAST, bPixelShaderFastPath && envmapContrast == 1.0f ); + SET_DYNAMIC_PIXEL_SHADER_NEW_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); // Don't write fog to alpha if we're using translucency - SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, bWriteDepthToAlpha ); - SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITEWATERFOGTODESTALPHA, bWriteWaterFogToAlpha ); - SET_DYNAMIC_PIXEL_SHADER_COMBO( LIGHTING_PREVIEW, nFixedLightingMode ); + SET_DYNAMIC_PIXEL_SHADER_NEW_COMBO( WRITE_DEPTH_TO_DESTALPHA, bWriteDepthToAlpha ); + SET_DYNAMIC_PIXEL_SHADER_NEW_COMBO( WRITEWATERFOGTODESTALPHA, bWriteWaterFogToAlpha ); + SET_DYNAMIC_PIXEL_SHADER_NEW_COMBO( LIGHTING_PREVIEW, nFixedLightingMode ); - SET_DYNAMIC_PIXEL_SHADER_CMD( DynamicCmdsOut, lightmappedgeneric_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_NEW_CMD( DynamicCmdsOut, lightmappedgeneric_ps20b ); } else { diff --git a/materialsystem/stdshaders/lightmappedgeneric_dx9_helper.h b/materialsystem/stdshaders/lightmappedgeneric_dx9_helper.h index 00375b9f1d..57c3e2ed6f 100644 --- a/materialsystem/stdshaders/lightmappedgeneric_dx9_helper.h +++ b/materialsystem/stdshaders/lightmappedgeneric_dx9_helper.h @@ -86,7 +86,12 @@ struct LightmappedGeneric_DX9_Vars_t int m_nOutlineStart1; int m_nOutlineEnd0; int m_nOutlineEnd1; - + // Parallax cubemaps + bool m_bEnableParallaxCubemaps; + int m_nEnvmapParallaxObb1; + int m_nEnvmapParallaxObb2; + int m_nEnvmapParallaxObb3; + int m_nEnvmapOrigin; }; void InitParamsLightmappedGeneric_DX9( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, LightmappedGeneric_DX9_Vars_t &info ); diff --git a/materialsystem/stdshaders/lightmappedgeneric_ps2_3_x.h b/materialsystem/stdshaders/lightmappedgeneric_ps2_3_x.h index 585ea1f680..b8332e11c5 100644 --- a/materialsystem/stdshaders/lightmappedgeneric_ps2_3_x.h +++ b/materialsystem/stdshaders/lightmappedgeneric_ps2_3_x.h @@ -100,7 +100,11 @@ const float4 g_FlashlightAttenuationFactors : register( c13 ); const float3 g_FlashlightPos : register( c14 ); const float4x4 g_FlashlightWorldToTexture : register( c15 ); // through c18 const float4 g_ShadowTweaks : register( c19 ); - +// Parallax cubemaps +#if ( PARALLAXCORRECT ) +const float3 g_CubemapPos : register( c21 ); +const float4x4 g_ObbMatrix : register( c22 ); // Through c25 +#endif sampler BaseTextureSampler : register( s0 ); sampler LightmapSampler : register( s1 ); @@ -530,7 +534,26 @@ HALF4 main( PS_INPUT i ) : COLOR HALF fresnel = 1.0 - dot( worldSpaceNormal, eyeVect ); fresnel = pow( fresnel, 5.0 ); fresnel = fresnel * g_OneMinusFresnelReflection + g_FresnelReflection; - + + // Parallax correction (2_0b and beyond) + // Adapted from http://seblagarde.wordpress.com/2012/09/29/image-based-lighting-approaches-and-parallax-corrected-cubemap/ +#if !( defined( SHADER_MODEL_PS_1_1 ) || defined( SHADER_MODEL_PS_1_4 ) || defined( SHADER_MODEL_PS_2_0 ) ) +#if ( PARALLAXCORRECT ) + float3 worldPos = i.worldPos_projPosZ.xyz; + float3 positionLS = mul( float4( worldPos, 1 ), g_ObbMatrix ); + float3 rayLS = mul( reflectVect, (float3x3)g_ObbMatrix ); + + float3 firstPlaneIntersect = ( float3( 1.0f, 1.0f, 1.0f ) - positionLS ) / rayLS; + float3 secondPlaneIntersect = ( -positionLS ) / rayLS; + float3 furthestPlane = max( firstPlaneIntersect, secondPlaneIntersect ); + float distance = min( furthestPlane.x, min( furthestPlane.y, furthestPlane.z ) ); + + // Use distance in WS directly to recover intersection + float3 intersectPositionWS = worldPos + reflectVect * distance; + reflectVect = intersectPositionWS - g_CubemapPos; +#endif +#endif + specularLighting = ENV_MAP_SCALE * texCUBE( EnvmapSampler, reflectVect ); specularLighting *= specularFactor; diff --git a/materialsystem/stdshaders/lightmappedgeneric_ps2x.fxc b/materialsystem/stdshaders/lightmappedgeneric_ps2x.fxc index 599d16a4ff..32ded72c2f 100644 --- a/materialsystem/stdshaders/lightmappedgeneric_ps2x.fxc +++ b/materialsystem/stdshaders/lightmappedgeneric_ps2x.fxc @@ -24,6 +24,7 @@ // STATIC: "NORMALMASK_DECODE_MODE" "0..0" [PC] // STATIC: "DETAIL_BLEND_MODE" "0..11" // STATIC: "FLASHLIGHT" "0..1" [ps20b] [XBOX] +// STATIC: "PARALLAXCORRECT" "0..1" // DYNAMIC: "FASTPATHENVMAPCONTRAST" "0..1" // DYNAMIC: "FASTPATH" "0..1" @@ -54,6 +55,8 @@ // SKIP: ($DETAIL_BLEND_MODE == 8 ) || ($DETAIL_BLEND_MODE == 9 ) // SKIP ($DETAIL_BLEND_MODE == 10 ) && ($BUMPMAP == 0 ) // SKIP ($DETAIL_BLEND_MODE == 11 ) && ($BUMPMAP != 0 ) +// SKIP: $PARALLAXCORRECT && !$CUBEMAP +// SKIP: $PARALLAXCORRECT [ps20] #include "lightmappedgeneric_ps2_3_x.h" diff --git a/materialsystem/stdshaders/worldvertextransition.cpp b/materialsystem/stdshaders/worldvertextransition.cpp index e7d6a9ab01..076c1cce44 100644 --- a/materialsystem/stdshaders/worldvertextransition.cpp +++ b/materialsystem/stdshaders/worldvertextransition.cpp @@ -119,6 +119,7 @@ BEGIN_VS_SHADER( WorldVertexTransition_DX9, "Help for WorldVertexTransition" ) info.m_nSelfShadowedBumpFlag = SSBUMP; info.m_nSeamlessMappingScale = SEAMLESS_SCALE; info.m_nAlphaTestReference = -1; + info.m_bEnableParallaxCubemaps = false; } SHADER_FALLBACK diff --git a/public/shaderlib/cshader.h b/public/shaderlib/cshader.h index 9c693638bf..5387195922 100644 --- a/public/shaderlib/cshader.h +++ b/public/shaderlib/cshader.h @@ -351,6 +351,7 @@ inline bool CShader_IsFlag2Set( IMaterialVar **params, MaterialVarFlags2_t _flag #define BEGIN_INHERITED_SHADER( _name, _base, _help ) BEGIN_INHERITED_SHADER_FLAGS( _name, _base, _help, 0 ) #define END_INHERITED_SHADER END_SHADER } +#ifndef NEW_SHADER_COMPILE // psh ## shader is used here to generate a warning if you don't ever call SET_DYNAMIC_PIXEL_SHADER #define DECLARE_DYNAMIC_PIXEL_SHADER( shader ) \ int declaredynpixshader_ ## shader ## _missingcurlybraces = 0; \ @@ -488,5 +489,243 @@ inline bool CShader_IsFlag2Set( IMaterialVar **params, MaterialVarFlags2_t _flag NOTE_UNUSED( vsh_testAllCombos ); \ NOTE_UNUSED( vsh ## shader ); \ pShaderShadow->SetVertexShader( #shader, _vshIndex.GetIndex() ) +#else +// psh ## shader is used here to generate a warning if you don't ever call SET_DYNAMIC_PIXEL_SHADER +#define DECLARE_DYNAMIC_PIXEL_SHADER( shader ) \ + shader ## _Dynamic_Index _pshIndex( pShaderAPI ); \ + constexpr int psh ## shader = 1 + +// vsh ## shader is used here to generate a warning if you don't ever call SET_DYNAMIC_VERTEX_SHADER +#define DECLARE_DYNAMIC_VERTEX_SHADER( shader ) \ + shader ## _Dynamic_Index _vshIndex( pShaderAPI ); \ + constexpr int vsh ## shader = 1 + + +// psh ## shader is used here to generate a warning if you don't ever call SET_STATIC_PIXEL_SHADER +#define DECLARE_STATIC_PIXEL_SHADER( shader ) \ + shader ## _Static_Index _pshIndex( pShaderShadow, params ); \ + constexpr int psh ## shader = 1 + +// vsh ## shader is used here to generate a warning if you don't ever call SET_STATIC_VERTEX_SHADER +#define DECLARE_STATIC_VERTEX_SHADER( shader ) \ + shader ## _Static_Index _vshIndex( pShaderShadow, params ); \ + constexpr int vsh ## shader = 1 + + +// psh_forgot_to_set_dynamic_ ## var is used to make sure that you set all +// all combos. If you don't, you will get an undefined variable used error +// in the SET_DYNAMIC_PIXEL_SHADER block. +#define SET_DYNAMIC_PIXEL_SHADER_COMBO( var, val ) \ + _pshIndex.Set ## var( ( val ) ); \ + constexpr int psh_forgot_to_set_dynamic_ ## var = 1 + +#define SET_DYNAMIC_PIXEL_SHADER_COMBO_OVERRIDE_DEFAULT( var, val ) \ + _pshIndex.Set ## var( ( val ) ); + + +// vsh_forgot_to_set_dynamic_ ## var is used to make sure that you set all +// all combos. If you don't, you will get an undefined variable used error +// in the SET_DYNAMIC_VERTEX_SHADER block. +#define SET_DYNAMIC_VERTEX_SHADER_COMBO( var, val ) \ + _vshIndex.Set ## var( ( val ) ); \ + constexpr int vsh_forgot_to_set_dynamic_ ## var = 1 + +#define SET_DYNAMIC_VERTEX_SHADER_COMBO_OVERRIDE_DEFAULT( var, val ) \ + _vshIndex.Set ## var( ( val ) ); + + +// psh_forgot_to_set_static_ ## var is used to make sure that you set all +// all combos. If you don't, you will get an undefined variable used error +// in the SET_STATIC_PIXEL_SHADER block. +#define SET_STATIC_PIXEL_SHADER_COMBO( var, val ) \ + _pshIndex.Set ## var( ( val ) ); \ + constexpr int psh_forgot_to_set_static_ ## var = 1 + +#define SET_STATIC_PIXEL_SHADER_COMBO_OVERRIDE_DEFAULT( var, val ) \ + _pshIndex.Set ## var( ( val ) ); + + +// vsh_forgot_to_set_static_ ## var is used to make sure that you set all +// all combos. If you don't, you will get an undefined variable used error +// in the SET_STATIC_VERTEX_SHADER block. +#define SET_STATIC_VERTEX_SHADER_COMBO( var, val ) \ + _vshIndex.Set ## var( ( val ) ); \ + constexpr int vsh_forgot_to_set_static_ ## var = 1 + +#define SET_STATIC_VERTEX_SHADER_COMBO_OVERRIDE_DEFAULT( var, val ) \ + _vshIndex.Set ## var( ( val ) ); + + +// psh_testAllCombos adds up all of the psh_forgot_to_set_dynamic_ ## var's from +// SET_DYNAMIC_PIXEL_SHADER_COMBO so that an error is generated if they aren't set. +// psh_testAllCombos is set to itself to avoid an unused variable warning. +// psh ## shader being set to itself ensures that DECLARE_DYNAMIC_PIXEL_SHADER +// was called for this particular shader. +#define SET_DYNAMIC_PIXEL_SHADER( shader ) \ + static_assert( ( shaderDynamicTest_ ## shader ) != 0, "Missing combo!" ); \ + static_assert( psh ## shader != 0, "Not pixel shader!" ); \ + pShaderAPI->SetPixelShaderIndex( _pshIndex.GetIndex() ) + +#define SET_DYNAMIC_PIXEL_SHADER_CMD( cmdstream, shader ) \ + static_assert( ( shaderDynamicTest_ ## shader ) != 0, "Missing combo!" ); \ + static_assert( psh ## shader != 0, "Not pixel shader!" ); \ + cmdstream.SetPixelShaderIndex( _pshIndex.GetIndex() ) + + +// vsh_testAllCombos adds up all of the vsh_forgot_to_set_dynamic_ ## var's from +// SET_DYNAMIC_VERTEX_SHADER_COMBO so that an error is generated if they aren't set. +// vsh_testAllCombos is set to itself to avoid an unused variable warning. +// vsh ## shader being set to itself ensures that DECLARE_DYNAMIC_VERTEX_SHADER +// was called for this particular shader. +#define SET_DYNAMIC_VERTEX_SHADER( shader ) \ + static_assert( ( shaderDynamicTest_ ## shader ) != 0, "Missing combo!" ); \ + static_assert( vsh ## shader != 0, "Not vertex shader!" ); \ + pShaderAPI->SetVertexShaderIndex( _vshIndex.GetIndex() ) + +#define SET_DYNAMIC_VERTEX_SHADER_CMD( cmdstream, shader ) \ + static_assert( shaderDynamicTest_ ## shader != 0, "Missing combo!" ); \ + static_assert( vsh ## shader != 0, "Not vertex shader!" ); \ + cmdstream.SetVertexShaderIndex( _vshIndex.GetIndex() ) + + +// psh_testAllCombos adds up all of the psh_forgot_to_set_static_ ## var's from +// SET_STATIC_PIXEL_SHADER_COMBO so that an error is generated if they aren't set. +// psh_testAllCombos is set to itself to avoid an unused variable warning. +// psh ## shader being set to itself ensures that DECLARE_STATIC_PIXEL_SHADER +// was called for this particular shader. +#define SET_STATIC_PIXEL_SHADER( shader ) \ + static_assert( ( shaderStaticTest_ ## shader ) != 0, "Missing combo!" ); \ + static_assert( psh ## shader != 0, "Not pixel shader!" ); \ + pShaderShadow->SetPixelShader( #shader, _pshIndex.GetIndex() ) + +// vsh_testAllCombos adds up all of the vsh_forgot_to_set_static_ ## var's from +// SET_STATIC_VERTEX_SHADER_COMBO so that an error is generated if they aren't set. +// vsh_testAllCombos is set to itself to avoid an unused variable warning. +// vsh ## shader being set to itself ensures that DECLARE_STATIC_VERTEX_SHADER +// was called for this particular shader. +#define SET_STATIC_VERTEX_SHADER( shader ) \ + static_assert( shaderStaticTest_ ## shader != 0, "Missing combo!" ); \ + static_assert( vsh ## shader != 0, "Not vertex shader!" ); \ + pShaderShadow->SetVertexShader( #shader, _vshIndex.GetIndex() ) +#endif + + +// psh ## shader is used here to generate a warning if you don't ever call SET_DYNAMIC_PIXEL_SHADER +#define DECLARE_DYNAMIC_PIXEL_SHADER_NEW( shader ) \ + shader ## _Dynamic_Index _pshIndex( pShaderAPI ); \ + constexpr int psh ## shader = 1 + +// vsh ## shader is used here to generate a warning if you don't ever call SET_DYNAMIC_VERTEX_SHADER_NEW +#define DECLARE_DYNAMIC_VERTEX_SHADER_NEW( shader ) \ + shader ## _Dynamic_Index _vshIndex( pShaderAPI ); \ + constexpr int vsh ## shader = 1 + + +// psh ## shader is used here to generate a warning if you don't ever call SET_STATIC_PIXEL_SHADER_NEW +#define DECLARE_STATIC_PIXEL_SHADER_NEW( shader ) \ + shader ## _Static_Index _pshIndex( pShaderShadow, params ); \ + constexpr int psh ## shader = 1 + +// vsh ## shader is used here to generate a warning if you don't ever call SET_STATIC_VERTEX_SHADER_NEW +#define DECLARE_STATIC_VERTEX_SHADER_NEW( shader ) \ + shader ## _Static_Index _vshIndex( pShaderShadow, params ); \ + constexpr int vsh ## shader = 1 + + +// psh_forgot_to_set_dynamic_ ## var is used to make sure that you set all +// all combos. If you don't, you will get an undefined variable used error +// in the SET_DYNAMIC_PIXEL_SHADER_NEW block. +#define SET_DYNAMIC_PIXEL_SHADER_NEW_COMBO( var, val ) \ + _pshIndex.Set ## var( ( val ) ); \ + constexpr int psh_forgot_to_set_dynamic_ ## var = 1 + +#define SET_DYNAMIC_PIXEL_SHADER_NEW_COMBO_OVERRIDE_DEFAULT( var, val ) \ + _pshIndex.Set ## var( ( val ) ); + + +// vsh_forgot_to_set_dynamic_ ## var is used to make sure that you set all +// all combos. If you don't, you will get an undefined variable used error +// in the SET_DYNAMIC_VERTEX_SHADER_NEW block. +#define SET_DYNAMIC_VERTEX_SHADER_NEW_COMBO( var, val ) \ + _vshIndex.Set ## var( ( val ) ); \ + constexpr int vsh_forgot_to_set_dynamic_ ## var = 1 + +#define SET_DYNAMIC_VERTEX_SHADER_NEW_COMBO_OVERRIDE_DEFAULT( var, val ) \ + _vshIndex.Set ## var( ( val ) ); + + +// psh_forgot_to_set_static_ ## var is used to make sure that you set all +// all combos. If you don't, you will get an undefined variable used error +// in the SET_STATIC_PIXEL_SHADER_NEW block. +#define SET_STATIC_PIXEL_SHADER_NEW_COMBO( var, val ) \ + _pshIndex.Set ## var( ( val ) ); \ + constexpr int psh_forgot_to_set_static_ ## var = 1 + +#define SET_STATIC_PIXEL_SHADER_NEW_COMBO_OVERRIDE_DEFAULT( var, val ) \ + _pshIndex.Set ## var( ( val ) ); + + +// vsh_forgot_to_set_static_ ## var is used to make sure that you set all +// all combos. If you don't, you will get an undefined variable used error +// in the SET_STATIC_VERTEX_SHADER_NEW block. +#define SET_STATIC_VERTEX_SHADER_NEW_COMBO( var, val ) \ + _vshIndex.Set ## var( ( val ) ); \ + constexpr int vsh_forgot_to_set_static_ ## var = 1 + +#define SET_STATIC_VERTEX_SHADER_NEW_COMBO_OVERRIDE_DEFAULT( var, val ) \ + _vshIndex.Set ## var( ( val ) ); + + +// psh_testAllCombos adds up all of the psh_forgot_to_set_dynamic_ ## var's from +// SET_DYNAMIC_PIXEL_SHADER_NEW_COMBO so that an error is generated if they aren't set. +// psh_testAllCombos is set to itself to avoid an unused variable warning. +// psh ## shader being set to itself ensures that DECLARE_DYNAMIC_PIXEL_SHADER_NEW +// was called for this particular shader. +#define SET_DYNAMIC_PIXEL_SHADER_NEW( shader ) \ + static_assert( ( shaderDynamicTest_ ## shader ) != 0, "Missing combo!" ); \ + static_assert( psh ## shader != 0, "Not pixel shader!" ); \ + pShaderAPI->SetPixelShaderIndex( _pshIndex.GetIndex() ) + +#define SET_DYNAMIC_PIXEL_SHADER_NEW_CMD( cmdstream, shader ) \ + static_assert( ( shaderDynamicTest_ ## shader ) != 0, "Missing combo!" ); \ + static_assert( psh ## shader != 0, "Not pixel shader!" ); \ + cmdstream.SetPixelShaderIndex( _pshIndex.GetIndex() ) + + +// vsh_testAllCombos adds up all of the vsh_forgot_to_set_dynamic_ ## var's from +// SET_DYNAMIC_VERTEX_SHADER_NEW_COMBO so that an error is generated if they aren't set. +// vsh_testAllCombos is set to itself to avoid an unused variable warning. +// vsh ## shader being set to itself ensures that DECLARE_DYNAMIC_VERTEX_SHADER_NEW +// was called for this particular shader. +#define SET_DYNAMIC_VERTEX_SHADER_NEW( shader ) \ + static_assert( ( shaderDynamicTest_ ## shader ) != 0, "Missing combo!" ); \ + static_assert( vsh ## shader != 0, "Not vertex shader!" ); \ + pShaderAPI->SetVertexShaderIndex( _vshIndex.GetIndex() ) + +#define SET_DYNAMIC_VERTEX_SHADER_NEW_CMD( cmdstream, shader ) \ + static_assert( shaderDynamicTest_ ## shader != 0, "Missing combo!" ); \ + static_assert( vsh ## shader != 0, "Not vertex shader!" ); \ + cmdstream.SetVertexShaderIndex( _vshIndex.GetIndex() ) + + +// psh_testAllCombos adds up all of the psh_forgot_to_set_static_ ## var's from +// SET_STATIC_PIXEL_SHADER_NEW_COMBO so that an error is generated if they aren't set. +// psh_testAllCombos is set to itself to avoid an unused variable warning. +// psh ## shader being set to itself ensures that DECLARE_STATIC_PIXEL_SHADER_NEW +// was called for this particular shader. +#define SET_STATIC_PIXEL_SHADER_NEW( shader ) \ + static_assert( ( shaderStaticTest_ ## shader ) != 0, "Missing combo!" ); \ + static_assert( psh ## shader != 0, "Not pixel shader!" ); \ + pShaderShadow->SetPixelShader( #shader, _pshIndex.GetIndex() ) + +// vsh_testAllCombos adds up all of the vsh_forgot_to_set_static_ ## var's from +// SET_STATIC_VERTEX_SHADER_NEW_COMBO so that an error is generated if they aren't set. +// vsh_testAllCombos is set to itself to avoid an unused variable warning. +// vsh ## shader being set to itself ensures that DECLARE_STATIC_VERTEX_SHADER_NEW +// was called for this particular shader. +#define SET_STATIC_VERTEX_SHADER_NEW( shader ) \ + static_assert( shaderStaticTest_ ## shader != 0, "Missing combo!" ); \ + static_assert( vsh ## shader != 0, "Not vertex shader!" ); \ + pShaderShadow->SetVertexShader( #shader, _vshIndex.GetIndex() ) #endif // CSHADER_H diff --git a/utils/vbsp/cubemap.cpp b/utils/vbsp/cubemap.cpp index 829efdfb9e..dde80bcac8 100644 --- a/utils/vbsp/cubemap.cpp +++ b/utils/vbsp/cubemap.cpp @@ -76,7 +76,7 @@ struct CubemapSideData_t }; static CubemapSideData_t s_aCubemapSideData[MAX_MAP_BRUSHSIDES]; - +char *g_pParallaxObbStrs[MAX_MAP_CUBEMAPSAMPLES]; inline bool SideHasCubemapAndWasntManuallyReferenced( int iSide ) @@ -85,8 +85,10 @@ inline bool SideHasCubemapAndWasntManuallyReferenced( int iSide ) } -void Cubemap_InsertSample( const Vector& origin, int size ) +void Cubemap_InsertSample( const Vector &origin, int size, char *pParallaxObbStr = "" ) { + g_pParallaxObbStrs[g_nCubemapSamples] = pParallaxObbStr; + dcubemapsample_t *pSample = &g_CubemapSamples[g_nCubemapSamples]; pSample->origin[0] = ( int )origin[0]; pSample->origin[1] = ( int )origin[1]; @@ -528,7 +530,7 @@ static void GeneratePatchedName( const char *pMaterialName, const PatchInfo_t &i //----------------------------------------------------------------------------- // Patches the $envmap for a material and all its dependents, returns true if any patching happened //----------------------------------------------------------------------------- -static bool PatchEnvmapForMaterialAndDependents( const char *pMaterialName, const PatchInfo_t &info, const char *pCubemapTexture ) +static bool PatchEnvmapForMaterialAndDependents( const char *pMaterialName, const PatchInfo_t &info, const char *pCubemapTexture, const char *pParallaxObbMatrix = "" ) { // Do *NOT* patch the material if there is an $envmap specified and it's not 'env_cubemap' @@ -546,7 +548,7 @@ static bool PatchEnvmapForMaterialAndDependents( const char *pMaterialName, cons const char *pDependentMaterial = FindDependentMaterial( pMaterialName, &pDependentMaterialVar ); if ( pDependentMaterial ) { - bDependentMaterialPatched = PatchEnvmapForMaterialAndDependents( pDependentMaterial, info, pCubemapTexture ); + bDependentMaterialPatched = PatchEnvmapForMaterialAndDependents( pDependentMaterial, info, pCubemapTexture, pParallaxObbMatrix ); } // If we have neither to patch, we're done @@ -557,7 +559,7 @@ static bool PatchEnvmapForMaterialAndDependents( const char *pMaterialName, cons char pPatchedMaterialName[1024]; GeneratePatchedName( pMaterialName, info, true, pPatchedMaterialName, 1024 ); - MaterialPatchInfo_t pPatchInfo[2]; + MaterialPatchInfo_t pPatchInfo[6]; int nPatchCount = 0; if ( bShouldPatchEnvCubemap ) { @@ -578,7 +580,30 @@ static bool PatchEnvmapForMaterialAndDependents( const char *pMaterialName, cons ++nPatchCount; } - CreateMaterialPatch( pMaterialName, pPatchedMaterialName, nPatchCount, pPatchInfo, PATCH_REPLACE ); + // Parallax cubemap matrix + CUtlVector matRowList; + if ( pParallaxObbMatrix[0] != '\0' ) + { + V_SplitString( pParallaxObbMatrix, ";", matRowList ); + + pPatchInfo[nPatchCount].m_pKey = "$envMapParallaxOBB1"; + pPatchInfo[nPatchCount].m_pValue = matRowList[0]; + ++nPatchCount; + pPatchInfo[nPatchCount].m_pKey = "$envMapParallaxOBB2"; + pPatchInfo[nPatchCount].m_pValue = matRowList[1]; + ++nPatchCount; + pPatchInfo[nPatchCount].m_pKey = "$envMapParallaxOBB3"; + pPatchInfo[nPatchCount].m_pValue = matRowList[2]; + ++nPatchCount; + pPatchInfo[nPatchCount].m_pKey = "$envMapOrigin"; + pPatchInfo[nPatchCount].m_pValue = matRowList[3]; + ++nPatchCount; + } + + CreateMaterialPatch( pMaterialName, pPatchedMaterialName, nPatchCount, pPatchInfo, PATCH_INSERT ); + + // Clean up parallax stuff + matRowList.PurgeAndDeleteElements(); return true; } @@ -597,7 +622,7 @@ static bool PatchEnvmapForMaterialAndDependents( const char *pMaterialName, cons // default (skybox) cubemap into this file so the cubemap doesn't have the pink checkerboard at // runtime before they run buildcubemaps. //----------------------------------------------------------------------------- -static int Cubemap_CreateTexInfo( int originalTexInfo, int origin[3] ) +static int Cubemap_CreateTexInfo( int originalTexInfo, int origin[3], int cubemapIndex ) { // Don't make cubemap tex infos for nodes if ( originalTexInfo == TEXINFO_NODE ) @@ -638,9 +663,16 @@ static int Cubemap_CreateTexInfo( int originalTexInfo, int origin[3] ) char pTextureName[1024]; GeneratePatchedName( "c", info, false, pTextureName, 1024 ); + // Append origin info if this cubemap has a parallax OBB + char originAppendedString[1024] = ""; + if ( g_pParallaxObbStrs[cubemapIndex][0] != '\0' ) + { + Q_snprintf( originAppendedString, 1024, "%s;[%d %d %d]", g_pParallaxObbStrs[cubemapIndex], origin[0], origin[1], origin[2] ); + } + // Hook the texture into the material and all dependent materials // but if no hooking was necessary, exit out - if ( !PatchEnvmapForMaterialAndDependents( pMaterialName, info, pTextureName ) ) + if ( !PatchEnvmapForMaterialAndDependents( pMaterialName, info, pTextureName, originAppendedString ) ) return originalTexInfo; // Store off the name of the cubemap that we need to create since we successfully patched @@ -730,7 +762,7 @@ void Cubemap_FixupBrushSidesMaterials( void ) } #endif - pSide->texinfo = Cubemap_CreateTexInfo( pSide->texinfo, g_CubemapSamples[cubemapID].origin ); + pSide->texinfo = Cubemap_CreateTexInfo( pSide->texinfo, g_CubemapSamples[cubemapID].origin, cubemapID ); if ( pSide->pMapDisp ) { pSide->pMapDisp->face.texinfo = pSide->texinfo; @@ -946,7 +978,7 @@ void Cubemap_AttachDefaultCubemapToSpecularSides( void ) Assert( pSide->texinfo == pSide->pMapDisp->face.texinfo ); } #endif - pSide->texinfo = Cubemap_CreateTexInfo( pSide->texinfo, g_CubemapSamples[iCubemap].origin ); + pSide->texinfo = Cubemap_CreateTexInfo( pSide->texinfo, g_CubemapSamples[iCubemap].origin, iCubemap ); if ( pSide->pMapDisp ) { pSide->pMapDisp->face.texinfo = pSide->texinfo; diff --git a/utils/vbsp/map.cpp b/utils/vbsp/map.cpp index 2221c79fff..d2229ea1a2 100644 --- a/utils/vbsp/map.cpp +++ b/utils/vbsp/map.cpp @@ -5,6 +5,7 @@ // $NoKeywords: $ //=============================================================================// +#include "matrixinvert.h" #include "vbsp.h" #include "map_shared.h" #include "disp_vbsp.h" @@ -1617,17 +1618,97 @@ ChunkFileResult_t CMapFile::LoadEntityCallback(CChunkFile *pFile, int nParam) { if( ( g_nDXLevel == 0 ) || ( g_nDXLevel >= 70 ) ) { - const char *pSideListStr = ValueForKey( mapent, "sides" ); + const char* pSideListStr = ValueForKey( mapent, "sides" ); + char *pParallaxObbStr = ValueForKey( mapent, "parallaxobb" ); int size; size = IntForKey( mapent, "cubemapsize" ); - Cubemap_InsertSample( mapent->origin, size ); - Cubemap_SaveBrushSides( pSideListStr ); + Cubemap_InsertSample( mapent->origin, size, pParallaxObbStr ); } // clear out this entity mapent->epairs = NULL; return(ChunkFile_Ok); } + // + // parallax_obb brushes are removed after the transformation matrix is found and saved into + // the entity's data (ent will be removed after data transferred to patched materials) + // + if ( !strcmp( "parallax_obb", pClassName ) ) + { + matrix3x4_t obbMatrix, invObbMatrix; + SetIdentityMatrix( obbMatrix ); + SetIdentityMatrix( invObbMatrix ); + + // Get corner and its 3 edges (scaled, local x, y, and z axes) + mapbrush_t *brush = &mapbrushes[mapent->firstbrush]; + Vector corner, x, y, z; + + // Find first valid winding (with these whiles, if not enough valid windings then identity matrix is passed through to VMTs) + int i = 0; + while ( i < brush->numsides ) + { + winding_t *wind = brush->original_sides[i].winding; + if ( !wind ) + { + i++; + continue; + } + + corner = wind->p[0]; + y = wind->p[1] - corner; + z = wind->p[3] - corner; + x = CrossProduct( y, z ).Normalized(); + + i++; + break; + } + + // Skip second valid winding (opposite face from first, unusable for finding Z's length) + while ( i < brush->numsides ) + { + winding_t *wind = brush->original_sides[i].winding; + if ( !wind ) + { + i++; + continue; + } + i++; + break; + } + + // Find third valid winding + while ( i < brush->numsides ) + { + winding_t *wind = brush->original_sides[i].winding; + if ( !wind ) + { + i++; + continue; + } + + // Find length of X + // Start with diagonal, then scale X by the projection of diag onto X + Vector diag = wind->p[0] - wind->p[2]; + x *= abs( DotProduct( diag, x ) ); + + // Build transformation matrix (what is needed to turn a [0,0,0] - [1,1,1] cube into this brush) + MatrixSetColumn( x, 0, obbMatrix ); + MatrixSetColumn( y, 1, obbMatrix ); + MatrixSetColumn( z, 2, obbMatrix ); + MatrixSetColumn( corner, 3, obbMatrix ); + + // Find inverse (we need the world to local matrix, "transformationmatrix" is kind of a misnomer) + MatrixInversion( obbMatrix, invObbMatrix ); + break; + } + + char szMatrix[1024]; + Q_snprintf( szMatrix, 1024, "[%f %f %f %f];[%f %f %f %f];[%f %f %f %f]", invObbMatrix[0][0], invObbMatrix[0][1], invObbMatrix[0][2], invObbMatrix[0][3], invObbMatrix[1][0], invObbMatrix[1][1], invObbMatrix[1][2], invObbMatrix[1][3], invObbMatrix[2][0], invObbMatrix[2][1], invObbMatrix[2][2], invObbMatrix[2][3] ); + SetKeyValue( mapent, "transformationmatrix", szMatrix ); + + return ( ChunkFile_Ok ); + } + if ( !strcmp( "test_sidelist", pClassName ) ) { ConvertSideList(mapent, "sides"); @@ -2611,6 +2692,28 @@ bool LoadMapFile( const char *pszFileName ) if ((eResult == ChunkFile_Ok) || (eResult == ChunkFile_EOF)) { + // Fill out parallax obb matrix array + for ( int i = 0; i < g_nCubemapSamples; i++ ) + { + if ( g_pParallaxObbStrs[i][0] != '\0' ) + { + entity_t *obbEnt = EntityByName( g_pParallaxObbStrs[i] ); + g_pParallaxObbStrs[i] = ValueForKey( obbEnt, "transformationmatrix" ); + } + } + + // Remove parallax_obb entities (in a nice slow linear search) + for ( int i = 0; i < g_MainMap->num_entities; i++ ) + { + entity_t *mapent = &g_MainMap->entities[i]; + const char *pClassName = ValueForKey( mapent, "classname" ); + if ( !strcmp( "parallax_obb", pClassName ) ) + { + mapent->numbrushes = 0; + mapent->epairs = NULL; + } + } + // Update the overlay/side list(s). Overlay_UpdateSideLists( g_LoadingMap->m_StartMapOverlays ); OverlayTransition_UpdateSideLists( g_LoadingMap->m_StartMapWaterOverlays ); diff --git a/utils/vbsp/vbsp.h b/utils/vbsp/vbsp.h index 689bbaa874..98507ce3f6 100644 --- a/utils/vbsp/vbsp.h +++ b/utils/vbsp/vbsp.h @@ -607,7 +607,8 @@ void SaveVertexNormals( void ); //============================================================================= // cubemap.cpp -void Cubemap_InsertSample( const Vector& origin, int size ); +extern char *g_pParallaxObbStrs[MAX_MAP_CUBEMAPSAMPLES]; +void Cubemap_InsertSample( const Vector &origin, int size, char *pParallaxObbStr ); void Cubemap_CreateDefaultCubemaps( void ); void Cubemap_SaveBrushSides( const char *pSideListStr ); void Cubemap_FixupBrushSidesMaterials( void );