Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions sp/src/game/client/C_Env_Projected_Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class C_EnvProjectedTexture : public C_BaseEntity

void UpdateLight( void );

void UpdateProjectedLightAnimation(void);

C_EnvProjectedTexture();
~C_EnvProjectedTexture();

Expand Down Expand Up @@ -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;
Expand All @@ -95,6 +98,7 @@ class C_EnvProjectedTexture : public C_BaseEntity
float m_flShadowFilter;

bool m_bAlwaysDraw;
bool m_bEnableTextureAnimation;
//bool m_bProjectedTextureVersion;
#endif

Expand Down
56 changes: 50 additions & 6 deletions sp/src/game/client/c_env_projectedtexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 ) ),
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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");
Expand All @@ -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;
}
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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);
}
}

Expand Down
4 changes: 4 additions & 0 deletions sp/src/game/server/env_projectedtexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ),
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 ) ),
Expand Down Expand Up @@ -162,6 +165,7 @@ CEnvProjectedTexture::CEnvProjectedTexture( void )
m_flConstantAtten = 0.0f;
m_flShadowAtten = 0.0f;
m_flShadowFilter = 0.5f;
m_bEnableTextureAnimation = false;
#endif
}

Expand Down
4 changes: 4 additions & 0 deletions sp/src/game/server/env_projectedtexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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
Expand Down