diff --git a/src/main/java/com/gtnewhorizons/angelica/glsm/GLStateManager.java b/src/main/java/com/gtnewhorizons/angelica/glsm/GLStateManager.java index b5770fc0c..47c61861f 100644 --- a/src/main/java/com/gtnewhorizons/angelica/glsm/GLStateManager.java +++ b/src/main/java/com/gtnewhorizons/angelica/glsm/GLStateManager.java @@ -1252,7 +1252,7 @@ public class GLStateManager { i = mipmap ? GL11.GL_LINEAR_MIPMAP_LINEAR : GL11.GL_LINEAR; j = GL11.GL_LINEAR; } else { - i = mipmap ? GL11.GL_NEAREST_MIPMAP_LINEAR : GL11.GL_NEAREST; + i = mipmap ? GL11.GL_LINEAR_MIPMAP_LINEAR : GL11.GL_NEAREST; j = GL11.GL_NEAREST; } glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, i); diff --git a/src/main/java/com/gtnewhorizons/angelica/glsm/texture/TextureInfo.java b/src/main/java/com/gtnewhorizons/angelica/glsm/texture/TextureInfo.java index d03b8e94a..3ae17febf 100644 --- a/src/main/java/com/gtnewhorizons/angelica/glsm/texture/TextureInfo.java +++ b/src/main/java/com/gtnewhorizons/angelica/glsm/texture/TextureInfo.java @@ -12,7 +12,7 @@ public class TextureInfo { protected int width = -1; protected int height = -1; - @Getter @Setter protected int minFilter = GL11.GL_NEAREST_MIPMAP_LINEAR; + @Getter @Setter protected int minFilter = GL11.GL_LINEAR_MIPMAP_LINEAR; @Getter @Setter protected int magFilter = GL11.GL_LINEAR; @Getter @Setter protected int wrapS = GL11.GL_REPEAT; @Getter @Setter protected int wrapT = GL11.GL_REPEAT; diff --git a/src/main/java/com/prupe/mcpatcher/hd/MipmapHelper.java b/src/main/java/com/prupe/mcpatcher/hd/MipmapHelper.java index 18bf250f7..ea21213c1 100644 --- a/src/main/java/com/prupe/mcpatcher/hd/MipmapHelper.java +++ b/src/main/java/com/prupe/mcpatcher/hd/MipmapHelper.java @@ -74,7 +74,7 @@ public class MipmapHelper { int mipmaps = useMipmapsForTexture(textureName) ? getMipmapLevels(width, height, 1) : 0; logger.finer("setupTexture(%s) %dx%d %d mipmaps", textureName, width, height, mipmaps); int magFilter = blur ? GL11.GL_LINEAR : GL11.GL_NEAREST; - int minFilter = mipmaps > 0 ? GL11.GL_NEAREST_MIPMAP_LINEAR : magFilter; + int minFilter = mipmaps > 0 ? GL11.GL_LINEAR_MIPMAP_LINEAR : magFilter; int wrap = clamp ? GL11.GL_CLAMP : GL11.GL_REPEAT; if (mipmaps > 0) { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LEVEL, mipmaps); diff --git a/src/main/java/net/coderbot/iris/pipeline/transform/ShaderTransformer.java b/src/main/java/net/coderbot/iris/pipeline/transform/ShaderTransformer.java index 86e3ae5cd..14c79e42e 100644 --- a/src/main/java/net/coderbot/iris/pipeline/transform/ShaderTransformer.java +++ b/src/main/java/net/coderbot/iris/pipeline/transform/ShaderTransformer.java @@ -222,6 +222,10 @@ public class ShaderTransformer { for (var entry : types.entrySet()) { String formattedShader = getFormattedShader(entry.getValue(), prepatched.get(entry.getKey())); + // Restore identifiers that were temporarily renamed to dodge GLSL reserved keywords. + formattedShader = formattedShader.replace("iris_renamed_texture", "texture"); + formattedShader = formattedShader.replace("iris_renamed_sample", "sample"); + // Please don't mind the entire rest of this loop basically, we're doing awful fragile regex on the transformed // shader output to do things that I can't figure out with AST because I'm bad at it diff --git a/src/main/java/net/coderbot/iris/postprocess/BufferFlipper.java b/src/main/java/net/coderbot/iris/postprocess/BufferFlipper.java index a4b6f32ef..93e35179c 100644 --- a/src/main/java/net/coderbot/iris/postprocess/BufferFlipper.java +++ b/src/main/java/net/coderbot/iris/postprocess/BufferFlipper.java @@ -13,6 +13,13 @@ public class BufferFlipper { } public void flip(int target) { + // colortex6 carries material/mask data that the gbuffer populates every frame. + // If we allow it to flip, the alternate texture remains empty and later copy-back + // wipes the fresh mask, breaking TAA mask lookups (notably on foliage/transparents). + if (target == 6) { + return; + } + if (!flippedBuffers.remove(target)) { // If the target wasn't in the set, add it to the set. flippedBuffers.add(target); diff --git a/src/main/java/net/coderbot/iris/postprocess/FinalPassRenderer.java b/src/main/java/net/coderbot/iris/postprocess/FinalPassRenderer.java index ac70dda69..50efeab0a 100644 --- a/src/main/java/net/coderbot/iris/postprocess/FinalPassRenderer.java +++ b/src/main/java/net/coderbot/iris/postprocess/FinalPassRenderer.java @@ -49,6 +49,7 @@ public class FinalPassRenderer { @Nullable private final Pass finalPass; private final ImmutableList swapPasses; + private final ImmutableSet flippedBuffers; private final GlFramebuffer baseline; private final GlFramebuffer colorHolder; private int lastColorTextureId; @@ -72,6 +73,7 @@ public class FinalPassRenderer { this.noiseTexture = noiseTexture; this.renderTargets = renderTargets; + this.flippedBuffers = flippedBuffers; this.customUniforms = customUniforms; this.finalPass = pack.getCompositeFinal().map(source -> { Pass pass = new Pass(); @@ -101,23 +103,37 @@ public class FinalPassRenderer { // TODO: We don't actually fully swap the content, we merely copy it from alt to main // This works for the most part, but it's not perfect. A better approach would be creating secondary // framebuffers for every other frame, but that would be a lot more complex... - ImmutableList.Builder swapPasses = ImmutableList.builder(); + final ImmutableList.Builder swapPasses = ImmutableList.builder(); - flippedBuffers.forEach(i -> { - int target = i; + // BUG FIX: Swap passes are only needed for NON-flipped buffers that might flip in the future. + // Flipped buffers use ping-pong mechanism - no swap needed. + // Original code created swaps for ALL flippedAtLeastOnce buffers and copied ALT→MAIN, + // which destroyed fresh data in MAIN for currently-flipped buffers (breaking TAA). + // Fixed: Only create swaps for buffers that are in flippedAtLeastOnce but NOT currently flipped. + flippedAtLeastOnce.forEach(i -> { + final int target = i; + + // Skip buffer 6 (material mask) - gbuffers always write to MAIN, never flipped + if (target == 6) { + return; + } + + // Skip buffers that are currently flipped - they use ping-pong, no swap needed + if (flippedBuffers.contains(target)) { + return; + } if (buffersToBeCleared.contains(target)) { return; } - SwapPass swap = new SwapPass(); - RenderTarget target1 = renderTargets.get(target); + final SwapPass swap = new SwapPass(); + final RenderTarget target1 = renderTargets.get(target); swap.target = target; swap.width = target1.getWidth(); swap.height = target1.getHeight(); + // Non-flipped buffers write to ALT, copy ALT→MAIN to preserve data swap.from = renderTargets.createColorFramebuffer(ImmutableSet.of(), new int[] {target}); - // NB: This is handled in RenderTargets now. - //swap.from.readBuffer(target); swap.targetTexture = renderTargets.get(target).getMainTexture(); swapPasses.add(swap); @@ -264,8 +280,10 @@ public class FinalPassRenderer { public void recalculateSwapPassSize() { for (SwapPass swapPass : swapPasses) { - RenderTarget target = renderTargets.get(swapPass.target); + final RenderTarget target = renderTargets.get(swapPass.target); renderTargets.destroyFramebuffer(swapPass.from); + // Match constructor logic - swap passes are only for non-flipped buffers + // Copy ALT→MAIN to preserve data written to ALT swapPass.from = renderTargets.createColorFramebuffer(ImmutableSet.of(), new int[] {swapPass.target}); swapPass.width = target.getWidth(); swapPass.height = target.getHeight(); @@ -274,7 +292,7 @@ public class FinalPassRenderer { } private static void setupMipmapping(RenderTarget target, boolean readFromAlt) { - int texture = readFromAlt ? target.getAltTexture() : target.getMainTexture(); + final int texture = readFromAlt ? target.getAltTexture() : target.getMainTexture(); // TODO: Only generate the mipmap if a valid mipmap hasn't been generated or if we've written to the buffer // (since the last mipmap was generated) @@ -319,13 +337,13 @@ public class FinalPassRenderer { source.getVertexSource().orElseThrow(NullPointerException::new), source.getGeometrySource().orElse(null), source.getFragmentSource().orElseThrow(NullPointerException::new)); - String vertex = transformed.get(PatchShaderType.VERTEX); - String geometry = transformed.get(PatchShaderType.GEOMETRY); - String fragment = transformed.get(PatchShaderType.FRAGMENT); + final String vertex = transformed.get(PatchShaderType.VERTEX); + final String geometry = transformed.get(PatchShaderType.GEOMETRY); + final String fragment = transformed.get(PatchShaderType.FRAGMENT); PatchedShaderPrinter.debugPatchedShaders(source.getName(), vertex, geometry, fragment); Objects.requireNonNull(flipped); - ProgramBuilder builder; + final ProgramBuilder builder; try { builder = ProgramBuilder.begin(source.getName(), vertex, geometry, fragment, @@ -337,7 +355,7 @@ public class FinalPassRenderer { this.customUniforms.assignTo(builder); - ProgramSamplers.CustomTextureSamplerInterceptor customTextureSamplerInterceptor = ProgramSamplers.customTextureSamplerInterceptor(builder, customTextureIds, flippedAtLeastOnceSnapshot); + final ProgramSamplers.CustomTextureSamplerInterceptor customTextureSamplerInterceptor = ProgramSamplers.customTextureSamplerInterceptor(builder, customTextureIds, flippedAtLeastOnceSnapshot); CommonUniforms.addDynamicUniforms(builder); IrisSamplers.addRenderTargetSamplers(customTextureSamplerInterceptor, () -> flipped, renderTargets, true); @@ -361,15 +379,15 @@ public class FinalPassRenderer { } private ComputeProgram[] createComputes(ComputeSource[] compute, ImmutableSet flipped, ImmutableSet flippedAtLeastOnceSnapshot, Supplier shadowTargetsSupplier) { - ComputeProgram[] programs = new ComputeProgram[compute.length]; + final ComputeProgram[] programs = new ComputeProgram[compute.length]; for (int i = 0; i < programs.length; i++) { - ComputeSource source = compute[i]; + final ComputeSource source = compute[i]; if (source == null || !source.getSource().isPresent()) { continue; } else { // TODO: Properly handle empty shaders Objects.requireNonNull(flipped); - ProgramBuilder builder; + final ProgramBuilder builder; try { builder = ProgramBuilder.beginCompute(source.getName(), source.getSource().orElse(null), IrisSamplers.COMPOSITE_RESERVED_TEXTURE_UNITS);