Hi, community!
Recently I had a discussion about how to draw a cylinder with outline and contours just for its lids.
I remembered, that I saw such functionality in LDrawLoader example.
@prisoner849 this looks great! I’d originally added support for conditional lines to the LDrawLoader but I hadn’t thought about generating them dynamically. It seems useful – it is a really nice effect.
It looks like your example generates control points only for a cylinder but it should be possible to generalize it for any geometry, right? Kind of like how EdgesGeometry works with a threshold for always rendered “hard” edge but also outputs conditional lines for everything else by looking at the adjacent faces.
An aside but looking at the shader again I wonder if it could be improved by collapsing a line down to 0, 0, 0 if it needs to be discarded instead of discarding all the pixels in the fragment stage. It might help performance in complex cases but I suppose it might be minor.
I use edges geometry a lot, and it does have its issues, so I’m always looking for alternatives. Could anyone explain what the difference is with the Ldraw edges compared to edges geometry? And @prisoner849 why wouldn’t you have done this with edges geometry?
@user123 Because I barely understood how it works in general.
LDraw conditional edges use additional information, that processed in shaders to decide if a line will be drawn or not. Maybe it’s possible to modify EdgesGeometry so it’ll have that additional information for vertices of geometry. Feel free to experiment with it
I’m guessing if edge geometry used a shader it would be a lot better performance-wise.
I will try to have a look at what you have done though and see if I can figure anything out but, unfortunately, I suspect it’s well beyond me
@prisoner849 That’s really great, thanks a lot. Ill try find some time to copy and throw some more difficult models at it. Could you see this as a replacement for the current Edges Geometry?
@user123
Not sure it’s a good candidate as a replacement.
It is needed in specific cases, when you really need such an outline effect. In other cases you’ll have a geometry with extra data (4 additional buffer attributes). And moreover, conditional segments need different material.
So, maybe it’s worth to be in examples as a separate module.
I took a crack at it too to see how it looked with more complex and smoother geometry – there are a few weird cases but it looks pretty good. This is using EdgesGeometry to render hard edges along with the conditional lines:
For collapsing a hidden edge I originally tried setting gl_Position to vec4( 0.0, 0.0, 0.0, 1.0 ) but saw some weird artifacts for some reason. I wound up just setting the position to the control point 0 vector in order to collapse the line – using the direction seems good, too. It work well enough on the two machines I tried it on, at least. I’m not sure why setting the position to 0.0 results in artifacts, though
I wasn’t planning on it but anyone is free to grab what they want from it. The quality of the effect is really dependent on the structure of the 3d model but it seems to look great when it works well.
It does have a little bit of a borderlands effect! Especially with the content of the 3d model.
If anyone is interested in more robust outline effects there were a couple solutions discussed in this github issue, too. Specifically this talk on the Borderlands outline effect which is all in screen space is really nice:
And this write up on using normal and depth buffers to extract outlines: