Outline Generation for 2D Shape

Hi community!

Is it possible to generate an outline (optionally dashed) for a generic 2D shape (random polygon) using shading? I’ve already tried to research the topic and came across edge detection. Unfortunately, I wasn’t able to implement it… is it even possible? Currently, I’m solving it using an inner and outer extruded geometry, but this approach isn’t very performance-friendly when dealing with many elements.

Example:
https://codepen.io/Faustooo/pen/jEEmBjK

You can probably achieve this with a shader or hacked material of some kind, but controlling the appearance on arbitrary polygons might be challenging. For just a square it probably wouldn’t be too bad