From b7713815a4efafc8fe141de09e875a281a25b3b9 Mon Sep 17 00:00:00 2001 From: mcrcortex <18544518+MCRcortex@users.noreply.github.com> Date: Thu, 10 Apr 2025 20:53:51 +1000 Subject: [PATCH] slightly improve hiz --- .../voxy/client/core/rendering/util/HiZBuffer.java | 9 +++++---- .../voxy/shaders/lod/hierarchical/screenspace.glsl | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/util/HiZBuffer.java b/src/main/java/me/cortex/voxy/client/core/rendering/util/HiZBuffer.java index 4556a8db..adab295a 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/util/HiZBuffer.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/util/HiZBuffer.java @@ -49,13 +49,13 @@ public class HiZBuffer { //GL_DEPTH_COMPONENT32F //Cant use this as it does not match the depth format of the provided depth buffer this.texture = new GlTexture().store(this.type, this.levels, width, height).name("HiZ"); - glTextureParameteri(this.texture.id, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTextureParameteri(this.texture.id, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); glTextureParameteri(this.texture.id, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTextureParameteri(this.texture.id, GL_TEXTURE_COMPARE_MODE, GL_NONE); glTextureParameteri(this.texture.id, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTextureParameteri(this.texture.id, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glSamplerParameteri(this.sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glSamplerParameteri(this.sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); glSamplerParameteri(this.sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glSamplerParameteri(this.sampler, GL_TEXTURE_COMPARE_MODE, GL_NONE); glSamplerParameteri(this.sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); @@ -95,17 +95,18 @@ public class HiZBuffer { glUniform1i(0, 0); int cw = this.width; int ch = this.height; + glViewport(0, 0, cw, ch); for (int i = 0; i < this.levels-1; i++) { glTextureParameteri(this.texture.id, GL_TEXTURE_BASE_LEVEL, i); glTextureParameteri(this.texture.id, GL_TEXTURE_MAX_LEVEL, i); this.fb.bind(GL_DEPTH_ATTACHMENT, this.texture, i+1); - cw /= 2; ch /= 2; glViewport(0, 0, cw, ch); + cw = Math.max(cw/2, 2); ch = Math.max(ch/2, 2); glViewport(0, 0, cw, ch); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); glTextureBarrier(); glMemoryBarrier(GL_FRAMEBUFFER_BARRIER_BIT); } glTextureParameteri(this.texture.id, GL_TEXTURE_BASE_LEVEL, 0); - glTextureParameteri(this.texture.id, GL_TEXTURE_MAX_LEVEL, this.levels-1);//TODO: CHECK IF ITS -1 or -0 + glTextureParameteri(this.texture.id, GL_TEXTURE_MAX_LEVEL, 1000);//TODO: CHECK IF ITS -1 or -0 glDepthFunc(GL_LEQUAL); glDisable(GL_DEPTH_TEST); diff --git a/src/main/resources/assets/voxy/shaders/lod/hierarchical/screenspace.glsl b/src/main/resources/assets/voxy/shaders/lod/hierarchical/screenspace.glsl index 8f3d6995..f60bf831 100644 --- a/src/main/resources/assets/voxy/shaders/lod/hierarchical/screenspace.glsl +++ b/src/main/resources/assets/voxy/shaders/lod/hierarchical/screenspace.glsl @@ -84,16 +84,16 @@ bool isCulledByHiz() { vec2 ssize = size * vec2(screenW, screenH); float miplevel = ceil(log2(max(max(ssize.x, ssize.y),1))); - miplevel = clamp(miplevel, 0, 20); + //miplevel = clamp(miplevel, 0, 20); vec2 midpoint = (maxBB.xy + minBB.xy)*0.5f; //TODO: maybe get rid of clamp //Todo: replace with some rasterization, e.g. especially for request back to cpu vec2 midpoint2 = clamp(midpoint, vec2(0), vec2(1)); bool culled = textureLod(hizDepthSampler, vec3(midpoint2, minBB.z), miplevel) < 0.0001f; //printf("HiZ sample point: (%f,%f)@%f against %f", midpoint.x, midpoint.y, miplevel, minBB.z); - if (culled && node22.lodLevel != 4) { - printf("HiZ sample point: (%f,%f)@%f against %f", midpoint.x, midpoint.y, miplevel, minBB.z); - } + //if (culled && node22.lodLevel != 4) { + // printf("HiZ sample point: (%f,%f)@%f against %f, value %f", midpoint.x, midpoint.y, miplevel, minBB.z, textureLod(hizDepthSampler, vec3(0.0f,0.0f, 0.000001f), 20)); + //} return culled; }