Alien Swarm Glow

From Valve Developer Community
Revision as of 14:42, 8 June 2012 by Gammerman12 (talk | contribs) (Created page with "thumb|The Glow Effect used in-game, surrounding two MP5s. Originally, if you wanted to highlight an object in 2007, you would need to follow the [...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
The Glow Effect used in-game, surrounding two MP5s.

Originally, if you wanted to highlight an object in 2007, you would need to follow the L4D Glow Effect tutorial by the guys over at GoldenEye: Source. But this implementation is harder to use, and unnecessary in any Alien Swarm codebases, because Alien Swarm uses sections of the Left 4 Dead codebase, including the glow effect.

ClientMode Update:

Note.pngNote:If you are using default asw code without a new clientmode implementation, skip this step.

If you are using a template like Sandern's SDK template, you will need to make sure your ClientMode is properly working for post processes. You can find out if it's rendering Glow effects by going to your clientmode_<mod> file (clientmode_asw, clientmode_sdk, etc.) In the case of Sandern's mod, at the bottom of clientmode_sdk.cpp, you can find an empty DoPostScreenSpaceEffects line. First, lets make sure to include our required files:

#ifdef CLIENT_DLL
#include "glow_outline_effect.h"
#endif

Then make the DoPostScreenSpaceEffects line look like this:

void ClientModeSDK::DoPostScreenSpaceEffects( const CViewSetup *pSetup )
{
	CMatRenderContextPtr pRenderContext( materials );

	g_GlowObjectManager.RenderGlowEffects( pSetup, 0 /*GetSplitScreenPlayerSlot()*/ );
}

Implementation

For this tutorial, I decided to use weapon_sdkbase, but you can do this with any entity that is linked to the client and server. First, we should add this to the top of the file:

#include "glow_outline_effect.h"

Then, we need to define our glow effect. In the header file, or the declarations, add this to a private section:

private:
#ifdef CLIENT_DLL
	CGlowObject m_GlowObject;
#endif

Also add this to the public class:

public:
#ifdef CLIENT_DLL
	virtual void ClientThink();
#endif

Next, we want to modify the constructor of our entity. This will initialize our glow. You're gonna want to do this differently, so have this replace the whole first part of your constructor:

CWeaponSDKBase::CWeaponSDKBase()
#ifdef CLIENT_DLL
:m_GlowObject( this, Vector( 0.0f, 0.4f, 0.75f ), 1.0f, false, true )
#else
#endif

Finally, add ClientThink to your file. This particular implementation makes it so if someone isn't holding the weapon, it will not glow:

#ifdef CLIENT_DLL
void CWeaponSDKBase::ClientThink()
{
	bool bShouldGlow = false;

	if ( !GetOwner() )
	{
		bShouldGlow = true;
	}

	m_GlowObject.SetRenderFlags( false, bShouldGlow );

	if ( m_GlowObject.IsRendering() )
	{
		m_GlowObject.SetAlpha( 255 );
	}
}
#endif

You can use different things in the same area where Alpha is being modified. A list of these options can be found in CGlowObject's declarations in glow_outline_effect.h (SetAlpha, SetColor, SetRenderFlags, etc.)

Conclusion

Todo: Make Conclusion