From cadb7219b9922e486d9b07f17ea6ca0bc1c4e779 Mon Sep 17 00:00:00 2001 From: mcrcortex <18544518+MCRcortex@users.noreply.github.com> Date: Fri, 9 Feb 2024 13:58:00 +1000 Subject: [PATCH] Hackfix for translucency being double applied --- .../client/core/model/ModelTextureBakery.java | 13 +++++++++++-- .../core/rendering/Gl46FarWorldRenderer.java | 16 +++++++++------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/main/java/me/cortex/voxy/client/core/model/ModelTextureBakery.java b/src/main/java/me/cortex/voxy/client/core/model/ModelTextureBakery.java index 70c7286a..db430992 100644 --- a/src/main/java/me/cortex/voxy/client/core/model/ModelTextureBakery.java +++ b/src/main/java/me/cortex/voxy/client/core/model/ModelTextureBakery.java @@ -144,9 +144,18 @@ public class ModelTextureBakery { glEnable(GL_CULL_FACE); //glDepthFunc(GL_LESS); - glBlendEquation(GL_FUNC_ADD);//TODO: reset this to the default - glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + //TODO: Find a better solution + if (renderLayer == RenderLayer.getTranslucent()) { + //Very hacky blend function to retain the effect of the applied alpha since we dont really want to apply alpha + // this is because we apply the alpha again when rendering the terrain meaning the alpha is being double applied + glBlendFuncSeparate(GL_ONE_MINUS_DST_ALPHA, GL_DST_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + } else { + glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + } + + + //glBlendFunc(GL_ONE, GL_ONE); glStencilOp(GL_KEEP, GL_KEEP, GL_INCR); glStencilFunc(GL_ALWAYS, 1, 0xFF); diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/Gl46FarWorldRenderer.java b/src/main/java/me/cortex/voxy/client/core/rendering/Gl46FarWorldRenderer.java index 947c4035..bfd50076 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/Gl46FarWorldRenderer.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/Gl46FarWorldRenderer.java @@ -24,6 +24,7 @@ import static org.lwjgl.opengl.ARBMultiDrawIndirect.glMultiDrawElementsIndirect; import static org.lwjgl.opengl.GL11.GL_TRIANGLES; import static org.lwjgl.opengl.GL11.GL_UNSIGNED_SHORT; import static org.lwjgl.opengl.GL11.glGetInteger; +import static org.lwjgl.opengl.GL14C.glBlendFuncSeparate; import static org.lwjgl.opengl.GL30.glBindVertexArray; import static org.lwjgl.opengl.GL30C.GL_R8UI; import static org.lwjgl.opengl.GL30C.GL_RED_INTEGER; @@ -172,15 +173,18 @@ public class Gl46FarWorldRenderer extends AbstractFarWorldRenderer { RenderLayer.getTranslucent().startDrawing(); glBindVertexArray(this.vao); glDisable(GL_CULL_FACE); - RenderSystem.enableBlend(); - RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SrcFactor.ONE, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA); + glEnable(GL_BLEND); + + //TODO: maybe change this so the alpha isnt applied in the same way or something?? since atm the texture bakery uses a very hacky + // blend equation to make it avoid double applying translucency + glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - int oldActiveTexture = glGetInteger(GL_ACTIVE_TEXTURE); glBindSampler(0, this.models.getSamplerId()); glActiveTexture(GL_TEXTURE0); - int oldBoundTexture = glGetInteger(GL_TEXTURE_BINDING_2D); glBindTexture(GL_TEXTURE_2D, this.models.getTextureId()); + + //RenderSystem.blendFunc(GlStateManager.SrcFactor.ONE, GlStateManager.DstFactor.ONE); this.lodShader.bind(); glDepthMask(false); @@ -192,9 +196,7 @@ public class Gl46FarWorldRenderer extends AbstractFarWorldRenderer { glBindSampler(0, 0); - GL11C.glBindTexture(GL_TEXTURE_2D, oldBoundTexture); - glActiveTexture(oldActiveTexture); - RenderSystem.disableBlend(); + glDisable(GL_BLEND); RenderLayer.getTranslucent().endDrawing(); }