I have 2 layers, and I would like to make holes in the front layer to let the user see the back layer. For this purpose, I'm drawing circles in a canvas, whitch is placed between the 2 layers (don't know if its place is correct).
For demonstration purpose, I have exploded the 3 layers, and displayed the canvas.
I have try several combinations of blend / mask, but I'm missing something here, and looking for help.
Where should be placed the canvas regarding the 2 layers, and what kind of blend operation should I make to make holes in the front layer ?
One solution should be to tell the front layer that it should use the canvas as an alpha mask when displayed.
Note : the back layer should remain untouched.
Here is a screenshot explaining the layout :
...and the codepen link: Mask Effect
/***
** onclick(e)
*/
$( document ).click(function(e) {
var ctx = $("canvas")[0].getContext('2d');
var radius = Math.random() * 50 + 10;
ctx.beginPath();
ctx.arc(e.clientX, e.clientY, radius, 0, 2 * Math.PI, false);
ctx.fillStyle = 'white';
ctx.fill();
ctx.closePath();
// ctx.globalCompositeOperation = 'screen';
// ctx.drawImage(ctx.canvas.toDataURL("image/png"),0,0); // debug: visualize
$('#front').css({
'mask-image':"url(" + ctx.canvas.toDataURL("image/png")+ ")",
'background-blend-mode':"screen",
'background-image':"url(" + ctx.canvas.toDataURL("image/png")+ ")"
});