Seperated out the projection matrix from vanilla terrain projection
This commit is contained in:
@@ -18,6 +18,7 @@ import net.minecraft.registry.RegistryKeys;
|
|||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.chunk.WorldChunk;
|
import net.minecraft.world.chunk.WorldChunk;
|
||||||
|
import org.joml.Matrix4f;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -107,6 +108,23 @@ public class VoxelCore {
|
|||||||
this.renderer.setupRender(frustum, camera);
|
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) {
|
public void renderOpaque(MatrixStack matrices, double cameraX, double cameraY, double cameraZ) {
|
||||||
matrices.push();
|
matrices.push();
|
||||||
matrices.translate(-cameraX, -cameraY, -cameraZ);
|
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
|
// this is cause the terrain might not exist and so all the caves are visible causing hell for the
|
||||||
// occlusion culler
|
// 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
|
//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
|
//We can render the translucent directly after as it is the furthest translucent objects
|
||||||
this.renderer.renderFarAwayTranslucent();
|
this.renderer.renderFarAwayTranslucent();
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import net.minecraft.client.render.Camera;
|
|||||||
import net.minecraft.client.render.Frustum;
|
import net.minecraft.client.render.Frustum;
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
import org.joml.FrustumIntersection;
|
import org.joml.FrustumIntersection;
|
||||||
|
import org.joml.Matrix4f;
|
||||||
import org.lwjgl.system.MemoryUtil;
|
import org.lwjgl.system.MemoryUtil;
|
||||||
|
|
||||||
import java.util.List;
|
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();
|
public abstract void renderFarAwayTranslucent();
|
||||||
|
|
||||||
|
|||||||
@@ -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.gl.shader.ShaderType;
|
||||||
import me.cortex.voxy.client.core.rendering.util.UploadStream;
|
import me.cortex.voxy.client.core.rendering.util.UploadStream;
|
||||||
import me.cortex.voxy.client.mixin.joml.AccessFrustumIntersection;
|
import me.cortex.voxy.client.mixin.joml.AccessFrustumIntersection;
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.render.RenderLayer;
|
import net.minecraft.client.render.RenderLayer;
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
import org.joml.Matrix4f;
|
import org.joml.Matrix4f;
|
||||||
@@ -83,9 +84,10 @@ public class Gl46FarWorldRenderer extends AbstractFarWorldRenderer {
|
|||||||
|
|
||||||
//FIXME: dont do something like this as it breaks multiviewport mods
|
//FIXME: dont do something like this as it breaks multiviewport mods
|
||||||
private int frameId = 0;
|
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());
|
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)));
|
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.translate(-innerTranslation.x, -innerTranslation.y, -innerTranslation.z);
|
||||||
mat.getToAddress(ptr); ptr += 4*4*4;
|
mat.getToAddress(ptr); ptr += 4*4*4;
|
||||||
@@ -101,7 +103,7 @@ public class Gl46FarWorldRenderer extends AbstractFarWorldRenderer {
|
|||||||
MemoryUtil.memPutInt(ptr, this.frameId++); ptr += 4;
|
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) {
|
if (this.geometry.getSectionCount() == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -117,7 +119,7 @@ public class Gl46FarWorldRenderer extends AbstractFarWorldRenderer {
|
|||||||
//RenderSystem.enableBlend();
|
//RenderSystem.enableBlend();
|
||||||
//RenderSystem.defaultBlendFunc();
|
//RenderSystem.defaultBlendFunc();
|
||||||
|
|
||||||
this.updateUniformBuffer(stack, cx, cy, cz);
|
this.updateUniformBuffer(projection, stack, cx, cy, cz);
|
||||||
|
|
||||||
UploadStream.INSTANCE.commit();
|
UploadStream.INSTANCE.commit();
|
||||||
|
|
||||||
|
|||||||
@@ -121,10 +121,10 @@ public class PostProcessing {
|
|||||||
|
|
||||||
//Computes ssao on the current framebuffer data and updates it
|
//Computes ssao on the current framebuffer data and updates it
|
||||||
// this means that translucency wont be effected etc
|
// this means that translucency wont be effected etc
|
||||||
public void computeSSAO(MatrixStack stack) {
|
public void computeSSAO(Matrix4f projection, MatrixStack stack) {
|
||||||
this.ssaoComp.bind();
|
this.ssaoComp.bind();
|
||||||
float[] data = new float[4*4];
|
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);
|
mat.get(data);
|
||||||
glUniformMatrix4fv(2, false, data);//MVP
|
glUniformMatrix4fv(2, false, data);//MVP
|
||||||
mat.invert();
|
mat.invert();
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -11,6 +11,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|||||||
public class MixinMinecraftClient {
|
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))
|
@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) {
|
private void injectRenderDoc(RunArgs args, CallbackInfo ci) {
|
||||||
System.load("C:\\Program Files\\RenderDoc\\renderdoc.dll");
|
//System.load("C:\\Program Files\\RenderDoc\\renderdoc.dll");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|||||||
public class MixinSodiumWorldRender {
|
public class MixinSodiumWorldRender {
|
||||||
@Inject(method = "drawChunkLayer", at = @At("HEAD"), cancellable = true, require = 0)
|
@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) {
|
private void cancelRender(RenderLayer renderLayer, MatrixStack matrixStack, double x, double y, double z, CallbackInfo ci) {
|
||||||
ci.cancel();
|
//ci.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,10 @@ import org.rocksdb.*;
|
|||||||
import redis.clients.jedis.JedisPool;
|
import redis.clients.jedis.JedisPool;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -22,6 +24,16 @@ public class RocksDBStorageBackend extends StorageBackend {
|
|||||||
private final List<AbstractImmutableNativeReference> closeList = new ArrayList<>();
|
private final List<AbstractImmutableNativeReference> closeList = new ArrayList<>();
|
||||||
|
|
||||||
public RocksDBStorageBackend(File path) {
|
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 ColumnFamilyOptions cfOpts = new ColumnFamilyOptions().optimizeUniversalStyleCompaction();
|
||||||
|
|
||||||
final List<ColumnFamilyDescriptor> cfDescriptors = Arrays.asList(
|
final List<ColumnFamilyDescriptor> cfDescriptors = Arrays.asList(
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#line 1
|
||||||
struct Frustum {
|
struct Frustum {
|
||||||
vec4 planes[6];
|
vec4 planes[6];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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
|
//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
|
// but im going to assume that since we are dealing with huge render distances, this shouldent matter that much
|
||||||
float extractFaceIndentation(uint faceData) {
|
float extractFaceIndentation(uint faceData) {
|
||||||
return float((faceData>>16)&63)/63;
|
return float((faceData>>16)&63)/63f;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 extractFaceSizes(uint faceData) {
|
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) {
|
uint faceHasAlphaCuttout(uint faceData) {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#line 1
|
||||||
#ifdef GL_ARB_gpu_shader_int64
|
#ifdef GL_ARB_gpu_shader_int64
|
||||||
#define Quad uint64_t
|
#define Quad uint64_t
|
||||||
|
|
||||||
|
|||||||
@@ -23,18 +23,18 @@ ivec3 extractRelativeLodPos() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
vec4 uint2vec4RGBA(uint colour) {
|
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 -)
|
//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 getDepthOffset(uint faceData, uint face) {
|
||||||
float offset = extractFaceIndentation(faceData);
|
float offset = extractFaceIndentation(faceData);
|
||||||
return offset * (1-((int(face)&1)*2));
|
return offset * (1f-((int(face)&1)*2f));
|
||||||
}
|
}
|
||||||
|
|
||||||
vec2 getFaceSizeOffset(uint faceData, uint corner) {
|
vec2 getFaceSizeOffset(uint faceData, uint corner) {
|
||||||
vec4 faceOffsetsSizes = extractFaceSizes(faceData);
|
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
|
//TODO: add a mechanism so that some quads can ignore backface culling
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#line 1
|
||||||
uint extractDetail(SectionMeta section) {
|
uint extractDetail(SectionMeta section) {
|
||||||
return section.posA>>28;
|
return section.posA>>28;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,3 +4,8 @@ accessible field net/minecraft/client/texture/SpriteContents image Lnet/minecraf
|
|||||||
accessible field net/minecraft/client/render/Frustum frustumIntersection Lorg/joml/FrustumIntersection;
|
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/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
|
||||||
@@ -7,7 +7,6 @@
|
|||||||
"minecraft.MixinBackgroundRenderer",
|
"minecraft.MixinBackgroundRenderer",
|
||||||
"minecraft.MixinClientChunkManager",
|
"minecraft.MixinClientChunkManager",
|
||||||
"minecraft.MixinDebugHud",
|
"minecraft.MixinDebugHud",
|
||||||
"minecraft.MixinGameRenderer",
|
|
||||||
"minecraft.MixinMinecraftClient",
|
"minecraft.MixinMinecraftClient",
|
||||||
"minecraft.MixinWorldRenderer"
|
"minecraft.MixinWorldRenderer"
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user