I am a libgdx learner. For an learning application that I am developing using libgdx on android, I need to show drop shadow or glow effect when a sprite is touched. The sprites are created from a TextureAtlas and can have any irregular shape as per the transparent image in the texture. There are a ton of images so it is not possible to create a separate shadow image for each one.
I have looked at some options but haven’t been able to figure out how to do it. What I have tried include:
-
I tried the approach of taking the texture and bluring it using the blurutils class provided by Matt Deslauriers at https://github.com/mattdesl/lwjgl-basics/wiki/OpenGL-ES-Blurs. The code I have used is below. But the performance was very slow on android devices for the BlurUitls.blur call.
private Sprite getShadowSprite(String name,float width,float height) { //Load the texture Pixmap orig = new Pixmap(Gdx.files.internal(name)); //blur it Pixmap blurred = BlurUtils.blur(orig, 16, 2, true); //we then create a GL texture with the blurred pixmap Texture blurTex = new Texture(blurred); Sprite shadow=new Sprite(blurTex); shadow.setSize(width,height); shadow.flip(false,true); //dispose our blurred data now that it resides on the GPU blurred.dispose(); return shadow; }
I do not have much of an understanding of shaders. Please advise as to what is the most performant way to be able to generate a drop shadow for a transparent image in libgdx.