Login | Register
 FEATURES APPLICATIONS DOWNLOADS EDUCATION BLOG WIKI FORUM STORE

## How do you render a bunch of 2d lines efficiently?

General discussion about anything TouchDesigner

### How do you render a bunch of 2d lines efficiently?

I have a bunch of 2d lines defined by start x,y and end x,y; These values are in a table DAT.

What is the best way to draw a bunch of 2d lines using these points?
danoved

Posts: 15
Joined: Tue May 01, 2018 11:04 pm

### Re: How do you render a bunch of 2d lines efficiently?

Hi there,

TouchDesigner doesn't have an easy way to do this strictly in 2D I believe. The best way to do it using native objects is to have an orthographic camera projection and using the replicator COMP, this will be efficient and will have the behaviour you expect. Only thing to consider is that you are gonna be referring to vectors in space, not pixel positions, so in some software something like this for instance:

line(0, 0, 50, 0)

Refers to points in pixels (startX = pixel 0, startY = pixel 0, EndX = pixel 50, end Y = pixel 0) .

With this method in contrast you refer to space positions, so the leftmost position in X would be -1 and the rightMost +1, for the upmost position of Y, it will be the ratio between the resolutionHeight / resolutionWidth * -1 and the downmost will be the positive version of that. Hope this makes sense.

If your table is in pixels, then a simple re-scaling using these guidelines can help you convert to the right space

Find attached an example.

Best,
Darien
Attachments
lines.tox
(1.99 KiB) Downloaded 96 times
__________
Darien Brito | AV artist - Multimedia Programmer
Qvoloid

Posts: 77
Joined: Wed Jun 25, 2014 6:29 pm
Location: Netherlands, Den Haag

### Re: How do you render a bunch of 2d lines efficiently?

If you dislike replicators you can also do this with a single DATto SOP.

Dariens tox modified for that technique attached.
Attachments
lines_noreplicator.tox
(1.26 KiB) Downloaded 111 times
Richard Burns

Ennui

Posts: 510
Joined: Sat Oct 03, 2009 2:23 pm

### Re: How do you render a bunch of 2d lines efficiently?

I think an incredibly efficient way would be to the coordinates into a texture, and then read those coordinates into a shader that uses line SDFs to contstruct the final image. However, the best performance to work ratio will probably be getting your center + width + rotation data into a Table DAT, using a DAT to CHOP, and then instancing a line sop with a wireframe material. If you only have the XY coordinates of the start and end of each line, presumably you could use function CHOPs to compute the center / width / rotation before the instancing.
Jonathan Thompson
@pointshader
http://pointshader.com

jmt4zj

Posts: 160
Joined: Mon Nov 01, 2010 3:15 am
Location: NYC

### Re: How do you render a bunch of 2d lines efficiently?

I made this approach as a take on your question here a few days ago which is quite similar to the instanced line approach jmt4zj suggested. Though it's even simpler as instead of computing the centres and rotation we can just subtract one point position/vector from the other to get the vector between the two points and use that to non-uniformly scale a simple gl line from one point to reach the other point.

This approach doesn't include a DAT to CHOP, I just used some noise CHOPs but you add that in fairly easily, or modify the approach to instance directly from a DAT. Though as jmt4zj mentioned if you want to animate them most efficiently you could store the positions in a texture / TOP and compute transformations there using GLSL TOPs and GLSL MAT executing on the GPU. But all you need is dozens or even hundreds of points (but not thousands,) that's a bit overkill and you might as well stick with DATs or CHOPs executing on the CPU.
Attachments
line_p2p_instancing.tox
(2.9 KiB) Downloaded 128 times

landonth

Posts: 79
Joined: Tue Sep 09, 2014 11:15 pm

### Re: How do you render a bunch of 2d lines efficiently?

Hi, someone really helped me in same problem on the Facebook Group called "TouchDesigner Help Group". Just search for "truncador lines 20'000" post.
Simplo

Posts: 82
Joined: Thu Feb 05, 2015 5:39 am

### Re: How do you render a bunch of 2d lines efficiently?

Moving from Techniques to General.

nadine
Staff

Posts: 23
Joined: Tue Oct 10, 2017 5:21 pm

Return to General TouchDesigner Discussion

### Who is online

Users browsing this forum: No registered users and 13 guests