Iris Shaders

Iris Shaders

38M Downloads

Inconsistency when rendering lines with RenderLayer.ALWAYS_DEPTH_TEST with clientcommands.

fooeyround opened this issue ยท 6 comments

commented

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:

  • for each line in the outline
    edge.renderLine(matrixStack, vertexConsumer, delta, prevPos.subtract(getPos()));

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)

commented

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

commented

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 )

commented

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

commented

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?

commented

Can still reproduce in 1.21.2 on Iris 1.8 beta 6 (which has all the rendering changes and improved mod support)

commented

The issue seems to be that Iris is ignoring the depth test value in the RenderLayer. This is causing the lines to not be render behind other blocks and to appear at different brightness depending on the angle you look at them, presumably because of Z-fighting.

With Iris:
Image

Without Iris:
Image

Steps to reproduce:

  1. Install clientcommands, Fabric API, Sodium and Iris from Modrinth
  2. Open a world and face a block.
  3. Type /cglow block <tab> <tab> <tab> 30.
    • replace <tab> with the tab key, to autocomplete the coordinates of the block you are looking at.
    • the 30 is the number of seconds you want the cube to stay for before disappearing, feel free to increase.
  4. Observe cube not rendering through blocks
  5. Uninstall Iris
  6. Repeat steps 2-3
  7. Observe cube properly rendering through blocks

I should note that I am using an Nvidia RTX 4060 Ti, using proprietary drivers on archlinux, but other users have reported that this issue is consistent across different vendors and systems.