我在这里查看所有不同类型的全局复合操作:
https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
他们都没有做我想做的事。有没有办法定义自定义 globalCompositeOperation?如果我可以创建一个着色器,然后在每次使用 CanvasRenderingContext2D.draw 方法绘制某些东西时使用它,那将是完美的。
具体来说,在每个像素的基础上,我希望 CanvasRenderingContext2D.draw 方法使用以下(伪代码)操作:
if the existing canvas color alpha is 0.0,
then draw the new shape's color and set alpha to 0.1
if the existing canvas color is the same as the new shape's color
then increase the alpha, by 0.1
if the existing canvas color is different from the the new shape's color
then decrease the alpha by 0.1
我是否正确地考虑了这一点?我感觉到我应该以某种方式使用 WebGLRenderingContext,但我对它们如何组合在一起有点不稳定。