godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.26k stars 21.04k forks source link

Mouse position not being scaled when nested viewport size is different from parent viewport #59858

Open kidinashell opened 2 years ago

kidinashell commented 2 years ago

Godot version

v3.5.beta3.official [3c0d32562]

System information

Windows 10, GLES3

Issue description

Info: The problem persists in earlier stable versions of Godot as well (3.3x and 3.4x)

What doesn't work? Mouse position is not scaled when using a viewport inside another viewport (through a ViewportContainer) and the child viewport has a different resolution (smaller or bigger) than the parent viewport.

https://user-images.githubusercontent.com/61805849/161480935-6852a68e-2bb9-4990-b615-c860ededdd43.mp4

How do I expect it to work? Mouse position is scaled to allow for child viewports inside parent viewports where the child viewport has a different resolution (for example super sampling / "down" sampling.

https://user-images.githubusercontent.com/61805849/161480979-84712438-34d3-46fe-9b99-8bbf1ac51999.mp4

Steps to reproduce

I've added a sample project which is also used for the showcases (videos) up top. The following steps can be used to reproduce from scratch and explains the necessary project setup which will lead to the mentioned behavior.

FIX FOR NOW: This bug can be circumvented with attaching the child viewport rectangle to the parent viewport rectangle. The following is from my example project which you can find below, to get a little deeper into this special case:

`var vrect = get_viewport().get_visible_rect()

#--- necessary for NON-HiDPI monitors ---#
print(vrect.size) # 1968 x 1080 on NON-HiDPI / 1920 x 1080 on HiDPI
vrect.size = get_viewport().size
print(vrect.size) # 1540 x  845 on NON-HiDPI / 1920 x 1080 on HiDPI
#----------------------------------------#

viewport.size = get_viewport().size * su_sa_scale

#--- necessary step to make sure, that mouse positions gets picked correctly;
#--- not quite sure why?
#--- UNCOMMENT LINE BELOW!

# viewport.set_attach_to_screen_rect(vrect)`

Minimal reproduction project

viewport_mouse_pos.zip

Calinou commented 2 years ago

Related to https://github.com/godotengine/godot/issues/34805 (possible duplicate?).

kidinashell commented 2 years ago

@Calinou Yes and no. The issue was mentioned for version Godot_v3.2-beta5_x11. Other people also mentioned this version or the following version 3.3. Then, the issue was added to the 4.0 Milestone, issue got copied over to 4.0, fixed there and closed, but it was nevrer fixed in the earlier versions, as far as I can see. Currently I see three different branches, where issues get fixed separately. 3.4, 3.x and 4.0. This issue was already fixed for 4.0 in #57082. Since 3.x get's released separately from 3.4 and 4.0 in the news section of godotengine.org I think it would be a good idea, to keep this separately, so it doesn't get merged with the other one, then fixed in one branch but not the other.

Calinou commented 2 years ago

Currently I see three different branches, where issues get fixed separately. 3.4, 3.x and 4.0.

Work on the stable Godot is only done on the 3.x branch, with bug fixes being cherry-picked to 3.4. The 3.4 branch generally doesn't have any work being done directly on that branch (since it would be lost after migrating to 3.5).

If https://github.com/godotengine/godot/issues/59858 is fixed in master, then its milestone should be changed to 3.x.