IOQ3 commit 2363

This commit is contained in:
Richard Allen 2012-12-12 20:02:51 +00:00
parent 5efc76340b
commit 5b0d606e06
8 changed files with 166 additions and 201 deletions

View file

@ -485,7 +485,7 @@ void RB_BeginDrawingView (void) {
// drawing more world check is in case of double renders, such as skyportals
if (backEnd.viewParms.targetFbo == NULL)
{
if (backEnd.framePostProcessed && (backEnd.refdef.rdflags & RDF_NOWORLDMODEL))
if (!tr.renderFbo || (backEnd.framePostProcessed && (backEnd.refdef.rdflags & RDF_NOWORLDMODEL)))
{
FBO_Bind(tr.screenScratchFbo);
}
@ -959,7 +959,7 @@ void RE_StretchRaw (int x, int y, int w, int h, int cols, int rows, const byte *
// FIXME: HUGE hack
if (glRefConfig.framebufferObject)
{
if (backEnd.framePostProcessed)
if (!tr.renderFbo || backEnd.framePostProcessed)
{
FBO_Bind(tr.screenScratchFbo);
}
@ -1108,7 +1108,7 @@ const void *RB_StretchPic ( const void *data ) {
// FIXME: HUGE hack
if (glRefConfig.framebufferObject)
{
if (backEnd.framePostProcessed)
if (!tr.renderFbo || backEnd.framePostProcessed)
{
FBO_Bind(tr.screenScratchFbo);
}
@ -1223,58 +1223,22 @@ const void *RB_DrawSurfs( const void *data ) {
qglColorMask(!backEnd.colorMask[0], !backEnd.colorMask[1], !backEnd.colorMask[2], !backEnd.colorMask[3]);
backEnd.depthFill = qfalse;
// If we're using multisampling, resolve the depth first
if (tr.msaaResolveFbo)
{
// If we're using multisampling, resolve the depth first
FBO_FastBlit(tr.renderFbo, NULL, tr.msaaResolveFbo, NULL, GL_DEPTH_BUFFER_BIT, GL_NEAREST);
}
else if (tr.renderFbo == NULL)
{
// If we're rendering directly to the screen, copy the depth to a texture
GL_BindToTMU(tr.renderDepthImage, 0);
qglCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, 0, 0, glConfig.vidWidth, glConfig.vidHeight, 0);
}
if (r_ssao->integer)
{
vec2_t srcTexScale;
vec4_t color;
vec4_t quadVerts[4];
vec2_t texCoords[4];
vec2_t invTexRes;
matrix_t idmatrix;
srcTexScale[0] = srcTexScale[1] = 1.0f;
color[0] = color[1] = color[2] = color[3] = 1.0f;
FBO_Bind(tr.hdrDepthFbo);
qglViewport(0, 0, tr.hdrDepthFbo->width, tr.hdrDepthFbo->height);
qglScissor(0, 0, tr.hdrDepthFbo->width, tr.hdrDepthFbo->height);
Matrix16Identity(idmatrix);
VectorSet4(quadVerts[0], -1, 1, 0, 1);
VectorSet4(quadVerts[1], 1, 1, 0, 1);
VectorSet4(quadVerts[2], 1, -1, 0, 1);
VectorSet4(quadVerts[3], -1, -1, 0, 1);
texCoords[0][0] = 0; texCoords[0][1] = 1;
texCoords[1][0] = 1; texCoords[1][1] = 1;
texCoords[2][0] = 1; texCoords[2][1] = 0;
texCoords[3][0] = 0; texCoords[3][1] = 0;
invTexRes[0] = 0.0f;
invTexRes[1] = 0.0f;
GL_State( GLS_DEPTHTEST_DISABLE );
GLSL_BindProgram(&tr.textureColorShader);
GL_BindToTMU(tr.renderDepthImage, TB_COLORMAP);
GLSL_SetUniformMatrix16(&tr.textureColorShader, TEXTURECOLOR_UNIFORM_MODELVIEWPROJECTIONMATRIX, idmatrix);
GLSL_SetUniformVec4(&tr.textureColorShader, TEXTURECOLOR_UNIFORM_COLOR, color);
GLSL_SetUniformVec2(&tr.textureColorShader, TEXTURECOLOR_UNIFORM_INVTEXRES, invTexRes);
GLSL_SetUniformVec2(&tr.textureColorShader, TEXTURECOLOR_UNIFORM_AUTOEXPOSUREMINMAX, tr.refdef.autoExposureMinMax);
GLSL_SetUniformVec3(&tr.textureColorShader, TEXTURECOLOR_UNIFORM_TONEMINAVGMAXLINEAR, tr.refdef.toneMinAvgMaxLinear);
RB_InstantQuad2(quadVerts, texCoords); //, color, shaderProgram, invTexRes);
// need the depth in a texture we can do GL_LINEAR sampling on, so copy it to an HDR image
FBO_BlitFromTexture(tr.renderDepthImage, NULL, NULL, tr.hdrDepthFbo, NULL, NULL, NULL, 0);
}
if (backEnd.viewParms.flags & VPF_USESUNLIGHT)
@ -1584,7 +1548,7 @@ const void *RB_ClearDepth(const void *data)
if (glRefConfig.framebufferObject)
{
if (backEnd.framePostProcessed)
if (!tr.renderFbo || backEnd.framePostProcessed)
{
FBO_Bind(tr.screenScratchFbo);
}
@ -1599,7 +1563,7 @@ const void *RB_ClearDepth(const void *data)
// if we're doing MSAA, clear the depth texture for the resolve buffer
if (tr.msaaResolveFbo)
{
FBO_Bind(tr.screenScratchFbo);
FBO_Bind(tr.msaaResolveFbo);
qglClear(GL_DEPTH_BUFFER_BIT);
}
@ -1648,33 +1612,23 @@ const void *RB_SwapBuffers( const void *data ) {
if (glRefConfig.framebufferObject)
{
// copy final image to screen
vec4_t color;
if (backEnd.framePostProcessed)
if (!backEnd.framePostProcessed)
{
// frame was postprocessed into screen fbo, copy from there
if (tr.msaaResolveFbo && r_hdr->integer)
{
// Resolving an RGB16F MSAA FBO to the screen messes with the brightness, so resolve to an RGB16F FBO first
FBO_FastBlit(tr.renderFbo, NULL, tr.msaaResolveFbo, NULL, GL_COLOR_BUFFER_BIT, GL_NEAREST);
FBO_FastBlit(tr.msaaResolveFbo, NULL, tr.screenScratchFbo, NULL, GL_COLOR_BUFFER_BIT, GL_NEAREST);
}
else if (!glRefConfig.framebuffer_srgb)
else if (tr.renderFbo)
{
// Copy render to screenscratch, possibly resolving MSAA
FBO_FastBlit(tr.renderFbo, NULL, tr.screenScratchFbo, NULL, GL_COLOR_BUFFER_BIT, GL_NEAREST);
}
else
{
FBO_t *srcFbo = tr.renderFbo;
if (tr.msaaResolveFbo)
{
// Resolve the MSAA before copying
FBO_FastBlit(srcFbo, NULL, tr.msaaResolveFbo, NULL, GL_COLOR_BUFFER_BIT, GL_NEAREST);
srcFbo = tr.msaaResolveFbo;
}
// need to copy from resolve to screenscratch to fix gamma
FBO_Blit(srcFbo, NULL, NULL, tr.screenScratchFbo, NULL, NULL, NULL, 0);
}
if (tr.screenScratchFbo)
{
vec4_t color;
color[0] =
color[1] =
@ -1690,6 +1644,7 @@ const void *RB_SwapBuffers( const void *data ) {
if (backEnd.colorMask[0] || backEnd.colorMask[1] || backEnd.colorMask[2] || backEnd.colorMask[3])
qglColorMask(!backEnd.colorMask[0], !backEnd.colorMask[1], !backEnd.colorMask[2], !backEnd.colorMask[3]);
}
}
if ( !glState.finishCalled ) {
qglFinish();
@ -1750,11 +1705,9 @@ const void *RB_PostProcess(const void *data)
FBO_t *srcFbo;
qboolean autoExposure;
if (!glRefConfig.framebufferObject)
if (!glRefConfig.framebufferObject || !r_postProcess->integer)
{
// do nothing
backEnd.framePostProcessed = qtrue;
return (const void *)(cmd + 1);
}
@ -1766,16 +1719,16 @@ const void *RB_PostProcess(const void *data)
srcFbo = tr.msaaResolveFbo;
}
if (r_postProcess->integer && r_ssao->integer)
if (r_ssao->integer)
{
vec4i_t dstBox;
VectorSet4(dstBox, 0, 0, srcFbo->width, srcFbo->height);
FBO_BlitFromTexture(tr.screenSsaoImage, NULL, NULL, srcFbo, dstBox, NULL, NULL, GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_ZERO);
FBO_BlitFromTexture(tr.screenSsaoImage, NULL, NULL, srcFbo, NULL, NULL, NULL, GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_ZERO);
}
if (r_postProcess->integer && (r_toneMap->integer || r_forceToneMap->integer))
if (srcFbo)
{
autoExposure = r_autoExposure->integer || r_forceAutoExposure;
if (r_hdr->integer && (r_toneMap->integer || r_forceToneMap->integer))
{
autoExposure = r_autoExposure->integer || r_forceAutoExposure->integer;
RB_ToneMap(srcFbo, autoExposure);
}
else if (!glRefConfig.framebuffer_srgb && r_cameraExposure->value == 0.0f)
@ -1793,9 +1746,10 @@ const void *RB_PostProcess(const void *data)
FBO_Blit(srcFbo, NULL, NULL, tr.screenScratchFbo, NULL, NULL, color, 0);
}
}
#ifdef REACTION
if (r_postProcess->integer && glRefConfig.framebufferObject)
if (1)
{
RB_GodRays();
@ -1820,16 +1774,16 @@ const void *RB_PostProcess(const void *data)
if (0)
{
vec4i_t dstBox;
VectorSet4(dstBox, 256, tr.screenScratchFbo->height - 256, 256, 256);
VectorSet4(dstBox, 256, glConfig.vidHeight - 256, 256, 256);
FBO_BlitFromTexture(tr.renderDepthImage, NULL, NULL, tr.screenScratchFbo, dstBox, NULL, NULL, 0);
VectorSet4(dstBox, 512, tr.screenScratchFbo->height - 256, 256, 256);
VectorSet4(dstBox, 512, glConfig.vidHeight - 256, 256, 256);
FBO_BlitFromTexture(tr.screenShadowImage, NULL, NULL, tr.screenScratchFbo, dstBox, NULL, NULL, 0);
}
if (0)
{
vec4i_t dstBox;
VectorSet4(dstBox, 256, tr.screenScratchFbo->height - 256, 256, 256);
VectorSet4(dstBox, 256, glConfig.vidHeight - 256, 256, 256);
FBO_BlitFromTexture(tr.renderImage, NULL, NULL, tr.screenScratchFbo, dstBox, NULL, NULL, 0);
}

View file

@ -502,29 +502,21 @@ void RE_BeginFrame( stereoFrame_t stereoFrame ) {
if (glRefConfig.framebufferObject)
{
// clear all framebuffers
// FIXME: must be a better way to do this
int i;
for (i = 0; i < 3; i++)
if (tr.msaaResolveFbo)
{
if (i == 1 && !tr.msaaResolveFbo)
continue;
switch(i)
{
case 0:
FBO_Bind(tr.renderFbo);
break;
case 1:
FBO_Bind(tr.msaaResolveFbo);
break;
case 2:
FBO_Bind(tr.screenScratchFbo);
break;
qglClear(GL_COLOR_BUFFER_BIT);
}
if (tr.renderFbo)
{
FBO_Bind(tr.renderFbo);
qglClear(GL_COLOR_BUFFER_BIT);
}
if (tr.screenScratchFbo)
{
FBO_Bind(tr.screenScratchFbo);
qglClear(GL_COLOR_BUFFER_BIT);
}

View file

@ -309,7 +309,7 @@ FBO_Bind
*/
void FBO_Bind(FBO_t * fbo)
{
if (fbo && glState.currentFBO == fbo)
if (glState.currentFBO == fbo)
return;
if (r_logFile->integer)
@ -405,6 +405,8 @@ void FBO_Init(void)
ri.Cvar_SetValue("r_ext_framebuffer_multisample", (float)multisample);
}
// only create a render FBO if we need to resolve MSAA or do HDR
// otherwise just render straight to the screen (tr.renderFbo = NULL)
if (multisample && glRefConfig.framebufferMultisample)
{
tr.renderFbo = FBO_Create("_render", tr.renderDepthImage->width, tr.renderDepthImage->height);
@ -427,7 +429,7 @@ void FBO_Init(void)
R_CheckFBO(tr.msaaResolveFbo);
}
else
else if (r_hdr->integer)
{
tr.renderFbo = FBO_Create("_render", tr.renderDepthImage->width, tr.renderDepthImage->height);
FBO_Bind(tr.renderFbo);
@ -443,10 +445,13 @@ void FBO_Init(void)
// clear render buffer
// this fixes the corrupt screen bug with r_hdr 1 on older hardware
if (tr.renderFbo)
{
FBO_Bind(tr.renderFbo);
qglClearColor( 1, 0, 0.5, 1 );
qglClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
FBO_Bind(NULL);
}
#ifdef REACTION
{
@ -525,6 +530,7 @@ void FBO_Init(void)
R_CheckFBO(tr.targetLevelsFbo);
}
if (r_softOverbright->integer)
{
//tr.screenScratchFbo = FBO_Create("_screenscratch", width, height);
tr.screenScratchFbo = FBO_Create("_screenscratch", tr.screenScratchImage->width, tr.screenScratchImage->height);

View file

@ -2943,6 +2943,7 @@ void R_CreateBuiltinImages( void ) {
tr.godRaysImage = R_CreateImage("*godRays", NULL, width, height, IMGTYPE_COLORALPHA, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, GL_RGBA8);
#endif
if (r_softOverbright->integer)
{
int format;
@ -3033,14 +3034,14 @@ void R_SetColorMappings( void ) {
tr.overbrightBits = 0; // need hardware gamma for overbright
}
// never overbright in windowed mode
if ( 0 /* !glConfig.isFullscreen */ )
// never overbright in windowed mode without soft overbright
if ( !glConfig.isFullscreen && !r_softOverbright->integer )
{
tr.overbrightBits = 0;
}
// never overbright with tonemapping
if ( r_toneMap->integer )
if ( r_toneMap->integer && r_hdr->integer )
{
tr.overbrightBits = 0;
}
@ -3077,8 +3078,11 @@ void R_SetColorMappings( void ) {
shift = tr.overbrightBits;
if (glRefConfig.framebufferObject)
// no shift with soft overbright
if (r_softOverbright->integer)
{
shift = 0;
}
for ( i = 0; i < 256; i++ ) {
if ( g == 1 ) {

View file

@ -107,6 +107,9 @@ cvar_t *r_mergeMultidraws;
cvar_t *r_mergeLeafSurfaces;
cvar_t *r_cameraExposure;
cvar_t *r_softOverbright;
cvar_t *r_hdr;
cvar_t *r_postProcess;
@ -1149,6 +1152,8 @@ void R_Register( void )
r_greyscale = ri.Cvar_Get("r_greyscale", "0", CVAR_ARCHIVE | CVAR_LATCH);
ri.Cvar_CheckRange(r_greyscale, 0, 1, qfalse);
r_softOverbright = ri.Cvar_Get( "r_softOverbright", "1", CVAR_ARCHIVE | CVAR_LATCH );
r_hdr = ri.Cvar_Get( "r_hdr", "1", CVAR_ARCHIVE | CVAR_LATCH );
r_postProcess = ri.Cvar_Get( "r_postProcess", "1", CVAR_ARCHIVE );

View file

@ -2092,6 +2092,8 @@ extern cvar_t *r_anaglyphMode;
extern cvar_t *r_mergeMultidraws;
extern cvar_t *r_mergeLeafSurfaces;
extern cvar_t *r_softOverbright;
extern cvar_t *r_hdr;
extern cvar_t *r_postProcess;

View file

@ -112,14 +112,16 @@ void RB_BokehBlur(float blur)
if (blur > 0.0f)
{
// create a quarter texture
FBO_Blit(tr.screenScratchFbo, NULL, NULL, tr.quarterFbo[0], NULL, NULL, NULL, 0);
//FBO_Blit(NULL, NULL, NULL, tr.quarterFbo[0], NULL, NULL, NULL, 0);
FBO_FastBlit(tr.screenScratchFbo, NULL, tr.quarterFbo[0], NULL, GL_COLOR_BUFFER_BIT, GL_LINEAR);
}
#ifndef HQ_BLUR
if (blur > 1.0f)
{
// create a 1/16th texture
FBO_Blit(tr.quarterFbo[0], NULL, NULL, tr.textureScratchFbo[0], NULL, NULL, NULL, 0);
//FBO_Blit(tr.quarterFbo[0], NULL, NULL, tr.textureScratchFbo[0], NULL, NULL, NULL, 0);
FBO_FastBlit(tr.quarterFbo[0], NULL, tr.textureScratchFbo[0], NULL, GL_COLOR_BUFFER_BIT, GL_LINEAR);
}
#endif
@ -340,15 +342,14 @@ void RB_GodRays(void)
VectorSet4(color, mul, mul, mul, 1);
// first, downsample the framebuffer
VectorSet4(srcBox, 0, 0, tr.godRaysFbo->width, tr.godRaysFbo->height);
VectorSet4(dstBox, 0, 0, tr.quarterFbo[0]->width, tr.quarterFbo[0]->height);
FBO_Blit(tr.godRaysFbo, srcBox, texScale, tr.quarterFbo[0], dstBox, &tr.textureColorShader, color, 0);
if (colorize)
{
VectorSet4(srcBox, 0, 0, tr.screenScratchFbo->width, tr.screenScratchFbo->height);
FBO_Blit(tr.screenScratchFbo, srcBox, texScale, tr.quarterFbo[0], dstBox, &tr.textureColorShader, color,
GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_ZERO);
FBO_FastBlit(tr.screenScratchFbo, NULL, tr.quarterFbo[0], NULL, GL_COLOR_BUFFER_BIT, GL_LINEAR);
FBO_Blit(tr.godRaysFbo, NULL, NULL, tr.quarterFbo[0], NULL, NULL, color, GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_ZERO);
}
else
{
FBO_FastBlit(tr.godRaysFbo, NULL, tr.quarterFbo[0], NULL, GL_COLOR_BUFFER_BIT, GL_LINEAR);
}
}
@ -375,7 +376,7 @@ void RB_GodRays(void)
VectorSet4(color, mul, mul, mul, 1);
VectorSet4(srcBox, 0, 0, tr.quarterFbo[0]->width, tr.quarterFbo[0]->height);
VectorSet4(dstBox, 0, 0, tr.screenScratchFbo->width, tr.screenScratchFbo->height);
VectorSet4(dstBox, 0, 0, glConfig.vidWidth, glConfig.vidHeight);
FBO_Blit(tr.quarterFbo[0], srcBox, texScale, tr.screenScratchFbo, dstBox, &tr.textureColorShader, color, GLS_SRCBLEND_ONE | GLS_DSTBLEND_ONE);
}
}
@ -462,13 +463,8 @@ void RB_GaussianBlur(float blur)
VectorSet4(color, 1, 1, 1, 1);
// first, downsample the framebuffer
VectorSet4(srcBox, 0, 0, tr.screenScratchFbo->width, tr.screenScratchFbo->height);
VectorSet4(dstBox, 0, 0, tr.quarterFbo[0]->width, tr.quarterFbo[0]->height);
FBO_Blit(tr.screenScratchFbo, srcBox, texScale, tr.quarterFbo[0], dstBox, &tr.textureColorShader, color, 0);
VectorSet4(srcBox, 0, 0, tr.quarterFbo[0]->width, tr.quarterFbo[0]->height);
VectorSet4(dstBox, 0, 0, tr.textureScratchFbo[0]->width, tr.textureScratchFbo[0]->height);
FBO_Blit(tr.quarterFbo[0], srcBox, texScale, tr.textureScratchFbo[0], dstBox, &tr.textureColorShader, color, 0);
FBO_FastBlit(tr.screenScratchFbo, NULL, tr.quarterFbo[0], NULL, GL_COLOR_BUFFER_BIT, GL_LINEAR);
FBO_FastBlit(tr.quarterFbo[0], NULL, tr.textureScratchFbo[0], NULL, GL_COLOR_BUFFER_BIT, GL_LINEAR);
// set the alpha channel
VectorSet4(srcBox, 0, 0, tr.whiteImage->width, tr.whiteImage->height);
@ -483,7 +479,7 @@ void RB_GaussianBlur(float blur)
// finally, merge back to framebuffer
VectorSet4(srcBox, 0, 0, tr.textureScratchFbo[0]->width, tr.textureScratchFbo[0]->height);
VectorSet4(dstBox, 0, 0, tr.screenScratchFbo->width, tr.screenScratchFbo->height);
VectorSet4(dstBox, 0, 0, glConfig.vidWidth, glConfig.vidHeight);
color[3] = factor;
FBO_Blit(tr.textureScratchFbo[0], srcBox, texScale, tr.screenScratchFbo, dstBox, &tr.textureColorShader, color, GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA);
}

View file

@ -99,6 +99,12 @@ Cvars for simple rendering features:
0 - No. (default)
1 - Yes.
r_softOverbright - Enable software overbrighting. This enables
overbrighting even in a window. Is disabled
when r_toneMap 1 and r_hdr 1.
0 - No.
1 - Yes. (default)
Cvars for HDR and tonemapping:
r_hdr - Do scene rendering in a framebuffer with
high dynamic range. (Less banding, and