Hi there,
After a whole day on this, I’m in to ask for some help! I’m learning GLSL so I know my questions will look silly… I’m trying to reproduce a project I already did in a classic nodes approach, but now in a GLSL approach to get most of the vertex calculation on the GPU.

Here is the project I want to reproduce: instagram.com/p/B2l3-ssoJAp/
For this video I used a Trail SOP + Sweep SOP, but this way uses a lot of resources if you push the number of trails, so I want to replace this with a GLSL vertex shader.

Here is where I am for now:

glsl-trails.toe (9.62 KB)
=> Top part of the network: I managed to create a version of the vertex shader working with a line. The translations for each points are ok and as expected, using the gl_VertexID to get the translation values from a CHOP.

=> Bottom part of the network: Next step, a shader working with a tube with end caps. Here come my problems:

The number of points and vertices are not the same, and I can’t understand how they are placed/ordered. So I’m struggling to find a way to translate every vertices correctly (resulting in weird points not translated and weird connections)

I can’t understand how I should deal with the rotations of each vertices. I tried using channels representing the bearing, but I know I’m wrong as the rotation of each ‘slice’ should change the translation of each verticies

Why is the output of the shader seems wireframe? Is it because I’m not translating every vertices correctly resulting in a broken geometry?

I understood now that a point can have multiple associated vertices. In my vertex shader, I was trying to identify a vertex with gl_VertexID, which was a bad idea. The solution is to use a Point SOP to add a custom attribute “pointIndex”, to be able to identify the point, and so the position of the vertex. You can add the custom attribute with the Point SOP using

me.inputPoint.index

I’m now able to move all the vertices in the expected way. I’m now also translating the normals. Can someone confirm that this is the good solution?

glsl-trails-v2.toe (9.88 KB)
[b]So now here is the questions I still can’t answer:

I can’t understand how I should deal with the rotations of each vertices. I tried using channels representing the bearing, but I know I’m wrong as the rotation of each ‘slice’ should change the translation of each vertices…

Why is the output of the shader seems wireframe? Is it because I’m not translating every vertices correctly resulting in a broken geometry?[/b]

Tube1 needed to be centered on the z-axis.
Tube1 needed to be set to triangles, not rows-and-columns.
The rotation values needed to be converted from degrees to radians for your shader.
sRotations on phong1GLSL needed to be set to texture buffer.
In the vertex shader I added my version of mat3 rotXYZ, which is somewhat cleaner than 3 sequential rotations. Look into Euler equations too if you haven’t.

Thanks a lot this is really helpful! I understand what were my errors here. (and yeah, I totally forgot that the angles needed to be radians…) Thanks for your rotXYZ also, pretty useful, I need to have a look at the Euler equations.

I now have to work on the next steps, still a lot to learn!

Keijiro’s swarm was one of the inspiration for starting this experiment/exercice. And you are right, I understand that the Object SOP is not enough. I will have a better look to try understand the logic behind his approach. Maybe one possibility I think is to calculate everything as textures in a GLSL Top with a feedback loop, then give the textures to the GLSL Mat as buffers.

I will post the next steps here when I find some time to work on this.
Thank again for your help David!

Ok, I switched everything to TOPs to feed the GLSL Mat, allowing me to manage the different instances. It’s really cool as I can now produce a lot of spaghetti and transform them on the GPU for a very little cost! I tried creating 1280 instances with a lot of details, and boom, everything is fine at 60fps.

But of course now here is my problem:

The geometry seems fine, but the normals are all messed up!

glsl-trails-v3.toe (10.5 KB)
I tried looking at the Swarm example, but I can’t figure out how I should deal with the normals and tangents. To replace the Object SOP calculating the rotation (previous files), I tried using a cache TOP to get frame-1, and feed a GLSL TOP with current frame + frame-1, to calculate the angle variation on xyz axis. Then I can feed this new TOP to the GLSL Mat. I also tried to add another buffer to calculate the tangents between frame and frame-1, but same, I don’t really understand what to do with this…

I tried to understand the problem, read a lot of explanations about dealing with normals while rotation and translation of vertex, but still no luck, the more I read the less I understand…