-
Notifications
You must be signed in to change notification settings - Fork 823
Description
Hi Daniel,
Me again 🙄...
I found an issue related to drawing a display object with a filter assigned to it. Apparently the matrix is not correctly computed when the parent (root) is shifted. Happily I have a piece of code to reproduce it easily.
I'm still trying to implement a post-effect stack and this issue is really blocking me because I cannot render my whole scene into a RenderTexture
to then apply extra FragmentFilters
or a custom MeshStyle
.. 😬 (edit: I found a workaround, see next comment)
I hope this is fixable 🤞
Best,
Aurélien
Description
When rendering a DisplayObject
with a FragmentFilter
applied on it in a RenderTexture
, the object position is not correct if the parent of the object is shifted.
Code to reproduce
The following code reproduces the issue on my side:
package
{
import starling.animation.IAnimatable;
import starling.core.Starling;
import starling.display.Image;
import starling.display.Quad;
import starling.display.Sprite;
import starling.filters.BlurFilter;
import starling.filters.GlowFilter;
import starling.textures.RenderTexture;
public class PostEffectTest extends Sprite implements IAnimatable
{
private var _renderingTexture:RenderTexture;
private var _renderingImage:Image;
private var _camera:Sprite
private var _entity:Quad;
public function PostEffectTest()
{
var offset:Number = 100; // set to 0 and it works as expected
// camera
_camera = new Sprite();
_camera.x = -offset;
// entity
_entity = new Quad(100, 100, 0xff0000);
_entity.alignPivot();
_entity.x = offset + Starling.current.stage.stageWidth * 0.5;
_entity.y = Starling.current.stage.stageHeight * 0.5;
_entity.filter = new GlowFilter(0x00ff00); // remove this line and it works
_camera.addChild(_entity);
// render
_renderingTexture = new RenderTexture(800, 480, false);
_renderingTexture.clear(); // might prevent Error #3605: Sampler 0 binds an invalid texture. (https://github.com/Gamua/Starling-Framework/issues/1087)
_renderingImage = new Image(_renderingTexture);
_renderingImage.filter = new BlurFilter();
addChild(_renderingImage);
// animation setup
Starling.current.juggler.add(this);
}
public function advanceTime(passedTime:Number):void
{
_entity.rotation += Math.PI * passedTime;
_renderingTexture.draw(_camera);
_renderingImage.setRequiresRedraw(); // required to update the image
}
}
}
Here is the faulty result with an offset of 100
applied on the camera (-) and the entity (+):
If the offset is set to 0
you get the expected result:
If the GlowFilter
applied to the entity is removed then you get the correct result (obviously without the expected filter):