diff --git a/src/main/java/net/coderbot/iris/Iris.java b/src/main/java/net/coderbot/iris/Iris.java index 0900177688..277117b5a2 100644 --- a/src/main/java/net/coderbot/iris/Iris.java +++ b/src/main/java/net/coderbot/iris/Iris.java @@ -14,6 +14,7 @@ import net.coderbot.iris.pipeline.WorldRenderingPipeline; import net.coderbot.iris.pipeline.newshader.NewWorldRenderingPipeline; import net.coderbot.iris.shaderpack.DimensionId; +import net.coderbot.iris.shaderpack.IrisDefines; import net.coderbot.iris.shaderpack.OptionalBoolean; import net.coderbot.iris.shaderpack.ProgramSet; import net.coderbot.iris.shaderpack.ShaderPack; diff --git a/src/main/java/net/coderbot/iris/gl/shader/StandardMacros.java b/src/main/java/net/coderbot/iris/gl/shader/StandardMacros.java index b130660aed..515761e18c 100644 --- a/src/main/java/net/coderbot/iris/gl/shader/StandardMacros.java +++ b/src/main/java/net/coderbot/iris/gl/shader/StandardMacros.java @@ -38,7 +38,7 @@ private static void define(List defines, String key, String value) { defines.add(new StringPair(key, value)); } - public static Iterable createStandardEnvironmentDefines() { + public static ImmutableList createStandardEnvironmentDefines() { ArrayList standardDefines = new ArrayList<>(); define(standardDefines, "MC_VERSION", getMcVersion()); diff --git a/src/main/java/net/coderbot/iris/rendertarget/RenderTargets.java b/src/main/java/net/coderbot/iris/rendertarget/RenderTargets.java index cc76d1bce3..d5559f80c0 100644 --- a/src/main/java/net/coderbot/iris/rendertarget/RenderTargets.java +++ b/src/main/java/net/coderbot/iris/rendertarget/RenderTargets.java @@ -372,4 +372,10 @@ public int getCurrentWidth() { public int getCurrentHeight() { return cachedHeight; } + + public void createIfUnsure(int index) { + if (targets[index] == null) { + create(index); + } + } } diff --git a/src/main/java/net/coderbot/iris/samplers/IrisImages.java b/src/main/java/net/coderbot/iris/samplers/IrisImages.java index 3cd91f0c22..d5a39e1d95 100644 --- a/src/main/java/net/coderbot/iris/samplers/IrisImages.java +++ b/src/main/java/net/coderbot/iris/samplers/IrisImages.java @@ -23,6 +23,8 @@ public static void addRenderTargetImages(ImageHolder images, Supplier { ImmutableSet flippedBuffers = flipped.get(); diff --git a/src/main/java/net/coderbot/iris/samplers/IrisSamplers.java b/src/main/java/net/coderbot/iris/samplers/IrisSamplers.java index 38bf55a8ad..f9f9aa55b5 100644 --- a/src/main/java/net/coderbot/iris/samplers/IrisSamplers.java +++ b/src/main/java/net/coderbot/iris/samplers/IrisSamplers.java @@ -78,6 +78,10 @@ public static void addRenderTargetSamplers(SamplerHolder samplers, Supplier\\d+)\\.(?\\d+)\\.*(?\\d*)(.*)"); + + private static void define(List defines, String key) { + defines.add(new StringPair(key, "")); + } + + private static void define(List defines, String key, String value) { + defines.add(new StringPair(key, value)); + } + + public static ImmutableList createIrisReplacements() { + ArrayList s = new ArrayList<>(StandardMacros.createStandardEnvironmentDefines()); + define(s, "PPT_NONE", "0"); + define(s, "PPT_RAIN", "1"); + define(s, "PPT_SNOW", "2"); + define(s, "BIOME_SWAMP_HILLS", "-1"); + + BiomeParameters.getBiomeMap().forEach((biome, id) -> define(s, "BIOME_" + biome.location().getPath().toUpperCase(Locale.ROOT), String.valueOf(id))); + + BiomeCategories[] categories = BiomeCategories.values(); + for (int i = 0; i < categories.length; i++) { + define(s, "CAT_" + categories[i].name().toUpperCase(Locale.ROOT), String.valueOf(i)); + } + + return ImmutableList.copyOf(s); + } +} diff --git a/src/main/java/net/coderbot/iris/shaderpack/ShaderPack.java b/src/main/java/net/coderbot/iris/shaderpack/ShaderPack.java index f9edbcd61f..6d733e3213 100644 --- a/src/main/java/net/coderbot/iris/shaderpack/ShaderPack.java +++ b/src/main/java/net/coderbot/iris/shaderpack/ShaderPack.java @@ -45,17 +45,7 @@ import java.nio.file.Files; import java.nio.file.NoSuchFileException; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Collections; -import java.util.EnumMap; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.Properties; -import java.util.Set; +import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -161,9 +151,10 @@ public ShaderPack(Path root, Map changedConfigs, Iterable replacements = IrisDefines.createIrisReplacements(); Iterable finalEnvironmentDefines = environmentDefines; this.shaderProperties = loadProperties(root, "shaders.properties") - .map(source -> new ShaderProperties(source, shaderPackOptions, finalEnvironmentDefines)) + .map(source -> new ShaderProperties(source, shaderPackOptions, finalEnvironmentDefines, replacements)) .orElseGet(ShaderProperties::empty); activeFeatures = new HashSet<>(); @@ -248,7 +239,8 @@ public ShaderPack(Path root, Map changedConfigs, Iterable finalEnvironmentDefines1 = environmentDefines; + ArrayList finalEnvironmentDefines1 = new ArrayList<>((Collection) finalEnvironmentDefines); + finalEnvironmentDefines1.addAll(IrisDefines.createIrisReplacements()); this.sourceProvider = (path) -> { String pathString = path.getPathString(); // Removes the first "/" in the path if present, and the file diff --git a/src/main/java/net/coderbot/iris/shaderpack/ShaderProperties.java b/src/main/java/net/coderbot/iris/shaderpack/ShaderProperties.java index 31e12f2657..32bb6eddf8 100644 --- a/src/main/java/net/coderbot/iris/shaderpack/ShaderProperties.java +++ b/src/main/java/net/coderbot/iris/shaderpack/ShaderProperties.java @@ -111,7 +111,11 @@ private ShaderProperties() { } // TODO: Is there a better solution than having ShaderPack pass a root path to ShaderProperties to be able to read textures? - public ShaderProperties(String contents, ShaderPackOptions shaderPackOptions, Iterable environmentDefines) { + public ShaderProperties(String contents, ShaderPackOptions shaderPackOptions, Iterable environmentDefines, Iterable replacements) { + for (StringPair pair : replacements) { + contents = contents.replace(pair.getKey(), pair.getValue()); + } + String preprocessedContents = PropertiesPreprocessor.preprocessSource(contents, shaderPackOptions, environmentDefines); Properties preprocessed = new OrderBackedProperties(); diff --git a/src/main/java/net/coderbot/iris/uniforms/BiomeParameters.java b/src/main/java/net/coderbot/iris/uniforms/BiomeParameters.java index 674715c1ca..4638325977 100644 --- a/src/main/java/net/coderbot/iris/uniforms/BiomeParameters.java +++ b/src/main/java/net/coderbot/iris/uniforms/BiomeParameters.java @@ -30,7 +30,6 @@ public static Object2IntMap> getBiomeMap() { } public static void addBiomeUniforms(UniformHolder uniforms) { - uniforms .uniform1i(PER_TICK, "biome", playerI(player -> biomeMap.getInt(player.level().getBiome(player.blockPosition()).unwrapKey().orElse(null)))) @@ -56,21 +55,7 @@ public static void addBiomeUniforms(UniformHolder uniforms) { .uniform1f(PER_TICK, "rainfall", playerF(player -> ((ExtendedBiome) (Object) player.level().getBiome(player.blockPosition()).value()).getDownfall())) .uniform1f(PER_TICK, "temperature", playerF(player -> - player.level().getBiome(player.blockPosition()).value().getBaseTemperature())) - - - .uniform1i(ONCE, "PPT_NONE", () -> 0) - .uniform1i(ONCE, "PPT_RAIN", () -> 1) - .uniform1i(ONCE, "PPT_SNOW", () -> 2) - // Temporary fix for Sildur's Vibrant - .uniform1i(ONCE, "BIOME_SWAMP_HILLS", () -> -1); - - - - - addBiomes(uniforms); - addCategories(uniforms); - + player.level().getBiome(player.blockPosition()).value().getBaseTemperature())); } private static BiomeCategories getBiomeCategory(Holder holder) { @@ -114,18 +99,6 @@ private static BiomeCategories getBiomeCategory(Holder holder) { } } - private static void addBiomes(UniformHolder uniforms) { - biomeMap.forEach((biome, id) -> uniforms.uniform1i(ONCE, "BIOME_" + biome.location().getPath().toUpperCase(Locale.ROOT), () -> id)); - } - - public static void addCategories(UniformHolder uniforms) { - BiomeCategories[] categories = BiomeCategories.values(); - for (int i = 0; i < categories.length; i++) { - int finalI = i; - uniforms.uniform1i(ONCE, "CAT_" + categories[i].name().toUpperCase(Locale.ROOT), () -> finalI); - } - } - static IntSupplier playerI(ToIntFunction function) { return () -> { LocalPlayer player = Minecraft.getInstance().player;