Godot-docs: Custom Drawing 2D: Add section on drawing anti-aliased lines

Created on 15 Apr 2019  Â·  1Comment  Â·  Source: godotengine/godot-docs

Currently the custom drawing in 2D tutorial demonstrates how to create aliased lines only:
https://docs.godotengine.org/en/latest/tutorials/2d/custom_drawing_in_2d.html

For many use cases, dynamically drawn antialiased lines are necessary to match an existing game aesthetic (e.g. a dynamically drawn HUD targeting display in a futuristic FPS, or trajectory preview in a minimalist 2d artillery/angry birds game). I think the article needs the addition of information on how to achieve dynamically drawn antialiased lines.

This is motivated by a personal need! In Unity I used the Vectrosity plugin to draw antialiased lines, I'm wondering how to do this in Godot.

enhancement

Most helpful comment

I think this functionality should be added in core for all kinds of 2D line drawing. Currently, draw_line() offers an antialiased parameter but it doesn't work well in all situations (e.g. with translucent lines). See https://github.com/godotengine/godot/issues/12840 and https://github.com/godotengine/godot/issues/8289.

As a workaround, you may be able to use Line2D/Path2D + Curve2D with a texture that features an one-pixel gradient on the top and bottom edges — see this example project I made. It works quite well with constant line widths, but antialiasing won't look as good if the line width is variable (since the gradient may end up being too thin or too thick for the displayed size).

>All comments

I think this functionality should be added in core for all kinds of 2D line drawing. Currently, draw_line() offers an antialiased parameter but it doesn't work well in all situations (e.g. with translucent lines). See https://github.com/godotengine/godot/issues/12840 and https://github.com/godotengine/godot/issues/8289.

As a workaround, you may be able to use Line2D/Path2D + Curve2D with a texture that features an one-pixel gradient on the top and bottom edges — see this example project I made. It works quite well with constant line widths, but antialiasing won't look as good if the line width is variable (since the gradient may end up being too thin or too thick for the displayed size).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RiverMesa picture RiverMesa  Â·  4Comments

eon-s picture eon-s  Â·  5Comments

youreperfect picture youreperfect  Â·  3Comments

puthre picture puthre  Â·  4Comments

mhilbrunner picture mhilbrunner  Â·  3Comments