godotengine / godot-demo-projects

Demonstration and Template Projects
https://godotengine.org
MIT License
5.75k stars 1.59k forks source link

Update viewport scaling demo to 4.0. #891

Closed rcorre closed 7 months ago

rcorre commented 1 year ago

Fixes #856.

The 3d_scaling demo was updated to use the built-in 3D scaling mechanisms in the Forward+ renderer.

A new 3d_scaling_compat demo was added to demonstrate the legacy SubViewport-based scaling method for the Compatibility renderer.

Calinou commented 1 year ago

I've pushed additional commits to https://github.com/Calinou/godot-demo-projects/tree/rcorre-update-viewport-scaling-demos to improve the demos in various ways, but the 3D Resolution Scaling (Compatibility) demo needs to resize the SubViewport when the window size changes. Otherwise, 3D rendering becomes pixelated or blurry once you increase the window size (which is unexpected from an user perspective, as we're using the canvas_items stretch mode).

I haven't been able to figure this out yet because you can't change a SubViewport's size when Stretch is enabled on the parent SubViewportContainer. We may end up having to disable Stretch and implement scaling ourselves, similar to what the 3D in 2D demo does.

rcorre commented 1 year ago

but the 3D Resolution Scaling (Compatibility) demo needs to resize the SubViewport when the window size changes

Huh, I figured that would happen automatically with Stretch enabled. I added this print:

get_tree().root.size_changed.connect(func(): prints(get_tree().root.size, viewport_container.size, viewport.size))

The viewport is resizing to the parent control, but the way the parent control resizes depends on the window/stretch/mode and window/stretch/aspect settings in the project. If you set mode=disabled, then the viewport container and the viewport auto-adjust to the window size.

leetNightshade commented 12 months ago

Idk if it's just me, but testing this on Godot 4.1.1.stable.custom_build on Steam Deck doesn't seem to do anything, it draws at the window resolution. I have this same problem in my project that emulates this subviewport project; and my project already handles size_changed.

Oh I guess related to this: https://github.com/godotengine/godot/issues/72548

Calinou commented 7 months ago

https://github.com/godotengine/godot/pull/83976 is landing in 4.3, so I'd prefer we just use the 3D scaling method for all rendering methods now. This way, there's only one way to achieve it in a way that doesn't lock you from switching rendering methods later on (or makes you use a suboptimal approach on Forward+/Mobile).

The separate-viewport scaling method is still worth documenting for 2D usage, but it's more niche in comparison, so it should remain in its separate demo and should cover 2D rendering instead. This mean it would have to be redone from scratch.

rcorre commented 7 months ago

I updated to only include the builtin scaling demo, and removed the 3D compat demo. I'm not as familiar with 2D, so I didn't attempt to create a 2D scaling demo.

Calinou commented 7 months ago

Merged manually with https://github.com/godotengine/godot-demo-projects/commit/722bd1168955b25e498d9b8967caf3970e02877e (which includes some visual and UI improvements to make scaling more noticeable). Thanks!

Screenshot