Search in sources :

Example 1 with ShaderPack

use of net.coderbot.iris.shaderpack.ShaderPack in project Iris by IrisShaders.

the class IdMapTest method testLoadIdMaps.

@Test
void testLoadIdMaps() {
    ShaderPack shaderPack;
    // ensure that we can actually load the shader pack
    try {
        shaderPack = new ShaderPack(IrisTests.getTestShaderPackPath("id_maps"));
    } catch (Exception e) {
        Assertions.fail("Couldn't load test shader pack id_maps", e);
        return;
    }
    Map<NamespacedId, BlockRenderType> overrides = shaderPack.getIdMap().getBlockRenderTypeMap();
    Int2ObjectMap<List<BlockEntry>> blocks = shaderPack.getIdMap().getBlockProperties();
    Assertions.assertEquals(EXPECTED_LAYERS, overrides);
    Assertions.assertEquals(EXPECTED_BLOCKS, blocks);
}
Also used : NamespacedId(net.coderbot.iris.shaderpack.materialmap.NamespacedId) BlockRenderType(net.coderbot.iris.shaderpack.materialmap.BlockRenderType) List(java.util.List) ShaderPack(net.coderbot.iris.shaderpack.ShaderPack) Test(org.junit.jupiter.api.Test)

Example 2 with ShaderPack

use of net.coderbot.iris.shaderpack.ShaderPack in project Iris by IrisShaders.

the class LanguageMapTest method testLoadLanguages.

@Test
void testLoadLanguages() {
    ShaderPack shaderPack;
    // ensure that we can actually load the shader pack
    try {
        shaderPack = new ShaderPack(IrisTests.getTestShaderPackPath("language_maps"));
    } catch (Exception e) {
        Assertions.fail("Couldn't load test shader pack language_maps", e);
        return;
    }
    // ensure that we only loaded two language files
    LanguageMap languageMap = shaderPack.getLanguageMap();
    Assertions.assertEquals(2, languageMap.getLanguages().size(), "number of languages loaded");
    // test that en_US.lang was loaded properly
    {
        Map<String, String> english = languageMap.getTranslations("en_us");
        Assertions.assertNotNull(english, "en_us translations");
        Assertions.assertEquals(2, english.size(), "number of translations in en_US.lang");
        Assertions.assertEquals("Test screen", english.get("screen.TEST"));
        Assertions.assertEquals("Test option", english.get("option.TEST_OPTION"));
    }
    // test that fr_FR.lang was loaded properly
    {
        Map<String, String> french = languageMap.getTranslations("fr_fr");
        Assertions.assertNotNull(french, "fr_fr translations");
        Assertions.assertEquals(1, french.size(), "number of translations in fr_FR.lang");
        Assertions.assertEquals("Écran de test", french.get("screen.TEST"));
    }
}
Also used : LanguageMap(net.coderbot.iris.shaderpack.LanguageMap) ShaderPack(net.coderbot.iris.shaderpack.ShaderPack) Map(java.util.Map) LanguageMap(net.coderbot.iris.shaderpack.LanguageMap) Test(org.junit.jupiter.api.Test)

Example 3 with ShaderPack

use of net.coderbot.iris.shaderpack.ShaderPack in project Iris by IrisShaders.

the class OptionApplyTest method testOptions.

// @Test
// TODO: Re-enable this once we can load shader packs in tests without referencing OpenGL / LWJGL / Minecraft.
void testOptions() {
    ShaderPack shaderPack;
    // ensure that we can actually load the shader pack
    try {
        shaderPack = new ShaderPack(IrisTests.getTestShaderPackPath("options"));
    } catch (Exception e) {
        Assertions.fail("Couldn't load test shader pack options", e);
        return;
    }
    ProgramSource basic = shaderPack.getProgramSet(DimensionId.OVERWORLD).getGbuffersBasic().orElseThrow(RuntimeException::new);
    String basicVsh = basic.getVertexSource().orElseThrow(RuntimeException::new);
    String basicFsh = basic.getFragmentSource().orElseThrow(RuntimeException::new);
    OptionAnnotatedSource basicVshAnnotated = new OptionAnnotatedSource(basicVsh);
    OptionAnnotatedSource basicFshAnnotated = new OptionAnnotatedSource(basicFsh);
    // TODO: Separate includes will need more complex boolean define reference behavior
    OptionSet basicVshSet = basicVshAnnotated.getOptionSet(AbsolutePackPath.fromAbsolutePath("/basic.vsh"), basicVshAnnotated.getBooleanDefineReferences().keySet());
    OptionSet basicFshSet = basicFshAnnotated.getOptionSet(AbsolutePackPath.fromAbsolutePath("/basic.fsh"), basicFshAnnotated.getBooleanDefineReferences().keySet());
    OptionSet.Builder setBuilder = OptionSet.builder();
    setBuilder.addAll(basicVshSet);
    setBuilder.addAll(basicFshSet);
    OptionSet options = setBuilder.build();
    Map<String, String> changes = ImmutableMap.of("SHADOWS", "false", "ambientOcclusionLevel", "0.0", "shadowDistance", "64", "ANNOYING_STUFF", "true", "GODRAYS", "16");
    OptionValues values = new MutableOptionValues(options, changes);
    System.out.println(basicVshAnnotated.apply(values));
    System.out.println(basicFshAnnotated.apply(values));
    System.out.println(options);
}
Also used : MutableOptionValues(net.coderbot.iris.shaderpack.option.values.MutableOptionValues) ProgramSource(net.coderbot.iris.shaderpack.ProgramSource) MutableOptionValues(net.coderbot.iris.shaderpack.option.values.MutableOptionValues) OptionValues(net.coderbot.iris.shaderpack.option.values.OptionValues) OptionAnnotatedSource(net.coderbot.iris.shaderpack.option.OptionAnnotatedSource) OptionSet(net.coderbot.iris.shaderpack.option.OptionSet) ShaderPack(net.coderbot.iris.shaderpack.ShaderPack)

Example 4 with ShaderPack

use of net.coderbot.iris.shaderpack.ShaderPack in project Iris by IrisShaders.

the class Iris method loadExternalShaderpack.

private static boolean loadExternalShaderpack(String name) {
    Path shaderPackRoot;
    Path shaderPackConfigTxt;
    try {
        shaderPackRoot = getShaderpacksDirectory().resolve(name);
        shaderPackConfigTxt = getShaderpacksDirectory().resolve(name + ".txt");
    } catch (InvalidPathException e) {
        logger.error("Failed to load the shaderpack \"{}\" because it contains invalid characters in its path", name);
        return false;
    }
    Path shaderPackPath;
    if (shaderPackRoot.toString().endsWith(".zip")) {
        Optional<Path> optionalPath;
        try {
            optionalPath = loadExternalZipShaderpack(shaderPackRoot);
        } catch (FileSystemNotFoundException | NoSuchFileException e) {
            logger.error("Failed to load the shaderpack \"{}\" because it does not exist in your shaderpacks folder!", name);
            return false;
        } catch (ZipException e) {
            logger.error("The shaderpack \"{}\" appears to be corrupted, please try downloading it again!", name);
            return false;
        } catch (IOException e) {
            logger.error("Failed to load the shaderpack \"{}\"!", name);
            logger.error("", e);
            return false;
        }
        if (optionalPath.isPresent()) {
            shaderPackPath = optionalPath.get();
        } else {
            logger.error("Could not load the shaderpack \"{}\" because it appears to lack a \"shaders\" directory", name);
            return false;
        }
    } else {
        if (!Files.exists(shaderPackRoot)) {
            logger.error("Failed to load the shaderpack \"{}\" because it does not exist!", name);
            return false;
        }
        // If it's a folder-based shaderpack, just use the shaders subdirectory
        shaderPackPath = shaderPackRoot.resolve("shaders");
    }
    if (!Files.exists(shaderPackPath)) {
        logger.error("Could not load the shaderpack \"{}\" because it appears to lack a \"shaders\" directory", name);
        return false;
    }
    Map<String, String> changedConfigs = tryReadConfigProperties(shaderPackConfigTxt).map(properties -> (Map<String, String>) (Map) properties).orElse(new HashMap<>());
    changedConfigs.putAll(shaderPackOptionQueue);
    clearShaderPackOptionQueue();
    if (resetShaderPackOptions) {
        changedConfigs.clear();
    }
    resetShaderPackOptions = false;
    try {
        currentPack = new ShaderPack(shaderPackPath, changedConfigs);
        MutableOptionValues changedConfigsValues = currentPack.getShaderPackOptions().getOptionValues().mutableCopy();
        // Store changed values from those currently in use by the shader pack
        Properties configsToSave = new Properties();
        changedConfigsValues.getBooleanValues().forEach((k, v) -> configsToSave.setProperty(k, Boolean.toString(v)));
        changedConfigsValues.getStringValues().forEach(configsToSave::setProperty);
        tryUpdateConfigPropertiesFile(shaderPackConfigTxt, configsToSave);
    } catch (Exception e) {
        logger.error("Failed to load the shaderpack \"{}\"!", name);
        logger.error("", e);
        return false;
    }
    currentPackName = name;
    logger.info("Using shaderpack: " + name);
    return true;
}
Also used : Path(java.nio.file.Path) FabricLoader(net.fabricmc.loader.api.FabricLoader) NoSuchFileException(java.nio.file.NoSuchFileException) InputConstants(com.mojang.blaze3d.platform.InputConstants) ShaderPackScreen(net.coderbot.iris.gui.screen.ShaderPackScreen) MutableOptionValues(net.coderbot.iris.shaderpack.option.values.MutableOptionValues) Level(org.apache.logging.log4j.Level) HashMap(java.util.HashMap) ClientLevel(net.minecraft.client.multiplayer.ClientLevel) DimensionType(net.minecraft.world.level.dimension.DimensionType) ShaderpackDirectoryManager(net.coderbot.iris.shaderpack.discovery.ShaderpackDirectoryManager) InvalidPathException(java.nio.file.InvalidPathException) SodiumVersionCheck(net.coderbot.iris.compat.sodium.SodiumVersionCheck) Minecraft(net.minecraft.client.Minecraft) ChatFormatting(net.minecraft.ChatFormatting) Map(java.util.Map) OptionValues(net.coderbot.iris.shaderpack.option.values.OptionValues) IrisConfig(net.coderbot.iris.config.IrisConfig) Path(java.nio.file.Path) ModContainer(net.fabricmc.loader.api.ModContainer) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) OutputStream(java.io.OutputStream) OptionalBoolean(net.coderbot.iris.shaderpack.OptionalBoolean) ClientModInitializer(net.fabricmc.api.ClientModInitializer) OptionSet(net.coderbot.iris.shaderpack.option.OptionSet) Properties(java.util.Properties) ZipException(java.util.zip.ZipException) FileSystemNotFoundException(java.nio.file.FileSystemNotFoundException) Files(java.nio.file.Files) KeyBindingHelper(net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper) Throwables(com.google.common.base.Throwables) Profile(net.coderbot.iris.shaderpack.option.Profile) IOException(java.io.IOException) FileSystem(java.nio.file.FileSystem) net.coderbot.iris.pipeline(net.coderbot.iris.pipeline) ResourceKey(net.minecraft.resources.ResourceKey) GLFW(org.lwjgl.glfw.GLFW) ProgramSet(net.coderbot.iris.shaderpack.ProgramSet) ShaderPack(net.coderbot.iris.shaderpack.ShaderPack) ZipError(java.util.zip.ZipError) Logger(org.apache.logging.log4j.Logger) DimensionId(net.coderbot.iris.shaderpack.DimensionId) Optional(java.util.Optional) KeyMapping(net.minecraft.client.KeyMapping) IrisApi(net.irisshaders.iris.api.v0.IrisApi) NotNull(org.jetbrains.annotations.NotNull) LogManager(org.apache.logging.log4j.LogManager) FileSystems(java.nio.file.FileSystems) MutableOptionValues(net.coderbot.iris.shaderpack.option.values.MutableOptionValues) NoSuchFileException(java.nio.file.NoSuchFileException) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) Properties(java.util.Properties) InvalidPathException(java.nio.file.InvalidPathException) NoSuchFileException(java.nio.file.NoSuchFileException) InvalidPathException(java.nio.file.InvalidPathException) ZipException(java.util.zip.ZipException) FileSystemNotFoundException(java.nio.file.FileSystemNotFoundException) IOException(java.io.IOException) FileSystemNotFoundException(java.nio.file.FileSystemNotFoundException) HashMap(java.util.HashMap) Map(java.util.Map) ShaderPack(net.coderbot.iris.shaderpack.ShaderPack)

Example 5 with ShaderPack

use of net.coderbot.iris.shaderpack.ShaderPack in project Iris by IrisShaders.

the class Iris method loadExternalZipShaderpack.

private static Optional<Path> loadExternalZipShaderpack(Path shaderpackPath) throws IOException {
    FileSystem zipSystem = FileSystems.newFileSystem(shaderpackPath, Iris.class.getClassLoader());
    zipFileSystem = zipSystem;
    // Should only be one root directory for a zip shaderpack
    Path root = zipSystem.getRootDirectories().iterator().next();
    Path potentialShaderDir = zipSystem.getPath("shaders");
    // Otherwise, manually search through each directory path until it ends with "shaders"
    if (Files.exists(potentialShaderDir)) {
        return Optional.of(potentialShaderDir);
    }
    // This makes it hard to determine what is the actual shaders dir
    return Files.walk(root).filter(Files::isDirectory).filter(path -> path.endsWith("shaders")).findFirst();
}
Also used : Path(java.nio.file.Path) FabricLoader(net.fabricmc.loader.api.FabricLoader) NoSuchFileException(java.nio.file.NoSuchFileException) InputConstants(com.mojang.blaze3d.platform.InputConstants) ShaderPackScreen(net.coderbot.iris.gui.screen.ShaderPackScreen) MutableOptionValues(net.coderbot.iris.shaderpack.option.values.MutableOptionValues) Level(org.apache.logging.log4j.Level) HashMap(java.util.HashMap) ClientLevel(net.minecraft.client.multiplayer.ClientLevel) DimensionType(net.minecraft.world.level.dimension.DimensionType) ShaderpackDirectoryManager(net.coderbot.iris.shaderpack.discovery.ShaderpackDirectoryManager) InvalidPathException(java.nio.file.InvalidPathException) SodiumVersionCheck(net.coderbot.iris.compat.sodium.SodiumVersionCheck) Minecraft(net.minecraft.client.Minecraft) ChatFormatting(net.minecraft.ChatFormatting) Map(java.util.Map) OptionValues(net.coderbot.iris.shaderpack.option.values.OptionValues) IrisConfig(net.coderbot.iris.config.IrisConfig) Path(java.nio.file.Path) ModContainer(net.fabricmc.loader.api.ModContainer) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) OutputStream(java.io.OutputStream) OptionalBoolean(net.coderbot.iris.shaderpack.OptionalBoolean) ClientModInitializer(net.fabricmc.api.ClientModInitializer) OptionSet(net.coderbot.iris.shaderpack.option.OptionSet) Properties(java.util.Properties) ZipException(java.util.zip.ZipException) FileSystemNotFoundException(java.nio.file.FileSystemNotFoundException) Files(java.nio.file.Files) KeyBindingHelper(net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper) Throwables(com.google.common.base.Throwables) Profile(net.coderbot.iris.shaderpack.option.Profile) IOException(java.io.IOException) FileSystem(java.nio.file.FileSystem) net.coderbot.iris.pipeline(net.coderbot.iris.pipeline) ResourceKey(net.minecraft.resources.ResourceKey) GLFW(org.lwjgl.glfw.GLFW) ProgramSet(net.coderbot.iris.shaderpack.ProgramSet) ShaderPack(net.coderbot.iris.shaderpack.ShaderPack) ZipError(java.util.zip.ZipError) Logger(org.apache.logging.log4j.Logger) DimensionId(net.coderbot.iris.shaderpack.DimensionId) Optional(java.util.Optional) KeyMapping(net.minecraft.client.KeyMapping) IrisApi(net.irisshaders.iris.api.v0.IrisApi) NotNull(org.jetbrains.annotations.NotNull) LogManager(org.apache.logging.log4j.LogManager) FileSystems(java.nio.file.FileSystems) FileSystem(java.nio.file.FileSystem) Files(java.nio.file.Files)

Aggregations

ShaderPack (net.coderbot.iris.shaderpack.ShaderPack)8 IOException (java.io.IOException)3 Files (java.nio.file.Files)3 Path (java.nio.file.Path)3 Map (java.util.Map)3 Optional (java.util.Optional)3 Properties (java.util.Properties)3 OptionSet (net.coderbot.iris.shaderpack.option.OptionSet)3 MutableOptionValues (net.coderbot.iris.shaderpack.option.values.MutableOptionValues)3 OptionValues (net.coderbot.iris.shaderpack.option.values.OptionValues)3 IrisApi (net.irisshaders.iris.api.v0.IrisApi)3 ChatFormatting (net.minecraft.ChatFormatting)3 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)3 GLFW (org.lwjgl.glfw.GLFW)3 Throwables (com.google.common.base.Throwables)2 InputConstants (com.mojang.blaze3d.platform.InputConstants)2 OutputStream (java.io.OutputStream)2 FileSystem (java.nio.file.FileSystem)2 FileSystemNotFoundException (java.nio.file.FileSystemNotFoundException)2 FileSystems (java.nio.file.FileSystems)2