Skip to content

Fix Viewport texture filter inheritance - #123746

Open
fsfgrafb wants to merge 3 commits into
godotengine:masterfrom
fsfgrafb:fix-viewport-filter-inheritance
Open

fsfgrafb wants to merge 3 commits into
godotengine:masterfrom
fsfgrafb:fix-viewport-filter-inheritance

Conversation

@fsfgrafb

Copy link
Copy Markdown

What problem(s) does this PR solve?

Additional information

This changes the inheritance lookup so it can fall back to the nearest enclosing Viewport when needed, while still respecting explicit CanvasItem filters and explicit Viewport filters.

Filter-change propagation now also crosses intermediate nodes.

The default texture filter of Window and SubViewport is unchanged; this only affects Viewports configured to inherit their filter.

I also added regression tests for nested Viewports, intermediate nodes, explicit overrides, reparenting, and Window/Popup cases. The existing Viewport tests pass with the fix.

@fsfgrafb
fsfgrafb requested review from a team as code owners September 23, 2026 07:12
Copilot AI lite review requested due to automatic review settings September 23, 2026 07:12

This comment was marked as low quality.

@AThousandShips

Copy link
Copy Markdown
Member

Please turn off Copilot reviews we do not accept them, thank you

@fsfgrafb

Copy link
Copy Markdown
Author

Thanks, turned it off.

@AThousandShips

Copy link
Copy Markdown
Member

Just to confirm, did you use AI tools while making this PR? See here

@fsfgrafb

Copy link
Copy Markdown
Author

Yes. I read the contribution policy in full before submitting the PR.

The actual changes were made by me. I only used AI at the end as an additional quality check, and treated its suggestions as reference rather than something to apply blindly.

@AThousandShips

Copy link
Copy Markdown
Member

Great thank you!

Comment thread scene/main/viewport.cpp Outdated
@radioactivejackal1414

radioactivejackal1414 commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

So, this is a substantial step forward. I built this, everything runs without errors, and I also got all your test cases to pass. This fixes one of the main issues mentioned in #119462.

The one case that I am getting to break is with this example:
fuzzy_textures
(with ProjectSettings set to Linear)

For whatever reason, pixel art textures used on the TextureRect or on the Sprite2D both use Linear instead of Nearest. The SubViewport seems to be inheriting SubViewportContainer's value instead of overriding with Nearest. I believe what's happening is the container is rendering all of its descendants with Linear since that's what it inherited, and then after the linear filter is applied, the SubviewPort is rendering them with Nearest (which does nothing since they're already blurry.

I'm pretty sure this is not intentional? If Viewport specifies a canvas_item_default_texture_filter other than Inherit, then all the children should use that filter, not be rendered with the parent's filter.

Edit above.

Co-authored-by: Jack Moody <74024384+radioactivejackal1414@users.noreply.github.com>
@fsfgrafb

Copy link
Copy Markdown
Author

I tried reproducing your example and noticed that either setting the SubViewportContainer’s Texture Filter to Nearest or changing the project’s default filter to Nearest made the result sharp.

I think there may be two filtering stages here: the SubViewport renders the Sprite2D and TextureRect using Nearest, then the SubViewportContainer displays that output texture using its own filter. In this setup, the container inherits Linear, which could explain the blur when magnified.

If that’s the case, this might be expected behavior rather than an inheritance issue.

@AThousandShips

Copy link
Copy Markdown
Member

See also:

Comment thread doc/classes/Viewport.xml Outdated
</member>
<member name="canvas_item_default_texture_filter" type="int" setter="set_default_canvas_item_texture_filter" getter="get_default_canvas_item_texture_filter" enum="Viewport.DefaultCanvasItemTextureFilter" default="1">
The default filter mode used by [CanvasItem] nodes in this viewport.
The root viewport's default filter is set by [member ProjectSettings.rendering/textures/canvas_textures/default_texture_filter]. To inherit filtering from the parent node or viewport in another viewport, use [constant DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_PARENT_NODE].

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

"viewport in another viewport" isn't very clear here, what does it mean?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I meant a Viewport nested under another Viewport in the scene tree.
I wanted to clarify how inheritance works in that case but I agree the wording is confusing.Since the enum description already explains this, I'll remove it.

@fsfgrafb

Copy link
Copy Markdown
Author

See also:

Thanks for pointing this out, I missed that PR. It looks like we addressed the same fallback issue. This PR also handles cases where a plain Node sits between Viewports, makes sure filter changes reach descendant nodes, and adds regression tests.

@radioactivejackal1414

Copy link
Copy Markdown
Contributor

If that’s the case, this might be expected behavior rather than an inheritance issue.

I wasn't exactly sure, but I think your explanation makes sense. All the user has to do is set the filter they want on the SubViewportContainer which is easy to do (albeit possibly confusing for someone not familiar with the filtering inheritance system). If it is indeed an issue then it could be fixed in a follow up.

@AThousandShips

Copy link
Copy Markdown
Member

It would depend on what is the intended behavior and expected behavior indeed, if the current behavior is intentional or expected changing it would break compatibility, so that'd have to be considered

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants