godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.16k stars 97 forks source link

Add antialiasing support to `CanvasItem.draw_multiline()` #6866

Closed Agecaf closed 18 hours ago

Agecaf commented 1 year ago

Describe the project you are working on

I am making a rhythm game with minimalistic aesthetics, notes will be drawn in canvas instead of using sprites. The exterior of a note can easily be drawn by using CanvasItem.draw_polyline, which draws lines connected with each other. There will be rhythmic markings on the inside, these could be easily drawn with CanvasItem.draw_multiline, which draws lines disconnected with each other.

Notes will move relatively quickly, so having them have antialiased graphics makes it look much, much smoother.

Describe the problem or limitation you are having in your project

Currently, CanvasItem.draw_multiline and CanvasItem.draw_multiline_colors do not have an option to be antialiased, while CanvasItem.draw_line and CanvasItem.draw_polyline can be antialiased.

In practice, if there's elements drawn without antialias, they look like they stutter, which is especially noticeable if they're close to elements which do have antialias.

While it is possible to rely on CanvasItem.draw_line to get the desired antialised multiple lines, being able to do so with the function designed to draw multiple lines directly would be more convenient.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

CanvasItem.draw_multiline and CanvasItem.draw_multiline_colors have an option to be antialiased.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

CanvasItem methods draw_multiline, draw_multiline_colors have an antialiased optional input, like the methods draw_line and draw_polyline.

draw_multiline ( PackedVector2Array points, Color color, float width=-1.0, bool antialiased=false )
draw_multiline_colors ( PackedVector2Array points, PackedColorArray colors, float width=-1.0, bool antialiased=false )

Implementationwise, I'm assuming something similar to the way draw_polyline can be antialiased might work?

If this enhancement will not be used often, can it be worked around with a few lines of script?

Yes, and very easily, by simply drawing multiple lines with draw_line.

But if this is the desired solution, why is draw_multilines around?

Is there a reason why this should be core and not an add-on in the asset library?

To standarize the ability to antialias lines among all the draw-lining methods of CanvasItem, instead of having some methods have the ability to antialias, and some others lack it.

Calinou commented 1 year ago

As a workaround, enable 2D MSAA in the advanced Project Settings. This is only implemented in Godot 4.x, and only works if using the Forward+ or Mobile rendering methods, not Compatibility.

kitbdev commented 19 hours ago