How to draw dashed line?


I am wondering how I can apply dashed lines (and dotted line) into regular lines. It would be really helpful if someone could give me any idea; I attached my toe file that displays a single sine wave. Thank you so much for your help.
question.toe (5.5 KB)

There’s the easier way, that’s slightly less robust, and a glsl way that can be really efficient but requires some knowledge of glsl.

The simpler way is to have a line, as a sop. And put a texture sop after and set it to … Segment length I think it is, though not at my machine to verify.

Then you simply use a constant mat, with a ramp texture set to horizontal with lots of repetitions.

You may have to play with the ramp period to get the look your after.

Thank you @lucasm
Unfortunately I am not familiar with glsl, so I am trying to follow your second idea. But to be honest, it’s been only three days since I started using TD, so it is a bit difficult to realize your idea on my side (for example, I could not find the segment length in the texture sop). If you don’t mind me asking, could you please show me your example? Thank you so much.

sorry it was called edge length, in the texture top!

edgeLengthDashedLine.1.toe (4.0 KB)

Also, welcome to the world of TouchDesigner :slight_smile:

Thank you @lucasm This looks awesome! Can I ask you some quick questions?

  1. Is it possible to change line weights by using the constant MAT like yours?
  2. If I use the line MAT instead of constant MAT, is it possible to apply the same ramp1 TOP into the line MAT to make the line dashed?

To be specific about my questions, I was able to control line weights with the line MAT but I could not apply the dotted/dashed texture over it. In contrast, with the constant MAT, I was able to apply the texture like yours but I could not find a way of how to change line weights.

Thank you so much for your help.

As you know there’s no texture slot anywhere in the line mat. So, it’s not possible to do both. Would be cool though! Maybe dashed line options or more general texturing options would be a good RFE to submit.

Maybe one of the devs can chime in on why the line mat is different, I suspect it’s because the line mat is doing much more complicated geometry shader generation, which probably makes using the incoming line sop’s uvs less clean, or nice looking.

One thing you could do, which would be a decent bit more expensive is to render out your line mat version, then with another render pass top, render out a very wide constant width line sop version, using the constant mat and dashed texture, then composite that with the original to create the dashed effect in top space.

you can set the line width in a constant top, by changing this parameter:

@lucasm I tried that but it didn’t work at all. Probably is the line width in the constant MAT not working in Mac?

seems to work here on windows, but ya I’m not sure what to tell you on osx! Don’t have a way to test there. Maybe someone else with experience there can chime in.