Muzzle Flash Lighting: Difference between revisions
m (→Muzzle Flash) |
m (→Muzzle Flash) |
||
Line 19: | Line 19: | ||
== Muzzle Flash== | == Muzzle Flash== | ||
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()''. Then, look at this little section of code: | |||
<pre> | <pre> | ||
// Make an elight | // Make an elight | ||
Line 34: | Line 34: | ||
el->color.exponent = 5; | el->color.exponent = 5; | ||
</pre> | </pre> | ||
As you may have noticed, Valve went a little crazy here and the result is 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: | |||
so | |||
<pre> | <pre> | ||
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 52: | Line 50: | ||
el->die = gpGlobals->curtime + 0.1f; | el->die = gpGlobals->curtime + 0.1f; | ||
</pre> | </pre> | ||
This two-light system works far better than most any other single dlight system. | This two-light system works far better than most any other single dlight system and fixes Valves mistakes. | ||
== Expanding the idea of Dlights== | == Expanding the idea of Dlights== |
Revision as of 10:14, 22 February 2009
This tutorial will lay out how to create a light that appears and lights up the world around you caused by the muzzle flash of the gun, like in counter-strike source.
First we will look at the Dynamics of this type of lighting known as a "Dlight" and then we will move on how to add the Dlight to the muzzle flash and then how you can implement this into other things.

This code works perfectly for the EP2 engine on both single player and multiplayer, and does in fact work with NPC's. this idea has not been tested with the EP1 engine, but feel free to try
Dlight
The Dlight, can be seen in its, i find, most popular way known as the "fire glow" this glow is what you find underneath the fire lighting up the ground, you can achieve this effect by simply ticking off the "Glow" in the flags of env_fire.
the Dligth can also be raised off the ground to light up not just the ground but the surrounding walls, but the best part of the Dlight i find is that it can be attached to a moving origin as used in this muzzle flash tutorial.
Almost every aspect of the Dlight can be edited, its color (RGB scale), radius of light, radius of distance from a wall and it's attachment point.
Muzzle Flash
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(). Then, look at this little section of code:
// 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 is 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->die = gpGlobals->curtime + 0.1f; dl->radius = random->RandomFloat( 245.0f, 256.0f ); dl->color.g = dl->color.b = random->RandomInt( 95, 128 ); dlight_t *el= effects->CL_AllocElight( index ); el->origin = vAttachment; el->color.r = 255; el->color.g = dl->color.b = random->RandomInt( 95, 128 ); el->radius = random->RandomFloat( 260.0f, 290.0f ); el->die = gpGlobals->curtime + 0.1f;
This two-light system works far better than most any other single dlight system and fixes Valves mistakes.
Expanding the idea of Dlights

Here are a few things you can do that can add that little extra bit of realism that can effect the atmosphere of some level or mods drastically.
1. Raise the Dlight of the fire, that's right raise it!, right now the fires dlight is sitting on the floor raise it up to the center of the fire and make light up the room with it
2. Add a dlight to the explosion, why? because the light u see coming from the explosion is a particle effect and doesn't effect the world around it, add a dligth effect everything!
3. Want to make your mod like the grand theft auto series? add a Dligh to the missile of the RPG and light up the surrounding walls as it flies down the hall way to its target