Conversation
f5e4556 to
d7013c8
Compare
|
I verified that we don't have strong differences with the original I used that as reference: Which I assume is supposedly a copy of (now broken link):
I have no idea where our bug is living. |
d7013c8 to
a02cb5e
Compare
|
When doing this: diff --git a/src/engine/renderer/glsl_source/fxaa3_11_fp.glsl b/src/engine/renderer/glsl_source/fxaa3_11_fp.glsl
index dd3757b08..c4ed80f73 100644
--- a/src/engine/renderer/glsl_source/fxaa3_11_fp.glsl
+++ b/src/engine/renderer/glsl_source/fxaa3_11_fp.glsl
@@ -1240,6 +1240,7 @@ FxaaFloat4 FxaaPixelShader(
#if (FXAA_DISCARD == 1)
return FxaaTexTop(tex, posM);
#else
+ return vec4(1.0, 0.0, 0.0, 1.0);
return FxaaFloat4(FxaaTexTop(tex, posM).xyz, lumaM);
#endif
}We see that the edges are properly detected: But the data written to those areas is garbage. |
|
Since the edge detection worked, I assumed that was the sampling that was broken. I tested using Without FXAA: With FXAA: Here are pixels modified by FXAA with Here are pixels modified by FXAA with This last screenshot is NOT the painting of pixels expected to be modified by FXAA by returning red as FXAA return value (like in previous comment), it is the painting of pixels actually modified by FXAA, by comparing the input and the output of the FXAA computation and painting in red what changed. |
|
So I checked the history, and that |
|
I'm now git blaming the XreaL code (the git reference below is from a locally converted repository), and our code: imageParams.filterType = filterType_t::FT_NEAREST;
imageParams.wrapType = wrapTypeEnum_t::WT_CLAMP;
tr.currentRenderImage[0] = R_CreateImage( "*currentRender0", nullptr, width, height, 1, imageParams );
tr.currentRenderImage[1] = R_CreateImage( "*currentRender1", nullptr, width, height, 1, imageParams );is ultimately deriving from: commit af8e5637ae850c20f375ba198acbe2dc4060e4f1
Author: Robert “Tr3B” Beckebans <xxx>
Date: Sun Sep 10 20:53:54 2006 +0000
simplified render to texture
diff --git a/xreal/code/renderer/tr_image.c b/xreal/code/renderer/tr_image.c
index cafe1ba4..ec253ec2 100644
--- a/xreal/code/renderer/tr_image.c
+++ b/xreal/code/renderer/tr_image.c
@@ -4540,38 +4540,7 @@ static void R_CreateCurrentRenderImage(void)
data = ri.Hunk_AllocateTempMemory(width * height * 4);
- tr.currentRenderImage = R_CreateImage("_currentRender", data, width, height, IF_NOPICMIP, FT_DEFAULT, WT_REPEAT);
-
- ri.Hunk_FreeTempMemory(data);
-}
-
-static void R_CreateCurrentRenderLinearImage(void)
-{
- int width, height;
- byte *data;
-
- width = NearestPowerOfTwo(glConfig.vidWidth);
- height = NearestPowerOfTwo(glConfig.vidHeight);
-
- data = ri.Hunk_AllocateTempMemory(width * height * 4);
-
- tr.currentRenderLinearImage = R_CreateImage("_currentRenderLinear", data, width, height, IF_NOPICMIP, FT_LINEAR, WT_REPEAT);
-
- ri.Hunk_FreeTempMemory(data);
-}
-
-static void R_CreateCurrentRenderNearestImage(void)
-{
- int width, height;
- byte *data;
-
- width = NearestPowerOfTwo(glConfig.vidWidth);
- height = NearestPowerOfTwo(glConfig.vidHeight);
-
- data = ri.Hunk_AllocateTempMemory(width * height * 4);
-
- tr.currentRenderNearestImage =
- R_CreateImage("_currentRenderNearest", data, width, height, IF_NOPICMIP, FT_NEAREST, WT_REPEAT);
+ tr.currentRenderImage = R_CreateImage("_currentRender", data, width, height, IF_NOPICMIP, FT_NEAREST, WT_REPEAT);
ri.Hunk_FreeTempMemory(data);
}
@@ -4673,8 +4642,6 @@ void R_CreateBuiltinImages(void)
R_CreateAttenuationXYImage();
R_CreateContrastRenderImage();
R_CreateCurrentRenderImage();
- R_CreateCurrentRenderLinearImage();
- R_CreateCurrentRenderNearestImage();
R_CreateCurrentRenderFBOImage();
R_CreatePortalRenderFBOImage();
}
diff --git a/xreal/code/renderer/tr_local.h b/xreal/code/renderer/tr_local.h
index 14dcb2fa..5813e7cd 100644
--- a/xreal/code/renderer/tr_local.h
+++ b/xreal/code/renderer/tr_local.h
@@ -1726,10 +1726,9 @@ typedef struct
image_t *identityLightImage; // full of tr.identityLightByte
image_t *noFalloffImage;
image_t *attenuationXYImage;
+
image_t *contrastRenderImage;
image_t *currentRenderImage;
- image_t *currentRenderLinearImage;
- image_t *currentRenderNearestImage;
image_t *currentRenderFBOImage[4];
image_t *portalRenderFBOImage[4];
diff --git a/xreal/code/renderer/tr_shade.c b/xreal/code/renderer/tr_shade.c
index 34ef1b5c..7082fd48 100644
--- a/xreal/code/renderer/tr_shade.c
+++ b/xreal/code/renderer/tr_shade.c
@@ -2637,9 +2637,8 @@ static void Render_heatHaze(int stage)
// capture current color buffer for u_CurrentMap
GL_SelectTexture(0);
- GL_Bind(tr.currentRenderNearestImage);
- qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, tr.currentRenderNearestImage->uploadWidth,
- tr.currentRenderNearestImage->uploadHeight);
+ GL_Bind(tr.currentRenderImage);
+ qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, tr.currentRenderImage->uploadWidth, tr.currentRenderImage->uploadHeight);
// clear color buffer
qglClear(GL_COLOR_BUFFER_BIT);
@@ -2668,7 +2667,7 @@ static void Render_heatHaze(int stage)
// bind u_CurrentMap
GL_SelectTexture(1);
- GL_Bind(tr.currentRenderNearestImage);
+ GL_Bind(tr.currentRenderImage);
DrawElements();
@@ -2695,7 +2694,7 @@ static void Render_heatHaze(int stage)
// bind u_CurrentMap
GL_SelectTexture(0);
- GL_Bind(tr.currentRenderNearestImage);
+ GL_Bind(tr.currentRenderImage);
// set 2D virtual screen size
qglPushMatrix();
@@ -2765,8 +2764,8 @@ static void Render_heatHaze(int stage)
}
else
{
- GL_Bind(tr.currentRenderLinearImage);
- qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, tr.currentRenderLinearImage->uploadWidth, tr.currentRenderLinearImage->uploadHeight);
+ GL_Bind(tr.currentRenderImage);
+ qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, tr.currentRenderImage->uploadWidth, tr.currentRenderImage->uploadHeight);
}
// bind u_ContrastMap
@@ -2822,9 +2821,8 @@ static void Render_bloom(int stage)
qglUniform2fARB(tr.contrastShader.u_NPOTScale, npotWidthScale, npotHeightScale);
GL_SelectTexture(0);
- GL_Bind(tr.currentRenderNearestImage);
- qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, tr.currentRenderNearestImage->uploadWidth,
- tr.currentRenderNearestImage->uploadHeight);
+ GL_Bind(tr.currentRenderImage);
+ qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, tr.currentRenderImage->uploadWidth, tr.currentRenderImage->uploadHeight);
qglMatrixMode(GL_TEXTURE);
qglLoadMatrixf(tess.svars.texMatrices[TB_COLORMAP]);
qglMatrixMode(GL_MODELVIEW);
@@ -2841,9 +2839,8 @@ static void Render_bloom(int stage)
qglUniform2fARB(tr.bloomShader.u_NPOTScale, npotWidthScale, npotHeightScale);
GL_SelectTexture(1);
- GL_Bind(tr.currentRenderLinearImage);
- qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, tr.currentRenderLinearImage->uploadWidth,
- tr.currentRenderLinearImage->uploadHeight);
+ GL_Bind(tr.contrastRenderImage);
+ qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, tr.contrastRenderImage->uploadWidth, tr.contrastRenderImage->uploadHeight);
DrawElements();
@@ -2877,9 +2874,8 @@ static void Render_bloom2(int stage)
qglUniform2fARB(tr.contrastShader.u_NPOTScale, npotWidthScale, npotHeightScale);
GL_SelectTexture(0);
- GL_Bind(tr.currentRenderNearestImage);
- qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, tr.currentRenderNearestImage->uploadWidth,
- tr.currentRenderNearestImage->uploadHeight);
+ GL_Bind(tr.currentRenderImage);
+ qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, tr.currentRenderImage->uploadWidth, tr.currentRenderImage->uploadHeight);
qglMatrixMode(GL_TEXTURE);
qglLoadMatrixf(tess.svars.texMatrices[TB_COLORMAP]);
qglMatrixMode(GL_MODELVIEW);
@@ -2894,9 +2890,8 @@ static void Render_bloom2(int stage)
qglUniform2fARB(tr.blurXShader.u_FBufScale, fbufWidthScale, fbufHeightScale);
qglUniform2fARB(tr.blurXShader.u_NPOTScale, npotWidthScale, npotHeightScale);
- GL_Bind(tr.currentRenderLinearImage);
- qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, tr.currentRenderLinearImage->uploadWidth,
- tr.currentRenderLinearImage->uploadHeight);
+ GL_Bind(tr.contrastRenderImage);
+ qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, tr.contrastRenderImage->uploadWidth, tr.contrastRenderImage->uploadHeight);
DrawElements();
@@ -2908,9 +2903,8 @@ static void Render_bloom2(int stage)
qglUniform2fARB(tr.blurYShader.u_FBufScale, fbufWidthScale, fbufHeightScale);
qglUniform2fARB(tr.blurYShader.u_NPOTScale, npotWidthScale, npotHeightScale);
- GL_Bind(tr.currentRenderLinearImage);
- qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, tr.currentRenderLinearImage->uploadWidth,
- tr.currentRenderLinearImage->uploadHeight);
+ GL_Bind(tr.contrastRenderImage);
+ qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, tr.contrastRenderImage->uploadWidth, tr.contrastRenderImage->uploadHeight);
DrawElements();
@@ -2924,10 +2918,10 @@ static void Render_bloom2(int stage)
qglUniform2fARB(tr.bloomShader.u_NPOTScale, npotWidthScale, npotHeightScale);
GL_SelectTexture(0);
- GL_Bind(tr.currentRenderNearestImage);
+ GL_Bind(tr.currentRenderImage);
GL_SelectTexture(1);
- GL_Bind(tr.currentRenderLinearImage);
+ GL_Bind(tr.contrastRenderImage);
DrawElements();
@@ -2963,9 +2957,8 @@ static void Render_rotoscope(int stage)
// bind u_ColorMap
GL_SelectTexture(0);
- GL_Bind(tr.currentRenderNearestImage);
- qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, tr.currentRenderNearestImage->uploadWidth,
- tr.currentRenderNearestImage->uploadHeight);
+ GL_Bind(tr.currentRenderImage);
+ qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, tr.currentRenderImage->uploadWidth, tr.currentRenderImage->uploadHeight);
qglMatrixMode(GL_TEXTURE);
qglLoadMatrixf(tess.svars.texMatrices[TB_COLORMAP]);
qglMatrixMode(GL_MODELVIEW);Before that XreaL commit, the code had some |
|
This usage of |
- fix FXAA by using GL_LINEAR on currentRender, - restore GL_NEAREST after that to not break other effects.
d505fbf to
2931004
Compare
|
Well, it works until we use bindless textures, and it's not suprising since the tweak requires a bind… |
|
@VReaperV I would appreciate your expertise on this ! 🙂️ The way to fix FXAA is to make sure the framebuffer is using I verified that in non-bindless mode, switching to And something I don't know how to do and what to do at all, is how this interacts with the bindless pipeline and how to make it work the bindless way. |
|
If you're OK with requiring OpenGL 3.3 you can use "sampler" objects.
|
|
Nice! |
|
I tried using |
2be5a7e to
24a5f26
Compare
3ca219b to
24fe6b1
Compare
|
If it works properly, maybe we will enable FXAA in We may want to disable FXAA internally when MSAA is enabled. |
| // That luminance vector comes from a comment in fxaa3_11_fp.glsl. | ||
| vec3 luminanceVector = vec3( 0.299, 0.587, 0.114 ); | ||
|
|
||
| float luminance = dot( color.rgb, luminanceVector ); |
There was a problem hiding this comment.
Apparently it should be called "luma" since you're doing it on sRGB values. While "luminance" would be with linear values
|
About blurring, yes. FXAA is commonly quoted as one of the common culpritq for “why modern games look blurry while older ones were crisp”. Not quoted as bad as temporal antialiasing, but quoted still. Also quoted among « why all games look the same » (they all copy pasted public domain fxaa). FXAA has some knobs and we may reduce the sensitivity of it. |
24fe6b1 to
2eb8150
Compare
|
@slipher I made the FXAA knobs configurable using cvars. Current: Current: Current: Low: In fact, we may even use values lower than the low limit documented in |
2eb8150 to
9eacf78
Compare
|
I reduced r_FXAAEdgeThreshold to |
|
Just for cosmetic reasons I also renamed |
|
Here is the game-side PR re-adding the FXAA option in UI and graphics presets: |
Why? This goes against the convention of how most other initial-ish cvars are named. For example I tried the latest version and it does reduce the blurring of the plat23 floor, but most screenshots look about the same including the Vega grating and the repeater posted above. |
src/engine/renderer/tr_backend.cpp
Outdated
| backEnd.currentMainFBO = 1 - backEnd.currentMainFBO; | ||
| R_BindFBO( tr.mainFBO[ backEnd.currentMainFBO ] ); | ||
|
|
||
| bool greaterThanGL33 = std::make_pair( glConfig.glMajor, glConfig.glMinor ) >= std::make_pair( 3, 3 ); |
There was a problem hiding this comment.
We still only request GL 3.2, right? So instead we should request and check the ARB_sampler_objects extension. And we can make it a requirement for bindless textures to keep things simple.
There was a problem hiding this comment.
We only request GL 3.2 by default. Drivers may provide higher versions anyway (Mesa provides 4.6 when we request 3.2 when 4.6 is available). We also provide cvars to request arbitrary versions.
If the discriminant isn't the version but ARB_sampler_objects then we can use that instead.
There was a problem hiding this comment.
I made the FXAA code requiring ARB_sampler_objects in all cases.
I noticed that:
- Mesa provides it on GL 2.1 devices.
- Mesa fails to provide
GL_ARB_vertex_array_objectwhenARB_sampler_objectsis disabled:
$ MESA_EXTENSION_OVERRIDE='-GL_ARB_sampler_objects ./daemon
Warn: Missing required extension GL_ARB_vertex_array_object.
We require GL_ARB_vertex_array_object anyway.
In case a device doesn't provide GL_ARB_vertex_array_object, I doubt it would be meaningful to run FXAA.
c26f6d0 to
e284494
Compare
|
That looks ready to me. |
src/engine/renderer/tr_backend.cpp
Outdated
| // FXAA expects GL_LINEAR for the sampling to work. | ||
| GLuint64 handle = 0; | ||
| GLuint sampler = 0; | ||
| glGenSamplers( 1, &sampler ); |
There was a problem hiding this comment.
This should only be done once, I would imagine. Doing it every frame seems like a possible memory leak
| extern cvar_t *r_FXAA; | ||
| extern Cvar::Range<Cvar::Cvar<int>> r_ssao; | ||
| extern Cvar::Range<Cvar::Cvar<int>> r_msaa; | ||
| extern Cvar::Range<Cvar::Cvar<int>> r_SSAO; |
There was a problem hiding this comment.
Please remove commits renaming unrelated cvars
There was a problem hiding this comment.
Too much painful to do. MSAA is renamed first so following FXAA commits are done right from the start. Reverting that rename means splitting that FXAA work into 3 pull requests, not counting all the rebases, just to avoid commits being right from the start.
The SSAO one is more controversial and since it comes last it can be easily delayed. But this PR has a companion on game side, and it's really much easier to do all of them at once on game side as well, yet again to avoid splitting the PRs into many just for obvious similar single line changes.
This keeps the merge constrained into one PR on engine side and one PR on game side. Those renames are very obvious.
There was a problem hiding this comment.
Each changes are done in their nice own commits. Once merged no one will care.
There was a problem hiding this comment.
I mean, I wouldn't rename them at all, rather than making more PRs. Anyway gamelogic-side PRs are not necessary since cvars are case-insensitive.
src/engine/sys/sdl_glimp.cpp
Outdated
| && glConfig.indirectParametersAvailable | ||
| && glConfig.multiDrawIndirectAvailable | ||
| && glConfig.pushBufferAvailable | ||
| && glConfig.samplerObjectsAvailable |
There was a problem hiding this comment.
This dependency can be removed since it was made a hard dependency of FXAA
e284494 to
c9a2128
Compare
src/engine/renderer/tr_backend.cpp
Outdated
|
|
||
| // FXAA expects GL_LINEAR for the sampling to work. | ||
| GLuint64 handle = 0; | ||
| static GLuint sampler = 0; |
There was a problem hiding this comment.
This is wrong after a vid_restart.
There was a problem hiding this comment.
This should be good now. I also make sure we call glDeleteSamplers() on shutdown. I wrote the code calling glGenSamplers() in a way if in the future we have a feature requiring a linear sampler, it would be reusable straightforward.
| extern cvar_t *r_FXAA; | ||
| extern Cvar::Range<Cvar::Cvar<int>> r_ssao; | ||
| extern Cvar::Range<Cvar::Cvar<int>> r_msaa; | ||
| extern Cvar::Range<Cvar::Cvar<int>> r_SSAO; |
There was a problem hiding this comment.
I mean, I wouldn't rename them at all, rather than making more PRs. Anyway gamelogic-side PRs are not necessary since cvars are case-insensitive.
c9a2128 to
894db38
Compare





















This is so good to have it I'm now considering it for 0.56.0.
GL_LINEARinstead ofGL_NEAREST)r_FXAAa new-style cvarfxaa_fp(we now have#insert)r_showLuminance)r_showFXAAFix #533 and fix #1701:
Original comment:
No urge. I was looking at it in hope I could find a quick fix, I haven't found a quick fix, this is as broken as before.
Anyway, the rework of this may be useful for when the fix for FXAA will be found.
r_FXAAa new-style cvarfxaa_fp(we now have#insert)r_showLuminance)r_showFXAAThe
r_showFXAAoption paints in red the pixels whose RGB color is modified byFxaaPixelShader(). ActuallyFxaaPixelShader()modifies random pixels (not at edges) and the result image is more buggy than without FXAA.