Seperated out the projection matrix from vanilla terrain projection

This commit is contained in:
mcrcortex
2024-02-06 15:12:37 +10:00
parent af1800226d
commit e197e07c94
15 changed files with 61 additions and 42 deletions

View File

@@ -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();

View File

@@ -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();

View File

@@ -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();

View File

@@ -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();

View File

@@ -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<Float> cir) {
cir.setReturnValue(16 * 3000f);
cir.cancel();
}
@ModifyConstant(method = "getBasicProjectionMatrix", constant = @Constant(floatValue = 0.05F))
public float modifyNearplane(float constant) {
//return 10;
return constant;
}
}

View File

@@ -11,6 +11,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
public class MixinMinecraftClient {
@Inject(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/resource/PeriodicNotificationManager;<init>(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");
}
}

View File

@@ -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();
}
}

View File

@@ -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<AbstractImmutableNativeReference> 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<ColumnFamilyDescriptor> cfDescriptors = Arrays.asList(

View File

@@ -1,3 +1,4 @@
#line 1
struct Frustum {
vec4 planes[6];
};

View File

@@ -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) {

View File

@@ -1,3 +1,4 @@
#line 1
#ifdef GL_ARB_gpu_shader_int64
#define Quad uint64_t

View File

@@ -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

View File

@@ -1,3 +1,4 @@
#line 1
uint extractDetail(SectionMeta section) {
return section.posA>>28;
}

View File

@@ -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;
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

View File

@@ -7,7 +7,6 @@
"minecraft.MixinBackgroundRenderer",
"minecraft.MixinClientChunkManager",
"minecraft.MixinDebugHud",
"minecraft.MixinGameRenderer",
"minecraft.MixinMinecraftClient",
"minecraft.MixinWorldRenderer"
],