jit.gl and subpatching (jit.gl.node?)

Marigold Maripol's icon

Hi -
I'm sure this has been answered somewhere, but I'm having a hard time understanding how this is supposed to work.

I'd like to access jit.gl within subpatchers, such as in the attached example. I'm assuming I need to use jit.gl.node for this, but I'm not entirely sure how. I'm slightly confused about what would be a texture and what would be the default representation of the 3d space.
Any advice on getting the patch working would be great, but also if there are any good resources for understanding this part of jitter, I would like to understand it better.

Thanks.

Max Patch
Copy patch and select New From Clipboard in Max.

TFL's icon

Jitter works just fine with abstractions and subpatcher, but there are some specific connections that cannot be done through them, like connecting a [jit.gl.multiple], [jit.gl.material] or [jit.gl.pbr] to a [jit.gl.mesh/gridshape/model], or connecting the middle outlet of a [jit.gl.node] to another object. These are specific kind of connections which tells the object which other object to connect to, but do not pass data like typical connections. So when you encapsulate your jit.gl.gridshape in your subpatcher, the jit.gl.material that is still in the main patcher just doesn't see the gridshape anymore, as it is now connected to a [patcher] object.

A few other objects work that way in the non-jitter world, like [attrui], [getattr], [grab] and probably some others.

Fortunately, you can name most jit.gl objects, and reference these names in other objects. For example you can create a [jit.gl.material @name mymat] and link it to a gridshape like so [jit.gl.gridshape @material mymat], and then no need for a patch cord between both objects! You want your gridshape to draw in a specific jit.gl.node? Then name your node [jit.gl.node @name mynode] and add a drawto attribute to the gridshape: [jit.gl.gridshape @material mymat @drawto mynode].

And this will work regardless of the patcher level of each object.

Other connections, like the green ones (for matrices), blue ones (for textures), and most others, can be passed in/from subpatchers/abstractions without issue!


Here is your patch with all the connections I could remove:

Max Patch
Copy patch and select New From Clipboard in Max.

(by the way you don't need the jit.gl.node here as you could draw the jit.gl.multiple directly to the world instead, but I left it anyway)

Marigold Maripol's icon

Thanks for the help - this is really interesting to hear about, I was banging my head against a wall trying to understand it for a long time!

One small question about this example patcher, though.. It seems like it produces a single unmoving gridshape, apart from the ones produces by jit.gl.multiple. I adjusted the sketch a bit to make it more visible. Any idea what causes this or what could be done to remove it?

Max Patch
Copy patch and select New From Clipboard in Max.

TFL's icon

The not-moving torus is the one from the gridshape while the moving ones are the copies from the jit.gl.multiple. It seems to be a small bug/inconsistency due to using @targetname in the jit.gl.multiple instead of connecting the object directly.

A workaround is to add @automatic 0 to the gridshape so it doesn't get rendered automatically (but its copies from jit.gl.multiple will still be).