Skip to content
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

[4.x] Faster Path2D drawing with polyline #55516

Merged
merged 1 commit into from
Dec 1, 2021

Conversation

lawnjelly
Copy link
Member

@lawnjelly lawnjelly commented Dec 1, 2021

Changes the Path2D drawing to use POLYLINE instead of thick lines.

Notes

  • Part version of Faster editor line drawing - Path2D and draw_line #54377 for Godot 4. There was interest in the PR meeting to port this to master.
  • The drawing lines as polygons part of the original PR is not done here because there is no batching in master
  • The anti-aliasing option seems to actually produce feathered polylines rather than anti-aliased at the borders. So it may be worth waiting for that to get fixed before merging this. Alternatively merging this may cause the anti-aliasing to get fixed.
  • I did try without anti-aliasing, but the lines didn't look very good at low scales. EDIT: Actually the existing code doesn't look good at low scale either so maybe that is an option...

Before this PR

Before zoomed out:
Screenshot from 2021-12-01 15-35-07

Before zoomed in:
Screenshot from 2021-12-01 15-35-25

This is the result of the PR with anti-aliasing on (the current pushed state):

After zoomed out:
Screenshot from 2021-12-01 15-31-53

After zoomed in:
Screenshot from 2021-12-01 15-31-29

Also for comparison, this PR with anti-aliasing switched to off (let me know if this is preferred and I can change it):

Screenshot from 2021-12-01 15-42-55
Screenshot from 2021-12-01 15-43-07

Changes the Path2D drawing to use POLYLINE instead of thick lines.
@lawnjelly lawnjelly requested a review from a team as a code owner December 1, 2021 15:29
@lawnjelly lawnjelly changed the title Faster Path2D drawing with polyline [4.x] Faster Path2D drawing with polyline Dec 1, 2021
@lawnjelly lawnjelly added this to the 4.0 milestone Dec 1, 2021
@Calinou
Copy link
Member

Calinou commented Dec 1, 2021

The anti-aliasing option seems to actually produce feathered polylines rather than anti-aliased at the borders. So it may be worth waiting for that to get fixed before merging this. Alternatively merging this may cause the anti-aliasing to get fixed.

In master, line antialiasing is done with triangle strips rather than relying on drawing a GL_LINE_SMOOTH line on top of the line's edge. This looks better and works properly with translucent lines, but it needs to be carefully tweaked to avoid looking blurry. For correct appearance, the camera zoom and 2D scale factor should be taken into account, and I don't think that's being done yet.

@lawnjelly
Copy link
Member Author

Yup I'm sure doing it properly ourselves will be better in the long run (for instance, OpenGL AA doesn't do anything on a lot of hardware, including most mobile afaik). Am unsure whether to leave this PR as is or just switch the anti-aliasing to false as a stop gap. 🤔

@clayjohn
Copy link
Member

clayjohn commented Dec 1, 2021

Can you post a before/after performance comparison?

@lawnjelly
Copy link
Member Author

Can you post a before/after performance comparison?

Yup sure I'll take a look. It's probably less than in 3.x as drawcalls are more expensive there, be interesting to see actually. 😁

@lawnjelly
Copy link
Member Author

lawnjelly commented Dec 1, 2021

Have done a test with 10 fairly squiggly Path2Ds and a small window (my GPU isn't super powerful so this is good to test vertex / drawcalls rather than fillrate).

Before 130 fps
After (with AntiAlias) 1300 fps
After (without AntiAlias) 2100 fps

So comparing like with like (as before has no anti alias) it's around 16x faster on my system.

That's fairly typical for differences I've seen between batched stuff and vulkan - vulkan is faster than GL but batched stuff for canvas items is still a good 10x faster in a lot of cases (for same type stuff). For mixed rendering vulkan does relatively better.

I think on 3.x, this code is around 40-80x faster which is more typical for GL, and that will probably be the case for the OpenGL renderer in Godot 4.

Here's the project BTW (needs recompiling with and without PR):
Dec21.zip

@akien-mga akien-mga merged commit 1c5a889 into godotengine:master Dec 1, 2021
@akien-mga
Copy link
Member

Thanks!

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.

4 participants