Tweeks to frustum issues with how did things
This commit is contained in:
@@ -20,10 +20,23 @@ layout(binding = HIZ_BINDING) uniform sampler2DShadow hizDepthSampler;
|
|||||||
vec3 minBB;
|
vec3 minBB;
|
||||||
vec3 maxBB;
|
vec3 maxBB;
|
||||||
vec2 size;
|
vec2 size;
|
||||||
|
bool insideFrustum;
|
||||||
|
|
||||||
uint BASE_IDX = gl_LocalInvocationID.x*8;
|
uint BASE_IDX = gl_LocalInvocationID.x*8;
|
||||||
shared vec2[LOCAL_SIZE*8] screenPoints;
|
shared vec2[LOCAL_SIZE*8] screenPoints;
|
||||||
|
|
||||||
|
bool within(vec2 a, vec2 b, vec2 c) {
|
||||||
|
return all(lessThan(a,b)) && all(lessThan(b, c));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool within(vec3 a, vec3 b, vec3 c) {
|
||||||
|
return all(lessThan(a,b)) && all(lessThan(b, c));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool within(float a, float b, float c) {
|
||||||
|
return a<b && b<c;
|
||||||
|
}
|
||||||
|
|
||||||
UnpackedNode node22;
|
UnpackedNode node22;
|
||||||
//Sets up screenspace with the given node id, returns true on success false on failure/should not continue
|
//Sets up screenspace with the given node id, returns true on success false on failure/should not continue
|
||||||
//Accesses data that is setup in the main traversal and is just shared to here
|
//Accesses data that is setup in the main traversal and is just shared to here
|
||||||
@@ -38,25 +51,33 @@ void setupScreenspace(in UnpackedNode node) {
|
|||||||
+ (transform.worldPos.xyz-camChunkPos))-camSubChunk);
|
+ (transform.worldPos.xyz-camChunkPos))-camSubChunk);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
vec4 base = VP*vec4(vec3(((node.pos<<node.lodLevel)-camSecPos)<<5)-camSubSecPos, 1);
|
|
||||||
|
|
||||||
//TODO: AABB SIZES not just a max cube
|
//TODO: AABB SIZES not just a max cube
|
||||||
|
|
||||||
//vec3 minPos = minSize + basePos;
|
//vec3 minPos = minSize + basePos;
|
||||||
//vec3 maxPos = maxSize + basePos;
|
//vec3 maxPos = maxSize + basePos;
|
||||||
|
|
||||||
minBB = base.xyz/base.w;
|
minBB = vec3(9999f);
|
||||||
maxBB = minBB;
|
maxBB = vec3(-9999f);
|
||||||
|
insideFrustum = false;
|
||||||
|
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
vec3 ppoint = vec3((i&1)!=0,(i&2)!=0,(i&4)!=0)*(32<<node.lodLevel);
|
||||||
|
|
||||||
|
ppoint += vec3(((node.pos<<node.lodLevel)-camSecPos)<<5)-camSubSecPos;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
screenPoints[BASE_IDX+0] = minBB.xy*0.5f+0.5f;
|
|
||||||
for (int i = 1; i < 8; i++) {
|
|
||||||
//NOTE!: cant this be precomputed and put in an array?? in the scene uniform??
|
//NOTE!: cant this be precomputed and put in an array?? in the scene uniform??
|
||||||
vec4 pPoint = (VP*vec4(vec3((i&1)!=0,(i&2)!=0,(i&4)!=0)*(32<<node.lodLevel),1));//Size of section is 32x32x32 (need to change it to a bounding box in the future)
|
vec4 pPoint = VP*vec4(ppoint, 1);//Size of section is 32x32x32 (need to change it to a bounding box in the future)
|
||||||
pPoint += base;
|
|
||||||
|
bool pointInside = within(vec3(-pPoint.w,-pPoint.w,0.0f), pPoint.xyz, vec3(pPoint.w));
|
||||||
|
insideFrustum = insideFrustum || pointInside;
|
||||||
|
|
||||||
vec3 point = pPoint.xyz/pPoint.w;
|
vec3 point = pPoint.xyz/pPoint.w;
|
||||||
//TODO: CLIP TO VIEWPORT
|
//TODO: CLIP TO VIEWPORT
|
||||||
minBB = min(minBB, point);
|
minBB = min(minBB, point);
|
||||||
maxBB = max(maxBB, point);
|
maxBB = max(maxBB, point);
|
||||||
|
|
||||||
screenPoints[BASE_IDX+i] = point.xy*0.5f+0.5f;
|
screenPoints[BASE_IDX+i] = point.xy*0.5f+0.5f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,7 +93,7 @@ void setupScreenspace(in UnpackedNode node) {
|
|||||||
|
|
||||||
//Checks if the node is implicitly culled (outside frustum)
|
//Checks if the node is implicitly culled (outside frustum)
|
||||||
bool outsideFrustum() {
|
bool outsideFrustum() {
|
||||||
return any(lessThanEqual(maxBB, vec3(0.0f))) || any(lessThanEqual(vec3(1.0f), minBB)) || maxBB.z < 0.5;// maxBB.z > 1 is actually wrong
|
return !insideFrustum;// maxW < 16 is a trick where 16 is the near plane
|
||||||
|
|
||||||
//|| any(lessThanEqual(minBB, vec3(0.0f, 0.0f, 0.0f))) || any(lessThanEqual(vec3(1.0f, 1.0f, 1.0f), maxBB));
|
//|| any(lessThanEqual(minBB, vec3(0.0f, 0.0f, 0.0f))) || any(lessThanEqual(vec3(1.0f, 1.0f, 1.0f), maxBB));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user