Copying a texture to a portion of another texture - on the GPU
Hi All,
Just wondering how to copy a texture that is 320x240 onto (for example) the upper right corner of another texture 640x480 - 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
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:
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
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
hello valentin,
this issue was discussed 3 weeks ago here:
https://cycling74.com/forums/jit-gl-texture-and-dstdimstart-dstdimend
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:
https://cycling74.com/forums/a-gpu-based-cropper
best,
l
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).
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 32x32).
parameters could be:
width, height, offset x, offest y
that would be realy nice.
best,
l
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.
hello robert,
thank you very much for posting the example.
this is a great starting point to get into jit.gl.pix !
best,
l
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.
somebody found out?