Support fabulous shaders

This commit is contained in:
JFronny 2021-10-03 19:26:26 +02:00
parent 97010cb1de
commit a06823a63c
No known key found for this signature in database
GPG Key ID: BEC5ACBBD4EE17E5
9 changed files with 44 additions and 26 deletions

View File

@ -3,7 +3,7 @@ Here is everything you need to know about configuring your resource with respack
Some pages may not have been updated, you can view those [here](old/)
### Compatibility
- Canvas/Frex Shaders
- Fabulous/Canvas/Frex Shaders
- Resource Packs
- DataPacks

View File

@ -1,8 +1,4 @@
# Usage in canvas/frex shaders
## Background
The FREX shader API (which shaders targeting the Canvas renderer utilize) allows other mods to register config code which shaders may `#include`.
Respackopts is one of such mods and utilizes this feature to expose the packs respackopts config.
# Usage in fabulous/canvas/frex shaders
## Getting started
All you need to do to access respackotps values is paste the following in a file where you want them: `#include respackopts:config_supplier`
However, usually you will want to still have a pack that works if respackotps is not present. In that case, canvas will still load the file,

View File

@ -18,8 +18,8 @@ nav:
- 'ToggleFiles.md'
- 'ToggleFilesWithFallback.md'
- 'MultipleFileSelection.md'
- 'Mod integrations':
- 'Canvas.md'
- 'Other usages':
- 'Shaders.md'
- 'Old wiki':
- About: 'old/README.md'
- home: 'old/home.md'

View File

@ -62,6 +62,8 @@ public class Respackopts implements ClientModInitializer {
public static boolean forcePackReload = false;
public static Path CONF_DIR;
public static ConfigFile CONFIG;
public static final Identifier RPO_SHADER_ID = new Identifier(Respackopts.ID, "config_supplier");
private static String shaderImportSource;
static {
GSON = new GsonBuilder()
@ -114,6 +116,16 @@ public class Respackopts implements ClientModInitializer {
STAR_SCRIPT.set(sanitizeString(e.getKey()), () -> e.getValue().buildStarscript());
}
});
SAVE_ACTIONS.add(() -> {
if (CONFIG.debugLogs)
LOGGER.info("Generating FREX shader code");
StringBuilder sb = new StringBuilder();
sb.append("#define respackopts_loaded");
for (Map.Entry<String, ConfigBranch> e : CONFIG_BRANCH.entrySet()) {
e.getValue().buildShader(sb, sanitizeString(e.getKey()));
}
shaderImportSource = sb.toString();
});
DirFilterEventImpl.init();
FileFilterEventImpl.init();
if (CONFIG.debugCommands)
@ -179,4 +191,12 @@ public class Respackopts implements ClientModInitializer {
}
return CompletableFuture.completedFuture(null);
}
public static String getShaderImportSource() {
if (shaderImportSource == null) {
Respackopts.LOGGER.error("Shader import source is null");
return "";
}
return shaderImportSource;
}
}

View File

@ -2,17 +2,13 @@ package io.gitlab.jfronny.respackopts.integration;
import grondag.frex.FrexInitializer;
import io.gitlab.jfronny.respackopts.Respackopts;
import io.gitlab.jfronny.respackopts.data.entry.ConfigBranch;
import io.vram.frex.api.config.ShaderConfig;
import net.minecraft.util.Identifier;
import java.util.Map;
public class FrexCompat implements FrexInitializer {
boolean initial = true;
@Override
public void onInitalizeFrex() {
ShaderConfig.registerShaderConfigSupplier(new Identifier(Respackopts.ID, "config_supplier"), FrexCompat::generateShader);
ShaderConfig.registerShaderConfigSupplier(Respackopts.RPO_SHADER_ID, Respackopts::getShaderImportSource);
Respackopts.LOGGER.info("enabled frex/canvas support");
Respackopts.SAVE_ACTIONS.add(() -> {
try {
@ -26,14 +22,4 @@ public class FrexCompat implements FrexInitializer {
});
}
public static String generateShader() {
if (Respackopts.CONFIG.debugLogs)
Respackopts.LOGGER.info("Generating FREX shader code");
StringBuilder sb = new StringBuilder();
sb.append("#define respackopts_loaded");
for (Map.Entry<String, ConfigBranch> e : Respackopts.CONFIG_BRANCH.entrySet()) {
e.getValue().buildShader(sb, Respackopts.sanitizeString(e.getKey()));
}
return sb.toString();
}
}

View File

@ -0,0 +1,15 @@
package io.gitlab.jfronny.respackopts.mixin;
import io.gitlab.jfronny.respackopts.Respackopts;
import net.minecraft.client.gl.GLImportProcessor;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;
@Mixin(GLImportProcessor.class)
public class GLImportProcessorMixin {
@ModifyArg(method = "readSource(Ljava/lang/String;)Ljava/util/List;", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gl/GLImportProcessor;parseImports(Ljava/lang/String;Lnet/minecraft/client/gl/GLImportProcessor$Context;Ljava/lang/String;)Ljava/util/List;"), index = 0)
private String modify(String value) {
return value.replace("#include " + Respackopts.RPO_SHADER_ID, Respackopts.getShaderImportSource());
}
}

View File

@ -56,6 +56,7 @@ public class ResourcePackManagerMixin {
}
}
});
Respackopts.save();
}
private MetadataLocateResult rpo$locateMetadata(ResourcePackProfile v) {

View File

@ -2,7 +2,6 @@ package io.gitlab.jfronny.respackopts.util;
import io.gitlab.jfronny.respackopts.Respackopts;
import io.gitlab.jfronny.respackopts.data.entry.ConfigBranch;
import io.gitlab.jfronny.respackopts.integration.FrexCompat;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import net.minecraft.text.Text;
@ -20,7 +19,7 @@ public class RpoCommand {
private static final ModContainer respackotps = FabricLoader.getInstance().getModContainer(Respackopts.ID).get();
public static void register() {
DISPATCHER.register(literal("rpo").then(literal("dump").then(literal("frex").executes(ctx -> {
ctx.getSource().sendFeedback(dump(FrexCompat.generateShader(), "frex.glsl"));
ctx.getSource().sendFeedback(dump(Respackopts.getShaderImportSource(), "frex.glsl"));
return 1;
}))));
DISPATCHER.register(literal("rpo").then(literal("dump").then(literal("config").executes(ctx -> {

View File

@ -8,7 +8,8 @@
"client": [
"OptionsScreenMixin",
"ResourcePackEntryMixin",
"ResourcePackManagerMixin"
"ResourcePackManagerMixin",
"GLImportProcessorMixin"
],
"injectors": {
"defaultRequire": 1