Difference between revisions of "Viewmodel Blood Splatter Overlay"

From Valve Developer Community
Jump to: navigation, search
(Link to code on subpage instead)
(Clean effect when player in the water and take medkit.)
Line 118: Line 118:
  
 
And that's all there is to it, if set up right you should now be able to see the blood splatter texture appear on your viewmodel based on the snippet of code we placed into '''basecombatcharacter.cpp'''.
 
And that's all there is to it, if set up right you should now be able to see the blood splatter texture appear on your viewmodel based on the snippet of code we placed into '''basecombatcharacter.cpp'''.
 +
 +
== Additional Functional ==
 +
 +
 +
For cleaning effect when you are ''in the water'', in '''player.cpp'''
 +
find function: '''void CBasePlayer::WaterMove()'''
 +
 +
And inside it, in the end, but before '''UpdateUnderwaterState();'''
 +
 +
Add this:
 +
 +
<source lang=cpp>
 +
if (GetWaterLevel() > 1)
 +
{
 +
 +
m_bShouldDrawBloodOverlay = false;
 +
 +
}
 +
</source>
 +
 +
For cleaning effect when you are ''take medkit'' find: '''int CBasePlayer::TakeHealth(float flHealth, int bitsDamageType)'''
 +
 +
add this inside:
 +
 +
<source lang=cpp>
 +
m_bShouldDrawBloodOverlay = false;
 +
</source>
 +
  
 
== External links ==
 
== External links ==

Revision as of 12:44, 1 June 2021

Introduction

In this tutorial, we'll be setting up a simple material proxy system that we can use to overlay a blood detail texture onto our viewmodel based on close-quarters combat.

Final results that can be made from this are, for example, hands and weapons covered in goo, acid, blood, water, animated raindrop water normals, and many more visual design elements.

Requirements

  • A Source SDK 2013 engine branch mod.
  • Beginner/Intermediate knowledge of C++.
  • Knowledge and familiarity with textures and materials.

What You Will Learn

  • To create a new material proxy system using the $detail parameter.
  • To create an overlay of blood onto a viewmodel after shooting flesh or blood materials (NPCs included of course) at close-quarters.

The Implementation

Before starting, we'll need this file:


Which you'll put into <src code directory>/src/game/client/

c_baseplayer.h

In c_baseplayer.h, inside the public: section, add the following line:

	bool m_bShouldDrawBloodOverlay;

c_baseplayer.cpp

In c_baseplayer.cpp, below RecvPropString( RECVINFO(m_szLastPlaceName) ), add:

		RecvPropBool( RECVINFO(m_bShouldDrawBloodOverlay) ),

Then in the constructor, below ListenForGameEvent( "base_player_teleported" );, add:

	m_bShouldDrawBloodOverlay = false;

player.h

In player.h, inside the public: section, add the following line:

	CNetworkVar( bool, m_bShouldDrawBloodOverlay ); // Have we been hit or have blood splatted on us?

player.cpp

In player.cpp, inside the constructor and below m_bitsDamageType = 0;, add:

	m_bShouldDrawBloodOverlay = false;

At the bottom of the InitialSpawn( void ) function, add:

	m_bShouldDrawBloodOverlay = false; // Reset blood overlay

Then inside IMPLEMENT_SERVERCLASS_ST( CBasePlayer, DT_BasePlayer ), below SendPropString (SENDINFO(m_szLastPlaceName) ),, add:

	SendPropBool( SENDINFO(m_bShouldDrawBloodOverlay) ),

basecombatcharacter.cpp

In basecombatcharacter.cpp, inside the OnTakeDamage_Alive( const CTakeDamageInfo &info ) function above return 1;, add:

	// Handle the viewmodel blood splatter overlay effect here:
	if ( ( info.GetDamageType() & ( DMG_BULLET | DMG_SLASH | DMG_BLAST | DMG_CLUB | DMG_BUCKSHOT ) ) )
	{
		CBasePlayer *pPlayer = UTIL_GetLocalPlayer();
		if ( pPlayer == this )
			pPlayer->m_bShouldDrawBloodOverlay = true;

		pPlayer = ToBasePlayer( info.GetAttacker() );
		if ( pPlayer && ( this->BloodColor() != BLOOD_COLOR_MECH ) )
		{
			if ( pPlayer->GetAbsOrigin().DistTo( this->GetAbsOrigin() ) < 200.0f )
				pPlayer->m_bShouldDrawBloodOverlay = true;
		}
	}

The Materials

Viewmodel VMTs

Now you'll have to edit every single viewmodel .vmt to include the following snippet of code:

"VertexLitGeneric"
{
	...

	"$detail" "detail/blood_detail"
	"$detailblendmode" "2"
	"$detailblendfactor" "0.0"
	"$detailscale" "1.0"

	"Proxies"
	{
		"BloodyTexture"
		{
		}
	}
}

Notice how we're calling for materials/detail/blood_detail.vtf, this is the blood detail texture that gets placed on top of our viewmodel.

Conclusion

Now all that remains is making your own blood detail texture for this, but for convenience/testing sake, you can download the included placeholder texture found in the "External links" section down below.

And that's all there is to it, if set up right you should now be able to see the blood splatter texture appear on your viewmodel based on the snippet of code we placed into basecombatcharacter.cpp.

Additional Functional

For cleaning effect when you are in the water, in player.cpp find function: void CBasePlayer::WaterMove()

And inside it, in the end, but before UpdateUnderwaterState();

Add this:

	if (GetWaterLevel() > 1)
	{

		m_bShouldDrawBloodOverlay = false;

	}

For cleaning effect when you are take medkit find: int CBasePlayer::TakeHealth(float flHealth, int bitsDamageType)

add this inside:

		m_bShouldDrawBloodOverlay = false;


External links

Download BloodDetailTexture.rar - A placeholder blood detail texture by Ian B.