From 7ce3d0c733aa0b601e2cc91261d6aba839f63c2e Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 27 Nov 2023 04:40:13 +0100 Subject: [PATCH] add toggle for texture zfight fix --- src/hardware/hw_main.c | 72 +++++++++++++++++++++++++++++++----------- src/hardware/hw_main.h | 1 + 2 files changed, 54 insertions(+), 19 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 03e829010..ed31a3c9d 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -101,6 +101,8 @@ consvar_t cv_grbatching = {"gr_batching", "On", 0, CV_OnOff, NULL, 0, NULL, NULL consvar_t cv_grfofcut = {"gr_fofcut", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_fofzfightfix = {"fofzfightfix", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + consvar_t cv_splitwallfix = {"splitwallfix", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; static CV_PossibleValue_t grrenderdistance_cons_t[] = { @@ -1324,13 +1326,23 @@ static void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, wallVerts[2].y = wallVerts[3].y = top; wallVerts[0].y = wallVerts[1].y = bot; #endif - - if (cutflag & FF_FOG) - HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Fog|PF_NoTexture|polyflags, true, lightnum, colormap); - else if (cutflag & FF_TRANSLUCENT) - HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Translucent|polyflags, false, lightnum, colormap); - else - HWR_ProjectWall(wallVerts, Surf, PF_Masked|polyflags, lightnum, colormap); + if (cv_fofzfightfix.value) + { + if (cutflag & FF_FOG) + HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Fog|PF_NoTexture|polyflags, true, lightnum, colormap); + else if (cutflag & FF_TRANSLUCENT) + HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Translucent|polyflags, false, lightnum, colormap); + else + HWR_ProjectWall(wallVerts, Surf, PF_Masked|polyflags, lightnum, colormap); + }else{ + if (cutflag & FF_FOG) + HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Fog|PF_NoTexture, true, lightnum, colormap); + else if (cutflag & FF_TRANSLUCENT) + HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Translucent, false, lightnum, colormap); + else + HWR_ProjectWall(wallVerts, Surf, PF_Masked, lightnum, colormap); + } + top = bot; #ifdef ESLOPE @@ -1368,12 +1380,22 @@ static void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, wallVerts[0].y = wallVerts[1].y = bot; #endif - if (cutflag & FF_FOG) - HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Fog|PF_NoTexture|polyflags, true, lightnum, colormap); - else if (cutflag & FF_TRANSLUCENT) - HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Translucent|polyflags, false, lightnum, colormap); - else - HWR_ProjectWall(wallVerts, Surf, PF_Masked|polyflags, lightnum, colormap); + if (cv_fofzfightfix.value) + { + if (cutflag & FF_FOG) + HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Fog|PF_NoTexture|polyflags, true, lightnum, colormap); + else if (cutflag & FF_TRANSLUCENT) + HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Translucent|polyflags, false, lightnum, colormap); + else + HWR_ProjectWall(wallVerts, Surf, PF_Masked|polyflags, lightnum, colormap); + }else{ + if (cutflag & FF_FOG) + HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Fog|PF_NoTexture, true, lightnum, colormap); + else if (cutflag & FF_TRANSLUCENT) + HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Translucent, false, lightnum, colormap); + else + HWR_ProjectWall(wallVerts, Surf, PF_Masked, lightnum, colormap); + } } // skywall list system for fixing portal issues by postponing skywall rendering (and using stencil buffer for them) @@ -2152,16 +2174,27 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom // Render midtextures on two-sided lines with a z-buffer offset. // This will cause the midtexture appear on top, if a FOF overlaps with it. - blendmode |= PF_Decal; + if (cv_fofzfightfix.value) + blendmode |= PF_Decal; if (!gl_drawing_stencil && gr_frontsector->numlights) { - if (!(blendmode & PF_Masked)) - HWR_SplitWall(gr_frontsector, wallVerts, gr_midtexture, &Surf, FF_TRANSLUCENT, NULL, PF_Decal); - else + if (cv_fofzfightfix.value) { - HWR_SplitWall(gr_frontsector, wallVerts, gr_midtexture, &Surf, FF_CUTLEVEL, NULL, PF_Decal); - } + if (!(blendmode & PF_Masked)) + HWR_SplitWall(gr_frontsector, wallVerts, gr_midtexture, &Surf, FF_TRANSLUCENT, NULL, PF_Decal); + else + { + HWR_SplitWall(gr_frontsector, wallVerts, gr_midtexture, &Surf, FF_CUTLEVEL, NULL, PF_Decal); + } + }else{ + if (!(blendmode & PF_Masked)) + HWR_SplitWall(gr_frontsector, wallVerts, gr_midtexture, &Surf, FF_TRANSLUCENT, NULL, 0); + else + { + HWR_SplitWall(gr_frontsector, wallVerts, gr_midtexture, &Surf, FF_CUTLEVEL, NULL, 0); + } + } } else if (!gl_drawing_stencil && !(blendmode & PF_Masked)) HWR_AddTransparentWall(wallVerts, &Surf, gr_midtexture, blendmode, false, lightnum, colormap); @@ -6415,6 +6448,7 @@ void HWR_AddCommands(void) CV_RegisterVar(&cv_grbatching); CV_RegisterVar(&cv_grfofcut); + CV_RegisterVar(&cv_fofzfightfix); CV_RegisterVar(&cv_splitwallfix); CV_RegisterVar(&cv_grscreentextures); diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index c8c25c03a..b86c4b70a 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -164,6 +164,7 @@ void HWR_CorrectSWTricks(void); // Console variables extern consvar_t cv_grshaders; extern consvar_t cv_grfofcut; +extern consvar_t cv_fofzfightfix; extern consvar_t cv_splitwallfix; extern consvar_t cv_grshearing; extern consvar_t cv_grfov;