Here is a simple splash showing my problem:
<html>
<head>
<title>Clear Color</title>
<style type="text/css">
#stage {
background-color: rgba(127,127,127,1);
}
</style>
</head>
<body>
<canvas id="stage" width="100", height="100"></canvas>
<script type="text/javascript">
var options = {
alpha: true,
premultipliedAlpha: true
};
var ctx = document.getElementById("stage").getContext("webgl", options);
ctx.clearColor(1, 0, 0, 0);
ctx.enable(ctx.BLEND);
ctx.blendFuncSeparate(
ctx.SRC_ALPHA, ctx.ONE_MINUS_SRC_ALPHA,
ctx.ONE, ctx.ONE_MINUS_SRC_ALPHA
);
ctx.clear(ctx.COLOR_BUFFER_BIT);
</script>
</body>
</html>
BlendFunc:
(sR * sA) + (dR * (1-sA)) = rR
(sG * sA) + (dG * (1-sA)) = rG
(sB * sA) + (dB * (1-sA) ) = rB
(sA * 1) + (dA * (1-sA)) = rA
... that translates into this (I think):
(1 * 0) + (0.5 * (1-0)) = 0.5
(0 * 0) + (0.5 * (1-0) ) = 0.5
(0 * 0) + (0.5 * (1-0)) = 0.5
(0 * 1) + (1.0 * (1-0)) = 1.0
Why do I see a light pink canvas instead of gray, which declares CSS? Pink obviously comes from my clearColor, but why does it show red when the alpha component is 0?
source
share