-
Notifications
You must be signed in to change notification settings - Fork 346
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
h2d.Graphics accuracy #776
Comments
Why do we add 0.01 to the vertices in a rect? Lines 467 to 473 in 50e0707
In my case it seems more accurate if I remove this code. |
Try to compile & run the example, then take a screenshot and look at the overlap between Graphics rect and Bitmap rect. Both should cove exactly the same zone |
I compiled your example. If you multiply the line size by 3, it seems like the problem is that the line width (3 pixels) can't possibly be centered around the rectangle boundaries: If I run your example (line size = 1) with my #969, I get: Now my question is: is it actually bad to have the lines not be drawn inside the rectangle? I doesn't seem much worse to me than only fixing the issues when the object offset aligns exactly with a pixel. What makes the problem a bit hard is that in Graphics.hx it's impossible to know the pixel alignment (also given viewport transformations, e.g. using Camera). What do you think of the following idea: Make shape borders be calculated inside (or outside) the shape. We don't need to know pixel alignment for this and the borders can be calculated perfectly. This would require calculating separate line offsets for each shape (easier) or creating a generic line drawing algorithm (maybe with modes |
The idea of 2d Graphics is that if you draw lines at x=55 then after taking
a screenshot it should be at this specific pixel. So yes its important to
have a pixel perfect rendering.
Le lun. 28 juin 2021 à 08:55, Christian Zommerfelds <
***@***.***> a écrit :
… I compiled your example. If you multiply the line size by 3, it seems like
the problem is that the line width (3 pixels) can't possibly be centered
around the rectangle boundaries:
[image: image]
<https://user-images.githubusercontent.com/1260622/123558100-e5795d80-d794-11eb-8076-2c9298087977.png>
If I run your example (line size = 1) with my #969
<#969>, I get:
[image: image]
<https://user-images.githubusercontent.com/1260622/123590968-b7733800-d7eb-11eb-9d8f-4bbf2344add8.png>
Now my question is: is it actually bad to have the lines not be drawn
inside the rectangle? I doesn't seem much worse to me than only fixing the
issues when the object offset aligns exactly with a pixel.
What makes the problem a bit hard is that in Graphics.hx it's impossible
to know the pixel alignment (also given viewport transformations, e.g.
using Camera).
What do you think of the following idea:
Make shape borders be calculated inside (or outside) the shape. We don't
need to know pixel alignment for this and the borders can be calculated
perfectly. This would require calculating separate line offsets for each
shape (easier) or creating a generic line drawing algorithm (maybe with
modes Center, InsideClockwise, OutsideClockwise)
[image: image]
<https://user-images.githubusercontent.com/1260622/123592972-3ff2d800-d7ee-11eb-8274-5ed282c1f059.png>
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#776 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAHZXQCGFJW3BVP6DATLKWTTVAMG5ANCNFSM4LVRMBLA>
.
|
Well unless x=55 is the rightmost point of a horizontal line, then the pixel at 55 should be empty and start at 54, right? So what do you think of the inset vs outset idea? This would allow pixel perfect rendering. |
I just updated #969. It now draws all the examples nicely. The only thing is that it now insets all lines as opposed to centering. This is good for pixel perfect rendering, but maybe some users would like to draw lines with their size centered. If you are interested I can add some enum or boolean to allow choosing between those modes. |
Yes I think we should have a default of "centered". When drawing lines with 1 pixel size, the default should be to match exactly what would happen if you draw on CPU in a bitmap, hence my comment earlier about x=55. A vertical line there should draw the pixel at x=55 and 54 would be empty. For odd line sizes there should be not be any problem as it's adding pixels around this line (3,5,9, etc.) on both sides equally. |
Hi Nicolas, one way to interpret what you are saying is that lines should start and end in the middle of pixels (+0.5/0.5). Adding a 0.5/0.5 offset would work if the Graphics object is pixel aligned, but won't if you can flexibly move the camera around, for example. I don't know how to solve this without adding more complexity to the Base2D shader or generic object rendering. Would you be interested if I updated my PR to support a default "centered" alignment but use inset (align right of line) for drawing shapes? If I understand the requirements correctly this would solve the problem here. It would also solve the problem of the arbitrary offset that is visible at higher zoom levels. Personally I find that having the border inside the shape is intuitive (like CSS). But we could leave the option open to the user by having a lineStyle(..., align) parameter. |
Using the following sample, I was about to see that h2d.Graphics was not very accurate when drawing lines using various primitives:
The text was updated successfully, but these errors were encountered: