slightly improve hiz

This commit is contained in:
mcrcortex
2025-04-10 20:53:51 +10:00
parent 47592b4e6d
commit b7713815a4
2 changed files with 9 additions and 8 deletions

View File

@@ -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);

View File

@@ -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;
}