By the way, I tried rotating the whole scene by 180 degree. The glitched area doesn't change.
EDIT: Sorry for the self reply.
I think I found a solution for the blurred background without fixing the bug.
The code has two optmizations for the original snapshot background feature.
1) Make a fastSnap function for the Bitmap class. The returned bitmap does not use a canvas like the old snap function. It links the render texture to its base texture. This function is very fast, unlike snap, which gets pixel data from the render texture before converting it into a canvas.
2) Add a blur filter to the sprite, instead of use the old canvas solution. Again, it is very fast and can be modifed for real time rendering. To hide the bug mentioned in the first post, I just add a child sprite which uses the same bitmap. The child sprite will have the blur filter, while the parent works like a background so you don't see the darker background behind. Since the border is very thin and smooth the flaw is very well hidden. Unless you want a very heavy blur.
JavaScript:
Bitmap.fastSnap = function(stage) {
var width = Graphics.width;
var height = Graphics.height;
if(!this.fsBitmap){
this.fsBitmap = new Bitmap(width, height);
this.fsBitmap._setDirty = function(){};
this.fsBitmap._dirty = false;
this.fsTexture = PIXI.RenderTexture.create(width, height);
this.fsBitmap.__baseTexture = this.fsTexture.baseTexture;
}
if (stage) {
Graphics._renderer.render(stage, this.fsTexture);
stage.worldTransform.identity();
}
return this.fsBitmap;
};
SceneManager.fastSnap = function() {
return Bitmap.fastSnap(this._scene);
};
SceneManager.snapForBackground = function() {
//webgl
if(Graphics.isWebGL()){
this._backgroundBitmap = this.fastSnap();
this._backgroundBitmap._needBlur = true;
}
else{
//canvas mode
this._backgroundBitmap = this.snap();
this._backgroundBitmap.blur();
}
};
(function(alias){
Sprite.prototype.update = function() {
//add blurred version over the normal one, to hide the flaw
if(this.bitmap && this.bitmap._needBlur && !this._blurChild){
var spriteBlur = new Sprite();
spriteBlur.bitmap = this.bitmap;
if(!Sprite._blurFilter){
var blurFilter = new PIXI.filters.BlurFilter();
blurFilter.blur=1;
blurFilter.padding=0;
Sprite._blurFilter = blurFilter;
}
spriteBlur._filters = spriteBlur._filters||[];
spriteBlur._filters.push(Sprite._blurFilter);
this.addChild(spriteBlur);
this._blurChild = spriteBlur._blurChild = spriteBlur;
}
alias.apply(this, arguments);
};
})(Sprite.prototype.update);