小编Jus*_*kas的帖子

libGDX 3D阴影瑕疵

我有一些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);
Run Code Online (Sandbox Code Playgroud)

对它来说并不多.另外考虑到它在桌面上运行我会认为影子实现本身有问题.有什么办法可以解决这个问题吗?考虑到我的生活中从未触及过着色器.一些简单的黑客可能吗?如果没有,也许有人可以为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 …
Run Code Online (Sandbox Code Playgroud)

java api 3d shadows libgdx

1
推荐指数
1
解决办法
1626
查看次数

标签 统计

3d ×1

api ×1

java ×1

libgdx ×1

shadows ×1