代码之家  ›  专栏  ›  技术社区  ›  vps11

libGDX错误地渲染PNG透明度

  •  1
  • vps11  · 技术社区  · 7 年前

    Sample

    我已添加 BlendingAttribute 但一些(并非所有)纹理仍然渲染不正确。这些尖面应该是透明的。以下是我的片段:

    private void doneLoading() {
    
        terrain = assets.get("xx.g3db", Model.class);
        terrainInstance = new ModelInstance(terrain);
        for(n = 2; n < terrainInstance.materials.size; n++){
            terrainInstance.materials.get(n).set(new BlendingAttribute(GL30.GL_SRC_ALPHA, GL30.GL_ONE_MINUS_SRC_ALPHA)); // this should working for all faces
        }
        instances.add(terrainInstance);
        loading = false;
    }
    
    @Override
    public void render() {
        if (loading && assets.update()) {
            doneLoading();
        }
        personcam.update(Gdx.graphics.getDeltaTime());
    
        Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        Gdx.gl.glTexParameteri(GL30.GL_TEXTURE_2D, GL30.GL_TEXTURE_MAG_FILTER, GL30.GL_NEAREST);
        Gdx.gl.glClearColor(1, 1, 1, 1);
        Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT | GL30.GL_DEPTH_BUFFER_BIT);
    
        modelBatch.begin(cam);
        modelBatch.render(instances, environment);
        modelBatch.end();
    
    }
    

    我已经检查了我的纹理文件,它们很好。我的FBX文件(我正在使用SketchUp 8)也很好。为什么有些面不能正确渲染透明度?这是臭虫吗?

    1 回复  |  直到 7 年前
        1
  •  1
  •   vps11    7 年前

    通过添加单行找到:

    terrainInstance.materials.get(n).set(new FloatAttribute(FloatAttribute.AlphaTest, 0.8f));
    

    for 循环修复了透明度问题。