crashinvaders / gdx-vfx

libGDX post-processing visual effects
https://crashinvaders.github.io/gdx-vfx
Apache License 2.0
191 stars 25 forks source link

Bloom effect creates lag on android #23

Open 4lfg24 opened 1 year ago

4lfg24 commented 1 year ago

I'm having an issue where applying the bloom effect drops the fps from 60 to 30 on Android, I know that applying bloom is a pretty expensive operation, but I was wondering if there was a solution to this, here's my code:

vfxManager.cleanUpBuffers(Color(0.3f, 0.3f,0.8f, 1f))

        vfxManager.beginInputCapture()

        SharedObjects.batch.use {
            for (entity in SharedObjects.entities){
                if(entity is Player) {
                    entity.render()
                }
                else {
                    entity.render()
                }
            }

            for(effect in SharedObjects.effects){
                effect.draw(SharedObjects.batch, delta)
                if (effect.isComplete){
                    SharedObjects.effects.removeValue(effect, true)
                    effect.free()
                }
            }
        }
        vfxManager.endInputCapture()

        vfxManager.applyEffects()
        vfxManager.renderToScreen()

Thank you in advance

metaphore commented 1 year ago

Hi, sorry for the late reply.

Not knowing what exactly happens in the rendering methods of your entities and effects, it's hard to judge where's the performance bottleneck.

However, speaking of the VFX, there are a few "not so fast" effects in the library, the bloom effect included. Where there's probably a more optimal implementation of the effect, I honestly don't think you can improve it dramatically with just a few amends (the bloom is a combination of multiple effects).

On many modern phones, a display may have an overwhelmingly huge resolution compared to the device's performance capabilities. That's why you need to be careful when you use heavy full-screen shaders, like the ones that are used in the bloom effect. At this point, if you want to get an instant gain in performance using post effects, I'd recommend you to reduce the size of the VFX buffers. The most performance impact comes from the number of pixels every effect needs to process. E.g. reducing VFX buffer resolution from 4K down to FHD makes every effect work 4 times faster and use 4 times less memory too. Of course, the downside would be the output resolution drop, but IMHO, for most mobile cases, that could be a fair tradeoff.

You can set the desired VFX resolution in the resize method. Here's how you cut it in half:

vfxManager.resize(width * 0.5f, height * 0.5f)
4lfg24 commented 1 year ago

Thank you for your help! I also experimented a bit and found out that reducing the bloom passes to below 7 increases the performance significantly.