kernelK
kernelK

Reputation: 189

How of use glBlendFunc to approximate a Photoshop Difference composite?

I am compositing one image on another using glBlendFunc() trying to approximate photoshop's difference compositing feature. I want similarities in the two images to be black while anything different pops out.

As I understand the glBlendfunc() is associative for any images composited in the context. Is that correct?

Upvotes: 0

Views: 522

Answers (1)

Tim
Tim

Reputation: 35943

I can't really think of any way to do this with glBlendFunc. You could use something like this:

glBlendEquation(GL_FUNC_SUBTRACT);
glBlendFunc(GL_ONE, GL_ONE);

But it would only work when the magnitude of the second texture was larger with the first (any subtraction result that is negative would be clamped to zero).

I'd recommend just sampling both textures at the same time with a multisampling shader, and outputting the result as the absolute difference.

gl_FragColor = abs(texture2D(tex1, uv) - texture2D(tex2,uv));

Upvotes: 1

Related Questions