X Tutup
Skip to content

[Visual Shader] Fix nodes' relative positions changed in a different display scale.#97620

Merged
akien-mga merged 1 commit intogodotengine:masterfrom
jj11hh:master
Dec 1, 2025
Merged

[Visual Shader] Fix nodes' relative positions changed in a different display scale.#97620
akien-mga merged 1 commit intogodotengine:masterfrom
jj11hh:master

Conversation

@jj11hh
Copy link
Contributor

@jj11hh jj11hh commented Sep 29, 2024

Node positions are not affected by theme scale but their sizes are. Fix this by multiplying GraphElements' positions by the theme scale.

Fix #97484 .

It is worth discussing whether is GraphEdit responsible for maintaining a consistent relative distance between GraphElements under different DPIs.

But in any case, before GraphEdit makes such compatibility-breaking changes, it is worthwhile to make Visual Shader Editor work properly at different DPIs.

Before:

Graph with 100% display scale:

屏幕截图 2024-09-29 231628

Graph with 200% display scale:

屏幕截图 2024-09-29 231955

After

Graph with 200% display scale:

屏幕截图 2024-09-29 231715

@jj11hh jj11hh requested a review from a team as a code owner September 29, 2024 15:57
@jj11hh jj11hh changed the title Fixed an issue where nodes' relative positions changed when opened a different display scale. [Visual Shader] Fixed nodes' relative positions changed in a different display scale. Sep 30, 2024
@jj11hh jj11hh deleted the branch godotengine:master September 30, 2024 08:24
@jj11hh jj11hh closed this Sep 30, 2024
@jj11hh jj11hh deleted the master branch September 30, 2024 08:24
@jj11hh jj11hh restored the master branch September 30, 2024 08:28
@jj11hh
Copy link
Contributor Author

jj11hh commented Sep 30, 2024

accidently closed by renaming branch, reopen now

@jj11hh jj11hh reopened this Sep 30, 2024
@AThousandShips AThousandShips changed the title [Visual Shader] Fixed nodes' relative positions changed in a different display scale. [Visual Shader] Fix nodes' relative positions changed in a different display scale. Sep 30, 2024
@AThousandShips AThousandShips added this to the 4.4 milestone Sep 30, 2024
@AThousandShips AThousandShips added the cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release label Sep 30, 2024
Copy link
Member

@Geometror Geometror left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was concerned that the positions of each node would change in the resource file each time your scale changes (problematic for teams), but this is not the case. However, the size does change. In case you have the time, could you check why this is happening? Otherwise I think it would be fine to merge without the size fix.

@jj11hh
Copy link
Contributor Author

jj11hh commented Sep 30, 2024

I was concerned that the positions of each node would change in the resource file each time your scale changes (problematic for teams), but this is not the case. However, the size does change. In case you have the time, could you check why this is happening? Otherwise I think it would be fine to merge without the size fix.

The positions in the resource file will not change by display scale with or without this fix. The editor stores the top-left position to file. But, with a bigger scale, all nodes will be rendered larger, which makes them overlap with each other.

Which makes the same graph look very different on different display scales. Shaders made by creators with a larger scale (may have a hiDPI display) show more sparse than normal on a smaller display scale and vice versa.

This fix makes no change to the stored position but applies scale to the nodes' position on canvas to avoid this case.

@jj11hh
Copy link
Contributor Author

jj11hh commented Sep 30, 2024

I was concerned that the positions of each node would change in the resource file each time your scale changes (problematic for teams), but this is not the case. However, the size does change. In case you have the time, could you check why this is happening? Otherwise I think it would be fine to merge without the size fix.

I have figured out that the node size is affected by multiple elements.
The most important thing may be font size. And it is scaled by EDSCALE(editor_fonts.cpp:153.).

image
This screenshot shows the window on display scale 150% but I changed editor_fonts.cpp from

	p_theme->set_default_font_size(default_font_size);

to

	p_theme->set_default_font_size(default_font_size / EDSCALE);

Where default_font_size was set to

// editor_fonts.cpp:153
	const int default_font_size = int(EDITOR_GET("interface/editor/main_font_size")) * EDSCALE;

The editor's theme's base scale is set to EDSCALE(editor_theme_manager.cpp:561).

EDSCALE and theme base scale (In an editor, they are the same thing) are used to determine minimal control size and some line width and content margin, they also affect node size.

Copy link
Member

@Geometror Geometror left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the long wait.
Looks like the display size of resizable nodes (inheriting from VisualShaderNodeResizableBase) also changes, which causes e.g. the expression node to be much bigger than it should at 200% editor scale:

100% scale 200% scale
Screenshot_20241120_191443 Screenshot_20241120_191613

@@ -281,6 +281,8 @@ class VisualShaderEditor : public ShaderEditor {
VBoxContainer *param_vbox = nullptr;
VBoxContainer *param_vbox2 = nullptr;

float cached_theme_base_scale = 1.0f;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just use EDSCALE instead of this separately cached scale?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I think eventually we will remove the EDSCALE macro for DPI per-monitor awareness

@Repiteo Repiteo added the cherrypick:4.4 Considered for cherry-picking into a future 4.4.x release label Feb 24, 2025
@Repiteo Repiteo modified the milestones: 4.4, 4.5 Feb 24, 2025
@Repiteo Repiteo added the cherrypick:4.5 Considered for cherry-picking into a future 4.5.x release label Sep 5, 2025
@Repiteo Repiteo modified the milestones: 4.5, 4.6 Sep 5, 2025
@OeilDeLance
Copy link

OeilDeLance commented Nov 18, 2025

This is a really good fix for a problem that is recurrent when more that one person is working on the same visual script.
Node positioning is a really important thing for a readable script and this bug makes it impossible to work at different DisplayScales.

I would really appreciate it if someone would retarget this to 4.5 or 4.6. I would very much like to integrate it to my own Godot build, even if it is not quite finished.

@jj11hh jj11hh requested a review from a team as a code owner November 18, 2025 15:16
@Repiteo Repiteo modified the milestones: 4.6, 4.x Nov 18, 2025
@jj11hh
Copy link
Contributor Author

jj11hh commented Nov 19, 2025

This is a really good fix for a problem that is recurrent when more that one person is working on the same visual script. Node positioning is a really important thing for a readable script and this bug makes it impossible to work at different DisplayScales.

I would really appreciate it if someone would retarget this to 4.5 or 4.6. I would very much like to integrate it to my own Godot build, even if it is not quite finished.

Done, you can test it.

@akien-mga akien-mga requested a review from Geometror November 28, 2025 09:55
@OeilDeLance
Copy link

We will very soon try to test this out on 4.5.1.
Will that merge fine ? Or is it more of a 4.6 retarget ?

@AThousandShips
Copy link
Member

This might be merged for 4.6, it's currently on the 4.x milestone, it will probably be cherry-picked for a 4.5.x version like 4.5.2

@OeilDeLance
Copy link

OeilDeLance commented Nov 28, 2025

Thanks for the quick answer, I did not know there was a 4.5.2.
Ok So we'll cherry pick and hope it's not gonna be too hard :)

Copy link
Member

@Geometror Geometror left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Retested, still works.
There is still the problem with VS nodes derived from VisualShaderNodeResizableBase like Expression (see my earlier comment), however this isn't a regression, so I think we can merge as is. As others have mentioned, this is a rather important fix for larger teams where several people work on the same VisualShader.

@jj11hh
Copy link
Contributor Author

jj11hh commented Nov 29, 2025

Godot's Editor UI still handles DisplayScale in a very messy way. The best approach may be to use density-independent pixels at the GUI framework level.

This fix isn't perfect. As it stands, a major overhaul of the GUI is needed to remove the use of pixels as the unit of measurement for UI components. We also need to remove the EDSCALE macro to support per-monitor Display Scale.

@akien-mga akien-mga modified the milestones: 4.x, 4.6 Nov 29, 2025
@akien-mga akien-mga merged commit 1575e3d into godotengine:master Dec 1, 2025
20 checks passed
@akien-mga
Copy link
Member

Thanks!

@akien-mga akien-mga removed the cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release label Dec 1, 2025
@akien-mga akien-mga removed the cherrypick:4.4 Considered for cherry-picking into a future 4.4.x release label Jan 8, 2026
@akien-mga
Copy link
Member

Cherry-picked for 4.5.2.

@akien-mga akien-mga removed the cherrypick:4.5 Considered for cherry-picking into a future 4.5.x release label Jan 8, 2026
@jj11hh jj11hh deleted the master branch January 18, 2026 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Visual Shader looks messy after changed display scale factor

6 participants

X Tutup