LDraw-like edges

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.

After reading the source code of the loader and LDraw specs (Line Type 5), here is an attempt to create such outlined cylinder: https://codepen.io/prisoner849/pen/dyGqWJy?editors=0010

UPD #1
Here is a prototype of enhanced EdgesGeometry, that produces data for approach with conditional line segments.

UPD #2
Looks interesting with a glTF model :slight_smile:

14 Likes

@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.

Nice work!

2 Likes

Looks really nice!
Looking forward to a general solution, maybe as a part of EdgeGeometry?

@gkjohnson
The loader is great job!

And yeah, I had the same thought about to move “discarding” to vertex shader.
So, here is two slightly different options with this approach:

  1. Uses an attribute with exact point that the last point of a line moves to:
    https://codepen.io/prisoner849/pen/BajOVgw

  2. Coordinates of the last point of a line compute in vertex shader, based on direction and distance (another attribute):
    https://codepen.io/prisoner849/pen/oNbPMzL

2 Likes

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. :blush:
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 :slight_smile:

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 :sob:

1 Like

Update in the main post :slight_smile:

@user123 @gkjohnson thanks for interesting question/idea :beers:

1 Like

@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.

1 Like

Update #2 in the main post.

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:

Here’s the live demo:

https://gkjohnson.github.io/threejs-sandbox/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 :confused:

10 Likes

@gkjohnson
Awww… from my point of view, it looks just great! :+1:
Do you plan to add it to official examples?

1 Like

this is awesome! wau

1 Like

tenor-1

2 Likes

@gkjohnson’s example reminded me about this:

3 Likes

Reminds me as well of
Scanner Darkly trailer

Fringe Episode 3.19 Scene - Your Safe

XIII game play


2 Likes

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:

2 Likes

Will this effect be added to EdgeGeometry/ threejs ?

@Deel96 This effect needs specific geometry and specific material.