mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-10-25 20:22:22 +00:00
Misc Shaderpack loading fixes (#1343)
This commit is contained in:
1 parent
90eabb5d40
commit
51533a81ec
10 files changed
+89
-22
No files matched your search
+1
-1
@@ -73,7 +73,7 @@ dependencies {
|
||||
compileOnly('org.jetbrains:annotations:26.0.2')
|
||||
api("com.github.GTNewHorizons:GTNHLib:0.9.6:dev")
|
||||
shadowImplementation("org.anarres:jcpp:1.4.14") // Apache 2.0
|
||||
shadowImplementation("org.taumc:glsl-transformation-lib:0.2.0-25.g3a943bb") {
|
||||
shadowImplementation("org.taumc:glsl-transformation-lib:0.2.0-26.g5ee7d96-GTNH") {
|
||||
exclude module: "antlr4" // we only want to shadow the runtime module
|
||||
}
|
||||
shadowImplementation("org.antlr:antlr4-runtime:4.13.2")
|
||||
|
||||
@@ -8,6 +8,7 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import jss.notfine.gui.GuiCustomMenu;
|
||||
import jss.notfine.gui.NotFineGameOptionPages;
|
||||
import me.flashyreese.mods.reeses_sodium_options.client.gui.ReeseSodiumVideoOptionsScreen;
|
||||
import me.jellysquid.mods.sodium.client.SodiumClientMod;
|
||||
import me.jellysquid.mods.sodium.client.gui.SodiumOptionsGUI;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
@@ -21,6 +22,7 @@ public class ClientProxy extends CommonProxy {
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
// FMLCommonHandler.instance().bus().register(this);
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
SodiumClientMod.options();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
||||
@@ -12,7 +12,7 @@ import org.lwjgl.opengl.KHRDebug;
|
||||
|
||||
public class ProgramCreator {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(ProgramCreator.class);
|
||||
private static final Logger LOGGER = LogManager.getLogger("ProgramCreator");
|
||||
|
||||
public static final int MC_ENTITY = 11;
|
||||
public static final int MC_MID_TEX_COORD = 12;
|
||||
|
||||
@@ -16,7 +16,11 @@ class AttributeTransformer {
|
||||
boolean isCore = profile.equals("core") || (version > 140 && !profile.equals("compatibility"));
|
||||
|
||||
// Common patches (compatibility profile)
|
||||
CommonTransformer.transform(transformer, parameters, isCore);
|
||||
CommonTransformer.transform(transformer, parameters, isCore, version);
|
||||
|
||||
// Entity ID and overlay color patching (uniform path)
|
||||
EntityPatcher.patchEntityId(transformer, parameters);
|
||||
EntityPatcher.patchOverlayColor(transformer, parameters);
|
||||
|
||||
if (isCore) {
|
||||
if (parameters.type == ShaderType.VERTEX) {
|
||||
|
||||
@@ -8,8 +8,8 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
class CeleritasTransformer {
|
||||
public static void transform(Transformer transformer, Parameters parameters) {
|
||||
CommonTransformer.transform(transformer, parameters, false);
|
||||
public static void transform(Transformer transformer, Parameters parameters, int glslVersion) {
|
||||
CommonTransformer.transform(transformer, parameters, false, glslVersion);
|
||||
|
||||
switch (parameters.type) {
|
||||
case FRAGMENT:
|
||||
|
||||
@@ -24,7 +24,7 @@ public class CommonTransformer {
|
||||
Map.entry("textureSize2D", "textureSize")
|
||||
);
|
||||
|
||||
public static void transform(Transformer root, Parameters parameters, boolean core) {
|
||||
public static void transform(Transformer root, Parameters parameters, boolean core, int glslVersion) {
|
||||
root.rename("gl_FogFragCoord", "iris_FogFragCoord");
|
||||
if (parameters.type == ShaderType.VERTEX) {
|
||||
root.injectVariable("out float iris_FogFragCoord;");
|
||||
@@ -66,8 +66,11 @@ public class CommonTransformer {
|
||||
root.injectFunction("struct iris_FogParameters {vec4 color;float density;float start;float end;float scale;};");
|
||||
root.injectFunction("iris_FogParameters iris_Fog = iris_FogParameters(iris_FogColor, iris_FogDensity, iris_FogStart, iris_FogEnd, 1.0f / (iris_FogEnd - iris_FogStart));");
|
||||
|
||||
root.renameFunctionCall(COMMON_TEXTURE_RENAMES);
|
||||
root.renameAndWrapShadow("shadow2D", "texture");
|
||||
root.renameAndWrapShadow("shadow2DLod", "textureLod");
|
||||
// GLSL 120 natively uses texture2D/shadow2D etc. Ttexture/textureLod don't exist in 120, so only rename for versions that support them.
|
||||
if (glslVersion > 120) {
|
||||
root.renameFunctionCall(COMMON_TEXTURE_RENAMES);
|
||||
root.renameAndWrapShadow("shadow2D", "texture");
|
||||
root.renameAndWrapShadow("shadow2DLod", "textureLod");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,8 @@ import org.taumc.glsl.Transformer;
|
||||
|
||||
class CompositeDepthTransformer {
|
||||
|
||||
public static void transform(Transformer transformer, Parameters parameters) {
|
||||
CommonTransformer.transform(transformer, parameters, false);
|
||||
public static void transform(Transformer transformer, Parameters parameters, int glslVersion) {
|
||||
CommonTransformer.transform(transformer, parameters, false, glslVersion);
|
||||
|
||||
int type = transformer.findType("centerDepthSmooth");
|
||||
if (type != 0) {
|
||||
|
||||
@@ -5,7 +5,7 @@ import org.taumc.glsl.Transformer;
|
||||
|
||||
public class ComputeTransformer {
|
||||
|
||||
public static void transform(Transformer transformer, Parameters parameters) {
|
||||
CommonTransformer.transform(transformer, parameters, true);
|
||||
public static void transform(Transformer transformer, Parameters parameters, int glslVersion) {
|
||||
CommonTransformer.transform(transformer, parameters, true, glslVersion);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package net.coderbot.iris.pipeline.transform;
|
||||
|
||||
import net.coderbot.iris.pipeline.transform.parameter.AttributeParameters;
|
||||
import org.taumc.glsl.Transformer;
|
||||
|
||||
class EntityPatcher {
|
||||
|
||||
public static void patchEntityId(Transformer transformer, AttributeParameters parameters) {
|
||||
injectUniformIfUndeclared(transformer, "entityId", "uniform int entityId;");
|
||||
injectUniformIfUndeclared(transformer, "blockEntityId", "uniform int blockEntityId;");
|
||||
injectUniformIfUndeclared(transformer, "currentRenderedItemId", "uniform int currentRenderedItemId;");
|
||||
}
|
||||
|
||||
public static void patchOverlayColor(Transformer transformer, AttributeParameters parameters) {
|
||||
injectUniformIfUndeclared(transformer, "entityColor", "uniform vec4 entityColor;");
|
||||
}
|
||||
|
||||
private static void injectUniformIfUndeclared(Transformer transformer, String name, String declaration) {
|
||||
if (transformer.containsCall(name) && !transformer.hasVariable(name)) {
|
||||
transformer.injectVariable(declaration);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,13 +9,17 @@ import net.coderbot.iris.Iris;
|
||||
import net.coderbot.iris.gl.shader.ShaderType;
|
||||
import net.coderbot.iris.pipeline.transform.parameter.Parameters;
|
||||
import net.coderbot.iris.pipeline.transform.parameter.AttributeParameters;
|
||||
import org.antlr.v4.runtime.CommonToken;
|
||||
import org.antlr.v4.runtime.tree.ParseTree;
|
||||
import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
||||
import org.antlr.v4.runtime.tree.TerminalNode;
|
||||
import org.embeddedt.embeddium.impl.gl.shader.ShaderConstants;
|
||||
import org.embeddedt.embeddium.impl.render.shader.ShaderLoader;
|
||||
import org.taumc.glsl.ShaderParser;
|
||||
import org.taumc.glsl.StorageCollector;
|
||||
import org.taumc.glsl.Transformer;
|
||||
import org.taumc.glsl.grammar.GLSLLexer;
|
||||
import org.taumc.glsl.grammar.GLSLParser;
|
||||
|
||||
import com.gtnewhorizons.angelica.glsm.RenderSystem;
|
||||
|
||||
@@ -31,9 +35,9 @@ import java.util.regex.Pattern;
|
||||
|
||||
public class ShaderTransformer {
|
||||
private static final Pattern versionPattern = Pattern.compile("#version\\s+(\\d+)(?:\\s+(\\w+))?");
|
||||
private static final Pattern inOutVaryingPattern = Pattern.compile("(?m)^\\s*(in|out)(\\s+)");
|
||||
private static final Pattern inPattern = Pattern.compile("(?m)^\\s*(in)(\\s+)");
|
||||
private static final Pattern outPattern = Pattern.compile("(?m)^\\s*(out)(\\s+)");
|
||||
private static final Pattern inOutVaryingPattern = Pattern.compile("(?m)^(\\s*(?:(?:flat|smooth|noperspective)\\s+)?)(in|out)(\\s+)");
|
||||
private static final Pattern inPattern = Pattern.compile("(?m)^(\\s*(?:(?:flat|smooth|noperspective)\\s+)?)(in)(\\s+)");
|
||||
private static final Pattern outPattern = Pattern.compile("(?m)^(\\s*(?:(?:flat|smooth|noperspective)\\s+)?)(out)(\\s+)");
|
||||
|
||||
private static final int CACHE_SIZE = 100;
|
||||
private static final Object2ObjectLinkedOpenHashMap<TransformKey<?>, Map<PatchShaderType, String>> shaderTransformationCache = new Object2ObjectLinkedOpenHashMap<>();
|
||||
@@ -372,6 +376,10 @@ public class ShaderTransformer {
|
||||
var parsedShader = ShaderParser.parseShader(input);
|
||||
var transformer = new Transformer(parsedShader.full());
|
||||
|
||||
if (parameters.type == ShaderType.VERTEX || parameters.type == ShaderType.FRAGMENT) {
|
||||
upgradeStorageQualifiers(transformer, parameters);
|
||||
}
|
||||
|
||||
doTransform(transformer, patchType, parameters, profile, versionInt);
|
||||
|
||||
// Check if we need to patch in texture LOD extension enabling
|
||||
@@ -436,13 +444,13 @@ public class ShaderTransformer {
|
||||
if (entry.getKey() == PatchShaderType.VERTEX) {
|
||||
// In vertex shaders, "in" declarations are vertex attributes, not varyings
|
||||
Matcher inMatcher = inPattern.matcher(formattedShader);
|
||||
formattedShader = inMatcher.replaceAll("attribute$2");
|
||||
formattedShader = inMatcher.replaceAll("$1attribute$3");
|
||||
Matcher outMatcher = outPattern.matcher(formattedShader);
|
||||
formattedShader = outMatcher.replaceAll("varying$2");
|
||||
formattedShader = outMatcher.replaceAll("$1varying$3");
|
||||
} else {
|
||||
// In fragment (and geometry) shaders, both in/out become varying
|
||||
Matcher inOutVaryingMatcher = inOutVaryingPattern.matcher(formattedShader);
|
||||
formattedShader = inOutVaryingMatcher.replaceAll("varying$2");
|
||||
formattedShader = inOutVaryingMatcher.replaceAll("$1varying$3");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -456,20 +464,20 @@ public class ShaderTransformer {
|
||||
private static void doTransform(Transformer transformer, Patch patchType, Parameters parameters, String profile, int versionInt) {
|
||||
switch (patchType) {
|
||||
case CELERITAS_TERRAIN:
|
||||
CeleritasTransformer.transform(transformer, parameters);
|
||||
CeleritasTransformer.transform(transformer, parameters, versionInt);
|
||||
// Handle mc_midTexCoord for Celeritas
|
||||
patchMultiTexCoord3(transformer, parameters);
|
||||
replaceMidTexCoord(transformer, IrisExtendedChunkVertexType.MID_TEX_SCALE);
|
||||
applyIntelHd4000Workaround(transformer);
|
||||
break;
|
||||
case COMPOSITE:
|
||||
CompositeDepthTransformer.transform(transformer, parameters);
|
||||
CompositeDepthTransformer.transform(transformer, parameters, versionInt);
|
||||
break;
|
||||
case ATTRIBUTES:
|
||||
AttributeTransformer.transform(transformer, (AttributeParameters) parameters, profile, versionInt);
|
||||
break;
|
||||
case COMPUTE:
|
||||
ComputeTransformer.transform(transformer, parameters);
|
||||
ComputeTransformer.transform(transformer, parameters, versionInt);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Unknown patch type: " + patchType.name());
|
||||
@@ -553,6 +561,33 @@ public class ShaderTransformer {
|
||||
return "\n\n" + chunkVertexHeader + "\n\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts GLSL 120 storage qualifiers (varying/attribute) to modern in/out tokens so downstream AST transforms (e.g. CompatibilityTransformer) can find them.
|
||||
* The hacky120Patches regex pass converts them back for the final output.
|
||||
*/
|
||||
public static void upgradeStorageQualifiers(Transformer root, Parameters parameters) {
|
||||
final List<TerminalNode> tokens = new ArrayList<>();
|
||||
root.mutateTree(tree -> ParseTreeWalker.DEFAULT.walk(new StorageCollector(tokens), tree));
|
||||
|
||||
for (TerminalNode node : tokens) {
|
||||
if (!(node.getSymbol() instanceof CommonToken token)) {
|
||||
return;
|
||||
}
|
||||
if (token.getType() == GLSLParser.ATTRIBUTE) {
|
||||
token.setType(GLSLParser.IN);
|
||||
token.setText(GLSLParser.VOCABULARY.getLiteralName(GLSLParser.IN).replace("'", ""));
|
||||
} else if (token.getType() == GLSLParser.VARYING) {
|
||||
if (parameters.type == ShaderType.VERTEX) {
|
||||
token.setType(GLSLParser.OUT);
|
||||
token.setText(GLSLParser.VOCABULARY.getLiteralName(GLSLParser.OUT).replace("'", ""));
|
||||
} else {
|
||||
token.setType(GLSLParser.IN);
|
||||
token.setText(GLSLParser.VOCABULARY.getLiteralName(GLSLParser.IN).replace("'", ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String getFormattedShader(ParseTree tree, String string) {
|
||||
final StringBuilder sb = new StringBuilder(string + "\n");
|
||||
final String[] tabHolder = {""};
|
||||
|
||||
Reference in new issue
Block a user