1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#include "cbase.h"
#include "particles_simple.h"
#include "particles_localspace.h"
#include "c_te_effect_dispatch.h"
#include "clienteffectprecachesystem.h"
// Precache our effects
CLIENTEFFECT_REGISTER_BEGIN( PrecacheEffect_CS_MuzzleFlash )
CLIENTEFFECT_MATERIAL( "effects/muzzleflashX" ) //.vmt
CLIENTEFFECT_MATERIAL( "sprites/muzzleflash4" ) //.vmt
CLIENTEFFECT_REGISTER_END()
void TE_DynamicLight( IRecipientFilter& filter, float delay,
const Vector* org, int r, int g, int b, int exponent, float radius, float time, float decay, int nLightIndex = LIGHT_INDEX_TE_DYNAMIC );
void CS_MuzzleFlashCallback( const CEffectData &data )
{
CSmartPtr<CLocalSpaceEmitter> pEmitter =
CLocalSpaceEmitter::Create( "CS_MuzzleFlash", data.m_hEntity, data.m_nAttachmentIndex, 0 );
if ( !pEmitter )
return;
// SetBBox() manually on the particle system so it doesn't have to be recalculated more than once.
Vector vCenter( 0.0f, 0.0f, 0.0f );
C_BaseEntity *pEnt = data.GetEntity();
if ( pEnt )
{
vCenter = pEnt->WorldSpaceCenter();
}
else
{
IClientRenderable *pRenderable = data.GetRenderable( );
if ( pRenderable )
{
Vector vecMins, vecMaxs;
pRenderable->GetRenderBoundsWorldspace( vecMins, vecMaxs );
VectorAdd( vecMins, vecMaxs, vCenter );
vCenter *= 0.5f;
}
}
Assert( pEmitter );
pEmitter->GetBinding().SetBBox( vCenter - Vector( 3, 3, 3 ), vCenter + Vector( 3, 3, 3 ) );
// haxors - make the clip much shorter so the alpha is not
// changed based on large clip distances
pEmitter->SetNearClip( 0, 5 );
PMaterialHandle hFlashMaterial = pEmitter->GetPMaterial( "sprites/muzzleflash4" );
for( int i=0;i<3;i++ )
{
SimpleParticle *pParticle = (SimpleParticle *)pEmitter->AddParticle( sizeof( SimpleParticle ),
hFlashMaterial,
vec3_origin );
if( pParticle )
{
pParticle->m_flLifetime = 0.0f;
pParticle->m_flDieTime = 0.08f;
pParticle->m_vecVelocity = vec3_origin;
pParticle->m_uchColor[0] = 255;
pParticle->m_uchColor[1] = 255;
pParticle->m_uchColor[2] = 255;
pParticle->m_uchStartAlpha = 80;
pParticle->m_uchEndAlpha = 30;
pParticle->m_uchStartSize = ( 3.0 + 3.0*i ) * data.m_flScale;
pParticle->m_uchEndSize = pParticle->m_uchStartSize * 0.8;
pParticle->m_flRoll = random->RandomInt( 0, 3 );
pParticle->m_flRollDelta = 0.0f;
}
}
// dynamic light temporary entity for the muzzle flash
CPVSFilter filter(pEmitter->GetSortOrigin());
TE_DynamicLight( filter, 0.0, &(pEmitter->GetSortOrigin()), 255, 192, 64, 5, 70, 0.05, 768 );
}
DECLARE_CLIENT_EFFECT( "CS_MuzzleFlash", CS_MuzzleFlashCallback );
// 'X' shaped muzzleflash used by certain weapons
void CS_MuzzleFlashXCallback( const CEffectData &data )
{
CSmartPtr<CLocalSpaceEmitter> pEmitter =
CLocalSpaceEmitter::Create( "CS_MuzzleFlashX", data.m_hEntity, data.m_nAttachmentIndex, 0 );
Assert( pEmitter );
// haxors - make the clip much shorter so the alpha is not
// changed based on large clip distances
pEmitter->SetNearClip( 0, 5 );
PMaterialHandle hFlashMaterial = pEmitter->GetPMaterial( "effects/muzzleflashX" );
SimpleParticle *pParticle = (SimpleParticle *)pEmitter->AddParticle( sizeof( SimpleParticle ),
hFlashMaterial,
vec3_origin );
if( pParticle )
{
pParticle->m_flLifetime = 0.0f;
pParticle->m_flDieTime = 0.08f;
pParticle->m_vecVelocity = vec3_origin;
pParticle->m_uchColor[0] = 255;
pParticle->m_uchColor[1] = 255;
pParticle->m_uchColor[2] = 255;
pParticle->m_uchStartAlpha = 130;
pParticle->m_uchEndAlpha = 80;
pParticle->m_uchStartSize = 6.0f * data.m_flScale * random->RandomFloat( 0.9, 1.1 );
pParticle->m_uchEndSize = pParticle->m_uchStartSize * 0.8;
pParticle->m_flRoll = random->RandomFloat( -0.25, 0.25 );
pParticle->m_flRollDelta = 0.0f;
}
// dynamic light temporary entity for the muzzle flash
CPVSFilter filter(pEmitter->GetSortOrigin());
TE_DynamicLight( filter, 0.0, &(pEmitter->GetSortOrigin()), 255, 192, 64, 5, 70, 0.05, 768 );
}
DECLARE_CLIENT_EFFECT( "CS_MuzzleFlash_X", CS_MuzzleFlashXCallback );
|