diff --git a/src/main/java/me/cortex/voxelmon/core/VoxelCore.java b/src/main/java/me/cortex/voxelmon/core/VoxelCore.java index b23c8229..a5f9bc40 100644 --- a/src/main/java/me/cortex/voxelmon/core/VoxelCore.java +++ b/src/main/java/me/cortex/voxelmon/core/VoxelCore.java @@ -57,7 +57,7 @@ public class VoxelCore { //Trigger the shared index buffer loading SharedIndexBuffer.INSTANCE.id(); 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.renderGen = new RenderGenerationService(this.world, this.renderTracker,4); diff --git a/src/main/java/me/cortex/voxelmon/core/rendering/Gl46FarWorldRenderer.java b/src/main/java/me/cortex/voxelmon/core/rendering/Gl46FarWorldRenderer.java index d93cf161..aeeb8d4c 100644 --- a/src/main/java/me/cortex/voxelmon/core/rendering/Gl46FarWorldRenderer.java +++ b/src/main/java/me/cortex/voxelmon/core/rendering/Gl46FarWorldRenderer.java @@ -40,6 +40,13 @@ public class Gl46FarWorldRenderer extends AbstractFarWorldRenderer { .add(ShaderType.FRAGMENT, "voxelmon:lod/gl46/quads.frag") .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); public Gl46FarWorldRenderer() { @@ -111,6 +118,7 @@ public class Gl46FarWorldRenderer extends AbstractFarWorldRenderer { super.shutdown(); this.commandGen.free(); this.lodShader.free(); + this.cullShader.free(); } @Override diff --git a/src/main/java/me/cortex/voxelmon/mixin/minecraft/MixinClientChunkManager.java b/src/main/java/me/cortex/voxelmon/mixin/minecraft/MixinClientChunkManager.java index 34acd55b..539f4676 100644 --- a/src/main/java/me/cortex/voxelmon/mixin/minecraft/MixinClientChunkManager.java +++ b/src/main/java/me/cortex/voxelmon/mixin/minecraft/MixinClientChunkManager.java @@ -14,6 +14,6 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; 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) private void injectUnload(ChunkPos pos, CallbackInfo ci, int index, WorldChunk worldChunk) { - //VoxelCore.INSTANCE.enqueueIngest(worldChunk); + VoxelCore.INSTANCE.enqueueIngest(worldChunk); } } diff --git a/src/main/resources/assets/voxelmon/shaders/lod/gl46/bindings.glsl b/src/main/resources/assets/voxelmon/shaders/lod/gl46/bindings.glsl index fe239601..161692d4 100644 --- a/src/main/resources/assets/voxelmon/shaders/lod/gl46/bindings.glsl +++ b/src/main/resources/assets/voxelmon/shaders/lod/gl46/bindings.glsl @@ -8,7 +8,7 @@ layout(binding = 0, std140) uniform SceneUniform { int sectionCount; Frustum frustum; vec3 cameraSubPos; - int _padA; + uint frameId; }; struct State { @@ -35,6 +35,9 @@ struct DrawCommand { uint baseInstance; }; +#ifndef Quad +#define Quad ivec2 +#endif layout(binding = 1, std430) readonly restrict buffer QuadBuffer { Quad quadData[]; }; @@ -54,3 +57,10 @@ layout(binding = 4, std430) readonly restrict buffer StateBuffer { 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 { + uint visibilityData[]; +}; diff --git a/src/main/resources/assets/voxelmon/shaders/lod/gl46/cmdgen.comp b/src/main/resources/assets/voxelmon/shaders/lod/gl46/cmdgen.comp index 53fa52ba..03e9ad44 100644 --- a/src/main/resources/assets/voxelmon/shaders/lod/gl46/cmdgen.comp +++ b/src/main/resources/assets/voxelmon/shaders/lod/gl46/cmdgen.comp @@ -1,34 +1,18 @@ #version 460 #extension GL_ARB_gpu_shader_int64 : enable + +layout(local_size_x = 128, local_size_y = 1, local_size_x = 1) in; + #import #import +#import +#import //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 -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 instanceCount; @@ -36,22 +20,6 @@ uint extractDetail(SectionMeta section) { int baseVertex; 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) { uvec3 detla = (pos - (baseSectionPos >> detail))&((1<<9)-1); diff --git a/src/main/resources/assets/voxelmon/shaders/lod/gl46/cull/raster.frag b/src/main/resources/assets/voxelmon/shaders/lod/gl46/cull/raster.frag index 5c2aa9fd..6e5bc37c 100644 --- a/src/main/resources/assets/voxelmon/shaders/lod/gl46/cull/raster.frag +++ b/src/main/resources/assets/voxelmon/shaders/lod/gl46/cull/raster.frag @@ -1,4 +1,10 @@ #version 460 core #extension GL_ARB_gpu_shader_int64 : enable +#define VISIBILITY_ACCESS writeonly +#import +flat in uint id; +flat in uint value; -#import \ No newline at end of file +void main() { + visibilityData[id] = value; +} \ No newline at end of file diff --git a/src/main/resources/assets/voxelmon/shaders/lod/gl46/cull/raster.vert b/src/main/resources/assets/voxelmon/shaders/lod/gl46/cull/raster.vert index 5c2aa9fd..97841ad3 100644 --- a/src/main/resources/assets/voxelmon/shaders/lod/gl46/cull/raster.vert +++ b/src/main/resources/assets/voxelmon/shaders/lod/gl46/cull/raster.vert @@ -1,4 +1,25 @@ #version 460 core #extension GL_ARB_gpu_shader_int64 : enable +#define VISIBILITY_ACCESS writeonly +#import +#import -#import \ No newline at end of file +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<>3; + value = frameId; +} \ No newline at end of file diff --git a/src/main/resources/assets/voxelmon/shaders/lod/gl46/frustum.glsl b/src/main/resources/assets/voxelmon/shaders/lod/gl46/frustum.glsl new file mode 100644 index 00000000..7bc74b2b --- /dev/null +++ b/src/main/resources/assets/voxelmon/shaders/lod/gl46/frustum.glsl @@ -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); +} \ No newline at end of file diff --git a/src/main/resources/assets/voxelmon/shaders/lod/gl46/quad_format.glsl b/src/main/resources/assets/voxelmon/shaders/lod/gl46/quad_format.glsl index 6da57029..87a10060 100644 --- a/src/main/resources/assets/voxelmon/shaders/lod/gl46/quad_format.glsl +++ b/src/main/resources/assets/voxelmon/shaders/lod/gl46/quad_format.glsl @@ -36,14 +36,26 @@ uint extractLightId(uint64_t quad) { #define Eu32(data, amountBits, shift) (uint((data)>>(shift))&((1u<<(amountBits))-1)) 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) { - 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) { return quad.y&7; } + +uint extractStateId(ivec2 quad) { + return 0; +} + +uint extractBiomeId(ivec2 quad) { + return 0; +} + +uint extractLightId(ivec2 quad) { + return 0; +} #endif \ No newline at end of file diff --git a/src/main/resources/assets/voxelmon/shaders/lod/gl46/section.glsl b/src/main/resources/assets/voxelmon/shaders/lod/gl46/section.glsl new file mode 100644 index 00000000..245c6c29 --- /dev/null +++ b/src/main/resources/assets/voxelmon/shaders/lod/gl46/section.glsl @@ -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; +}