laying one jit.matrix with an alpha channel over another… should I use jit.op?

Apr 19, 2012 at 1:24am

laying one jit.matrix with an alpha channel over another… should I use jit.op?

I’m brand new to Jitter and I have a couple of questions.

First, some background. Having had past experience with applications like Adobe Photoshop and After Effects, I’m used to creating composite images from layers. I know that if I place one layer over another, then provided the upper layer has a transparency layer, I’ll be able to see parts of the lower layer beneath it.

I’m now trying to apply this concept to Jitter. My progress is in this patch:

– Pasted Max Patch, click to expand. –

I have two matrices of 10 by 1 pixels.

The matrix on the left is filled with white pixels, all of which have their alpha channel to 255 (full opacity). In Photoshop terms, this could be seen as my image background.

The matrix on the right has pixels alternating between completely transparent (alpha of 0) and fully opaque red. In Photoshop terms, this is like my first layer that I will place over the background.

Now I want to lay the right matrix over the left matrix, and thus the resulting image would be pixels alternating between white (the background) and red (the first layer).

The closest to this I have achieved is using [jit.op @op -], although as you can see from my patch this isn’t quite right. (The cyan colour is unexpected, and it requires two bangs into each source matrix to get it.)

So my first question is: can/should Jitter be used in this way? Or do I need to get my head out of Photoshop world and into another way of thinking?

Secondly, if I am already on the right track, then is it jit.op that I should be using for this? And if so, which operator is the correct one to use?

Many thanks in advance to any experienced Jitter heads who can help me on my path into Jitter :)

#63071
Apr 19, 2012 at 4:48am
#227586
Apr 20, 2012 at 4:03pm

That was pretty easy – thanks Christopher.

Interesting… the resulting matrix that comes out of [jit.alphablend] has all of it’s alpha values set to 255, so after the blend it effectively ‘flattens’ the image (to use Photoshop terms again).

Eventually I will have multiple layers (possibly 8 of them) that I will want to blend this way in real time. I’m wondering whether [jit.alphablend] will be the right tool for the job – I guess there’s only one way to find out.

I’m also wondering whether a 3-dimensional matrix might come in handy, as that already has the idea of multiple layers built in. We shall see.

#227587
Apr 22, 2012 at 10:43am

GL can be pretty confusing if you are a beginner with Jitter, but is probably the most efficient way to do this and possibly easier with multiple layers. Here’s an example with qt.movie objects, but you could swap these for jit.matrix objects:

– Pasted Max Patch, click to expand. –
#227588
Apr 22, 2012 at 4:10pm

If you’re planning on blending 8 images, it’s better to do it on the GPU with jit.gl.videoplane as LW demonstrated.

#227589
Apr 22, 2012 at 4:22pm

Thanks guys.

In Jitter, does GL refer to OpenGL? And would it therefore be wise to get my head around that before trying to use it in Max? E.g. going over the docs at http://www.opengl.org/

Also, I assume the preference of using GL objects over the Jitter Matrix would be because of better performance. However, in my case, the ‘images’ are only going to be very small – as small as 1px x 10px to begin with. Bearing that in mind, would the Jitter Matrix be an acceptable substitute?

#227590
Apr 22, 2012 at 6:06pm

you can do it all with matrices. you just have to chain jit.alphablends together.
the output of the alphablend, will be the second input of the next alphablend.

here’s a basic example:

– Pasted Max Patch, click to expand. –
#227591
Apr 22, 2012 at 8:43pm

Hi Robert – yes, if I was going to use [jit.alphablend] then that is how I would do it – by chaining them together.

Here’s an interesting point though – one of my projects will require new layers to be placed onto the composite video at the rate of about 4 per second. These layers will fade to complete transparency, so that when the bottom layer has completely faded, it will be removed. So effectively I’ll have a continuously rotating stack of layers, with new layers being added to the top, and old layers being removed from the bottom. I can foresee that doing this with chained alphablends may be tricky, as I’d have to dynamically add/remove these alphablends, or do some clever re-routing to reuse existing alphablends as they become available. While I believe that dynamically adding objects is possible using javascript, I’m quite liking the codeless approach of Max, so I may get along better using a patcher object that’s suited to the job (e.g. jit.gl…)

#227592

You must be logged in to reply to this topic.