Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a config option to disable voxy when shaders are enabled. #80

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/main/java/me/cortex/voxy/client/config/VoxyConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import me.cortex.voxy.client.core.Capabilities;
import me.cortex.voxy.client.core.util.IrisUtil;
import me.cortex.voxy.client.saver.ContextSelectionSystem;
import net.fabricmc.loader.api.FabricLoader;
import org.lwjgl.opengl.GL;
Expand Down Expand Up @@ -32,8 +33,13 @@ public class VoxyConfig {
public int savingThreads = 4;
public int renderThreads = 5;
public boolean useMeshShaderIfPossible = true;
public boolean disableWhenShadersActive = false;
public String defaultSaveConfig;

public boolean VoxyShouldBeEnabled() {
if (IrisUtil.irisShadersEnabled() && disableWhenShadersActive) return false;
return enabled;
}

public static VoxyConfig loadOrCreate() {
var path = getConfigPath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ private static void addGeneralCategory(ConfigBuilder builder, VoxyConfig config)
.setDefaultValue(DEFAULT.useMeshShaderIfPossible)
.build());

category.addEntry(entryBuilder.startBooleanToggle(Text.translatable("voxy.config.general.shaderAutoDisable"), config.disableWhenShadersActive)
.setTooltip(Text.translatable("voxy.config.general.shaderAutoDisable.tooltip"))
.setSaveConsumer(val -> config.disableWhenShadersActive = val)
.setDefaultValue(DEFAULT.disableWhenShadersActive)
.build());

//category.addEntry(entryBuilder.startIntSlider(Text.translatable("voxy.config.general.compression"), config.savingCompressionLevel, 1, 21)
// .setTooltip(Text.translatable("voxy.config.general.compression.tooltip"))
// .setSaveConsumer(val -> config.savingCompressionLevel = val)
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/me/cortex/voxy/client/core/util/IrisUtil.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package me.cortex.voxy.client.core.util;

import me.cortex.voxy.client.core.IGetVoxelCore;
import net.fabricmc.loader.api.FabricLoader;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.api.v0.IrisApi;
import net.irisshaders.iris.apiimpl.IrisApiV0Impl;
import net.irisshaders.iris.config.IrisConfig;
import net.irisshaders.iris.shadows.ShadowRenderer;
import net.minecraft.client.MinecraftClient;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;

public class IrisUtil {
Expand All @@ -15,4 +22,6 @@ private static boolean irisShadowActive0() {
public static boolean irisShadowActive() {
return IRIS_INSTALLED && irisShadowActive0();
}

public static boolean irisShadersEnabled() { return IRIS_INSTALLED && Iris.getIrisConfig().areShadersEnabled(); }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package me.cortex.voxy.client.mixin.iris;

import me.cortex.voxy.client.core.IGetVoxelCore;
import net.irisshaders.iris.config.IrisConfig;
import net.minecraft.client.MinecraftClient;
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 = IrisConfig.class, remap = false)
public class MixinIrisShaders {

@Inject(method = "setShadersEnabled", at = @At("RETURN"))
private void injectRefresh(boolean enabled, CallbackInfo ci) {
var world = (IGetVoxelCore) MinecraftClient.getInstance().worldRenderer;
if (world != null && !enabled) {
world.reloadVoxelCore();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private void resetVoxelCore(CallbackInfo ci) {
if (this.world != null && this.core != null) {
this.core.shutdown();
this.core = null;
if (VoxyConfig.CONFIG.enabled) {
if (VoxyConfig.CONFIG.VoxyShouldBeEnabled()) {
this.populateCore();
}
}
Expand All @@ -76,7 +76,7 @@ private void initVoxelCore(ClientWorld world, CallbackInfo ci) {
this.core.shutdown();
this.core = null;
}
if (VoxyConfig.CONFIG.enabled) {
if (VoxyConfig.CONFIG.VoxyShouldBeEnabled()) {
this.populateCore();
}
}
Expand All @@ -87,7 +87,7 @@ public void reloadVoxelCore() {
this.core.shutdown();
this.core = null;
}
if (this.world != null && VoxyConfig.CONFIG.enabled) {
if (this.world != null && VoxyConfig.CONFIG.VoxyShouldBeEnabled()) {
this.populateCore();
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/voxy/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"voxy.config.general.renderDistance.tooltip": "The render distance in chunks (set to -1 to disable chunk unloading)",
"voxy.config.general.nvmesh": "Use nvidia mesh shaders",
"voxy.config.general.nvmesh.tooltip": "Use nvidia mesh shaders if possible to render LoDs",
"voxy.config.general.shaderAutoDisable": "Automatically disable Voxy with shaders",
"voxy.config.general.shaderAutoDisable.tooltip": "Automatically disable Voxy when shaders are applied.",

"voxy.config.threads.ingest": "Ingest",
"voxy.config.threads.ingest.tooltip": "How many threads voxy will use for ingesting new chunks",
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/voxy.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"nvidium.MixinRenderPipeline",
"sodium.MixinDefaultChunkRenderer",
"sodium.MixinRenderSectionManager",
"sodium.MixinSodiumWorldRender"
"sodium.MixinSodiumWorldRender",
"iris.MixinIrisShaders"
],
"injectors": {
"defaultRequire": 1
Expand Down