From 07bb8e04754512db25b14311c85340bf575826a6 Mon Sep 17 00:00:00 2001 From: mcrcortex <18544518+MCRcortex@users.noreply.github.com> Date: Tue, 22 Apr 2025 09:20:45 +1000 Subject: [PATCH] More work on fixing remaining hiz issues --- .../voxy/common/thread/ServiceThreadPool.java | 10 ++++++++ .../shaders/lod/hierarchical/screenspace.glsl | 23 +++++++++++-------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/main/java/me/cortex/voxy/common/thread/ServiceThreadPool.java b/src/main/java/me/cortex/voxy/common/thread/ServiceThreadPool.java index 39f66e06..aadc3ed4 100644 --- a/src/main/java/me/cortex/voxy/common/thread/ServiceThreadPool.java +++ b/src/main/java/me/cortex/voxy/common/thread/ServiceThreadPool.java @@ -3,6 +3,9 @@ package me.cortex.voxy.common.thread; import me.cortex.voxy.common.Logger; import me.cortex.voxy.common.util.Pair; +import java.lang.invoke.VarHandle; +import java.lang.management.ManagementFactory; +import java.lang.management.ThreadMXBean; import java.util.Arrays; import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; @@ -14,6 +17,12 @@ import java.util.function.Supplier; //TODO: could also probably replace all of this with just VirtualThreads and a Executors.newThreadPerTaskExecutor with a fixed thread pool // it is probably better anyway public class ServiceThreadPool { + /* + private static final ThreadMXBean THREAD_BEAN = ManagementFactory.getThreadMXBean(); + static { + THREAD_BEAN.setThreadCpuTimeEnabled(true); + }*/ + private volatile boolean running = true; private Thread[] workers = new Thread[0]; private final Semaphore jobCounter = new Semaphore(0); @@ -189,6 +198,7 @@ public class ServiceThreadPool { //Didnt consume the job, find a new job continue; } + //Consumed a job from the service, decrease weight by the amount if (this.totalJobWeight.addAndGet(-service.weightPerJob)<0) { throw new IllegalStateException("Total job weight is negative"); 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 f597acde..2d89eb00 100644 --- a/src/main/resources/assets/voxy/shaders/lod/hierarchical/screenspace.glsl +++ b/src/main/resources/assets/voxy/shaders/lod/hierarchical/screenspace.glsl @@ -128,22 +128,25 @@ bool outsideFrustum() { } bool isCulledByHiz() { - //if (minBB.z < 0) {//Minpoint is behind the camera, its always going to pass - // return false;//Just cull it for now cause other culling isnt working, TODO: FIXME - //} + if (any(lessThan(minBB.xy, vec2(0)) && lessThan(vec2(1), maxBB.xy))) { + return false; + } vec2 ssize = size * vec2(screenW, screenH); float miplevel = log2(max(max(ssize.x, ssize.y),1)); - miplevel = ceil(miplevel); + miplevel = ceil(miplevel); //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)); - vec2 midpoint2 = midpoint; - //the *2.0f-1.0f converts from the 0->1 range to -1->1 range that depth is in - bool culled = textureLod(hizDepthSampler, vec3(midpoint2, minBB.z*2.0f-1.0f), miplevel) < 0.0001f;//*0.5f+0.5f + //midpoint = clamp(midpoint, vec2(0), vec2(1)); + + float testAgainst = minBB.z; + //the *2.0f-1.0f converts from the 0->1 range to -1->1 range that depth is in (not having this causes tighter bounds, but causes culling issues in caves) + testAgainst = testAgainst*2.0f-1.0f; + + bool culled = textureLod(hizDepthSampler, vec3(midpoint, testAgainst), miplevel) < 0.0001f; + //printf("HiZ sample point: (%f,%f)@%f against %f", midpoint.x, midpoint.y, miplevel, minBB.z); //if ((culled) && node22.lodLevel == 0) { // printf("HiZ sample point: (%f,%f)@%f against %f, value %f", midpoint.x, midpoint.y, miplevel, minBB.z, textureLod(hizDepthSampler, vec3(0.5f,0.5f, 0.000000001f), 9.0f));