OpenGL Scissors and Glue

div's icon

Hi all,

Am looking for a way to do the same thing as jit.scissors and jit.glue in openGL. I need to splice an image into three and process it using some slabs then join it back! sounds too easy eh?

Any ideas? I had a quick look and am looking into number (3) of render contexts... not sure.

Thanks in advance.

Tim

Wesley Smith's icon

Use texture coordinate offset in your slab processing to just work on
one section of the video. It's a lot like using srcdim and dstdim for
jit.matrix. If the shader you want to use doesn't have a parameter
for tex coord offsets, just add it.

wes

On 10/10/06, Timothy Devine wrote:
>
> Hi all,
>
> Am looking for a way to do the same thing as jit.scissors and jit.glue in openGL. I need to splice an image into three and process it using some slabs then join it back! sounds too easy eh?
>
> Any ideas? I had a quick look and am looking into number (3) of render contexts... not sure.
>
> Thanks in advance.
>
> Tim
>

div's icon

Thanks Wes! That sounds like it is exactly what I need to do!

Ok I started trying to cut and paste the text into a slab but i have no idea about GLSL so i made a patch with rota slabs into a fourway mix...

it is essentially what i want to do... although it doesn't work... at the very least it is a visual map of how i think it should work...

Any suggestions?

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


Wesley Smith's icon

Hi Timothy,
Here's a start. There seem to be some multitexuring slab issues that
I couldn't figure out. I'll look into them later. Anyway, here's a
patch and a shader. To use the patch, load a video and start
rendering, then enable which video stream should go to the
concatentating shader with the router object. Notice how I don't have
the 2nd texture hooked up. This is because for some reason it gets
linked to the 3rd one *unless* you start things up and get it rolling
and *then* hook it up. I have no idea why this is right now. Anyway,
here's the patch and shader. THe shader is called td.glue.jxs. You
may want to modify it to suit your purposes.

wes

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

----------------------shader-----------------------

    Glue

div's icon

Hi wes,

Looks promising, cheers. Although i am having trouble with the shader.

I saved it as td.glue.jxs

and it didn't work so i added a couple of lines, in a kind of hack stlye GLSL i guess... didn't work... I have no idea about GLSL coding

Cheers,

Tim

------

//texcoord1 = vec2(gl_TextureMatrix[1] * gl_MultiTexCoord1);
//texcoord2 = vec2(gl_TextureMatrix[2] * gl_MultiTexCoord2);

// extract the x and y scalars from the texture matrix to
determine dimensions
texdim0 = vec2 (abs(gl_TextureMatrix[0][0][0]),abs(gl_TextureMatrix[0][1][1]));
//texdim1 = vec2
(abs(gl_TextureMatrix[1][0][0]),abs(gl_TextureMatrix[1][1][1]));
//texdim2 = vec2
(abs(gl_TextureMatrix[2][0][0]),abs(gl_TextureMatrix[2][1][1]));
}

]]>

------------------

The error i get in the max window is

• error: jit_xml_document: error reading file at byte offset 492 / not well-formed (invalid token)
• error: line (27): >
• error: jit.gl.shader: error reading shader xml file 'Gustav:/Applications/MaxMSP 4.6/Cycling '74/jitter-shaders/texdisplace/td.glue.jxs'

Wesley Smith's icon
div's icon

Sorry Wes,

Hmm... Still not sure that it is right

• error: jit_xml_document: error reading file at byte offset 7 / syntax error
• error: line (6): Glue
• error: jit.gl.shader: error reading shader xml file 'Gustav:/Applications/MaxMSP 4.6/Cycling '74/jitter-shaders/texdisplace/td.glue.jxs'

This is what i get... in Firefox, Safari and Mail emails...

div's icon

Ha! I didn't get an attachment BUT I recovered it from the source... how strange... I had to find and delete all the and it works...

Great!

Now...

I will have a play and see what i can do... Thanks! Wes

tim

Wesley Smith's icon

Another way which might be faster depending on your hardware is to
render the 3 split textures to 3 aligned videoplanes and render those
to a texture which you then feedback into the slab.

wes

On 10/10/06, Timothy Devine wrote:
>
> Ha! I didn't get an attachment BUT I recovered it from the source... how strange... I had to find and delete all the and it works...
>
> Great!
>
> Now...
>
> I will have a play and see what i can do... Thanks! Wes
>
> tim
>

div's icon

yeah I was thinking about that but have had trouble in the past having multiple videoplanes... I think hardware is not an issue...
I have an new iMac intel duo with 2gb ram and 128 graphics...

tim

div's icon

yeah... hardware is an issue... three video planes slows it right down...

the td.glue.jxs is very close to what i need to do i think the only thing is that when I move each plane into their thirds they black eachother out... if only they were layered ontop of eachother (depth) 1, 2 and 3 then it might be possible to move them to a position where it might work...

thanks for all your help wes it has been much apprecieated, if you're ever in melbourne i owe you a beer.

Wesley Smith's icon

> thanks for all your help wes it has been much apprecieated, if you're ever in melbourne i owe you a beer.

Cool. I'm still a little fizzy as to exactly what you're trying to
do. Here's what I think you're trying to do:

-take a video image
-segment it into 3 parts
-feed 1 of the parts back on itself.

I noticed that when you offset the sections, they feed into each other
potentially making the thing blowup (i.e. turn all
white/black/whatever). You can get around this by setting the alpha
channel in the td.glue.jxs shader appropriately. For instance, if you
want to feedback the middle section and the left section is feeding
into it, you may want to do some kind of cross fade with the straight
video so that the feedback isn't instantaneous. This will require
getting into GLSL a bit. Honestly though, it's not very hard. Start
with one of the example co.*.jxs shaders. Those are pretty simple and
are pixel shaders (which is what you want to process video with). If
you need help, the GLSL Orange book is the default reference although
I'm personally not too keen on it. If you really want to understand
GLSL, this is the document you need:
http://mat.ucsb.edu/~whsmith/GLSLangSpec.Full.1.10.59.pdf .

Give it a whirl. Here's a little example

//get the color of the pixel (fragment)
vec4 final = texture2DRect(tex0, texcoord0);

//set the alpha channel to pass if green (luma) is above a threshold
final.a = final.g*float(final.g > thresh);

This second line will look at the green value of the pixel and if it's
above the 'thresh' value, it will pass it. This is exactly the same
as jit.op operation '>p'. I think you'll find alot of flexibility
here and will be able to make your patches faster and more specific to
your needs. The shaders provided with Jitter are great and many, but
I almost never use them straight-up. They need little tweaks here and
there to be perfect. Give it a whirl, it should only take a day or so
of determined work to make decent headway into this stuff. Feel free
to ask any questions and good luck.

wes