From 560ba41fa5f422d7c1008e8ed2e2b273850ab689 Mon Sep 17 00:00:00 2001 From: MCRcortex <18544518+MCRcortex@users.noreply.github.com> Date: Mon, 10 Nov 2025 11:23:00 +1000 Subject: [PATCH] attempted fix for incorrect sampling of depth buffer stuffs --- .../cortex/voxy/client/core/AbstractRenderPipeline.java | 9 ++++++++- .../cortex/voxy/client/core/IrisVoxyRenderPipeline.java | 2 +- .../resources/assets/voxy/shaders/post/depth_copy.frag | 3 ++- 3 files changed, 11 insertions(+), 3 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 74e5f981..7b63e779 100644 --- a/src/main/java/me/cortex/voxy/client/core/AbstractRenderPipeline.java +++ b/src/main/java/me/cortex/voxy/client/core/AbstractRenderPipeline.java @@ -53,6 +53,11 @@ public abstract class AbstractRenderPipeline extends TrackedObject { private final FullscreenBlit depthMaskBlit = new FullscreenBlit("voxy:post/fullscreen2.vert", "voxy:post/noop.frag"); private final FullscreenBlit depthSetBlit = new FullscreenBlit("voxy:post/fullscreen2.vert", "voxy:post/depth0.frag"); private final FullscreenBlit depthCopy = new FullscreenBlit("voxy:post/fullscreen2.vert", "voxy:post/depth_copy.frag"); + private static final int DEPTH_SAMPLER = glGenSamplers(); + static { + glSamplerParameteri(DEPTH_SAMPLER, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glSamplerParameteri(DEPTH_SAMPLER, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + } protected AbstractRenderPipeline(AsyncNodeManager nodeManager, NodeCleaner nodeCleaner, HierarchicalOcclusionTraverser traversal, BooleanSupplier frexSupplier) { this.frexStillHasWork = frexSupplier; @@ -109,9 +114,11 @@ public abstract class AbstractRenderPipeline extends TrackedObject { // the mismatched formats in this case is the d32 to d24s8 glBindFramebuffer(GL30.GL_FRAMEBUFFER, targetFb); + this.depthCopy.bind(); int depthTexture = glGetNamedFramebufferAttachmentParameteri(sourceFrameBuffer, GL_DEPTH_ATTACHMENT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME); glBindTextureUnit(0, depthTexture); - + glBindSampler(0, DEPTH_SAMPLER); + glUniform2f(1,((float)width)/srcWidth, ((float)height)/srcHeight); glColorMask(false,false,false,false); this.depthCopy.blit(); diff --git a/src/main/java/me/cortex/voxy/client/core/IrisVoxyRenderPipeline.java b/src/main/java/me/cortex/voxy/client/core/IrisVoxyRenderPipeline.java index 3a267c22..443d75d2 100644 --- a/src/main/java/me/cortex/voxy/client/core/IrisVoxyRenderPipeline.java +++ b/src/main/java/me/cortex/voxy/client/core/IrisVoxyRenderPipeline.java @@ -113,7 +113,7 @@ public class IrisVoxyRenderPipeline extends AbstractRenderPipeline { glClear(GL_COLOR_BUFFER_BIT); } - if (this.data.useViewportDims) { + if (!this.data.useViewportDims) { srcWidth = viewport.width; srcHeight = viewport.height; } diff --git a/src/main/resources/assets/voxy/shaders/post/depth_copy.frag b/src/main/resources/assets/voxy/shaders/post/depth_copy.frag index c43f07a0..56ab97b8 100644 --- a/src/main/resources/assets/voxy/shaders/post/depth_copy.frag +++ b/src/main/resources/assets/voxy/shaders/post/depth_copy.frag @@ -1,8 +1,9 @@ #version 330 core layout(binding = 0) uniform sampler2D depthTex; +layout(location = 1) uniform vec2 scaleFactor; in vec2 UV; void main() { - gl_FragDepth = texture(depthTex, UV).r; + gl_FragDepth = texture(depthTex, UV*scaleFactor).r; } \ No newline at end of file