Add proper frustum check
This commit is contained in:
14
src/main/resources/assets/voxy/shaders/lod/frustum.glsl
Normal file
14
src/main/resources/assets/voxy/shaders/lod/frustum.glsl
Normal file
@@ -0,0 +1,14 @@
|
||||
struct Frustum {
|
||||
vec4 planes[6];
|
||||
};
|
||||
|
||||
bool testPlane(vec4 plane, vec3 base, float size) {
|
||||
return dot(plane.xyz, base+mix(vec3(size), vec3(0), lessThan(plane.xyz, vec3(0)))) >= -plane.w;
|
||||
}
|
||||
|
||||
//TODO: optimize this, this can be done by computing the base point value, then multiplying and adding a seperate value by the size
|
||||
bool outsideFrustum(in Frustum frustum, vec3 pos, float size) {
|
||||
return !(testPlane(frustum.planes[0], pos, size) && testPlane(frustum.planes[1], pos, size) &&
|
||||
testPlane(frustum.planes[2], pos, size) && testPlane(frustum.planes[3], pos, size) &&
|
||||
testPlane(frustum.planes[4], pos, size));//Dont need to test far plane
|
||||
}
|
||||
@@ -58,13 +58,16 @@ void setupScreenspace(in UnpackedNode node) {
|
||||
+ (transform.worldPos.xyz-camChunkPos))-camSubChunk);
|
||||
*/
|
||||
|
||||
//TODO: AABB SIZES not just a max cube
|
||||
|
||||
//vec3 minPos = minSize + basePos;
|
||||
//vec3 maxPos = maxSize + basePos;
|
||||
|
||||
vec3 basePos = vec3(((node.pos<<node.lodLevel)-camSecPos)<<5)-camSubSecPos;
|
||||
|
||||
insideFrustum = !outsideFrustum(frustum, basePos, float(32<<node.lodLevel));
|
||||
|
||||
//Fast exit
|
||||
if (!insideFrustum) {
|
||||
return;
|
||||
}
|
||||
|
||||
vec4 P000 = VP * vec4(basePos, 1);
|
||||
mat3x4 Axis = mat3x4(VP) * float(32<<node.lodLevel);
|
||||
|
||||
@@ -76,13 +79,6 @@ void setupScreenspace(in UnpackedNode node) {
|
||||
vec4 P011 = Axis[1] + P001;
|
||||
vec4 P111 = Axis[1] + P101;
|
||||
|
||||
insideFrustum = checkPointInView(P000) || checkPointInView(P100) || checkPointInView(P001) || checkPointInView(P101) ||
|
||||
checkPointInView(P010) || checkPointInView(P110) || checkPointInView(P011) || checkPointInView(P111);
|
||||
|
||||
//Fast exit
|
||||
if (!insideFrustum) {
|
||||
return;
|
||||
}
|
||||
|
||||
//Perspective divide + convert to screenspace (i.e. range 0->1 if within viewport)
|
||||
vec3 p000 = (P000.xyz/P000.w) * 0.5f + 0.5f;
|
||||
|
||||
@@ -5,12 +5,15 @@
|
||||
#define LOCAL_SIZE (1<<LOCAL_SIZE_BITS)
|
||||
layout(local_size_x=LOCAL_SIZE) in;//, local_size_y=1
|
||||
|
||||
#import <voxy:lod/frustum.glsl>
|
||||
|
||||
layout(binding = SCENE_UNIFORM_BINDING, std140) uniform SceneUniform {
|
||||
mat4 VP;
|
||||
ivec3 camSecPos;
|
||||
float screenW;
|
||||
vec3 camSubSecPos;
|
||||
float screenH;
|
||||
Frustum frustum;
|
||||
uint renderQueueMaxSize;
|
||||
float minSSS;
|
||||
uint frameId;
|
||||
|
||||
Reference in New Issue
Block a user