我在使用 libgdx 3d 阴影时遇到了一些问题。在我的游戏中,我实现了实验性的 DirectionalShadowLight。一切都在桌面上运行良好,但是当我在 android 上运行它时,地面上有很多工件。
图片(左安卓,右桌面):
我几乎直接从 libgdx 的 github 存储库中的测试中获取了渲染代码。
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);
没什么大不了的。还考虑到它可以在桌面上运行,我认为影子实现本身有问题。我能做些什么来解决这个问题吗?考虑到我一生中从未接触过着色器。一些简单的黑客可能?如果不是,也许有人可以为 libgdx 推荐其他工作影子实现?
谢谢你。
编辑:附加代码:
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);