From f53a81099e43815ecd677ef53b1091fb45bbf8f1 Mon Sep 17 00:00:00 2001 From: mcrcortex <18544518+MCRcortex@users.noreply.github.com> Date: Tue, 24 Sep 2024 00:11:10 +1000 Subject: [PATCH] Fixed culling? --- .../voxy/client/core/rendering/RenderService.java | 5 +++-- .../client/core/rendering/post/PostProcessing.java | 14 +++++++++----- .../voxy/client/core/rendering/util/HiZBuffer.java | 3 +++ .../voxy/shaders/lod/hierarchical/screenspace.glsl | 11 ++++++----- .../shaders/lod/hierarchical/traversal_dev.comp | 8 ++++---- .../resources/assets/voxy/shaders/post/depth0.frag | 7 +++++++ 6 files changed, 32 insertions(+), 16 deletions(-) create mode 100644 src/main/resources/assets/voxy/shaders/post/depth0.frag diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/RenderService.java b/src/main/java/me/cortex/voxy/client/core/rendering/RenderService.java index ab345d11..68e8081b 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/RenderService.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/RenderService.java @@ -77,8 +77,9 @@ public class RenderService, J extends Vi world.getMapper().setBiomeCallback(this.modelService::addBiome); //this.nodeManager.insertTopLevelNode(WorldEngine.getWorldSectionId(0, 0,0,0)); - //this.nodeManager.insertTopLevelNode(WorldEngine.getWorldSectionId(4, 0,0,0)); + this.nodeManager.insertTopLevelNode(WorldEngine.getWorldSectionId(4, 0,0,0)); + /* final int H_WIDTH = 10; for (int x = -H_WIDTH; x <= H_WIDTH; x++) { for (int y = 0; y <= 0; y++) { @@ -86,7 +87,7 @@ public class RenderService, J extends Vi this.nodeManager.insertTopLevelNode(WorldEngine.getWorldSectionId(4, x, y, z)); } } - } + }*/ } public void setup(Camera camera) { diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/post/PostProcessing.java b/src/main/java/me/cortex/voxy/client/core/rendering/post/PostProcessing.java index 3c777b87..91b92248 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/post/PostProcessing.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/post/PostProcessing.java @@ -32,6 +32,7 @@ public class PostProcessing { private GlTexture colourSSAO; private GlTexture depthStencil; private boolean didSSAO; + private final FullscreenBlit setDepth0 = new FullscreenBlit("voxy:post/depth0.frag"); private final FullscreenBlit emptyBlit = new FullscreenBlit("voxy:post/noop.frag"); //private final FullscreenBlit blitTexture = new FullscreenBlit("voxy:post/blit_texture_cutout.frag"); private final FullscreenBlit blitTexture = new FullscreenBlit("voxy:post/blit_texture_depth_cutout.frag"); @@ -93,6 +94,7 @@ public class PostProcessing { if (this.colour != null) this.colour.free(); if (this.depthStencil != null) this.depthStencil.free(); this.emptyBlit.delete(); + this.setDepth0.delete(); this.blitTexture.delete(); this.ssaoComp.free(); } @@ -121,14 +123,16 @@ public class PostProcessing { this.emptyBlit.blit(); glColorMask(true,true,true,true); glDepthMask(true); + //glDisable(GL_DEPTH_TEST); + + + glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); + //Set depth to 0 w.r.t mask + glStencilFunc(GL_EQUAL, 0, 0xFF); + this.setDepth0.blit(); glDisable(GL_DEPTH_TEST); - //Clear the depth buffer we copied cause else it will interfear with results (not really i think idk) - glClear(GL_DEPTH_BUFFER_BIT); - - //Make voxy terrain render only where there isnt mc terrain - glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); glStencilFunc(GL_EQUAL, 1, 0xFF); 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 aac382c3..7d17d2fb 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 @@ -74,6 +74,8 @@ public class HiZBuffer { glBindFramebuffer(GL_FRAMEBUFFER, this.fb.id); glDepthFunc(GL_ALWAYS); + glDepthMask(true); + glEnable(GL_DEPTH_TEST); //System.err.println("SRC: " + GlTexture.getRawTextureType(srcDepthTex) + " DST: " + this.texture.id); @@ -100,6 +102,7 @@ public class HiZBuffer { glTextureParameteri(this.texture.id, GL_TEXTURE_MAX_LEVEL, this.levels-1);//TODO: CHECK IF ITS -1 or -0 glDepthFunc(GL_LEQUAL); + glDisable(GL_DEPTH_TEST); glBindFramebuffer(GL_FRAMEBUFFER, boundFB); glViewport(0, 0, width, height); glBindVertexArray(0); 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 dbd155e6..776352ab 100644 --- a/src/main/resources/assets/voxy/shaders/lod/hierarchical/screenspace.glsl +++ b/src/main/resources/assets/voxy/shaders/lod/hierarchical/screenspace.glsl @@ -21,6 +21,7 @@ vec3 minBB; vec3 maxBB; vec2 size; +uint lod; //Sets up screenspace with the given node id, returns true on success false on failure/should not continue //Accesses data that is setup in the main traversal and is just shared to here @@ -34,7 +35,7 @@ void setupScreenspace(in UnpackedNode node) { vec3 point = VP*(((transform.transform*vec4((node.pos< 0.0001f; + // printf("HiZ sample point culled: (%f,%f)@%f against %f", midpoint.x, midpoint.y, miplevel, minBB.z); + return textureLod(hizDepthSampler, vec3(midpoint, minBB.z), miplevel) < 0.0001f; } //Returns if we should decend into its children or not bool shouldDecend() { - printf("Screen area %f: %f, %f", (size.x*size.y*float(screenW)*float(screenH)), float(size.x), float(size.y)); + //printf("Screen area %f: %f, %f", (size.x*size.y*float(screenW)*float(screenH)), float(size.x), float(size.y)); return (size.x*size.y*screenW*screenH) > minSSS; } \ No newline at end of file diff --git a/src/main/resources/assets/voxy/shaders/lod/hierarchical/traversal_dev.comp b/src/main/resources/assets/voxy/shaders/lod/hierarchical/traversal_dev.comp index 5c9cb33a..e5635e16 100644 --- a/src/main/resources/assets/voxy/shaders/lod/hierarchical/traversal_dev.comp +++ b/src/main/resources/assets/voxy/shaders/lod/hierarchical/traversal_dev.comp @@ -23,7 +23,7 @@ SIMPLE_QUEUE(uvec2, requestQueue, REQUEST_QUEUE_BINDING); SIMPLE_QUEUE(uint, renderQueue, RENDER_QUEUE_BINDING); void addRequest(inout UnpackedNode node) { - printf("Put node decend request"); + //printf("Put node decend request"); if (!hasRequested(node)) { if (requestQueueIndex.x < REQUEST_QUEUE_SIZE) { uint atomRes = atomicAdd(requestQueueIndex.x, 1); @@ -59,17 +59,17 @@ void enqueueSelfForRender(in UnpackedNode node) { void traverse(in UnpackedNode node) { //Compute screenspace setupScreenspace(node); - debugDumpNode(node); + //debugDumpNode(node); if (outsideFrustum() || isCulledByHiz()) { - printf("culled"); + //printf("culled"); } else { //It is visible, TODO: maybe do a more detailed hiz test? (or make it so that ) //Only decend if not a root node if (node.lodLevel!=0 && shouldDecend()) { if (hasChildren(node)) { - printf("A"); + //printf("A"); enqueueChildren(node); } else { printf("B"); diff --git a/src/main/resources/assets/voxy/shaders/post/depth0.frag b/src/main/resources/assets/voxy/shaders/post/depth0.frag new file mode 100644 index 00000000..8ca9e2c9 --- /dev/null +++ b/src/main/resources/assets/voxy/shaders/post/depth0.frag @@ -0,0 +1,7 @@ +#version 330 core +out vec4 colour; +in vec2 UV; +void main() { + colour = vec4(1,0,1,1); + gl_FragDepth = 0.0f; +} \ No newline at end of file