diff --git a/sp/src/game/client/C_Env_Projected_Texture.h b/sp/src/game/client/C_Env_Projected_Texture.h index cb6268148ca..0d2a427236e 100644 --- a/sp/src/game/client/C_Env_Projected_Texture.h +++ b/sp/src/game/client/C_Env_Projected_Texture.h @@ -41,6 +41,8 @@ class C_EnvProjectedTexture : public C_BaseEntity void UpdateLight( void ); + void UpdateProjectedLightAnimation(void); + C_EnvProjectedTexture(); ~C_EnvProjectedTexture(); @@ -84,6 +86,7 @@ class C_EnvProjectedTexture : public C_BaseEntity float m_flNearZ; float m_flFarZ; char m_SpotlightTextureName[ MAX_PATH ]; + CMaterialReference m_SpotlightMaterial; CTextureReference m_SpotlightTexture; int m_nSpotlightTextureFrame; int m_nShadowQuality; @@ -95,6 +98,7 @@ class C_EnvProjectedTexture : public C_BaseEntity float m_flShadowFilter; bool m_bAlwaysDraw; + bool m_bEnableTextureAnimation; //bool m_bProjectedTextureVersion; #endif diff --git a/sp/src/game/client/c_env_projectedtexture.cpp b/sp/src/game/client/c_env_projectedtexture.cpp index 6644965265a..37c7142a78d 100644 --- a/sp/src/game/client/c_env_projectedtexture.cpp +++ b/sp/src/game/client/c_env_projectedtexture.cpp @@ -15,6 +15,7 @@ #include "shareddefs.h" #include "materialsystem/imesh.h" #include "materialsystem/imaterial.h" +#include "materialsystem/imaterialvar.h" #include "view.h" #include "iviewrender.h" #include "view_shared.h" @@ -62,6 +63,7 @@ IMPLEMENT_CLIENTCLASS_DT( C_EnvProjectedTexture, DT_EnvProjectedTexture, CEnvPro RecvPropFloat( RECVINFO( m_flShadowAtten ) ), RecvPropFloat( RECVINFO( m_flShadowFilter ) ), RecvPropBool( RECVINFO( m_bAlwaysDraw ) ), + RecvPropBool(RECVINFO(m_bEnableTextureAnimation)), // Not needed on the client right now, change when it actually is needed //RecvPropBool( RECVINFO( m_bProjectedTextureVersion ) ), @@ -99,6 +101,7 @@ C_EnvProjectedTexture *C_EnvProjectedTexture::Create( ) pEnt->m_flQuadraticAtten = 0.0f; pEnt->m_flShadowAtten = 0.0f; pEnt->m_flShadowFilter = 0.5f; + pEnt->m_bEnableTextureAnimation = false; //pEnt->m_bProjectedTextureVersion = 1; #endif @@ -146,15 +149,17 @@ void C_EnvProjectedTexture::OnDataChanged( DataUpdateType_t updateType ) { if ( updateType == DATA_UPDATE_CREATED ) { - m_SpotlightTexture.Init( m_SpotlightTextureName, TEXTURE_GROUP_OTHER, true ); + m_SpotlightMaterial.Init(m_SpotlightTextureName, TEXTURE_GROUP_OTHER, true); + m_SpotlightTexture.Init(m_SpotlightTextureName, TEXTURE_GROUP_OTHER, true); } #ifdef MAPBASE else //if ( updateType == DATA_UPDATE_DATATABLE_CHANGED ) { // It could've been changed via input - if( !FStrEq(m_SpotlightTexture->GetName(), m_SpotlightTextureName) ) + if (!FStrEq(m_SpotlightTexture->GetName(), m_SpotlightTextureName) || !FStrEq(m_SpotlightMaterial->GetName(), m_SpotlightTextureName)) { - m_SpotlightTexture.Init( m_SpotlightTextureName, TEXTURE_GROUP_OTHER, true ); + m_SpotlightMaterial.Init(m_SpotlightTextureName, TEXTURE_GROUP_OTHER, true); + m_SpotlightTexture.Init(m_SpotlightTextureName, TEXTURE_GROUP_OTHER, true); } } #endif @@ -165,6 +170,34 @@ void C_EnvProjectedTexture::OnDataChanged( DataUpdateType_t updateType ) } static ConVar asw_perf_wtf("asw_perf_wtf", "0", FCVAR_DEVELOPMENTONLY, "Disable updating of projected shadow textures from UpdateLight" ); + +ConVar r_flashlightenabletextureanimation("r_flashlightenabletextureanimation", "1", FCVAR_ARCHIVE, "Enable/Disable Projected Texture Animation Support"); + +static ITexture* GetBaseProjectedTexture(IMaterial* pMaterial, ITexture *fallback_texture) +{ + bool foundVar; + IMaterialVar* pTextureVar = pMaterial->FindVar("$basetexture", &foundVar, false); + + if (!foundVar) + return fallback_texture; + + return pTextureVar->GetTextureValue(); +} + +static int GetProjectedTextureAnimationFrame(IMaterial* pMaterial) +{ + if (pMaterial->GetNumAnimationFrames() <= 1 || !r_flashlightenabletextureanimation.GetBool()) + return 0; + + bool foundVar; + IMaterialVar* pTextureVar = pMaterial->FindVar("$frame", &foundVar, false); + + if (!foundVar) + return 0; + + return pTextureVar->GetIntValue(); +} + void C_EnvProjectedTexture::UpdateLight( void ) { VPROF("C_EnvProjectedTexture::UpdateLight"); @@ -173,7 +206,7 @@ void C_EnvProjectedTexture::UpdateLight( void ) Vector vLinearFloatLightColor( m_LightColor.r, m_LightColor.g, m_LightColor.b ); float flLinearFloatLightAlpha = m_LightColor.a; - if ( m_bAlwaysUpdate ) + if (m_bAlwaysUpdate || (r_flashlightenabletextureanimation.GetBool() && m_bEnableTextureAnimation)) { m_bForceUpdate = true; } @@ -420,8 +453,8 @@ void C_EnvProjectedTexture::UpdateLight( void ) state.m_flShadowDepthBias = g_pMaterialSystemHardwareConfig->GetShadowDepthBias(); #endif state.m_bEnableShadows = m_bEnableShadows; - state.m_pSpotlightTexture = m_SpotlightTexture; - state.m_nSpotlightTextureFrame = m_nSpotlightTextureFrame; + state.m_pSpotlightTexture = GetBaseProjectedTexture(m_SpotlightMaterial, m_SpotlightTexture); + state.m_nSpotlightTextureFrame = m_bEnableTextureAnimation ? GetProjectedTextureAnimationFrame(m_SpotlightMaterial) : m_nSpotlightTextureFrame; state.m_nShadowQuality = m_nShadowQuality; // Allow entity to affect shadow quality @@ -464,6 +497,17 @@ void C_EnvProjectedTexture::UpdateLight( void ) if ( !asw_perf_wtf.GetBool() && !m_bForceUpdate ) { g_pClientShadowMgr->UpdateProjectedTexture( m_LightHandle, true ); + UpdateProjectedLightAnimation(); + } +} + +void C_EnvProjectedTexture::UpdateProjectedLightAnimation(void) +{ + if (r_flashlightenabletextureanimation.GetBool() && m_SpotlightMaterial.IsValid() && m_bEnableTextureAnimation) + { + //Note: This Bind Method Activte Linked Material Proxy + CMatRenderContextPtr pRenderContext(materials); + pRenderContext->Bind(m_SpotlightMaterial); } } diff --git a/sp/src/game/server/env_projectedtexture.cpp b/sp/src/game/server/env_projectedtexture.cpp index 15fb1367c51..2ed357541aa 100644 --- a/sp/src/game/server/env_projectedtexture.cpp +++ b/sp/src/game/server/env_projectedtexture.cpp @@ -51,6 +51,7 @@ BEGIN_DATADESC( CEnvProjectedTexture ) DEFINE_FIELD( m_flQuadraticAtten, FIELD_FLOAT ), DEFINE_KEYFIELD( m_flShadowAtten, FIELD_FLOAT, "shadowatten" ), DEFINE_KEYFIELD( m_flShadowFilter, FIELD_FLOAT, "shadowfilter" ), + DEFINE_KEYFIELD(m_bEnableTextureAnimation, FIELD_BOOLEAN, "enabletextureanimation"), #endif DEFINE_INPUTFUNC( FIELD_VOID, "TurnOn", InputTurnOn ), @@ -85,6 +86,7 @@ BEGIN_DATADESC( CEnvProjectedTexture ) DEFINE_INPUTFUNC( FIELD_VOID, "AlwaysDrawOff", InputAlwaysDrawOff ), DEFINE_INPUTFUNC( FIELD_VOID, "StopFollowingTarget", InputStopFollowingTarget ), DEFINE_INPUTFUNC( FIELD_VOID, "StartFollowingTarget", InputStartFollowingTarget ), + DEFINE_INPUTFUNC(FIELD_BOOLEAN, "SetTextureAnimationState", InputSetTextureAnimationState), #endif DEFINE_THINKFUNC( InitialThink ), END_DATADESC() @@ -120,6 +122,7 @@ IMPLEMENT_SERVERCLASS_ST( CEnvProjectedTexture, DT_EnvProjectedTexture ) SendPropFloat( SENDINFO( m_flShadowAtten ) ), SendPropFloat( SENDINFO( m_flShadowFilter ) ), SendPropBool( SENDINFO( m_bAlwaysDraw ) ), + SendPropBool(SENDINFO(m_bEnableTextureAnimation)), // Not needed on the client right now, change when it actually is needed //SendPropBool( SENDINFO( m_bProjectedTextureVersion ) ), @@ -162,6 +165,7 @@ CEnvProjectedTexture::CEnvProjectedTexture( void ) m_flConstantAtten = 0.0f; m_flShadowAtten = 0.0f; m_flShadowFilter = 0.5f; + m_bEnableTextureAnimation = false; #endif } diff --git a/sp/src/game/server/env_projectedtexture.h b/sp/src/game/server/env_projectedtexture.h index 6cb248baad6..336065039e2 100644 --- a/sp/src/game/server/env_projectedtexture.h +++ b/sp/src/game/server/env_projectedtexture.h @@ -66,6 +66,8 @@ class CEnvProjectedTexture : public CPointEntity void InputStartFollowingTarget( inputdata_t &inputdata ) { m_bDontFollowTarget = false; } void InputSetFilter( inputdata_t &inputdata ); + void InputSetTextureAnimationState(inputdata_t &inputdata) { m_bEnableTextureAnimation = inputdata.value.Bool(); } + // Corrects keyvalue/input attenuation for internal FlashlightEffect_t attenuation. float CorrectConstantAtten( float fl ) { return fl * 0.5f; } float CorrectLinearAtten( float fl ) { return fl * 100.0f; } @@ -110,6 +112,8 @@ class CEnvProjectedTexture : public CPointEntity CNetworkVar( bool, m_bAlwaysDraw ); + CNetworkVar( bool, m_bEnableTextureAnimation ); + // 1 = New projected texture // 0 = Non-Mapbase projected texture, e.g. one that uses the VDC parenting fix instead of the spawnflag // Not needed on the client right now, change to CNetworkVar when it actually is needed