diff --git a/src/main/java/me/cortex/voxy/client/core/VoxelCore.java b/src/main/java/me/cortex/voxy/client/core/VoxelCore.java index a16ac424..20d37741 100644 --- a/src/main/java/me/cortex/voxy/client/core/VoxelCore.java +++ b/src/main/java/me/cortex/voxy/client/core/VoxelCore.java @@ -18,6 +18,7 @@ import net.minecraft.registry.RegistryKeys; import net.minecraft.util.Identifier; import net.minecraft.world.World; import net.minecraft.world.chunk.WorldChunk; +import org.joml.Matrix4f; import java.io.File; import java.util.*; @@ -107,6 +108,23 @@ public class VoxelCore { this.renderer.setupRender(frustum, camera); } + private Matrix4f getProjectionMatrix() { + + var projection = new Matrix4f(); + var client = MinecraftClient.getInstance(); + var gameRenderer = client.gameRenderer; + + float fov = (float) gameRenderer.getFov(gameRenderer.getCamera(), client.getTickDelta(), true); + + projection.setPerspective(fov * 0.01745329238474369f, + (float) client.getWindow().getFramebufferWidth() / (float)client.getWindow().getFramebufferHeight(), + 64F, 16 * 3000f); + var transform = new Matrix4f().identity(); + transform.translate(gameRenderer.zoomX, -gameRenderer.zoomY, 0.0F); + transform.scale(gameRenderer.zoom, gameRenderer.zoom, 1.0F); + return transform.mul(projection); + } + public void renderOpaque(MatrixStack matrices, double cameraX, double cameraY, double cameraZ) { matrices.push(); matrices.translate(-cameraX, -cameraY, -cameraZ); @@ -129,10 +147,12 @@ public class VoxelCore { // this is cause the terrain might not exist and so all the caves are visible causing hell for the // occlusion culler - this.renderer.renderFarAwayOpaque(matrices, cameraX, cameraY, cameraZ); + var projection = this.getProjectionMatrix(); + + this.renderer.renderFarAwayOpaque(projection, matrices, cameraX, cameraY, cameraZ); //Compute the SSAO of the rendered terrain - this.postProcessing.computeSSAO(matrices); + //this.postProcessing.computeSSAO(projection, matrices); //We can render the translucent directly after as it is the furthest translucent objects this.renderer.renderFarAwayTranslucent(); diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/AbstractFarWorldRenderer.java b/src/main/java/me/cortex/voxy/client/core/rendering/AbstractFarWorldRenderer.java index 5caba1c2..d094de11 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/AbstractFarWorldRenderer.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/AbstractFarWorldRenderer.java @@ -14,6 +14,7 @@ import net.minecraft.client.render.Camera; import net.minecraft.client.render.Frustum; import net.minecraft.client.util.math.MatrixStack; import org.joml.FrustumIntersection; +import org.joml.Matrix4f; import org.lwjgl.system.MemoryUtil; import java.util.List; @@ -92,7 +93,7 @@ public abstract class AbstractFarWorldRenderer { } } - public abstract void renderFarAwayOpaque(MatrixStack stack, double cx, double cy, double cz); + public abstract void renderFarAwayOpaque(Matrix4f projection, MatrixStack stack, double cx, double cy, double cz); public abstract void renderFarAwayTranslucent(); diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/Gl46FarWorldRenderer.java b/src/main/java/me/cortex/voxy/client/core/rendering/Gl46FarWorldRenderer.java index 818e2d0a..c1168d2c 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/Gl46FarWorldRenderer.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/Gl46FarWorldRenderer.java @@ -7,6 +7,7 @@ import me.cortex.voxy.client.core.gl.shader.Shader; import me.cortex.voxy.client.core.gl.shader.ShaderType; import me.cortex.voxy.client.core.rendering.util.UploadStream; import me.cortex.voxy.client.mixin.joml.AccessFrustumIntersection; +import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.RenderLayer; import net.minecraft.client.util.math.MatrixStack; import org.joml.Matrix4f; @@ -83,9 +84,10 @@ public class Gl46FarWorldRenderer extends AbstractFarWorldRenderer { //FIXME: dont do something like this as it breaks multiviewport mods private int frameId = 0; - private void updateUniformBuffer(MatrixStack stack, double cx, double cy, double cz) { + private void updateUniformBuffer(Matrix4f projection, MatrixStack stack, double cx, double cy, double cz) { long ptr = UploadStream.INSTANCE.upload(this.uniformBuffer, 0, this.uniformBuffer.size()); - var mat = new Matrix4f(RenderSystem.getProjectionMatrix()).mul(stack.peek().getPositionMatrix()); + + var mat = new Matrix4f(projection).mul(stack.peek().getPositionMatrix()); var innerTranslation = new Vector3f((float) (cx-(this.sx<<5)), (float) (cy-(this.sy<<5)), (float) (cz-(this.sz<<5))); mat.translate(-innerTranslation.x, -innerTranslation.y, -innerTranslation.z); mat.getToAddress(ptr); ptr += 4*4*4; @@ -101,7 +103,7 @@ public class Gl46FarWorldRenderer extends AbstractFarWorldRenderer { MemoryUtil.memPutInt(ptr, this.frameId++); ptr += 4; } - public void renderFarAwayOpaque(MatrixStack stack, double cx, double cy, double cz) { + public void renderFarAwayOpaque(Matrix4f projection, MatrixStack stack, double cx, double cy, double cz) { if (this.geometry.getSectionCount() == 0) { return; } @@ -117,7 +119,7 @@ public class Gl46FarWorldRenderer extends AbstractFarWorldRenderer { //RenderSystem.enableBlend(); //RenderSystem.defaultBlendFunc(); - this.updateUniformBuffer(stack, cx, cy, cz); + this.updateUniformBuffer(projection, stack, cx, cy, cz); UploadStream.INSTANCE.commit(); diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/post/PostProcessing.java b/src/main/java/me/cortex/voxy/client/core/rendering/post/PostProcessing.java index 5e1b6421..6e5a1d68 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/post/PostProcessing.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/post/PostProcessing.java @@ -121,10 +121,10 @@ public class PostProcessing { //Computes ssao on the current framebuffer data and updates it // this means that translucency wont be effected etc - public void computeSSAO(MatrixStack stack) { + public void computeSSAO(Matrix4f projection, MatrixStack stack) { this.ssaoComp.bind(); float[] data = new float[4*4]; - var mat = new Matrix4f(RenderSystem.getProjectionMatrix()).mul(stack.peek().getPositionMatrix()); + var mat = new Matrix4f(projection).mul(stack.peek().getPositionMatrix()); mat.get(data); glUniformMatrix4fv(2, false, data);//MVP mat.invert(); diff --git a/src/main/java/me/cortex/voxy/client/mixin/minecraft/MixinGameRenderer.java b/src/main/java/me/cortex/voxy/client/mixin/minecraft/MixinGameRenderer.java deleted file mode 100644 index e740a20b..00000000 --- a/src/main/java/me/cortex/voxy/client/mixin/minecraft/MixinGameRenderer.java +++ /dev/null @@ -1,24 +0,0 @@ -package me.cortex.voxy.client.mixin.minecraft; - -import net.minecraft.client.render.GameRenderer; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Constant; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyConstant; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(GameRenderer.class) -public class MixinGameRenderer { - @Inject(method = "getFarPlaneDistance", at = @At("HEAD"), cancellable = true, require = 0) - public void method_32796(CallbackInfoReturnable cir) { - cir.setReturnValue(16 * 3000f); - cir.cancel(); - } - - @ModifyConstant(method = "getBasicProjectionMatrix", constant = @Constant(floatValue = 0.05F)) - public float modifyNearplane(float constant) { - //return 10; - return constant; - } -} \ No newline at end of file diff --git a/src/main/java/me/cortex/voxy/client/mixin/minecraft/MixinMinecraftClient.java b/src/main/java/me/cortex/voxy/client/mixin/minecraft/MixinMinecraftClient.java index 7d611b1f..8c3f0159 100644 --- a/src/main/java/me/cortex/voxy/client/mixin/minecraft/MixinMinecraftClient.java +++ b/src/main/java/me/cortex/voxy/client/mixin/minecraft/MixinMinecraftClient.java @@ -11,6 +11,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; public class MixinMinecraftClient { @Inject(method = "", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/resource/PeriodicNotificationManager;(Lnet/minecraft/util/Identifier;Lit/unimi/dsi/fastutil/objects/Object2BooleanFunction;)V", shift = At.Shift.AFTER)) private void injectRenderDoc(RunArgs args, CallbackInfo ci) { - System.load("C:\\Program Files\\RenderDoc\\renderdoc.dll"); + //System.load("C:\\Program Files\\RenderDoc\\renderdoc.dll"); } } diff --git a/src/main/java/me/cortex/voxy/client/mixin/sodium/MixinSodiumWorldRender.java b/src/main/java/me/cortex/voxy/client/mixin/sodium/MixinSodiumWorldRender.java index aff75e39..7bf9baee 100644 --- a/src/main/java/me/cortex/voxy/client/mixin/sodium/MixinSodiumWorldRender.java +++ b/src/main/java/me/cortex/voxy/client/mixin/sodium/MixinSodiumWorldRender.java @@ -12,6 +12,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; public class MixinSodiumWorldRender { @Inject(method = "drawChunkLayer", at = @At("HEAD"), cancellable = true, require = 0) private void cancelRender(RenderLayer renderLayer, MatrixStack matrixStack, double x, double y, double z, CallbackInfo ci) { - ci.cancel(); + //ci.cancel(); } } diff --git a/src/main/java/me/cortex/voxy/common/storage/rocksdb/RocksDBStorageBackend.java b/src/main/java/me/cortex/voxy/common/storage/rocksdb/RocksDBStorageBackend.java index 2acebc89..ac82cff5 100644 --- a/src/main/java/me/cortex/voxy/common/storage/rocksdb/RocksDBStorageBackend.java +++ b/src/main/java/me/cortex/voxy/common/storage/rocksdb/RocksDBStorageBackend.java @@ -7,8 +7,10 @@ import org.rocksdb.*; import redis.clients.jedis.JedisPool; import java.io.File; +import java.io.IOException; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -22,6 +24,16 @@ public class RocksDBStorageBackend extends StorageBackend { private final List closeList = new ArrayList<>(); public RocksDBStorageBackend(File path) { + try { + var lockPath = path.toPath().resolve("LOCK"); + if (Files.exists(lockPath)) { + System.err.println("WARNING, deleting rocksdb LOCK file"); + Files.delete(lockPath); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + final ColumnFamilyOptions cfOpts = new ColumnFamilyOptions().optimizeUniversalStyleCompaction(); final List cfDescriptors = Arrays.asList( diff --git a/src/main/resources/assets/voxy/shaders/lod/gl46/bindings.glsl b/src/main/resources/assets/voxy/shaders/lod/gl46/bindings.glsl index 3f59c552..f530bbf5 100644 --- a/src/main/resources/assets/voxy/shaders/lod/gl46/bindings.glsl +++ b/src/main/resources/assets/voxy/shaders/lod/gl46/bindings.glsl @@ -1,3 +1,4 @@ +#line 1 struct Frustum { vec4 planes[6]; }; diff --git a/src/main/resources/assets/voxy/shaders/lod/gl46/block_model.glsl b/src/main/resources/assets/voxy/shaders/lod/gl46/block_model.glsl index c12397fc..78f9aebc 100644 --- a/src/main/resources/assets/voxy/shaders/lod/gl46/block_model.glsl +++ b/src/main/resources/assets/voxy/shaders/lod/gl46/block_model.glsl @@ -1,11 +1,12 @@ +#line 1 //TODO: FIXME: this isnt actually correct cause depending on the face (i think) it could be 1/64 th of a position off // but im going to assume that since we are dealing with huge render distances, this shouldent matter that much float extractFaceIndentation(uint faceData) { - return float((faceData>>16)&63)/63; + return float((faceData>>16)&63)/63f; } vec4 extractFaceSizes(uint faceData) { - return (vec4(faceData&0xF, (faceData>>4)&0xF, (faceData>>8)&0xF, (faceData>>12)&0xF)/16)+vec4(0,1f/16,0,1f/16); + return (vec4(faceData&0xF, (faceData>>4)&0xF, (faceData>>8)&0xF, (faceData>>12)&0xF)/16f)+vec4(0f,1f/16f,0f,1f/16f); } uint faceHasAlphaCuttout(uint faceData) { diff --git a/src/main/resources/assets/voxy/shaders/lod/gl46/quad_format.glsl b/src/main/resources/assets/voxy/shaders/lod/gl46/quad_format.glsl index 8183f7d7..7423afff 100644 --- a/src/main/resources/assets/voxy/shaders/lod/gl46/quad_format.glsl +++ b/src/main/resources/assets/voxy/shaders/lod/gl46/quad_format.glsl @@ -1,3 +1,4 @@ +#line 1 #ifdef GL_ARB_gpu_shader_int64 #define Quad uint64_t diff --git a/src/main/resources/assets/voxy/shaders/lod/gl46/quads.vert b/src/main/resources/assets/voxy/shaders/lod/gl46/quads.vert index 25a8988a..bb2c9756 100644 --- a/src/main/resources/assets/voxy/shaders/lod/gl46/quads.vert +++ b/src/main/resources/assets/voxy/shaders/lod/gl46/quads.vert @@ -23,18 +23,18 @@ ivec3 extractRelativeLodPos() { } vec4 uint2vec4RGBA(uint colour) { - return vec4((uvec4(colour)>>uvec4(24,16,8,0))&uvec4(0xFF))/255; + return vec4((uvec4(colour)>>uvec4(24,16,8,0))&uvec4(0xFF))/255f; } //Gets the face offset with respect to the face direction (e.g. some will be + some will be -) float getDepthOffset(uint faceData, uint face) { float offset = extractFaceIndentation(faceData); - return offset * (1-((int(face)&1)*2)); + return offset * (1f-((int(face)&1)*2f)); } vec2 getFaceSizeOffset(uint faceData, uint corner) { vec4 faceOffsetsSizes = extractFaceSizes(faceData); - return mix(faceOffsetsSizes.xz, -(1-faceOffsetsSizes.yw), bvec2(((corner>>1)&1)==1, (corner&1)==1)); + return mix(faceOffsetsSizes.xz, -(1f-faceOffsetsSizes.yw), bvec2(((corner>>1)&1)==1, (corner&1)==1)); } //TODO: add a mechanism so that some quads can ignore backface culling diff --git a/src/main/resources/assets/voxy/shaders/lod/gl46/section.glsl b/src/main/resources/assets/voxy/shaders/lod/gl46/section.glsl index 1eed3f6b..be63ee63 100644 --- a/src/main/resources/assets/voxy/shaders/lod/gl46/section.glsl +++ b/src/main/resources/assets/voxy/shaders/lod/gl46/section.glsl @@ -1,3 +1,4 @@ +#line 1 uint extractDetail(SectionMeta section) { return section.posA>>28; } diff --git a/src/main/resources/voxy.accesswidener b/src/main/resources/voxy.accesswidener index 7d5ae33e..791ced83 100644 --- a/src/main/resources/voxy.accesswidener +++ b/src/main/resources/voxy.accesswidener @@ -3,4 +3,9 @@ accessWidener v1 named accessible field net/minecraft/client/texture/SpriteContents image Lnet/minecraft/client/texture/NativeImage; accessible field net/minecraft/client/render/Frustum frustumIntersection Lorg/joml/FrustumIntersection; accessible field net/minecraft/client/render/LightmapTextureManager texture Lnet/minecraft/client/texture/NativeImageBackedTexture; -accessible field net/minecraft/client/color/block/BlockColors providers Lnet/minecraft/util/collection/IdList; \ No newline at end of file +accessible field net/minecraft/client/color/block/BlockColors providers Lnet/minecraft/util/collection/IdList; +accessible field net/minecraft/client/render/GameRenderer zoomX F +accessible field net/minecraft/client/render/GameRenderer zoomY F +accessible field net/minecraft/client/render/GameRenderer zoom F + +accessible method net/minecraft/client/render/GameRenderer getFov (Lnet/minecraft/client/render/Camera;FZ)D \ No newline at end of file diff --git a/src/main/resources/voxy.mixins.json b/src/main/resources/voxy.mixins.json index 053a44a7..032cc746 100644 --- a/src/main/resources/voxy.mixins.json +++ b/src/main/resources/voxy.mixins.json @@ -7,7 +7,6 @@ "minecraft.MixinBackgroundRenderer", "minecraft.MixinClientChunkManager", "minecraft.MixinDebugHud", - "minecraft.MixinGameRenderer", "minecraft.MixinMinecraftClient", "minecraft.MixinWorldRenderer" ],