need help with VideoTexture (bge.texture)

I need a little help regarding VideoTexture
I am rendering a scene from a specified camera and assigning the image to texture channel “0”
In the next frame I want to get the rendered image from the channel “0” and assign it to texture channel “1”
Basically I need the image from the previously rendered frame.
So the question is - Is it possible to do that without rendering the image to hard drive and then getting it back to game.
Saving file really slowing things down so is not an option for me.

Perhaps there is a way to access the Videotexture buffer and fetch it from there to texture channel?

I think it is not possible to move the image from chanel “0” to “1”.
But you can use a global variable to switch every frame between the two rendering chanels. Then use the same variable to switch between the texture chanels in the shader.

 
Frame | Render Chanel | Shader Chanel
  1           0              (1)
  2           1               0
  3           0               1
  .           .               .

Or you can try to render the image in a Buffer. But I have never tried it, I don’t know if that works.
bge.texture.imageToArray(image, mode)
bge.texture.ImageBuff

The video texture module enables basic render to texture (from the view of some camera), and streaming to texture (from a data buffer of your choice).

It’s been a while since I touched that api, but I think the raw image data is available on the source via the image property.

So, maybe if you were to copy that buffer, and then stream it to some known “last frame” texture?

Like Goran said, you can set the texture to read from a list that represents the image captured, as well as get the list. So, capture the frame, then get the list and store it in a module or object variable, then read it back next frame.

HG1 mentioned the imageToArray() function. You could use that, or (as far as I can tell) just get the array directly from the image variable, then reassigning it and updating the source / image.

I haven’t done this in awhile, though, so that’s why I sound kinda vague. :confused:

Thank you guys!
With help of Moguri I managed to load texture from the buffer exactly like Goran mentioned. 1 important thingy is FilterRGBA32() for the buffer otherwise its size is wrong.


...
buffer = texture1.source.image
...
texture2.source = texture.ImageBuff()
texture2.source.filter = texture.FilterRGBA32()
texture2.source.load(buffer,512,512)

next problem :slight_smile:
it loads the same image in the same frame with no delay. Perhaps some sort of ping-pong timer is needed for this…

I did it storing the rendered image in the bge.logic class:

Blend file:
texture_replacement.blend (510 KB)

Image:
http://blenderartists.org/forum/asset.php?fid=163631&uid=61192&d=1327919263

Better image:


was impossible upload the blend file with the image packed :mad:

More clear blend:

texture_replacement2.blend (93.8 KB)


hey, thanks xaedro!
this is clever :slight_smile: