Version 0.1.1

This commit is contained in:
mcrcortex
2024-02-21 07:41:22 +10:00
parent 1ae5392a47
commit 5b689c622a
15 changed files with 101 additions and 47 deletions

View File

@@ -52,6 +52,9 @@ dependencies {
modRuntimeOnly "maven.modrinth:sodium:mc1.20.4-0.5.8" modRuntimeOnly "maven.modrinth:sodium:mc1.20.4-0.5.8"
modCompileOnly "maven.modrinth:sodium:mc1.20.4-0.5.8" modCompileOnly "maven.modrinth:sodium:mc1.20.4-0.5.8"
//modRuntimeOnly "maven.modrinth:nvidium:0.2.6-beta"
modCompileOnly "maven.modrinth:nvidium:0.2.6-beta"
modImplementation("maven.modrinth:cloth-config:13.0.121+fabric") modImplementation("maven.modrinth:cloth-config:13.0.121+fabric")
modImplementation("maven.modrinth:modmenu:9.0.0") modImplementation("maven.modrinth:modmenu:9.0.0")
modCompileOnly("maven.modrinth:iris:1.6.17+1.20.4") modCompileOnly("maven.modrinth:iris:1.6.17+1.20.4")

View File

@@ -8,7 +8,7 @@ yarn_mappings=1.20.4+build.1
loader_version=0.15.0 loader_version=0.15.0
# Mod Properties # Mod Properties
mod_version = 0.1.0-alpha mod_version = 0.1.1-alpha
maven_group = me.cortex maven_group = me.cortex
archives_base_name = voxy archives_base_name = voxy

View File

@@ -6,9 +6,18 @@ import me.cortex.voxy.client.terrain.WorldImportCommand;
import me.cortex.voxy.common.storage.config.Serialization; import me.cortex.voxy.common.storage.config.Serialization;
import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import net.minecraft.client.world.ClientWorld; import net.minecraft.client.world.ClientWorld;
public class Voxy implements ClientModInitializer { public class Voxy implements ClientModInitializer {
public static final String VERSION;
static {
ModContainer mod = (ModContainer) FabricLoader.getInstance().getModContainer("voxy").orElseThrow(NullPointerException::new);
VERSION = mod.getMetadata().getVersion().getFriendlyString();
}
@Override @Override
public void onInitializeClient() { public void onInitializeClient() {
Serialization.init(); Serialization.init();

View File

@@ -73,7 +73,7 @@ public class VoxyConfigScreenFactory implements ModMenuApi {
.setDefaultValue(DEFAULT.ingestEnabled) .setDefaultValue(DEFAULT.ingestEnabled)
.build()); .build());
category.addEntry(entryBuilder.startIntSlider(Text.translatable("voxy.config.general.quality"), config.qualityScale, 8, 50) category.addEntry(entryBuilder.startIntSlider(Text.translatable("voxy.config.general.quality"), config.qualityScale, 8, 32)
.setTooltip(Text.translatable("voxy.config.general.quality.tooltip")) .setTooltip(Text.translatable("voxy.config.general.quality.tooltip"))
.setSaveConsumer(val -> config.qualityScale = val) .setSaveConsumer(val -> config.qualityScale = val)
.setDefaultValue(DEFAULT.qualityScale) .setDefaultValue(DEFAULT.qualityScale)
@@ -103,19 +103,19 @@ public class VoxyConfigScreenFactory implements ModMenuApi {
ConfigEntryBuilder entryBuilder = builder.entryBuilder(); ConfigEntryBuilder entryBuilder = builder.entryBuilder();
category.addEntry(entryBuilder.startIntSlider(Text.translatable("voxy.config.threads.ingest"), config.ingestThreads, 1, Runtime.getRuntime().availableProcessors()) category.addEntry(entryBuilder.startIntSlider(Text.translatable("voxy.config.threads.ingest"), config.ingestThreads, 1, Runtime.getRuntime().availableProcessors())
.setTooltip(Text.translatable("voxy.config.general.ingest.tooltip")) .setTooltip(Text.translatable("voxy.config.ingest.tooltip"))
.setSaveConsumer(val -> config.ingestThreads = val) .setSaveConsumer(val -> config.ingestThreads = val)
.setDefaultValue(DEFAULT.ingestThreads) .setDefaultValue(DEFAULT.ingestThreads)
.build()); .build());
category.addEntry(entryBuilder.startIntSlider(Text.translatable("voxy.config.threads.saving"), config.savingThreads, 1, Runtime.getRuntime().availableProcessors()) category.addEntry(entryBuilder.startIntSlider(Text.translatable("voxy.config.threads.saving"), config.savingThreads, 1, Runtime.getRuntime().availableProcessors())
.setTooltip(Text.translatable("voxy.config.general.saving.tooltip")) .setTooltip(Text.translatable("voxy.config.saving.tooltip"))
.setSaveConsumer(val -> config.savingThreads = val) .setSaveConsumer(val -> config.savingThreads = val)
.setDefaultValue(DEFAULT.savingThreads) .setDefaultValue(DEFAULT.savingThreads)
.build()); .build());
category.addEntry(entryBuilder.startIntSlider(Text.translatable("voxy.config.threads.render"), config.renderThreads, 1, Runtime.getRuntime().availableProcessors()) category.addEntry(entryBuilder.startIntSlider(Text.translatable("voxy.config.threads.render"), config.renderThreads, 1, Runtime.getRuntime().availableProcessors())
.setTooltip(Text.translatable("voxy.config.general.render.tooltip")) .setTooltip(Text.translatable("voxy.config.render.tooltip"))
.setSaveConsumer(val -> config.renderThreads = val) .setSaveConsumer(val -> config.renderThreads = val)
.setDefaultValue(DEFAULT.renderThreads) .setDefaultValue(DEFAULT.renderThreads)
.build()); .build());

View File

@@ -2,6 +2,7 @@ package me.cortex.voxy.client.core;
import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import me.cortex.voxy.client.Voxy;
import me.cortex.voxy.client.config.VoxyConfig; import me.cortex.voxy.client.config.VoxyConfig;
import me.cortex.voxy.client.core.rendering.*; import me.cortex.voxy.client.core.rendering.*;
import me.cortex.voxy.client.core.rendering.building.RenderGenerationService; import me.cortex.voxy.client.core.rendering.building.RenderGenerationService;
@@ -113,7 +114,7 @@ public class VoxelCore {
this.renderer.setupRender(frustum, camera); this.renderer.setupRender(frustum, camera);
} }
private Matrix4f getProjectionMatrix() { private static Matrix4f makeProjectionMatrix(float near, float far) {
//TODO: use the existing projection matrix use mulLocal by the inverse of the projection and then mulLocal our projection //TODO: use the existing projection matrix use mulLocal by the inverse of the projection and then mulLocal our projection
var projection = new Matrix4f(); var projection = new Matrix4f();
@@ -124,11 +125,14 @@ public class VoxelCore {
projection.setPerspective(fov * 0.01745329238474369f, projection.setPerspective(fov * 0.01745329238474369f,
(float) client.getWindow().getFramebufferWidth() / (float)client.getWindow().getFramebufferHeight(), (float) client.getWindow().getFramebufferWidth() / (float)client.getWindow().getFramebufferHeight(),
16F, 16 * 3000f); near, far);
var transform = new Matrix4f().identity(); return projection;
transform.translate(gameRenderer.zoomX, -gameRenderer.zoomY, 0.0F); }
transform.scale(gameRenderer.zoom, gameRenderer.zoom, 1.0F);
return transform.mul(projection); private static Matrix4f computeProjectionMat() {
return new Matrix4f(RenderSystem.getProjectionMatrix()).mulLocal(
makeProjectionMatrix(0.05f, MinecraftClient.getInstance().gameRenderer.getFarPlaneDistance()).invert()
).mulLocal(makeProjectionMatrix(16, 16*3000));
} }
public void renderOpaque(MatrixStack matrices, double cameraX, double cameraY, double cameraZ) { public void renderOpaque(MatrixStack matrices, double cameraX, double cameraY, double cameraZ) {
@@ -159,7 +163,7 @@ public class VoxelCore {
// this is cause the terrain might not exist and so all the caves are visible causing hell for the // this is cause the terrain might not exist and so all the caves are visible causing hell for the
// occlusion culler // occlusion culler
var projection = this.getProjectionMatrix(); var projection = computeProjectionMat();
this.renderer.renderFarAwayOpaque(projection, matrices, cameraX, cameraY, cameraZ); this.renderer.renderFarAwayOpaque(projection, matrices, cameraX, cameraY, cameraZ);
@@ -177,7 +181,7 @@ public class VoxelCore {
public void addDebugInfo(List<String> debug) { public void addDebugInfo(List<String> debug) {
debug.add(""); debug.add("");
debug.add(""); debug.add("");
debug.add("Voxy Core"); debug.add("Voxy Core: " + Voxy.VERSION);
debug.add("Ingest service tasks: " + this.world.ingestService.getTaskCount()); debug.add("Ingest service tasks: " + this.world.ingestService.getTaskCount());
debug.add("Saving service tasks: " + this.world.savingService.getTaskCount()); debug.add("Saving service tasks: " + this.world.savingService.getTaskCount());
debug.add("Render service tasks: " + this.renderGen.getTaskCount()); debug.add("Render service tasks: " + this.renderGen.getTaskCount());
@@ -208,7 +212,7 @@ public class VoxelCore {
public WorldImporter createWorldImporter(World mcWorld, File worldPath) { public WorldImporter createWorldImporter(World mcWorld, File worldPath) {
var importer = new WorldImporter(this.world, mcWorld); var importer = new WorldImporter(this.world, mcWorld);
importer.importWorldAsyncStart(worldPath, 15, null, ()->{ importer.importWorldAsyncStart(worldPath, 4, null, ()->{
System.err.println("DONE IMPORT"); System.err.println("DONE IMPORT");
}); });
return importer; return importer;

View File

@@ -148,7 +148,8 @@ public class ModelManager {
// while the depth is computed from the depth buffer data // while the depth is computed from the depth buffer data
public int addEntry(int blockId, BlockState blockState) { public int addEntry(int blockId, BlockState blockState) {
if (this.idMappings[blockId] != -1) { if (this.idMappings[blockId] != -1) {
throw new IllegalArgumentException("Trying to add entry for duplicate id"); System.err.println("Block id already added: " + blockId + " for state: " + blockState);
return this.idMappings[blockId];
} }
boolean isFluid = blockState.getBlock() instanceof FluidBlock; boolean isFluid = blockState.getBlock() instanceof FluidBlock;

View File

@@ -7,6 +7,8 @@ import me.cortex.voxy.client.core.gl.GlBuffer;
import me.cortex.voxy.client.core.rendering.building.BuiltSection; import me.cortex.voxy.client.core.rendering.building.BuiltSection;
import me.cortex.voxy.client.core.rendering.util.BufferArena; import me.cortex.voxy.client.core.rendering.util.BufferArena;
import me.cortex.voxy.client.core.rendering.util.UploadStream; import me.cortex.voxy.client.core.rendering.util.UploadStream;
import net.minecraft.client.MinecraftClient;
import net.minecraft.text.Text;
import org.lwjgl.system.MemoryUtil; import org.lwjgl.system.MemoryUtil;
import java.util.concurrent.ConcurrentLinkedDeque; import java.util.concurrent.ConcurrentLinkedDeque;
@@ -79,6 +81,9 @@ public class GeometryManager {
//Create the new meta //Create the new meta
meta = this.createMeta(result); meta = this.createMeta(result);
if (meta == null) {
continue;
}
this.sectionMetadata.set(id, meta); this.sectionMetadata.set(id, meta);
long ptr = UploadStream.INSTANCE.upload(this.sectionMetaBuffer, (long)SECTION_METADATA_SIZE * id, SECTION_METADATA_SIZE); long ptr = UploadStream.INSTANCE.upload(this.sectionMetaBuffer, (long)SECTION_METADATA_SIZE * id, SECTION_METADATA_SIZE);
meta.writeMetadata(ptr); meta.writeMetadata(ptr);
@@ -90,6 +95,9 @@ public class GeometryManager {
//Create the new meta //Create the new meta
var meta = this.createMeta(result); var meta = this.createMeta(result);
if (meta == null) {
continue;
}
this.sectionMetadata.add(meta); this.sectionMetadata.add(meta);
long ptr = UploadStream.INSTANCE.upload(this.sectionMetaBuffer, (long)SECTION_METADATA_SIZE * id, SECTION_METADATA_SIZE); long ptr = UploadStream.INSTANCE.upload(this.sectionMetaBuffer, (long)SECTION_METADATA_SIZE * id, SECTION_METADATA_SIZE);
meta.writeMetadata(ptr); meta.writeMetadata(ptr);
@@ -158,6 +166,12 @@ public class GeometryManager {
private SectionMeta createMeta(BuiltSection geometry) { private SectionMeta createMeta(BuiltSection geometry) {
int geometryPtr = (int) this.geometryBuffer.upload(geometry.geometryBuffer); int geometryPtr = (int) this.geometryBuffer.upload(geometry.geometryBuffer);
if (geometryPtr == -1) {
String msg = "Buffer arena out of memory, please increase it in settings or decrease LoD quality";
MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(Text.literal(msg));
System.err.println(msg);
return null;
}
return new SectionMeta(geometry.position, geometry.aabb, geometryPtr, (int) (geometry.geometryBuffer.size/8), geometry.offsets); return new SectionMeta(geometry.position, geometry.aabb, geometryPtr, (int) (geometry.geometryBuffer.size/8), geometry.offsets);
} }

View File

@@ -14,7 +14,7 @@ public class BuiltSectionMeshCache {
public BuiltSection getMesh(long key) { public BuiltSection getMesh(long key) {
BuiltSection[] res = new BuiltSection[1]; BuiltSection[] res = new BuiltSection[1];
this.renderCache.computeIfPresent(key, (a, value) -> { this.renderCache.computeIfPresent(key, (a, value) -> {
if (value == null || value == HOLDER) { if (value == HOLDER) {
return value; return value;
} }
res[0] = value.clone(); res[0] = value.clone();

View File

@@ -29,7 +29,7 @@ public class BufferArena {
int size = (int) (buffer.size/this.elementSize); int size = (int) (buffer.size/this.elementSize);
long addr = this.allocationMap.alloc(size); long addr = this.allocationMap.alloc(size);
if (addr == -1) { if (addr == -1) {
throw new IllegalStateException("Buffer arena out of memory"); return -1;
} }
long uploadPtr = UploadStream.INSTANCE.upload(this.buffer, addr * this.elementSize, buffer.size); long uploadPtr = UploadStream.INSTANCE.upload(this.buffer, addr * this.elementSize, buffer.size);
MemoryUtil.memCopy(buffer.address, uploadPtr, buffer.size); MemoryUtil.memCopy(buffer.address, uploadPtr, buffer.size);

View File

@@ -0,0 +1,29 @@
package me.cortex.voxy.client.mixin.nvidium;
import me.cortex.nvidium.RenderPipeline;
import me.cortex.voxy.client.config.VoxyConfig;
import me.cortex.voxy.client.core.IGetVoxelCore;
import me.jellysquid.mods.sodium.client.render.chunk.ChunkRenderMatrices;
import me.jellysquid.mods.sodium.client.render.chunk.terrain.DefaultTerrainRenderPasses;
import me.jellysquid.mods.sodium.client.render.viewport.Viewport;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.util.math.MatrixStack;
import org.joml.Matrix4f;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(value = RenderPipeline.class, remap = false)
public class MixinRenderPipeline {
@Inject(method = "renderFrame", at = @At("RETURN"))
private void injectVoxyRender(Viewport frustum, ChunkRenderMatrices crm, double px, double py, double pz, CallbackInfo ci) {
var core = ((IGetVoxelCore) MinecraftClient.getInstance().worldRenderer).getVoxelCore();
if (core != null) {
var stack = new MatrixStack();
stack.loadIdentity();
stack.multiplyPositionMatrix(new Matrix4f(crm.modelView()));
core.renderOpaque(stack, px, py, pz);
}
}
}

View File

@@ -1,14 +0,0 @@
package me.cortex.voxy.client.mixin.sodium;
import me.jellysquid.mods.sodium.client.render.chunk.occlusion.OcclusionCuller;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(value = OcclusionCuller.class, remap = false)
public class MixinOcclusionCuller {
@Redirect(method = "isOutsideRenderDistance", at = @At(value = "INVOKE", target = "Ljava/lang/Math;abs(F)F"), require = 0)
private static float redirectAbs(float a) {
return 0;
}
}

View File

@@ -142,18 +142,23 @@ public class Serialization {
} }
private static List<String> collectAllClasses(String pack) { private static List<String> collectAllClasses(String pack) {
InputStream stream = Serialization.class.getClassLoader() try {
.getResourceAsStream(pack.replaceAll("[.]", "/")); InputStream stream = Serialization.class.getClassLoader()
BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); .getResourceAsStream(pack.replaceAll("[.]", "/"));
return reader.lines().flatMap(inner -> { BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
if (inner.endsWith(".class")) { return reader.lines().flatMap(inner -> {
return Stream.of(pack + "." + inner.replace(".class", "")); if (inner.endsWith(".class")) {
} else if (!inner.contains(".")) { return Stream.of(pack + "." + inner.replace(".class", ""));
return collectAllClasses(pack + "." + inner).stream(); } else if (!inner.contains(".")) {
} else { return collectAllClasses(pack + "." + inner).stream();
return Stream.of(); } else {
} return Stream.of();
}).collect(Collectors.toList()); }
}).collect(Collectors.toList());
} catch (Exception e) {
System.err.println("Failed to collect classes in package: " + pack);
return List.of();
}
} }
private static List<String> collectAllClasses(Path base, String pack) { private static List<String> collectAllClasses(Path base, String pack) {
if (!Files.exists(base.resolve(pack.replaceAll("[.]", "/")))) { if (!Files.exists(base.resolve(pack.replaceAll("[.]", "/")))) {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 58 KiB

After

Width:  |  Height:  |  Size: 60 KiB

View File

@@ -2,8 +2,8 @@
"schemaVersion": 1, "schemaVersion": 1,
"id": "voxy", "id": "voxy",
"version": "${version}", "version": "${version}",
"name": "voxy", "name": "Voxy",
"description": "", "description": "Far distance rendering mod utilising LoDs",
"authors": [ "authors": [
"Cortex" "Cortex"
], ],
@@ -24,7 +24,10 @@
"voxy.mixins.json" "voxy.mixins.json"
], ],
"depends": { "depends": {
"fabricloader": ">=0.14.22" "minecraft": "1.20.4",
"fabricloader": ">=0.14.22",
"fabric-api": ">=0.91.1",
"sodium": "*"
}, },
"accessWidener": "voxy.accesswidener" "accessWidener": "voxy.accesswidener"
} }

View File

@@ -9,13 +9,13 @@
"minecraft.MixinDebugHud", "minecraft.MixinDebugHud",
"minecraft.MixinMinecraftClient", "minecraft.MixinMinecraftClient",
"minecraft.MixinWorldRenderer", "minecraft.MixinWorldRenderer",
"sodium.MixinOcclusionCuller",
"sodium.MixinSodiumWorldRender" "sodium.MixinSodiumWorldRender"
], ],
"injectors": { "injectors": {
"defaultRequire": 1 "defaultRequire": 1
}, },
"mixins": [ "mixins": [
"nvidium.MixinRenderPipeline",
"sodium.MixinDefaultChunkRenderer", "sodium.MixinDefaultChunkRenderer",
"sodium.MixinRenderSectionManager" "sodium.MixinRenderSectionManager"
] ]