Alien Swarm Glow

From Valve Developer Community
Jump to: navigation, search
The Glow Effect used in-game, surrounding an MP5.

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 these to the public class:

public:
#ifdef CLIENT_DLL
	virtual void ClientThink();
	virtual void OnDataChanged( DataUpdateType_t updateType );
#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 )
#else
#endif
{
#ifdef CLIENT_DLL
	m_GlowObject.SetColor( Vector( 0.3f, 0.6f, 0.1f ) );
	m_GlowObject.SetRenderFlags( false, true );
#endif
}

We will also want to execute our ClientThink, so we use OnDataChanged. Alternatively, you could use Spawn, but Swarm uses OnDataChanged more, so it seems like the better choice.

#ifdef CLIENT_DLL
void CWeaponSDKBase::OnDataChanged( DataUpdateType_t updateType )
{
	BaseClass::OnDataChanged( updateType );

	if ( updateType == DATA_UPDATE_CREATED )
	{
		SetNextClientThink( CLIENT_THINK_ALWAYS );
	}
}
#endif // CLIENT_DLL

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

void CWeaponSDKBase::ClientThink()
{
#ifdef CLIENT_DLL
	BaseClass::ClientThink();

	if ( !GetOwner() )
	{
		m_GlowObject.SetRenderFlags( true, true );
	}
	else
	{
		m_GlowObject.SetRenderFlags( false, false );
	}
#endif
}