Setup for rasterized occlusion culling

This commit is contained in:
mcrcortex
2023-11-14 09:31:33 +10:00
parent 046a419e4f
commit 92e31986b1
10 changed files with 103 additions and 44 deletions

View File

@@ -57,7 +57,7 @@ public class VoxelCore {
//Trigger the shared index buffer loading //Trigger the shared index buffer loading
SharedIndexBuffer.INSTANCE.id(); SharedIndexBuffer.INSTANCE.id();
this.renderer = new Gl46FarWorldRenderer(); this.renderer = new Gl46FarWorldRenderer();
this.world = new WorldEngine(new File("ethoslab.db"), 16, 5);//"hc9.db"//"storagefile.db" this.world = new WorldEngine(new File("storagefile.db"), 5, 5);//"storagefile.db"//"ethoslab.db"
this.renderTracker = new RenderTracker(this.world, this.renderer); this.renderTracker = new RenderTracker(this.world, this.renderer);
this.renderGen = new RenderGenerationService(this.world, this.renderTracker,4); this.renderGen = new RenderGenerationService(this.world, this.renderTracker,4);

View File

@@ -40,6 +40,13 @@ public class Gl46FarWorldRenderer extends AbstractFarWorldRenderer {
.add(ShaderType.FRAGMENT, "voxelmon:lod/gl46/quads.frag") .add(ShaderType.FRAGMENT, "voxelmon:lod/gl46/quads.frag")
.compile(); .compile();
//TODO: Note the cull shader needs a different element array since its rastering cubes not quads
private final Shader cullShader = Shader.make()
.add(ShaderType.VERTEX, "voxelmon:lod/gl46/cull/raster.vert")
.add(ShaderType.FRAGMENT, "voxelmon:lod/gl46/cull/raster.frag")
.compile();
private final GlBuffer glCommandBuffer = new GlBuffer(100_000*5*4, 0); private final GlBuffer glCommandBuffer = new GlBuffer(100_000*5*4, 0);
public Gl46FarWorldRenderer() { public Gl46FarWorldRenderer() {
@@ -111,6 +118,7 @@ public class Gl46FarWorldRenderer extends AbstractFarWorldRenderer {
super.shutdown(); super.shutdown();
this.commandGen.free(); this.commandGen.free();
this.lodShader.free(); this.lodShader.free();
this.cullShader.free();
} }
@Override @Override

View File

@@ -14,6 +14,6 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
public class MixinClientChunkManager { public class MixinClientChunkManager {
@Inject(method = "unload", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/world/ClientChunkManager$ClientChunkMap;compareAndSet(ILnet/minecraft/world/chunk/WorldChunk;Lnet/minecraft/world/chunk/WorldChunk;)Lnet/minecraft/world/chunk/WorldChunk;", shift = At.Shift.BEFORE), locals = LocalCapture.CAPTURE_FAILHARD) @Inject(method = "unload", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/world/ClientChunkManager$ClientChunkMap;compareAndSet(ILnet/minecraft/world/chunk/WorldChunk;Lnet/minecraft/world/chunk/WorldChunk;)Lnet/minecraft/world/chunk/WorldChunk;", shift = At.Shift.BEFORE), locals = LocalCapture.CAPTURE_FAILHARD)
private void injectUnload(ChunkPos pos, CallbackInfo ci, int index, WorldChunk worldChunk) { private void injectUnload(ChunkPos pos, CallbackInfo ci, int index, WorldChunk worldChunk) {
//VoxelCore.INSTANCE.enqueueIngest(worldChunk); VoxelCore.INSTANCE.enqueueIngest(worldChunk);
} }
} }

View File

@@ -8,7 +8,7 @@ layout(binding = 0, std140) uniform SceneUniform {
int sectionCount; int sectionCount;
Frustum frustum; Frustum frustum;
vec3 cameraSubPos; vec3 cameraSubPos;
int _padA; uint frameId;
}; };
struct State { struct State {
@@ -35,6 +35,9 @@ struct DrawCommand {
uint baseInstance; uint baseInstance;
}; };
#ifndef Quad
#define Quad ivec2
#endif
layout(binding = 1, std430) readonly restrict buffer QuadBuffer { layout(binding = 1, std430) readonly restrict buffer QuadBuffer {
Quad quadData[]; Quad quadData[];
}; };
@@ -54,3 +57,10 @@ layout(binding = 4, std430) readonly restrict buffer StateBuffer {
layout(binding = 5, std430) readonly restrict buffer BiomeBuffer { layout(binding = 5, std430) readonly restrict buffer BiomeBuffer {
Biome biomeData[]; Biome biomeData[];
}; };
#ifndef VISIBILITY_ACCESS
#define VISIBILITY_ACCESS readonly
#endif
layout(binding = 6, std430) VISIBILITY_ACCESS restrict buffer VisibilityBuffer {
uint visibilityData[];
};

View File

@@ -1,34 +1,18 @@
#version 460 #version 460
#extension GL_ARB_gpu_shader_int64 : enable #extension GL_ARB_gpu_shader_int64 : enable
layout(local_size_x = 128, local_size_y = 1, local_size_x = 1) in;
#import <voxelmon:lod/gl46/quad_format.glsl> #import <voxelmon:lod/gl46/quad_format.glsl>
#import <voxelmon:lod/gl46/bindings.glsl> #import <voxelmon:lod/gl46/bindings.glsl>
#import <voxelmon:lod/gl46/frustum.glsl>
#import <voxelmon:lod/gl46/section.glsl>
//https://github.com/KhronosGroup/GLSL/blob/master/extensions/ext/GL_EXT_shader_16bit_storage.txt //https://github.com/KhronosGroup/GLSL/blob/master/extensions/ext/GL_EXT_shader_16bit_storage.txt
// adds support for uint8_t which can use for compact visibility buffer // adds support for uint8_t which can use for compact visibility buffer
layout(local_size_x = 128, local_size_y = 1, local_size_x = 1) in;
bool testFrustumPoint(vec4 plane, vec3 min, vec3 max) {
vec3 point = mix(max, min, lessThan(plane.xyz, vec3(0))) * plane.xyz;
return (point.x + point.y + point.z) >= -plane.w;
}
bool testFrustum(Frustum frust, vec3 min, vec3 max) {
return testFrustumPoint(frust.planes[0], min, max) &&
testFrustumPoint(frust.planes[1], min, max) &&
testFrustumPoint(frust.planes[2], min, max) &&
testFrustumPoint(frust.planes[3], min, max) &&
testFrustumPoint(frust.planes[4], min, max) &&
testFrustumPoint(frust.planes[5], min, max);
}
uint extractDetail(SectionMeta section) {
return section.header.x>>28;
}
/* /*
uint count; uint count;
uint instanceCount; uint instanceCount;
@@ -36,22 +20,6 @@ uint extractDetail(SectionMeta section) {
int baseVertex; int baseVertex;
uint baseInstance; uint baseInstance;
*/ */
ivec3 extractPosition(SectionMeta section) {
int y = ((int(section.header.x)<<4)>>24);
int x = (int(section.header.y)<<4)>>8;
int z = int((section.header.x&((1<<20)-1))<<4);
z |= int(section.header.y>>28);
z <<= 8;
z >>= 8;
return ivec3(x,y,z);
}
uint extractQuadStart(SectionMeta meta) {
return meta.header.z;
}
uint extractQuadCount(SectionMeta meta) {
return meta.header.w;
}
uint encodeLocalLodPos(uint detail, ivec3 pos) { uint encodeLocalLodPos(uint detail, ivec3 pos) {
uvec3 detla = (pos - (baseSectionPos >> detail))&((1<<9)-1); uvec3 detla = (pos - (baseSectionPos >> detail))&((1<<9)-1);

View File

@@ -1,4 +1,10 @@
#version 460 core #version 460 core
#extension GL_ARB_gpu_shader_int64 : enable #extension GL_ARB_gpu_shader_int64 : enable
#define VISIBILITY_ACCESS writeonly
#import <voxelmon:lod/gl46/bindings.glsl> #import <voxelmon:lod/gl46/bindings.glsl>
flat in uint id;
flat in uint value;
void main() {
visibilityData[id] = value;
}

View File

@@ -1,4 +1,25 @@
#version 460 core #version 460 core
#extension GL_ARB_gpu_shader_int64 : enable #extension GL_ARB_gpu_shader_int64 : enable
#define VISIBILITY_ACCESS writeonly
#import <voxelmon:lod/gl46/bindings.glsl> #import <voxelmon:lod/gl46/bindings.glsl>
#import <voxelmon:lod/gl46/section.glsl>
flat out uint id;
flat out uint value;
void main() {
SectionMeta section = sectionData[gl_VertexID>>3];
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);
vec3 cornerPos = vec3(((ipos<<detail)-baseSectionPos)<<5);
gl_Position = MVP * vec4(cornerPos,1);
//Write to this id
id = gl_VertexID>>3;
value = frameId;
}

View File

@@ -0,0 +1,13 @@
bool testFrustumPoint(vec4 plane, vec3 min, vec3 max) {
vec3 point = mix(max, min, lessThan(plane.xyz, vec3(0))) * plane.xyz;
return (point.x + point.y + point.z) >= -plane.w;
}
bool testFrustum(Frustum frust, vec3 min, vec3 max) {
return testFrustumPoint(frust.planes[0], min, max) &&
testFrustumPoint(frust.planes[1], min, max) &&
testFrustumPoint(frust.planes[2], min, max) &&
testFrustumPoint(frust.planes[3], min, max) &&
testFrustumPoint(frust.planes[4], min, max) &&
testFrustumPoint(frust.planes[5], min, max);
}

View File

@@ -36,14 +36,26 @@ uint extractLightId(uint64_t quad) {
#define Eu32(data, amountBits, shift) (uint((data)>>(shift))&((1u<<(amountBits))-1)) #define Eu32(data, amountBits, shift) (uint((data)>>(shift))&((1u<<(amountBits))-1))
vec3 extractPos(ivec2 quad) { vec3 extractPos(ivec2 quad) {
return vec3(Eu32(quad.y, 5, 21), Eu32(quad.y, 5, 16), Eu32(quad.y, 5, 11)); return vec3(0);
} }
ivec2 extractSize(ivec2 quad) { ivec2 extractSize(ivec2 quad) {
return ivec2(Eu32(quad.y, 4, 3), Eu32(quad.y, 4, 7)) + ivec2(1);//the + 1 is cause you cant actually have a 0 size quad return ivec2(0);
} }
uint extractFace(ivec2 quad) { uint extractFace(ivec2 quad) {
return quad.y&7; return quad.y&7;
} }
uint extractStateId(ivec2 quad) {
return 0;
}
uint extractBiomeId(ivec2 quad) {
return 0;
}
uint extractLightId(ivec2 quad) {
return 0;
}
#endif #endif

View File

@@ -0,0 +1,21 @@
uint extractDetail(SectionMeta section) {
return section.header.x>>28;
}
ivec3 extractPosition(SectionMeta section) {
int y = ((int(section.header.x)<<4)>>24);
int x = (int(section.header.y)<<4)>>8;
int z = int((section.header.x&((1<<20)-1))<<4);
z |= int(section.header.y>>28);
z <<= 8;
z >>= 8;
return ivec3(x,y,z);
}
uint extractQuadStart(SectionMeta meta) {
return meta.header.z;
}
uint extractQuadCount(SectionMeta meta) {
return meta.header.w;
}