- Trace checks added to flares (HUGE speedup)

- Remove obsolete Quake2-era "gamma" code that shouldn't be there anymore since there's a modern way to gamma correct now
This commit is contained in:
leilei-
2016-06-22 01:19:36 -04:00
parent 6711f046d3
commit cf103f3cb0
2 changed files with 104 additions and 55 deletions

View File

@@ -22,6 +22,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
// tr_flares.c // tr_flares.c
#include "tr_local.h" #include "tr_local.h"
#include "../qcommon/cm_local.h"
/* /*
============================================================================= =============================================================================
@@ -348,6 +349,10 @@ FLARE BACK END
*/ */
void CM_Trace( trace_t *results, const vec3_t start, const vec3_t end, vec3_t mins, vec3_t maxs,
clipHandle_t model, const vec3_t origin, int brushmask, int capsule, sphere_t *sphere );
/* /*
================== ==================
RB_TestFlareFast RB_TestFlareFast
@@ -355,7 +360,7 @@ RB_TestFlareFast
faster simple one. faster simple one.
================== ==================
*/ */
static void RB_TestFlareFast( flare_t *f ) { static void RB_TestFlareFast( flare_t *f, int dotrace ) {
float depth; float depth;
qboolean visible; qboolean visible;
float fade; float fade;
@@ -367,8 +372,20 @@ static void RB_TestFlareFast( flare_t *f ) {
// doing a readpixels is as good as doing a glFinish(), so // doing a readpixels is as good as doing a glFinish(), so
// don't bother with another sync // don't bother with another sync
glState.finishCalled = qfalse; glState.finishCalled = qfalse;
if (f->type == 2) dotrace = 0; // sun cant trace
// leilei - do trace, then complain
if (dotrace){
trace_t yeah;
CM_Trace( &yeah, f->origin, backEnd.or.viewOrigin, NULL, NULL, NULL, f->origin, 1, NULL, NULL );
if (yeah.fraction < 1){
visible = 0;
return;
}
else
{
visible = 1;
}
}
// leilei - delay hack, to speed up the renderer // leilei - delay hack, to speed up the renderer
@@ -433,7 +450,7 @@ static void RB_TestFlareFast( flare_t *f ) {
RB_TestFlare RB_TestFlare
================== ==================
*/ */
static void RB_TestFlare( flare_t *f ) { static void RB_TestFlare( flare_t *f, int dotrace ) {
float depth; float depth;
qboolean visible; qboolean visible;
float fade; float fade;
@@ -445,6 +462,22 @@ static void RB_TestFlare( flare_t *f ) {
// doing a readpixels is as good as doing a glFinish(), so // doing a readpixels is as good as doing a glFinish(), so
// don't bother with another sync // don't bother with another sync
glState.finishCalled = qfalse; glState.finishCalled = qfalse;
if (f->type == 2) dotrace = 0; // sun cant trace
// leilei - do trace, then complain
if (dotrace){
trace_t yeah;
CM_Trace( &yeah, f->origin, backEnd.or.viewOrigin, NULL, NULL, NULL, f->origin, 1, NULL, NULL );
if (yeah.fraction < 1){
visible = 0;
return;
}
else
{
visible = 1;
}
}
// read back the z buffer contents // read back the z buffer contents
@@ -486,6 +519,59 @@ static void RB_TestFlare( flare_t *f ) {
} }
static void RB_TestFlareTraceOnly( flare_t *f ) {
float depth;
qboolean visible;
float fade;
float screenZ;
backEnd.pc.c_flareTests++;
// doing a readpixels is as good as doing a glFinish(), so
// don't bother with another sync
glState.finishCalled = qfalse;
// read from a traceline
trace_t yeah;
CM_Trace( &yeah, f->origin, backEnd.or.viewOrigin, NULL, NULL, NULL, f->origin, 1, NULL, NULL );
if (yeah.fraction < 1){
visible = 0;
return;
}
else
{
visible = 1;
}
if ( visible ) {
if ( !f->visible ) {
f->visible = qtrue;
f->fadeTime = backEnd.refdef.time - 1;
}
{
fade = ( ( backEnd.refdef.time - f->fadeTime ) / 1000.0f ) * r_flareFade->value;
}
} else {
if ( f->visible ) {
f->visible = qfalse;
f->fadeTime = backEnd.refdef.time - 1;
}
fade = 1.0f - ( ( backEnd.refdef.time - f->fadeTime ) / 1000.0f ) * r_flareFade->value;
}
if ( fade < 0 ) {
fade = 0;
}
if ( fade > 1 ) {
fade = 1;
}
f->drawIntensity = fade;
}
/* /*
@@ -1153,10 +1239,18 @@ void RB_RenderFlares (void) {
f->drawIntensity = 0; f->drawIntensity = 0;
if ( f->frameSceneNum == backEnd.viewParms.frameSceneNum if ( f->frameSceneNum == backEnd.viewParms.frameSceneNum
&& f->inPortal == backEnd.viewParms.isPortal ) { && f->inPortal == backEnd.viewParms.isPortal ) {
if (r_flareQuality->integer > 1) // leilei - flare quality test if (r_flareQuality->integer > 4) // highest flare quality - only frequent readpixels, no trace
RB_TestFlare( f ); RB_TestFlare( f, 0 );
else if (r_flareQuality->integer == 4) // highest flare quality - frequent readpixels, trace
RB_TestFlare( f, 1 );
else if (r_flareQuality->integer == 3) // highest flare quality - delayed readpixels, no trace
RB_TestFlareFast( f, 0 );
else if (r_flareQuality->integer == 2) // highest flare quality - delayed readpixels, trace
RB_TestFlareFast( f, 1 );
else if (r_flareQuality->integer == 1) // highest flare quality - no readpixels, trace
RB_TestFlareTraceOnly( f );
else else
RB_TestFlareFast( f ); RB_TestFlareFast( f, 1 );
if ( f->drawIntensity ) { if ( f->drawIntensity ) {
draw = qtrue; draw = qtrue;

View File

@@ -806,52 +806,7 @@ lighting range
*/ */
void R_LightScaleTexture (unsigned *in, int inwidth, int inheight, qboolean only_gamma ) void R_LightScaleTexture (unsigned *in, int inwidth, int inheight, qboolean only_gamma )
{ {
if ( only_gamma ) return; // leilei - quake2 "gamma" code is obsolete here. breaks shaders
{
if ( !glConfig.deviceSupportsGamma )
{
int i, c;
byte *p;
p = (byte *)in;
c = inwidth*inheight;
for (i=0 ; i<c ; i++, p+=4)
{
p[0] = s_gammatable[p[0]];
p[1] = s_gammatable[p[1]];
p[2] = s_gammatable[p[2]];
}
}
}
else
{
int i, c;
byte *p;
p = (byte *)in;
c = inwidth*inheight;
if ( glConfig.deviceSupportsGamma )
{
for (i=0 ; i<c ; i++, p+=4)
{
p[0] = s_intensitytable[p[0]];
p[1] = s_intensitytable[p[1]];
p[2] = s_intensitytable[p[2]];
}
}
else
{
for (i=0 ; i<c ; i++, p+=4)
{
p[0] = s_gammatable[s_intensitytable[p[0]]];
p[1] = s_gammatable[s_intensitytable[p[1]]];
p[2] = s_gammatable[s_intensitytable[p[2]]];
}
}
}
} }
@@ -1818,7 +1773,7 @@ static void Upload32( unsigned *data,
Com_Memcpy( scaledBuffer, data, width * height * 4 ); Com_Memcpy( scaledBuffer, data, width * height * 4 );
} }
R_LightScaleTexture (scaledBuffer, scaled_width, scaled_height, !mipmap ); //R_LightScaleTexture (scaledBuffer, scaled_width, scaled_height, !mipmap );
*pUploadWidth = scaled_width; *pUploadWidth = scaled_width;
*pUploadHeight = scaled_height; *pUploadHeight = scaled_height;
@@ -2930,7 +2885,7 @@ void R_SetColorMappings( void ) {
} }
for (i=0 ; i<256 ; i++) { for (i=0 ; i<256 ; i++) {
j = i * r_intensity->value; j = i * 1; // leilei - disable this because it breaks everything.
if (j > 255) { if (j > 255) {
j = 255; j = 255;
} }