Dynamically shifting storage location of frames in 3D texture
I've had a lot of great results reworking the subtex.3d.maxpat example for to create interesting slit scan effects on the GPU. One thing I've been hoping to do is figure out a way to shift the storage location of each frame in the Z buffer of the jit.gl.texture object. Currently it's quite simple to write each new frame of a camera or movie by writing the frame to a location on the Z buffer using dstdim (dstdimstart 0 0 $1, dstdimend 1023 1023 $1). However once I reach the end of the buffer I have to cycle back to the beginning of the buffer to write over previously written frames which creates a pretty abrupt transition when trying to work with continuous frames (i.e. a live camera input).
What I'm hoping to do is figure out a way push each frame in the Z buffer to be stored at location that is 1 less than its current location. Essentially the first frame in the buffer would always be the most recent frame with previous frames shifting down 1 slot until it reaches the oldest frame which is removed from the buffer. This would allow for a smoother way of working with continuous frames in real time.
Is this kind of storage shifting possible using the dstdim attribute with jit.gl.texture or conversely would there be some way to do this with jit.gl.pix? Would this be too computationally heavy even if I could get it working? I spent some time looking into the OpenGL structure for 3D textures but couldn't find anything on this. Any help, ideas or internet rabbitholes to fall down would be appreciated. Attached is the basic slitscan patch I've created by ripping most of the subtex.3d patch and adding in the jit.bfg object as the luminance map..
hey Matt. i don't think there's an easy solution for this.
the one thing I can think of is to keep two 3d texture buffers, that maintain that offset, and when you need to loop, switch to the second.
so something like, 2nd buffer keeps slot 0 free, when the writer hits the last frame load it into slot 0 of buffer 2, and when the reader hits last frame switch to buffer 2.
I think I get what you're saying Rob but yeah, I'm not sure if that would really get exactly what I'm looking for. Do you know if the limitation to achieving this is in the way the Max objects are set up or is that kind of array shifting just not possible with 3D textures in OpenGL?
afaik there's no builtin way to shift the contents of an opengl 3d texture, as it's not really an array but a 3d texture. maybe you want to keep a jit.matrix array as backing storage, perform your shifting on that, and re-upload to the gpu texture.