Connected points. GLSL or particle

Hi!

Im new to touchdesigner. I have been using processing a lot before and are more used to code. I want to make a particle system where every particle is connected to the other particles with lines according to the distance. I can easily code this in processing but how do I manage in good way in touchdesigner? Shall I look into building GLSL shaders?

In processing I would have treated every particle as an object, giving them individual velocity, deciding their starting position etc. Then I would connect the different objects to eachother with lines while looping through the objects.

But how can I manage the same in touchdesigner in the best way. on the GPU? Can I do all this coding in a shader?

hi acroscene, welcome to the forum.
If you search the forum for “plexus” you’ll find some C++ variants.

That said, the best performing option on the GPU will be if you write a shader for it.
A good approach for this would be to first generate some CHOP noise (x,y,z) where you want your particles to be, feed this CHOP to a Geometry COMP to use geometry instancing to create a circle (particle) on all locations. See here a tutorial on geometry instancing: matthewragan.com/2014/04/23/ins … hdesigner/

Then you would need to write a GLSL Material which has has a geometry shader to create new lines between those particles, probably depending on the current distance between two particles to see if that is within your set threshold to draw a line.

TouchDesigner mostly assumes you have learned your GLSL knowledge using the abundant resources available online elsewhere, instead of from the TouchDesigner documentation - so this is something you will have to find yourself. Once you know a bit of GLSL it is easy to apply that code in GLSL nodes. Once you are at the point you already have some GLSL knowledge and are ready to implement this in TD, this page will be your bible: How to write a GLSL Material.
The easiest way to start experimenting with GLSL materials in TD is to place a Phong MAT and click the button “Output shader” in it’s parameter window. It will place the code for the vertex and pixel shader it uses, and you can immediately edit those.

If you really want to learn about shaders (and for this case: specifically geometry shaders) and how to write GLSL , I recommend getting this great book which will teach you all about GLSL: Graphics Shaders Theory and practice, second edition. It has lots of practical examples and is updated to glsl 4.x.

Also search the forum for “geometry shaders” for some examples such as this one:
derivative.ca/Forum/viewtopi … 14&p=35565

Thanks for your answer! I have created and instancing my spheres. How do I make them as individual objects with their own velocity and with the possibility of adding collision and so on. And also the lines between them. And bounce against the borders etc.

Am I doing all this in a shader?
instancingNoise.toe (7.79 KB)

acroscene -

There are a few approaches to solving this. In some cases you can do this in CHOPs. Vincent, for example, uses the FleX solver and has a C++ chop here you that you can look over:
github.com/vinz9/FlexCHOP

The Bullet physics library as a C++ chop is also another route:
github.com/vinz9/BulletCHOP

Both of these assume a educational or commercial license (required for the C++ CHOP).

You can also do this in a few shaders. If you open the palette and look for the particlesGPU example inside you’ll see that the motion of instances is described with several TOPs that are then sampled by a glsl material. Here instances are set up manually and location and movement is only described through the sampled TOPs.

For a limited number of points the particle SOP can also provide some interesting movement as well when fed with forces - this tends to be a farily expensive OP, so limiting the number of points and their lifetime is well worth keeping an eye on:
youtube.com/watch?v=8Tn3z2VDAo8
youtube.com/watch?v=bO2HNy_wbJc

see also here, Elburz is adding a new chapter about GPU particle systems to his TD book.
A big part is already online, enough to dive in.

hi acroscene,

I don’t think you can add this effect with a vertex shader because you can’t create geometry or delete, only duplicate. And i don’t think you can have access to others nears points coordinates because all append in the time on all points in GLSL shaders.
In Geometry shaders, you can create primitives and lines. Take a look.

In Tscript (old school way) you had a expression to get the distance between points
[url]https://www.derivative.ca/wiki099/index.php?title=TScript:Distance()[/url]
Don’t know if there is a python expression, but it will be to slow to calculate.

The best is the Vince Houze C++ (commercial)
[url]Distance Threshold Cplusplus CHOP (plexus-like effects) - Shared .tox Components - TouchDesigner forum