30 Jun 2010

This commit is contained in:
g-cont 2010-06-30 00:00:00 +04:00 committed by Alibek Omarov
parent 2170e82a7b
commit 9eb4e5cde1
22 changed files with 1125 additions and 24 deletions

View File

@ -183,7 +183,7 @@ void TE_ParseExplosion( void )
char szDecal[32];
sprintf( szDecal, "{scorch%i", RANDOM_LONG( 1, 3 ));
g_pTempEnts->PlaceDecal( pos, NULLENT_INDEX, szDecal );
g_pTempEnts->PlaceDecal( pos2, 0, szDecal );
if( !( flags & TE_EXPLFLAG_NOSOUND ))
{

View File

@ -27,6 +27,20 @@ struct dlight_s
bool dark; // subtracts light instead of adding
};
// decal flags
#define FDECAL_PERMANENT 0x01 // This decal should not be removed in favor of any new decals
#define FDECAL_REFERENCE 0x02 // This is a decal that's been moved from another level
#define FDECAL_CUSTOM 0x04 // This is a custom clan logo and should not be saved/restored
#define FDECAL_HFLIP 0x08 // Flip horizontal (U/S) axis
#define FDECAL_VFLIP 0x10 // Flip vertical (V/T) axis
#define FDECAL_CLIPTEST 0x20 // Decal needs to be clip-tested
#define FDECAL_NOCLIP 0x40 // Decal is not clipped by containing polygon
#define FDECAL_USESAXIS 0x80 // Uses the s axis field to determine orientation
#define FDECAL_DYNAMIC 0x100 // Indicates the decal is dynamic
#define FDECAL_SECONDPASS 0x200 // Decals that have to be drawn after everything else
#define FDECAL_WATER 0x400 // Decal should only be applied to water
#define FDECAL_DONTSAVE 0x800 // Decal was loaded from adjacent level, don't save it for this level
typedef struct efxapi_s
{
particle_t* (*R_AllocParticle)( void );

View File

@ -503,7 +503,6 @@ void CL_AddParticles( void )
// send the particle to the renderer
re->AddPolygon( &p->poly );
// evaluate particle
p->org[0] += p->vel[0] * frametime;
p->org[1] += p->vel[1] * frametime;
@ -1165,7 +1164,14 @@ void CL_AddDecals( void )
void CL_DecalShoot( HSPRITE hDecal, edict_t *pEnt, int modelIndex, float *pos, int flags )
{
CL_SpawnDecal( hDecal, pEnt, pos, 0, 90.0f, 5.0f );
int entityIndex = 0;
rgba_t color;
if( CL_IsValidEdict( pEnt ))
entityIndex = pEnt->serialnumber;
Vector4Set( color, 255, 255, 255, 255 );
if( re ) re->DecalShoot( hDecal, entityIndex, modelIndex, pos, NULL, 0, color );
}
/*
@ -1176,12 +1182,12 @@ CL_SpawnStaticDecal
*/
void CL_SpawnStaticDecal( vec3_t origin, int decalIndex, int entityIndex, int modelIndex )
{
edict_t *pEnt;
rgba_t color;
pEnt = CL_GetEdictByIndex( entityIndex );
decalIndex = bound( 0, decalIndex, MAX_DECALS - 1 );
decalIndex = bound( 0, decalIndex, MAX_DECALNAMES - 1 );
Vector4Set( color, 255, 255, 255, 255 );
CL_SpawnDecal( cl.decal_shaders[decalIndex], pEnt, origin, 0, 90.0f, 32.0f );
if( re ) re->DecalShoot( cl.decal_shaders[decalIndex], entityIndex, modelIndex, origin, NULL, 0, color );
}
void CL_FindExplosionPlane( const vec3_t origin, float radius, vec3_t result )

View File

@ -2023,7 +2023,7 @@ static int pfnDecalIndexFromName( const char *szDecalName )
int i;
// look through the loaded sprite name list for SpriteName
for( i = 0; i < MAX_DECALS && cl.configstrings[CS_DECALS+i+1][0]; i++ )
for( i = 0; i < MAX_DECALNAMES && cl.configstrings[CS_DECALS+i+1][0]; i++ )
{
if( !com.stricmp( szDecalName, cl.configstrings[CS_DECALS+i+1] ))
return cl.decal_shaders[i+1];
@ -2039,7 +2039,7 @@ pfnDecalIndex
*/
static int pfnDecalIndex( int id )
{
id = bound( 0, id, MAX_DECALS - 1 );
id = bound( 0, id, MAX_DECALNAMES - 1 );
return cl.decal_shaders[id];
}

View File

@ -684,7 +684,7 @@ void CL_PrepVideo( void )
SCR_UpdateScreen();
}
for( i = 0; i < MAX_DECALS && cl.configstrings[CS_DECALS+1+i][0]; i++ )
for( i = 0; i < MAX_DECALNAMES && cl.configstrings[CS_DECALS+1+i][0]; i++ )
{
com.strncpy( name, cl.configstrings[CS_DECALS+1+i], MAX_STRING );
cl.decal_shaders[i+1] = re->RegisterShader( name, SHADER_DECAL );

View File

@ -629,7 +629,7 @@ void CL_ParseConfigString( sizebuf_t *msg )
{
cl.sound_precache[i-CS_SOUNDS] = S_RegisterSound( cl.configstrings[i] );
}
else if( i >= CS_DECALS && i < CS_DECALS+MAX_DECALS && cl.video_prepped )
else if( i >= CS_DECALS && i < CS_DECALS+MAX_DECALNAMES && cl.video_prepped )
{
cl.decal_shaders[i-CS_DECALS] = re->RegisterShader( cl.configstrings[i], SHADER_DECAL );
}

View File

@ -113,7 +113,7 @@ typedef struct
model_t models[MAX_MODELS];
string_t edict_classnames[MAX_CLASSNAMES];
sound_t sound_precache[MAX_SOUNDS];
shader_t decal_shaders[MAX_DECALS];
shader_t decal_shaders[MAX_DECALNAMES];
} client_t;
extern client_t cl;

View File

@ -162,7 +162,7 @@ static const net_desc_t NWDesc[] =
#define CS_MODELS 32 // configstrings starts here
#define CS_SOUNDS (CS_MODELS+MAX_MODELS) // sound names
#define CS_DECALS (CS_SOUNDS+MAX_SOUNDS) // server decal indexes
#define CS_EVENTS (CS_DECALS+MAX_DECALS) // queue events
#define CS_EVENTS (CS_DECALS+MAX_DECALNAMES) // queue events
#define CS_GENERICS (CS_EVENTS+MAX_EVENTS) // edicts classnames
#define CS_CLASSNAMES (CS_GENERICS+MAX_GENERICS) // generic resources (e.g. color decals)
#define CS_LIGHTSTYLES (CS_CLASSNAMES+MAX_CLASSNAMES) // lightstyle patterns

View File

@ -61,7 +61,7 @@ int SV_SoundIndex( const char *name )
int SV_DecalIndex( const char *name )
{
return SV_FindIndex( name, CS_DECALS, MAX_DECALS, true );
return SV_FindIndex( name, CS_DECALS, MAX_DECALNAMES, true );
}
int SV_EventIndex( const char *name )

View File

@ -13,7 +13,8 @@
#define MAX_CLIENTS 32 // max allowed clients (modify with precaution)
#define MAX_DLIGHTS 32 // dynamic lights (rendered per one frame)
#define MAX_LIGHTSTYLES 256 // can't be blindly increased
#define MAX_DECALS 1024 // server decal indexes (different decalnames, not a render limit)
#define MAX_DECALS 4096 // max rendering decals per a level
#define MAX_DECALNAMES 1024 // server decal indexes (different decalnames, not a render limit)
#define MAX_USER_MESSAGES 200 // another 56 messages reserved for engine routines
#define MAX_EVENTS 1024 // playback events that can be queued (a byte range, don't touch)
#define MAX_GENERICS 1024 // generic files that can download from server

View File

@ -77,6 +77,7 @@
#define Vector4Set(v, a, b, c, d) ((v)[0]=(a),(v)[1]=(b),(v)[2]=(c),(v)[3] = (d))
#define VectorClear(x) ((x)[0]=(x)[1]=(x)[2]=0)
#define Vector4Clear(x) ((x)[0]=(x)[1]=(x)[2]=(x)[3]=0)
#define Vector2Lerp( v1, lerp, v2, c ) ((c)[0] = (v1)[0] + (lerp) * ((v2)[0] - (v1)[0]), (c)[1] = (v1)[1] + (lerp) * ((v2)[1] - (v1)[1]))
#define VectorLerp( v1, lerp, v2, c ) ((c)[0] = (v1)[0] + (lerp) * ((v2)[0] - (v1)[0]), (c)[1] = (v1)[1] + (lerp) * ((v2)[1] - (v1)[1]), (c)[2] = (v1)[2] + (lerp) * ((v2)[2] - (v1)[2]))
#define VectorNormalize( v ) { float ilength = (float)com.sqrt(DotProduct(v, v));if (ilength) ilength = 1.0f / ilength;v[0] *= ilength;v[1] *= ilength;v[2] *= ilength; }
#define VectorNormalize2( v, dest ) {float ilength = (float)com.sqrt(DotProduct(v,v));if (ilength) ilength = 1.0f / ilength;dest[0] = v[0] * ilength;dest[1] = v[1] * ilength;dest[2] = v[2] * ilength; }

View File

@ -165,6 +165,7 @@ typedef struct render_exp_s
// prepare frame to rendering
bool (*AddRefEntity)( edict_t *pRefEntity, int ed_type, shader_t customShader );
bool (*AddTmpEntity)( struct tempent_s *TempEnt, int ed_type, shader_t customShader );
bool (*DecalShoot)( shader_t decal, int ent, model_t mod, vec3_t pos, vec3_t saxis, int flags, rgba_t color );
bool (*AddDLight)( vec3_t pos, rgb_t color, float radius, int flags );
bool (*AddPolygon)( const poly_t *poly );
bool (*AddLightStyle)( int stylenum, vec3_t color );

View File

@ -2964,6 +2964,7 @@ static _inline void R_SetColorForOutlines( void )
pglColor4fv( colorBlue );
break;
case MB_POLY:
case MB_DECAL:
pglColor4fv( colorGreen );
break;
}

1015
vid_gl/r_decals.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -183,12 +183,12 @@ enum
typedef struct
{
vec3_t origin;
vec3_t color; // dlight color
float intensity; // cdlight->radius
vec3_t mins, maxs;
const ref_shader_t *shader;
int flags; // misc flags
vec3_t origin;
vec3_t color; // dlight color
float intensity; // cdlight->radius
vec3_t mins, maxs;
ref_shader_t *shader;
int flags; // misc flags
} ref_dlight_t;
typedef struct
@ -321,6 +321,9 @@ extern ref_entity_t r_entities[MAX_ENTITIES];
extern uint r_numDlights;
extern ref_dlight_t r_dlights[MAX_DLIGHTS];
extern uint r_numDecals;
extern decal_t *r_drawdecals[MAX_DECALS];
extern uint r_numPolys;
extern poly_t r_polys[MAX_POLYS];
@ -422,6 +425,7 @@ extern cvar_t *gl_texture_anisotropy;
extern cvar_t *gl_texture_lodbias;
extern cvar_t *gl_round_down;
extern cvar_t *gl_compress_textures;
extern cvar_t *r_decals;
extern cvar_t *r_mode;
extern cvar_t *r_nobind;
extern cvar_t *r_picmip;
@ -700,6 +704,15 @@ void R_ShutdownGLSLPrograms( void );
void R_ProgramList_f( void );
void R_ProgramDump_f( void );
//
// r_decals.c
//
bool R_DecalShoot( shader_t texture, int entity, model_t modelIndex, vec3_t pos, vec3_t saxis, int flags, rgba_t color );
void R_AddSurfaceDecals( msurface_t *surf );
void R_DrawSingleDecal( const meshbuffer_t *mb );
void R_AddDecalsToList( void );
//
// r_poly.c
//

View File

@ -1621,6 +1621,8 @@ void R_RenderView( const ref_params_t *fd )
R_AddPolysToList();
R_AddDecalsToList();
if( r_speeds->integer )
r_add_polys += ( Sys_DoubleTime() - starttime );
}
@ -1789,6 +1791,7 @@ void R_ClearScene( void )
{
r_numEntities = 1; // worldmodel
r_numDlights = 0;
r_numDecals = 0;
r_numPolys = 0;
RI.previousentity = NULL;
RI.currententity = r_worldent;
@ -2708,6 +2711,7 @@ render_exp_t DLLEXPORT *CreateAPI(stdlib_api_t *input, render_imp_t *engfuncs )
re.AddTmpEntity = R_AddTeEntToScene;
re.AddDLight = R_AddDynamicLight;
re.AddPolygon = R_AddPolyToScene;
re.DecalShoot = R_DecalShoot;
re.ClearScene = R_ClearScene;
re.BeginFrame = R_BeginFrame;

View File

@ -319,7 +319,7 @@ meshbuffer_t *R_AddMeshToList( int type, mfog_t *fog, ref_shader_t *shader, int
if( !shader ) return NULL;
if( RI.currententity && (shader->flags & SHADER_RENDERMODE))
if( RI.currententity && ( shader->flags & SHADER_RENDERMODE ))
{
switch( RI.currententity->rendermode )
{
@ -517,6 +517,9 @@ static void R_BatchMeshBuffer( const meshbuffer_t *mb, const meshbuffer_t *nextm
R_LoadIdentity();
R_RenderMeshBuffer( mb );
break;
case MB_DECAL:
R_DrawSingleDecal( mb );
break;
}
}

View File

@ -30,8 +30,9 @@ enum
MB_MODEL,
MB_SPRITE,
MB_POLY,
MB_DECAL,
MB_CORONA,
MB_MAXTYPES = 4
MB_MAXTYPES = 5
};
typedef struct mesh_s

View File

@ -58,6 +58,37 @@ typedef struct
cplane_t *planes;
} mfog_t;
typedef struct
{
vec4_t m_vPos;
vec2_t m_tCoords; // these are the texcoords for the decal itself
vec2_t m_LMCoords; // lightmap texcoords for the decal.
// FIXME: adds the lightmapnum here ?
} decalvert_t;
typedef struct decal_s
{
struct decal_s *pnext; // linked list for each surface
struct msurface_s *psurf; // surface id for persistence / unlinking
ref_shader_t *shader; // decal image
vec3_t position; // location of the decal center in world space.
vec3_t saxis; // direction of the s axis in world space
float dx; // Offsets into surface texture
float dy;
float scale; // pixel scale
short flags; // decal flags FDECAL_*
short entityIndex; // entity this is attached to
int m_Size; // size of decal, used for rejecting on dispinfo planes
// NOTE: The following variables are dynamic variables.
// We could put these into a separate array and reference them
// by index to reduce memory costs of this...
float fadeDuration; // Negative value means to fade in
float fadeStartTime;
rgba_t color;
} decal_t;
// miptex features (will be convert to a shader settings)
#define MIPTEX_CONVEYOR BIT( 0 ) // create conveyour surface
#define MIPTEX_LIQUID BIT( 1 ) // is a liquid
@ -80,7 +111,7 @@ typedef struct mtexinfo_s
short height;
} mtexinfo_t;
typedef struct
typedef struct msurface_s
{
int visframe; // should be drawn when node is crossed
int flags; // see SURF_ for details
@ -96,6 +127,7 @@ typedef struct
ref_shader_t *shader;
mesh_t *mesh;
mfog_t *fog;
decal_t *pdecals; // linked surface decals
cplane_t *plane;
union

View File

@ -96,6 +96,7 @@ cvar_t *r_bloom_fast_sample;
cvar_t *r_allow_software;
cvar_t *r_3dlabs_broken;
cvar_t *r_decals;
cvar_t *r_himodels;
cvar_t *r_lefthand;
cvar_t *r_physbdebug;
@ -566,6 +567,7 @@ void GL_InitCommands( void )
r_shadows_self_shadow = Cvar_Get( "r_shadows_self_shadow", "0", CVAR_ARCHIVE, "allow self-shadowing" );
r_himodels = Cvar_Get( "cl_himodels", "1", CVAR_ARCHIVE, "draw high-resolution player models in multiplayer" );
r_decals = Cvar_Get( "r_decals", "4096", CVAR_ARCHIVE, "sets the maximum number of decals" );
r_gamma = Cvar_Get( "vid_gamma", "1.0", CVAR_ARCHIVE, "gamma amount" );
r_colorbits = Cvar_Get( "r_colorbits", "0", CVAR_ARCHIVE | CVAR_LATCH_VIDEO, "pixelformat color bits (0 - auto)" );

View File

@ -155,6 +155,9 @@ static meshbuffer_t *R_AddSurfaceToList( msurface_t *surf, unsigned int clipflag
mb = R_AddMeshToList( MB_MODEL, surf->fog, shader, surf - r_worldbrushmodel->surfaces + 1 );
RI.surfmbuffers[surf - r_worldbrushmodel->surfaces] = mb;
// also add all surface decals
R_AddSurfaceDecals( surf );
return mb;
}

View File

@ -130,6 +130,10 @@ SOURCE=.\r_cull.c
# End Source File
# Begin Source File
SOURCE=.\r_decals.c
# End Source File
# Begin Source File
SOURCE=.\r_draw.c
# End Source File
# Begin Source File