Cleaned up the bloom code a little, fixed bloom so view2/splitscreen doesn't cause the main view to get a double dose, by pulling the pixel offsets from outside rather than recalculating them (thus no longer wrongly assuming a full screen). Made the code slightly more readable - no more ugly braces!

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@2930 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2008-02-21 03:19:46 +00:00
parent 9060465c0e
commit b134fd9e65
2 changed files with 261 additions and 243 deletions

View file

@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
// r_bloom.c: 2D lighting post process effect // gl_bloom.c: 2D lighting post process effect
//http://www.quakesrc.org/forums/viewtopic.php?t=4340&start=0 //http://www.quakesrc.org/forums/viewtopic.php?t=4340&start=0
@ -27,7 +27,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifdef RGLQUAKE #ifdef RGLQUAKE
#include "glquake.h" #include "glquake.h"
extern vrect_t scr_vrect; extern vrect_t gl_truescreenrect;
/* /*
============================================================================== ==============================================================================
@ -61,54 +61,60 @@ static float Diamond4x[4][4] = {
{0.4f, 0.9f, 0.9f, 0.4f}, {0.4f, 0.9f, 0.9f, 0.4f},
{0.3f, 0.4f, 0.4f, 0.3f} }; {0.3f, 0.4f, 0.4f, 0.3f} };
cvar_t r_bloom = FCVAR("r_bloom", "gl_bloom", "0", CVAR_ARCHIVE);
static cvar_t r_bloom_alpha = SCVAR("r_bloom_alpha", "0.5");
static cvar_t r_bloom_diamond_size = SCVAR("r_bloom_diamond_size", "8");
static cvar_t r_bloom_intensity = SCVAR("r_bloom_intensity", "1");
static cvar_t r_bloom_darken = SCVAR("r_bloom_darken", "3");
static cvar_t r_bloom_sample_size = SCVARF("r_bloom_sample_size", "256", CVAR_RENDERERLATCH);
static cvar_t r_bloom_fast_sample = SCVARF("r_bloom_fast_sample", "0", CVAR_RENDERERLATCH);
static int BLOOM_SIZE; typedef struct {
//texture numbers
int tx_screen;
int tx_effect;
int tx_backup;
int tx_downsample;
cvar_t r_bloom = FCVAR("r_bloom", "gl_bloom", "0", CVAR_ARCHIVE); //the viewport dimensions
cvar_t r_bloom_alpha = SCVAR("r_bloom_alpha", "0.5"); int vp_x;
cvar_t r_bloom_diamond_size = SCVAR("r_bloom_diamond_size", "8"); int vp_y;
cvar_t r_bloom_intensity = SCVAR("r_bloom_intensity", "1"); int vp_w;
cvar_t r_bloom_darken = SCVAR("r_bloom_darken", "3"); int vp_h;
cvar_t r_bloom_sample_size = SCVARF("r_bloom_sample_size", "256", CVAR_RENDERERLATCH);
cvar_t r_bloom_fast_sample = SCVARF("r_bloom_fast_sample", "0", CVAR_RENDERERLATCH);
int r_bloomscreentexture; //texture coordinates of screen data inside screentexture
int r_bloomeffecttexture; float scr_s;
int r_bloombackuptexture; float scr_t;
int r_bloomdownsamplingtexture;
static int r_screendownsamplingtexture_size; //dimensions of the screen texture (power of two)
static int screen_texture_width, screen_texture_height; int scr_w;
static int r_screenbackuptexture_size; int scr_h;
//current refdef size: //downsampled dimensions (will always be smaller than viewport)
static int curView_x; int smp_w;
static int curView_y; int smp_h;
static int curView_width; //tex coords to be used for the sample
static int curView_height; float smp_s;
float smp_t;
//texture coordinates of screen data inside screentexture int size_downsample;
static float screenText_tcw; int size_backup;
static float screenText_tch; int size_sample;
} bloomstate_t;
static int sample_width; static bloomstate_t bs;
static int sample_height;
//texture coordinates of adjusted textures
static float sampleText_tcw;
static float sampleText_tch;
//this macro is in sample size workspace coordinates //this macro is in sample size workspace coordinates
#define R_Bloom_SamplePass( xpos, ypos ) \ #define R_Bloom_SamplePass( xpos, ypos ) \
qglBegin(GL_QUADS); \ qglBegin(GL_QUADS); \
qglTexCoord2f( 0, sampleText_tch); \ qglTexCoord2f( 0, bs.smp_t); \
qglVertex2f( xpos, ypos); \ qglVertex2f( xpos, ypos); \
qglTexCoord2f( 0, 0); \ qglTexCoord2f( 0, 0); \
qglVertex2f( xpos, ypos+sample_height); \ qglVertex2f( xpos, ypos+bs.smp_h); \
qglTexCoord2f( sampleText_tcw, 0); \ qglTexCoord2f( bs.smp_s, 0); \
qglVertex2f( xpos+sample_width, ypos+sample_height); \ qglVertex2f( xpos+bs.smp_w, ypos+bs.smp_h); \
qglTexCoord2f( sampleText_tcw, sampleText_tch); \ qglTexCoord2f( bs.smp_s, bs.smp_t); \
qglVertex2f( xpos+sample_width, ypos); \ qglVertex2f( xpos+bs.smp_w, ypos); \
qglEnd(); qglEnd();
#define R_Bloom_Quad( x, y, width, height, textwidth, textheight ) \ #define R_Bloom_Quad( x, y, width, height, textwidth, textheight ) \
@ -130,17 +136,16 @@ static float sampleText_tch;
R_Bloom_InitBackUpTexture R_Bloom_InitBackUpTexture
================= =================
*/ */
void R_Bloom_InitBackUpTexture( int width, int height ) void R_Bloom_InitBackUpTexture(int widthheight)
{ {
qbyte *data; qbyte *data;
data = Z_Malloc( width * height * 4 ); data = Z_Malloc(widthheight * widthheight * 4);
r_screenbackuptexture_size = width; bs.size_backup = widthheight;
bs.tx_backup = GL_LoadTexture32("***bs.tx_backup***", bs.size_backup, bs.size_backup, (unsigned int*)data, false, false);
r_bloombackuptexture = GL_LoadTexture32("***r_bloombackuptexture***", width, height, (unsigned int*)data, false, false );
Z_Free ( data ); Z_Free (data);
} }
/* /*
@ -148,38 +153,38 @@ void R_Bloom_InitBackUpTexture( int width, int height )
R_Bloom_InitEffectTexture R_Bloom_InitEffectTexture
================= =================
*/ */
void R_Bloom_InitEffectTexture( void ) void R_Bloom_InitEffectTexture(void)
{ {
qbyte *data; qbyte *data;
float bloomsizecheck; float bloomsizecheck;
if( r_bloom_sample_size.value < 32 ) if (r_bloom_sample_size.value < 32)
Cvar_SetValue (&r_bloom_sample_size, 32); Cvar_SetValue (&r_bloom_sample_size, 32);
//make sure bloom size is a power of 2 //make sure bloom size is a power of 2
BLOOM_SIZE = r_bloom_sample_size.value; bs.size_sample = r_bloom_sample_size.value;
bloomsizecheck = (float)BLOOM_SIZE; bloomsizecheck = (float)bs.size_sample;
while(bloomsizecheck > 1.0f) bloomsizecheck /= 2.0f; while (bloomsizecheck > 1.0f) bloomsizecheck /= 2.0f;
if( bloomsizecheck != 1.0f ) if (bloomsizecheck != 1.0f)
{ {
BLOOM_SIZE = 32; bs.size_sample = 32;
while( BLOOM_SIZE < r_bloom_sample_size.value ) while (bs.size_sample < r_bloom_sample_size.value)
BLOOM_SIZE *= 2; bs.size_sample *= 2;
} }
//make sure bloom size doesn't have stupid values //make sure bloom size doesn't have stupid values
if( BLOOM_SIZE > screen_texture_width || if (bs.size_sample > bs.scr_w ||
BLOOM_SIZE > screen_texture_height ) bs.size_sample > bs.scr_h)
BLOOM_SIZE = min( screen_texture_width, screen_texture_height ); bs.size_sample = min(bs.scr_w, bs.scr_h);
if( BLOOM_SIZE != r_bloom_sample_size.value ) if (bs.size_sample != r_bloom_sample_size.value)
Cvar_SetValue (&r_bloom_sample_size, BLOOM_SIZE); Cvar_SetValue (&r_bloom_sample_size, bs.size_sample);
data = Z_Malloc( BLOOM_SIZE * BLOOM_SIZE * 4 ); data = Z_Malloc(bs.size_sample * bs.size_sample * 4);
r_bloomeffecttexture = GL_LoadTexture32("***r_bloomeffecttexture***", BLOOM_SIZE, BLOOM_SIZE, (unsigned int*)data, false, false ); bs.tx_effect = GL_LoadTexture32("***bs.tx_effect***", bs.size_sample, bs.size_sample, (unsigned int*)data, false, false);
Z_Free ( data ); Z_Free (data);
} }
/* /*
@ -187,58 +192,59 @@ void R_Bloom_InitEffectTexture( void )
R_Bloom_InitTextures R_Bloom_InitTextures
================= =================
*/ */
void R_Bloom_InitTextures( void ) void R_Bloom_InitTextures(void)
{ {
qbyte *data; qbyte *data;
int size; int size;
int maxtexsize; int maxtexsize;
//find closer power of 2 to screen size //find closer power of 2 to screen size
for (screen_texture_width = 1;screen_texture_width < glwidth;screen_texture_width *= 2); for (bs.scr_w = 1;bs.scr_w < glwidth;bs.scr_w *= 2);
for (screen_texture_height = 1;screen_texture_height < glheight;screen_texture_height *= 2); for (bs.scr_h = 1;bs.scr_h < glheight;bs.scr_h *= 2);
//disable blooms if we can't handle a texture of that size //disable blooms if we can't handle a texture of that size
qglGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxtexsize); qglGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxtexsize);
if( screen_texture_width > maxtexsize || if (bs.scr_w > maxtexsize ||
screen_texture_height > maxtexsize ) { bs.scr_h > maxtexsize)
screen_texture_width = screen_texture_height = 0; {
bs.scr_w = bs.scr_h = 0;
Cvar_SetValue (&r_bloom, 0); Cvar_SetValue (&r_bloom, 0);
Con_Printf( "WARNING: 'R_InitBloomScreenTexture' too high resolution for Light Bloom. Effect disabled\n" ); Con_Printf("WARNING: 'R_InitBloomScreenTexture' too high resolution for Light Bloom. Effect disabled\n");
return; return;
} }
//init the screen texture //init the screen texture
size = screen_texture_width * screen_texture_height * 4; size = bs.scr_w * bs.scr_h * 4;
data = Z_Malloc( size ); data = Z_Malloc(size);
memset( data, 255, size ); memset(data, 255, size);
if (!r_bloomscreentexture) if (!bs.tx_screen)
r_bloomscreentexture = texture_extension_number++; bs.tx_screen = texture_extension_number++;
GL_Bind(r_bloomscreentexture); GL_Bind(bs.tx_screen);
qglTexImage2D (GL_TEXTURE_2D, 0, gl_solid_format, screen_texture_width, screen_texture_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); qglTexImage2D (GL_TEXTURE_2D, 0, gl_solid_format, bs.scr_w, bs.scr_h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
Z_Free ( data ); Z_Free (data);
//validate bloom size and init the bloom effect texture //validate bloom size and init the bloom effect texture
R_Bloom_InitEffectTexture (); R_Bloom_InitEffectTexture ();
//if screensize is more than 2x the bloom effect texture, set up for stepped downsampling //if screensize is more than 2x the bloom effect texture, set up for stepped downsampling
r_bloomdownsamplingtexture = 0; bs.tx_downsample = 0;
r_screendownsamplingtexture_size = 0; bs.size_downsample = 0;
if( glwidth > (BLOOM_SIZE * 2) && !r_bloom_fast_sample.value ) if (glwidth > (bs.size_sample * 2) && !r_bloom_fast_sample.value)
{ {
r_screendownsamplingtexture_size = (int)(BLOOM_SIZE * 2); bs.size_downsample = (int)(bs.size_sample * 2);
data = Z_Malloc( r_screendownsamplingtexture_size * r_screendownsamplingtexture_size * 4 ); data = Z_Malloc(bs.size_downsample * bs.size_downsample * 4);
r_bloomdownsamplingtexture = GL_LoadTexture32("***r_bloomdownsamplingtexture***", r_screendownsamplingtexture_size, r_screendownsamplingtexture_size, (unsigned int*)data, false, false ); bs.tx_downsample = GL_LoadTexture32("***bs.tx_downsample***", bs.size_downsample, bs.size_downsample, (unsigned int*)data, false, false);
Z_Free ( data ); Z_Free (data);
} }
//Init the screen backup texture //Init the screen backup texture
if( r_screendownsamplingtexture_size ) if (bs.size_downsample)
R_Bloom_InitBackUpTexture( r_screendownsamplingtexture_size, r_screendownsamplingtexture_size ); R_Bloom_InitBackUpTexture(bs.size_downsample);
else else
R_Bloom_InitBackUpTexture( BLOOM_SIZE, BLOOM_SIZE ); R_Bloom_InitBackUpTexture(bs.size_sample);
} }
void R_BloomRegister(void) void R_BloomRegister(void)
@ -257,13 +263,13 @@ void R_BloomRegister(void)
R_InitBloomTextures R_InitBloomTextures
================= =================
*/ */
void R_InitBloomTextures( void ) void R_InitBloomTextures(void)
{ {
BLOOM_SIZE = 0; bs.size_sample = 0;
if( !r_bloom.value ) if (!r_bloom.value)
return; return;
r_bloomscreentexture = 0; //this came from a vid_restart, where none of the textures are valid any more. bs.tx_screen = 0; //this came from a vid_restart, where none of the textures are valid any more.
R_Bloom_InitTextures (); R_Bloom_InitTextures ();
} }
@ -273,22 +279,22 @@ void R_InitBloomTextures( void )
R_Bloom_DrawEffect R_Bloom_DrawEffect
================= =================
*/ */
void R_Bloom_DrawEffect( void ) void R_Bloom_DrawEffect(void)
{ {
GL_Bind(r_bloomeffecttexture); GL_Bind(bs.tx_effect);
qglEnable(GL_BLEND); qglEnable(GL_BLEND);
qglBlendFunc(GL_ONE, GL_ONE); qglBlendFunc(GL_ONE, GL_ONE);
qglColor4f(r_bloom_alpha.value, r_bloom_alpha.value, r_bloom_alpha.value, 1.0f); qglColor4f(r_bloom_alpha.value, r_bloom_alpha.value, r_bloom_alpha.value, 1.0f);
GL_TexEnv(GL_MODULATE); GL_TexEnv(GL_MODULATE);
qglBegin(GL_QUADS); qglBegin(GL_QUADS);
qglTexCoord2f( 0, sampleText_tch ); qglTexCoord2f (0, bs.smp_t);
qglVertex2f( curView_x, curView_y ); qglVertex2f (bs.vp_x, bs.vp_y);
qglTexCoord2f( 0, 0 ); qglTexCoord2f (0, 0);
qglVertex2f( curView_x, curView_y + curView_height ); qglVertex2f (bs.vp_x, bs.vp_y + bs.vp_h);
qglTexCoord2f( sampleText_tcw, 0 ); qglTexCoord2f (bs.smp_s, 0);
qglVertex2f( curView_x + curView_width, curView_y + curView_height ); qglVertex2f (bs.vp_x + bs.vp_w, bs.vp_y + bs.vp_h);
qglTexCoord2f( sampleText_tcw, sampleText_tch ); qglTexCoord2f (bs.smp_s, bs.smp_t);
qglVertex2f( curView_x + curView_width, curView_y ); qglVertex2f (bs.vp_x + bs.vp_w, bs.vp_y);
qglEnd(); qglEnd();
qglDisable(GL_BLEND); qglDisable(GL_BLEND);
@ -301,7 +307,7 @@ void R_Bloom_DrawEffect( void )
R_Bloom_GeneratexCross - alternative bluring method R_Bloom_GeneratexCross - alternative bluring method
================= =================
*/ */
void R_Bloom_GeneratexCross( void ) void R_Bloom_GeneratexCross(void)
{ {
int i; int i;
static int BLOOM_BLUR_RADIUS = 8; static int BLOOM_BLUR_RADIUS = 8;
@ -311,16 +317,16 @@ void R_Bloom_GeneratexCross( void )
static float range; static float range;
//set up sample size workspace //set up sample size workspace
qglViewport( 0, 0, sample_width, sample_height ); qglViewport( 0, 0, bs.smp_w, bs.smp_h );
qglMatrixMode( GL_PROJECTION ); qglMatrixMode( GL_PROJECTION );
qglLoadIdentity (); qglLoadIdentity ();
qglOrtho(0, sample_width, sample_height, 0, -10, 100); qglOrtho(0, bs.smp_w, bs.smp_h, 0, -10, 100);
qglMatrixMode( GL_MODELVIEW ); qglMatrixMode( GL_MODELVIEW );
qglLoadIdentity (); qglLoadIdentity ();
//copy small scene into r_bloomeffecttexture //copy small scene into bs.tx_effect
GL_Bind(0, r_bloomeffecttexture); GL_Bind(0, bs.tx_effect);
qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, sample_width, sample_height); qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, bs.smp_w, bs.smp_h);
//start modifying the small scene corner //start modifying the small scene corner
qglColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); qglColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
@ -335,7 +341,7 @@ void R_Bloom_GeneratexCross( void )
for(i=0; i<r_bloom_darken->integer ;i++) { for(i=0; i<r_bloom_darken->integer ;i++) {
R_Bloom_SamplePass( 0, 0 ); R_Bloom_SamplePass( 0, 0 );
} }
qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, sample_width, sample_height); qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, bs.smp_w, bs.smp_h);
} }
//bluring passes //bluring passes
@ -352,7 +358,7 @@ void R_Bloom_GeneratexCross( void )
R_Bloom_SamplePass( -1, 1 ); R_Bloom_SamplePass( -1, 1 );
R_Bloom_SamplePass( -1, -1 ); R_Bloom_SamplePass( -1, -1 );
R_Bloom_SamplePass( 1, -1 ); R_Bloom_SamplePass( 1, -1 );
qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, sample_width, sample_height); qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, bs.smp_w, bs.smp_h);
for(i=-(BLOOM_BLUR_RADIUS+1);i<BLOOM_BLUR_RADIUS;i++) { for(i=-(BLOOM_BLUR_RADIUS+1);i<BLOOM_BLUR_RADIUS;i++) {
intensity = BLOOM_BLUR_INTENSITY/(range*2+1)*(1 - fabs(i*i)/(float)(range*range)); intensity = BLOOM_BLUR_INTENSITY/(range*2+1)*(1 - fabs(i*i)/(float)(range*range));
@ -362,7 +368,7 @@ void R_Bloom_GeneratexCross( void )
//R_Bloom_SamplePass( -i, 0 ); //R_Bloom_SamplePass( -i, 0 );
} }
qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, sample_width, sample_height); qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, bs.smp_w, bs.smp_h);
//for(i=0;i<BLOOM_BLUR_RADIUS;i++) { //for(i=0;i<BLOOM_BLUR_RADIUS;i++) {
for(i=-(BLOOM_BLUR_RADIUS+1);i<BLOOM_BLUR_RADIUS;i++) { for(i=-(BLOOM_BLUR_RADIUS+1);i<BLOOM_BLUR_RADIUS;i++) {
@ -373,7 +379,7 @@ void R_Bloom_GeneratexCross( void )
//R_Bloom_SamplePass( 0, -i ); //R_Bloom_SamplePass( 0, -i );
} }
qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, sample_width, sample_height); qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, bs.smp_w, bs.smp_h);
} }
//restore full screen workspace //restore full screen workspace
@ -392,89 +398,104 @@ void R_Bloom_GeneratexCross( void )
R_Bloom_GeneratexDiamonds R_Bloom_GeneratexDiamonds
================= =================
*/ */
void R_Bloom_GeneratexDiamonds( void ) void R_Bloom_GeneratexDiamonds(void)
{ {
int i, j; int i, j;
static float intensity; float intensity;
//set up sample size workspace //set up sample size workspace
qglViewport( 0, 0, sample_width, sample_height ); qglViewport(0, 0, bs.smp_w, bs.smp_h);
qglMatrixMode( GL_PROJECTION ); qglMatrixMode(GL_PROJECTION);
qglLoadIdentity (); qglLoadIdentity();
qglOrtho(0, sample_width, sample_height, 0, -10, 100); qglOrtho(0, bs.smp_w, bs.smp_h, 0, -10, 100);
qglMatrixMode( GL_MODELVIEW ); qglMatrixMode(GL_MODELVIEW);
qglLoadIdentity (); qglLoadIdentity();
//copy small scene into r_bloomeffecttexture //copy small scene into bs.tx_effect
GL_Bind(r_bloomeffecttexture); GL_Bind(bs.tx_effect);
qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, sample_width, sample_height); qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, bs.smp_w, bs.smp_h);
//start modifying the small scene corner //start modifying the small scene corner
qglColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); qglColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
qglEnable(GL_BLEND); qglEnable(GL_BLEND);
//darkening passes //darkening passes
if( r_bloom_darken.value ) if (r_bloom_darken.value)
{ {
qglBlendFunc(GL_DST_COLOR, GL_ZERO); qglBlendFunc(GL_DST_COLOR, GL_ZERO);
GL_TexEnv(GL_MODULATE); GL_TexEnv(GL_MODULATE);
for(i=0; i<r_bloom_darken.value ;i++) { for (i=0; i<r_bloom_darken.value ;i++)
R_Bloom_SamplePass( 0, 0 ); {
R_Bloom_SamplePass(0, 0);
} }
qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, sample_width, sample_height); qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, bs.smp_w, bs.smp_h);
} }
//bluring passes //bluring passes
//qglBlendFunc(GL_ONE, GL_ONE); //qglBlendFunc(GL_ONE, GL_ONE);
qglBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR); qglBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR);
if( r_bloom_diamond_size.value > 7 || r_bloom_diamond_size.value <= 3) if (r_bloom_diamond_size.value > 7 || r_bloom_diamond_size.value <= 3)
{ {
if( r_bloom_diamond_size.value != 8 ) Cvar_SetValue( &r_bloom_diamond_size, 8 ); if (r_bloom_diamond_size.value != 8)
Cvar_SetValue(&r_bloom_diamond_size, 8);
for(i=0; i<r_bloom_diamond_size.value; i++) { for (i=0; i<r_bloom_diamond_size.value; i++)
for(j=0; j<r_bloom_diamond_size.value; j++) { {
for (j=0; j<r_bloom_diamond_size.value; j++)
{
intensity = r_bloom_intensity.value * 0.3 * Diamond8x[i][j]; intensity = r_bloom_intensity.value * 0.3 * Diamond8x[i][j];
if( intensity < 0.01f ) continue; if (intensity < 0.01f)
qglColor4f( intensity, intensity, intensity, 1.0); continue;
R_Bloom_SamplePass( i-4, j-4 ); qglColor4f(intensity, intensity, intensity, 1.0);
R_Bloom_SamplePass(i-4, j-4);
} }
} }
} else if( r_bloom_diamond_size.value > 5 ) { }
else if (r_bloom_diamond_size.value > 5)
if( r_bloom_diamond_size.value != 6 ) Cvar_SetValue(&r_bloom_diamond_size, 6 ); {
if (r_bloom_diamond_size.value != 6)
Cvar_SetValue(&r_bloom_diamond_size, 6);
for(i=0; i<r_bloom_diamond_size.value; i++) { for(i=0; i<r_bloom_diamond_size.value; i++)
for(j=0; j<r_bloom_diamond_size.value; j++) { {
for(j=0; j<r_bloom_diamond_size.value; j++)
{
intensity = r_bloom_intensity.value * 0.5 * Diamond6x[i][j]; intensity = r_bloom_intensity.value * 0.5 * Diamond6x[i][j];
if( intensity < 0.01f ) continue; if (intensity < 0.01f)
qglColor4f( intensity, intensity, intensity, 1.0); continue;
R_Bloom_SamplePass( i-3, j-3 ); qglColor4f(intensity, intensity, intensity, 1.0);
R_Bloom_SamplePass(i-3, j-3);
} }
} }
} else if( r_bloom_diamond_size.value > 3 ) { }
else if (r_bloom_diamond_size.value > 3)
{
if (r_bloom_diamond_size.value != 4)
Cvar_SetValue(&r_bloom_diamond_size, 4);
if( r_bloom_diamond_size.value != 4 ) Cvar_SetValue(&r_bloom_diamond_size, 4 ); for (i=0; i<r_bloom_diamond_size.value; i++)
{
for(i=0; i<r_bloom_diamond_size.value; i++) { for (j=0; j<r_bloom_diamond_size.value; j++)
for(j=0; j<r_bloom_diamond_size.value; j++) { {
intensity = r_bloom_intensity.value * 0.8f * Diamond4x[i][j]; intensity = r_bloom_intensity.value * 0.8f * Diamond4x[i][j];
if( intensity < 0.01f ) continue; if (intensity < 0.01f)
qglColor4f( intensity, intensity, intensity, 1.0); continue;
qglColor4f(intensity, intensity, intensity, 1.0);
R_Bloom_SamplePass( i-2, j-2 ); R_Bloom_SamplePass( i-2, j-2 );
} }
} }
} }
qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, sample_width, sample_height); qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, bs.smp_w, bs.smp_h);
//restore full screen workspace //restore full screen workspace
qglViewport( 0, 0, glwidth, glheight ); qglViewport(0, 0, glwidth, glheight);
qglMatrixMode( GL_PROJECTION ); qglMatrixMode(GL_PROJECTION);
qglLoadIdentity (); qglLoadIdentity ();
qglOrtho(0, glwidth, glheight, 0, -10, 100); qglOrtho(0, glwidth, glheight, 0, -10, 100);
qglMatrixMode( GL_MODELVIEW ); qglMatrixMode(GL_MODELVIEW);
qglLoadIdentity (); qglLoadIdentity ();
} }
@ -485,60 +506,44 @@ R_Bloom_DownsampleView
*/ */
void R_Bloom_DownsampleView( void ) void R_Bloom_DownsampleView( void )
{ {
qglDisable( GL_BLEND ); qglDisable(GL_BLEND);
qglColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); qglColor4f(1.0f, 1.0f, 1.0f, 1.0f);
//stepped downsample //stepped downsample
if( r_screendownsamplingtexture_size ) if (bs.size_downsample)
{ {
int midsample_width = r_screendownsamplingtexture_size * sampleText_tcw; int midsample_width = bs.size_downsample * bs.smp_s;
int midsample_height = r_screendownsamplingtexture_size * sampleText_tch; int midsample_height = bs.size_downsample * bs.smp_t;
if (qglGetError())
Con_Printf("GL Error whilst rendering bloom\n");
//copy the screen and draw resized //copy the screen and draw resized
GL_Bind(r_bloomscreentexture); GL_Bind(bs.tx_screen);
if (qglGetError()) qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bs.vp_x, glheight - (bs.vp_y + bs.vp_h), bs.vp_w, bs.vp_h);
Con_Printf("GL Error whilst rendering bloom\n");
qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, curView_x, glheight - (curView_y + curView_height), curView_width, curView_height); R_Bloom_Quad(0, glheight-midsample_height, midsample_width, midsample_height, bs.scr_s, bs.scr_t);
if (qglGetError())
Con_Printf("GL Error whilst rendering bloom\n");
R_Bloom_Quad( 0, glheight-midsample_height, midsample_width, midsample_height, screenText_tcw, screenText_tch );
if (qglGetError())
Con_Printf("GL Error whilst rendering bloom\n");
//now copy into Downsampling (mid-sized) texture //now copy into Downsampling (mid-sized) texture
GL_Bind(r_bloomdownsamplingtexture); GL_Bind(bs.tx_downsample);
qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, midsample_width, midsample_height); qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, midsample_width, midsample_height);
if (qglGetError())
Con_Printf("GL Error whilst rendering bloom\n");
//now draw again in bloom size //now draw again in bloom size
qglColor4f( 0.5f, 0.5f, 0.5f, 1.0f ); qglColor4f(0.5f, 0.5f, 0.5f, 1.0f);
R_Bloom_Quad( 0, glheight-sample_height, sample_width, sample_height, sampleText_tcw, sampleText_tch ); R_Bloom_Quad(0, glheight-bs.smp_h, bs.smp_w, bs.smp_h, bs.smp_s, bs.smp_t);
if (qglGetError())
Con_Printf("GL Error whilst rendering bloom\n");
//now blend the big screen texture into the bloom generation space (hoping it adds some blur) //now blend the big screen texture into the bloom generation space (hoping it adds some blur)
qglEnable( GL_BLEND ); qglEnable(GL_BLEND);
qglBlendFunc(GL_ONE, GL_ONE); qglBlendFunc(GL_ONE, GL_ONE);
qglColor4f( 0.5f, 0.5f, 0.5f, 1.0f ); qglColor4f(0.5f, 0.5f, 0.5f, 1.0f);
GL_Bind(r_bloomscreentexture); GL_Bind(bs.tx_screen);
R_Bloom_Quad( 0, glheight-sample_height, sample_width, sample_height, screenText_tcw, screenText_tch ); R_Bloom_Quad(0, glheight-bs.smp_h, bs.smp_w, bs.smp_h, bs.scr_s, bs.scr_t);
qglColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); qglColor4f(1.0f, 1.0f, 1.0f, 1.0f);
qglDisable( GL_BLEND ); qglDisable(GL_BLEND);
}
else
{ //downsample simple
if (qglGetError()) GL_Bind(bs.tx_screen);
Con_Printf("GL Error whilst rendering bloom\n"); qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bs.vp_x, glheight - (bs.vp_y + bs.vp_h), bs.vp_w, bs.vp_h);
R_Bloom_Quad(0, glheight-bs.smp_h, bs.smp_w, bs.smp_h, bs.scr_s, bs.scr_t);
} else { //downsample simple
GL_Bind(r_bloomscreentexture);
qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, curView_x, glheight - (curView_y + curView_height), curView_width, curView_height);
R_Bloom_Quad( 0, glheight-sample_height, sample_width, sample_height, screenText_tcw, screenText_tch );
} }
} }
@ -549,79 +554,78 @@ R_BloomBlend
*/ */
void R_BloomBlend (void)//refdef_t *fd, meshlist_t *meshlist ) void R_BloomBlend (void)//refdef_t *fd, meshlist_t *meshlist )
{ {
if(!r_bloom.value) int buw, buh;
if (!r_bloom.value)
return; return;
if( !BLOOM_SIZE || screen_texture_width < glwidth || screen_texture_height < glheight) if (!bs.size_sample || bs.scr_w < glwidth || bs.scr_h < glheight)
R_Bloom_InitTextures(); R_Bloom_InitTextures();
if( screen_texture_width < BLOOM_SIZE || if (bs.scr_w < bs.size_sample ||
screen_texture_height < BLOOM_SIZE ) bs.scr_h < bs.size_sample)
return; return;
//set up full screen workspace //set up full screen workspace
qglViewport( 0, 0, glwidth, glheight ); qglViewport(0, 0, glwidth, glheight);
qglDisable( GL_DEPTH_TEST ); qglDisable(GL_DEPTH_TEST);
qglMatrixMode( GL_PROJECTION ); qglMatrixMode(GL_PROJECTION);
qglLoadIdentity (); qglLoadIdentity();
qglOrtho(0, glwidth, glheight, 0, -10, 100); qglOrtho(0, glwidth, glheight, 0, -10, 100);
qglMatrixMode( GL_MODELVIEW ); qglMatrixMode(GL_MODELVIEW);
qglLoadIdentity (); qglLoadIdentity();
qglDisable(GL_CULL_FACE); qglDisable(GL_CULL_FACE);
qglDisable( GL_BLEND ); qglDisable(GL_BLEND);
qglEnable( GL_TEXTURE_2D ); qglEnable(GL_TEXTURE_2D);
qglColor4f( 1, 1, 1, 1 ); qglColor4f(1, 1, 1, 1);
if (qglGetError())
Con_Printf("GL Error whilst rendering bloom\n");
//set up current sizes //set up current sizes
curView_x = scr_vrect.x*((float)glwidth/vid.width); bs.vp_x = gl_truescreenrect.x;
curView_y = scr_vrect.y*((float)glheight/vid.height); bs.vp_y = glheight - gl_truescreenrect.y;
curView_width = scr_vrect.width*((float)glwidth/vid.width); bs.vp_w = gl_truescreenrect.width;
curView_height = scr_vrect.height*((float)glheight/vid.height); bs.vp_h = gl_truescreenrect.height;
screenText_tcw = ((float)curView_width / (float)screen_texture_width); bs.scr_s = (float)bs.vp_w / (float)bs.scr_w;
screenText_tch = ((float)curView_height / (float)screen_texture_height); bs.scr_t = (float)bs.vp_h / (float)bs.scr_h;
if( scr_vrect.height > scr_vrect.width ) { if (bs.vp_h > bs.vp_w)
sampleText_tcw = ((float)(scr_vrect.width+0.5) / (float)scr_vrect.height); {
sampleText_tch = 1.0f; bs.smp_s = (float)bs.vp_w / (float)bs.vp_h;
} else { bs.smp_t = 1.0f;
sampleText_tcw = 1.0f;
sampleText_tch = ((float)(scr_vrect.height+0.5) / (float)scr_vrect.width);
} }
sample_width = BLOOM_SIZE * sampleText_tcw; else
sample_height = BLOOM_SIZE * sampleText_tch; {
bs.smp_s = 1.0f;
bs.smp_t = (float)bs.vp_h / (float)bs.vp_w;
}
bs.smp_w = bs.size_sample * bs.smp_s;
bs.smp_h = bs.size_sample * bs.smp_t;
if (qglGetError()) bs.smp_s = (float)bs.smp_w/bs.size_sample;
Con_Printf("GL Error whilst rendering bloom\n"); bs.smp_t = (float)bs.smp_h/bs.size_sample;
buw = bs.size_downsample * bs.smp_s;
buh = bs.size_downsample * bs.smp_t;
//copy the screen space we'll use to work into the backup texture //copy the screen space we'll use to work into the backup texture
GL_Bind(r_bloombackuptexture); GL_Bind(bs.tx_backup);
qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, r_screenbackuptexture_size * sampleText_tcw, r_screenbackuptexture_size * sampleText_tch); qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, buw, buh);
if (qglGetError())
Con_Printf("GL Error whilst rendering bloom\n");
//create the bloom image //create the bloom image
R_Bloom_DownsampleView(); R_Bloom_DownsampleView();
if (qglGetError())
Con_Printf("GL Error whilst rendering bloom\n");
R_Bloom_GeneratexDiamonds(); R_Bloom_GeneratexDiamonds();
//R_Bloom_GeneratexCross(); //R_Bloom_GeneratexCross();
if (qglGetError())
Con_Printf("GL Error whilst rendering bloom\n");
//restore the screen-backup to the screen //restore the screen-backup to the screen
qglDisable(GL_BLEND); qglDisable(GL_BLEND);
GL_Bind(r_bloombackuptexture); GL_Bind(bs.tx_backup);
qglColor4f( 1, 1, 1, 1 ); qglColor4f(1, 1, 1, 1);
R_Bloom_Quad( 0, R_Bloom_Quad(0,
glheight - (r_screenbackuptexture_size * sampleText_tch), glheight - (buh),
r_screenbackuptexture_size * sampleText_tcw, buw,
r_screenbackuptexture_size * sampleText_tch, buh,
sampleText_tcw, bs.smp_s,
sampleText_tch ); bs.smp_t);
R_Bloom_DrawEffect(); R_Bloom_DrawEffect();

View file

@ -36,6 +36,8 @@ void R_RenderBrushPoly (msurface_t *fa);
extern int gl_canstencil; extern int gl_canstencil;
vrect_t gl_truescreenrect;
FTEPFNGLCOMPRESSEDTEXIMAGE2DARBPROC qglCompressedTexImage2DARB; FTEPFNGLCOMPRESSEDTEXIMAGE2DARBPROC qglCompressedTexImage2DARB;
FTEPFNGLGETCOMPRESSEDTEXIMAGEARBPROC qglGetCompressedTexImageARB; FTEPFNGLGETCOMPRESSEDTEXIMAGEARBPROC qglGetCompressedTexImageARB;
@ -737,6 +739,13 @@ void GLR_DrawEntitiesOnList (void)
} }
} }
if (currententity->model->engineflags & MDLF_NOTREPLACEMENTS)
{
if (currententity->model->fromgame != fg_quake || currententity->model->type != mod_halflife)
if (!ruleset_allow_sensative_texture_replacements.value)
continue;
}
switch (currententity->model->type) switch (currententity->model->type)
{ {
case mod_alias: case mod_alias:
@ -1008,6 +1017,11 @@ void R_SetupGL (void)
w = h = 256; w = h = 256;
} }
gl_truescreenrect.x = x;
gl_truescreenrect.y = y;
gl_truescreenrect.width = w;
gl_truescreenrect.height = h;
qglViewport (glx + x, gly + y2, w, h); qglViewport (glx + x, gly + y2, w, h);
qglMatrixMode(GL_PROJECTION); qglMatrixMode(GL_PROJECTION);