Skip to content

Commit d6c869c

Browse files
committed
- s_interrupt - allows sounds to be interrupted by the same sound or entity channel
- new dynamic light calculation for vertex lighting, affecting vertex color (no projected dlight textures) - rgbGen material for allowing calculation for diffuse, specular, emmissive vertex colors by hex values - rgbMod shader command allowing new vertex color effects - removed deprecated R_ParseStageSimple, it never worked as intended
1 parent 74046d7 commit d6c869c

10 files changed

Lines changed: 951 additions & 1129 deletions

File tree

code/client/snd_dma.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,30 @@ static void S_Base_StartSoundEx( vec3_t origin, int entityNum, int entchannel, s
576576
}
577577

578578
ch = s_channels;
579+
580+
581+
// leilei - check if this sound is already playing and kill it
582+
if (s_interrupts->integer == 1)
583+
{
584+
for ( i = 0; i < MAX_CHANNELS ; i++, ch++ ) {
585+
if (ch->entnum == entityNum && ch->thesfx == sfx)
586+
{
587+
S_ChannelFree(ch);
588+
}
589+
}
590+
}
591+
592+
// leilei - check if this channel is being used, and kill that too
593+
else if (s_interrupts->integer == 2)
594+
{
595+
for ( i = 0; i < MAX_CHANNELS ; i++, ch++ ) {
596+
if (ch->entnum == entityNum && ch->entchannel == entchannel && ch->thesfx && (entchannel != CHAN_AUTO))
597+
{
598+
S_ChannelFree(ch);
599+
}
600+
}
601+
}
602+
579603
inplay = 0;
580604
for ( i = 0; i < MAX_CHANNELS ; i++, ch++ ) {
581605
if (ch->entnum == entityNum && ch->thesfx == sfx) {

code/client/snd_local.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ extern cvar_t *s_musicVolume;
199199
extern cvar_t *s_muted;
200200
extern cvar_t *s_doppler;
201201

202+
extern cvar_t *s_interrupts;
203+
202204
extern cvar_t *s_testsound;
203205

204206
qboolean S_LoadSound( sfx_t *sfx );

code/client/snd_main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ cvar_t *s_backend;
3434
cvar_t *s_muteWhenMinimized;
3535
cvar_t *s_muteWhenUnfocused;
3636

37+
cvar_t *s_interrupts;
38+
3739
static soundInterface_t si;
3840

3941
/*
@@ -485,6 +487,7 @@ void S_Init( void )
485487
s_muted = Cvar_Get("s_muted", "0", CVAR_ROM);
486488
s_doppler = Cvar_Get( "s_doppler", "1", CVAR_ARCHIVE );
487489
s_backend = Cvar_Get( "s_backend", "", CVAR_ROM );
490+
s_interrupts = Cvar_Get( "s_interrupts", "0", CVAR_ARCHIVE ); // leilei - pre-1.25 sound behavior
488491
s_muteWhenMinimized = Cvar_Get( "s_muteWhenMinimized", "0", CVAR_ARCHIVE );
489492
s_muteWhenUnfocused = Cvar_Get( "s_muteWhenUnfocused", "0", CVAR_ARCHIVE );
490493

code/renderer_oa/tr_image.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,9 +1129,6 @@ static void Upload32( unsigned *data,
11291129
int forceBits = 0;
11301130

11311131

1132-
if (lightMap && r_parseStageSimple->integer) hackoperation = 4;
1133-
1134-
11351132
//
11361133
// convert to exact power of 2 sizes
11371134
//

code/renderer_oa/tr_init.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ cvar_t *r_flaresDlightScale;
208208
//cvar_t *r_flaresSurfradii;
209209
cvar_t *r_alternateBrightness; // leilei - linux overbright fix
210210
cvar_t *r_mockvr; // Leilei - for debugging PVR only!
211-
cvar_t *r_parseStageSimple; // Leilei - for debugging PVR only!
212211
cvar_t *r_leifx; // Leilei - leifx nostalgia filter
213212
cvar_t *r_modelshader; // Leilei
214213
cvar_t *r_particles; // Leilei - particle effects motif
@@ -1327,7 +1326,6 @@ void R_Register( void )
13271326

13281327

13291328
r_mockvr = ri.Cvar_Get( "r_mockvr", "0" , CVAR_CHEAT);
1330-
r_parseStageSimple = ri.Cvar_Get( "r_parseStageSimple", "0" , CVAR_CHEAT);
13311329
r_leifx = ri.Cvar_Get( "r_leifx", "0" , CVAR_ARCHIVE | CVAR_LATCH);
13321330
r_modelshader = ri.Cvar_Get( "r_modelshader", "0" , CVAR_ARCHIVE | CVAR_LATCH); // leilei - load and use special shaders for lightDiffuse models
13331331
r_detailTextureScale = ri.Cvar_Get( "r_detailtextureScale", "0", CVAR_ARCHIVE | CVAR_LATCH ); // leilei - adjust scale of detail textures

code/renderer_oa/tr_local.h

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ typedef enum {
187187
CGEN_FOG, // standard fog
188188
CGEN_CONST, // fixed color
189189
CGEN_VERTEX_LIT, // leilei - tess.vertexColors * tr.identityLight * ambientlight*directlight
190+
CGEN_MATERIAL, // leilei - material system
190191
CGEN_LIGHTING_DIFFUSE_SPECULAR // leilei - LIGHTING_DIFFUSE, capped by specular exponent
191192
} colorGen_t;
192193

@@ -265,6 +266,17 @@ typedef enum {
265266
TMOD_ENTITY_TRANSLATE
266267
} texMod_t;
267268

269+
// leilei - rgbMod - color modulations
270+
typedef enum {
271+
CMOD_BAD,
272+
CMOD_GLOW,
273+
CMOD_LIGHTING,
274+
CMOD_NORMALIZETOALPHA,
275+
CMOD_NORMALIZETOALPHAFAST,
276+
CMOD_UVCOL,
277+
CMOD_OPAQUE
278+
} colorMod_t;
279+
268280
#define MAX_SHADER_DEFORMS 3
269281
typedef struct {
270282
deform_t deformation; // vertex coordinate modification type
@@ -361,6 +373,17 @@ typedef struct {
361373
int imgWidth;
362374
int imgHeight; //leilei for glsl shaders
363375

376+
colorMod_t rgbMod; // leilei - rgbMod
377+
int rgbModCol;
378+
int rgbModMode;
379+
380+
int matAmb; // leilei - material ambience
381+
int matDif; // leilei - material diffuse
382+
int matSpec; // leilei - material specular
383+
int matEmis; // leilei - material emissive
384+
int matHard; // leilei - material specular hardness
385+
int matAlpha; // leilei - material alpha
386+
364387
} shaderStage_t;
365388

366389
struct shaderCommands_s;
@@ -1399,7 +1422,6 @@ extern cvar_t *r_flaresMotionBlur;
13991422
//extern cvar_t *r_flaresSurfradii;
14001423

14011424
extern cvar_t *r_alternateBrightness; // leilei - alternate brightness
1402-
extern cvar_t *r_parseStageSimple; // Leilei - handling textures into alphas
14031425
extern cvar_t *r_leifx; // Leilei - leifx nostalgia filter
14041426
extern cvar_t *r_modelshader; // Leilei - new model shading
14051427

@@ -2189,6 +2211,14 @@ void RB_CalcFlatAmbient( unsigned char *colors ); // leilei - cel hack
21892211
void RB_CalcFlatDirect( unsigned char *colors ); // leilei - cel hack
21902212
void RB_CalcNormal( unsigned char *colors ); // leilei - normal hack
21912213

2214+
void RB_CalcGlowBlend( unsigned char *colors, int glowcol, int fx ); // leilei - rgbMod
2215+
void RB_CalcUVColor( unsigned char *colors, int glowcol, int fx ); // leilei - rgbMod
2216+
void RB_CalcNormalizeToAlpha( unsigned char *colors); // leilei - rgbMod
2217+
2218+
void RB_CalcMaterials( unsigned char *colors, int ambient, int diffuse, int specular, int emissive, int spechard, int alpha ); // leilei - materials
2219+
2220+
void RB_CalcVertLights( unsigned char *colors ); // leilei - dynamic vertex lights
2221+
21922222
/*
21932223
=============================================================
21942224

code/renderer_oa/tr_scene.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ void RE_RenderScene( const refdef_t *fd ) {
361361
// turn off dynamic lighting globally by clearing all the
362362
// dlights if it needs to be disabled or if vertex lighting is enabled
363363
if ( r_dynamiclight->integer == 0 ||
364-
r_vertexLight->integer == 1 ||
364+
// r_vertexLight->integer == 1 || // leilei - commented this out, as we can now do dynamic lights with vertex light
365365
glConfig.hardwareType == GLHW_PERMEDIA2 ) {
366366
tr.refdef.num_dlights = 0;
367367
}

code/renderer_oa/tr_shade.c

Lines changed: 77 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,7 @@ static void ProjectDlightTexture( void ) {
807807
return;
808808
}
809809
#endif
810+
if ( !r_vertexLight->integer )
810811
ProjectDlightTexture_scalar();
811812
}
812813

@@ -944,35 +945,10 @@ static void ComputeColors( shaderStage_t *pStage )
944945
}
945946
}
946947
break;
947-
case CGEN_VERTEX_LIT: // leilei - mixing vertex colors with lighting through a glorious light hack
948-
{ // should only be used for entity models, not map assets!
949-
vec3_t dcolor, acolor; // to save the color from actual light
950-
vec3_t vcolor;
951-
int y;
952-
953-
954-
// Backup our colors
955-
VectorCopy( backEnd.currentEntity->ambientLight, acolor );
956-
VectorCopy( backEnd.currentEntity->directedLight, dcolor );
957-
VectorCopy( backEnd.currentEntity->e.shaderRGBA, vcolor );
958-
959-
// Make our vertex color take over
960-
961-
for(y=0;y<3;y++){
962-
backEnd.currentEntity->ambientLight[y] *= (vcolor[y] / 255);
963-
964-
if (backEnd.currentEntity->ambientLight[y] < 1) backEnd.currentEntity->ambientLight[y] = 1; // black!!!
965-
if (backEnd.currentEntity->ambientLight[y] > 255) backEnd.currentEntity->ambientLight[y] = 255; // white!!!!!
966-
// backEnd.currentEntity->ambientLight[y] *= (vcolor[y] / 255);
967-
// backEnd.currentEntity->directedLight[y] *= (vcolor[y] / 255);
968-
}
969-
970-
// run it through our favorite preferred lighting calculation functions
971-
RB_CalcDiffuseColor( ( unsigned char * ) tess.svars.colors );
972-
973-
// Restore light color for any other stage that doesn't do it
974-
VectorCopy( acolor, backEnd.currentEntity->ambientLight);
975-
VectorCopy( dcolor, backEnd.currentEntity->directedLight);
948+
case CGEN_VERTEX_LIT: // leilei - for world only
949+
{
950+
Com_Memcpy( tess.svars.colors, tess.vertexColors, tess.numVertexes * sizeof( tess.vertexColors[0] ) );
951+
RB_CalcVertLights( ( unsigned char * ) tess.svars.colors );
976952
}
977953
break;
978954
case CGEN_ONE_MINUS_VERTEX:
@@ -1031,42 +1007,14 @@ static void ComputeColors( shaderStage_t *pStage )
10311007
}
10321008
}
10331009
break;
1034-
}
1035-
1036-
// leilei PowerVR Hack
1037-
1038-
if (r_parseStageSimple->integer)
1039-
{
1040-
float scale;
1041-
vec3_t normme;
1042-
if ((pStage->isBlend == 1) || (pStage->isBlend == 3)){ // additive or subtracive
1043-
1044-
for(i = 0; i < tess.numVertexes; i++)
1045-
{
1046-
scale = LUMA(tess.svars.colors[i][0], tess.svars.colors[i][1], tess.svars.colors[i][2]);
1047-
tess.svars.colors[i][3] = scale - tess.svars.colors[i][3];
1048-
if (tess.svars.colors[i][3] > 255) tess.svars.colors[i][3] = 255;
1049-
1050-
1051-
normme[0] = tess.svars.colors[i][0];
1052-
normme[1] = tess.svars.colors[i][1];
1053-
normme[2] = tess.svars.colors[i][2];
1054-
1055-
// normme[0] *= (4 * tr.identityLight);
1056-
// normme[1] *= (4 * tr.identityLight);
1057-
// normme[2] *= (4 * tr.identityLight);
1058-
1059-
1060-
VectorNormalize(normme);
1061-
1062-
1063-
tess.svars.colors[i][0] = normme[0]*255;
1064-
tess.svars.colors[i][1] = normme[1]*255;
1065-
tess.svars.colors[i][2] = normme[2]*255;
1066-
}
1010+
case CGEN_MATERIAL:
1011+
if (r_shownormals->integer > 1 || (pStage->isLeiShade)){
1012+
RB_CalcNormal( ( unsigned char * ) tess.svars.colors ); // leilei - debug normals, or use the normals as a color for a lighting shader
1013+
break;
10671014
}
1068-
1069-
}
1015+
RB_CalcMaterials( ( unsigned char * ) tess.svars.colors, pStage->matAmb, pStage->matDif, pStage->matSpec, pStage->matEmis, pStage->matHard, pStage->matAlpha );
1016+
break;
1017+
}
10701018

10711019
//
10721020
// alphaGen
@@ -1153,6 +1101,34 @@ static void ComputeColors( shaderStage_t *pStage )
11531101
break;
11541102
}
11551103

1104+
//
1105+
// rgbMod
1106+
//
1107+
switch ( pStage->rgbMod )
1108+
{
1109+
case CMOD_GLOW:
1110+
RB_CalcGlowBlend( ( unsigned char * ) tess.svars.colors, pStage->rgbModCol, pStage->rgbModMode );
1111+
break;
1112+
case CMOD_UVCOL:
1113+
RB_CalcUVColor( ( unsigned char * ) tess.svars.colors, pStage->rgbModCol, pStage->rgbModMode );
1114+
break;
1115+
case CMOD_NORMALIZETOALPHA:
1116+
RB_CalcNormalizeToAlpha( ( unsigned char * ) tess.svars.colors );
1117+
break;
1118+
case CMOD_NORMALIZETOALPHAFAST: // TODO: use first vert
1119+
RB_CalcNormalizeToAlpha( ( unsigned char * ) tess.svars.colors );
1120+
break;
1121+
case CMOD_OPAQUE:
1122+
for ( i = 0; i < tess.numVertexes; i++ )
1123+
tess.svars.colors[i][3] = 0xff;
1124+
break;
1125+
case CMOD_LIGHTING:
1126+
// TODO
1127+
break;
1128+
case CMOD_BAD:
1129+
return;
1130+
}
1131+
11561132
//
11571133
// fog adjustment for colors to fade out as fog increases
11581134
//
@@ -1198,6 +1174,43 @@ static void ComputeColors( shaderStage_t *pStage )
11981174
}
11991175
}
12001176

1177+
1178+
/*
1179+
===============
1180+
ComputeUVColors
1181+
===============
1182+
*/
1183+
static void ComputeUVColors( shaderStage_t *pStage )
1184+
{
1185+
int i;
1186+
1187+
//
1188+
// rgbMod
1189+
//
1190+
switch ( pStage->rgbMod )
1191+
{
1192+
case CMOD_GLOW:
1193+
// we do this elsewhere
1194+
break;
1195+
case CMOD_UVCOL:
1196+
RB_CalcUVColor( ( unsigned char * ) tess.svars.colors, pStage->rgbModCol, pStage->rgbModMode );
1197+
break;
1198+
case CMOD_NORMALIZETOALPHA:
1199+
break;
1200+
case CMOD_NORMALIZETOALPHAFAST: // TODO: use first vert
1201+
break;
1202+
case CMOD_OPAQUE:
1203+
break;
1204+
case CMOD_LIGHTING:
1205+
break;
1206+
case CMOD_BAD:
1207+
return;
1208+
}
1209+
1210+
1211+
}
1212+
1213+
12011214
/*
12021215
===============
12031216
ComputeTexCoords

0 commit comments

Comments
 (0)