【问题标题】:Minecraft transparent render hides blocksMinecraft 透明渲染隐藏块
【发布时间】:2018-04-25 03:01:00
【问题描述】:

我不明白为什么当我从南面或东面看时我的纹理呈现出预期的效果,但从北面或西面看时却隐藏了它们背后的对象。

我有一个不可见的块,它在其中呈现多个项目,并且在处理具有半透明纹理的块时遇到了问题。已尝试切换基础块和纹理块的所有块属性(例如渲染类型、图层、不透明),并尝试在渲染上使用不同的混合选项。

锻造版本 1.12

普通视图 破碎的视图 渲染器

public class BlueRenderer extends TileEntitySpecialRenderer<TileEntityBlue> {

    @Override
    public void render(TileEntityBlue tile, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
        itemRenderer = mc.getRenderItem();
        textureManager = mc.getTextureManager();
        blockModelShapes = mc.getBlockRendererDispatcher().getBlockModelShapes();

        GlStateManager.pushAttrib();
        GlStateManager.pushMatrix();

        GlStateManager.translate(x, y, z);
        GlStateManager.disableRescaleNormal();

        renderItem(new GetBlock("minecraft:jukebox"), 0.5F);
        renderItem(new GetBlock("mymod:blue"), 1F);

        GlStateManager.popMatrix();
        GlStateManager.popAttrib();
    }

    private void renderItem(GetBlock block, float scale) {

        RenderHelper.enableStandardItemLighting();
        GlStateManager.enableLighting();
        GlStateManager.pushMatrix();
        GlStateManager.translate(0.5, 0.5, 0.5);
        GlStateManager.scale(scale, scale, scale);

        IBakedModel model = blockModelShapes.getModelForState(block.state);
        model = ForgeHooksClient.handleCameraTransforms(model, ItemCameraTransforms.TransformType.NONE, false);

        GlStateManager.enableBlend();
        GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

        textureManager.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
        itemRenderer.renderItem(block.stack, model);

        GlStateManager.disableBlend();

        GlStateManager.popMatrix();
    }

【问题讨论】:

    标签: minecraft-forge opengl-1.x


    【解决方案1】:

    阅读 transparency 后 - 我打开了深度蒙版,但缺少 alpha 函数。

        GlStateManager.enableBlend();
        GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        if (transparent) {
            GlStateManager.depthMask(false);
            GlStateManager.alphaFunc(GL11.GL_LESS, 1.0F);
            itemRenderer.renderItem(block.stack, model);
            GlStateManager.depthMask(true);
        } else {
            GlStateManager.alphaFunc(GL11.GL_EQUAL, 1.0F);
            itemRenderer.renderItem(block.stack, model);
        }
        GlStateManager.disableBlend();
    

    注意事项:

    最后渲染透明项目,否则它们将无法正确显示为“内部”。

        renderItem(new GetBlock("minecraft:jukebox"), 0.5F, false );
        renderItem(new GetBlock("mymod:blue"), 1F, true /*transparent*/);
    

    实体项目还需要混合函数GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);,因为堆栈中的第一个实体项目会在某些角度出现故障:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-07
      • 1970-01-01
      • 2010-11-21
      • 2018-01-27
      • 2016-08-25
      • 1970-01-01
      • 2013-07-05
      • 2011-12-26
      相关资源
      最近更新 更多