-
-
Notifications
You must be signed in to change notification settings - Fork 22k
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
Allow viewport stretch without shrink #76304
base: master
Are you sure you want to change the base?
Allow viewport stretch without shrink #76304
Conversation
4e025ca
to
8dfc1ce
Compare
Shrink can now go down to zero, and gets special treatment. Code that forces the viewport resolution checks that shrink is greater than zero. Transforms are done by dividing the sizes of the viewport and the container (not necessarily in that order), instead of using the shrink value directly. To accomplish this, _send_event_to_viewports does the scaling now, instead of _gui_input. I always cast viewport size to floats, because otherwise it casts it implicitly, but only when it's on the right of the operator, and I don't like playing dice.
d1a80f6
to
2dd2e7f
Compare
Note that on the root Viewport (which is a Window), you can set Content Scale Factor (or the equivalent project setting) to achieve this with any stretch mode. This PR makes it possible to achieve the same on SubViewports which may sometimes be useful, but the main use case is really for the root Viewport. (If you split 2D and 3D rendering in separate viewports, you generally keep 2D rendering in the root Viewport, which allows you to use Content ScaleFactor.) |
High res is one of the options for 3D, but I also allow the user to set a lower target resolution. |
There was some talk about moving Window's stretch modes to Viewport, but I presume doing so will break compatibility.
Note that we have Scaling 3D project settings and Viewport properties since 4.0, although it currently lacks a nearest-neighbor filtering mode and doesn't work with the Compatibility rendering method yet. |
Using 3D scaling either in project settings or a sub viewport spams my errors ( |
For my project I have a low base resolution, and use scaling mode canvas_items.
This lets me have pixel art UI over high res 3D. I set the viewport's resolution via script.
The issue is that when the SubViewportContainer gets scaled up by canvas_items, it becomes much too large.
One solution is to use Stretch, so that the viewport is displayed at the size of its container.
But my problem there is, I don't want to use Stretch Shrink, because it limits the viewport size to the base resolution of the project, meaning it becomes pixelated when increasing the window size.
My solution is to allow shrink to go to 0, where it doesn't force viewport resolution, but still stretches/shrinks the texture to fit the container.
I've also adjusted the relevant input methods and tested all my changes to make sure it works as expected, and updated relevant tooltips.
It seems to work correctly with Size 2D Override and Size 2D Override Stretch too.
Before I made changes to the engine, I worked around this using scripts and a TextureRect, and required math to get mouse position correctly.
SubViewportContainer does have scale, but it gave me issues with floating point imprecision, and was just a hassle.
I think this will be of use to other people too, as it makes SubViewportContainer more versatile.
Here's a test project so you can see it in action: Stretch Shrink Test.zip
I'd love to hear your feedback!