instancing instances

Anybody know if this is possible?

example:

A triangle is instanced around a circle, like marks on a clock face. Then the clock is instanced on a 100x100 grid. BUT, each clock has a different number of marks-- so the triangle should be the GPU instance and not the “clock”.

I guess it would be about using chops to translate/rotate/scale each instance on two levels: relative to the center of each clock face, and relative to world origin… seems like that might get counter-effective pretty easily.

I think you should skip the CHOPs and attempt all of this in GLSL. Here’s the outline:

Put a circle sop with 3 sides (a triangle) in a Geo comp. This triangle should be small because it’s the basic shape that you’re going to be instancing in a world whose content should fit within [-1,-1,-1] to [1,1,1] for simplicity.

Set the instancing on the Geo comp to manual and do not pass an instancing CHOP. You’re going to do it with math in a vertex shader…

Create a Phong Mat. From the RGB pane, export it to a GLSL Material. Apply the GLSL material to the geo comp.

Open up the vertex shader in a text editor. You have access to gl_InstanceID, which will range from 0 to N-1, where N is the number of instances on the Geo comp. Write code that will transform the world space coordinates of the triangle’s vertices based on gl_InstanceID. You don’t know which of the three vertices you’re modifying, so the transformation you think of should be correct for all three vertices. Based on your description, it looks like you’re going to have to do some math tricks involving sums of arithmetic series to do the correct transformation per triangle.

Thanks for the tips, David!

I definitely need to learn more about GLSL (and programming in general) so I can start realizing more of the things in my head. I am able to manipulate instance position based on instanceID in the shader like you described…

…But I am still faced with the problem of having both 1) a group of instances, and 2) a group of “sub” instances per instance, where each group of sub-instances needs to have a different number of instances and different transforms.

Here’s another approach to my question: Is there any way to feed multi-sample data into a shader besides transform values? If there is, then I can feed in another variable per-instance so that I can tell the shader to duplicate and transform each instance according to the value of this extra variable (see attached)
sub_instancing.tox (1.29 KB)

The other approach I’ve been thinking of is using CHOPS:

Say I have a CHOP with tx ty tz channels for a 5x5 grid of points, so that’s 25 samples. Then I have another CHOP with 25 samples of random integers. Can each sample of the tx ty tz channels be “elongated” or duplicated X number of times? (X being the value of the relative sample found in that second CHOP)

You can instance one cube, or you can instance two cubes, but you can’t sometimes instance one cube and sometimes instance two cubes.

I think what you need is a Python script that will create a DAT with the tx, ty, tz that you need. Use a for loop and write rows to a table DAT.

Another idea would be to have a table of tx and a table of ty and set up a Python script that would take combinatoric combinations of the rows in the two tables.

You should also look into passing arrays to a GLSL mat.
sub_instancing.1.toe (5.92 KB)

I think this sample project will help a lot. It can scale up really well as long as you avoid constantly cooking SOP transformations outside of the vertex shader. If you need to move the SOP, figure out how to do it in the vertex shader.
Instancing_Instances.1.toe (7.38 KB)

1 Like

This is a HUGE help. Thanks, David! I am dissecting it now