IrisShaders / Iris

A modern shaders mod for Minecraft compatible with existing OptiFine shader packs
https://irisshaders.dev
GNU Lesser General Public License v3.0
3.31k stars 625 forks source link

Inconsistency when rendering lines with RenderLayer.ALWAYS_DEPTH_TEST with clientcommands. #2112

Open fooeyround opened 1 year ago

fooeyround commented 1 year ago

What happened?


    public static RenderLayer NO_DEPTH_LAYER = RenderLayer.of("clientcommands_no_depth", VertexFormats.LINES, VertexFormat.DrawMode.LINES, 256, true, true, RenderLayer.MultiPhaseParameters.builder()
            .program(RenderLayer.LINES_PROGRAM)
            .writeMaskState(RenderLayer.COLOR_MASK)
            .cull(RenderLayer.DISABLE_CULLING)
            .depthTest(RenderLayer.ALWAYS_DEPTH_TEST)
            .layering(RenderLayer.VIEW_OFFSET_Z_LAYERING)
            .lineWidth(new RenderLayer.LineWidth(OptionalDouble.of(Line.THICKNESS)))
            .build(true));
}

with this RenderLayer and rendering with these calls:

that code leads to this:

    public void renderLine(MatrixStack matrixStack, VertexConsumer vertexConsumer, float delta, Vec3d prevPosOffset) {
        Vec3d normal = this.end.subtract(this.start).normalize();
        putVertex(matrixStack, vertexConsumer, this.start.add(prevPosOffset.multiply(1 - delta)), normal);
        putVertex(matrixStack, vertexConsumer, this.end.add(prevPosOffset.multiply(1 - delta)), normal);
    }

    private void putVertex(MatrixStack matrixStack, VertexConsumer vertexConsumer, Vec3d pos, Vec3d normal) {
        vertexConsumer.vertex(
                matrixStack.peek().getPositionMatrix(),
                (float) pos.getX(),
                (float) pos.getY(),
                (float) pos.getZ()
        ).color(
                ((color >> 16) & 0xFF) / 255.0F,
                ((color >> 8) & 0xFF) / 255.0F,
                (color & 0xFF) / 255.0F,
                1.0F
        ).normal(
                matrixStack.peek().getNormalMatrix(),
                (float) normal.getX(),
                (float) normal.getY(),
                (float) normal.getZ()
        ).next();
    }

the lines are just the 12 from a cuboid outline, added by the /cglow command, each BoundingBox from a VoxelShape getting added separately.

these classes can be found here

GlowCommand Cuboid RenderQueue

Screenshots

with iris

without iris

Log output

with iris without iris

Minecraft Version

Minecraft 1.20.1

Iris Version

iris-mc1.20.1-1.6.8.jar (with sodium 0.5.2)

Operating System

Windows 11

What is your GPU?

Nvidia GeForce RTX 3080 ti

Additional context

I am wondering if it is actually iris causing it. and if there is a way to fix this on client commands side that would be compatible with vanilla and sodium+iris or if it is something that needs to be fixed by iris....

I see issues in sodium that are closed stating this is a general iris issue, I am unsure if it is fixed.

I hope this report is not a bother, I am not trying to blame iris...

I am not good with rendering stuff, but this should be 2 frames captured in render doc

can-not-see

can-see

It may help you out, but I am not sure... (they are taken with only fabric api, clientcommands, sodium, and iris)

fooeyround commented 1 year ago

If you need anything else, you can ask of course... I may be a bit slow to respond.

fooeyround commented 1 year ago

oh, I forgot to make it clear here in writing. As seen in the picture, the lines seem to be almost depth culled, somehow being rendered as if they had normal depth testing applied. This is not for every frame though, as seen sometimes it works.... It is dependent on where the camera is, not really relative to the line it seems, as they all share the same test, and also share this bug at the exact same time. Never does one have depth and not the other. I have no clue if this actually makes any sense, I have no clue what is happening xD (That is probably very obvious )

fooeyround commented 1 year ago

also did not show this. But this renders after entities, with the fapi callback.

coderbot16 commented 8 months ago

At a quick glance it almost looks like this is some sort of subchunk being culled... Are the disappearing boxes aligned on a chunk boundary? Otherwise, is it correlated to what else is being rendered - in other words, do you get the same behavior in an empty superflat world with no other entities for example?