@@ -9248,56 +9248,58 @@ this.createjs = this.createjs||{};
92489248 */
92499249 StageGL.UV_RECT = {t:0, l:0, b:1, r:1};
92509250
9251- /**
9252- * Vertex positions for a card that covers the entire render. Used with render targets primarily.
9253- * @property COVER_VERT
9254- * @static
9255- * @final
9256- * @type {Float32Array}
9257- * @readonly
9258- */
9259- StageGL.COVER_VERT = new Float32Array([
9260- -1, 1, //TL
9261- 1, 1, //TR
9262- -1, -1, //BL
9263- 1, 1, //TR
9264- 1, -1, //BR
9265- -1, -1 //BL
9266- ]);
9267-
9268- /**
9269- * U/V for {{#crossLink "StageGL/COVER_VERT:property"}}{{/crossLink}}.
9270- * @property COVER_UV
9271- * @static
9272- * @final
9273- * @type {Float32Array}
9274- * @readonly
9275- */
9276- StageGL.COVER_UV = new Float32Array([
9277- 0, 0, //TL
9278- 1, 0, //TR
9279- 0, 1, //BL
9280- 1, 0, //TR
9281- 1, 1, //BR
9282- 0, 1 //BL
9283- ]);
9284-
9285- /**
9286- * Flipped U/V for {{#crossLink "StageGL:COVER_VERT:property"}}{{/crossLink}}.
9287- * @property COVER_UV_FLIP
9288- * @static
9289- * @final
9290- * @type {Float32Array}
9291- * @readonly
9292- */
9293- StageGL.COVER_UV_FLIP = new Float32Array([
9294- 0, 1, //TL
9295- 1, 1, //TR
9296- 0, 0, //BL
9297- 1, 1, //TR
9298- 1, 0, //BR
9299- 0, 0 //BL
9300- ]);
9251+ try {
9252+ /**
9253+ * Vertex positions for a card that covers the entire render. Used with render targets primarily.
9254+ * @property COVER_VERT
9255+ * @static
9256+ * @final
9257+ * @type {Float32Array}
9258+ * @readonly
9259+ */
9260+ StageGL.COVER_VERT = new Float32Array([
9261+ -1, 1, //TL
9262+ 1, 1, //TR
9263+ -1, -1, //BL
9264+ 1, 1, //TR
9265+ 1, -1, //BR
9266+ -1, -1 //BL
9267+ ]);
9268+
9269+ /**
9270+ * U/V for {{#crossLink "StageGL/COVER_VERT:property"}}{{/crossLink}}.
9271+ * @property COVER_UV
9272+ * @static
9273+ * @final
9274+ * @type {Float32Array}
9275+ * @readonly
9276+ */
9277+ StageGL.COVER_UV = new Float32Array([
9278+ 0, 0, //TL
9279+ 1, 0, //TR
9280+ 0, 1, //BL
9281+ 1, 0, //TR
9282+ 1, 1, //BR
9283+ 0, 1 //BL
9284+ ]);
9285+
9286+ /**
9287+ * Flipped U/V for {{#crossLink "StageGL:COVER_VERT:property"}}{{/crossLink}}.
9288+ * @property COVER_UV_FLIP
9289+ * @static
9290+ * @final
9291+ * @type {Float32Array}
9292+ * @readonly
9293+ */
9294+ StageGL.COVER_UV_FLIP = new Float32Array([
9295+ 0, 1, //TL
9296+ 1, 1, //TR
9297+ 0, 0, //BL
9298+ 1, 1, //TR
9299+ 1, 0, //BR
9300+ 0, 0 //BL
9301+ ]);
9302+ } catch(e) { /* Breaking in older browsers, but those browsers wont run StageGL so no recovery or warning needed */ }
93019303
93029304 /**
93039305 * Portion of the shader that contains the "varying" properties required in both vertex and fragment shaders. The
@@ -9392,7 +9394,17 @@ this.createjs = this.createjs||{};
93929394 "{{alternates}}" +
93939395 "}" +
93949396
9395- "gl_FragColor = vec4(color.rgb{{premultiply}}, color.a * alphaValue);" +
9397+ "{{fragColor}}" +
9398+ "}"
9399+ );
9400+ StageGL.REGULAR_FRAG_COLOR_NORMAL = (
9401+ "gl_FragColor = vec4(color.rgb, color.a * alphaValue);"
9402+ );
9403+ StageGL.REGULAR_FRAG_COLOR_PREMULTIPLY = (
9404+ "if(color.a > 0.0035) {" + // 1/255 = 0.0039, so ignore any value below 1 because it's probably noise
9405+ "gl_FragColor = vec4(color.rgb/color.a, color.a * alphaValue);" +
9406+ "} else {" +
9407+ "gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);" +
93969408 "}"
93979409 );
93989410
@@ -10280,7 +10292,7 @@ this.createjs = this.createjs||{};
1028010292 insert += "} else if (indexPicker <= "+ i +".5) { color = texture2D(uSampler["+ i +"], vTextureCoord);";
1028110293 }
1028210294 str = str.replace(/{{alternates}}/g, insert);
10283- str = str.replace(/{{premultiply }}/g, this._premultiply ? "/color.a" : "" );
10295+ str = str.replace(/{{fragColor }}/g, this._premultiply ? StageGL.REGULAR_FRAG_COLOR_NORMAL : StageGL.REGULAR_FRAG_COLOR_PREMULTIPLY );
1028410296
1028510297 // actually compile the shader
1028610298 var shader = gl.createShader(type);
@@ -10689,15 +10701,14 @@ this.createjs = this.createjs||{};
1068910701 mtx = mtx.clone();
1069010702 mtx.scale(1/manager.scale, 1/manager.scale);
1069110703 mtx = mtx.invert();
10692- mtx.translate(-manager.offX/manager.scale, -manager.offY/manager.scale);
10704+ mtx.translate(-manager.offX/manager.scale*target.scaleX , -manager.offY/manager.scale*target.scaleY );
1069310705 var container = this._cacheContainer;
1069410706 container.children = [target];
1069510707 container.transformMatrix = mtx;
1069610708
1069710709 this._backupBatchTextures(false);
1069810710
10699- var filterCount = filters && filters.length;
10700- if (filterCount) {
10711+ if (filters && filters.length) {
1070110712 this._drawFilters(target, filters, manager);
1070210713 } else {
1070310714 // is this for another stage or mine?
@@ -10743,7 +10754,7 @@ this.createjs = this.createjs||{};
1074310754 var wBackup = this._viewportWidth, hBackup = this._viewportHeight;
1074410755
1074510756 var container = this._cacheContainer;
10746- var filterCount = filters && filters .length;
10757+ var filterCount = filters.length;
1074710758
1074810759 // we don't know which texture slot we're dealing with previously and we need one out of the way
1074910760 // once we're using that slot activate it so when we make and bind our RenderTexture it's safe there
@@ -10762,10 +10773,8 @@ this.createjs = this.createjs||{};
1076210773 this.setTextureParams(gl);
1076310774
1076410775 var flipY = false;
10765-
10766- // apply each filter in order, but remember to toggle used texture and render buffer
10767- for (var i=0; i<filterCount; i++) {
10768- var filter = filters[i];
10776+ var i = 0, filter = filters[i];
10777+ do { // this is safe because we wouldn't be in apply filters without a filter count of at least 1
1076910778
1077010779 // swap to correct shader
1077110780 this._activeShader = this.getFilterShader(filter);
@@ -10787,10 +10796,14 @@ this.createjs = this.createjs||{};
1078710796 this.setTextureParams(gl);
1078810797
1078910798 // use flipping to keep things upright, things already cancel out on a single filter
10790- if (filterCount > 1) {
10799+ // this needs to be here as multiPass is not accurate to _this_ frame until after shader acquisition
10800+ if (filterCount > 1 || filters[0]._multiPass) {
1079110801 flipY = !flipY;
1079210802 }
10793- }
10803+
10804+ // work through the multipass if it's there, otherwise move on
10805+ filter = filter._multiPass !== null ? filter._multiPass : filters[++i];
10806+ } while (filter);
1079410807
1079510808 // is this for another stage or mine
1079610809 if (this.isCacheControlled) {
@@ -14289,6 +14302,15 @@ this.createjs = this.createjs||{};
1428914302 */
1429014303 this.usesContext = false;
1429114304
14305+ /**
14306+ * Another filter that is required to act as part of this filter and created and managed under the hood.
14307+ * @private
14308+ * @property _multiPass
14309+ * @type {Filter}
14310+ * @default null
14311+ */
14312+ this._multiPass = null;
14313+
1429214314 /**
1429314315 * Pre-processed template shader code. It will be parsed before being fed in into the shader compiler.
1429414316 * This should be based upon StageGL.SHADER_VERTEX_BODY_REGULAR
@@ -14891,9 +14913,8 @@ this.createjs = this.createjs||{};
1489114913
1489214914 var data;
1489314915
14894- var l = filters.length;
14895- for (var i=0; i<l; i++) {
14896- var filter = filters[i];
14916+ var i = 0, filter = filters[i];
14917+ do { // this is safe because we wouldn't be in apply filters without a filter count of at least 1
1489714918 if(filter.usesContext){
1489814919 if(data) {
1489914920 ctx.putImageData(data, 0,0);
@@ -14906,7 +14927,10 @@ this.createjs = this.createjs||{};
1490614927 }
1490714928 filter._applyFilter(data);
1490814929 }
14909- }
14930+
14931+ // work through the multipass if it's there, otherwise move on
14932+ filter = filter._multiPass !== null ? filter._multiPass : filters[++i];
14933+ } while (filter);
1491014934
1491114935 //done
1491214936 if(data) {
@@ -16621,6 +16645,6 @@ this.createjs = this.createjs || {};
1662116645 * @type String
1662216646 * @static
1662316647 **/
16624- s.buildDate = /*=date*/"Tue, 04 Jul 2017 15:42:51 GMT"; // injected by build process
16648+ s.buildDate = /*=date*/"Mon, 17 Jul 2017 17:06:39 GMT"; // injected by build process
1662516649
1662616650})();
0 commit comments