diff --git a/build.gradle b/build.gradle index 9312e4c2b2..cbf1fc6584 100644 --- a/build.gradle +++ b/build.gradle @@ -107,7 +107,8 @@ repositories { dependencies { minecraft "com.mojang:minecraft:${minecraft_version}" mappings loom.officialMojangMappings() - forge "net.neoforged:forge:${minecraft_version}-${forge_version}" + //forge "net.neoforged:forge:${minecraft_version}-${neoforge_version}" + forge "net.minecraftforge:forge:${minecraft_version}-${forge_version}" modImplementation "org.embeddedt:embeddium-${minecraft_version}:${embeddium_version}" modCompileOnly("maven.modrinth:distanthorizonsapi:3.0.0") diff --git a/gradle.properties b/gradle.properties index e5b8ecf860..0d2ef79a3b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,14 +4,15 @@ org.gradle.jvmargs=-Xmx3G loom.platform = forge # Fabric Properties - # check these on https://fabricmc.net/develop - minecraft_version=1.20.1 - forge_version=47.1.105 +# check these on https://fabricmc.net/develop +minecraft_version=1.20.1 +forge_version=47.4.0 +neoforge_version=47.1.105 # Mod Properties - mod_version = 1.8.0 - maven_group = net.coderbot - archives_base_name = oculus +mod_version = 1.8.1 +maven_group = net.coderbot +archives_base_name = oculus # Dependencies - embeddium_version=0.3.31-beta.53+mc1.20.1 +embeddium_version=0.3.31-beta.53+mc1.20.1 diff --git a/src/main/java/net/irisshaders/iris/Iris.java b/src/main/java/net/irisshaders/iris/Iris.java index 28ef05acd5..986debdb12 100644 --- a/src/main/java/net/irisshaders/iris/Iris.java +++ b/src/main/java/net/irisshaders/iris/Iris.java @@ -771,7 +771,7 @@ public static void onEarlyInitialize() { logger.warn("", e); } - irisConfig = new IrisConfig(FMLPaths.CONFIGDIR.get().resolve(MODID + ".properties")); + irisConfig = new IrisConfig(FMLPaths.CONFIGDIR.get().resolve(MODID + ".properties"), FMLPaths.CONFIGDIR.get().resolve("iris-excluded.json")); try { irisConfig.initialize(); diff --git a/src/main/java/net/irisshaders/iris/compat/SkipList.java b/src/main/java/net/irisshaders/iris/compat/SkipList.java new file mode 100644 index 0000000000..02a5d49220 --- /dev/null +++ b/src/main/java/net/irisshaders/iris/compat/SkipList.java @@ -0,0 +1,15 @@ +package net.irisshaders.iris.compat; + +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; + +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.util.Map; + +public class SkipList { + public static Map, MethodHandle> shouldSkipList = new Object2ObjectOpenHashMap<>(); + + public static final MethodHandle NONE = MethodHandles.constant(Integer.class, 2); + + public static final MethodHandle ALWAYS = MethodHandles.constant(Integer.class, 1); +} diff --git a/src/main/java/net/irisshaders/iris/config/IrisConfig.java b/src/main/java/net/irisshaders/iris/config/IrisConfig.java index 2a18c9f9cf..e901f39a4c 100644 --- a/src/main/java/net/irisshaders/iris/config/IrisConfig.java +++ b/src/main/java/net/irisshaders/iris/config/IrisConfig.java @@ -1,14 +1,21 @@ package net.irisshaders.iris.config; +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import net.irisshaders.iris.Iris; import net.irisshaders.iris.gui.option.IrisVideoSettings; import net.irisshaders.iris.pathways.colorspace.ColorSpace; +import net.minecraft.resources.ResourceLocation; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; import java.util.Optional; import java.util.Properties; @@ -19,6 +26,7 @@ public class IrisConfig { private static final String COMMENT = "This file stores configuration options for Iris, such as the currently active shaderpack"; private final Path propertiesPath; + private final Path excludedPath; /** * The path to the current shaderpack. Null if the internal shaderpack is being used. */ @@ -27,21 +35,32 @@ public class IrisConfig { * Whether or not shaders are used for rendering. False to disable all shader-based rendering, true to enable it. */ private boolean enableShaders; + /** + * Whether or not to allow core shaders to draw to the main color texture. + */ + private boolean allowUnknownShaders; /** * If debug features should be enabled. Gives much more detailed OpenGL error outputs at the cost of performance. */ private boolean enableDebugOptions; + /** + * What shaders should be nuked. + */ + private List shadersToSkip = new ArrayList<>(); /** * If the update notification should be disabled or not. */ private boolean disableUpdateMessage; - public IrisConfig(Path propertiesPath) { + public IrisConfig(Path propertiesPath, Path excluded) { shaderPackName = null; enableShaders = true; enableDebugOptions = false; disableUpdateMessage = false; this.propertiesPath = propertiesPath; + allowUnknownShaders = false; + this.excludedPath = excluded; + } /** @@ -113,6 +132,14 @@ public void setShadersEnabled(boolean enabled) { this.enableShaders = enabled; } + public void setUnknown(boolean b) throws IOException { + this.allowUnknownShaders = b; + save(); + } + + private static Gson GSON = new Gson(); + + /** * loads the config file and then populates the string, int, and boolean entries with the parsed entries * @@ -124,6 +151,24 @@ public void load() throws IOException { return; } + if (Files.exists(excludedPath)) { + JsonArray json = JsonParser.parseString(Files.readString(excludedPath)).getAsJsonObject().getAsJsonArray("excluded"); + for (int i = 0; i < json.size(); i++) { + ResourceLocation resource = ResourceLocation.tryParse(json.get(i).getAsString()); + if (resource == null) { + Iris.logger.warn("Unknown shader " + json.get(i).getAsString()); + } + + shadersToSkip.add(resource); + } + } else { + JsonObject defaultV = new JsonObject(); + JsonArray array = new JsonArray(); + array.add("put:valuesHere"); + defaultV.add("excluded", array); + Files.writeString(excludedPath, GSON.toJson(defaultV)); + } + Properties properties = new Properties(); // NB: This uses ISO-8859-1 with unicode escapes as the encoding try (InputStream is = Files.newInputStream(propertiesPath)) { @@ -133,6 +178,8 @@ public void load() throws IOException { enableShaders = !"false".equals(properties.getProperty("enableShaders")); enableDebugOptions = "true".equals(properties.getProperty("enableDebugOptions")); disableUpdateMessage = "true".equals(properties.getProperty("disableUpdateMessage")); + allowUnknownShaders = "true".equals(properties.getProperty("allowUnknownShaders")); + try { IrisVideoSettings.shadowDistance = Integer.parseInt(properties.getProperty("maxShadowRenderDistance", "32")); IrisVideoSettings.colorSpace = ColorSpace.valueOf(properties.getProperty("colorSpace", "SRGB")); @@ -163,9 +210,18 @@ public void save() throws IOException { properties.setProperty("disableUpdateMessage", disableUpdateMessage ? "true" : "false"); properties.setProperty("maxShadowRenderDistance", String.valueOf(IrisVideoSettings.shadowDistance)); properties.setProperty("colorSpace", IrisVideoSettings.colorSpace.name()); + properties.setProperty("allowUnknownShaders", allowUnknownShaders ? "true" : "false"); // NB: This uses ISO-8859-1 with unicode escapes as the encoding try (OutputStream os = Files.newOutputStream(propertiesPath)) { properties.store(os, COMMENT); } } + + public boolean shouldAllowUnknownShaders() { + return allowUnknownShaders; + } + + public boolean shouldSkip(ResourceLocation value) { + return shadersToSkip.contains(value); // TODO + } } diff --git a/src/main/java/net/irisshaders/iris/gl/shader/StandardMacros.java b/src/main/java/net/irisshaders/iris/gl/shader/StandardMacros.java index d06b27963d..6030ba60be 100644 --- a/src/main/java/net/irisshaders/iris/gl/shader/StandardMacros.java +++ b/src/main/java/net/irisshaders/iris/gl/shader/StandardMacros.java @@ -56,6 +56,10 @@ public static ImmutableList createStandardEnvironmentDefines() { define(standardDefines, "DISTANT_HORIZONS"); } + if (Iris.getIrisConfig().shouldAllowUnknownShaders()) { + define(standardDefines, "ALLOWS_UNKNOWN_SHADERS"); + } + define(standardDefines, "DH_BLOCK_UNKNOWN", String.valueOf(0)); define(standardDefines, "DH_BLOCK_LEAVES", String.valueOf(1)); define(standardDefines, "DH_BLOCK_STONE", String.valueOf(2)); diff --git a/src/main/java/net/irisshaders/iris/gui/screen/ShaderPackScreen.java b/src/main/java/net/irisshaders/iris/gui/screen/ShaderPackScreen.java index 55a8437c5d..fac2762d59 100644 --- a/src/main/java/net/irisshaders/iris/gui/screen/ShaderPackScreen.java +++ b/src/main/java/net/irisshaders/iris/gui/screen/ShaderPackScreen.java @@ -107,6 +107,20 @@ public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) Component.literal("No"))); } + if (Screen.hasControlDown() && InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), GLFW.GLFW_KEY_G)) { + Minecraft.getInstance().setScreen(new ConfirmScreen((option) -> { + try { + Iris.getIrisConfig().setUnknown(option); + } catch (IOException e) { + throw new RuntimeException(e); + } + Minecraft.getInstance().setScreen(this); + }, Component.literal("Unknown shader toggle"), + Component.literal("This allows unknown shaders to load in."), + Component.literal("Enable"), + Component.literal("Disable"))); + } + if (!this.guiHidden) { if (optionMenuOpen && this.shaderOptionList != null) { this.shaderOptionList.render(guiGraphics, mouseX, mouseY, delta); diff --git a/src/main/java/net/irisshaders/iris/mixin/MixinShaderInstance.java b/src/main/java/net/irisshaders/iris/mixin/MixinShaderInstance.java index 78d58f3ef7..271c8716ee 100644 --- a/src/main/java/net/irisshaders/iris/mixin/MixinShaderInstance.java +++ b/src/main/java/net/irisshaders/iris/mixin/MixinShaderInstance.java @@ -2,16 +2,23 @@ import com.google.common.collect.ImmutableSet; import com.google.gson.JsonObject; +import com.mojang.blaze3d.shaders.Program; import com.mojang.blaze3d.shaders.Uniform; import com.mojang.blaze3d.vertex.VertexFormat; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import net.irisshaders.iris.Iris; +import net.irisshaders.iris.compat.SkipList; +import net.irisshaders.iris.gl.GLDebug; import net.irisshaders.iris.gl.IrisRenderSystem; import net.irisshaders.iris.gl.blending.DepthColorStorage; +import net.irisshaders.iris.pipeline.IrisRenderingPipeline; import net.irisshaders.iris.pipeline.ShaderRenderingPipeline; import net.irisshaders.iris.pipeline.WorldRenderingPipeline; import net.irisshaders.iris.pipeline.programs.ExtendedShader; import net.irisshaders.iris.pipeline.programs.FallbackShader; import net.irisshaders.iris.pipeline.programs.ShaderInstanceInterface; +import net.irisshaders.iris.shadows.ShadowRenderer; +import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.ShaderInstance; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.packs.resources.ResourceProvider; @@ -20,7 +27,9 @@ import org.lwjgl.opengl.GL20C; import org.lwjgl.opengl.GL30C; import net.minecraft.util.GsonHelper; +import org.lwjgl.opengl.KHRDebug; import org.slf4j.Logger; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; @@ -30,14 +39,88 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; +import java.io.IOException; import java.io.Reader; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; +import java.util.Map; import java.util.Objects; @Mixin(ShaderInstance.class) public abstract class MixinShaderInstance implements ShaderInstanceInterface { @Unique private static final ImmutableSet ATTRIBUTE_LIST = ImmutableSet.of("Position", "Color", "Normal", "UV0", "UV1", "UV2"); + @Shadow + private static ShaderInstance lastAppliedShader; + @Shadow + @Final + private int programId; + @Shadow + @Final + private Program vertexProgram; + @Shadow + @Final + private Program fragmentProgram; + @Unique + private static final MethodHandle NONE = MethodHandles.constant(Integer.class, 2); + + @Unique + private static final MethodHandle ALWAYS = MethodHandles.constant(Integer.class, 1); + + @Unique + private MethodHandle shouldSkip; + + private static Map, MethodHandle> shouldSkipList = new Object2ObjectOpenHashMap<>(); + + static { + shouldSkipList.put(ExtendedShader.class, NONE); + shouldSkipList.put(FallbackShader.class, NONE); + } + + @Override + public void setShouldSkip(MethodHandle s) { + shouldSkip = s; + } + + @Inject(method = "(Lnet/minecraft/server/packs/resources/ResourceProvider;Lnet/minecraft/resources/ResourceLocation;Lcom/mojang/blaze3d/vertex/VertexFormat;)V", at = @At("TAIL"), require = 0) + private void iriss$storeSkip(ResourceProvider resourceProvider, ResourceLocation string, VertexFormat vertexFormat, CallbackInfo ci) { + shouldSkip = shouldSkipList.computeIfAbsent(getClass(), x -> { + try { + MethodHandle iris$skipDraw = MethodHandles.lookup().findVirtual(x, "iris$skipDraw", MethodType.methodType(boolean.class)); + Iris.logger.warn("Class " + x.getName() + " has opted out of being rendered with shaders."); + return iris$skipDraw; + } catch (NoSuchMethodException | IllegalAccessException e) { + return NONE; + } + }); + + + if (Iris.getIrisConfig().shouldSkip(string)) { + shouldSkip = ALWAYS; + } + } + + public boolean iris$shouldSkipThis() { + if (Iris.getIrisConfig().shouldAllowUnknownShaders()) { + if (ShadowRenderer.ACTIVE) return true; + if (!shouldOverrideShaders()) return false; + + if (shouldSkip == NONE) return false; + if (shouldSkip == ALWAYS) return true; + + try { + return (boolean) shouldSkip.invoke(((ShaderInstance) (Object) this)); + } catch (Throwable e) { + throw new RuntimeException(e); + } + } else { + return !(((Object) this) instanceof ExtendedShader || ((Object) this) instanceof FallbackShader || !shouldOverrideShaders()); + } + } + + @Unique private static boolean shouldOverrideShaders() { WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable(); @@ -70,22 +153,62 @@ private static boolean shouldOverrideShaders() { } } - @Inject(method = "apply", at = @At("TAIL")) + @Inject(method = "", at = @At("RETURN")) + private void name(ResourceProvider resourceProvider, String string, VertexFormat vertexFormat, CallbackInfo ci) { + GLDebug.nameObject(KHRDebug.GL_PROGRAM, this.programId, string); + GLDebug.nameObject(KHRDebug.GL_SHADER, this.vertexProgram.getId(), string); + GLDebug.nameObject(KHRDebug.GL_SHADER, this.fragmentProgram.getId(), string); + } + + @Inject(method = "apply", at = @At("HEAD")) private void iris$lockDepthColorState(CallbackInfo ci) { - if (((Object) this) instanceof ExtendedShader || ((Object) this) instanceof FallbackShader || !shouldOverrideShaders()) { - return; + if (lastAppliedShader != null) { + lastAppliedShader.clear(); + lastAppliedShader = null; } - - DepthColorStorage.disableDepthColor(); } @Inject(method = "clear", at = @At("HEAD")) private void iris$unlockDepthColorState(CallbackInfo ci) { - if (((Object) this) instanceof ExtendedShader || ((Object) this) instanceof FallbackShader || !shouldOverrideShaders()) { + if (!iris$shouldSkipThis()) { + if (!isKnownShader() && shouldOverrideShaders()) { + WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable(); + + if (pipeline instanceof IrisRenderingPipeline) { + Minecraft.getInstance().getMainRenderTarget().bindWrite(false); + } + } + return; } DepthColorStorage.unlockDepthColor(); + + } + + @Inject(method = "apply", at = @At("TAIL")) + private void onTail(CallbackInfo ci) { + if (!iris$shouldSkipThis()) { + if (!isKnownShader() && shouldOverrideShaders()) { + WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable(); + + if (pipeline instanceof IrisRenderingPipeline) { + if (ShadowRenderer.ACTIVE) { + // ((IrisRenderingPipeline) pipeline).bindDefaultShadow(); don't rn + } else { + ((IrisRenderingPipeline) pipeline).bindDefault(); + } + } + } + + return; + } + + DepthColorStorage.disableDepthColor(); + } + + private boolean isKnownShader() { + return ((Object) this) instanceof ExtendedShader || ((Object) this) instanceof FallbackShader; } @Redirect(method = "(Lnet/minecraft/server/packs/resources/ResourceProvider;Lnet/minecraft/resources/ResourceLocation;Lcom/mojang/blaze3d/vertex/VertexFormat;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/GsonHelper;parse(Ljava/io/Reader;)Lcom/google/gson/JsonObject;")) @@ -94,6 +217,27 @@ private static boolean shouldOverrideShaders() { return GsonHelper.parse(reader); } + @Inject(method = "(Lnet/minecraft/server/packs/resources/ResourceProvider;Lnet/minecraft/resources/ResourceLocation;Lcom/mojang/blaze3d/vertex/VertexFormat;)V", at = @At("TAIL"), require = 0) + private void iriss$storeSkipNeo(ResourceProvider resourceProvider, ResourceLocation string, VertexFormat vertexFormat, CallbackInfo ci) { + MethodHandle shouldSkip = shouldSkipList.computeIfAbsent(getClass(), x -> { + try { + MethodHandle iris$skipDraw = MethodHandles.lookup().findVirtual(x, "iris$skipDraw", MethodType.methodType(boolean.class)); + Iris.logger.warn("Class " + x.getName() + " has opted out of being rendered with shaders."); + return iris$skipDraw; + } catch (NoSuchMethodException | IllegalAccessException e) { + return SkipList.NONE; + } + }); + + + if (Iris.getIrisConfig().shouldSkip(string)) { + shouldSkip = ALWAYS; + } + + ((ShaderInstanceInterface) this).setShouldSkip(shouldSkip); + } + + @Override public void iris$createExtraShaders(ResourceProvider provider, ResourceLocation name) { //no-op, used for ExtendedShader to call before the super constructor diff --git a/src/main/java/net/irisshaders/iris/pipeline/IrisRenderingPipeline.java b/src/main/java/net/irisshaders/iris/pipeline/IrisRenderingPipeline.java index 6212a6e93e..0e3dc9da71 100644 --- a/src/main/java/net/irisshaders/iris/pipeline/IrisRenderingPipeline.java +++ b/src/main/java/net/irisshaders/iris/pipeline/IrisRenderingPipeline.java @@ -183,6 +183,11 @@ public class IrisRenderingPipeline implements WorldRenderingPipeline, ShaderRend private ColorSpace currentColorSpace; private CloudSetting dhCloudSetting; + + private GlFramebuffer defaultFB; + private GlFramebuffer defaultFBAlt; + private GlFramebuffer defaultFBShadow; + public IrisRenderingPipeline(ProgramSet programSet) { ShaderPrinter.resetPrintState(); @@ -472,6 +477,8 @@ public IrisRenderingPipeline(ProgramSet programSet) { shadowRenderer = null; } + defaultFBShadow = shadowRenderTargets.createFramebufferWritingToMain(new int[] {0}); + } else { this.shadowClearPasses = ImmutableList.of(); this.shadowClearPassesFull = ImmutableList.of(); @@ -541,6 +548,10 @@ public void process(int target) { } currentColorSpace = IrisVideoSettings.colorSpace; + int defaultTex = packDirectives.getFallbackTex(); + + defaultFB = flippedAfterPrepare.contains(defaultTex) ? renderTargets.createFramebufferWritingToAlt(new int[] { defaultTex }) : renderTargets.createFramebufferWritingToMain(new int[] { defaultTex }); + defaultFBAlt = flippedAfterTranslucent.contains(defaultTex) ? renderTargets.createFramebufferWritingToAlt(new int[] { defaultTex }) : renderTargets.createFramebufferWritingToMain(new int[] { defaultTex }); } private ComputeProgram[] createShadowComputes(ComputeSource[] compute, ProgramSet programSet) { @@ -1214,6 +1225,9 @@ public void destroy() { customImages.forEach(GlImage::destroy); + if (shadowRenderTargets != null) { + shadowRenderTargets.destroy(); + } if (shadowRenderer != null) { shadowRenderer.destroy(); } @@ -1306,4 +1320,16 @@ public GlFramebuffer createDHFramebufferShadow(ProgramSource sources) { public boolean hasShadowRenderTargets() { return shadowRenderTargets != null; } + + public void bindDefault() { + if (isBeforeTranslucent) { + defaultFB.bind(); + } else { + defaultFBAlt.bind(); + } + } + + public void bindDefaultShadow() { + defaultFBShadow.bind(); + } } diff --git a/src/main/java/net/irisshaders/iris/pipeline/fallback/ShaderSynthesizer.java b/src/main/java/net/irisshaders/iris/pipeline/fallback/ShaderSynthesizer.java index 3b4c37c806..1d3a0cb742 100644 --- a/src/main/java/net/irisshaders/iris/pipeline/fallback/ShaderSynthesizer.java +++ b/src/main/java/net/irisshaders/iris/pipeline/fallback/ShaderSynthesizer.java @@ -29,34 +29,34 @@ public static String vsh(boolean hasChunkOffset, ShaderAttributeInputs inputs, F if (inputs.isNewLines()) { shader.append("const float VIEW_SHRINK = 1.0 - (1.0 / 256.0);\n" + - "const mat4 VIEW_SCALE = mat4(\n" + - " VIEW_SHRINK, 0.0, 0.0, 0.0,\n" + - " 0.0, VIEW_SHRINK, 0.0, 0.0,\n" + - " 0.0, 0.0, VIEW_SHRINK, 0.0,\n" + - " 0.0, 0.0, 0.0, 1.0\n" + - ");\n"); + "const mat4 VIEW_SCALE = mat4(\n" + + " VIEW_SHRINK, 0.0, 0.0, 0.0,\n" + + " 0.0, VIEW_SHRINK, 0.0, 0.0,\n" + + " 0.0, 0.0, VIEW_SHRINK, 0.0,\n" + + " 0.0, 0.0, 0.0, 1.0\n" + + ");\n"); shader.append("uniform float LineWidth;\n" + - "uniform vec2 ScreenSize;\n"); + "uniform vec2 ScreenSize;\n"); main.append("vec4 linePosStart = ProjMat * VIEW_SCALE * ModelViewMat * vec4(" + position + ", 1.0);\n" + - " vec4 linePosEnd = ProjMat * VIEW_SCALE * ModelViewMat * vec4(" + position + " + Normal, 1.0);\n" + - "\n" + - " vec3 ndc1 = linePosStart.xyz / linePosStart.w;\n" + - " vec3 ndc2 = linePosEnd.xyz / linePosEnd.w;\n" + - "\n" + - " vec2 lineScreenDirection = normalize((ndc2.xy - ndc1.xy) * ScreenSize);\n" + - " vec2 lineOffset = vec2(-lineScreenDirection.y, lineScreenDirection.x) * LineWidth / ScreenSize;\n" + - "\n" + - " if (lineOffset.x < 0.0) {\n" + - " lineOffset *= -1.0;\n" + - " }\n" + - "\n" + - " if (gl_VertexID % 2 == 0) {\n" + - " gl_Position = vec4((ndc1 + vec3(lineOffset, 0.0)) * linePosStart.w, linePosStart.w);\n" + - " } else {\n" + - " gl_Position = vec4((ndc1 - vec3(lineOffset, 0.0)) * linePosStart.w, linePosStart.w);\n" + - " }\n"); + " vec4 linePosEnd = ProjMat * VIEW_SCALE * ModelViewMat * vec4(" + position + " + Normal, 1.0);\n" + + "\n" + + " vec3 ndc1 = linePosStart.xyz / linePosStart.w;\n" + + " vec3 ndc2 = linePosEnd.xyz / linePosEnd.w;\n" + + "\n" + + " vec2 lineScreenDirection = normalize((ndc2.xy - ndc1.xy) * ScreenSize);\n" + + " vec2 lineOffset = vec2(-lineScreenDirection.y, lineScreenDirection.x) * LineWidth / ScreenSize;\n" + + "\n" + + " if (lineOffset.x < 0.0) {\n" + + " lineOffset *= -1.0;\n" + + " }\n" + + "\n" + + " if (gl_VertexID % 2 == 0) {\n" + + " gl_Position = vec4((ndc1 + vec3(lineOffset, 0.0)) * linePosStart.w, linePosStart.w);\n" + + " } else {\n" + + " gl_Position = vec4((ndc1 - vec3(lineOffset, 0.0)) * linePosStart.w, linePosStart.w);\n" + + " }\n"); } else { main.append(" gl_Position = ProjMat * ModelViewMat * vec4("); main.append(position); @@ -82,13 +82,13 @@ public static String vsh(boolean hasChunkOffset, ShaderAttributeInputs inputs, F // Copied from Mojang code. shader.append("vec4 minecraft_mix_light(vec3 lightDir0, vec3 lightDir1, vec3 normal, vec4 color) {\n" + - " lightDir0 = normalize(lightDir0);\n" + - " lightDir1 = normalize(lightDir1);\n" + - " float light0 = max(0.0, dot(lightDir0, normal));\n" + - " float light1 = max(0.0, dot(lightDir1, normal));\n" + - " float lightAccum = min(1.0, (light0 + light1) * 0.6 + 0.4);\n" + - " return vec4(color.rgb * lightAccum, color.a);\n" + - "}\n"); + " lightDir0 = normalize(lightDir0);\n" + + " lightDir1 = normalize(lightDir1);\n" + + " float light0 = max(0.0, dot(lightDir0, normal));\n" + + " float light1 = max(0.0, dot(lightDir1, normal));\n" + + " float lightAccum = min(1.0, (light0 + light1) * 0.6 + 0.4);\n" + + " return vec4(color.rgb * lightAccum, color.a);\n" + + "}\n"); shader.append("in vec3 Normal;\n"); @@ -244,4 +244,4 @@ public static String fsh(ShaderAttributeInputs inputs, FogMode fogMode, AlphaTes return shader.toString(); } -} +} \ No newline at end of file diff --git a/src/main/java/net/irisshaders/iris/pipeline/programs/ExtendedShader.java b/src/main/java/net/irisshaders/iris/pipeline/programs/ExtendedShader.java index c18dbcfd5a..aba569cecf 100644 --- a/src/main/java/net/irisshaders/iris/pipeline/programs/ExtendedShader.java +++ b/src/main/java/net/irisshaders/iris/pipeline/programs/ExtendedShader.java @@ -38,6 +38,7 @@ import org.lwjgl.opengl.KHRDebug; import java.io.IOException; +import java.lang.invoke.MethodHandle; import java.util.List; import java.util.function.BiConsumer; import java.util.function.Consumer; @@ -276,6 +277,9 @@ public String applyImport(boolean bl, String string) { }); } + @Override + public void setShouldSkip(MethodHandle s) {} + public Program getGeometry() { return this.geometry; } diff --git a/src/main/java/net/irisshaders/iris/pipeline/programs/ShaderInstanceInterface.java b/src/main/java/net/irisshaders/iris/pipeline/programs/ShaderInstanceInterface.java index d374cf1a8c..dc30b25c59 100644 --- a/src/main/java/net/irisshaders/iris/pipeline/programs/ShaderInstanceInterface.java +++ b/src/main/java/net/irisshaders/iris/pipeline/programs/ShaderInstanceInterface.java @@ -4,7 +4,10 @@ import net.minecraft.server.packs.resources.ResourceProvider; import java.io.IOException; +import java.lang.invoke.MethodHandle; public interface ShaderInstanceInterface { void iris$createExtraShaders(ResourceProvider factory, ResourceLocation name) throws IOException; + + void setShouldSkip(MethodHandle s); } diff --git a/src/main/java/net/irisshaders/iris/shaderpack/properties/PackDirectives.java b/src/main/java/net/irisshaders/iris/shaderpack/properties/PackDirectives.java index 132a7e95b7..81bf50ae9b 100644 --- a/src/main/java/net/irisshaders/iris/shaderpack/properties/PackDirectives.java +++ b/src/main/java/net/irisshaders/iris/shaderpack/properties/PackDirectives.java @@ -22,6 +22,7 @@ public class PackDirectives { private final PackRenderTargetDirectives renderTargetDirectives; private final PackShadowDirectives shadowDirectives; private final float drynessHalfLife; + private int fallbackTex; private boolean supportsColorCorrection; private int noiseTextureResolution; private float sunPathRotation; @@ -89,6 +90,9 @@ public PackDirectives(Set supportedRenderTargets, ShaderProperties prop particleRenderingSettings = properties.getParticleRenderingSettings(); textureMap = properties.getCustomTexturePatching(); bufferObjects = properties.getBufferObjects(); + fallbackTex = properties.getFallbackTex(); + + } PackDirectives(Set supportedRenderTargets, PackDirectives directives) { @@ -106,6 +110,7 @@ public PackDirectives(Set supportedRenderTargets, ShaderProperties prop particleRenderingSettings = directives.particleRenderingSettings; textureMap = directives.textureMap; bufferObjects = directives.bufferObjects; + fallbackTex = directives.fallbackTex; } private static float clamp(float val, float lo, float hi) { @@ -312,4 +317,8 @@ public Vector2i getTextureScaleOverride(int index, int dimensionX, int dimension return scale; } + + public int getFallbackTex() { + return fallbackTex; + } } diff --git a/src/main/java/net/irisshaders/iris/shaderpack/properties/ProgramDirectives.java b/src/main/java/net/irisshaders/iris/shaderpack/properties/ProgramDirectives.java index 33b032c4c2..2f5d7c2df1 100644 --- a/src/main/java/net/irisshaders/iris/shaderpack/properties/ProgramDirectives.java +++ b/src/main/java/net/irisshaders/iris/shaderpack/properties/ProgramDirectives.java @@ -36,6 +36,7 @@ public class ProgramDirectives { private final ImmutableMap explicitFlips; private boolean unknownDrawBuffers; + private ProgramDirectives(int[] drawBuffers, ViewportData viewportScale, @Nullable AlphaTest alphaTestOverride, Optional blendModeOverride, List bufferBlendInformations, ImmutableSet mipmappedBuffers, ImmutableMap explicitFlips) { diff --git a/src/main/java/net/irisshaders/iris/shaderpack/properties/ShaderProperties.java b/src/main/java/net/irisshaders/iris/shaderpack/properties/ShaderProperties.java index 67faf6aa21..7d3d40d608 100644 --- a/src/main/java/net/irisshaders/iris/shaderpack/properties/ShaderProperties.java +++ b/src/main/java/net/irisshaders/iris/shaderpack/properties/ShaderProperties.java @@ -115,6 +115,9 @@ public class ShaderProperties { private List requiredFeatureFlags = new ArrayList<>(); private List optionalFeatureFlags = new ArrayList<>(); + private int fallbackTex = 0; + + private ShaderProperties() { // empty } @@ -222,6 +225,8 @@ public ShaderProperties(String contents, ShaderPackOptions shaderPackOptions, It }); handleBooleanDirective(key, value, "prepareBeforeShadow", bool -> prepareBeforeShadow = bool); handleBooleanDirective(key, value, "supportsColorCorrection", bool -> supportsColorCorrection = bool); + handleIntDirective(key, value, "fallbackTex", bool -> fallbackTex = bool); + if (key.startsWith("particles.ordering")) { Optional settings = ParticleRenderingSettings.fromString(value.trim().toUpperCase(Locale.US)); @@ -951,4 +956,8 @@ public CustomUniforms.Builder getCustomUniforms() { public CloudSetting getDHCloudSetting() { return dhCloudSetting; } + + public int getFallbackTex() { + return fallbackTex; + } } diff --git a/src/main/java/net/irisshaders/iris/shadows/ShadowRenderer.java b/src/main/java/net/irisshaders/iris/shadows/ShadowRenderer.java index bc759726c8..cf85f6ecd3 100644 --- a/src/main/java/net/irisshaders/iris/shadows/ShadowRenderer.java +++ b/src/main/java/net/irisshaders/iris/shadows/ShadowRenderer.java @@ -718,7 +718,6 @@ private String getBlockEntitiesDebugString() { } public void destroy() { - targets.destroy(); ((MemoryTrackingRenderBuffers) buffers).freeAndDeleteBuffers(); }