This commit is contained in:
mcrcortex
2025-06-16 20:45:49 +10:00
parent 341119386a
commit b454d54a99
4 changed files with 21 additions and 36 deletions

View File

@@ -173,20 +173,22 @@ public class HierarchicalOcclusionTraverser {
viewport.section.getToAddress(ptr); ptr += 4*3;
MemoryUtil.memPutFloat(ptr, viewport.width); ptr += 4;
//MemoryUtil.memPutFloat(ptr, viewport.width); ptr += 4;
MemoryUtil.memPutInt(ptr, viewport.hiZBuffer.getPackedLevels()); ptr += 4;
viewport.innerTranslation.getToAddress(ptr); ptr += 4*3;
MemoryUtil.memPutFloat(ptr, viewport.height); ptr += 4;
//MemoryUtil.memPutFloat(ptr, viewport.height); ptr += 4;
final float screenspaceAreaDecreasingSize = VoxyConfig.CONFIG.subDivisionSize*VoxyConfig.CONFIG.subDivisionSize;
//Screen space size for descending
MemoryUtil.memPutFloat(ptr, (float) (screenspaceAreaDecreasingSize) /(viewport.width*viewport.height)); ptr += 4;
setFrustum(viewport, ptr); ptr += 4*4*6;
MemoryUtil.memPutInt(ptr, (int) (viewport.getRenderList().size()/4-1)); ptr += 4;
final float screenspaceAreaDecreasingSize = VoxyConfig.CONFIG.subDivisionSize*VoxyConfig.CONFIG.subDivisionSize;
//Screen space size for descending
MemoryUtil.memPutFloat(ptr, (float) (screenspaceAreaDecreasingSize) /(viewport.width*viewport.height)); ptr += 4;
//VisibilityId
MemoryUtil.memPutInt(ptr, this.nodeCleaner.visibilityId); ptr += 4;

View File

@@ -126,4 +126,8 @@ public class HiZBuffer {
public int getHizTextureId() {
return this.texture.id;
}
public int getPackedLevels() {
return ((Integer.numberOfTrailingZeros(this.width))<<16)|(Integer.numberOfTrailingZeros(this.height));//+1
}
}

View File

@@ -39,7 +39,6 @@ bool checkPointInView(vec4 point) {
vec3 minBB = vec3(0.0f);
vec3 maxBB = vec3(0.0f);
vec2 size = vec2(0.0f);
bool insideFrustum = false;
float screenSize = 0.0f;
@@ -119,8 +118,6 @@ void setupScreenspace(in UnpackedNode node) {
minBB = clamp(minBB, vec3(0), vec3(1));
maxBB = clamp(maxBB, vec3(0), vec3(1));
size = clamp(maxBB.xy - minBB.xy, vec2(0), vec2(1));
}
//Checks if the node is implicitly culled (outside frustum)
@@ -131,23 +128,18 @@ bool outsideFrustum() {
}
bool isCulledByHiz() {
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
ivec2 ssize = ivec2(1)<<ivec2((packedHizSize>>16)&0xFFFF,packedHizSize&0xFFFF);
vec2 size = (maxBB.xy-minBB.xy)*ssize;
float miplevel = log2(max(max(size.x, size.y),1));
miplevel = floor(miplevel)-1;
miplevel = clamp(miplevel, 0, textureQueryLevels(hizDepthSampler)-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;
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);
ssize = ssize>>ml;
ivec2 mxbb = ivec2(maxBB.xy*ssize);
ivec2 mnbb = ivec2(minBB.xy*ssize);
float pointSample = -1.0f;
//float pointSample2 = 0.0f;
for (int x = mnbb.x; x<=mxbb.x; x++) {
@@ -159,20 +151,8 @@ bool isCulledByHiz() {
}
}
//pointSample = mix(pointSample, pointSample2, pointSample<=0.000001f);
/*
float pointSample = textureLod(hizDepthSampler, maxBB.xy, miplevel).x;
pointSample = max(pointSample, textureLod(hizDepthSampler, vec2(maxBB.x, minBB.y), miplevel).x);
pointSample = max(pointSample, textureLod(hizDepthSampler, vec2(minBB.x, maxBB.y), miplevel).x);
pointSample = max(pointSample, textureLod(hizDepthSampler, minBB.xy, miplevel).x);
*/
//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));
//}
return pointSample<=testAgainst;
return pointSample<=minBB.z;
}

View File

@@ -10,12 +10,11 @@ layout(local_size_x=LOCAL_SIZE) in;//, local_size_y=1
layout(binding = SCENE_UNIFORM_BINDING, std140) uniform SceneUniform {
mat4 VP;
ivec3 camSecPos;
float screenW;
int packedHizSize;
vec3 camSubSecPos;
float screenH;
float minSSS;
Frustum frustum;
uint renderQueueMaxSize;
float minSSS;
uint frameId;
};