2
0
mirror of https://github.com/FWGS/xash3d-fwgs synced 2024-11-25 11:19:59 +01:00

ref: gl: allow shadows, use shadows from magic's engine fork

This commit is contained in:
Alibek Omarov 2024-02-23 04:05:26 +03:00
parent 462b64b8ce
commit cd7727b7de

View File

@ -32,8 +32,11 @@ typedef struct
model_t *model; model_t *model;
} player_model_t; } player_model_t;
// never gonna change, just shut up const warning // never gonna change you up, never gonna override you down
cvar_t r_shadows = { (char *)"r_shadows", (char *)"0", 0 }; // TODO: actually let client.dll override it
CVAR_DEFINE_AUTO( r_shadows, "0", FCVAR_ARCHIVE, "drop ugly shadow" );
CVAR_DEFINE_AUTO( r_shadow_alpha, "0.5", FCVAR_ARCHIVE, "ugly shadow opacity" );
CVAR_DEFINE_AUTO( r_shadow_height, "0", FCVAR_ARCHIVE, "ugly shadow height" );
static vec3_t hullcolor[8] = static vec3_t hullcolor[8] =
{ {
@ -154,8 +157,12 @@ void R_StudioInit( void )
Matrix3x4_LoadIdentity( g_studio.rotationmatrix ); Matrix3x4_LoadIdentity( g_studio.rotationmatrix );
// g-cont. cvar disabled by Valve // a1ba: enabled since HL25
// gEngfuncs.Cvar_RegisterVariable( &r_shadows ); gEngfuncs.Cvar_RegisterVariable( &r_shadows );
// a1ba: TimeWarp cvars (TODO: move to client.dll)
gEngfuncs.Cvar_RegisterVariable( &r_shadow_alpha );
gEngfuncs.Cvar_RegisterVariable( &r_shadow_height );
g_studio.interpolate = true; g_studio.interpolate = true;
g_studio.framecount = 0; g_studio.framecount = 0;
@ -2930,25 +2937,35 @@ R_StudioDrawPointsShadow
static void R_StudioDrawPointsShadow( void ) static void R_StudioDrawPointsShadow( void )
{ {
float *av, height; float *av, height;
float vec_x, vec_y;
mstudiomesh_t *pmesh; mstudiomesh_t *pmesh;
vec3_t point;
int i, k; int i, k;
pmtrace_t tr;
vec3_t trEnd;
if( FBitSet( RI.currententity->curstate.effects, EF_NOSHADOW )) if( FBitSet( RI.currententity->curstate.effects, EF_NOSHADOW ))
return; return;
VectorCopy( RI.currententity->origin, trEnd );
trEnd[2] -= 4096;
tr = gEngfuncs.CL_TraceLine( RI.currententity->origin, trEnd, PM_STUDIO_IGNORE | PM_GLASS_IGNORE );
// didn't hit floor
if( tr.fraction >= 1.0f )
return;
if( glState.stencilEnabled ) if( glState.stencilEnabled )
pglEnable( GL_STENCIL_TEST ); pglEnable( GL_STENCIL_TEST );
height = g_studio.lightspot[2] + 1.0f; height = r_shadow_height.value;
vec_x = -g_studio.lightvec[0] * 8.0f;
vec_y = -g_studio.lightvec[1] * 8.0f;
for( k = 0; k < m_pSubModel->nummesh; k++ ) for( k = 0; k < m_pSubModel->nummesh; k++ )
{ {
short *ptricmds; short *ptricmds;
if( FBitSet( g_studio.meshes[k].flags, STUDIO_NF_MASKED | STUDIO_NF_ADDITIVE | STUDIO_NF_FULLBRIGHT ))
continue;
pmesh = (mstudiomesh_t *)((byte *)m_pStudioHeader + m_pSubModel->meshindex) + k; pmesh = (mstudiomesh_t *)((byte *)m_pStudioHeader + m_pSubModel->meshindex) + k;
ptricmds = (short *)((byte *)m_pStudioHeader + pmesh->triindex); ptricmds = (short *)((byte *)m_pStudioHeader + pmesh->triindex);
@ -2970,11 +2987,7 @@ static void R_StudioDrawPointsShadow( void )
for( ; i > 0; i--, ptricmds += 4 ) for( ; i > 0; i--, ptricmds += 4 )
{ {
av = g_studio.verts[ptricmds[0]]; av = g_studio.verts[ptricmds[0]];
point[0] = av[0] - (vec_x * ( av[2] - g_studio.lightspot[2] )); pglVertex3f( av[0], av[1], tr.endpos[2] + height + 0.16f );
point[1] = av[1] - (vec_y * ( av[2] - g_studio.lightspot[2] ));
point[2] = g_studio.lightspot[2] + 1.0f;
pglVertex3fv( point );
} }
pglEnd(); pglEnd();
@ -3035,12 +3048,10 @@ static void GL_StudioDrawShadow( void )
if( r_shadows.value && g_studio.rendermode != kRenderTransAdd && !FBitSet( RI.currentmodel->flags, STUDIO_AMBIENT_LIGHT )) if( r_shadows.value && g_studio.rendermode != kRenderTransAdd && !FBitSet( RI.currentmodel->flags, STUDIO_AMBIENT_LIGHT ))
{ {
float color = 1.0f - (tr.blend * 0.5f);
pglDisable( GL_TEXTURE_2D ); pglDisable( GL_TEXTURE_2D );
pglBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); pglBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
pglEnable( GL_BLEND ); pglEnable( GL_BLEND );
pglColor4f( 0.0f, 0.0f, 0.0f, 1.0f - color ); pglColor4f( 0.0f, 0.0f, 0.0f, ( tr.blend - 1 ) + r_shadow_alpha.value );
pglDepthFunc( GL_LESS ); pglDepthFunc( GL_LESS );
R_StudioDrawPointsShadow(); R_StudioDrawPointsShadow();