3

我迷失了为什么当我从南方或东方看时我的纹理会按预期渲染,但从北方或西方看时隐藏在它们后面的对象。

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

锻造版本 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();
    }
4

1 回答 1

0

在阅读了透明度之后- 我有深度蒙版并且缺少 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);,因为堆栈上的第一个实体项目会在某些角度出现故障:

在此处输入图像描述

于 2017-11-12T10:29:28.123 回答