Skip to content

Commit e1b51f0

Browse files
committed
renderer: implement high precision rendering framebuffers
This is needed to avoid color-banding with the various division/multiplication round trips of the complete overBright implementation. This will also be needed for sRGB colors in the future too. It is enabled by default if a feature requires it. This is optional and can be disabled with r_highPrecisionRendering, or automatically disabled if the hardware doesn't support the feature.
1 parent 10b0601 commit e1b51f0

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

src/engine/renderer/tr_image.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2408,13 +2408,24 @@ static void R_CreateCurrentRenderImage()
24082408

24092409
imageParams_t imageParams = {};
24102410
imageParams.bits = IF_NOPICMIP;
2411+
2412+
bool bestWithHighPrecisionFrameBuffer = !r_mapClampOverBright.Get();
2413+
2414+
if ( bestWithHighPrecisionFrameBuffer && glConfig2.textureFloatAvailable && r_highPrecisionRendering.Get() )
2415+
{
2416+
imageParams.bits |= IF_RGBA16;
2417+
}
2418+
24112419
imageParams.filterType = filterType_t::FT_NEAREST;
24122420
imageParams.wrapType = wrapTypeEnum_t::WT_CLAMP;
24132421

24142422
tr.currentRenderImage[0] = R_CreateImage( "_currentRender[0]", nullptr, width, height, 1, imageParams );
24152423
tr.currentRenderImage[1] = R_CreateImage( "_currentRender[1]", nullptr, width, height, 1, imageParams );
24162424

2417-
imageParams.bits |= IF_PACKED_DEPTH24_STENCIL8;
2425+
imageParams = {};
2426+
imageParams.bits = IF_NOPICMIP | IF_PACKED_DEPTH24_STENCIL8;
2427+
imageParams.filterType = filterType_t::FT_NEAREST;
2428+
imageParams.wrapType = wrapTypeEnum_t::WT_CLAMP;
24182429

24192430
tr.currentDepthImage = R_CreateImage( "_currentDepth", nullptr, width, height, 1, imageParams );
24202431
}

src/engine/renderer/tr_init.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
186186
cvar_t *r_halfLambertLighting;
187187
cvar_t *r_rimLighting;
188188
cvar_t *r_rimExponent;
189+
190+
Cvar::Cvar<bool> r_highPrecisionRendering("r_highPrecisionRendering", "use high precision frame buffers for rendering and blending", Cvar::NONE, true);
191+
189192
cvar_t *r_gamma;
190193
cvar_t *r_lockpvs;
191194
cvar_t *r_noportals;
@@ -1254,6 +1257,8 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
12541257
r_rimExponent = Cvar_Get( "r_rimExponent", "3", CVAR_CHEAT | CVAR_LATCH );
12551258
AssertCvarRange( r_rimExponent, 0.5, 8.0, false );
12561259

1260+
Cvar::Latch( r_highPrecisionRendering );
1261+
12571262
r_drawBuffer = Cvar_Get( "r_drawBuffer", "GL_BACK", CVAR_CHEAT );
12581263
r_lockpvs = Cvar_Get( "r_lockpvs", "0", CVAR_CHEAT );
12591264
r_noportals = Cvar_Get( "r_noportals", "0", CVAR_CHEAT );

src/engine/renderer/tr_local.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3030,6 +3030,8 @@ enum class dynamicLightRenderer_t { LEGACY, TILED };
30303030
extern cvar_t *r_rimLighting;
30313031
extern cvar_t *r_rimExponent;
30323032

3033+
extern Cvar::Cvar<bool> r_highPrecisionRendering;
3034+
30333035
extern cvar_t *r_logFile; // number of frames to emit GL logs
30343036

30353037
extern cvar_t *r_clear; // force screen clear every frame

0 commit comments

Comments
 (0)