Comparing two frames and render polygons

Hi,

I want to compare two frames and render polygons where the two frames differ. I think this can be done but I’m missing some theory.

The paper “Artistic Silhouettes: A Hybrid Approach” (link to PDF) describes more or less what I want to do but instead of doing edge detection, doing difference between two frames.

Once we have detected the silhouette edges in the current frame,
the next step is to determine which portions of the silhouette edges
are visible.
[…]
We next iterate over all the pixels in the reference image and build
a list L of edges that contributed at least one pixel

That second part is where I’m a bit lost. How would I go and do this with two frames? I would assume I would have to render to two render targets (previous and current frame) and compare them, then build some polygons. I can only think of doing all of this in the CPU, is it possible to do this in the GPU? Also, are there any examples of doing this in any of the two?

Thanks.

i would build 2 FBOs with each 2 texture attachments. each frame you render your scene into another FBO, that way you dont have to make any changes to any of these FBOs. once you finished with rendering your scene, invoke a computeshader: it has 3 “images” (= textures), 2 of them as “read-only”, 1 of them as “result”. the task of the compute shader is to calculate the color difference (image 1 - image 2) for each pixel. when finished, put the “result” image on the screen

how to do it:
generate 3 textures, 2 framebuffers
1st FBO:
color attachment 1 = texture 1
color attachment 2 = texture 3
2nd FBO:
color attachment 1 = texture 2
color attachment 2 = texture 3
(each frame, you render into another FBO)

compute shader images:
image 1 = texture 1
image 2= texture 2
image 3 = texture 3
(next frame, you swap texture 1 and 2 for the compute shader)

after computeshader has done the job, blit framebuffer (color attachment 2) onto the screen

compute shader example:
https://sites.google.com/site/john87connor/compute-shader/tutorial-5-1-loading-bmp-image

Hi john_connor, thanks for the reply.

I didn’t know about compute shaders, I’m looking into them. I have two questions about your approach.

  1. Are compute shaders supported cross platform? The small amount of info I’ve seen states they are not supported on Mac OS X as it doesn’t support OpenGL 4.3.
  2. Where would I create these polygons? Looks like after the compute shader is done it outputs the resulting image onto the screen. I need to check for the differences and create a list of polygons from it. I would have read that texture back right? How would I go to do that?

opengl is generally “cross platform” (its a standard, not a software), compute shaders are part of opengl (4.3)

either your platform has to support opengl 4.3 or the “ARB_compute_shader” extension, otherwise you cant use that shader
https://www.khronos.org/opengl/wiki/Compute_Shader

no, it doesnt, you have to call “glBlitFramebuffer(…)” to copy the data onto screen or you have to render a fullscreen quad with that “result” texture