I would like to create a new line material that would be used to highlight objects’s edges, similar to what CAD programs do, when face outlines are shown. First I experimented with LineSegments2, LineSegmentsGeometry, and LineMaterial, but I think I will have to create something custom.
These are my requirements:
- I want to show the edges of an object’s faces.
- The color and thickness of the edge must be configurable.
- There shouldn’t be Z fighting between the drawn edge and the faces.
- I want to draw the edges that are occluded by the object itself, but with a different color (and possibly translucent).
Here is an example of what I want to achieve. Visible edges are black, occluded edges are white.
Items 1-3 are solvable with the aforementioned three classes. My main headache is the 4th item in the list. My current idea is to create a DepthTexture, pass it to the material and to the custom fragment shader and use the depth information to decide if the line is occluded or not. Maybe a separate render target and two render passes will be necessary for this, I not sure about that. To be honest, this whole thing feels a bit “hacky” and inefficient but I can’t think of anything better. Do you think this solution is feasible? Are there better solutions to this problem?