- made details sprites light up when illuminated by flashlight

This commit is contained in:
Biohazard 2013-09-27 20:07:28 +02:00
parent 82b4b79301
commit a4db8d9e00
11 changed files with 67 additions and 8 deletions

View file

@ -103,9 +103,29 @@ static void ModulateByFlashlight( const Vector &vecOrigin, Vector &vecColor )
C_GstringPlayer *pPlayer = ToGstringPlayer( C_BasePlayer::GetLocalPlayer() );
if ( pPlayer != NULL
&& pPlayer->IsEffectActive( EF_DIMLIGHT ) )
&& pPlayer->IsRenderingFlashlight() )
{
vecColor = Vector( 1, 1, 1 );
Vector vecFlashlightPos, vecFlashlightForward;
pPlayer->GetFlashlightPosition( vecFlashlightPos );
pPlayer->GetFlashlightForward( vecFlashlightForward );
Vector delta = ( vecOrigin + Vector( 0, 0, 20 ) ) - CurrentViewOrigin();
const float flDist = delta.NormalizeInPlace();
const float flDot = DotProduct( delta, vecFlashlightForward );
const float flFOV = pPlayer->GetFlashlightDot();
if ( flDot > flFOV )
{
float flScale = RemapValClamped( flDot, flFOV, flFOV + 0.04f, 0.0f, 1.0f );
flScale *= RemapValClamped( flDist, 0.0f, 500.0f, 1.0f, 0.0f );
float flMaxLight = ( vecColor.x + vecColor.y + vecColor.z ) * 0.15f + 0.5f;
flMaxLight = MIN( 1.0f, flMaxLight );
vecColor = Lerp( flScale, vecColor, Vector( flMaxLight, flMaxLight, flMaxLight ) );
}
}
}

View file

@ -86,6 +86,8 @@ CFlashlightEffect::CFlashlightEffect(int nEntIndex)
{
m_FlashlightTexture.Init( "effects/flashlight001", TEXTURE_GROUP_OTHER, true );
}
m_flHorizontalFOV = 90.0f; // GSTRINGMIGRATION
}
@ -320,6 +322,8 @@ void CFlashlightEffect::UpdateLightNew(const Vector &vecPos, const Vector &vecFo
state.m_fVerticalFOVDegrees = r_flashlightfov.GetFloat();
}
m_flHorizontalFOV = state.m_fHorizontalFOVDegrees; // GSTRINGMIGRATION
state.m_fConstantAtten = r_flashlightconstant.GetFloat();
state.m_Color[0] = 1.0f;
state.m_Color[1] = 1.0f;

View file

@ -27,6 +27,8 @@ public:
ClientShadowHandle_t GetFlashlightHandle( void ) { return m_FlashlightHandle; }
void SetFlashlightHandle( ClientShadowHandle_t Handle ) { m_FlashlightHandle = Handle; }
float GetHorizontalFOV() const { return m_flHorizontalFOV; } // GSTRINGMIGRATION
protected:
@ -47,6 +49,8 @@ protected:
// Texture for flashlight
CTextureReference m_FlashlightTexture;
float m_flHorizontalFOV; // GSTRINGMIGRATION
};
class CHeadlightEffect : public CFlashlightEffect

View file

@ -33,6 +33,7 @@ C_GstringPlayer::C_GstringPlayer()
, m_flMuzzleFlashTime( 0.0f )
, m_pMuzzleFlashEffect( NULL )
, m_flMuzzleFlashDuration( 0.0f )
, m_bFlashlightVisible( false )
{
}
@ -157,7 +158,9 @@ void C_GstringPlayer::UpdateFlashlight()
m_flMuzzleFlashDuration = 0.0f;
}
if ( bDoFlashlight || bDoMuzzleflash )
m_bFlashlightVisible = bDoFlashlight || bDoMuzzleflash;
if ( m_bFlashlightVisible )
{
ConVarRef scissor( "r_flashlightscissor" );
scissor.SetValue( "0" );
@ -187,6 +190,12 @@ void C_GstringPlayer::UpdateFlashlight()
}
}
m_vecFlashlightPosition = vecPos;
m_vecFlashlightForward = vecForward;
#define FLASHLIGHT_FOV_ADJUST 15.0f
#define FLASHLIGHT_FOV_MIN 5.0f
if ( bDoFlashlight )
{
if (!m_pFlashlight)
@ -202,8 +211,12 @@ void C_GstringPlayer::UpdateFlashlight()
// Update the light with the new position and direction.
m_pFlashlight->UpdateLight( vecPos, vecForward, vecRight, vecUp, FLASHLIGHT_DISTANCE );
m_flFlashlightDot = m_pFlashlight->GetHorizontalFOV() - FLASHLIGHT_FOV_ADJUST;
m_flFlashlightDot = MAX( m_flFlashlightDot, FLASHLIGHT_FOV_MIN );
m_flFlashlightDot = cos( DEG2RAD( m_flFlashlightDot ) );
}
else if (m_pFlashlight)
else if ( m_pFlashlight )
{
// Turned off the flashlight; delete it.
delete m_pFlashlight;
@ -225,6 +238,10 @@ void C_GstringPlayer::UpdateFlashlight()
// Update the light with the new position and direction.
m_pMuzzleFlashEffect->UpdateLight( vecPos, vecForward, vecRight, vecUp, flStrength * flStrength );
m_flFlashlightDot = m_pMuzzleFlashEffect->GetHorizontalFOV() - FLASHLIGHT_FOV_ADJUST;
m_flFlashlightDot = MAX( m_flFlashlightDot, FLASHLIGHT_FOV_MIN );
m_flFlashlightDot = cos( DEG2RAD( m_flFlashlightDot ) );
}
else
{
@ -233,20 +250,22 @@ void C_GstringPlayer::UpdateFlashlight()
}
}
bool C_GstringPlayer::IsRenderFlashlight() const
bool C_GstringPlayer::IsRenderingFlashlight() const
{
return false;
return m_bFlashlightVisible;
}
void C_GstringPlayer::GetFlashlightPosition( Vector &vecPos ) const
{
vecPos = m_vecFlashlightPosition;
}
void C_GstringPlayer::GetFlashlightForward( Vector &vecForward ) const
{
vecForward = m_vecFlashlightForward;
}
float C_GstringPlayer::GetFlashlightDot() const
{
return 0.0f;
return m_flFlashlightDot;
}

View file

@ -26,7 +26,7 @@ public:
virtual void ProcessMuzzleFlashEvent();
virtual void UpdateFlashlight();
virtual bool IsRenderFlashlight() const;
virtual bool IsRenderingFlashlight() const;
virtual void GetFlashlightPosition( Vector &vecPos ) const;
virtual void GetFlashlightForward( Vector &vecForward ) const;
virtual float GetFlashlightDot() const;
@ -42,6 +42,10 @@ private:
float m_flMuzzleFlashDuration;
C_MuzzleflashEffect *m_pMuzzleFlashEffect;
bool m_bFlashlightVisible;
Vector m_vecFlashlightPosition;
Vector m_vecFlashlightForward;
float m_flFlashlightDot;
};
inline C_GstringPlayer *ToGstringPlayer( C_BaseEntity *pPlayer )

View file

@ -12,6 +12,8 @@ C_MuzzleflashEffect::C_MuzzleflashEffect()
m_FlashlightHandle = CLIENTSHADOW_INVALID_HANDLE;
m_FlashlightTexture.Init( "effects/muzzleflashlight", TEXTURE_GROUP_OTHER, true );
m_flHorizontalFOV = 90.0f;
}
C_MuzzleflashEffect::~C_MuzzleflashEffect()
@ -45,6 +47,8 @@ void C_MuzzleflashEffect::UpdateLight( const Vector &vecPos, const Vector &vecDi
state.m_bEnableShadows = true;
state.m_flShadowMapResolution = r_flashlightdepthres.GetInt();
m_flHorizontalFOV = state.m_fHorizontalFOVDegrees;
state.m_pSpotlightTexture = m_FlashlightTexture;
state.m_nSpotlightTextureFrame = 0;

View file

@ -11,12 +11,16 @@ public:
virtual void UpdateLight(const Vector &vecPos, const Vector &vecDir, const Vector &vecRight, const Vector &vecUp, float flStrength );
float GetHorizontalFOV() const { return m_flHorizontalFOV; }
protected:
void UpdateLightNew(const Vector &vecPos, const Vector &vecDir, const Vector &vecRight, const Vector &vecUp);
ClientShadowHandle_t m_FlashlightHandle;
CTextureReference m_FlashlightTexture;
float m_flHorizontalFOV;
};
#endif

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.