From e0efe0aa23e5783451c533911eeb26ad8c243dd8 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Tue, 7 Dec 2021 09:04:16 +0300 Subject: [PATCH] engine: remove emboss filter. There seems no real use for it. --- common/com_image.h | 2 +- common/render_api.h | 2 +- engine/common/common.h | 2 +- engine/common/imagelib/img_utils.c | 114 +---------------------------- engine/common/mod_bmodel.c | 4 +- engine/ref_api.h | 2 +- ref_gl/gl_image.c | 13 +--- ref_gl/gl_local.h | 1 - ref_gl/gl_opengl.c | 2 - ref_soft/r_context.c | 1 - ref_soft/r_image.c | 9 --- ref_soft/r_local.h | 1 - ref_soft/r_main.c | 1 - 13 files changed, 8 insertions(+), 146 deletions(-) diff --git a/common/com_image.h b/common/com_image.h index 33a0f812..063309ab 100644 --- a/common/com_image.h +++ b/common/com_image.h @@ -82,7 +82,7 @@ typedef enum IMAGE_ROT_90 = BIT(18), // flip from upper left corner to down right corner IMAGE_ROT180 = IMAGE_FLIP_X|IMAGE_FLIP_Y, IMAGE_ROT270 = IMAGE_FLIP_X|IMAGE_FLIP_Y|IMAGE_ROT_90, - IMAGE_EMBOSS = BIT(19), // apply emboss mapping +// reserved IMAGE_RESAMPLE = BIT(20), // resample image to specified dims // reserved // reserved diff --git a/common/render_api.h b/common/render_api.h index c59f4683..f41d297f 100644 --- a/common/render_api.h +++ b/common/render_api.h @@ -82,7 +82,7 @@ typedef enum TF_KEEP_SOURCE = (1<<1), // some images keep source TF_NOFLIP_TGA = (1<<2), // Steam background completely ignore tga attribute 0x20 TF_EXPAND_SOURCE = (1<<3), // Don't keep source as 8-bit expand to RGBA - TF_ALLOW_EMBOSS = (1<<4), // Allow emboss-mapping for this image +// reserved TF_RECTANGLE = (1<<5), // this is GL_TEXTURE_RECTANGLE TF_CUBEMAP = (1<<6), // it's cubemap texture TF_DEPTHMAP = (1<<7), // custom texture filter used diff --git a/engine/common/common.h b/engine/common/common.h index 0c54664f..ad4ccc59 100644 --- a/engine/common/common.h +++ b/engine/common/common.h @@ -594,7 +594,7 @@ qboolean FS_SaveImage( const char *filename, rgbdata_t *pix ); rgbdata_t *FS_CopyImage( rgbdata_t *in ); void FS_FreeImage( rgbdata_t *pack ); extern const bpc_desc_t PFDesc[]; // image get pixelformat -qboolean Image_Process( rgbdata_t **pix, int width, int height, uint flags, float bumpscale ); +qboolean Image_Process( rgbdata_t **pix, int width, int height, uint flags, float reserved ); void Image_PaletteHueReplace( byte *palSrc, int newHue, int start, int end, int pal_size ); void Image_PaletteTranslate( byte *palSrc, int top, int bottom, int pal_size ); void Image_SetForceFlags( uint flags ); // set image force flags on loading diff --git a/engine/common/imagelib/img_utils.c b/engine/common/imagelib/img_utils.c index 8d93f81e..49976277 100644 --- a/engine/common/imagelib/img_utils.c +++ b/engine/common/imagelib/img_utils.c @@ -80,15 +80,6 @@ static byte palette_hl[768] = 147,255,247,199,255,255,255,159,91,83 }; -static float img_emboss[FILTER_SIZE][FILTER_SIZE] = -{ -{-0.7f, -0.7f, -0.7f, -0.7f, 0.0f }, -{-0.7f, -0.7f, -0.7f, 0.0f, 0.7f }, -{-0.7f, -0.7f, 0.0f, 0.7f, 0.7f }, -{-0.7f, 0.0f, 0.7f, 0.7f, 0.7f }, -{ 0.0f, 0.7f, 0.7f, 0.7f, 0.7f }, -}; - /* ============================================================================= @@ -1368,107 +1359,7 @@ qboolean Image_RemapInternal( rgbdata_t *pic, int topColor, int bottomColor ) return true; } -/* -================== -Image_ApplyFilter - -Applies a 5 x 5 filtering matrix to the texture, then runs it through a simulated OpenGL texture environment -blend with the original data to derive a new texture. Freaky, funky, and *f--king* *fantastic*. You can do -reasonable enough "fake bumpmapping" with this baby... - -Filtering algorithm from http://www.student.kuleuven.ac.be/~m0216922/CG/filtering.html -All credit due -================== -*/ -static void Image_ApplyFilter( rgbdata_t *pic, float factor ) -{ - int i, x, y; - uint *fin, *fout; - size_t size; - - // don't waste time - if( factor <= 0.0f ) return; - - // first expand the image into 32-bit buffer - pic = Image_DecompressInternal( pic ); - factor = bound( 0.0f, factor, 1.0f ); - size = image.width * image.height * 4; - image.tempbuffer = Mem_Realloc( host.imagepool, image.tempbuffer, size ); - fout = (uint *)image.tempbuffer; - fin = (uint *)pic->buffer; - - for( x = 0; x < image.width; x++ ) - { - for( y = 0; y < image.height; y++ ) - { - vec3_t vout = { 0.0f, 0.0f, 0.0f }; - int pos_x, pos_y; - float avg; - - for( pos_x = 0; pos_x < FILTER_SIZE; pos_x++ ) - { - for( pos_y = 0; pos_y < FILTER_SIZE; pos_y++ ) - { - int img_x = (x - (FILTER_SIZE / 2) + pos_x + image.width) % image.width; - int img_y = (y - (FILTER_SIZE / 2) + pos_y + image.height) % image.height; - - // casting's a unary operation anyway, so the othermost set of brackets in the left part - // of the rvalue should not be necessary... but i'm paranoid when it comes to C... - vout[0] += ((float)((byte *)&fin[img_y * image.width + img_x])[0]) * img_emboss[pos_x][pos_y]; - vout[1] += ((float)((byte *)&fin[img_y * image.width + img_x])[1]) * img_emboss[pos_x][pos_y]; - vout[2] += ((float)((byte *)&fin[img_y * image.width + img_x])[2]) * img_emboss[pos_x][pos_y]; - } - } - - // multiply by factor, add bias, and clamp - for( i = 0; i < 3; i++ ) - { - vout[i] *= factor; - vout[i] += 128.0f; // base - vout[i] = bound( 0.0f, vout[i], 255.0f ); - } - - // NTSC greyscale conversion standard - avg = (vout[0] * 30.0f + vout[1] * 59.0f + vout[2] * 11.0f) / 100.0f; - - // divide by 255 so GL operations work as expected - vout[0] = avg / 255.0f; - vout[1] = avg / 255.0f; - vout[2] = avg / 255.0f; - - // write to temp - first, write data in (to get the alpha channel quickly and - // easily, which will be left well alone by this particular operation...!) - fout[y * image.width + x] = fin[y * image.width + x]; - - // now write in each element, applying the blend operator. blend - // operators are based on standard OpenGL TexEnv modes, and the - // formulas are derived from the OpenGL specs (http://www.opengl.org). - for( i = 0; i < 3; i++ ) - { - // divide by 255 so GL operations work as expected - float src = ((float)((byte *)&fin[y * image.width + x])[i]) / 255.0f; - float tmp; - - // default is GL_BLEND here - // CsS + CdD works out as Src * Dst * 2 - tmp = vout[i] * src * 2.0f; - - // multiply back by 255 to get the proper byte scale - tmp *= 255.0f; - - // bound the temp target again now, cos the operation may have thrown it out - tmp = bound( 0.0f, tmp, 255.0f ); - // and copy it in - ((byte *)&fout[y * image.width + x])[i] = (byte)tmp; - } - } - } - - // copy result back - memcpy( fin, fout, size ); -} - -qboolean Image_Process( rgbdata_t **pix, int width, int height, uint flags, float bumpscale ) +qboolean Image_Process(rgbdata_t **pix, int width, int height, uint flags, float reserved ) { rgbdata_t *pic = *pix; qboolean result = true; @@ -1509,9 +1400,6 @@ qboolean Image_Process( rgbdata_t **pix, int width, int height, uint flags, floa if( FBitSet( flags, IMAGE_LIGHTGAMMA )) pic = Image_LightGamma( pic ); - if( FBitSet( flags, IMAGE_EMBOSS )) - Image_ApplyFilter( pic, bumpscale ); - out = Image_FlipInternal( pic->buffer, &pic->width, &pic->height, pic->type, flags ); if( pic->buffer != out ) memcpy( pic->buffer, image.tempbuffer, pic->size ); diff --git a/engine/common/mod_bmodel.c b/engine/common/mod_bmodel.c index 7b9c761d..8d8dcae8 100644 --- a/engine/common/mod_bmodel.c +++ b/engine/common/mod_bmodel.c @@ -2023,7 +2023,7 @@ static void Mod_LoadTextures( dbspmodel_t *bmod ) if( FS_FileExists( texpath, false )) { - tx->gl_texturenum = ref.dllFuncs.GL_LoadTexture( texpath, NULL, 0, TF_ALLOW_EMBOSS|txFlags ); + tx->gl_texturenum = ref.dllFuncs.GL_LoadTexture( texpath, NULL, 0, txFlags ); bmod->wadlist.wadusage[j]++; // this wad are really used break; } @@ -2039,7 +2039,7 @@ static void Mod_LoadTextures( dbspmodel_t *bmod ) if( custom_palette ) size += sizeof( short ) + 768; Q_snprintf( texname, sizeof( texname ), "#%s:%s.mip", loadstat.name, mt->name ); - tx->gl_texturenum = ref.dllFuncs.GL_LoadTexture( texname, (byte *)mt, size, TF_ALLOW_EMBOSS|txFlags ); + tx->gl_texturenum = ref.dllFuncs.GL_LoadTexture( texname, (byte *)mt, size, txFlags ); } // if texture is completely missed diff --git a/engine/ref_api.h b/engine/ref_api.h index 26c67a3a..bfe210a6 100644 --- a/engine/ref_api.h +++ b/engine/ref_api.h @@ -417,7 +417,7 @@ typedef struct ref_api_s void (*Image_SetForceFlags)( uint flags ); void (*Image_ClearForceFlags)( void ); qboolean (*Image_CustomPalette)( void ); - qboolean (*Image_Process)( rgbdata_t **pix, int width, int height, uint flags, float bumpscale ); + qboolean (*Image_Process)( rgbdata_t **pix, int width, int height, uint flags, float reserved ); rgbdata_t *(*FS_LoadImage)( const char *filename, const byte *buffer, size_t size ); qboolean (*FS_SaveImage)( const char *filename, rgbdata_t *pix ); rgbdata_t *(*FS_CopyImage)( rgbdata_t *in ); diff --git a/ref_gl/gl_image.c b/ref_gl/gl_image.c index 610d762f..643325d9 100644 --- a/ref_gl/gl_image.c +++ b/ref_gl/gl_image.c @@ -1266,7 +1266,6 @@ do specified actions on pixels */ static void GL_ProcessImage( gl_texture_t *tex, rgbdata_t *pic ) { - float emboss_scale = 0.0f; uint img_flags = 0; // force upload texture as RGB or RGBA (detail textures requires this) @@ -1299,12 +1298,6 @@ static void GL_ProcessImage( gl_texture_t *tex, rgbdata_t *pic ) tex->flags &= ~TF_MAKELUMA; } - if( tex->flags & TF_ALLOW_EMBOSS ) - { - img_flags |= IMAGE_EMBOSS; - tex->flags &= ~TF_ALLOW_EMBOSS; - } - if( !FBitSet( tex->flags, TF_IMG_UPLOADED ) && FBitSet( tex->flags, TF_KEEP_SOURCE )) tex->original = gEngfuncs.FS_CopyImage( pic ); // because current pic will be expanded to rgba @@ -1312,12 +1305,8 @@ static void GL_ProcessImage( gl_texture_t *tex, rgbdata_t *pic ) if( pic->type == PF_INDEXED_24 || pic->type == PF_INDEXED_32 ) img_flags |= IMAGE_FORCE_RGBA; - // dedicated server doesn't register this variable - if( gl_emboss_scale != NULL ) - emboss_scale = gl_emboss_scale->value; - // processing image before uploading (force to rgba, make luma etc) - if( pic->buffer ) gEngfuncs.Image_Process( &pic, 0, 0, img_flags, emboss_scale ); + if( pic->buffer ) gEngfuncs.Image_Process( &pic, 0, 0, img_flags, 0 ); if( FBitSet( tex->flags, TF_LUMINANCE )) ClearBits( pic->flags, IMAGE_HAS_COLOR ); diff --git a/ref_gl/gl_local.h b/ref_gl/gl_local.h index f8231b75..09e657c2 100644 --- a/ref_gl/gl_local.h +++ b/ref_gl/gl_local.h @@ -723,7 +723,6 @@ extern cvar_t *gl_texture_lodbias; extern cvar_t *gl_texture_nearest; extern cvar_t *gl_lightmap_nearest; extern cvar_t *gl_keeptjunctions; -extern cvar_t *gl_emboss_scale; extern cvar_t *gl_round_down; extern cvar_t *gl_wireframe; extern cvar_t *gl_polyoffset; diff --git a/ref_gl/gl_opengl.c b/ref_gl/gl_opengl.c index 4ada975a..1199478e 100644 --- a/ref_gl/gl_opengl.c +++ b/ref_gl/gl_opengl.c @@ -11,7 +11,6 @@ cvar_t *gl_texture_lodbias; cvar_t *gl_texture_nearest; cvar_t *gl_lightmap_nearest; cvar_t *gl_keeptjunctions; -cvar_t *gl_emboss_scale; cvar_t *gl_check_errors; cvar_t *gl_polyoffset; cvar_t *gl_wireframe; @@ -848,7 +847,6 @@ void GL_InitCommands( void ) gl_texture_anisotropy = gEngfuncs.Cvar_Get( "gl_anisotropy", "8", FCVAR_ARCHIVE, "textures anisotropic filter" ); gl_texture_lodbias = gEngfuncs.Cvar_Get( "gl_texture_lodbias", "0.0", FCVAR_ARCHIVE, "LOD bias for mipmapped textures (perfomance|quality)" ); gl_keeptjunctions = gEngfuncs.Cvar_Get( "gl_keeptjunctions", "1", FCVAR_ARCHIVE, "removing tjuncs causes blinking pixels" ); - gl_emboss_scale = gEngfuncs.Cvar_Get( "gl_emboss_scale", "0", FCVAR_ARCHIVE|FCVAR_LATCH, "fake bumpmapping scale" ); gl_finish = gEngfuncs.Cvar_Get( "gl_finish", "0", FCVAR_ARCHIVE, "use glFinish instead of glFlush" ); gl_nosort = gEngfuncs.Cvar_Get( "gl_nosort", "0", FCVAR_ARCHIVE, "disable sorting of translucent surfaces" ); gl_test = gEngfuncs.Cvar_Get( "gl_test", "0", 0, "engine developer cvar for quick testing new features" ); diff --git a/ref_soft/r_context.c b/ref_soft/r_context.c index ec256031..747e029d 100644 --- a/ref_soft/r_context.c +++ b/ref_soft/r_context.c @@ -20,7 +20,6 @@ ref_globals_t *gpGlobals; gl_globals_t tr; ref_speeds_t r_stats; poolhandle_t r_temppool; -cvar_t *gl_emboss_scale; viddef_t vid; static void GAME_EXPORT R_ClearScreen( void ) { diff --git a/ref_soft/r_image.c b/ref_soft/r_image.c index 4867a73a..a374d401 100644 --- a/ref_soft/r_image.c +++ b/ref_soft/r_image.c @@ -777,12 +777,6 @@ static void GL_ProcessImage( image_t *tex, rgbdata_t *pic ) tex->flags &= ~TF_MAKELUMA; } - if( tex->flags & TF_ALLOW_EMBOSS ) - { - img_flags |= IMAGE_EMBOSS; - tex->flags &= ~TF_ALLOW_EMBOSS; - } - if( !FBitSet( tex->flags, TF_IMG_UPLOADED ) && FBitSet( tex->flags, TF_KEEP_SOURCE )) tex->original = gEngfuncs.FS_CopyImage( pic ); // because current pic will be expanded to rgba @@ -790,9 +784,6 @@ static void GL_ProcessImage( image_t *tex, rgbdata_t *pic ) if( pic->type == PF_INDEXED_24 || pic->type == PF_INDEXED_32 ) img_flags |= IMAGE_FORCE_RGBA; - // processing image before uploading (force to rgba, make luma etc) - if( pic->buffer ) gEngfuncs.Image_Process( &pic, 0, 0, img_flags, gl_emboss_scale->value ); - if( FBitSet( tex->flags, TF_LUMINANCE )) ClearBits( pic->flags, IMAGE_HAS_COLOR ); } diff --git a/ref_soft/r_local.h b/ref_soft/r_local.h index 2e3bedf3..4546544a 100644 --- a/ref_soft/r_local.h +++ b/ref_soft/r_local.h @@ -686,7 +686,6 @@ void TriBrightness( float brightness ); extern ref_api_t gEngfuncs; extern ref_globals_t *gpGlobals; -extern cvar_t *gl_emboss_scale; extern cvar_t *r_dynamic; DECLARE_ENGINE_SHARED_CVAR_LIST() diff --git a/ref_soft/r_main.c b/ref_soft/r_main.c index c6d11f84..dd09e5d1 100644 --- a/ref_soft/r_main.c +++ b/ref_soft/r_main.c @@ -1915,7 +1915,6 @@ qboolean GAME_EXPORT R_Init( void ) RETRIEVE_ENGINE_SHARED_CVAR_LIST(); - gl_emboss_scale = gEngfuncs.Cvar_Get( "gl_emboss_scale", "0", FCVAR_ARCHIVE|FCVAR_LATCH, "fake bumpmapping scale" ); r_fullbright = gEngfuncs.Cvar_Get( "r_fullbright", "0", FCVAR_CHEAT, "disable lightmaps, get fullbright for entities" ); // sw_aliasstats = ri.Cvar_Get ("sw_polymodelstats", "0", 0);