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:

  1. OpenGL ES drop shadows for 2D sprites

  2. 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);
    //dispose our blurred data now that it resides on the GPU
    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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.