uniform sampler2D source;
uniform sampler2D destination;
uniform float opacity;

varying vec2 texCoord;

vec4 result;
vec4 finalresult;
vec4 sourcetexel;
vec4 desttexel;
vec4 white;

vec4 screen() {
   vec4 white = vec4(1.0, 1.0, 1.0, 1.0);
   return white - ((white - desttexel) * (white - sourcetexel));
}

void main(void) {

   sourcetexel = texture2D(source, texCoord);
   desttexel = texture2D(destination, texCoord);

   result = screen();
   
   finalresult = mix(sourcetexel, result, opacity);
   gl_FragColor = finalresult;
}
