From 0ed453fe1d779eafdf168e7ed7d355460fca9114 Mon Sep 17 00:00:00 2001 From: mcrcortex <18544518+MCRcortex@users.noreply.github.com> Date: Thu, 28 Aug 2025 08:47:35 +1000 Subject: [PATCH] Fix issues with mesa stencil, added self culling option, --- .../voxy/client/core/AbstractRenderPipeline.java | 10 +++++++--- .../me/cortex/voxy/client/core/model/ModelFactory.java | 6 ------ .../voxy/client/core/model/bakery/GlViewCapture.java | 2 ++ .../core/rendering/building/RenderDataFactory.java | 7 ++++--- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/main/java/me/cortex/voxy/client/core/AbstractRenderPipeline.java b/src/main/java/me/cortex/voxy/client/core/AbstractRenderPipeline.java index 17d4a6d8..e8e5332a 100644 --- a/src/main/java/me/cortex/voxy/client/core/AbstractRenderPipeline.java +++ b/src/main/java/me/cortex/voxy/client/core/AbstractRenderPipeline.java @@ -2,6 +2,7 @@ package me.cortex.voxy.client.core; import me.cortex.voxy.client.RenderStatistics; import me.cortex.voxy.client.TimingStatistics; +import me.cortex.voxy.client.core.gl.Capabilities; import me.cortex.voxy.client.core.model.ModelBakerySubsystem; import me.cortex.voxy.client.core.rendering.Viewport; import me.cortex.voxy.client.core.rendering.hierachical.AsyncNodeManager; @@ -93,13 +94,16 @@ public abstract class AbstractRenderPipeline extends TrackedObject { } protected void initDepthStencil(int sourceFrameBuffer, int targetFb, int width, int height) { - glClearNamedFramebufferfi(targetFb, GL_DEPTH_STENCIL, 0, 1.0f, 1); glBlitNamedFramebuffer(sourceFrameBuffer, targetFb, 0,0, width, height, 0,0, width, height, GL_DEPTH_BUFFER_BIT, GL_NEAREST); glBindFramebuffer(GL30.GL_FRAMEBUFFER, targetFb); - //GL11C.glClearStencil(1); - //GL11C.glClear(GL_STENCIL_BUFFER_BIT); + + /* + if (Capabilities.INSTANCE.isMesa){ + glClearStencil(1); + glClear(GL_STENCIL_BUFFER_BIT); + }*/ //This whole thing is hell, we basicly want to create a mask stenicel/depth mask specificiclly // in theory we could do this in a single pass by passing in the depth buffer from the sourceFrambuffer diff --git a/src/main/java/me/cortex/voxy/client/core/model/ModelFactory.java b/src/main/java/me/cortex/voxy/client/core/model/ModelFactory.java index 6048f2a5..786d21eb 100644 --- a/src/main/java/me/cortex/voxy/client/core/model/ModelFactory.java +++ b/src/main/java/me/cortex/voxy/client/core/model/ModelFactory.java @@ -273,12 +273,6 @@ public class ModelFactory { int checkMode = blockRenderLayer==BlockRenderLayer.SOLID?TextureUtils.WRITE_CHECK_STENCIL:TextureUtils.WRITE_CHECK_ALPHA; - if (Capabilities.INSTANCE.isMesa) { - //Mesa does not work with GL_DEPTH_STENCIL_TEXTURE_MODE GL_STENCIL_INDEX - // the sampler in the compute shader always reads zero even when stencil is guarenteed not to be zero - // (e.g. clearing with stencil 10) - checkMode = TextureUtils.WRITE_CHECK_ALPHA; - } var colourProvider = getColourProvider(blockState.getBlock()); diff --git a/src/main/java/me/cortex/voxy/client/core/model/bakery/GlViewCapture.java b/src/main/java/me/cortex/voxy/client/core/model/bakery/GlViewCapture.java index dabd36a4..de3fc3b3 100644 --- a/src/main/java/me/cortex/voxy/client/core/model/bakery/GlViewCapture.java +++ b/src/main/java/me/cortex/voxy/client/core/model/bakery/GlViewCapture.java @@ -42,6 +42,8 @@ public class GlViewCapture { this.framebuffer = new GlFramebuffer().bind(GL_COLOR_ATTACHMENT0, this.colourTex).bind(GL_DEPTH_STENCIL_ATTACHMENT, this.depthTex).verify().name("ModelFramebuffer"); glTextureParameteri(this.stencilTex.id, GL_DEPTH_STENCIL_TEXTURE_MODE, GL_STENCIL_INDEX); + glTextureParameteri(this.stencilTex.id, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTextureParameteri(this.stencilTex.id, GL_TEXTURE_MIN_FILTER, GL_NEAREST); this.copyOutShader = Shader.makeAuto() .define("WIDTH", width) diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/building/RenderDataFactory.java b/src/main/java/me/cortex/voxy/client/core/rendering/building/RenderDataFactory.java index 0d60e15f..c667cd93 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/building/RenderDataFactory.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/building/RenderDataFactory.java @@ -18,6 +18,7 @@ import java.util.Arrays; public class RenderDataFactory { private static final boolean CHECK_NEIGHBOR_FACE_OCCLUSION = true; + private static final boolean DISABLE_CULL_SAME_OCCLUDES = true; private static final boolean VERIFY_MESHING = VoxyCommon.isVerificationFlagOn("verifyMeshing"); @@ -340,7 +341,7 @@ public class RenderDataFactory { private static final long LM = (0xFFL<<55); private static boolean shouldMeshNonOpaqueBlockFace(int face, long quad, long meta, long neighborQuad, long neighborMeta) { - if (((quad^neighborQuad)&(0xFFFFL<<26))==0) return false;//This is a hack, if the neigbor and this are the same, dont mesh the face + if (((quad^neighborQuad)&(0xFFFFL<<26))==0 && ((!DISABLE_CULL_SAME_OCCLUDES) || ModelQueries.faceOccludes(meta, face))) return false;//This is a hack, if the neigbor and this are the same, dont mesh the face// TODO: FIXME if (!ModelQueries.faceExists(meta, face)) return false;//Dont mesh if no face //if (ModelQueries.faceCanBeOccluded(meta, face)) //TODO: maybe enable this if (ModelQueries.faceOccludes(neighborMeta, face^1)) return false; @@ -752,7 +753,7 @@ public class RenderDataFactory { //Check and test if can cull W.R.T neighbor if (Mapper.getBlockId(neighborId) != 0) {//Not air int modelId = this.modelMan.getModelId(Mapper.getBlockId(neighborId)); - if (modelId == ((A>>26)&0xFFFF)) { + if (modelId == ((A>>26)&0xFFFF)) {//TODO: FIXME, this technically isnt correct as need to check self occulsion, thinks? fail = true; } else { long meta = this.modelMan.getModelMetadataFromClientId(modelId); @@ -766,7 +767,7 @@ public class RenderDataFactory { long nA = this.sectionData[(idx+skipAmount) * 2]; long nB = this.sectionData[(idx+skipAmount) * 2 + 1]; boolean failB = false; - if ((nA&(0xFFFFL<<26)) == (A&(0xFFFFL<<26))) { + if ((nA&(0xFFFFL<<26)) == (A&(0xFFFFL<<26))) {//TODO: FIXME, this technically isnt correct as need to check self occulsion, thinks? failB = true; } else { if (ModelQueries.faceOccludes(nB, (axis << 1) | (side))) {