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 4616dfdd..0cb5b79d 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 @@ -69,12 +69,12 @@ public class HiZBuffer { } public void buildMipChain(int srcDepthTex, int width, int height) { - if (this.width != Integer.highestOneBit(width*2) || this.height != Integer.highestOneBit(height*2)) { + if (this.width != Integer.highestOneBit(width) || this.height != Integer.highestOneBit(height)) { if (this.texture != null) { this.texture.free(); this.texture = null; } - this.alloc(Integer.highestOneBit(width*2), Integer.highestOneBit(height*2)); + this.alloc(Integer.highestOneBit(width), Integer.highestOneBit(height)); } glBindVertexArray(RenderService.STATIC_VAO); int boundFB = GL11.glGetInteger(GL_DRAW_FRAMEBUFFER_BINDING); @@ -86,26 +86,19 @@ public class HiZBuffer { glEnable(GL_DEPTH_TEST); - //System.err.println("SRC: " + GlTexture.getRawTextureType(srcDepthTex) + " DST: " + this.texture.id); - glCopyImageSubData(srcDepthTex, GL_TEXTURE_2D, 0,0,0,0, - this.texture.id, GL_TEXTURE_2D, 0,0,0,0, - width, height, 1); - - glBindTextureUnit(0, srcDepthTex); glBindSampler(0, this.sampler); 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 = Math.max(cw/2, 1); ch = Math.max(ch/2, 1); glViewport(0, 0, cw, ch); + for (int i = 0; i < this.levels; i++) { + this.fb.bind(GL_DEPTH_ATTACHMENT, this.texture, i); + glViewport(0, 0, cw, ch); cw = Math.max(cw/2, 1); ch = Math.max(ch/2, 1); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); glTextureBarrier(); glMemoryBarrier(GL_FRAMEBUFFER_BARRIER_BIT|GL_TEXTURE_FETCH_BARRIER_BIT); + glTextureParameteri(this.texture.id, GL_TEXTURE_BASE_LEVEL, i); + glTextureParameteri(this.texture.id, GL_TEXTURE_MAX_LEVEL, i); if (i==0) { glBindTextureUnit(0, this.texture.id); } 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 3e8acb38..167e4db1 100644 --- a/src/main/resources/assets/voxy/shaders/lod/hierarchical/screenspace.glsl +++ b/src/main/resources/assets/voxy/shaders/lod/hierarchical/screenspace.glsl @@ -131,7 +131,7 @@ bool outsideFrustum() { } bool isCulledByHiz() { - vec2 asize = size * vec2(screenW, screenH); + vec2 asize = size * vec2(1024, 512); float miplevel = log2(max(max(asize.x, asize.y),1)); //TODO: make a path for if the miplevel would result in the textureSampler sampling a size of 1 @@ -140,14 +140,12 @@ bool isCulledByHiz() { miplevel = floor(miplevel)-1; miplevel = clamp(miplevel, 0, textureQueryLevels(hizDepthSampler)-1); - vec2 midpoint = (maxBB.xy + minBB.xy)*0.5f; - 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; - int ml = 4;//int(miplevel); - ivec2 msize = ivec2(128,64);//textureSize(hizDepthSampler, ml);//max(ivec2(1),ivec2(screenW, screenH)>>ml); + int ml = int(miplevel); + ivec2 msize = textureSize(hizDepthSampler, ml);//max(ivec2(1),ivec2(screenW, screenH)>>ml); ivec2 mxbb = clamp(ivec2(maxBB.xy*msize), ivec2(0), msize); ivec2 mnbb = clamp(ivec2(minBB.xy*msize), ivec2(0), msize); float pointSample = -1.0f; @@ -173,11 +171,8 @@ bool isCulledByHiz() { //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)); //} - if (pointSample==0.0f) { - //return false; - } - return pointSample