Gamua / Starling-Framework

The Cross Platform Game Engine
http://www.starling-framework.org
Other
2.85k stars 819 forks source link

GlowFilter performance slower than in previous versions #860

Closed Jacowaco closed 6 years ago

Jacowaco commented 8 years ago

I was experiencing lag with the GlowFilter in my game's menu so i tried to made an example to reproduce it. In this case i apply a glow filter to many images, when they dont move, everything works fine, but when they move, the fps drop and the draw count increases a lot.

public class Game extends Sprite 
{
    private var sprite:Sprite;

    public function Game() 
    {
        super();

        sprite = new Sprite();
        addChild(sprite);

        for (var i:int = 0; i < 50; i++)
        {
            var img:Image = new Image(Texture.fromEmbeddedAsset(Main.imgTest, false, false, 1));
            img.x = i * 20;
            sprite.addChild(img);
            img.filter = new GlowFilter(0x0000ff, 1, 1, 1);
        }

        //comment this line of code and the fps won't drop
        goDown();
    }

    public function goDown():void
    {
        Starling.juggler.tween(sprite, 2, {y:400, onComplete:goUp});
    }

    public function goUp():void
    {
        Starling.juggler.tween(sprite, 2, {y:0, onComplete:goDown});
    }
}
Jacowaco commented 8 years ago

This is for Starling 2.0, i didn't have that lag in 1.8.x

PrimaryFeather commented 8 years ago

Hm ... that this will become slow is not surprising: a glow filter requires several passes, and having it on so many objects will be very expensive.

However, the number of draw calls of this scene is the same in Starling 1.8 and 2.0 (both need 200). So performance should be roughly the same. Are you sure that the equal scene is becoming so much slower in Starling 2? Have you tried the sample from above in both versions, on the same hardware + release mode?

Jacowaco commented 8 years ago

The same example with Starling 1.8.x changing only the GlowFilter line for: img.filter = BlurFilter.createGlow(0x0000ff, 1, 1, 1); Doesn't lag at all, runs at 60 fps

Starling 1.8: 102 draw calls, 60fps Starling 2.0: 96 draw calls, 50fps

This is a example i made to ilustrate the lag, but in my game i only have 9 items with glow (not 50), and the moving animation lags too, maybe because they are larger images than the one i tried in this example.

PrimaryFeather commented 8 years ago

That's interesting! Definitely something I want to analyze. I'm starting a vacation soon, so it might take a little longer; but I'll get back to you as soon as I know more.

BTW, which device did you test on? And, the usual question: are you sure you used release mode? It would also help to look at a Scout analysis of both versions; does anything interesting pop up?

Jacowaco commented 8 years ago

I tested on PC Desktop. In release mode the fps don't drop but the animation looks more lagged than in 1.8, even though the fps are mantained.

PrimaryFeather commented 8 years ago

Okay, thanks! I'll have a look at what Scout says when I'm back from my vacation.

serjek commented 8 years ago

I had the same problem and I use filter.cache() as a workaround. Note that cache() has many special traits and might not work in your particular case.

PrimaryFeather commented 6 years ago

Since this issue was opened, I made numerous optimizations on the FragmentFilter class, so it's about as fast as I can manage to get it. Thus, I'm closing this issue now.