Forums > Jitter

Copying a texture to a portion of another texture – on the GPU

June 1, 2012 | 9:05 pm

Hi All,

Just wondering how to copy a texture that is 320×240 onto (for example) the upper right corner of another texture 640×480 – replacing just a portion of texture 2 with texture 1 which is a smaller texture.

I want the rest of texture 2 to stay as-is.. and of course be able to do this repeatedly ( texture 1 will ultimately be a movie… the unchanging portion of texture2 will be a still image).

I know how to do it before it gets to the GPU, I’m hoping it is possible to do this on the GPU.

Any ideas would be awesome, thanks!

Valentin


June 1, 2012 | 9:19 pm

hello valentin.

you need to do 3 things to make this work:

- set @usedstdim 1 on your jit.gl.texture
- set @dstdimstart and @dstdimend vals on your jit.gl.texture
- send matrices to your texture using the "subtex_matrix" message instead of the "jit_matrix" message

here’s a basic patch:

– Pasted Max Patch, click to expand. –

June 1, 2012 | 11:14 pm

Hi Robert,

I see how this works for the larger texture being a still image (where you have connected jit.noise).

How do I get the smaller texture to be derived from a movie (as you have it) and have the larger image be a movie as well?

I’ve tried a few variations of order of bangs, and it doesn’t seem to work.

I’m sure there’s a simple trick I’m missing. – Thanks!

V


June 1, 2012 | 11:23 pm

I also meant to ask.. does this basic approach work if both of the inputs are textures?

In your example, one input is a movie and the other is a jit.noise, they both go to a jit.gl.texture, with one sending subtex_messages so that it alone "talks" to texture using the usedstdim .

What would be different if the movie was already on one texture, and I want to use it to replace a portion of another texture? (i.e. 2 jit.gl.textures – one somehow is setup to fill a subtext of the other on an ongoing basis)

did that make any sense?

V


June 4, 2012 | 10:20 am

hello valentin,

this issue was discussed 3 weeks ago here:

http://cycling74.com/forums/topic.php?id=23446

it would be great to copy parts from one texture to another.

may workaround was using the crop shader (m_crop.jxs), which i found here:

http://cycling74.com/forums/topic.php?id=23618

best,
l


June 4, 2012 | 7:06 pm

subtex_matrix only works with matrices, and only if the "background" image remains static.

more complex scenarios should make use of shaders (or jit.gl.pix).


June 5, 2012 | 1:14 pm

hi robert,
thanks for clarification !
is it possible to post an example with jit.gl.pix, which gets an input texture (for example: dim640x480) and outputs a croped portion of the input texture (for example: dim 32×32).

parameters could be:
width, height, offset x, offest y

that would be realy nice.
best,
l


June 5, 2012 | 6:10 pm

it would be something like this the below patch.
all parameters work with normalized values (0 to 1).
it’s left to you to convert to convert these to pixel values.

– Pasted Max Patch, click to expand. –

June 6, 2012 | 9:57 am

hello robert,

thank you very much for posting the example.
this is a great starting point to get into jit.gl.pix !

best,
l


June 6, 2012 | 11:15 am

hllo robert,

one more thing:

in your example, you genereated an alpha channel around the croped texture.
is it possible to output only the croped texture, so that the dimension of the input and output texture is different ?

best,
l.

– Pasted Max Patch, click to expand. –

May 25, 2013 | 4:54 am

somebody found out?


Viewing 11 posts - 1 through 11 (of 11 total)