From 860a2673239b95ec640cc9195de6d81676a617ad Mon Sep 17 00:00:00 2001 From: Fox <80159542+WilyFoxM@users.noreply.github.com> Date: Fri, 13 Nov 2026 20:38:33 +0300 Subject: [PATCH] Draw the line after the level, so water no longer tints it The line went into the level's own submits, and water is drawn after them. It is now always drawn after the level render, as it already was with a shader pack, depth-tested against the main depth buffer. AfterShaders is renamed AfterLevel. --- .../{AfterShaders.java => AfterLevel.java} | 19 ++++++----- .../trajectory/client/DotRenderer.java | 34 +++++-------------- .../mixin/GameRendererAfterLevelMixin.java | 11 +++--- 3 files changed, 25 insertions(+), 39 deletions(-) rename src/main/java/ru/wilyfox/trajectory/client/{AfterShaders.java => AfterLevel.java} (88%) diff --git a/src/main/java/ru/wilyfox/trajectory/client/AfterShaders.java b/src/main/java/ru/wilyfox/trajectory/client/AfterLevel.java similarity index 88% rename from src/main/java/ru/wilyfox/trajectory/client/AfterShaders.java rename to src/main/java/ru/wilyfox/trajectory/client/AfterLevel.java index 1c9d842..0ea3064 100644 --- a/src/main/java/ru/wilyfox/trajectory/client/AfterShaders.java +++ b/src/main/java/ru/wilyfox/trajectory/client/AfterLevel.java @@ -25,13 +25,14 @@ import ru.wilyfox.trajectory.TrajectoryProjected; /** - * Drawing after an Iris shader pack has composed the frame. While a pack is active, Iris draws the - * level with the pack's programs and skips pipelines it has no program for, ours included. So the - * geometry is recorded during the level's submit phase instead, and replayed with our own pipelines - * right after the level render returns: onto the finished image, depth-tested against the main - * depth buffer the pack leaves behind. + * Drawing after the level has been rendered, onto the finished image, depth-tested against the main + * depth buffer. By then water and other translucent layers are drawn, and composed where improved + * transparency keeps them apart, so they do not tint the line; with an Iris shader pack, the pack + * has composed the frame too, and it skips pipelines it has no program for, ours included. The + * geometry is recorded during the level's submit phase and replayed with our own pipelines right + * after the level render returns. */ -public final class AfterShaders { +public final class AfterLevel { private static final boolean IRIS = FabricLoader.getInstance().isModLoaded("iris"); private static final MethodHandle PACK_IN_USE = resolve("isShaderPackInUse"); private static final MethodHandle SHADOW_PASS = resolve("isRenderingShadowPass"); @@ -39,10 +40,10 @@ public final class AfterShaders { private static final List RECORDED = new ArrayList<>(); private static Matrix4fc viewRotation; - private AfterShaders() {} + private AfterLevel() {} /** Whether a shader pack is active now; read every frame, since a pack can be toggled. */ - public static boolean active() { + public static boolean shaderPackActive() { return call(PACK_IN_USE); } @@ -78,7 +79,7 @@ static void record( PoseStack poseStack, RenderType type, SubmitNodeCollector.CustomGeometryRenderer geometry) { - AfterShaders.viewRotation = new Matrix4f(viewRotation); + AfterLevel.viewRotation = new Matrix4f(viewRotation); RECORDED.add(new Recorded(type, poseStack.last().copy(), geometry)); } diff --git a/src/main/java/ru/wilyfox/trajectory/client/DotRenderer.java b/src/main/java/ru/wilyfox/trajectory/client/DotRenderer.java index c3b4093..0c7f201 100644 --- a/src/main/java/ru/wilyfox/trajectory/client/DotRenderer.java +++ b/src/main/java/ru/wilyfox/trajectory/client/DotRenderer.java @@ -235,13 +235,6 @@ final class DotRenderer { private static final double LIFT = 1.25; private static final double ENTITY_PULL = 0.25; - /** - * Submit order for all our geometry. Entity layers use orders from 1 up (a slime's shell, eyes, - * armor), and an order is drawn after all lower ones; a late order keeps the line and the marker - * on top of translucent entity layers instead of tinted under them. - */ - private static final int SUBMIT_ORDER = 64; - /** Near the camera the line fades in over these distances, so it does not cover the crosshair. */ private static final double NEAR_FADE_START = 1.0; @@ -343,12 +336,10 @@ final class DotRenderer { private DotRenderer() {} static void collect(LevelRenderContext context) { - if (AfterShaders.shadowPass()) { + if (AfterLevel.shadowPass()) { return; } - if (AfterShaders.active()) { - AfterShaders.beginFrame(); - } + AfterLevel.beginFrame(); ShotPreview.Prediction current = ShotPreview.current(); if (current == null) { return; @@ -596,9 +587,8 @@ private static void submitZone( | parts; emit( context, - SUBMIT_ORDER - 1, context.poseStack(), - AfterShaders.active() ? ZONES_OVER_SHADERS : ZONES, + AfterLevel.shaderPackActive() ? ZONES_OVER_SHADERS : ZONES, (pose, buffer) -> { for (ZoneSurfaces.Patch patch : patches) { // A convex polygon as a fan of quads; an odd last one repeats its final corner. @@ -657,9 +647,8 @@ private static void submitRing(LevelRenderContext context, Vec3d at, Vec3 cam) { float r = (float) RING_RADIUS; emit( context, - SUBMIT_ORDER - 1, context.poseStack(), - AfterShaders.active() ? ZONES_OVER_SHADERS : ZONES, + AfterLevel.shaderPackActive() ? ZONES_OVER_SHADERS : ZONES, (pose, buffer) -> { buffer.addVertex(pose, x - r, y, z - r).setUv(-1.0F, -1.0F).setColor(color); buffer.addVertex(pose, x - r, y, z + r).setUv(-1.0F, 1.0F).setColor(color); @@ -681,28 +670,23 @@ private static void submit( } emit( context, - SUBMIT_ORDER, poseStack, type, (pose, buffer) -> dots.forEach(d -> d.emit(pose, buffer, up, left, scale))); } /** - * Hands geometry to the level's submit collector, or, with a shader pack active, to {@link - * AfterShaders} to draw once the pack has composed the frame. + * Hands geometry to {@link AfterLevel}, to draw once the level is rendered: over water and other + * translucent layers, which would otherwise tint it, and over entity layers. Drawn in the order + * handed over: the zone first, then the line and the marker. */ private static void emit( LevelRenderContext context, - int order, PoseStack poseStack, RenderType type, SubmitNodeCollector.CustomGeometryRenderer geometry) { - if (AfterShaders.active()) { - AfterShaders.record( - context.levelState().cameraRenderState.viewRotationMatrix, poseStack, type, geometry); - return; - } - context.submitNodeCollector().order(order).submitCustomGeometry(poseStack, type, geometry); + AfterLevel.record( + context.levelState().cameraRenderState.viewRotationMatrix, poseStack, type, geometry); } /** diff --git a/src/main/java/ru/wilyfox/trajectory/mixin/GameRendererAfterLevelMixin.java b/src/main/java/ru/wilyfox/trajectory/mixin/GameRendererAfterLevelMixin.java index 368df14..e12398b 100644 --- a/src/main/java/ru/wilyfox/trajectory/mixin/GameRendererAfterLevelMixin.java +++ b/src/main/java/ru/wilyfox/trajectory/mixin/GameRendererAfterLevelMixin.java @@ -12,11 +12,12 @@ import org.joml.Vector4f; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -import ru.wilyfox.trajectory.client.AfterShaders; +import ru.wilyfox.trajectory.client.AfterLevel; /** - * Right after the level render, before the hand: with an Iris shader pack active, the pack has - * composed the frame by then, and what was recorded for {@link AfterShaders} is drawn on top. + * Right after the level render, before the hand: water and other translucent layers are drawn and + * composed by then, as is an Iris shader pack's frame, and what was recorded for {@link AfterLevel} + * is drawn on top. */ @Mixin(GameRenderer.class) abstract class GameRendererAfterLevelMixin { @@ -27,7 +28,7 @@ abstract class GameRendererAfterLevelMixin { value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;render(Lcom/mojang/blaze3d/resource/GraphicsResourceAllocator;Lnet/minecraft/client/DeltaTracker;ZLnet/minecraft/client/renderer/state/level/CameraRenderState;Lorg/joml/Matrix4fc;Lcom/mojang/blaze3d/buffers/GpuBufferSlice;Lorg/joml/Vector4f;Z)V")) - private void trajectory$drawAfterShaders( + private void trajectory$drawAfterLevel( LevelRenderer levelRenderer, GraphicsResourceAllocator allocator, DeltaTracker deltaTracker, @@ -48,6 +49,6 @@ abstract class GameRendererAfterLevelMixin { terrainFog, fogColor, shouldCreateFog); - AfterShaders.flush(); + AfterLevel.flush(); } }