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

    Jun 01 2012 | 9:05 pm
    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!

    • Jun 01 2012 | 9:19 pm
      hello valentin.
      you need to do 3 things to make this work:
      - set @usedstdim 1 on your - set @dstdimstart and @dstdimend vals on your - send matrices to your texture using the "subtex_matrix" message instead of the "jit_matrix" message
      here's a basic patch:
    • Jun 01 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!
    • Jun 01 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, 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 - one somehow is setup to fill a subtext of the other on an ongoing basis)
      did that make any sense?
    • Jun 04 2012 | 10:20 am
      hello valentin,
      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:
      best, l
    • Jun 04 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
    • Jun 05 2012 | 1:14 pm
      hi robert, thanks for clarification ! is it possible to post an example with, 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
    • Jun 05 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.
    • Jun 06 2012 | 9:57 am
      hello robert,
      thank you very much for posting the example. this is a great starting point to get into !
      best, l
    • Jun 06 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.
    • May 25 2013 | 11:54 am
      somebody found out?