Rasterized occlusion culling

This commit is contained in:
mcrcortex
2023-11-16 12:55:35 +10:00
parent 5d01a37192
commit 7e74d4fec8
11 changed files with 160 additions and 54 deletions

View File

@@ -50,17 +50,21 @@ layout(binding = 3, std430) readonly restrict buffer SectionBuffer {
SectionMeta sectionData[];
};
layout(binding = 4, std430) readonly restrict buffer StateBuffer {
State stateData[];
};
layout(binding = 5, std430) readonly restrict buffer BiomeBuffer {
Biome biomeData[];
};
#ifndef VISIBILITY_ACCESS
#define VISIBILITY_ACCESS readonly
#endif
layout(binding = 6, std430) VISIBILITY_ACCESS restrict buffer VisibilityBuffer {
layout(binding = 4, std430) VISIBILITY_ACCESS restrict buffer VisibilityBuffer {
uint visibilityData[];
};
layout(binding = 5, std430) readonly restrict buffer StateBuffer {
State stateData[];
};
layout(binding = 6, std430) readonly restrict buffer BiomeBuffer {
Biome biomeData[];
};
layout(binding = 7, std430) readonly restrict buffer LightingBuffer {
vec4 lightData[];
};

View File

@@ -34,12 +34,20 @@ void main() {
uint detail = extractDetail(meta);
ivec3 ipos = extractPosition(meta);
//TODO: fixme; i dont think this is correct
vec3 cornerPos = vec3(((ipos<<detail)-baseSectionPos)<<5)-cameraSubPos;
bool shouldRender = testFrustum(frustum, cornerPos, cornerPos+vec3(1<<(detail+5)));
//Check the occlusion data from last frame
if (visibilityData[gl_GlobalInvocationID.x] != frameId - 1) {
shouldRender = false;
}
//Clear the occlusion data (not strictly? needed? i think???)
//visibilityData[gl_GlobalInvocationID.x] = 0;
//TODO: need to make it check that only if it was also in the frustum last frame does it apply the visibilityData check!
//This prevents overflow of the relative position encoder
if (shouldRender) {
shouldRender = !any(lessThan(ivec3(254), abs(ipos-(baseSectionPos>>detail))));

View File

@@ -4,7 +4,9 @@
#import <voxelmon:lod/gl46/bindings.glsl>
flat in uint id;
flat in uint value;
//out vec4 colour;
void main() {
visibilityData[id] = value;
//colour = vec4(float(id&7)/7, float((id>>3)&7)/7, float((id>>6)&7)/7, 1);
}

View File

@@ -8,18 +8,20 @@ flat out uint id;
flat out uint value;
void main() {
SectionMeta section = sectionData[gl_VertexID>>3];
uint sid = gl_InstanceID;
SectionMeta section = sectionData[sid];
uint detail = extractDetail(section);
ivec3 ipos = extractPosition(section);
//Transform ipos with respect to the vertex corner
ipos += ivec3(gl_VertexID&1, (gl_VertexID>>1)&1, (gl_VertexID>>2)&1);
ipos += ivec3(gl_VertexID&1, (gl_VertexID>>2)&1, (gl_VertexID>>1)&1);
vec3 cornerPos = vec3(((ipos<<detail)-baseSectionPos)<<5);
gl_Position = MVP * vec4(cornerPos,1);
//Write to this id
id = gl_VertexID>>3;
id = sid;
value = frameId;
}