Skip to content

Conversation

Calinou
Copy link
Member

@Calinou Calinou commented Apr 13, 2020

This results in better appearance for textures viewed from oblique angles. Many other engines now enable it by default. On today's desktop platforms, the performance impact is minimal if other effects are already taxing the GPU.

The anisotropic filtering quality can be configured as usual in the Project Settings. Setting it to 1 should disable it even if individual materials have it enabled, so this is easy to revert if you don't want it.

This remains disabled by default on platforms with mobile (TBDR) GPUs for performance reasons, as texture reads are often the bottleneck there.

I see screenshots of Godot projects not using anisotropic filtering too often – let's change that! 🙂

This closes godotengine/godot-proposals#3134.

Preview

I used this Sponza demo for the screenshots. Click to view at full size, look at the floor.

Before

aniso_off

After

Note: the screenshot below uses 4× anisotropic filtering, not 8× which is the new default on desktop platforms.

aniso_on

@Calinou Calinou added this to the 4.0 milestone Apr 13, 2020
@akien-mga akien-mga requested a review from reduz April 13, 2020 13:33
@Logharaa
Copy link
Contributor

Logharaa commented Jul 5, 2020

Why is it not merged?

@Calinou
Copy link
Member Author

Calinou commented Jul 5, 2020

@Logharaa reduz said on IRC he'd prefer this to be implemented in a more fine-grained fashion.

@Logharaa
Copy link
Contributor

Logharaa commented Jul 5, 2020

@Calinou Oh ok thanks for the info!

@reduz
Copy link
Member

reduz commented Oct 19, 2020

Mobile cant deal with this as well, and it needs to be tested on lower end devices too, so lets wait a bit on this one

@Calinou Calinou force-pushed the default-enable-anisotropic-filtering branch from f5764fd to ebf43c9 Compare November 7, 2020 15:54
@Calinou
Copy link
Member Author

Calinou commented Nov 7, 2020

I amended the pull request to use 8× anisotropic filtering on desktop and 1× on mobile (which effectively disables it there).

@Calinou Calinou force-pushed the default-enable-anisotropic-filtering branch from ebf43c9 to 26bfca0 Compare November 7, 2020 15:56
@Calinou Calinou changed the title Enable anisotropic filtering for 3D materials by default Enable anisotropic filtering for 3D materials by default on desktop platforms Nov 7, 2020
@Calinou Calinou force-pushed the default-enable-anisotropic-filtering branch from 26bfca0 to 391a922 Compare November 7, 2020 16:02
@Calinou Calinou requested a review from a team as a code owner November 7, 2020 16:02
@Calinou Calinou force-pushed the default-enable-anisotropic-filtering branch 2 times, most recently from 94a406e to dd0dd5c Compare November 7, 2020 16:05
@Calinou Calinou force-pushed the default-enable-anisotropic-filtering branch from dd0dd5c to f60ac01 Compare April 1, 2021 23:30
@Calinou Calinou requested review from a team as code owners April 1, 2021 23:30
@Calinou Calinou force-pushed the default-enable-anisotropic-filtering branch from f60ac01 to 044ed04 Compare April 1, 2021 23:48
@Calinou Calinou force-pushed the default-enable-anisotropic-filtering branch 3 times, most recently from 5152d5a to 1d56552 Compare August 16, 2021 03:34
@reduz
Copy link
Member

reduz commented Jul 28, 2022

This needs testing on low end desktop devices to ensure it makes a difference in performance or not.

@fire
Copy link
Member

fire commented Nov 6, 2024

I salvaged the PR, but I'll let it simmer in my branch of Godot Engine for a bit until I submit it.

https://github.com/V-Sekai/godot/tree/vsk-default-enable-anisotropic-filtering-4.4

@Calinou Calinou force-pushed the default-enable-anisotropic-filtering branch from 1d56552 to 0a69239 Compare November 7, 2024 00:01
@Calinou Calinou requested review from a team as code owners November 7, 2024 00:01
@Calinou
Copy link
Member Author

Calinou commented Nov 7, 2024

Rebased and tested again (using @fire's work as a base), it works as expected.

I've also modified the glTF importer to handle this for material import (remember to reimport 3D scenes for this change to apply, e.g. by removing the .godot/ folder).

@fire fire requested a review from clayjohn November 7, 2024 17:23
Copy link
Contributor

@Repiteo Repiteo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codestyle checks out. Kinda surprised that anisotropic filtering wasn't already the default; always assumed it was a pretty free feature (maybe not for really low-end devices?)

@Repiteo Repiteo modified the milestones: 4.x, 4.4 Nov 25, 2024
@clayjohn
Copy link
Member

I agree with reduz, this needs confirmation that it won't harm low end devices. I'm confident that it is a good change for most dedicated GPUs, but I suspect that many integrated GPUs will take a performance hit from this. Since this imposes a new default on all users, we need to be careful and validate these changes before we go ahead.

@Calinou
Copy link
Member Author

Calinou commented Nov 28, 2024

I did some tests of https://github.com/Calinou/godot-sponza-4 on my laptop (on AC in balanced mode):

PC specifications
  • CPU: Intel Core i9-13900H
  • GPU: Intel Iris Xe / NVIDIA GeForce RTX 4060 Laptop GPU
  • RAM: 48 GB (16 + 32 GB DDR4-3200 C22)
  • SSD: Solidigm P44 Pro 2 TB
  • OS: Windows 11 23H2
Type master (no AF) This PR (8x AF)
Intel, Mobile, 1152x648 296 FPS (3.38 mspf) 283 FPS (3.54 mspf)
Intel, Mobile, 2560x1600 90 FPS (11.11 mspf) 88 FPS (11.36 mspf)
Intel, Compatibility, 1152x648 490 FPS (2.04 mspf) 492 FPS (2.03 mspf)
Intel, Compatibility, 2560x1600 144 FPS (6.94 mspf) 140 FPS (7.14 mspf)
NVIDIA, Mobile, 1152x648 1510 FPS (0.66 mspf) 1487 FPS (0.67 mspf)
NVIDIA, Mobile, 2560x1600 611 FPS (1.64 mspf) 599 FPS (1.67 mspf)
NVIDIA, Compatibility, 1152x648 1695 FPS (0.59 mspf) 1727 FPS (0.58 mspf)
NVIDIA, Compatibility, 2560x1600 798 FPS (1.25 mspf) 797 FPS (1.25 mspf)

The performance difference is very small on average, especially compared to the significant gain in quality. Limiting ourselves to 8x probably did the heavy lifting here, since it's basically twice as cheap as 16x with only a slight loss in visual quality. (Console versions of games often limit themselves to 8x AF for a similar reason, since CPU and GPU memory is shared.)

Note that this is a scene with no post-processing effects applied, so scenes with post-processing will spend a greater time in areas other than anisotropic texture sampling (therefore reducing the % impact of anisotropic filtering).

@Zireael07
Copy link
Contributor

What about Android devices? They're the ones which are really low-end for Godot...

@Calinou
Copy link
Member Author

Calinou commented Nov 28, 2024

What about Android devices? They're the ones which are really low-end for Godot...

I've tested 8x AF on my Samsung Galaxy Z Fold4 and couldn't spot a performance difference on its main screen (it always ran at a locked 120 FPS, also on Truck Town).

However, this PR doesn't enable anisotropic filtering by default on mobile (since the .mobile feature tag override is used to set it to 1x, which is the same as disabled). We could revisit this in a future PR - I expect 2x AF to perform well on all mobile devices nowadays, maybe even 4x.

@clayjohn
Copy link
Member

However, this PR doesn't enable anisotropic filtering by default on mobile (since the .mobile feature tag override is used to set it to 1x, which is the same as disabled). We could revisit this in a future PR - I expect 2x AF to perform well on all mobile devices nowadays, maybe even 4x.

The performance impact of anisotropic textures doesn't work like that. There is no inherent performance penalty from using it (except for on very old devices), the performance cost comes from the additional bandwidth needed to sample it. Mobile devices are often bottlenecked by reading from textures, so multiplying the cost of texture reads is prohibitive. Desktop devices are almost never bottlenecked by texture reads, so its a free quality improvement. Remember, taking more time for something that isn't the bottleneck is essentially free (until you optimize your existing bottleneck).

Low end integrated devices struggle more with texture reads than dedicated GPUs do. So we need to test there to assess the realistic impact. Testing on a high end device or a dedicated GPU won't give you any useful information unfortunately

@clayjohn clayjohn modified the milestones: 4.4, 4.x Jan 14, 2025
Copy link
Contributor

@lyuma lyuma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems good to bring Godot up to industry standard texture quality on PC platforms.

@lyuma lyuma moved this from Ready for review to Approved, Waiting for Production in Asset Pipeline Issue Triage Apr 13, 2025
@clayjohn
Copy link
Member

I was doing some performance profiling on macOS last week of the TPS demo and I found that anisotropic textures were a significant cause of high bandwidth in that demo. TBDR GPUs tend to get bandwidth limited fast, so increasing bandwidth is a big concern. It would be nice if this could be scoped to non-TBDR GPUs. I'm not sure if there is an easy way for us to do that.

Unfortunately this means that this PR will likely hurt performance on any ARM-based laptops as well as all mobile devices. It might be a tradeoff worth making, but I'm not sure if it is

@fire
Copy link
Member

fire commented Apr 14, 2025

We discussed a long time ago where known incompatible systems degrade to a more performant setting. Unknown systems assume to work better.

@Calinou
Copy link
Member Author

Calinou commented Apr 15, 2025

TBDR GPUs tend to get bandwidth limited fast, so increasing bandwidth is a big concern. It would be nice if this could be scoped to non-TBDR GPUs. I'm not sure if there is an easy way for us to do that.

If we had a way to use multiple feature tags at once in the Project Settings, we could use .macos.arm and .windows.arm as an override to disable anisotropic filtering like we currently do for .mobile.

Maybe we can disable it for .arm more generally (and keep the .mobile override in place). It is possible to use a traditional non-TBDR GPU on an ARM system (mostly on Linux with Jetson development boards), but it's a very rare use case for gaming.

@fire
Copy link
Member

fire commented Apr 15, 2025

If your platform is a nintendo switch your platform provider probably wants a hook

@v1993
Copy link

v1993 commented Jun 10, 2025

From my perspective this should be a pretty easy merge in its current state, as this gives a noticeable quality boost on default settings and primarily enables proper control over anisotropic filtering (via the existing project setting), meaning that the feature isn't forced on anyone and can be easily opted out of if it turns out to cause problems for a project. I don't think there's really a need for more override options, at least for the initial merge - on desktop anisotropic filtering is traditionally exposed as a setting to end users anyways, which those with a TBDR GPU could turn down manually if they get bottlenecked by it.

@clayjohn
Copy link
Member

Discussed in the rendering meeting this week.

I am again confirming what reduz and I both say above. This has a huge impact on performance for all non-desktop GPUs. It should not be enabled by default.

This results in better appearance for textures viewed from oblique
angles. Many other engines now enable it by default.
On today's desktop platforms, the performance impact is minimal if
other effects are already taxing the GPU.

The default value chosen (8x) is a good balance between performance
and quality. Depending on the scene, you may be able to use 16x
anisotropic filtering with little to no cost in terms of frame time.

The anisotropic filtering quality can be configured as usual in the
Project Settings. Setting it to 1x will disable it even if individual
materials have it enabled, so this is easy to revert if you don't
want it.

This remains disabled by default on platforms with mobile (TBDR) GPUs
for performance reasons, as texture reads are often the bottleneck
there.
@Calinou Calinou force-pushed the default-enable-anisotropic-filtering branch from 0a69239 to ed59616 Compare September 25, 2025 13:59
@Calinou
Copy link
Member Author

Calinou commented Sep 25, 2025

Rebased and tested again, it works as expected.

I've changed the feature tag that disables anisotropic filtering from mobile to arm, for the reason I mentioned in #37847 (comment). However, it also has the side effect that when using the macOS or Android editor, you won't see a visible difference when switching between isotropic and anisotropic filters in BaseMaterial3D. (Previously, this already affected the Android editor, but the issue becomes more noticeable now that it also impacts macOS.)

It may be possible to find better criteria and create an actual tbdr feature tag. For example, this could be treated as arm, but excluded if any dedicated GPU memory is found (so that Linux ARM boards with a dedicated GPU are not seen as TBDR).

At the end of the day, there's no ideal solution here. What do other engines do by default in 2025?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Approved, Waiting for Production
Development

Successfully merging this pull request may close these issues.

Set default 3D material sampling method to Linear Mipmap Anisotropic
10 participants