Muzzle Flash Lighting: Difference between revisions
m (Made some sentences at the start 3rd person) |
(Removed 2nd and 1st person language and fixed minor grammar/capitalization mistakes) |
||
Line 12: | Line 12: | ||
{{warning| Some dynamic props will not be lit when using dlights.}} | {{warning| Some dynamic props will not be lit when using dlights.}} | ||
{{warning| Too many dlights may result in severe performance losses on low-end systems. When coding for lighting, dlights should be used sparingly.}} | {{warning| Too many dlights may result in severe performance losses on low-end systems. When coding for lighting, dlights should be used sparingly.}} | ||
{{Note | From Slam12f, even better | {{Note | From Slam12f, even better to can write a console command to enable or disable dlights. It is easy to implement with help. Use static ConVar.}} | ||
{{Note | The quality of dynamic lights depends on the lightmap scale.}} | {{Note | The quality of dynamic lights depends on the lightmap scale.}} | ||
== Implementing Dlight-based Muzzleflashes == | == Implementing Dlight-based Muzzleflashes == | ||
The coding begins! Only a few minor changes are needed here to make | The coding begins! Only a few minor changes are needed here to make muzzleflashes look better than ever. | ||
First off, open up '''c_baseanimating.cpp''' and search for the function ''void C_BaseAnimating::ProcessMuzzleFlashEvent()'' | First off, open up '''c_baseanimating.cpp''' and search for the function ''void C_BaseAnimating::ProcessMuzzleFlashEvent()'' | ||
Line 36: | Line 36: | ||
el->color.exponent = 5; | el->color.exponent = 5; | ||
</source> | </source> | ||
Valve went a little crazy here and the result was a seemingly ugly muzzleflash. This tutorial is all about making things pretty, so lets change that. Replace the entries above with this: | |||
<source lang=cpp> | <source lang=cpp> | ||
Vector vAttachment, vAng; | Vector vAttachment, vAng; | ||
Line 61: | Line 61: | ||
== Notes == | == Notes == | ||
Further work is being made on this idea, the updates will add more visual effects to this idea to create a more realistic and cleaner look to the muzzle flash. The update will only work on the orange box engine | |||
A link will be provided HERE when the new muzzle flash is done | A link will be provided HERE when the new muzzle flash is done | ||
A NOTE FROM GAMERMAN12: I had updated this code so that the lights decay after firing, so you have a flashing effect when shooting machine guns. And it fades so that it's | A NOTE FROM GAMERMAN12: I had updated this code so that the lights decay after firing, so you have a flashing effect when shooting machine guns. And it fades so that it's a litle more realistic. Thanks. | ||
[[Category:Weapons programming]] | [[Category:Weapons programming]] |
Revision as of 17:43, 10 March 2022

This tutorial will show you how to create a muzzleflash that dynamically appears and lights up the world around the player, like in Counter-Strike: Source. These types of lights are called "dlights".
This code was designed for any Orange Box based mod, singleplayer or multiplayer. It also works with NPCs, assuming they work properly.




Implementing Dlight-based Muzzleflashes
The coding begins! Only a few minor changes are needed here to make muzzleflashes look better than ever.
First off, open up c_baseanimating.cpp and search for the function void C_BaseAnimating::ProcessMuzzleFlashEvent()
Vector vAttachment;
QAngle dummyAngles;
GetAttachment( attachment, vAttachment, dummyAngles );
// Make an elight
dlight_t *el = effects->CL_AllocElight( LIGHT_INDEX_MUZZLEFLASH + index );
el->origin = vAttachment;
el->radius = random->RandomInt( 32, 64 );
el->decay = el->radius / 0.05f;
el->die = gpGlobals->curtime + 0.05f;
el->color.r = 255;
el->color.g = 192;
el->color.b = 64;
el->color.exponent = 5;
Valve went a little crazy here and the result was a seemingly ugly muzzleflash. This tutorial is all about making things pretty, so lets change that. Replace the entries above with this:
Vector vAttachment, vAng;
QAngle angles;
#ifdef HL2_EPISODIC
GetAttachment( 1, vAttachment, angles ); // set 1 instead "attachment"
#else
GetAttachment( attachment, vAttachment, angles );
#endif
AngleVectors( angles, &vAng );
vAttachment += vAng * 2;
dlight_t *dl = effects->CL_AllocDlight ( index );
dl->origin = vAttachment;
dl->color.r = 231;
dl->color.g = 219;
dl->color.b = 14;
dl->die = gpGlobals->curtime + 0.05f;
dl->radius = random->RandomFloat( 245.0f, 256.0f );
dl->decay = 512.0f;

Edit: Changed the code for the colors, by default it was set to a magenta-ish color. A good muzzle flash color is closer to white, you can try 252, 238, 128 for a realistic washed out yellow.
Notes
Further work is being made on this idea, the updates will add more visual effects to this idea to create a more realistic and cleaner look to the muzzle flash. The update will only work on the orange box engine A link will be provided HERE when the new muzzle flash is done
A NOTE FROM GAMERMAN12: I had updated this code so that the lights decay after firing, so you have a flashing effect when shooting machine guns. And it fades so that it's a litle more realistic. Thanks.