shawnlawson / The_Force

webGL live coding performance IDE
https://shawnlawson.github.io/The_Force/
MIT License
274 stars 52 forks source link

Get the previous webcam frame #27

Open aatishb opened 3 years ago

aatishb commented 3 years ago

Hi, I wanted to create an effect where I take the difference of the current and the previous webcam frame to detect motion. I tried something like this:

void main () {

    vec4 w1 = texture2D(channel0, uvN());
    vec4 w2 = texture2D(backbuffer, uvN());
    vec4 test = w1 - w2;

    gl_FragColor = vec4(test) ;

}

But this doesn't work because it subtracts the previous output frame (instead of the previous webcam frame) from the current webcam frame, which leads to a flickering effect. So my question is simply, is there a way for me to access the previous webcam frame?

Thanks so much for this tool, it is really fun to play around and learn with.

shawnlawson commented 3 years ago

Oh, interesting. I tried drawing to different areas of the frame buffer, but turns out that I have texturing set to clamp to edge, meaning that the edge color stretches across the frame. So even with an overlay blackout, I'm not convinced that method would work either.

I honestly haven't used the camera much as a texture, but sounds like an interesting feature. Should we add it as a feature?