Skip to content

Commit d825d6f

Browse files
committed
Sun stuff
- r_drawSun is now default 1 (was 0), because... - sunShader key - allows sky shaders to explicitly define a shader to use for the sun. In addition to that, a flare type number and a size multiplier number can follow for a little more customization. Partially inspired by RTCW's sunshader key, which only dealt with the image (and never finished their lens flare reflections) - Suns with a portal on screen won't cancel out the sun or its flare - If no sun flare is specified, don't draw a sun flare at all. should be one less unnecessary depth read - r_drawSun 2 is the old 'always show sun' behavior - sun shader now correctly orientated - drawing the sun uses a quadstamp - some 'low end video' alternative shader loading that current does not work. May revert - ifdefing out shademethod LOD for fixing later
1 parent 16ae6f4 commit d825d6f

File tree

7 files changed

+162
-71
lines changed

7 files changed

+162
-71
lines changed

code/renderer_oa/tr_bsp.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,6 +1878,9 @@ void RE_LoadWorldMap( const char *name ) {
18781878
tr.sunDirection[0] = 0.45f;
18791879
tr.sunDirection[1] = 0.3f;
18801880
tr.sunDirection[2] = 0.9f;
1881+
1882+
// leilei - deactivate sun and flare if it ain't there
1883+
tr.sunOn = 0; tr.sunFlare = 0; tr.sunShaderCustom = 0;
18811884

18821885
VectorNormalize( tr.sunDirection );
18831886

@@ -1929,6 +1932,12 @@ void RE_LoadWorldMap( const char *name ) {
19291932
R_LoadEntities( &header->lumps[LUMP_ENTITIES] );
19301933
R_LoadLightGrid( &header->lumps[LUMP_LIGHTGRID] );
19311934

1935+
// leilei - load our specific custom sun here
1936+
if (tr.sunShaderCustom)
1937+
tr.sunShader = R_FindShader( tr.sunShaderCustom, LIGHTMAP_NONE, qtrue );
1938+
else
1939+
tr.sunShader = R_FindShader( "sun", LIGHTMAP_NONE, qtrue );
1940+
19321941
s_worldData.dataSize = (byte *)ri.Hunk_Alloc(0, h_low) - startMarker;
19331942

19341943
// only set tr.world now that we know the entire level has loaded properly

code/renderer_oa/tr_flares.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,11 +1330,31 @@ void RB_DrawSunFlare( void )
13301330
return;
13311331
}
13321332

1333+
// leilei - don't draw the flare if we ain't got the sun
1334+
if ( !r_drawSun->integer ) {
1335+
return;
1336+
}
1337+
1338+
// don't draw the flare if we don't define the sun
1339+
if ( r_drawSun->integer == 1 && (!tr.sunOn) ) {
1340+
return;
1341+
}
1342+
13331343
if ( backEnd.doneSunFlare) // leilei - only do sun once
13341344
return;
13351345

1346+
if (backEnd.viewParms.isPortal) // leilei - do sun only not in the portal (keeps sun from disappearing when portal is onscreen)
1347+
return;
1348+
13361349
fetype = r_flareSun->integer;
13371350

1351+
// if we specified a flare type for sunshader in the sky, then we use it.
1352+
if (tr.sunOn && (r_drawSun->integer == 1)) {
1353+
fetype = tr.sunFlare;
1354+
}
1355+
// but, if we don't want the sunflare (type is 0 - either on the r_drawSun 2 override or the shader) then we just forget it
1356+
if (fetype == 0) return;
1357+
13381358
qglLoadMatrixf( backEnd.viewParms.world.modelMatrix );
13391359
qglTranslatef (backEnd.viewParms.or.origin[0], backEnd.viewParms.or.origin[1], backEnd.viewParms.or.origin[2]);
13401360

code/renderer_oa/tr_init.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@ cvar_t *r_suggestiveThemes; // leilei - mature content control
222222

223223
cvar_t *r_textureDither; // leilei - Dithered texture
224224

225+
cvar_t *r_lerpbias; // Leilei - lerping bias
226+
227+
cvar_t *r_lowEndVideo; // leilei - load .low shaders
225228
// leilei - fallback shader hack
226229

227230

@@ -1196,7 +1199,7 @@ void R_Register( void )
11961199
r_ignoreGLErrors = ri.Cvar_Get( "r_ignoreGLErrors", "1", CVAR_ARCHIVE );
11971200
r_fastsky = ri.Cvar_Get( "r_fastsky", "0", CVAR_ARCHIVE );
11981201
r_inGameVideo = ri.Cvar_Get( "r_inGameVideo", "1", CVAR_ARCHIVE );
1199-
r_drawSun = ri.Cvar_Get( "r_drawSun", "0", CVAR_ARCHIVE );
1202+
r_drawSun = ri.Cvar_Get( "r_drawSun", "1", CVAR_ARCHIVE ); // leilei - default 1 for allowing sky shaders to define a sun.
12001203
r_dynamiclight = ri.Cvar_Get( "r_dynamiclight", "1", CVAR_ARCHIVE );
12011204
r_dlightBacks = ri.Cvar_Get( "r_dlightBacks", "1", CVAR_ARCHIVE );
12021205
r_finish = ri.Cvar_Get ("r_finish", "0", CVAR_ARCHIVE);
@@ -1307,12 +1310,16 @@ void R_Register( void )
13071310
r_particles = ri.Cvar_Get( "r_particles", "0" , CVAR_ARCHIVE | CVAR_LATCH);
13081311
r_leidebugeye = ri.Cvar_Get( "r_leidebugeye", "0" , CVAR_CHEAT);
13091312

1313+
r_lerpbias = ri.Cvar_Get( "r_lerpbias", "-2" , CVAR_ARCHIVE);
1314+
13101315
r_iconmip = ri.Cvar_Get ("r_iconmip", "0", CVAR_ARCHIVE | CVAR_LATCH ); // leilei - icon mip
13111316
r_iconBits = ri.Cvar_Get ("r_iconBits", "0", CVAR_ARCHIVE | CVAR_LATCH ); // leilei - icon bits
13121317

13131318
r_lightmapBits = ri.Cvar_Get ("r_lightmapBits", "0", CVAR_ARCHIVE | CVAR_LATCH ); // leilei - lightmap color bits
13141319
r_lightmapColorNorm = ri.Cvar_Get ("r_lightmapColorNorm", "1", CVAR_ARCHIVE | CVAR_LATCH ); // leilei - lightmap color normalization
13151320

1321+
r_lowEndVideo = ri.Cvar_Get( "r_lowEndVideo", "0", CVAR_ARCHIVE | CVAR_LATCH );
1322+
13161323
r_textureDither = ri.Cvar_Get ("r_textureDither", "0", CVAR_ARCHIVE | CVAR_LATCH ); // leilei - dithered textures
13171324

13181325
// make sure all the commands added here are also

code/renderer_oa/tr_local.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,7 @@ typedef struct {
11521152
shader_t *flareShader;
11531153
shader_t *flareShaderAtlas; // leilei - lens reflections
11541154
shader_t *sunShader;
1155+
char *sunShaderCustom; // leilei - sunShader override
11551156

11561157
shader_t *coneShader; // leilei - flashblends
11571158

@@ -1193,6 +1194,8 @@ typedef struct {
11931194

11941195
vec3_t sunLight; // from the sky shader for this level
11951196
vec3_t sunDirection;
1197+
int sunFlare; // leilei - sun flare type
1198+
float sunOn; // leilei - allow the sun to be drawn, if a sunShader is specified by a sky shader. This is a float so we can multiply the size of the sun in the shader
11961199

11971200
frontEndCounters_t pc;
11981201
int frontEndMsec; // not in pc due to clearing issue
@@ -1255,7 +1258,7 @@ extern glstate_t glState; // outside of TR since it shouldn't be cleared during
12551258
extern qboolean vertexShaders;
12561259
extern qboolean postprocess;
12571260
extern int leifxmode; // leilei - leifx
1258-
extern char depthimage;
1261+
extern char depthimage;
12591262

12601263
//
12611264
// cvars
@@ -1396,6 +1399,8 @@ extern cvar_t *r_particles; // Leilei - particles!
13961399
extern cvar_t *r_iconmip; // leilei - icon mip - picmip for 2d icons
13971400
extern cvar_t *r_iconBits; // leilei - icon color depth for 2d icons
13981401

1402+
extern cvar_t *r_lerpbias; // Leilei - lerping bias
1403+
13991404
extern cvar_t *r_lightmapBits; // leilei - lightmap color depth
14001405
extern cvar_t *r_lightmapColorNorm; // leilei - lightmap color normalize
14011406

@@ -1406,6 +1411,8 @@ extern cvar_t *r_textureDither; // leilei - apply dithering for lower texture
14061411

14071412
extern cvar_t *r_skytess; // leilei - adjusts the subdivisions of the sky (max 8, min 1)
14081413

1414+
extern cvar_t *r_lowEndVideo; // leilei - load .low shaders
1415+
14091416
//====================================================================
14101417

14111418
void R_SwapBuffers( int );
@@ -1567,12 +1574,12 @@ typedef struct shaderCommands_s
15671574

15681575
shader_t *shader;
15691576
float shaderTime;
1570-
int fogNum;
1577+
int fogNum;
15711578

1572-
int dlightBits; // or together of all vertexDlightBits
1579+
int dlightBits; // or together of all vertexDlightBits
15731580

1574-
int numIndexes;
1575-
int numVertexes;
1581+
int numIndexes;
1582+
int numVertexes;
15761583

15771584
// info extracted from current shader
15781585
int numPasses;

code/renderer_oa/tr_shade_calc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,6 +1818,7 @@ void RB_CalcDiffuseColor( unsigned char *colors )
18181818
{
18191819
RB_CalcMaterials( colors, 0xFFFFFF, 0x808080, 0x808080, 0x000000, 128, 255 );
18201820
}
1821+
#if BROKEN // leilei: FIXME this does not work as intended
18211822
else if ((r_shadeMethod->integer > 150) && (r_shadeMethod->integer < 667)) // values in a certain range is an adaptive LOD selection of -1, 0 and 3
18221823
{
18231824
float projectedRadius, fsh, shadescale, radius;
@@ -1838,6 +1839,7 @@ void RB_CalcDiffuseColor( unsigned char *colors )
18381839
RB_CalcDiffuseColor_flat( colors );
18391840

18401841
}
1842+
#endif // BROKEN
18411843
else // standard idtech3 shading
18421844
{
18431845
RB_CalcDiffuseColor_scalar( colors );

code/renderer_oa/tr_shader.c

Lines changed: 85 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3604,6 +3604,38 @@ static qboolean ParseShader( char **text )
36043604
SkipRestOfLine( text );
36053605
continue;
36063606
}
3607+
3608+
// leilei - Parse a shader for the sun, and a type of flare for the number after it.
3609+
// Inspired by ET's sunShader (my own implementation)
3610+
else if ( !Q_stricmp( token, "sunShader" ) ) {
3611+
// load a sun shader to override our default shader
3612+
token = COM_ParseExt( text, qfalse );
3613+
3614+
tr.sunShaderCustom = CopyString(token); // leilei - copy the shader's name so we can load it properly elsewhere (doing it here would make a broken sun)
3615+
tr.sunOn = 1; // activate sun to be rendered for r_drawSun 1.
3616+
3617+
// the next one is the flare type.
3618+
token = COM_ParseExt( text, qfalse );
3619+
if ( !token[0] )
3620+
{
3621+
tr.sunFlare = 0; // dont flare if we dont specify
3622+
continue;
3623+
}
3624+
tr.sunFlare = atoi( token );
3625+
3626+
// the next one is a size multiplier.
3627+
token = COM_ParseExt( text, qfalse );
3628+
if ( !token[0] )
3629+
{
3630+
tr.sunOn = 1; // sun is always normal size if we don't specify
3631+
continue;
3632+
}
3633+
if (atof( token )>1)
3634+
tr.sunOn = atof( token );
3635+
3636+
continue;
3637+
}
3638+
36073639
// sun parms
36083640
else if ( !Q_stricmp( token, "q3map_sun" ) ) {
36093641
float a, b;
@@ -5346,18 +5378,41 @@ a single large text block that can be scanned for shader names
53465378
=====================
53475379
*/
53485380
#define MAX_SHADER_FILES 4096
5381+
5382+
static int Shader_AddFileToList( char *name, char *list[0x1000], int nfiles ) {
5383+
int i;
5384+
5385+
if ( nfiles == 0x1000 - 1 ) {
5386+
return nfiles;
5387+
}
5388+
for ( i = 0 ; i < nfiles ; i++ ) {
5389+
if ( !Q_stricmp( name, list[i] ) ) {
5390+
return nfiles; // allready in list
5391+
}
5392+
}
5393+
list[nfiles] = CopyString( name );
5394+
nfiles++;
5395+
5396+
return nfiles;
5397+
}
5398+
5399+
53495400
static void ScanAndLoadShaderFiles( void )
53505401
{
53515402
char **shaderFiles;
5403+
53525404
char *buffers[MAX_SHADER_FILES];
53535405
char *p;
53545406
int numShaderFiles;
5355-
int i;
5407+
int i, j;
53565408
char *oldp, *token, *hashMem, *textEnd;
53575409
int shaderTextHashTableSizes[MAX_SHADERTEXT_HASH], hash, size;
53585410
char shaderName[MAX_QPATH];
53595411
int shaderLine;
53605412

5413+
char **lowShaderFiles;
5414+
int numLowShaderFiles;
5415+
53615416
long sum = 0, summand;
53625417
// scan for shader files
53635418
shaderFiles = ri.FS_ListFiles( "scripts", ".shader", &numShaderFiles );
@@ -5368,10 +5423,6 @@ static void ScanAndLoadShaderFiles( void )
53685423
return;
53695424
}
53705425

5371-
if ( numShaderFiles > MAX_SHADER_FILES ) {
5372-
numShaderFiles = MAX_SHADER_FILES;
5373-
}
5374-
53755426
// load and parse shader files
53765427
for ( i = 0; i < numShaderFiles; i++ )
53775428
{
@@ -5383,7 +5434,7 @@ static void ScanAndLoadShaderFiles( void )
53835434

53845435
if ( !buffers[i] )
53855436
ri.Error( ERR_DROP, "Couldn't load %s", filename );
5386-
5437+
53875438
// Do a simple check on the shader structure in that file to make sure one bad shader file cannot fuck up all other shaders.
53885439
p = buffers[i];
53895440
COM_BeginParseSession(filename);
@@ -5427,8 +5478,35 @@ static void ScanAndLoadShaderFiles( void )
54275478
sum += summand;
54285479
}
54295480

5481+
// leilei - low end video
5482+
if (r_lowEndVideo->integer)
5483+
{
5484+
5485+
5486+
lowShaderFiles = ri.FS_ListFiles( "scripts", ".low", &numLowShaderFiles );
5487+
// shaderFiles += lowShaderFiles;
5488+
// numShaderFiles += numLowShaderFiles;
5489+
5490+
// leilei - append in low shader files
5491+
if (numLowShaderFiles)
5492+
for ( i = 0; i < numLowShaderFiles; i++ )
5493+
{
5494+
ri.Printf( PRINT_WARNING, "USING LOW END SHADER: %s\n", lowShaderFiles[i]);
5495+
// Shader_AddFileToList (lowShaderFiles[i], shaderFiles, numShaderFiles);
5496+
// shaderFiles[numShaderFiles+1] = lowShaderFiles[i];CopyString( lowShaderFiles[i] );
5497+
// numShaderFiles++;
5498+
// shaderFiles[numShaderFiles+1] = lowShaderFiles[i];
5499+
5500+
}
5501+
}
5502+
5503+
5504+
if ( numShaderFiles > MAX_SHADER_FILES ) {
5505+
numShaderFiles = MAX_SHADER_FILES;
5506+
}
5507+
54305508
// build single large buffer
5431-
s_shaderText = ri.Hunk_Alloc( sum + numShaderFiles*2, h_low );
5509+
s_shaderText = ri.Hunk_Alloc( sum + (numShaderFiles*2) + (numLowShaderFiles*2), h_low );
54325510
s_shaderText[ 0 ] = '\0';
54335511
textEnd = s_shaderText;
54345512

@@ -5576,9 +5654,6 @@ static void CreateExternalShaders( void ) {
55765654
}
55775655
}
55785656

5579-
5580-
tr.sunShader = R_FindShader( "sun", LIGHTMAP_NONE, qtrue );
5581-
55825657
// leilei - placeholder shaders
55835658
tr.placeholderTextureShader = R_FindShader( "placeholder_texture", LIGHTMAP_NONE, qtrue );
55845659
tr.placeholderModelShader = R_FindShader( "placeholder_model", LIGHTMAP_NONE, qtrue );

0 commit comments

Comments
 (0)