Drawing thick 3D lines
Asked Answered
W

9

0

I can't seem to find a way to draw thick three-dimensional lines. Line width parameter in the spatial shader says it's disabled. I also cannot use custom shaders because there is no access to vertex data in screen space. Is there a way to draw 3D lines in Godot? My project depends on this ability.

Woodham answered 13/9, 2021 at 5:22 Comment(0)
T
0

Godot currently has no built-in way to draw 3D lines in projects, so you have to resort to procedural geometry generation or use primitive meshes instead. You can use add-ons such as https://github.com/RedefineGamedev/Line3D (more full-featured) or https://github.com/jegor377/Line3D (simpler).

Alternatively, you can create a MeshInstance with a BoxShape or CylinderShape and stretch it to draw a thick straight line.

Line width parameter in the spatial shader says it's disabled.

The Line Width property only works for line-based geometry, not triangle-based geometry. Even then, relying on the Line Width property is ill-advised as its behavior is driver-specific (OpenGL line drawing is used). For instance, AMD GPUs don't support any line widths greater than 1.

Turoff answered 13/9, 2021 at 20:43 Comment(0)
W
0

Initial idea required drawing splines. I then simplified the whole concept to use circular arcs (still in 3d space). As per visual concept, I need to stroke the same line/curve with multiple superimposed strokes of different widths. Most elegant way to handle this would be by screen space shaders.

In the end I settled for a single stroke. Generating it via immediate geometry node as a 3d tube (i.e. thin partial torus positioned in 3d space). It's not exactly what I wanted but it'll have to do.

Thanks for the insights!

Woodham answered 13/9, 2021 at 23:49 Comment(0)
B
0

You can render wireframe with barycentric coordinates. Not sure if that is what you need, but it may give you some ideas. This is a Unity tutorial, but all the math is there if you want to port to Godot. https://catlikecoding.com/unity/tutorials/advanced-rendering/flat-and-wireframe-shading/

Boldt answered 14/9, 2021 at 4:23 Comment(0)
W
0

Thanks @cybereality. Not sure if it's really applicable to standalone lines but it's still good to know. In fact I'm using similar approach in current project to render meridians and parallels on a globe.

Woodham answered 14/9, 2021 at 12:11 Comment(0)
B
0

No, it wouldn't work for standalone lines, it's for rendering geometry in wireframe.

Boldt answered 14/9, 2021 at 17:5 Comment(0)
W
0

I think Godot currently can't do this in an elegant way. Adding a shader option to skip projection transforms would be enough to allow for making custom line stroking shaders. Similar to already exsisting skip_vertex_transform. But I'm guessing this may break something down in the spatial material pipeline.

Woodham answered 14/9, 2021 at 22:15 Comment(0)
B
0

Are you sure about that? You can do whatever you want in the vertex shader, including not doing anything (and just leaving the points in local space). Also, with that wireframe shader I posted, you can draw a standalone line by rendering a triangle and not processing the 2nd two edges. It's a bit of a round-about, but it works fine.

Boldt answered 15/9, 2021 at 1:16 Comment(0)
W
0

Local space is not enough. I need to be able to control them in screen space. Documentation explicitly states that when you disable vertex transforms, projection transformation happens anyway "later". There's even an example that shows "manual" vertex-matrix multiplication and it does only modelview multiplication. Even though you get the projection matrix as a built-in uniform, there's no use for it in this regard. Projection part is seemingly automatic and hidden from the user. I suspect there's a good reason for it.

Anyway, drawing straight lines is not my main concern. I need 3d curves; smooth, thick and with controllable, possibly animated width. Best way to do it is to expand triangle strips in screen space. I even have operational glsl shaders from my previous gl projects. It would be trivial to adapt them if automatic projection multiplication could be disabled and instead be done manually.

That all being said I still love Godot's light abstraction of glsl.

Woodham answered 15/9, 2021 at 2:23 Comment(0)
B
0

Interesting. I don't think I tried to draw in screen space so maybe that is why I never encountered that problem. I understand what you are saying.

Boldt answered 16/9, 2021 at 0:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.