While reviewing my notes, I saw I had written
down that TextureRect in Godot uses
nearest filtering instead of linear filtering by
default and that the only solution was to change the
texture_filter value from the
baseCanvasItem class.
I remember finding a way to change this by
default everywhere in the project; in Godot
4.5.1.stable.arch_linux there's a project setting
rendering/textures/canvas_textures/default_texture_filter
which can be changed to change the default
texture_filter for
CanvasItem.
However, it appears that the default is already
set to Linear filtering, so I did some digging to
see when this was changed. I found that the
rendering/textures/canvas_textures/default_texture_filter
is also already set to linear in 4.0.stable.
However, 4.0.stable was released on March 1, 2023 1 and my note about the default texture filter is from July 22, 2024. My note was written while working on no signal and since I largely kept up to date on Godot versions while working on no signal, I must have been mistaken about Godot's default behavior when I wrote the note.
Checking the
VOD when I wrote the note, it seems that at 4h
18m 38s, I changed the filter on the
CanvasItem from inherit to nearest and
observed no change. This might have been why I made
this assumption, though there could be other reasons
for why this may have been the case, like the
filtering mode having been accidentally set to
nearest.
So, to recap, TextureRect in Godot
may scale badly due to:
- The
TextureRectusing the default project setting forrendering/textures/canvas_textures/default_texture_filter, which may be set to a scaling mode you don't like. - A parent
CanvasItemexplicitly setting a scaling mode you don't like.
And to fix this, you may need to:
- Change the
rendering/textures/canvas_textures/default_texture_filterto the desired texture filter. - Make sure all
CanvasItemparents don't have an explicitly set texture filter, if you want the default texture filter. - Explicitly change or set the
texture_filtervalue on the respectiveCanvasItemclass (which node you do this to in the tree depends on whether or not each successive parent has inherit as its filter or not).