Very nice, I was thinking about adding more ways to visualize borders, that gives me some ideas.
The main difference is that I don’t identify quads, I detect if line segments belong to two coplanar triangles, so any flat shape will not have visualized edges inside it (like the ring in the example).
I can add some doc-like description here, you are interested in finding edges or visualization?
If I make borders the same width, they will not match, and I don’t want to make the shader code way more complex and slow, so I’m going to call it a feature not a bug and leave it as is for now.
The solution for long large polygons is currently to divide them, for example:
First, all the required info about segments is gathered, each triangle is considered to be made out of 3 segments:
Each segment can be a part of one or two triangles. For each of these triangles a normal is calculated and if all the normals are parallel to each other to a certain (customizable) degree, the segment is not an edge, otherwise it is.
The visualization is based on interpolation of vertex attributes, namely, RGB colors. Each segment is associated with one RGB channel and, in case the segment is an edge, a gradient (from 1 to 0) is created in that channel, that can then be used for creating visuals in the fragment shader.
in case the segment is not an edge, there is no gradient.
this info is stored in clr / vclr attribute.
To remove notches, some vertices assigned values of another clr2 / vclr2 attribute, to create similar gradient, based on the observation that if a segment has a gradient of vclr in any of the triangles it belongs to, there will be “a notch situation” that needs to be resolved.
The code is not really optimized for speed, but you can run it once “offline”, print out clr and clr2 attributes and hardwire them back to your program, in this case you don’t need the code.
When I asked for instructions, I was talking about a simple Github style documentation.
// Usage
Import { method } from "lib"
const result = method(x)
But you went with a thorough explanation, this can be a draft for a premium level medium article. Thank you very much for your kindness and taking the time instructing a fellow three.js pal, I definitely learned something new here and for sure it will come in handy in the future.