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

Jun 1, 2012 at 9:05pm

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

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

#56461
Jun 1, 2012 at 9:19pm

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. –
#202447
Jun 1, 2012 at 11:14pm

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

#202448
Jun 1, 2012 at 11:23pm

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

#202449
Jun 4, 2012 at 10:20am

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

#202450
Jun 4, 2012 at 7:06pm

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).

#202451
Jun 5, 2012 at 1:14pm

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

#202452
Jun 5, 2012 at 6:10pm

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. –
#202453
Jun 6, 2012 at 9:57am

hello robert,

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

best,
l

#202454
Jun 6, 2012 at 11:15am

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. –
#202455
May 25, 2013 at 4:54am

somebody found out?

#250653

You must be logged in to reply to this topic.