-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add antialiasing filters (FXAA, SSAA) #13253
Conversation
How is the performance difference between FXAA and SSAA? |
SSAA is simpler and accurate but is slow, as it renders multiple times to get multiple samples. |
Yeah, SSAA was rather expensive on my Android device, it doubled the drawtime and lowered FPS from 60 (without) to ~25 in the same area, other settings were the same when testing with and without. |
Impact varies by hardware, here is an example for Core i5 3317U (a 10yo laptop)
|
On my GPU (RTX 3050), the impact on FPS with SSAA is marginal (-4 FPS at worst), but the quality is second to none. |
On my "NVIDIA GeForce GTX 1650 Max-Q":
Nice! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested in various scenarios. Works fine.
Code looks reasonable (but I am not an expert in this)
QQ: How does this all relate to the "Antialiasing" setting on the main settings page? |
That setting controls built-in / "hardware" which only works partially and in direct pipeline without postprocessing (which is coupled to shaders) |
Is the SSAA shader set to 2X or 4X? |
I suggest removing that feature or using the same setting for it |
SSAA is at 2x |
Can it be increased to 4X through the shader or not? If not, can we have it available to tweak, at least from the shader code if you don't want to expose it? |
Hmm... The conflicting fixed-pipeline (right?) antialiasing on the settingspage is indeed confusing. It would indeed be nice if we somehow could have one setting. At least remove it from the main settingspage, as there is nothing special about it anymore. @AbduSharif 2x is already comparatively slow. Do you expect a great visual improvement from this? |
Yes I do expect a visual improvement from it, the slowness I had was during a worst case scenario only and it works well other times for me. Having the option wouldn't hurt as the shader is already labled as "(expensive)". |
(Removed the "One Approval" as there is still work needed) |
If enable_fsaa requires post-processing to be disabled, should we disable the dropdown for 5.7.0 when post-processing enabled? |
To my understanding that’s 2× in each direction, so 4× samples.
Won’t that make the image a bit blurry? I’d expect simple averaging (which is equivalent to bilinear sampling for 2× actually) Anyway, did you try using multisampling with per-sample shading? That should work better than equivalent SSAA, and is a bit more flexible. |
You can try allowing the usage of 16× MSAA, which is implemented as 4× MSAA + 4× SSAA in most graphics drivers. (Despite the name, there is no such thing as actual 16× MSAA; it's always a mix of supersampling and multisampling.) However, I've noticed that forcing 16× MSAA in the graphics driver (like in #13397) makes 2D elements in Minetest blurry (including text). This occurs with some other games too, but not all of them. |
texture2D(rendered, uv + vec2(-1., -1.) * 0.25 * texelSize0).rgba + | ||
texture2D(rendered, uv + vec2(1., -1.) * 0.25 * texelSize0).rgba + | ||
texture2D(rendered, uv + vec2(-1., 1.) * 0.25 * texelSize0).rgba + | ||
texture2D(rendered, uv + vec2(1., 1.) * 0.25 * texelSize0).rgba); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm probably missing something, but for simple 2x SSAA implementation I'd expect something like:
vec4 color = 0.25 * (
texture2D(rendered, uv + vec2(0.0, 0.0) * texelSize0).rgba +
texture2D(rendered, uv + vec2(0.5, 0.0) * texelSize0).rgba +
texture2D(rendered, uv + vec2(0.5, 0.5) * texelSize0).rgba +
texture2D(rendered, uv + vec2(0.0, 0.5) * texelSize0).rgba);
(Maybe with half-pixel offset.)
Is there a reason you've decided to go with this "plus" shape?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no “plus” shape. The samples are in square corners, spaced by 0.5*texelSize0
, but centered at uv
unlike your sample. Assuming texelSize0
is the size of destination pixel, the code is correct.
OTOH it could leverage built-in linear filtering and take only 2 samples, at ±{0, 0.25} (or ±{0.25, 0}) of 1 sample at texelSize0
uv
exactly, that’d be the same. Not sure does Irrlicht support that currently, I think I saw some code that disables filtration for RTT textures. Or whether it makes any sense at all with actual hardware.
Or it could do texelFetch
es instead of sampling. Using maybe 2 * gl_FragCoord
for coordinates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, I miss something. It seems the code in secondstage.cpp
enables linear filter but this shader still does 4 samples at locations that are either exact texel centers (so the filter doesn’t add anything) or weird. @x2048 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no “plus” shape.
Brain fart. Somehow I thought that these offsets are like (0.25, 0.0), (0.0, 0.25), etc.
Note to self: Don't ask questions before your morning coffee.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@numberZero I've changed the shader to make full use of bilinear filtering. For 2x2 it will make a single sample.
Thanks for adding in the configuration possibility. |
The settings have been changed as follows: @Calinou I don't have nVidia so cannot test driver-forced antialiasing. I guess blurring of the UI occurs because AA filter is applied to entire screen including UI. Here we apply filter to 3D scene only (not even the wield item). The config now allows SSAA 2x2, 4x4, 8x8 and 16x16 (insane). |
Also, there is a configuration option already for MSAA at 16x16, but it has no effect on my hardware (maybe, nVidia works). |
This looks good to me now. |
fsaa does not do anything, it seems like that is expected. ssaa reduces my FPS to almost 1/2. |
fsaa works when shaders are off (and the other options don't) |
I maintain my "One approval" |
What's holding this one? |
@x2048 if this is considered ready feel free to merge |
As far as I know, that would be box filtering or pixel mixing and is not the same as bilinear filtering. A related issue about SSAA with SSIM-based perceptual downscaling: #6976 |
Adds FXAA and SSAA post-processing filter controlled by
antialiasing
setting.FXAA is based on WebGL code circulating on the internet, MIT-licensed.
SSAA is a simple render to 2x the texture sixe + 3x3 tent filter using bilinear filtering.
To do
This PR is Ready for Review.
How to test
antialiasing = fxaa
Look around
There should be less pixelation
antialiasing = ssaa
Look around
There should be even less pixelation and visual noise