I am having some troubles with libgdx 3d shadows. In my game I implemented the experimental DirectionalShadowLight. And everything works great on desktop however when I run it on android there are a lot of artifacts on the ground.
Picture (left-android, right-desktop):
I took the rendering code almost directly from tests in libgdx's github repositories.
Gdx.gl.glClearColor(ExtendedEnvironment.FarBackgroundColor.r,ExtendedEnvironment.FarBackgroundColor.g,ExtendedEnvironment.FarBackgroundColor.b,1);
Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
terrain.prepareForShadows();
environment.shadowLight.begin(new Vector3(cam.position.x+10,0,0), cam.direction);
shadowBatch.begin(environment.shadowLight.getCamera());
ball.draw(shadowBatch, null);
terrain.draw(shadowBatch, null);
shadowBatch.end();
environment.shadowLight.end();
terrain.recoverFromShadows(ball.getPosition().x);
Theres not much to it. Also considering that it works on desktop I would think that theres something wrong with shadow implementation itself. Is there anything I can do to fix this? Considering that I had never touched a shader in my life. Some simple hack maybe? If not maybe someone could recommend other working shadow implementation for libgdx?
Thank you.
EDIT: additional code:
BlendingAttribute blendAttribute = new BlendingAttribute(1f)
IntAttribute intAttribute = IntAttribute.createCullFace(GL20.GL_FRONT);
public void prepareForShadows(){
batchedCubesInstance.materials.first().remove(blendAttribute.type);
batchedCubesInstance.materials.first().remove(intAttribute.type);
}
public void recoverFromShadows(float posX){
batchedCubesInstance.materials.first().set(blendAttribute);
batchedCubesInstance.materials.first().set(intAttribute);
}
//creating the batchedMesh:
ModelBuilder builder = new ModelBuilder();
builder.begin();
MeshPartBuilder mpb = builder.part("cubes", GL20.GL_TRIANGLES, (Usage.Position | Usage.Normal | Usage.Color), new Material(
IntAttribute.createCullFace(GL20.GL_FRONT),//For some reason, libgdx ModelBuilder makes boxes with faces wound in reverse, so cull FRONT
blendAttribute = new BlendingAttribute(1f), //opaque since multiplied by vertex color
new DepthTestAttribute(true), //don't want depth mask or rear cubes might not show through
ColorAttribute.createDiffuse(Color.WHITE) //white since multiplied by vertex color
));
for (int i=0; i < NUMCUBES; i++){
mpb.box(1, 1, 1);
}
batchedCubes = builder.end();
batchedCubesInstance = new ModelInstance(batchedCubes);