texture coordinates with jit.gl.multiple

Letraset Catalogue's icon

Hi, is there any way to set individual texture coordinates for each instance with jit.gl.multiple? This is not what i'm trying to do, but imagine you're trying to split apart or shatter one larger image into a grid of smaller individual videoplanes.

Rob Ramirez's icon
Max Patch
Copy patch and select New From Clipboard in Max.

absolutely. since max 6 gl.multiple allows setting texplane_s/t as one of the glparams matrices.
here's a silly example i made way back when. it uses this feature to utilize a font-atlas with gl.multiple.

Letraset Catalogue's icon

Cool patch. I can't see any coordinate variation though? dstdimstart dstdimend.

Letraset Catalogue's icon

@rob. Is the alphabet supposed to map on the spheres - each letter per sphere? If so it isn't working on my machine.

Processor 2.6 GHz Intel Core i7
Memory 16 GB 1600 MHz DDR3
Graphics NVIDIA GeForce GT 650M 1024 MB
Software OS X 10.9 (13A603)

Rob Ramirez's icon

it maps whatever letter you type on the keyboard. possibly only works for US keyboard layouts.

in any case, to send texture coordinates to gl.multiple instances, provide tex_plane_s tex_plane_t as args to the @glparams attribute, and send 4 plane float32 matrices to the corresponding inputs.

Letraset Catalogue's icon

Sorry, I forgot to thank you. That patch has taught me how to use jit.multiple. Thank you!

vichug's icon

thanks for bumping this up, as i have looked for a way to have different textures on several instances from a jit.gl.multiple, and this might be the solution !

Eric Souther's icon

Good afternoon. I was hoping someone on here might help. I'm trying to get a cache of frames to instance across a series of jit.gl.gridshapes using jit.gl.multiple. Even if I can get the frame index how might I apply them throughout the group in succession?

3dFRAMEBuffer.maxpat
Max Patch

Rob Ramirez's icon

from a quick look at the source, I believe you can have up to 256 texture names as args to the texture attribute (also the limit of values you can supply to the char matrix). so you need to construct the list of texture names in some logical order, prepend it with texture, and you can then control which texture is set to which instance via the texture_matrix input. so if you have "texture tex1 tex2 tex3 ...", you set the cell val to 0 for tex1, 1 for tex2, etc.

there may be some other limitation to the number of textures supported.

Roland Sproll's icon

@rob, I try to run your "silly example" with gl3, but I get the message "texgen/apply is obsolete when using the gl3 engine" (it works fine with gl2). What is the trick with gl3 to set the tex coordinates of the jit.gl.multiple instances individually?

Roland Sproll's icon

Is there anyone who has made tex_plane_s/tex_plane_t work with jit.gl.multiple with gl3? I would be very happy to get a small example. Thanks a lot.

Rob Ramirez's icon

yeah those attributes are deprecated with the gl3. as with most gl2 to gl3 porting tasks, the answer is to do it in the shader. let me see if i can throw something together that provides this functionality.

Rob Ramirez's icon

for starters, here's a modernized version of that ancient patch

wobbly-word-pad.maxpat
Max Patch

Rob Ramirez's icon

Ok here's the update of this patch for gl3. It's based on the Mesh Instances example from the launcher patch, since currently the gl3 version of jit.gl.multiple doesn't support custom shaders.

We simply add another instanced buffer to the mesh that contains the two non-zero values of each tex_plane_s/t list, packed into a 4 plane matrix. These values are used in the shader to calculate the tex_map 1 (Object plane) texture coordinates for each instance. We also add a fourth element to the position buffer to handle uniform scaling of each instance in the shader.

hopefully this gives you something to go on.

gl3-wobbly-word-pad.maxpat
Max Patch

instancing.mesh.tc.jxs
jxs 4.49 KB

Roland Sproll's icon

That's great, thank you Rob!
I think I still have a lot to learn and this is a good start.