How to add “single pixel” edges to a Polygon2D

I’m looking to add “single pixel” edges to my Polygon2D objects, but I can’t figure out how. Here’s a simple example of what I’m hoping to achieve:

I’m still very new to shaders and it appears that making this is hard! Polygon2D polygons don’t have any default UV mapping, I’m not using any textures, and the pixel size of the outline would ideally be relative to the world and not to screen space.

How would I go about this?

Some sort of edge detection shader I would imagine. Not sure how accurate it would be though.

Finally figured this for my own use case and it’s actually in the docs: Custom drawing in 2D

I still had to do some trickery because the next polygon draw would slightly overlap. Putting the _draw() function into a child node that I set as top level did the trick though.

Here’s the final mess and the code:

extends Node2D

var parent : Polygon2D

func _draw() -> void:
  parent = get_parent()
  draw_polyline(parent.polygon, Color.WHITE, 2.0)

As you hinted at the UV mapping, that’s missing because just like I you don’t set a texture on that polygon2D. SubViewports are the way to go for that as explained in this video https://youtu.be/YCI0tL9L4sU?t=466

Besides using the _draw callback for a draw_polyline call, you can get Line2D to do this too (after feeding itspoints array the polygon’s polygon array), if you use the correct texture filter (this screenshot contains the it as the default setting in my PoC project, but you can assign it in any CanvasItem)

Here’s a scene tree. There are no shaders or whatever: