Render to / and use texture

Hi,

I’m trying to create a cummulative effect in which new data is added to the framebuffer on each frame.
Ideally I would like to render the first frame to a texture and then use this texture as the background for the next, add the 2nd frame to it and so on…

Doe anybody know if this is possible using (only) vertex/fragment shaders in WebGL? I guess I can probably read back the texture and download it again, but I expect to have some performance issues doing this.

Thx !

Ideally, you want to render to an FBO so you can read that into a texture on the following frame. However, because you’re not allowed to read and write from the same texture at the same time, you will need to do a double-buffer arrangement. So create two texture/FBO’s (let’s call them A & B).

Bind A as a texture, set B as the render target.
Draw your new effect into B, merging in A as you go.
Bind B as a texture, copy it onto the screen by drawing a screen-sized quad.
Swap A and B.
Repeat.

You can do that pretty fast.