Skip to content

Commit bb39e2a

Browse files
committed
Add support for color correction exclusion mask
1 parent 6cc2937 commit bb39e2a

24 files changed

Lines changed: 1100 additions & 98 deletions

sp/src/game/client/baseclientrendertargets.cpp

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,30 @@ ITexture* CBaseClientRenderTargets::CreateCameraTexture( IMaterialSystem* pMater
4545
CREATERENDERTARGETFLAGS_HDR );
4646
}
4747

48+
#ifdef MAPBASE
49+
ITexture* CBaseClientRenderTargets::CreateCustomCameraTexture( IMaterialSystem* pMaterialSystem, const char *pszTextureName, int iSize )
50+
{
51+
return pMaterialSystem->CreateNamedRenderTargetTextureEx2(
52+
pszTextureName,
53+
iSize, iSize, RT_SIZE_DEFAULT,
54+
pMaterialSystem->GetBackBufferFormat(),
55+
MATERIAL_RT_DEPTH_SHARED,
56+
0,
57+
CREATERENDERTARGETFLAGS_HDR );
58+
}
59+
60+
ITexture* CBaseClientRenderTargets::CreateColCorrectMaskTexture( IMaterialSystem* pMaterialSystem, int iSize )
61+
{
62+
return pMaterialSystem->CreateNamedRenderTargetTextureEx2(
63+
"_rt_ColCorrectMask",
64+
iSize, iSize, RT_SIZE_PICMIP,
65+
pMaterialSystem->GetBackBufferFormat(), //IMAGE_FORMAT_A8
66+
MATERIAL_RT_DEPTH_SHARED,
67+
TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT,
68+
CREATERENDERTARGETFLAGS_HDR );
69+
}
70+
#endif
71+
4872
//-----------------------------------------------------------------------------
4973
// Purpose: Called by the engine in material system init and shutdown.
5074
// Clients should override this in their inherited version, but the base
@@ -60,6 +84,21 @@ void CBaseClientRenderTargets::InitClientRenderTargets( IMaterialSystem* pMateri
6084

6185
// Monitors
6286
m_CameraTexture.Init( CreateCameraTexture( pMaterialSystem, iCameraTextureSize ) );
87+
88+
#ifdef MAPBASE
89+
int iNumCameras = CommandLine()->ParmValue( "-numcameratextures", 3 );
90+
for ( int i = 0; i < iNumCameras; i++ )
91+
{
92+
char szName[32];
93+
Q_snprintf( szName, sizeof(szName), "_rt_Camera%i", i );
94+
95+
int iRefIndex = m_CameraTextures.AddToTail();
96+
m_CameraTextures[iRefIndex].Init( CreateCustomCameraTexture( pMaterialSystem, szName, iCameraTextureSize ) );
97+
}
98+
99+
// Miscellaneous
100+
m_ColCorrectMaskTexture.Init( CreateColCorrectMaskTexture( pMaterialSystem ) );
101+
#endif
63102
}
64103

65104
//-----------------------------------------------------------------------------
@@ -75,4 +114,14 @@ void CBaseClientRenderTargets::ShutdownClientRenderTargets()
75114

76115
// Monitors
77116
m_CameraTexture.Shutdown();
78-
}
117+
118+
#ifdef MAPBASE
119+
for ( int i = 0; i < m_CameraTextures.Count(); i++ )
120+
{
121+
m_CameraTextures[i].Shutdown();
122+
}
123+
124+
// Miscellaneous
125+
m_ColCorrectMaskTexture.Shutdown();
126+
#endif
127+
}

sp/src/game/client/baseclientrendertargets.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ class CBaseClientRenderTargets : public IClientRenderTargets
5959
ITexture* CreateWaterRefractionTexture( IMaterialSystem* pMaterialSystem, int iSize = 1024 );
6060
ITexture* CreateCameraTexture( IMaterialSystem* pMaterialSystem, int iSize = 256 );
6161

62+
#ifdef MAPBASE
63+
// Mapbase render targets
64+
CUtlVector<CTextureReference> m_CameraTextures;
65+
CTextureReference m_ColCorrectMaskTexture;
66+
67+
ITexture *CreateCustomCameraTexture( IMaterialSystem *pMaterialSystem, const char *pszTextureName, int iSize = 256 );
68+
ITexture *CreateColCorrectMaskTexture( IMaterialSystem *pMaterialSystem, int iSize = 1024 );
69+
#endif
70+
6271
};
6372

6473
#endif // CLIENTRENDERTARTETS_H_

sp/src/game/client/c_baseentity.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3710,7 +3710,9 @@ void C_BaseEntity::ComputeFxBlend( void )
37103710
//-----------------------------------------------------------------------------
37113711
int C_BaseEntity::GetFxBlend( void )
37123712
{
3713+
#ifndef MAPBASE // Spams the console when drawing beams in stencils, which don't need to update the FX blend
37133714
Assert( m_nFXComputeFrame == gpGlobals->framecount );
3715+
#endif
37143716
return m_nRenderFXBlend;
37153717
}
37163718

sp/src/game/client/c_colorcorrection.cpp

Lines changed: 96 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,14 @@ IMPLEMENT_CLIENTCLASS_DT(C_ColorCorrection, DT_ColorCorrection, CColorCorrection
3434
#endif
3535
RecvPropString( RECVINFO(m_netLookupFilename) ),
3636
RecvPropBool( RECVINFO(m_bEnabled) ),
37-
#ifdef MAPBASE // From Alien Swarm SDK
37+
#ifdef MAPBASE
38+
// -- From Alien Swarm SDK --
3839
RecvPropBool( RECVINFO(m_bMaster) ),
3940
RecvPropBool( RECVINFO(m_bClientSide) ),
40-
RecvPropBool( RECVINFO(m_bExclusive) )
41+
RecvPropBool( RECVINFO(m_bExclusive) ),
42+
//---------------------------
43+
RecvPropBool( RECVINFO(m_bMaskEnabled) ),
44+
RecvPropBool( RECVINFO(m_bMaskInvert) ),
4145
#endif
4246

4347
END_RECV_TABLE()
@@ -48,7 +52,8 @@ END_RECV_TABLE()
4852
//------------------------------------------------------------------------------
4953
C_ColorCorrection::C_ColorCorrection()
5054
{
51-
#ifdef MAPBASE // From Alien Swarm SDK
55+
#ifdef MAPBASE
56+
// -- From Alien Swarm SDK --
5257
m_minFalloff = -1.0f;
5358
m_maxFalloff = -1.0f;
5459
m_flFadeInDuration = 0.0f;
@@ -59,6 +64,9 @@ C_ColorCorrection::C_ColorCorrection()
5964
m_bEnabled = false;
6065
m_bMaster = false;
6166
m_bExclusive = false;
67+
//---------------------------
68+
m_bMaskEnabled = false;
69+
m_bMaskInvert = false;
6270
#endif
6371
m_CCHandle = INVALID_CLIENT_CCHANDLE;
6472

@@ -134,7 +142,7 @@ void C_ColorCorrection::Update( C_BasePlayer *pPlayer, float ccScale )
134142
if ( mat_colcorrection_disableentities.GetInt() )
135143
{
136144
// Allow the colorcorrectionui panel (or user) to turn off color-correction entities
137-
g_pColorCorrectionMgr->SetColorCorrectionWeight( m_CCHandle, 0.0f, m_bExclusive );
145+
g_pColorCorrectionMgr->SetColorCorrectionWeight( m_CCHandle, 0.0f, m_bExclusive, m_bMaskEnabled, m_bMaskInvert );
138146
return;
139147
}
140148

@@ -146,7 +154,7 @@ void C_ColorCorrection::Update( C_BasePlayer *pPlayer, float ccScale )
146154

147155
if( !m_bEnabled && m_flCurWeight == 0.0f )
148156
{
149-
g_pColorCorrectionMgr->SetColorCorrectionWeight( m_CCHandle, 0.0f, m_bExclusive );
157+
g_pColorCorrectionMgr->SetColorCorrectionWeight( m_CCHandle, 0.0f, m_bExclusive, m_bMaskEnabled, m_bMaskInvert );
150158
return;
151159
}
152160

@@ -161,7 +169,7 @@ void C_ColorCorrection::Update( C_BasePlayer *pPlayer, float ccScale )
161169
if ( weight>1.0f ) weight = 1.0f;
162170
}
163171

164-
g_pColorCorrectionMgr->SetColorCorrectionWeight( m_CCHandle, m_flCurWeight * ( 1.0 - weight ) * ccScale, m_bExclusive );
172+
g_pColorCorrectionMgr->SetColorCorrectionWeight( m_CCHandle, m_flCurWeight * ( 1.0 - weight ) * ccScale, m_bExclusive, m_bMaskEnabled, m_bMaskInvert );
165173
}
166174

167175
void C_ColorCorrection::EnableOnClient( bool bEnable, bool bSkipFade )
@@ -214,7 +222,7 @@ float C_ColorCorrection::GetMaxFalloff()
214222

215223
void C_ColorCorrection::SetWeight( float fWeight )
216224
{
217-
g_pColorCorrectionMgr->SetColorCorrectionWeight( m_CCHandle, fWeight, false );
225+
g_pColorCorrectionMgr->SetColorCorrectionWeight( m_CCHandle, fWeight, false, m_bMaskEnabled, m_bMaskInvert );
218226
}
219227

220228
void C_ColorCorrection::StartFade( float flDuration )
@@ -288,7 +296,88 @@ void C_ColorCorrection::ClientThink()
288296
}
289297
#endif
290298

299+
#ifdef MAPBASE
300+
class C_ColorCorrectionExclude : public C_BaseEntity
301+
{
302+
public:
303+
DECLARE_CLASS( C_ColorCorrectionExclude, C_BaseEntity );
304+
DECLARE_CLIENTCLASS();
305+
306+
void OnDataChanged( DataUpdateType_t type );
307+
void UpdateOnRemove( void );
308+
309+
void UpdateExclude( void );
310+
void DestroyExclude( void );
311+
312+
EHANDLE m_hExcludeTarget;
313+
color32 m_ExcludeColor;
314+
bool m_bExcludeDisabled;
315+
316+
int m_nExcludeHandle = -1;
317+
};
318+
319+
IMPLEMENT_CLIENTCLASS_DT( C_ColorCorrectionExclude, DT_ColorCorrectionExclude, CColorCorrectionExclude )
320+
RecvPropEHandle( RECVINFO( m_hExcludeTarget ) ),
321+
RecvPropInt( RECVINFO( m_ExcludeColor ), 0, RecvProxy_IntToColor32 ),
322+
RecvPropBool( RECVINFO( m_bExcludeDisabled ) ),
323+
END_RECV_TABLE()
291324

325+
//-----------------------------------------------------------------------------
326+
// Purpose:
327+
//-----------------------------------------------------------------------------
328+
void C_ColorCorrectionExclude::OnDataChanged( DataUpdateType_t updateType )
329+
{
330+
BaseClass::OnDataChanged( updateType );
331+
332+
UpdateExclude();
333+
}
334+
335+
//-----------------------------------------------------------------------------
336+
// Purpose:
337+
//-----------------------------------------------------------------------------
338+
void C_ColorCorrectionExclude::UpdateOnRemove( void )
339+
{
340+
DestroyExclude();
341+
342+
BaseClass::UpdateOnRemove();
343+
}
344+
345+
//-----------------------------------------------------------------------------
346+
// Purpose:
347+
//-----------------------------------------------------------------------------
348+
void C_ColorCorrectionExclude::UpdateExclude( void )
349+
{
350+
// destroy the existing effect
351+
DestroyExclude();
352+
353+
// create a new effect
354+
if ( m_hExcludeTarget && !m_bExcludeDisabled )
355+
{
356+
Vector4D vecColor( m_ExcludeColor.r, m_ExcludeColor.g, m_ExcludeColor.b, m_ExcludeColor.a );
357+
for (int i = 0; i < 4; i++)
358+
{
359+
if (vecColor[i] == 0.0f)
360+
continue;
361+
362+
vecColor[i] /= 255.0f;
363+
}
364+
365+
m_nExcludeHandle = g_pColorCorrectionMgr->RegisterExclusionObject( m_hExcludeTarget, &vecColor.AsVector3D(), vecColor.w );
366+
}
367+
}
368+
369+
//-----------------------------------------------------------------------------
370+
// Purpose:
371+
//-----------------------------------------------------------------------------
372+
void C_ColorCorrectionExclude::DestroyExclude( void )
373+
{
374+
if ( m_nExcludeHandle != -1 )
375+
{
376+
g_pColorCorrectionMgr->UnregisterExclusionObject( m_nExcludeHandle );
377+
m_nExcludeHandle = -1;
378+
}
379+
}
380+
#endif
292381

293382

294383

sp/src/game/client/c_colorcorrection.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ class C_ColorCorrection : public C_BaseEntity
6767

6868
bool m_bEnabled;
6969

70-
#ifdef MAPBASE // From Alien Swarm SDK
70+
#ifdef MAPBASE
71+
// -- From Alien Swarm SDK --
7172
float m_flFadeInDuration;
7273
float m_flFadeOutDuration;
7374
float m_flMaxWeight;
@@ -80,6 +81,10 @@ class C_ColorCorrection : public C_BaseEntity
8081
float m_flFadeStartWeight;
8182
float m_flFadeStartTime;
8283
float m_flFadeDuration;
84+
//---------------------------
85+
86+
bool m_bMaskEnabled;
87+
bool m_bMaskInvert;
8388
#endif
8489

8590
ClientCCHandle_t m_CCHandle;

sp/src/game/client/client_mapbase.vpc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ $Project
7474
$File "mapbase\c_point_glow.cpp"
7575
$File "mapbase\c_vgui_text_display.cpp"
7676
$File "mapbase\c_weapon_custom_hl2.cpp"
77+
$File "mapbase\colorcorrectionmgr_exclude.cpp"
7778
$File "mapbase\mapbase_autocubemap.cpp"
7879
$File "mapbase\hud_generic_timer.cpp"
7980
}
@@ -83,6 +84,9 @@ $Project
8384
// Original stunstick files are conditional'd out in the HL2 VPCs
8485
$File "$SRCDIR\game\shared\hl2mp\weapon_stunstick.cpp"
8586
$File "$SRCDIR\game\shared\hl2mp\weapon_stunstick.h"
87+
88+
$File "hl2\hl2_rendertargets.cpp"
89+
$File "hl2\hl2_rendertargets.h"
8690
}
8791

8892
$Folder "HL2MP"

sp/src/game/client/clientmode_shared.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,18 @@ bool ClientModeShared::DoPostScreenSpaceEffects( const CViewSetup *pSetup )
835835
return true;
836836
}
837837

838+
#ifdef MAPBASE
839+
//-----------------------------------------------------------------------------
840+
// Purpose:
841+
//-----------------------------------------------------------------------------
842+
bool ClientModeShared::DoPostScreenSpaceEffectsPostViewModel( const CViewSetup *pSetup )
843+
{
844+
g_pColorCorrectionMgr->RenderExclusionObjects( pSetup );
845+
846+
return true;
847+
}
848+
#endif
849+
838850
//-----------------------------------------------------------------------------
839851
// Purpose:
840852
// Output : vgui::Panel

sp/src/game/client/clientmode_shared.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ class ClientModeShared : public IClientMode, public CGameEventListener
139139
//=============================================================================
140140

141141
virtual bool DoPostScreenSpaceEffects( const CViewSetup *pSetup );
142+
#ifdef MAPBASE
143+
virtual bool DoPostScreenSpaceEffectsPostViewModel( const CViewSetup *pSetup );
144+
#endif
142145

143146
virtual void DisplayReplayMessage( const char *pLocalizeName, float flDuration, bool bUrgent,
144147
const char *pSound, bool bDlg );

0 commit comments

Comments
 (0)