Skip to content

Commit f2d2d78

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 62cf2cf commit f2d2d78

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
@@ -2467,13 +2467,24 @@ static void R_CreateCurrentRenderImage()
24672467

24682468
imageParams_t imageParams = {};
24692469
imageParams.bits = IF_NOPICMIP;
2470+
2471+
bool bestWithHighPrecisionFrameBuffer = !r_mapClampOverBright.Get();
2472+
2473+
if ( bestWithHighPrecisionFrameBuffer && glConfig2.textureFloatAvailable && r_highPrecisionRendering.Get() )
2474+
{
2475+
imageParams.bits |= IF_RGBA16;
2476+
}
2477+
24702478
imageParams.filterType = filterType_t::FT_NEAREST;
24712479
imageParams.wrapType = wrapTypeEnum_t::WT_CLAMP;
24722480

24732481
tr.currentRenderImage[0] = R_CreateImage( "_currentRender[0]", nullptr, width, height, 1, imageParams );
24742482
tr.currentRenderImage[1] = R_CreateImage( "_currentRender[1]", nullptr, width, height, 1, imageParams );
24752483

2476-
imageParams.bits |= IF_PACKED_DEPTH24_STENCIL8;
2484+
imageParams = {};
2485+
imageParams.bits = IF_NOPICMIP | IF_PACKED_DEPTH24_STENCIL8;
2486+
imageParams.filterType = filterType_t::FT_NEAREST;
2487+
imageParams.wrapType = wrapTypeEnum_t::WT_CLAMP;
24772488

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

src/engine/renderer/tr_init.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
177177
cvar_t *r_halfLambertLighting;
178178
cvar_t *r_rimLighting;
179179
cvar_t *r_rimExponent;
180+
181+
Cvar::Cvar<bool> r_highPrecisionRendering("r_highPrecisionRendering", "use high precision frame buffers for rendering and blending", Cvar::NONE, true);
182+
180183
cvar_t *r_gamma;
181184
cvar_t *r_lockpvs;
182185
cvar_t *r_noportals;
@@ -1243,6 +1246,8 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
12431246
r_rimExponent = Cvar_Get( "r_rimExponent", "3", CVAR_CHEAT | CVAR_LATCH );
12441247
AssertCvarRange( r_rimExponent, 0.5, 8.0, false );
12451248

1249+
Cvar::Latch( r_highPrecisionRendering );
1250+
12461251
r_drawBuffer = Cvar_Get( "r_drawBuffer", "GL_BACK", CVAR_CHEAT );
12471252
r_lockpvs = Cvar_Get( "r_lockpvs", "0", CVAR_CHEAT );
12481253
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
@@ -3027,6 +3027,8 @@ enum class deluxeMode_t { NONE, GRID, MAP };
30273027
extern cvar_t *r_rimLighting;
30283028
extern cvar_t *r_rimExponent;
30293029

3030+
extern Cvar::Cvar<bool> r_highPrecisionRendering;
3031+
30303032
extern cvar_t *r_logFile; // number of frames to emit GL logs
30313033

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

0 commit comments

Comments
 (0)