-
-
Notifications
You must be signed in to change notification settings - Fork 97
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
Add a way to draw 1-pixel wide lines that scale with viewport zoom #1363
Comments
Here's the code that handles line width in 4.0 for reference:
From what I can gather from previous discussions, we could simply add an extra argument to this method and
|
I agree :-) |
Describe the project you are working on:
I'm coding some tools we need for our current project and at one point I needed to draw a rectangle enclosing an area of a sprite.
Describe the problem or limitation you are having in your project:
I set the line width to 1 expecting a thickness of one pixel of the sprite. Instead, the line is literally of 1 pixel width, giving an unexpected result as it wasn't taking into account the amount of zoom the viewport had. Further experimentation showed the problem happened while in game too, not only in the editor viewport.
I opened an issue but it looks like the bug was already reported (but I missed it when I searched before opening a new one):
Mine: godotengine/godot#41176
Older: godotengine/godot#19844
As the bug was already reported I closed my issue, but as suggested by @pouleyKetchoupp I'm bringing this to the Godot proposals. In my report there are screenshots showing both the bug and the expected result, the first patch I did at the code of Godot and a small Godot project showing the problem (shown in the second set of before-after images).
The issue is present both in the 3.x and 4.x branches, and affects Vulkan, GLES2 and GLES3. It is caused by a optimization where the line draw function checks if the width is <= 1 so it can use a simpler approach for speed reasons. As it can be seen in my issue I tried to patch the check and recompile Godot but I was a bit clumsy with the pull requests :-) Also I didn't take into account Vulkan (I'm currently at version 3.2.2).
This problem happens when using draw_rect(), etc, as in the end it's the line draw function that is called.
Describe the feature / enhancement and how it helps to overcome the problem or limitation:
Reading the old issue has been interesting because we all arrived at similar conclusions. Probably not really a good idea to fix for 3.x at this point? But there are use cases both for the correct width and the fixed 1 pixel width, so for the sake of correctness it would be nice to make this work.
Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
I propose to change the size check for a constant with a negative value, instead of less or equal than 1. A value of 0 should give a non-visible line. A value of 0.5 should give a line that is half the width of a line 1 pixel thick if the zoom level allows for it. Or have a new draw line function that only draws lines of 1 pixel screen space pixels width.
I'm quite happy with Godot and plan to contribute when I can, so I would be happy to make a new pull request after we agree on the best way to fix the issue.
If this enhancement will not be used often, can it be worked around with a few lines of script?:
It can't be worked around.
Is there a reason why this should be core and not an add-on in the asset library?:
It's a change on "core" code.
The text was updated successfully, but these errors were encountered: