Dear TouchDesigner Developers,
I understand from the documentation that the GLSL Advanced POP allows for the manipulation and creation of points, vertices, and primitives. However, the workflow is still unclear to me. I have looked at the examples included in overview.toe, but they are a bit complex to follow, and I am not sure whether it is possible to work in a way similar to the Script SOP.
In the Script SOP, one typically defines functions and then generates points, primitives, or other geometry using methods such as appendPoint(), appendPoly(), etc.
I’m attaching an example of the kind of result I would like to achieve, and I kindly ask if you could provide a practical example using GLSL Advanced POP that parallels this workflow. It would help me establish a more direct comparison with something I am already familiar with.
Thank you very much for your support and time.
Best regards,
Edwin Lucchesi
Script SOP and GLSL Advance POP.toe (7.8 KB)
Ok, my explorations with the GLSL Advanced POP have led me to understand how to connect a line strip by following the indices in order.
(If any other adventurous soul feels like sharing some feedback, you’re more than welcome!)
Now the question is… how do I close the geometry into a filled polygon?
Script SOP and GLSL Advance POP.2.toe (8.0 KB)
1 Like
Through trial and error, I’m starting to get a glimpse of how GLSL Advanced POP works. I continued experimenting and managed to close the line strip into a polygon shape by applying the triangle fan logic. The result isn’t identical to what the Script SOP does, that one creates a single polygon, while my GLSL Advanced POP currently generates n separate polygons. Also, the Script SOP version still leaves some holes in the geometry.
From what I gather in the documentation, it seems that for now POPs don’t support creating a single primitive with n vertices. Here the patch here for anyone curious to dive in (:
Script SOP and GLSL Advance POP.3.toe (8.7 KB)
1 Like
Hello,
Sorry for the delayed answer, glad you managed to make sense of it.
Indeed only triangles and quads are currently supported in POPs - we have on our list to add a feature to triangulate closed line strips.
Otherwise I’ll look shortly at your toe and let you know if I have any comments.
We’ll aim to have more examples of creating geometry with the GLSL POPs soon as well.
1 Like
Hi @vincentDev !
No problem at all for the delay! I ended up doing quite a bit of trial and error and “believing” I was starting to understand various things.
In fact, having some guidance or even a few “golden rules” to follow when working with GLSL Advanced POPs would be incredibly valuable especially since I encountered several crashes during the learning process.
Any notes or best practices would be greatly appreciated!
Hello,
I looked a bit at your file and had a few comments.
So POPs are the most efficient when working in parallel, so as much as possible you want to avoid a single thread doing a for loop.
so instead of
// We write the line from a single thread only
if (id == 0) {
// For each point, write to the I[] buffer
for (uint i = 0; i < n; i++) {
I[i] = i;
} // This closes the line
I[n] = 0;
}
you would want to do
I[id] = id;
and make sure you have the correct number of threads.
also line strips are a bit more complicated to work with, each line strip should end with a special vertex signifying it’s the end of the line strip (value should be cTDPrimRestartIndex, which is defined for you by TD), since line strips can have different number of vertices, unlike the the other primitive types. So you might have the last thread writing multiple verts (to close the line strip + add the restart index for example)
Though when dealing with small number of points/verts it doesn’t make much of a difference.
The other thing is POPs have to allocate their memory in advance, so they won’t have appendPoint() or appendPoly() - it sort of works backwards where you want to allocate the max number of points/verts and then in the shader count which ones you’re actually writing to, and you can specify these on the output page of the GLSL Advanced POP or the Topology POP.
We might add a script POP in the future but it would mostly be a wrapper around script SOP + SOP to POP where everything is done on the CPU and then copied to the GPU, not leveraging POPs parallelism.
Anyway still on our list to have a more step by step and comprehensive set of examples on how to build geometry with the GLSL Advanced POP, there’s a lot to cover if we want to be more detailed.
You mentionned overview.toe but I think you meant GLSLPOPs_Update.toe? that’s where the current limited set of examples is
1 Like
Thanks @vincentDev for the detailed info.
So for a single line strip like in my case, would this code be fine?
void main() {
uint id = TDIndex();
uint n = TDInputNumPoints(0);
// Write the point indices
if (id < n) {
I[id] = id;
}
// The last thread writes the restart index
if (id == n) {
I[id] = cTDPrimRestartIndex;
}
}
Yes, sorry, I got confused. In those examples, I actually tried to analyze the GLSLCreateDeprecated examples, but they completely lack explanations for the reasoning behind certain choices, so I’ve been working through them by analyzing and guessing; still, it’s a great learning exercise. Anyway, thanks a lot for the work you do and for taking the time to answer all these questions.
You’re welcome, and yes code above is correct, you want to make sure the number of threads mode is “per max output vertex” and max Line strip vertex is set appropriately (input points + 1)
if number of threads is set to “input points” then you would want the last thread to write the last two vertices, since id would go from 0 to n-1
(this is a bit simplified since you always get workgroups of 32/64 threads (nvidia/amd), but if your number of points was a multiple of 32 you would be missing one thread)
For line strips the other thing you want is to set “Line Strip Info Update” param on output page to “Auto” instead of Zero, otherwise you’ll run into issues with downstream POPs.
Besides the primitive restart index between each line strips, line strips also require extra info buffers (also because line strips can have different length)
Auto calculates them for you, using the primitive restart index, but you can also provide them manually in the GLSL Advanced POP or the Topology POP
There’s a bit more info in RecreateCopy container, the “copying line strips” block, or the LineStrips container in GLSLPOPs_Update.toe.
Yeah the GLSLCreateDeprecated container could be expanded a bit, for a couple versions there was a GLSL Create POP that got removed, replaced by new features on GLSL Advanced POP, so I converted the examples but there could be more and more comments