0

I am using Box2DLights in one of my project. I worked on this project for a couple of month now, and I just tried to port it on Android, to see how it looks. While the light effect look very nice on the desktop version of the game, it looks really ugly on the Android version. The light gradient is not smooth at all, with a color banding effect. Here are screenshots of the desktop and android versions : enter image description here

To use Box2DLights in my game, I use this code in my GameScreen :

RayHandler.useDiffuseLight(true); 
rayHandler = new RayHandler(world); 
rayHandler.resizeFBO(Gdx.graphics.getWidth()/5, Gdx.graphics.getHeight()/5); 
rayHandler.setBlur(true);   
rayHandler.setAmbientLight(new Color(0.15f, 0.15f, 0.15f, 0.1f));

I also tried to play with different parameters, such as :

rayHandler.diffuseBlendFunc.set(GL20.GL_DST_COLOR, GL20.GL_SRC_COLOR);

Or

rayHandler.shadowBlendFunc.set(GL20.GL_DST_COLOR, GL20.GL_SRC_COLOR);

Or

Gdx.gl.glEnable(GL20.GL_DITHER);

I don't know it that helps, but here are other precisions :

  • My tileset was made on Photoshop and recorded as a PNG file with the mode RGB, 8 bits/channel
  • This effect was observed on my 2 Android devices that are :
    • Tablet Transformer Prime TF701 with Android 4.2.1
    • LG G Stylo with Android 5.0.2

Thanks for you help !

Sebastian
  • 5,721
  • 3
  • 43
  • 69
vdlmrc
  • 737
  • 5
  • 17

1 Answers1

0

Here is the solution :

The problem was linked to a low bit depth on Android. If you look to the code of AndroidApplicationConfiguration.java, you'll notice at lines 30 and 31 this code :

/** number of bits per color channel **/
public int r = 5, g = 6, b = 5, a = 0;

Thus, Android applications with libGDX render, by default, low bit images. This can be easily modified in the AndroidLauncher.java of your application.

The default AndroidLauncher.java of your app looks like this :

public class AndroidLauncher extends AndroidApplication {
    @Override
    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
        initialize(new MyGdxGame(), config);
    }
}

All you have to do, to have a render format of RGBA8888 for your Android app is :

public class AndroidLauncher extends AndroidApplication {
    @Override
    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
        config.r = 8;
        config.g = 8;
        config.b = 8;
        config.a = 8;
        initialize(new MyGdxGame(), config);
    }
}

Et voilĂ  ! Here is a comparative screenshot of Android RGB565 VS Android RGBA8888 VS Desktop : enter image description here

You can see that the Android RGBA8888 is very close to the desktop version.

vdlmrc
  • 737
  • 5
  • 17