Basic GLSL drawing

Hello everybody!

I’m trying to do a simple glsl excercise, at least from my point of view.
I have a simple particles setup, with few (4-5) particles bouncing in a box.
I would like to draw a line between each particle with a GLSL OP.
I had it done with a Script TOP that would append a poligon of two points (a line) in a for loop, but it’s too much CPU consuming if I increment the particles number.

I don’t know how to approach it in GLSL…

I’ve tried to create an instanced sphere in a Geo COMP, where it gets the particle position from a Sopto CHOP. Then I applied a GLSL Mat, thinking that I could get the points positions from the instances in the Vertex Shader. But from there I don’t know how to create a line… and made me think that maybe it should be done in the Pixel Shader, but no idea neither on how to go on.

Any clue? Any tip?

Thanks a lot for your time

Greetings

V.

Maybe the ideas here could help Object CHOP Techniques
and here for a fast CHOP way of getting all pairs of points Optimized function for returning distances - #2 by DavidBraun

Thanks David,

I really didn’t know this operator, and how fast it calculates distances, but for what I understood, I should have an Object Chop for each particle… and when I increased the number of particles it would be a huge project. (I’m starting with few particles, but planning to increase them). Besides, I’d like to condition the line depending on the distance.
I really would like to transform this piece of code I made in Phyton to GLSL, if there is a way…

p = 0
q = p+1
while p <= points-1:
	while q < points:
		if distance (parti[p], parti[q]) > Min and distance (parti[p], parti[q]) < Max :
			poly = scriptOP.appendPoly(2,closed=False, addPoints=True)
			poly[0].point.x =parti[p].P[0]
			poly[0].point.y =parti[p].P[1]
			poly[0].point.z =parti[p].P[2]
			poly[1].point.x =parti[q].P[0]
			poly[1].point.y =parti[q].P[1]
			poly[1].point.z =parti[q].P[2]
		q += 1
	p += 1
	q = p+1

As you see, each point checks its distance to every other point, and if the distance is right then draws the line between each other. Works fine with 20-30 particles but when I increase it above 50 the performance starts decreasing very fast.

Again, thanks for your time

v.

I just added a plexus effect to the tox TouchDesigner_Shared/numpy_distance_pairs.tox at master · DBraun/TouchDesigner_Shared · GitHub It ends up being really fast :smiley:

1 Like

Just Wow!

That’s seems like what I wanted! Let me understand your project a little bit and adapt it to mine and I’ll get back to you with more feedback.

It’s always interesting to see how other people do the same things in other ways :slight_smile:

Thanks a lot for your effort!

V

Well, after a couple of adjustments it fits perfectly with my project and I have to admit that has improved the performance significantly!
Giving the scenario that the min distance is 0 and the max > maximum distance (all particles link with all others) and N is P*(P-1)/2+P (maximum number of vertex given P particles), with my approach I could emit 30 particles maximum before I got less than 60fps in performance mode.
With your approach, I can emit up to 60 particles!!! Maybe in particles doesn’t seem much, but in lines goes from 435 to 1770 !!!

Thanks again, David, and I wouldn’t like to seem ungrateful, but I’m still willing to know if this is possible to release the CPU of all these calculations and leave it to the GPU, as I would like to add more interactivity and need to do more calculations.

Another subject would be how to split this calculations to other threads, as when it starts to lower FPS, I just have 1 core at 100% out of 16 (merely a 6% in overall) but I think I should upgrade to Pro to be able to do that.

Thanks again David, still waiting to solve the question, but with a lot of new knowledge acquired!

Greetings

V.

@Cannavizion_1

You might give @paketa12’s tutorial on plexus a look, it’s a different approach, but would be another way to simulate the plexus like effect.

1 Like

Wow , and again, wow!

It’s amazing to learn how you can do the same but with a totally different approach!
I felt my brain being nicely fu**ed last night while I was watching @paketa12 tutorial…
It is a game changer, as easily I can charge 1280 particles (maximum resolution for the free TD) and no loss of frames!
Thanks @raganmd, and thanks @DavidBraun for your time and patience to understand and solve my problem, and of course, thanks @paketa12 for the enlightenment!

Greetings

V.

1 Like

Hey guys!

What has changed since last summer in TD that the “Plexus in TouchDesigner” by @paketa12 isn’t working anymore?
Instead of links between particles, it draws lines in opposite directions.

Any clue?

Thank you

Greetings

V.

Ok, I found it…
In the Rotate to Vector: Forward Direction, I just had to change from -Z to +Z
(when instancing the lines)

Sorry to bother you.

Thanks anyway

Greetings.

V.