Skip to content

Commit ad316cb

Browse files
Davidlannymcnie
authored andcommitted
Added fix for some devices pre multiply handling, specifically a division by 0 error.
1 parent 457f46f commit ad316cb

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/easeljs/display/StageGL.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,17 @@ this.createjs = this.createjs||{};
717717
"{{alternates}}" +
718718
"}" +
719719

720-
"gl_FragColor = vec4(color.rgb{{premultiply}}, color.a * alphaValue);" +
720+
"{{fragColor}}" +
721+
"}"
722+
);
723+
StageGL.REGULAR_FRAG_COLOR_NORMAL = (
724+
"gl_FragColor = vec4(color.rgb, color.a * alphaValue);"
725+
);
726+
StageGL.REGULAR_FRAG_COLOR_PREMULTIPLY = (
727+
"if(color.a > 0.0035) {" + // 1/255 = 0.0039, so ignore any value below 1 because it's probably noise
728+
"gl_FragColor = vec4(color.rgb/color.a, color.a * alphaValue);" +
729+
"} else {" +
730+
"gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);" +
721731
"}"
722732
);
723733

@@ -1605,7 +1615,7 @@ this.createjs = this.createjs||{};
16051615
insert += "} else if (indexPicker <= "+ i +".5) { color = texture2D(uSampler["+ i +"], vTextureCoord);";
16061616
}
16071617
str = str.replace(/{{alternates}}/g, insert);
1608-
str = str.replace(/{{premultiply}}/g, this._premultiply ? "/color.a" : "");
1618+
str = str.replace(/{{fragColor}}/g, this._premultiply ? StageGL.REGULAR_FRAG_COLOR_NORMAL : StageGL.REGULAR_FRAG_COLOR_PREMULTIPLY);
16091619

16101620
// actually compile the shader
16111621
var shader = gl.createShader(type);

0 commit comments

Comments
 (0)