mirror of
https://github.com/UberGames/ioef.git
synced 2024-11-27 14:32:55 +00:00
OpenGL2: Reimplement soft overbright to avoid a framebuffer blit.
This commit is contained in:
parent
a7c5fc0ee7
commit
8c3ae8d7d2
8 changed files with 70 additions and 79 deletions
|
@ -449,7 +449,7 @@ void RB_BeginDrawingView (void) {
|
|||
{
|
||||
if (!tr.renderFbo || (backEnd.framePostProcessed && (backEnd.refdef.rdflags & RDF_NOWORLDMODEL)))
|
||||
{
|
||||
FBO_Bind(tr.screenScratchFbo);
|
||||
FBO_Bind(NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -859,7 +859,7 @@ void RE_StretchRaw (int x, int y, int w, int h, int cols, int rows, const byte *
|
|||
{
|
||||
if (!tr.renderFbo || backEnd.framePostProcessed)
|
||||
{
|
||||
FBO_Bind(tr.screenScratchFbo);
|
||||
FBO_Bind(NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -946,7 +946,7 @@ const void *RB_StretchPic ( const void *data ) {
|
|||
{
|
||||
if (!tr.renderFbo || backEnd.framePostProcessed)
|
||||
{
|
||||
FBO_Bind(tr.screenScratchFbo);
|
||||
FBO_Bind(NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1443,7 +1443,7 @@ const void *RB_ClearDepth(const void *data)
|
|||
{
|
||||
if (!tr.renderFbo || backEnd.framePostProcessed)
|
||||
{
|
||||
FBO_Bind(tr.screenScratchFbo);
|
||||
FBO_Bind(NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1512,32 +1512,13 @@ const void *RB_SwapBuffers( const void *data ) {
|
|||
{
|
||||
// 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);
|
||||
FBO_FastBlit(tr.msaaResolveFbo, NULL, NULL, NULL, GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
}
|
||||
else if (tr.renderFbo)
|
||||
{
|
||||
FBO_FastBlit(tr.renderFbo, NULL, tr.screenScratchFbo, NULL, GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
FBO_FastBlit(tr.renderFbo, NULL, NULL, NULL, GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
}
|
||||
}
|
||||
|
||||
if (tr.screenScratchFbo)
|
||||
{
|
||||
vec4_t color;
|
||||
|
||||
color[0] =
|
||||
color[1] =
|
||||
color[2] = pow(2, tr.overbrightBits); //exp2(tr.overbrightBits);
|
||||
color[3] = 1.0f;
|
||||
|
||||
// turn off colormask when copying final image
|
||||
if (backEnd.colorMask[0] || backEnd.colorMask[1] || backEnd.colorMask[2] || backEnd.colorMask[3])
|
||||
qglColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||
|
||||
FBO_Blit(tr.screenScratchFbo, NULL, NULL, NULL, NULL, NULL, color, 0);
|
||||
|
||||
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 ) {
|
||||
|
@ -1654,11 +1635,11 @@ const void *RB_PostProcess(const void *data)
|
|||
if (r_hdr->integer && (r_toneMap->integer || r_forceToneMap->integer))
|
||||
{
|
||||
autoExposure = r_autoExposure->integer || r_forceAutoExposure->integer;
|
||||
RB_ToneMap(srcFbo, srcBox, tr.screenScratchFbo, dstBox, autoExposure);
|
||||
RB_ToneMap(srcFbo, srcBox, NULL, dstBox, autoExposure);
|
||||
}
|
||||
else if (r_cameraExposure->value == 0.0f)
|
||||
{
|
||||
FBO_FastBlit(srcFbo, srcBox, tr.screenScratchFbo, dstBox, GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
FBO_FastBlit(srcFbo, srcBox, NULL, dstBox, GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1669,15 +1650,15 @@ const void *RB_PostProcess(const void *data)
|
|||
color[2] = pow(2, r_cameraExposure->value); //exp2(r_cameraExposure->value);
|
||||
color[3] = 1.0f;
|
||||
|
||||
FBO_Blit(srcFbo, srcBox, NULL, tr.screenScratchFbo, dstBox, NULL, color, 0);
|
||||
FBO_Blit(srcFbo, srcBox, NULL, NULL, dstBox, NULL, color, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (r_drawSunRays->integer)
|
||||
RB_SunRays(tr.screenScratchFbo, srcBox, tr.screenScratchFbo, dstBox);
|
||||
RB_SunRays(NULL, srcBox, NULL, dstBox);
|
||||
|
||||
if (1)
|
||||
RB_BokehBlur(tr.screenScratchFbo, srcBox, tr.screenScratchFbo, dstBox, backEnd.refdef.blurFactor);
|
||||
RB_BokehBlur(NULL, srcBox, NULL, dstBox, backEnd.refdef.blurFactor);
|
||||
else
|
||||
RB_GaussianBlur(backEnd.refdef.blurFactor);
|
||||
|
||||
|
@ -1685,27 +1666,27 @@ const void *RB_PostProcess(const void *data)
|
|||
{
|
||||
vec4i_t dstBox;
|
||||
VectorSet4(dstBox, 0, 0, 128, 128);
|
||||
FBO_BlitFromTexture(tr.sunShadowDepthImage[0], NULL, NULL, tr.screenScratchFbo, dstBox, NULL, NULL, 0);
|
||||
FBO_BlitFromTexture(tr.sunShadowDepthImage[0], NULL, NULL, NULL, dstBox, NULL, NULL, 0);
|
||||
VectorSet4(dstBox, 128, 0, 128, 128);
|
||||
FBO_BlitFromTexture(tr.sunShadowDepthImage[1], NULL, NULL, tr.screenScratchFbo, dstBox, NULL, NULL, 0);
|
||||
FBO_BlitFromTexture(tr.sunShadowDepthImage[1], NULL, NULL, NULL, dstBox, NULL, NULL, 0);
|
||||
VectorSet4(dstBox, 256, 0, 128, 128);
|
||||
FBO_BlitFromTexture(tr.sunShadowDepthImage[2], NULL, NULL, tr.screenScratchFbo, dstBox, NULL, NULL, 0);
|
||||
FBO_BlitFromTexture(tr.sunShadowDepthImage[2], NULL, NULL, NULL, dstBox, NULL, NULL, 0);
|
||||
}
|
||||
|
||||
if (0)
|
||||
{
|
||||
vec4i_t dstBox;
|
||||
VectorSet4(dstBox, 256, glConfig.vidHeight - 256, 256, 256);
|
||||
FBO_BlitFromTexture(tr.renderDepthImage, NULL, NULL, tr.screenScratchFbo, dstBox, NULL, NULL, 0);
|
||||
FBO_BlitFromTexture(tr.renderDepthImage, NULL, NULL, NULL, dstBox, NULL, NULL, 0);
|
||||
VectorSet4(dstBox, 512, glConfig.vidHeight - 256, 256, 256);
|
||||
FBO_BlitFromTexture(tr.screenShadowImage, NULL, NULL, tr.screenScratchFbo, dstBox, NULL, NULL, 0);
|
||||
FBO_BlitFromTexture(tr.screenShadowImage, NULL, NULL, NULL, dstBox, NULL, NULL, 0);
|
||||
}
|
||||
|
||||
if (0)
|
||||
{
|
||||
vec4i_t dstBox;
|
||||
VectorSet4(dstBox, 256, glConfig.vidHeight - 256, 256, 256);
|
||||
FBO_BlitFromTexture(tr.sunRaysImage, NULL, NULL, tr.screenScratchFbo, dstBox, NULL, NULL, 0);
|
||||
FBO_BlitFromTexture(tr.sunRaysImage, NULL, NULL, NULL, dstBox, NULL, NULL, 0);
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
@ -1717,8 +1698,8 @@ const void *RB_PostProcess(const void *data)
|
|||
if (cubemapIndex)
|
||||
{
|
||||
VectorSet4(dstBox, 0, glConfig.vidHeight - 256, 256, 256);
|
||||
//FBO_BlitFromTexture(tr.renderCubeImage, NULL, NULL, tr.screenScratchFbo, dstBox, &tr.testcubeShader, NULL, 0);
|
||||
FBO_BlitFromTexture(tr.cubemaps[cubemapIndex - 1], NULL, NULL, tr.screenScratchFbo, dstBox, &tr.testcubeShader, NULL, 0);
|
||||
//FBO_BlitFromTexture(tr.renderCubeImage, NULL, NULL, NULL, dstBox, &tr.testcubeShader, NULL, 0);
|
||||
FBO_BlitFromTexture(tr.cubemaps[cubemapIndex - 1], NULL, NULL, NULL, dstBox, &tr.testcubeShader, NULL, 0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -442,12 +442,6 @@ void RE_BeginFrame( stereoFrame_t stereoFrame ) {
|
|||
qglClear(GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
|
||||
if (tr.screenScratchFbo)
|
||||
{
|
||||
FBO_Bind(tr.screenScratchFbo);
|
||||
qglClear(GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
|
||||
FBO_Bind(NULL);
|
||||
}
|
||||
|
||||
|
|
|
@ -526,22 +526,6 @@ 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);
|
||||
FBO_Bind(tr.screenScratchFbo);
|
||||
|
||||
//FBO_CreateBuffer(tr.screenScratchFbo, format, 0, 0);
|
||||
FBO_AttachTextureImage(tr.screenScratchImage, 0);
|
||||
|
||||
// FIXME: hack: share zbuffer between render fbo and pre-screen fbo
|
||||
//FBO_CreateBuffer(tr.screenScratchFbo, GL_DEPTH_COMPONENT24_ARB, 0, 0);
|
||||
R_AttachFBOTextureDepth(tr.renderDepthImage->texnum);
|
||||
|
||||
R_CheckFBO(tr.screenScratchFbo);
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
tr.quarterFbo[i] = FBO_Create(va("_quarter%d", i), tr.quarterImage[i]->width, tr.quarterImage[i]->height);
|
||||
|
|
|
@ -2931,9 +2931,6 @@ void R_CreateBuiltinImages( void ) {
|
|||
if (r_drawSunRays->integer)
|
||||
tr.sunRaysImage = R_CreateImage("*sunRays", NULL, width, height, IMGTYPE_COLORALPHA, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, rgbFormat);
|
||||
|
||||
if (r_softOverbright->integer)
|
||||
tr.screenScratchImage = R_CreateImage("*screenScratch", NULL, width, height, IMGTYPE_COLORALPHA, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, rgbFormat);
|
||||
|
||||
if (glRefConfig.framebufferObject)
|
||||
{
|
||||
tr.renderDepthImage = R_CreateImage("*renderdepth", NULL, width, height, IMGTYPE_COLORALPHA, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, GL_DEPTH_COMPONENT24_ARB);
|
||||
|
|
|
@ -1620,7 +1620,6 @@ typedef struct {
|
|||
image_t *renderDepthImage;
|
||||
image_t *pshadowMaps[MAX_DRAWN_PSHADOWS];
|
||||
image_t *textureScratchImage[2];
|
||||
image_t *screenScratchImage;
|
||||
image_t *quarterImage[2];
|
||||
image_t *calcLevelsImage;
|
||||
image_t *targetLevelsImage;
|
||||
|
@ -1639,7 +1638,6 @@ typedef struct {
|
|||
FBO_t *depthFbo;
|
||||
FBO_t *pshadowFbos[MAX_DRAWN_PSHADOWS];
|
||||
FBO_t *textureScratchFbo[2];
|
||||
FBO_t *screenScratchFbo;
|
||||
FBO_t *quarterFbo[2];
|
||||
FBO_t *calcLevelsFbo;
|
||||
FBO_t *targetLevelsFbo;
|
||||
|
|
|
@ -255,10 +255,20 @@ static void RB_RadialBlur(FBO_t *srcFbo, FBO_t *dstFbo, int passes, float stretc
|
|||
float s1 = iscale + s0;
|
||||
float t1 = iscale + t0;
|
||||
|
||||
srcBox[0] = s0 * srcFbo->width;
|
||||
srcBox[1] = t0 * srcFbo->height;
|
||||
srcBox[2] = (s1 - s0) * srcFbo->width;
|
||||
srcBox[3] = (t1 - t0) * srcFbo->height;
|
||||
if (srcFbo)
|
||||
{
|
||||
srcBox[0] = s0 * srcFbo->width;
|
||||
srcBox[1] = t0 * srcFbo->height;
|
||||
srcBox[2] = (s1 - s0) * srcFbo->width;
|
||||
srcBox[3] = (t1 - t0) * srcFbo->height;
|
||||
}
|
||||
else
|
||||
{
|
||||
srcBox[0] = s0 * glConfig.vidWidth;
|
||||
srcBox[1] = t0 * glConfig.vidHeight;
|
||||
srcBox[2] = (s1 - s0) * glConfig.vidWidth;
|
||||
srcBox[3] = (t1 - t0) * glConfig.vidHeight;
|
||||
}
|
||||
|
||||
FBO_Blit(srcFbo, srcBox, texScale, dstFbo, dstBox, &tr.textureColorShader, color, GLS_SRCBLEND_ONE | GLS_DSTBLEND_ONE );
|
||||
|
||||
|
@ -351,10 +361,20 @@ void RB_SunRays(FBO_t *srcFbo, vec4i_t srcBox, FBO_t *dstFbo, vec4i_t dstBox)
|
|||
|
||||
VectorSet4(color, mul, mul, mul, 1);
|
||||
|
||||
rayBox[0] = srcBox[0] * tr.sunRaysFbo->width / srcFbo->width;
|
||||
rayBox[1] = srcBox[1] * tr.sunRaysFbo->height / srcFbo->height;
|
||||
rayBox[2] = srcBox[2] * tr.sunRaysFbo->width / srcFbo->width;
|
||||
rayBox[3] = srcBox[3] * tr.sunRaysFbo->height / srcFbo->height;
|
||||
if (srcFbo)
|
||||
{
|
||||
rayBox[0] = srcBox[0] * tr.sunRaysFbo->width / srcFbo->width;
|
||||
rayBox[1] = srcBox[1] * tr.sunRaysFbo->height / srcFbo->height;
|
||||
rayBox[2] = srcBox[2] * tr.sunRaysFbo->width / srcFbo->width;
|
||||
rayBox[3] = srcBox[3] * tr.sunRaysFbo->height / srcFbo->height;
|
||||
}
|
||||
else
|
||||
{
|
||||
rayBox[0] = srcBox[0] * tr.sunRaysFbo->width / glConfig.vidWidth;
|
||||
rayBox[1] = srcBox[1] * tr.sunRaysFbo->height / glConfig.vidHeight;
|
||||
rayBox[2] = srcBox[2] * tr.sunRaysFbo->width / glConfig.vidWidth;
|
||||
rayBox[3] = srcBox[3] * tr.sunRaysFbo->height / glConfig.vidHeight;
|
||||
}
|
||||
|
||||
quarterBox[0] = 0;
|
||||
quarterBox[1] = tr.quarterFbo[0]->height;
|
||||
|
@ -480,7 +500,7 @@ void RB_GaussianBlur(float blur)
|
|||
VectorSet4(color, 1, 1, 1, 1);
|
||||
|
||||
// first, downsample the framebuffer
|
||||
FBO_FastBlit(tr.screenScratchFbo, NULL, tr.quarterFbo[0], NULL, GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
||||
FBO_FastBlit(NULL, 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
|
||||
|
@ -498,6 +518,6 @@ void RB_GaussianBlur(float blur)
|
|||
VectorSet4(srcBox, 0, 0, tr.textureScratchFbo[0]->width, tr.textureScratchFbo[0]->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);
|
||||
FBO_Blit(tr.textureScratchFbo[0], srcBox, texScale, NULL, dstBox, &tr.textureColorShader, color, GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -443,7 +443,7 @@ static void ProjectDlightTexture( void ) {
|
|||
}
|
||||
|
||||
|
||||
static void ComputeShaderColors( shaderStage_t *pStage, vec4_t baseColor, vec4_t vertColor )
|
||||
static void ComputeShaderColors( shaderStage_t *pStage, vec4_t baseColor, vec4_t vertColor, int blend )
|
||||
{
|
||||
baseColor[0] =
|
||||
baseColor[1] =
|
||||
|
@ -601,6 +601,23 @@ static void ComputeShaderColors( shaderStage_t *pStage, vec4_t baseColor, vec4_t
|
|||
break;
|
||||
}
|
||||
|
||||
// multiply color by overbrightbits if this isn't a blend
|
||||
if (r_softOverbright->integer && tr.overbrightBits
|
||||
&& !((blend & GLS_SRCBLEND_BITS) == GLS_SRCBLEND_DST_COLOR)
|
||||
&& !((blend & GLS_SRCBLEND_BITS) == GLS_SRCBLEND_ONE_MINUS_DST_COLOR)
|
||||
&& !((blend & GLS_DSTBLEND_BITS) == GLS_DSTBLEND_SRC_COLOR)
|
||||
&& !((blend & GLS_DSTBLEND_BITS) == GLS_DSTBLEND_ONE_MINUS_SRC_COLOR))
|
||||
{
|
||||
float scale = 1 << tr.overbrightBits;
|
||||
|
||||
baseColor[0] *= scale;
|
||||
baseColor[1] *= scale;
|
||||
baseColor[2] *= scale;
|
||||
vertColor[0] *= scale;
|
||||
vertColor[1] *= scale;
|
||||
vertColor[2] *= scale;
|
||||
}
|
||||
|
||||
// FIXME: find some way to implement this.
|
||||
#if 0
|
||||
// if in greyscale rendering mode turn all color values into greyscale.
|
||||
|
@ -769,7 +786,7 @@ static void ForwardDlight( void ) {
|
|||
vec4_t baseColor;
|
||||
vec4_t vertColor;
|
||||
|
||||
ComputeShaderColors(pStage, baseColor, vertColor);
|
||||
ComputeShaderColors(pStage, baseColor, vertColor, GLS_SRCBLEND_ONE | GLS_DSTBLEND_ONE);
|
||||
|
||||
GLSL_SetUniformVec4(sp, UNIFORM_BASECOLOR, baseColor);
|
||||
GLSL_SetUniformVec4(sp, UNIFORM_VERTCOLOR, vertColor);
|
||||
|
@ -1141,7 +1158,7 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )
|
|||
vec4_t baseColor;
|
||||
vec4_t vertColor;
|
||||
|
||||
ComputeShaderColors(pStage, baseColor, vertColor);
|
||||
ComputeShaderColors(pStage, baseColor, vertColor, pStage->stateBits);
|
||||
|
||||
if ((backEnd.refdef.colorScale != 1.0f) && !(backEnd.refdef.rdflags & RDF_NOWORLDMODEL))
|
||||
{
|
||||
|
|
|
@ -449,7 +449,7 @@ static void DrawSkySide( struct image_s *image, const int mins[2], const int max
|
|||
|
||||
color[0] =
|
||||
color[1] =
|
||||
color[2] = tr.identityLight * backEnd.refdef.colorScale;
|
||||
color[2] = (r_softOverbright->integer ? 1.0 : tr.identityLight) * backEnd.refdef.colorScale;
|
||||
color[3] = 1.0f;
|
||||
GLSL_SetUniformVec4(sp, UNIFORM_BASECOLOR, color);
|
||||
|
||||
|
|
Loading…
Reference in a new issue