Began work on config, found out that i dont think occlusion culling is doing occlusion culling

This commit is contained in:
mcrcortex
2024-01-20 14:56:54 +10:00
parent e3bd036385
commit df6c56d62d
10 changed files with 135 additions and 13 deletions

View File

@@ -44,7 +44,12 @@ dependencies {
modImplementation(fabricApi.module("fabric-command-api-v2", project.fabric_version))
modImplementation("net.fabricmc.fabric-api:fabric-rendering-data-attachment-v1:0.3.38+73761d2e9a")
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modImplementation "maven.modrinth:sodium:mc1.20.3-0.5.5"
modImplementation("maven.modrinth:cloth-config:13.0.121+fabric")
modImplementation("maven.modrinth:modmenu:9.0.0")
}

View File

@@ -0,0 +1,11 @@
package me.cortex.zenith.client.config;
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;
public class ScreenFactory implements ModMenuApi {
@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return parent -> null;
}
}

View File

@@ -0,0 +1,15 @@
package me.cortex.zenith.client.config;
public class ZenithConfig {
int qualityScale;
int ingestThreads;
int savingThreads;
int renderThreads;
int savingCompressionLevel;
StorageConfig storageConfig;
public static abstract class StorageConfig { }
public static class FragmentedStorageConfig extends StorageConfig { }
public static class LmdbStorageConfig extends StorageConfig { }
}

View File

@@ -0,0 +1,7 @@
package me.cortex.zenith.client.config;
import com.terraformersmc.modmenu.api.ModMenuApi;
public class ZenithConfigScreenFactory implements ModMenuApi {
}

View File

@@ -9,6 +9,7 @@ import me.cortex.zenith.client.core.other.BlockStateColour;
import me.cortex.zenith.client.core.other.ColourResolver;
import me.cortex.zenith.common.world.other.Mapper;
import me.cortex.zenith.client.importers.WorldImporter;
import me.cortex.zenith.common.world.storage.SplicedStorageBackendAdaptor;
import me.cortex.zenith.common.world.storage.lmdb.LMDBStorageBackend;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
@@ -65,17 +66,17 @@ public class VoxelCore {
SharedIndexBuffer.INSTANCE.id();
this.renderer = new Gl46FarWorldRenderer();
System.out.println("Renderer initialized");
this.world = new WorldEngine(new LMDBStorageBackend(new File("storagefile.db")), 2, 20, 5);//"storagefile.db"//"ethoslab.db"
this.world = new WorldEngine(new SplicedStorageBackendAdaptor(), 2, 20, 5);//"storagefile.db"//"ethoslab.db"
System.out.println("World engine");
this.renderTracker = new RenderTracker(this.world, this.renderer);
this.renderGen = new RenderGenerationService(this.world,5, this.renderTracker::processBuildResult);
this.renderGen = new RenderGenerationService(this.world,7, this.renderTracker::processBuildResult);
this.world.setDirtyCallback(this.renderTracker::sectionUpdated);
this.renderTracker.setRenderGen(this.renderGen);
System.out.println("Render tracker and generator initialized");
//To get to chunk scale multiply the scale by 2, the scale is after how many chunks does the lods halve
this.distanceTracker = new DistanceTracker(this.renderTracker, 5, 20);//16
this.distanceTracker = new DistanceTracker(this.renderTracker, 5, 64);//16
System.out.println("Distance tracker initialized");
this.postProcessing = null;//new PostProcessing();

View File

@@ -23,26 +23,27 @@ import static org.lwjgl.opengl.GL42.*;
import static org.lwjgl.opengl.GL42.GL_FRAMEBUFFER_BARRIER_BIT;
import static org.lwjgl.opengl.GL43.*;
import static org.lwjgl.opengl.GL43.GL_SHADER_STORAGE_BUFFER;
import static org.lwjgl.opengl.NVRepresentativeFragmentTest.GL_REPRESENTATIVE_FRAGMENT_TEST_NV;
public class Gl46FarWorldRenderer extends AbstractFarWorldRenderer {
private final Shader commandGen = Shader.make()
.add(ShaderType.COMPUTE, "voxelmon:lod/gl46/cmdgen.comp")
.add(ShaderType.COMPUTE, "zenith:lod/gl46/cmdgen.comp")
.compile();
private final Shader lodShader = Shader.make()
.add(ShaderType.VERTEX, "voxelmon:lod/gl46/quads.vert")
.add(ShaderType.FRAGMENT, "voxelmon:lod/gl46/quads.frag")
.add(ShaderType.VERTEX, "zenith:lod/gl46/quads.vert")
.add(ShaderType.FRAGMENT, "zenith: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")
.add(ShaderType.VERTEX, "zenith:lod/gl46/cull/raster.vert")
.add(ShaderType.FRAGMENT, "zenith:lod/gl46/cull/raster.frag")
.compile();
private final GlBuffer glCommandBuffer = new GlBuffer(100_000*5*4, 0);
private final GlBuffer glVisibilityBuffer = new GlBuffer(100_000*4, 0);
private final GlBuffer glCommandBuffer = new GlBuffer(200_000*5*4, 0);
private final GlBuffer glVisibilityBuffer = new GlBuffer(200_000*4, 0);
public Gl46FarWorldRenderer() {
super();
@@ -108,6 +109,11 @@ public class Gl46FarWorldRenderer extends AbstractFarWorldRenderer {
cullShader.bind();
glColorMask(false, false, false, false);
glDepthMask(false);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
//glEnable(GL_REPRESENTATIVE_FRAGMENT_TEST_NV);
glDrawElementsInstanced(GL_TRIANGLES, 6 * 2 * 3, GL_UNSIGNED_BYTE, (1 << 16) * 6 * 2, this.geometry.getSectionCount());
glDepthMask(true);
glColorMask(true, true, true, true);

View File

@@ -48,7 +48,7 @@ public class SaveLoadSystem {
raw.limit(raw.position());
raw.rewind();
ByteBuffer compressedData = MemoryUtil.memAlloc((int)ZSTD_COMPRESSBOUND(raw.remaining()));
long compressedSize = ZSTD_compress(compressedData, raw, 15);
long compressedSize = ZSTD_compress(compressedData, raw, 7);
compressedData.limit((int) compressedSize);
compressedData.rewind();
MemoryUtil.memFree(raw);

View File

@@ -0,0 +1,74 @@
package me.cortex.zenith.common.world.storage;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import me.cortex.zenith.common.world.storage.lmdb.LMDBStorageBackend;
import net.minecraft.util.math.random.RandomSeed;
import java.io.File;
import java.nio.ByteBuffer;
//Segments the section data into multiple dbs
public class SplicedStorageBackendAdaptor extends StorageBackend {
private final StorageBackend[] backends = new StorageBackend[32];
public SplicedStorageBackendAdaptor() {
for (int i = 0; i < this.backends.length; i++) {
this.backends[i] = new LMDBStorageBackend(new File("db_store/storage-db-"+i+".db"));
}
}
//public static long getWorldSectionId(int lvl, int x, int y, int z) {
// return ((long)lvl<<60)|((long)(y&0xFF)<<52)|((long)(z&((1<<24)-1))<<28)|((long)(x&((1<<24)-1))<<4);//NOTE: 4 bits spare for whatever
// }
//private int getSegmentId(long key) {
// return (int) (((key>>4)&1)|((key>>27)&0b10)|((key>>50)&0b100));
//}
private int getSegmentId(long key) {
return (int) (RandomSeed.mixStafford13(RandomSeed.mixStafford13(key)^key)&0x1F);
}
//TODO: reencode the key to be shifted one less OR
// use like a mix64 to shuffle the key in getSegmentId so that
// multiple layers of spliced storage backends can be stacked
@Override
public ByteBuffer getSectionData(long key) {
return this.backends[this.getSegmentId(key)].getSectionData(key);
}
@Override
public void setSectionData(long key, ByteBuffer data) {
this.backends[this.getSegmentId(key)].setSectionData(key, data);
}
@Override
public void deleteSectionData(long key) {
this.backends[this.getSegmentId(key)].deleteSectionData(key);
}
@Override
public void putIdMapping(int id, ByteBuffer data) {
this.backends[0].putIdMapping(id, data);
}
@Override
public Int2ObjectOpenHashMap<byte[]> getIdMappingsData() {
return this.backends[0].getIdMappingsData();
}
@Override
public void flush() {
for (var db : this.backends) {
db.flush();
}
}
@Override
public void close() {
for (var db : this.backends) {
db.close();
}
}
}

View File

@@ -4,9 +4,9 @@
#import <zenith:lod/gl46/bindings.glsl>
flat in uint id;
flat in uint value;
//out vec4 colour;
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);
colour = vec4(float(id&7)/7, float((id>>3)&7)/7, float((id>>6)&7)/7, 1);
}

View File

@@ -15,6 +15,9 @@
"entrypoints": {
"client": [
"me.cortex.zenith.client.Voxelmon"
],
"modmenu": [
"me.cortex.zenith.client.config.ZenithConfigScreenFactory"
]
},
"mixins": [