Iris support v1

This commit is contained in:
mcrcortex
2024-02-18 12:02:57 +10:00
parent 4d29cc4889
commit 71cfe67fe7
12 changed files with 119 additions and 16 deletions

View File

@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.2-SNAPSHOT'
id 'fabric-loom' version "1.5.7"
id 'maven-publish'
}
@@ -49,11 +49,12 @@ dependencies {
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
//TODO: this is to eventually not need sodium installed as atm its just used for parsing shaders
modRuntimeOnly "maven.modrinth:sodium:mc1.20.3-0.5.5"
modCompileOnly "maven.modrinth:sodium:mc1.20.3-0.5.5"
modRuntimeOnly "maven.modrinth:sodium:mc1.20.4-0.5.8"
modCompileOnly "maven.modrinth:sodium:mc1.20.4-0.5.8"
modImplementation("maven.modrinth:cloth-config:13.0.121+fabric")
modImplementation("maven.modrinth:modmenu:9.0.0")
modImplementation("maven.modrinth:iris:1.6.17+1.20.4")
}

View File

@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@@ -1,6 +1,7 @@
package me.cortex.voxy.client.core;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import me.cortex.voxy.client.config.VoxyConfig;
import me.cortex.voxy.client.core.rendering.*;
import me.cortex.voxy.client.core.rendering.building.RenderGenerationService;
@@ -9,6 +10,7 @@ import me.cortex.voxy.client.core.util.DebugUtil;
import me.cortex.voxy.client.saver.ContextSelectionSystem;
import me.cortex.voxy.common.world.WorldEngine;
import me.cortex.voxy.client.importers.WorldImporter;
import net.coderbot.iris.Iris;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.Camera;
import net.minecraft.client.render.Frustum;
@@ -136,6 +138,9 @@ public class VoxelCore {
//this.renderer.getModelManager().updateEntry(0, Blocks.COMPARATOR.getDefaultState());
//this.renderer.getModelManager().updateEntry(0, Blocks.OAK_LEAVES.getDefaultState());
var fb = Iris.getPipelineManager().getPipelineNullable().getSodiumTerrainPipeline().getTerrainSolidFramebuffer();
fb.bind();
int boundFB = GlStateManager.getBoundFramebuffer();
this.postProcessing.setup(MinecraftClient.getInstance().getFramebuffer().textureWidth, MinecraftClient.getInstance().getFramebuffer().textureHeight, boundFB);
@@ -159,7 +164,7 @@ public class VoxelCore {
this.renderer.renderFarAwayTranslucent();
this.postProcessing.renderPost(boundFB);
this.postProcessing.renderPost(projection, RenderSystem.getProjectionMatrix(), boundFB);
}

View File

@@ -113,6 +113,7 @@ public class Gl46FarWorldRenderer extends AbstractFarWorldRenderer {
}
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
//this.models.bakery.renderFaces(Blocks.WATER.getDefaultState().with(FluidBlock.LEVEL, 1), 1234, true);

View File

@@ -19,6 +19,10 @@ public class FullscreenBlit {
.compile();
}
public void bind() {
this.shader.bind();
}
public void blit() {
glBindVertexArray(EMPTY_VAO);
this.shader.bind();

View File

@@ -33,7 +33,8 @@ public class PostProcessing {
private GlTexture depthStencil;
private final FullscreenBlit emptyBlit = new FullscreenBlit("voxy:post/noop.frag");
private final FullscreenBlit blitTexture = new FullscreenBlit("voxy:post/blit_texture_cutout.frag");
//private final FullscreenBlit blitTexture = new FullscreenBlit("voxy:post/blit_texture_cutout.frag");
private final FullscreenBlit blitTexture = new FullscreenBlit("voxy:post/blit_texture_depth_cutout.frag");
private final Shader ssaoComp = Shader.make()
.add(ShaderType.COMPUTE, "voxy:post/ssao.comp")
.compile();
@@ -134,7 +135,7 @@ public class PostProcessing {
//Executes the post processing and emits to whatever framebuffer is currently bound via a blit
public void renderPost(int outputFB) {
public void renderPost(Matrix4f fromProjection, Matrix4f tooProjection, int outputFB) {
glDisable(GL_STENCIL_TEST);
@@ -145,11 +146,23 @@ public class PostProcessing {
//glBlitNamedFramebuffer(this.framebuffer.id, outputFB, 0,0, this.width, this.height, 0,0, this.width, this.height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
this.blitTexture.bind();
float[] data = new float[4*4];
var mat = new Matrix4f(fromProjection).invert();
mat.get(data);
glUniformMatrix4fv(2, false, data);//inverse fromProjection
tooProjection.get(data);
glUniformMatrix4fv(3, false, data);//tooProjection
glActiveTexture(GL_TEXTURE1);
GL11C.glBindTexture(GL_TEXTURE_2D, this.depthStencil.id);
glTexParameteri (GL_TEXTURE_2D, GL_DEPTH_STENCIL_TEXTURE_MODE, GL_DEPTH_COMPONENT);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, this.colour.id);
glEnable(GL_DEPTH_TEST);
glDepthMask(false);
glDepthMask(true);
this.blitTexture.blit();
glDisable(GL_DEPTH_TEST);
glDepthMask(true);

View File

@@ -39,7 +39,7 @@ public abstract class MixinWorldRenderer implements IGetVoxelCore {
private void injectOpaqueRender(MatrixStack matrices, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightmapTextureManager lightmapTextureManager, Matrix4f projectionMatrix, CallbackInfo ci) {
if (this.core != null) {
var cam = camera.getPos();
this.core.renderOpaque(matrices, cam.x, cam.y, cam.z);
//this.core.renderOpaque(matrices, cam.x, cam.y, cam.z);
}
}

View File

@@ -0,0 +1,34 @@
package me.cortex.voxy.client.mixin.sodium;
import me.cortex.voxy.client.core.IGetVoxelCore;
import me.jellysquid.mods.sodium.client.gl.device.CommandList;
import me.jellysquid.mods.sodium.client.render.chunk.ChunkRenderMatrices;
import me.jellysquid.mods.sodium.client.render.chunk.DefaultChunkRenderer;
import me.jellysquid.mods.sodium.client.render.chunk.lists.ChunkRenderListIterable;
import me.jellysquid.mods.sodium.client.render.chunk.terrain.DefaultTerrainRenderPasses;
import me.jellysquid.mods.sodium.client.render.chunk.terrain.TerrainRenderPass;
import me.jellysquid.mods.sodium.client.render.viewport.CameraTransform;
import net.coderbot.iris.pipeline.ShadowRenderer;
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 = DefaultChunkRenderer.class, remap = false)
public class MixinDefaultChunkRenderer {
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/render/chunk/ShaderChunkRenderer;end(Lme/jellysquid/mods/sodium/client/render/chunk/terrain/TerrainRenderPass;)V", shift = At.Shift.BEFORE))
private void injectRender(ChunkRenderMatrices matrices, CommandList commandList, ChunkRenderListIterable renderLists, TerrainRenderPass renderPass, CameraTransform camera, CallbackInfo ci) {
if (renderPass == DefaultTerrainRenderPasses.CUTOUT) {
var core = ((IGetVoxelCore) MinecraftClient.getInstance().worldRenderer).getVoxelCore();
if (core != null && !ShadowRenderer.ACTIVE) {
var stack = new MatrixStack();
stack.loadIdentity();
stack.multiplyPositionMatrix(new Matrix4f(matrices.modelView()));
core.renderOpaque(stack, camera.x, camera.y, camera.z);
}
}
}
}

View File

@@ -24,14 +24,25 @@ public class RocksDBStorageBackend extends StorageBackend {
private final List<AbstractImmutableNativeReference> closeList = new ArrayList<>();
public RocksDBStorageBackend(String path) {
try {
var lockPath = new File(path).toPath().resolve("LOCK");
if (Files.exists(lockPath)) {
System.err.println("WARNING, deleting rocksdb LOCK file");
Files.delete(lockPath);
var lockPath = new File(path).toPath().resolve("LOCK");
if (Files.exists(lockPath)) {
System.err.println("WARNING, deleting rocksdb LOCK file");
int attempts = 10;
while (attempts-- != 0) {
try {
Files.delete(lockPath);
break;
} catch (IOException e) {
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
throw new RuntimeException(ex);
}
}
}
if (Files.exists(lockPath)) {
throw new RuntimeException("Unable to delete rocksdb lock file");
}
} catch (IOException e) {
throw new RuntimeException(e);
}
final ColumnFamilyOptions cfOpts = new ColumnFamilyOptions().optimizeUniversalStyleCompaction();

View File

@@ -13,6 +13,7 @@ uint faceHasAlphaCuttout(uint faceData) {
return (faceData>>22)&1u;
}
//TODO: try and get rid of
uint faceHasAlphaCuttoutOverride(uint faceData) {
return (faceData>>23)&1u;
}

View File

@@ -0,0 +1,32 @@
#version 450 core
layout(binding = 0) uniform sampler2D colourTex;
layout(binding = 1) uniform sampler2D depthTex;
layout(location = 2) uniform mat4 invProjMat;
layout(location = 3) uniform mat4 projMat;
out vec4 colour;
in vec2 UV;
vec3 rev3d(vec3 clip) {
vec4 view = invProjMat * vec4(clip*2.0-1.0,1.0);
return view.xyz/view.w;
}
float projDepth(vec3 pos) {
vec4 view = projMat * vec4(pos, 1);
return view.z/view.w;
}
void main() {
colour = texture(colourTex, UV.xy);
if (colour.a == 0.0) {
discard;
}
float depth = texture(depthTex, UV.xy).r;
depth = projDepth(rev3d(vec3(UV.xy, depth)));
depth = min(1f-(2f/((1<<24)-1)), depth);
depth = depth * 0.5f + 0.5f;
depth = gl_DepthRange.diff * depth + gl_DepthRange.near;
gl_FragDepth = depth;
}

View File

@@ -16,6 +16,7 @@
"defaultRequire": 1
},
"mixins": [
"sodium.MixinDefaultChunkRenderer",
"sodium.MixinRenderSectionManager"
]
}