jit.gl.cornerpin alternative to create a videomapping using 3 corners instead of 4 ?

Bart's icon

Hi there,

For a small project, I'm looking for a way to create a multi-surfaces videomapping on some triangular surfaces. Using jit.gl.cornerpin could do the trick, but it has (as far as I know) only 4 pins to create a square. For this project, it would be much easier if I could create a triangle and use 3 pins to map it in the space.

Is there a way to do it with jit.gl.cornerpin ? I assume not, because a video is a rectangular. Do you have an idea ? My first intuition would be to slice in a triangular shape my media. But then ?

Thanks in advance for your help !

Rob Ramirez's icon

simplest way i can think of is simply draw a triangle with gl.mesh and provide texcoords as desired. you can then capture this to a texture and further process using gl.cornerpin:

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

Bart's icon

Hey Rob,

Thank you ! Of course, that's a thought, and your exemple can do the trick. Even more, because, I think I don't need to use the cornerpin function for further process. I could only change the coordinates of each corner of the triangle (but I'm loosing the ability to use the mouse directly on the output, but I don't care). I need to dig a bit now ;-)

Rob Ramirez's icon

you can easily hack something together using jit.gl.handle to modify the positions of the triangle vertex:

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

Bart's icon

Hey Rob,

Thanks a lot for this idea. I didn't get any time to dig more into it, but I will be on it this month.
Using jit.gl.handle can definitely a way to achieve the idea. I will work on it and come back to you with my result ;-)

Thanks again ! And happy new year.

Jonas Magnussen's icon

Hi guys, really cool technique! I figure this can be expanded with a polygon draw_mode to allow for more complex mapping, but after messing around with it I find that figuring out the proper texture coordinates for different amounts of vertices is not very intuitive, actually I can't figure it out at all! It's all looking very kaleidoscopic to me. Any pointers?

Jonas Magnussen's icon

Never mind, this article all made it very clear.
https://learnopengl.com/Getting-started/Textures

It works super well! I'm getting ideas to expand this with draw mode quads to allow for multiple rectangles, poly~ to easily change the number of corners, and update texcoords automatically. Will post the results if I end up putting in the time. I'm going to do projection mapping of an oval scene soon, I suspect it would be possible to use jit.gl.gridshape @shape circle with some scaling to make the same technique work there. With the old projection mapping patches getting discontinued, I'm very happy to have found this approach.