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

Allow stretch mode setting for SubViewport. #7974

Open
uzkbwza opened this issue Oct 3, 2023 · 5 comments
Open

Allow stretch mode setting for SubViewport. #7974

uzkbwza opened this issue Oct 3, 2023 · 5 comments

Comments

@uzkbwza
Copy link

uzkbwza commented Oct 3, 2023

Describe the project you are working on

A 2d pixel-art game with a high-resolution root display and a pixel-perfect, low resolution game view.

Describe the problem or limitation you are having in your project

All 2D SubViewports behave normally in-editor, but in-game act as if they are using the canvas_items stretch mode in Project Settings; they do not respect the resolution set in size_2d_override. There is no apparent way to change this behavior. I am trying to make a game that has a pixel-perfect low-resolution game-view with high-resolution pillarbox art. This appears to be impossible to do with Viewports currently, and is an important inconsistency as this behavior is desired for many pixel art games.

Godot_v4.2-dev5_win64_otKZtlhkH2.mp4

It is notable to me that the viewport setting in Project Settings does not line up with the actual behavior of viewports in-game.

Reference: godotengine/godot#82708

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Allowing the user to select a stretch mode (such as viewport or canvas_items) on a SubViewport would provide needed flexibility to SubViewports and allow developers to choose how their viewports should be displayed without relying on ViewportTexture, which comes with the major drawbacks of having no support for audio or mouse input.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Something like this.
Godot_v4 2-dev5_win64_BfGcPxd7YR

If this enhancement will not be used often, can it be worked around with a few lines of script?

No. It would require many hacks and a lot of friction to use ViewportTexture as if it were a SubViewport in a SubViewportContainer.

Is there a reason why this should be core and not an add-on in the asset library?

Setting aside that this would line up with user expectations based on the behavior of other tools (and, I believe, how Viewports already worked in 3.x), this would drastically improve the functionality and flexibility of 2D games with complicated game-view layouts, with little added complexity and no new features to develop, as it already exists for the root viewport (configurable via Project Settings). It would be a major usability upgrade for people making pixel art games that is currently impossible or very difficult to implement by scripting while appearing to be a simple change on the engine side.

@Calinou
Copy link
Member

Calinou commented Oct 3, 2023

I believe this is already supported. The 3D in 2D demo has specific code to resize the viewport used for 3D rendering when the window size changes. Otherwise, it would be pixelated at resolutions different than the default window size. If you remove these lines of code, you should get the desired effect.

@uzkbwza
Copy link
Author

uzkbwza commented Oct 3, 2023

Yeah, after downloading that demo and removing the function in the code you linked, the result is no different than how it is by default.

@Sauermann
Copy link

@rafrafek
Copy link

Is there a SubViewport equivalent of setting the project stretch mode to canvas_item?

I have a low res pixel game, but high res text. When the texts are on a canvas layer and NOT under a subviewport, they're crispy. However, when I have text under a subviewport they are all pixelated due to the low resolution of the subviewport. Anyway to increase the resolution of the subviewport's camera without changing the size of everything so that I can keep my text crispy?

Originally posted on Reddit by user -ThatGingerKid-. I just have a very similar problem.

@Sauermann
Copy link

@rafrafek That project setting affects the root Windows property content_scale_mode.
This property is Window-specific and not available in SubViewport.

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

No branches or pull requests

4 participants