Skip to content
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

SubViewport size_2d_override is limited by being of type Vector2i #104601

Open
timoschwarzer opened this issue Mar 25, 2025 · 6 comments · May be fixed by #104602
Open

SubViewport size_2d_override is limited by being of type Vector2i #104601

timoschwarzer opened this issue Mar 25, 2025 · 6 comments · May be fixed by #104602

Comments

@timoschwarzer
Copy link
Contributor

Tested versions

  • 4.4-stable
  • current master

System information

Godot v4.5.dev (6b5b84c) - Arch Linux #1 ZEN SMP PREEMPT_DYNAMIC Sun, 23 Mar 2025 17:17:17 +0000 on Wayland - X11 display driver, Multi-window, 2 monitors - Vulkan (Forward+) - dedicated Intel(R) Arc(tm) A770 Graphics (DG2) - Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz (16 threads)

Issue description

Currently, SubViewport size_2d_override is a property of type Vector2i. Since size_2d_override is solely used to calculate the viewport stretch transform, this unnecessarily limits the stretch transform to discrete values. I am currently working on a pixel art game with high resolution UI and this makes it impossible to correctly align the UI (which is rendered in a SubViewport with higher resolution) with the game world. The game world resolution can have fractional parts because one pixel in the game world are likely multiple pixels on the real screen.

Screencast.From.2025-03-25.12-19-15.mp4

Steps to reproduce

  • Have a SubViewport with a high resolution size (e.g. 500x500)
  • Place a sprite with a high resolution texture in that SubViewport and scale it down to e.g. 10x10
  • → it is impossible to render a quad of e.g. 10.5x10.5 in-viewport pixels to the high resolution SubViewport although there is nothing going against it.

Minimal reproduction project (MRP)

subviewport-size-2d-override-repro.zip

@AThousandShips
Copy link
Member

Changing this isn't possible without breaking compatibility in pretty serious ways, and was rejected as a change in:

Where a different solution was chosen, so this is unlikely to change in 4.x

@timoschwarzer
Copy link
Contributor Author

@AThousandShips could you elaborate on where this would break? I did see that issue before but to me it looks like it was chosen not to change the type of the property because it was possible to fix that issue without. This issue however is impossible to workaround because there is no way to set the stretch transform on a Viewport other than setting size_2d_override, which is currently limited to integers.

The only way I can currently see this breaking any existing code if someone is currently setting size_2d_override to a Vector2 with fractional parts:

func _ready() -> void:
	var some_size := Vector2(10.5, 10.5)
	viewport.size_2d_override = some_size

This example would now yield in a different result because of the missing implicit conversion to Vector2i. I get that this is a breaking change and that it is eventually not desirable to merge until a new major version, but I imagine you have some bigger breakage in mind that I have overlooked when you talk about breaking compat in pretty serious ways. 👀

@AThousandShips
Copy link
Member

This is not a bug to fix, it's at most a limitation to improve on, so breaking compatibility is a real concern. First of all this type is established as being integer valued, which informs use

Further C# uses properties exclusively so I'm unsure how this kind of breakgage is handled there

Further the actual viability of using non-integer scaling would need to be evaluated, just changing this type doesn't mean it will work properly, and I suspect there are other parts of the code that uses (or relies on) integer values, or at least don't support non-integers

@timoschwarzer
Copy link
Contributor Author

timoschwarzer commented Mar 25, 2025

@AThousandShips Thank you! I didn't know C# doesn't use the compatibility getters/setters. The solution from the other PR is only a solution to that specific symptom in that issue though. The core issue still exists and has real usecases that aren't possible because of this.

First of all this type is established as being integer valued, which informs use

After that logic this change should be no problem because Viewport already uses Size2 and not Size2i for this property. 😅 It's only SubViewport that uses Size2i.

Further the actual viability of using non-integer scaling would need to be evaluated, just changing this type doesn't mean it will work properly, and I suspect there are other parts of the code that uses (or relies on) integer values, or at least don't support non-integers

From what I can see, there are exactly two places that handle size_2d_override:

  • Here it is converted to the stretch transform. The resulting scale is already almost always non-integer.
  • And here the size of the rect returned by get_visible_rect is set. This logic actually looks very flawed to me, because the visible rectangle is only the size of size_2d_override if 1. size_2d_override_stretch is enabled and 2. both components of size_2d_override are > 0.

So from what I gather, if set, size_2d_override actually does nothing but making get_visible_rect return a wrong value if size_2d_override_stretch is set to false. If size_2d_override_stretch is set to true, the stretch transform is derived from size_2d_override and the size of the rect returned by get_visible_rect is set to size_2d_override.

@AThousandShips
Copy link
Member

AThousandShips commented Mar 25, 2025

(Please don't tag people who are already engaging in conversation, it's creating unnecessary noise for no reason)

The change to the property type in C# would risk introducing bugs as it changes the type, i.e. breaking compatibility, it uses the getters/setters internally but you can't use them in C#

After that logic this change should be no problem because Viewport already uses Size2 and not Size2i for this property.

There's no such property

@timoschwarzer
Copy link
Contributor Author

There's no such property

Wrong word, my bad. I'm talking about Size2 Viewport::size_2d_override, which is a private member of Viewport. In the end SubViewport does nothing else than setting and getting that member.

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

Successfully merging a pull request may close this issue.

2 participants