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

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