Muzzle Flash Lighting: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
(Category:Weapons programming, syntax highlight)
Line 11: Line 11:


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()''
<pre>
<source lang=cpp>
// Make an elight
// Make an elight
dlight_t *el = effects->CL_AllocElight( LIGHT_INDEX_MUZZLEFLASH + index );
dlight_t *el = effects->CL_AllocElight( LIGHT_INDEX_MUZZLEFLASH + index );
Line 22: Line 22:
el->color.b = 64;
el->color.b = 64;
el->color.exponent = 5;
el->color.exponent = 5;
</pre>
</source>
As you may have noticed, Valve went a little crazy here and the result was a seemingly ugly muzzleflash. This tutorial is all about making things pretty, so we're going to change that. Replace the entries above with this:
As you may have noticed, Valve went a little crazy here and the result was a seemingly ugly muzzleflash. This tutorial is all about making things pretty, so we're going to change that. Replace the entries above with this:
<pre>
<source lang=cpp>
dlight_t *dl = effects->CL_AllocDlight ( index );
dlight_t *dl = effects->CL_AllocDlight ( index );
dl->origin = vAttachment + Vector( 0, 0, 4 );
dl->origin = vAttachment + Vector( 0, 0, 4 );
Line 40: Line 40:
el->radius = random->RandomFloat( 260.0f, 290.0f );
el->radius = random->RandomFloat( 260.0f, 290.0f );
el->die = gpGlobals->curtime + 0.1f;
el->die = gpGlobals->curtime + 0.1f;
</pre>
</source>
This two-dlight system works far better than most any other single dlight system and fixes Valves mistakes.  
This two-dlight system works far better than most any other single dlight system and fixes Valves mistakes.  
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.
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.
Line 47: Line 47:
I am currently working further 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
I am currently working further 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
[[Category:Programming]]
[[Category:Weapons programming]]

Revision as of 09:45, 15 August 2009

This tutorial will show you how to create a muzzleflash that dynamically appears and lights up the world around you, 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 that you've gotten them to work properly.

Warning.pngWarning: Some dynamic props will not be lit when using dlights.
Warning.pngWarning: Too many dlights may result in severe performance losses on low-end systems. When coding for lighting, dlights should be used sparingly.

Implementing Dlight-based Muzzleflashes

The coding begins! Only a few minor changes are needed here to make your muzzleflashes look better than ever.

First off, open up c_baseanimating.cpp and search for the function void C_BaseAnimating::ProcessMuzzleFlashEvent()

// 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;

As you may have noticed, Valve went a little crazy here and the result was a seemingly ugly muzzleflash. This tutorial is all about making things pretty, so we're going to change that. Replace the entries above with this:

			
dlight_t *dl = effects->CL_AllocDlight ( index );
dl->origin = vAttachment + Vector( 0, 0, 4 );
dl->color.r = 255;
dl->color.g = 255;
dl->color.b = 255;
dl->die = gpGlobals->curtime + 0.1f;
dl->radius = random->RandomFloat( 245.0f, 256.0f );

dlight_t *el= effects->CL_AllocElight( index );
el->origin = vAttachment;
el->color.r = 255;
el->color.g = 255;
el->color.b = 255;
el->radius = random->RandomFloat( 260.0f, 290.0f );
el->die = gpGlobals->curtime + 0.1f;

This two-dlight system works far better than most any other single dlight system and fixes Valves mistakes. 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

I am currently working further 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