Video feedback loop

Hi everyone!

I’d like to create a simple video feedback loop on the GPU in a shader. How might I go about accomplishing something like this? The frag shader would just be something standard to display a texture.

I thought I’d be able to do something like:

        shader.setUniformTexture("tex0", videoTexture, 0);  
       shader2.setUniformTexture("tex0", fbo.getTextureReference(), 0);  
fbo.draw(0,0); //output  

But it’s just drawing the source video. Any ideas?

Thanks in advance for any help!

if your shader simply draws a texture, it’s perfectly logic that it just draws the source video.

first of all: when you speak about video feedback, are you thinking about something like this?

if this is the case, the simplest way to do it would be:

  • avoid clearing the fbo, so every new frame will be drawn on top of the previous one

  • if you want the cortex/loop effect, every new frame will need to have a different size and angle from the previous one, so you’ll need to keep track of these changes: you can increase a couple variables, or use trig functions together with ofGetElapsedTimef(), etc…

  • finally draw each new frame on the top of the previous one, deforming and tilting it as you wish: you could do it in super simple way using a combination of ofRotate(), ofScale and videoTexture.draw(), or you could make it happen inside a frag shader (using some trigonometry, there a lot of GLSL “vortex effect” examples around the web).

Hi Naus3a, thanks for the quick response!

I should have been more clear with what sort of feedback I am looking for. I believe the image you posted below is a type of feedback similar to the droste effect (

I’m actually looking to make something more akin to this video

I followed the trail back to this page, which goes into some detail about the actual shader being used I’d like to use video input rather than random noise.

I’m less interested in what the shader is doing (seems like the white one steps are outlined pretty well) than how to set up the feedback system itself. I think I understand the underlying concept of feeding your output back into your input, but actually setting this up has been confusing me. It seems like you have to initially kick it off with a current frame and a previous frame, but then at some point hand off the textures to the feedback loop, so that each new frame is using the previous frame as input, and blending the two together. I’m also a little unsure of this process, because the only way I’ve been able to think of doing it involves writing to and reading from the texture at the same time. I’ve read about pingponging two fbo’s and I tried getting something like that going but never got the result I wanted.

How do you prevent your fbo’s from clearing each frame? I tried using

    glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);  

and that seemed to be a start in the right direction.

This has obviously been done before, and I feel like it just involves getting all the different pieces to read/write in the correct order.

Thanks again!

did you ever figure this out?


It’s pretty straightforward

// render some shader in your main fbo
       someShaderEffect.setUniformTexture("tex0", rttFbo.getTexture(), 0);

// render first fbo to texture

// draw fbo

Of course most of the work is done in the shader itself. Small changes like editing texcoords can have big impacts futher down the line in a process like this. I’d poke around on for feedback effects if you’re looking for specifics.

1 Like