big progress in fixing culling
This commit is contained in:
@@ -69,12 +69,12 @@ public class HiZBuffer {
|
||||
}
|
||||
|
||||
public void buildMipChain(int srcDepthTex, int width, int height) {
|
||||
if (this.width != width || this.height != height) {
|
||||
if (this.width != Integer.highestOneBit(width*2) || this.height != Integer.highestOneBit(height*2)) {
|
||||
if (this.texture != null) {
|
||||
this.texture.free();
|
||||
this.texture = null;
|
||||
}
|
||||
this.alloc(width, height);
|
||||
this.alloc(Integer.highestOneBit(width*2), Integer.highestOneBit(height*2));
|
||||
}
|
||||
glBindVertexArray(RenderService.STATIC_VAO);
|
||||
int boundFB = GL11.glGetInteger(GL_DRAW_FRAMEBUFFER_BINDING);
|
||||
@@ -92,7 +92,7 @@ public class HiZBuffer {
|
||||
width, height, 1);
|
||||
|
||||
|
||||
glBindTextureUnit(0, this.texture.id);
|
||||
glBindTextureUnit(0, srcDepthTex);
|
||||
glBindSampler(0, this.sampler);
|
||||
glUniform1i(0, 0);
|
||||
int cw = this.width;
|
||||
@@ -106,6 +106,9 @@ public class HiZBuffer {
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
glTextureBarrier();
|
||||
glMemoryBarrier(GL_FRAMEBUFFER_BARRIER_BIT|GL_TEXTURE_FETCH_BARRIER_BIT);
|
||||
if (i==0) {
|
||||
glBindTextureUnit(0, this.texture.id);
|
||||
}
|
||||
}
|
||||
glTextureParameteri(this.texture.id, GL_TEXTURE_BASE_LEVEL, 0);
|
||||
glTextureParameteri(this.texture.id, GL_TEXTURE_MAX_LEVEL, 1000);//TODO: CHECK IF ITS -1 or -0
|
||||
|
||||
@@ -117,6 +117,9 @@ void setupScreenspace(in UnpackedNode node) {
|
||||
minBB = min(min(min(p000, p100), min(p001, p101)), min(min(p010, p110), min(p011, p111)));
|
||||
maxBB = max(max(max(p000, p100), max(p001, p101)), max(max(p010, p110), max(p011, p111)));
|
||||
|
||||
minBB = clamp(minBB, vec3(0), vec3(1));
|
||||
maxBB = clamp(maxBB, vec3(0), vec3(1));
|
||||
|
||||
size = clamp(maxBB.xy - minBB.xy, vec2(0), vec2(1));
|
||||
}
|
||||
|
||||
@@ -128,18 +131,14 @@ bool outsideFrustum() {
|
||||
}
|
||||
|
||||
bool isCulledByHiz() {
|
||||
vec2 ssize = size * vec2(screenW, screenH);
|
||||
float miplevel = log2(max(max(ssize.x, ssize.y),1));
|
||||
vec2 asize = size * vec2(screenW, screenH);
|
||||
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
|
||||
|
||||
|
||||
miplevel = floor(miplevel)-1;
|
||||
miplevel = clamp(miplevel, 0, 20);
|
||||
|
||||
if (miplevel >= 10.0f) {//Level 9 or 10// TODO: FIX THIS JANK SHIT
|
||||
//return false;
|
||||
}
|
||||
miplevel = clamp(miplevel, 0, textureQueryLevels(hizDepthSampler)-1);
|
||||
|
||||
vec2 midpoint = (maxBB.xy + minBB.xy)*0.5f;
|
||||
|
||||
@@ -147,11 +146,11 @@ bool isCulledByHiz() {
|
||||
//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 = int(miplevel);
|
||||
ivec2 msize = textureSize(hizDepthSampler, ml);
|
||||
ivec2 mxbb = clamp(ivec2(ceil(maxBB.xy*msize)), ivec2(0), msize);
|
||||
ivec2 mnbb = clamp(ivec2(floor(minBB.xy*msize)), ivec2(0), msize);
|
||||
float pointSample = 0.0f;
|
||||
int ml = 4;//int(miplevel);
|
||||
ivec2 msize = ivec2(128,64);//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;
|
||||
//float pointSample2 = 0.0f;
|
||||
for (int x = mnbb.x; x<=mxbb.x; x++) {
|
||||
for (int y = mnbb.y; y<=mxbb.y; y++) {
|
||||
@@ -174,7 +173,11 @@ 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));
|
||||
//}
|
||||
return pointSample<=testAgainst;
|
||||
if (pointSample==0.0f) {
|
||||
//return false;
|
||||
}
|
||||
|
||||
return pointSample<testAgainst;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user