[英]libGDX/Box2DLights Color Banding on Android
我在我的項目之一中使用Box2DLights。 我已經在這個項目上工作了兩個月,然后我嘗試將其移植到Android上,以查看其外觀。 雖然光效果在游戲的桌面版本上看起來非常不錯,但在Android版本上看起來確實很丑。 光梯度根本不平滑,具有色帶效果。 這是台式機和Android版本的屏幕截圖:
要在我的游戲中使用Box2DLights,我在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));
我還嘗試使用不同的參數,例如:
rayHandler.diffuseBlendFunc.set(GL20.GL_DST_COLOR, GL20.GL_SRC_COLOR);
要么
rayHandler.shadowBlendFunc.set(GL20.GL_DST_COLOR, GL20.GL_SRC_COLOR);
要么
Gdx.gl.glEnable(GL20.GL_DITHER);
我不知道這有什么幫助,但是這里還有其他精度:
謝謝您的幫助!
這是解決方案:
該問題與Android上的低位深度有關。 如果查看AndroidApplicationConfiguration.java的代碼, 則會在第30和31行注意到此代碼:
/** number of bits per color channel **/
public int r = 5, g = 6, b = 5, a = 0;
因此,帶有libGDX的Android應用程序默認情況下呈現低位圖像。 您可以在應用程序的AndroidLauncher.java中輕松地對此進行修改。
您應用的默認AndroidLauncher.java如下所示:
public class AndroidLauncher extends AndroidApplication {
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
initialize(new MyGdxGame(), config);
}
}
要為您的Android應用提供RGBA8888渲染格式,您需要做的就是:
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);
}
}
等等! 這是Android RGB565 VS Android RGBA8888 VS Desktop的對比屏幕截圖:
您會看到Android RGBA8888非常接近桌面版本。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.