godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.14k stars 96 forks source link

Allow stretch mode setting for SubViewport. #7974

Open uzkbwza opened 1 year ago

uzkbwza commented 1 year ago

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.

https://github.com/godotengine/godot/assets/43023911/03a78f13-36d7-4514-bee6-3412e1f28e6f

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago
rafrafek commented 5 months ago

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 commented 5 months ago

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