Autmatic iris support

This commit is contained in:
mcrcortex
2024-02-20 08:06:43 +10:00
parent 7975e3816c
commit c18726652c
5 changed files with 28 additions and 6 deletions

View File

@@ -54,7 +54,8 @@ dependencies {
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")
modCompileOnly("maven.modrinth:iris:1.6.17+1.20.4")
//modRuntimeOnly("maven.modrinth:iris:1.6.17+1.20.4")
}

View File

@@ -10,13 +10,11 @@ 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;
import net.minecraft.client.util.math.MatrixStack;
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;

View File

@@ -0,0 +1,18 @@
package me.cortex.voxy.client.core.util;
import net.coderbot.iris.pipeline.ShadowRenderer;
import net.fabricmc.loader.api.FabricLoader;
import org.spongepowered.asm.mixin.Unique;
public class IrisUtil {
private static final boolean IRIS_INSTALLED = FabricLoader.getInstance().isModLoaded("iris");
private static boolean irisShadowActive0() {
return ShadowRenderer.ACTIVE;
}
public static boolean irisShadowActive() {
return IRIS_INSTALLED && irisShadowActive0();
}
}

View File

@@ -1,6 +1,7 @@
package me.cortex.voxy.client.mixin.sodium;
import me.cortex.voxy.client.core.IGetVoxelCore;
import me.cortex.voxy.client.core.util.IrisUtil;
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;
@@ -9,21 +10,25 @@ import me.jellysquid.mods.sodium.client.render.chunk.terrain.DefaultTerrainRende
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.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.util.math.MatrixStack;
import org.joml.Matrix4f;
import org.spongepowered.asm.mixin.FabricUtil;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
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) {
if (core != null && !IrisUtil.irisShadowActive()) {
var stack = new MatrixStack();
stack.loadIdentity();
stack.multiplyPositionMatrix(new Matrix4f(matrices.modelView()));

View File

@@ -9,7 +9,7 @@ out vec4 colour;
in vec2 UV;
vec3 rev3d(vec3 clip) {
vec4 view = invProjMat * vec4(clip*2.0-1.0,1.0);
vec4 view = invProjMat * vec4(clip*2.0f-1.0f,1.0f);
return view.xyz/view.w;
}
float projDepth(vec3 pos) {
@@ -25,7 +25,7 @@ void main() {
float depth = texture(depthTex, UV.xy).r;
depth = projDepth(rev3d(vec3(UV.xy, depth)));
depth = min(1f-(2f/((1<<24)-1)), depth);
depth = min(1.0f-(2.0f/((1<<24)-1)), depth);
depth = depth * 0.5f + 0.5f;
depth = gl_DepthRange.diff * depth + gl_DepthRange.near;
gl_FragDepth = depth;