Skip to content

Commit

Permalink
mint-arena: Example for player model damage skins
Browse files Browse the repository at this point in the history
Load up to 10 shaders for each mesh from .skin files. Use first shader
at full health and later shaders as health decreases. If there are only
two shaders, then first is for health 51+ and second is for 0 to 50.

Put baseq3/doom-damage-skin.pk3dir in your baseq3 directory, use
'model doom/damage' and cg_forceModel 1 so bots use it too.

Based on unused code I wrote for Turtle Arena (removed in TA 0.7).
  • Loading branch information
zturtleman committed May 17, 2019
1 parent 21d91ce commit c52a18b
Show file tree
Hide file tree
Showing 12 changed files with 276 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
h_helmet,models/players/doom/doom01,models/players/doom/doom02,models/players/doom/doom03,models/players/doom/doom04,models/players/doom/doom05,models/players/doom/doom06,models/players/doom/doom07,models/players/doom/doom08,models/players/doom/doom09,models/players/doom/doom10
h_visor,models/players/doom/doom_f00
tag_head,
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
l_legs,models/players/doom/doom01,models/players/doom/doom02,models/players/doom/doom03,models/players/doom/doom04,models/players/doom/doom05,models/players/doom/doom06,models/players/doom/doom07,models/players/doom/doom08,models/players/doom/doom09,models/players/doom/doom10
tag_torso,
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
u_torso,models/players/doom/doom01,models/players/doom/doom02,models/players/doom/doom03,models/players/doom/doom04,models/players/doom/doom05,models/players/doom/doom06,models/players/doom/doom07,models/players/doom/doom08,models/players/doom/doom09,models/players/doom/doom10
tag_head,
tag_torso,
tag_weapon,
u_larm,models/players/doom/doom01,models/players/doom/doom02,models/players/doom/doom03,models/players/doom/doom04,models/players/doom/doom05,models/players/doom/doom06,models/players/doom/doom07,models/players/doom/doom08,models/players/doom/doom09,models/players/doom/doom10
u_rarm,models/players/doom/doom01,models/players/doom/doom02,models/players/doom/doom03,models/players/doom/doom04,models/players/doom/doom05,models/players/doom/doom06,models/players/doom/doom07,models/players/doom/doom08,models/players/doom/doom09,models/players/doom/doom10
158 changes: 158 additions & 0 deletions baseq3/doom-damage-skin.pk3dir/scripts/doom-damage-skin.shader
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
// Doom damage skins

// Single shader damage skin (entity alpha)
// mesh,models/players/doom/doom00

models/players/doom/doom00
{
{
map models/players/doom/doom.tga
rgbGen lightingDiffuse
}
{
map models/players/doom/doom_statue.tga
alphaGen entity
blendFunc blend
}
}

models/players/doom/doom_f00
{
{
map models/players/doom/doom_f.tga
rgbGen lightingDiffuse
}
{
map models/players/doom/doom_f_statue.tga
alphaGen entity
blendFunc blend
}
}

// Multi-shader damage skin:
// mesh,models/players/doom/doom01,models/players/doom/doom02,models/players/doom/doom03,models/players/doom/doom04,models/players/doom/doom05,models/players/doom/doom06,models/players/doom/doom07,models/players/doom/doom08,models/players/doom/doom09,models/players/doom/doom10

// 91+ health
models/players/doom/doom01
{
{
map models/players/doom/doom.tga
rgbGen lightingDiffuse
}
}

// 81 - 90 health
models/players/doom/doom02
{
{
map models/players/doom/doom.tga
rgbGen lightingDiffuse
}
{
map models/players/doom/red.tga
alphaGen const 0.3
blendFunc blend
}
}

// 71 - 80 health
models/players/doom/doom03
{
{
map models/players/doom/doom.tga
rgbGen lightingDiffuse
}
{
map models/players/doom/red.tga
alphaGen const 0.4
blendFunc blend
}
}

// 61 - 70 health
models/players/doom/doom04
{
{
map models/players/doom/doom.tga
rgbGen lightingDiffuse
}
{
map models/players/doom/red.tga
alphaGen const 0.6
blendFunc blend
}
}

// 51 - 60 health
models/players/doom/doom05
{
{
map models/players/doom/doom.tga
rgbGen lightingDiffuse
}
{
map models/players/doom/red.tga
alphaGen const 0.8
blendFunc blend
}
}

// 41 - 50 health
models/players/doom/doom06
{
{
map models/players/doom/red.tga
rgbGen lightingDiffuse
}
}

// 31 - 40 health
models/players/doom/doom07
{
{
map models/players/doom/red.tga
rgbGen lightingDiffuse
}
{
map models/players/doom/doom_statue.tga
alphaGen const 0.25
blendFunc blend
}
}

// 21 - 30 health
models/players/doom/doom08
{
{
map models/players/doom/red.tga
rgbGen lightingDiffuse
}
{
map models/players/doom/doom_statue.tga
alphaGen const 0.5
blendFunc blend
}
}

// 11 - 20 health
models/players/doom/doom09
{
{
map models/players/doom/red.tga
rgbGen lightingDiffuse
}
{
map models/players/doom/doom_statue.tga
alphaGen const 0.75
blendFunc blend
}
}

// 0 - 10 health
models/players/doom/doom10
{
{
map models/players/doom/doom_statue.tga
rgbGen lightingDiffuse
}
}
20 changes: 15 additions & 5 deletions code/cgame/cg_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ CG_Draw3DModelEx
================
*/
void CG_Draw3DModelEx( float x, float y, float w, float h, qhandle_t model, cgSkin_t *skin, vec3_t origin, vec3_t angles, const byte *rgba ) {
void CG_Draw3DModelEx( float x, float y, float w, float h, qhandle_t model, cgSkin_t *skin, vec3_t origin, vec3_t angles, const byte *rgba, entityState_t *state ) {
refdef_t refdef;
refEntity_t ent;

Expand All @@ -118,7 +118,7 @@ void CG_Draw3DModelEx( float x, float y, float w, float h, qhandle_t model, cgSk
AnglesToAxis( angles, ent.axis );
VectorCopy( origin, ent.origin );
ent.hModel = model;
ent.customSkin = CG_AddSkinToFrame( skin );
ent.customSkin = CG_AddSkinToFrame( skin, state );
ent.renderfx = RF_NOSHADOW; // no stencil shadows

if ( rgba ) {
Expand Down Expand Up @@ -151,7 +151,7 @@ CG_Draw3DModel
================
*/
void CG_Draw3DModel( float x, float y, float w, float h, qhandle_t model, cgSkin_t *skin, vec3_t origin, vec3_t angles ) {
CG_Draw3DModelEx( x, y, w, h, model, skin, origin, angles, NULL );
CG_Draw3DModelEx( x, y, w, h, model, skin, origin, angles, NULL, NULL );
}

/*
Expand All @@ -167,6 +167,8 @@ void CG_DrawHead( float x, float y, float w, float h, int playerNum, vec3_t head
float len;
vec3_t origin;
vec3_t mins, maxs;
entityState_t *entityState;
byte color[4];

pi = &cgs.playerinfo[ playerNum ];

Expand All @@ -190,7 +192,15 @@ void CG_DrawHead( float x, float y, float w, float h, int playerNum, vec3_t head
// allow per-model tweaking
VectorAdd( origin, pi->headOffset, origin );

CG_Draw3DModelEx( x, y, w, h, pi->headModel, &pi->modelSkin, origin, headAngles, pi->c1RGBA );
// TODO: Use prediction entity state for local players?
entityState = &cg_entities[playerNum].currentState;

color[0] = pi->c1RGBA[0];
color[1] = pi->c1RGBA[1];
color[2] = pi->c1RGBA[2];
color[3] = entityState->skinFraction * 255;

CG_Draw3DModelEx( x, y, w, h, pi->headModel, &pi->modelSkin, origin, headAngles, color, entityState );
} else if ( cg_drawIcons.integer ) {
CG_DrawPic( x, y, w, h, pi->modelIcon );
}
Expand Down Expand Up @@ -2999,7 +3009,7 @@ void CG_DrawMiscGamemodels( void ) {
}
ent.hModel = cgs.miscGameModels[i].model;

ent.customSkin = CG_AddSkinToFrame( &cgs.miscGameModels[i].skin );
ent.customSkin = CG_AddSkinToFrame( &cgs.miscGameModels[i].skin, NULL );
trap_R_AddRefEntityToScene( &ent );

drawn++;
Expand Down
4 changes: 2 additions & 2 deletions code/cgame/cg_ents.c
Original file line number Diff line number Diff line change
Expand Up @@ -1120,11 +1120,11 @@ static void CG_TeamBase( centity_t *cent ) {

if ( cent->currentState.modelindex == TEAM_RED ) {
model.hModel = cgs.media.harvesterModel;
model.customSkin = CG_AddSkinToFrame( &cgs.media.harvesterRedSkin );
model.customSkin = CG_AddSkinToFrame( &cgs.media.harvesterRedSkin, &cent->currentState );
}
else if ( cent->currentState.modelindex == TEAM_BLUE ) {
model.hModel = cgs.media.harvesterModel;
model.customSkin = CG_AddSkinToFrame( &cgs.media.harvesterBlueSkin );
model.customSkin = CG_AddSkinToFrame( &cgs.media.harvesterBlueSkin, &cent->currentState );
}
else {
model.hModel = cgs.media.harvesterNeutralModel;
Expand Down
12 changes: 9 additions & 3 deletions code/cgame/cg_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,15 @@ typedef struct {

// skin surfaces array shouldn't be dynamically allocated because players reuse the same skin structure when changing models
#define MAX_CG_SKIN_SURFACES 100
#define MAX_CG_SKIN_SURFACE_SHADERS 10
typedef struct {
int numSurfaces;
qhandle_t surfaces[MAX_CG_SKIN_SURFACES];
qhandle_t surfaces[MAX_CG_SKIN_SURFACE_SHADERS]; // allocated skin surfaces (mesh name + shader)
int numShaders;
} cgSkinMesh_t;

typedef struct {
int numMeshes;
cgSkinMesh_t meshes[MAX_CG_SKIN_SURFACES];
} cgSkin_t;

//=================================================
Expand Down Expand Up @@ -1713,7 +1719,7 @@ int CG_Text_Height( const char *text, float scale, int limit );
void CG_Player( centity_t *cent );
void CG_ResetPlayerEntity( centity_t *cent );
void CG_AddRefEntityWithPowerups( refEntity_t *ent, entityState_t *state );
qhandle_t CG_AddSkinToFrame( const cgSkin_t *skin );
qhandle_t CG_AddSkinToFrame( const cgSkin_t *skin, entityState_t *state );
qboolean CG_RegisterSkin( const char *name, cgSkin_t *skin, qboolean append );
void CG_NewPlayerInfo( int playerNum );
sfxHandle_t CG_CustomSound( int playerNum, const char *soundName );
Expand Down
Loading

0 comments on commit c52a18b

Please sign in to comment.