21 May 2018

This commit is contained in:
g-cont 2018-05-21 00:00:00 +03:00 committed by Alibek Omarov
parent 05cbb432c2
commit 202f3dda91
12 changed files with 169 additions and 88 deletions

View File

@ -117,14 +117,14 @@ BRUSH MODELS
#define LUMP_FACEINFO 1 // landscape and lightmap resolution info
#define LUMP_CUBEMAPS 2 // cubemap description
#define LUMP_VERTNORMALS 3 // phong shaded vertex normals
#define LUMP_VERTEX_LIGHT 4 // contain compressed light cubes per empty leafs
#define LUMP_LEAF_LIGHTING 4 // store vertex lighting for statics
#define LUMP_WORLDLIGHTS 5 // list of all the virtual and real lights (used to relight models in-game)
#define LUMP_COLLISION 6 // physics engine collision hull dump
#define LUMP_AINODEGRAPH 7 // node graph that stored into the bsp
#define LUMP_COLLISION 6 // physics engine collision hull dump (userdata)
#define LUMP_AINODEGRAPH 7 // node graph that stored into the bsp (userdata)
#define LUMP_SHADOWMAP 8 // contains shadow map for direct light
#define LUMP_UNUSED1 9 // one lump reserved for me
#define LUMP_UNUSED2 10 // one lump reserved for me
#define LUMP_UNUSED3 11 // one lump reserved for me
#define LUMP_VERTEX_LIGHT 9 // store vertex lighting for statics
#define LUMP_UNUSED0 10 // one lump reserved for me
#define LUMP_UNUSED1 11 // one lump reserved for me
#define EXTRA_LUMPS 12 // count of the extra lumps
// texture flags

View File

@ -211,7 +211,7 @@ typedef struct render_api_s
void (*GL_DrawParticles)( const struct ref_viewpass_s *rvp, qboolean trans_pass, float frametime );
void (*EnvShot)( const float *vieworg, const char *name, qboolean skyshot, int shotsize ); // store skybox into gfx\env folder
int (*SPR_LoadExt)( const char *szPicName, unsigned int texFlags ); // extended version of SPR_Load
colorVec (*LightVec)( const float *start, const float *end, float *lightspot );
colorVec (*LightVec)( const float *start, const float *end, float *lightspot, float *lightvec );
struct mstudiotex_s *( *StudioGetTexture )( struct cl_entity_s *e );
const struct ref_overview_s *( *GetOverviewParms )( void );
const char *( *GetFileByIndex )( int fileindex );

View File

@ -1226,6 +1226,12 @@ void CL_EmitEntities( void )
if( !cl.frames[cl.parsecountmod].valid )
return;
// animate lightestyles
CL_RunLightStyles ();
// decay dynamic lights
CL_DecayLights ();
// compute last interpolation amount
CL_UpdateFrameLerp ();

View File

@ -2059,13 +2059,11 @@ void CL_ReadPackets( void )
if( cl.maxclients > 1 && cls.state == ca_active && !host_developer.value )
Cvar_SetCheatState();
#endif
// singleplayer never has connection timeout
if( NET_IsLocalAddress( cls.netchan.remote_address ))
return;
// hot precache and downloading resources
if( cls.signon == SIGNONS && cl.lastresourcecheck < host.realtime )
{
double checktime = Host_IsLocalGame() ? 0.1 : 1.0;
if( !cls.dl.custom && cl.resourcesneeded.pNext != &cl.resourcesneeded )
{
// check resource for downloading and precache
@ -2073,9 +2071,14 @@ void CL_ReadPackets( void )
CL_BatchResourceRequest( false );
cls.dl.custom = true;
}
cl.lastresourcecheck = host.realtime + 5.0f; // don't checking too often
cl.lastresourcecheck = host.realtime + checktime;
}
// singleplayer never has connection timeout
if( NET_IsLocalAddress( cls.netchan.remote_address ))
return;
// if in the debugger last frame, don't timeout
if( host.frametime > 5.0f ) cls.netchan.last_received = Sys_DoubleTime();
@ -2774,12 +2777,6 @@ void Host_ClientFrame( void )
// update audio
SND_UpdateSound ();
// animate lightestyles
CL_RunLightStyles ();
// decay dynamic lights
CL_DecayLights ();
// play avi-files
SCR_RunCinematic ();

View File

@ -202,6 +202,9 @@ void SCR_RSpeeds( void )
Con_DrawString( x, y, p, color );
y += height;
// handle '\n\n'
if( *p == '\n' )
y += height;
if( end ) p = end + 1;
else break;
} while( 1 );

View File

@ -863,40 +863,44 @@ void R_AliasDynamicLight( cl_entity_t *ent, alight_t *plight )
VectorScale( lightDir, 2048.0f, vecEnd );
VectorAdd( vecEnd, vecSrc, vecEnd );
light = R_LightVec( vecSrc, vecEnd, g_alias.lightspot );
light = R_LightVec( vecSrc, vecEnd, g_alias.lightspot, g_alias.lightvec );
VectorScale( lightDir, 2048.0f, vecEnd );
VectorAdd( vecEnd, vecSrc, vecEnd );
if( VectorIsNull( g_alias.lightvec ))
{
vecSrc[0] -= 16.0f;
vecSrc[1] -= 16.0f;
vecEnd[0] -= 16.0f;
vecEnd[1] -= 16.0f;
vecSrc[0] -= 16.0f;
vecSrc[1] -= 16.0f;
vecEnd[0] -= 16.0f;
vecEnd[1] -= 16.0f;
gcolor = R_LightVec( vecSrc, vecEnd, NULL, NULL );
grad[0] = ( gcolor.r + gcolor.g + gcolor.b ) / 768.0f;
gcolor = R_LightVec( vecSrc, vecEnd, NULL );
grad[0] = ( gcolor.r + gcolor.g + gcolor.b ) / 768.0f;
vecSrc[0] += 32.0f;
vecEnd[0] += 32.0f;
vecSrc[0] += 32.0f;
vecEnd[0] += 32.0f;
gcolor = R_LightVec( vecSrc, vecEnd, NULL, NULL );
grad[1] = ( gcolor.r + gcolor.g + gcolor.b ) / 768.0f;
gcolor = R_LightVec( vecSrc, vecEnd, NULL );
grad[1] = ( gcolor.r + gcolor.g + gcolor.b ) / 768.0f;
vecSrc[1] += 32.0f;
vecEnd[1] += 32.0f;
vecSrc[1] += 32.0f;
vecEnd[1] += 32.0f;
gcolor = R_LightVec( vecSrc, vecEnd, NULL, NULL );
grad[2] = ( gcolor.r + gcolor.g + gcolor.b ) / 768.0f;
gcolor = R_LightVec( vecSrc, vecEnd, NULL );
grad[2] = ( gcolor.r + gcolor.g + gcolor.b ) / 768.0f;
vecSrc[0] -= 32.0f;
vecEnd[0] -= 32.0f;
vecSrc[0] -= 32.0f;
vecEnd[0] -= 32.0f;
gcolor = R_LightVec( vecSrc, vecEnd, NULL, NULL );
grad[3] = ( gcolor.r + gcolor.g + gcolor.b ) / 768.0f;
gcolor = R_LightVec( vecSrc, vecEnd, NULL );
grad[3] = ( gcolor.r + gcolor.g + gcolor.b ) / 768.0f;
lightDir[0] = grad[0] - grad[1] - grad[2] + grad[3];
lightDir[1] = grad[1] + grad[0] - grad[2] - grad[3];
VectorNormalize( lightDir );
lightDir[0] = grad[0] - grad[1] - grad[2] + grad[3];
lightDir[1] = grad[1] + grad[0] - grad[2] - grad[3];
VectorNormalize( lightDir );
}
else
{
VectorCopy( g_alias.lightvec, lightDir );
}
}
VectorSet( finalLight, light.r, light.g, light.b );
@ -1313,6 +1317,8 @@ static void R_AliasDrawLightTrace( cl_entity_t *e )
{
if( r_drawentities->value == 7 )
{
vec3_t origin;
pglDisable( GL_TEXTURE_2D );
pglDisable( GL_DEPTH_TEST );
@ -1322,6 +1328,13 @@ static void R_AliasDrawLightTrace( cl_entity_t *e )
pglVertex3fv( g_alias.lightspot );
pglEnd();
pglBegin( GL_LINES );
pglColor3f( 0, 0.5, 1 );
VectorMA( g_alias.lightspot, -64.0f, g_alias.lightvec, origin );
pglVertex3fv( g_alias.lightspot );
pglVertex3fv( origin );
pglEnd();
pglPointSize( 5.0f );
pglColor3f( 1, 0, 0 );
pglBegin( GL_POINTS );
@ -1429,11 +1442,16 @@ void R_DrawAliasModel( cl_entity_t *e )
R_AliasSetRemapColors( topcolor, bottomcolor );
}
pglTranslatef( m_pAliasHeader->scale_origin[0], m_pAliasHeader->scale_origin[1], m_pAliasHeader->scale_origin[2] );
if( tr.fFlipViewModel )
{
pglTranslatef( m_pAliasHeader->scale_origin[0], -m_pAliasHeader->scale_origin[1], m_pAliasHeader->scale_origin[2] );
pglScalef( m_pAliasHeader->scale[0], -m_pAliasHeader->scale[1], m_pAliasHeader->scale[2] );
else pglScalef( m_pAliasHeader->scale[0], m_pAliasHeader->scale[1], m_pAliasHeader->scale[2] );
}
else
{
pglTranslatef( m_pAliasHeader->scale_origin[0], m_pAliasHeader->scale_origin[1], m_pAliasHeader->scale_origin[2] );
pglScalef( m_pAliasHeader->scale[0], m_pAliasHeader->scale[1], m_pAliasHeader->scale[2] );
}
anim = (int)(g_alias.time * 10) & 3;
skin = bound( 0, RI.currententity->curstate.skin, m_pAliasHeader->numskins - 1 );

View File

@ -330,7 +330,7 @@ void R_AnimateLight( void );
void R_GetLightSpot( vec3_t lightspot );
void R_MarkLights( dlight_t *light, int bit, mnode_t *node );
void R_LightForPoint( const vec3_t point, color24 *ambientLight, qboolean invLight, qboolean useAmbient, float radius );
colorVec R_LightVec( const vec3_t start, const vec3_t end, vec3_t lightspot );
colorVec R_LightVec( const vec3_t start, const vec3_t end, vec3_t lightspot, vec3_t lightvec );
int R_CountSurfaceDlights( msurface_t *surf );
colorVec R_LightPoint( const vec3_t p0 );
int R_CountDlights( void );

View File

@ -217,6 +217,7 @@ int R_CountSurfaceDlights( msurface_t *surf )
=======================================================================
*/
static vec3_t g_trace_lightspot;
static vec3_t g_trace_lightvec;
static float g_trace_fraction;
/*
@ -230,10 +231,11 @@ static qboolean R_RecursiveLightPoint( model_t *model, mnode_t *node, float p1f,
int i, map, side, size;
float ds, dt, s, t;
int sample_size;
color24 *lm, *dm;
mextrasurf_t *info;
msurface_t *surf;
mtexinfo_t *tex;
color24 *lm;
matrix3x4 tbn;
vec3_t mid;
// didn't hit anything
@ -306,6 +308,31 @@ static qboolean R_RecursiveLightPoint( model_t *model, mnode_t *node, float p1f,
lm = surf->samples + Q_rint( dt ) * smax + Q_rint( ds );
g_trace_fraction = midf;
size = smax * tmax;
dm = NULL;
if( surf->info->deluxemap )
{
vec3_t faceNormal;
if( FBitSet( surf->flags, SURF_PLANEBACK ))
VectorNegate( surf->plane->normal, faceNormal );
else VectorCopy( surf->plane->normal, faceNormal );
// compute face TBN
#if 1
Vector4Set( tbn[0], surf->info->lmvecs[0][0], surf->info->lmvecs[0][1], surf->info->lmvecs[0][2], 0.0f );
Vector4Set( tbn[1], -surf->info->lmvecs[1][0], -surf->info->lmvecs[1][1], -surf->info->lmvecs[1][2], 0.0f );
Vector4Set( tbn[2], faceNormal[0], faceNormal[1], faceNormal[2], 0.0f );
#else
Vector4Set( tbn[0], surf->info->lmvecs[0][0], -surf->info->lmvecs[1][0], faceNormal[0], 0.0f );
Vector4Set( tbn[1], surf->info->lmvecs[0][1], -surf->info->lmvecs[1][1], faceNormal[1], 0.0f );
Vector4Set( tbn[2], surf->info->lmvecs[0][2], -surf->info->lmvecs[1][2], faceNormal[2], 0.0f );
#endif
VectorNormalize( tbn[0] );
VectorNormalize( tbn[1] );
VectorNormalize( tbn[2] );
dm = surf->info->deluxemap + Q_rint( dt ) * smax + Q_rint( ds );
}
for( map = 0; map < MAXLIGHTMAPS && surf->styles[map] != 255; map++ )
{
@ -324,6 +351,18 @@ static qboolean R_RecursiveLightPoint( model_t *model, mnode_t *node, float p1f,
cv->b += LightToTexGamma( lm->b ) * scale;
}
lm += size; // skip to next lightmap
if( dm != NULL )
{
vec3_t srcNormal, lightNormal;
float f = (1.0f / 255.0f);
VectorSet( srcNormal, (dm->r * f) * 2.0f - 1.0f, (dm->g * f) * 2.0f - 1.0f, (dm->b * f) * 2.0f - 1.0f );
Matrix3x4_VectorIRotate( tbn, srcNormal, lightNormal ); // turn to world space
VectorScale( lightNormal, (float)scale * -1.0f, lightNormal ); // turn direction from light
VectorAdd( g_trace_lightvec, lightNormal, g_trace_lightvec );
dm += size; // skip to next deluxmap
}
}
return true;
@ -340,13 +379,14 @@ R_LightVec
check bspmodels to get light from
=================
*/
colorVec R_LightVec( const vec3_t start, const vec3_t end, vec3_t lspot )
colorVec R_LightVec( const vec3_t start, const vec3_t end, vec3_t lspot, vec3_t lvec )
{
float last_fraction;
int i, maxEnts = 1;
colorVec light, cv;
if( lspot ) VectorClear( lspot );
if( lvec ) VectorClear( lvec );
if( cl.worldmodel && cl.worldmodel->lightdata )
{
@ -354,7 +394,7 @@ colorVec R_LightVec( const vec3_t start, const vec3_t end, vec3_t lspot )
last_fraction = 1.0f;
// get light from bmodels too
if( r_lighting_extended->value )
if( CVAR_TO_BOOL( r_lighting_extended ))
maxEnts = clgame.pmove->numphysent;
// check all the bsp-models
@ -383,6 +423,7 @@ colorVec R_LightVec( const vec3_t start, const vec3_t end, vec3_t lspot )
}
VectorClear( g_trace_lightspot );
VectorClear( g_trace_lightvec );
g_trace_fraction = 1.0f;
if( !R_RecursiveLightPoint( pe->model, pnodes, 0.0f, 1.0f, &cv, start_l, end_l ))
@ -391,6 +432,7 @@ colorVec R_LightVec( const vec3_t start, const vec3_t end, vec3_t lspot )
if( g_trace_fraction < last_fraction )
{
if( lspot ) VectorCopy( g_trace_lightspot, lspot );
if( lvec ) VectorNormalize2( g_trace_lightvec, lvec );
light.r = Q_min(( cv.r >> 7 ), 255 );
light.g = Q_min(( cv.g >> 7 ), 255 );
light.b = Q_min(( cv.b >> 7 ), 255 );
@ -420,5 +462,5 @@ colorVec R_LightPoint( const vec3_t p0 )
VectorSet( p1, p0[0], p0[1], p0[2] - 2048.0f );
return R_LightVec( p0, p1, NULL );
return R_LightVec( p0, p1, NULL, NULL );
}

View File

@ -280,13 +280,10 @@ void GL_BuildPolygonFromSurface( model_t *mod, msurface_t *fa )
float s, t;
glpoly_t *poly;
// already created
if( !mod || fa->polys ) return;
if( !fa->texinfo || !fa->texinfo->texture )
if( !mod || !fa->texinfo || !fa->texinfo->texture )
return; // bad polygon ?
if( fa->flags & SURF_CONVEYOR && fa->texinfo->texture->gl_texturenum != 0 )
if( FBitSet( fa->flags, SURF_CONVEYOR ) && fa->texinfo->texture->gl_texturenum != 0 )
{
glt = R_GetTexture( fa->texinfo->texture->gl_texturenum );
tex = fa->texinfo->texture;
@ -304,8 +301,12 @@ void GL_BuildPolygonFromSurface( model_t *mod, msurface_t *fa )
lnumverts = fa->numedges;
vertpage = 0;
// draw texture
poly = Mem_Alloc( mod->mempool, sizeof( glpoly_t ) + ( lnumverts - 4 ) * VERTEXSIZE * sizeof( float ));
// detach if already created, reconstruct again
poly = fa->polys;
fa->polys = NULL;
// quake simple models (healthkits etc) need to be reconstructed their polys because LM coords has changed after the map change
poly = Mem_Realloc( mod->mempool, poly, sizeof( glpoly_t ) + ( lnumverts - 4 ) * VERTEXSIZE * sizeof( float ));
poly->next = fa->polys;
poly->flags = fa->flags;
fa->polys = poly;
@ -1996,8 +1997,10 @@ void GL_CreateSurfaceLightmap( msurface_t *surf )
mextrasurf_t *info = surf->info;
byte *base;
if( !cl.worldmodel->lightdata ) return;
if( surf->flags & SURF_DRAWTILED )
if( !loadmodel->lightdata )
return;
if( FBitSet( surf->flags, SURF_DRAWTILED ))
return;
sample_size = Mod_SampleSizeForFace( surf );

View File

@ -1688,40 +1688,44 @@ void R_StudioDynamicLight( cl_entity_t *ent, alight_t *plight )
VectorScale( lightDir, 2048.0f, vecEnd );
VectorAdd( vecEnd, vecSrc, vecEnd );
light = R_LightVec( vecSrc, vecEnd, g_studio.lightspot );
light = R_LightVec( vecSrc, vecEnd, g_studio.lightspot, g_studio.lightvec );
VectorScale( lightDir, 2048.0f, vecEnd );
VectorAdd( vecEnd, vecSrc, vecEnd );
if( VectorIsNull( g_studio.lightvec ))
{
vecSrc[0] -= 16.0f;
vecSrc[1] -= 16.0f;
vecEnd[0] -= 16.0f;
vecEnd[1] -= 16.0f;
vecSrc[0] -= 16.0f;
vecSrc[1] -= 16.0f;
vecEnd[0] -= 16.0f;
vecEnd[1] -= 16.0f;
gcolor = R_LightVec( vecSrc, vecEnd, NULL, NULL );
grad[0] = ( gcolor.r + gcolor.g + gcolor.b ) / 768.0f;
gcolor = R_LightVec( vecSrc, vecEnd, NULL );
grad[0] = ( gcolor.r + gcolor.g + gcolor.b ) / 768.0f;
vecSrc[0] += 32.0f;
vecEnd[0] += 32.0f;
vecSrc[0] += 32.0f;
vecEnd[0] += 32.0f;
gcolor = R_LightVec( vecSrc, vecEnd, NULL, NULL );
grad[1] = ( gcolor.r + gcolor.g + gcolor.b ) / 768.0f;
gcolor = R_LightVec( vecSrc, vecEnd, NULL );
grad[1] = ( gcolor.r + gcolor.g + gcolor.b ) / 768.0f;
vecSrc[1] += 32.0f;
vecEnd[1] += 32.0f;
vecSrc[1] += 32.0f;
vecEnd[1] += 32.0f;
gcolor = R_LightVec( vecSrc, vecEnd, NULL, NULL );
grad[2] = ( gcolor.r + gcolor.g + gcolor.b ) / 768.0f;
gcolor = R_LightVec( vecSrc, vecEnd, NULL );
grad[2] = ( gcolor.r + gcolor.g + gcolor.b ) / 768.0f;
vecSrc[0] -= 32.0f;
vecEnd[0] -= 32.0f;
vecSrc[0] -= 32.0f;
vecEnd[0] -= 32.0f;
gcolor = R_LightVec( vecSrc, vecEnd, NULL, NULL );
grad[3] = ( gcolor.r + gcolor.g + gcolor.b ) / 768.0f;
gcolor = R_LightVec( vecSrc, vecEnd, NULL );
grad[3] = ( gcolor.r + gcolor.g + gcolor.b ) / 768.0f;
lightDir[0] = grad[0] - grad[1] - grad[2] + grad[3];
lightDir[1] = grad[1] + grad[0] - grad[2] - grad[3];
VectorNormalize( lightDir );
lightDir[0] = grad[0] - grad[1] - grad[2] + grad[3];
lightDir[1] = grad[1] + grad[0] - grad[2] - grad[3];
VectorNormalize( lightDir );
}
else
{
VectorCopy( g_studio.lightvec, lightDir );
}
}
VectorSet( finalLight, light.r, light.g, light.b );
@ -2531,6 +2535,7 @@ static void R_StudioDrawAbsBBox( void )
TriVertex3fv( p[boxpnt[i][3]] );
}
TriEnd();
TriRenderMode( kRenderNormal );
}
/*
@ -3126,6 +3131,13 @@ void R_StudioRenderFinal( void )
pglVertex3fv( g_studio.lightspot );
pglEnd();
pglBegin( GL_LINES );
pglColor3f( 0, 0.5, 1 );
VectorMA( g_studio.lightspot, -64.0f, g_studio.lightvec, origin );
pglVertex3fv( g_studio.lightspot );
pglVertex3fv( origin );
pglEnd();
pglPointSize( 5.0f );
pglColor3f( 1, 0, 0 );
pglBegin( GL_POINTS );

View File

@ -362,7 +362,7 @@ static int Mod_ArrayUsage( const char *szItem, int items, int maxitems, int item
Con_Printf( "%-12s %7i/%-7i %8i/%-8i (%4.1f%%) ", szItem, items, maxitems, items * itemsize, maxitems * itemsize, percentage );
if( percentage > 99.9f )
if( percentage > 99.99f )
Con_Printf( "^1SIZE OVERFLOW!!!^7\n" );
else if( percentage > 95.0f )
Con_Printf( "^3SIZE DANGER!^7\n" );
@ -384,7 +384,7 @@ static int Mod_GlobUsage( const char *szItem, int itemstorage, int maxstorage )
Con_Printf( "%-15s %-12s %8i/%-8i (%4.1f%%) ", szItem, "[variable]", itemstorage, maxstorage, percentage );
if( percentage > 99.9f )
if( percentage > 99.99f )
Con_Printf( "^1SIZE OVERFLOW!!!^7\n" );
else if( percentage > 95.0f )
Con_Printf( "^3SIZE DANGER!^7\n" );

View File

@ -588,7 +588,7 @@ static void Netchan_CreateFragments_( netchan_t *chan, sizebuf_t *msg )
if( pbOut && uCompressedSize > 0 && uCompressedSize < uSourceSize )
{
Con_DPrintf( "Compressing split packet (%d -> %d bytes)\n", uSourceSize, uCompressedSize );
Con_Reportf( "Compressing split packet (%d -> %d bytes)\n", uSourceSize, uCompressedSize );
memcpy( msg->pData, pbOut, uCompressedSize );
MSG_SeekToBit( msg, uCompressedSize << 3, SEEK_SET );
}