From 540a45f22546407965b2047b50a1242db29bedbc Mon Sep 17 00:00:00 2001 From: IMS212 Date: Wed, 13 Dec 2023 10:25:31 -0800 Subject: [PATCH] Fix patching --- .../pipeline/transform/TransformPatcher.java | 2 +- .../parameter/AttributeParameters.java | 2 +- .../parameter/GeometryInfoParameters.java | 4 +- .../parameter/VanillaParameters.java | 4 +- .../transformer/AttributeTransformer.java | 59 ++++++++++++++++++- 5 files changed, 64 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/coderbot/iris/pipeline/transform/TransformPatcher.java b/src/main/java/net/coderbot/iris/pipeline/transform/TransformPatcher.java index abe112019f..ebfcec90d1 100644 --- a/src/main/java/net/coderbot/iris/pipeline/transform/TransformPatcher.java +++ b/src/main/java/net/coderbot/iris/pipeline/transform/TransformPatcher.java @@ -390,7 +390,7 @@ public static Map patchVanilla( ShaderAttributeInputs inputs, Object2ObjectMap, String> textureMap) { return transform(vertex, geometry, tessControl, tessEval, fragment, - new VanillaParameters(Patch.VANILLA, textureMap, alpha, isLines, hasChunkOffset, inputs, geometry != null)); + new VanillaParameters(Patch.VANILLA, textureMap, alpha, isLines, hasChunkOffset, inputs, geometry != null, tessControl != null || tessEval != null)); } public static Map patchSodium(String vertex, String geometry, String tessControl, String tessEval, String fragment, diff --git a/src/main/java/net/coderbot/iris/pipeline/transform/parameter/AttributeParameters.java b/src/main/java/net/coderbot/iris/pipeline/transform/parameter/AttributeParameters.java index 83b6659530..fd9a81ecfe 100644 --- a/src/main/java/net/coderbot/iris/pipeline/transform/parameter/AttributeParameters.java +++ b/src/main/java/net/coderbot/iris/pipeline/transform/parameter/AttributeParameters.java @@ -15,7 +15,7 @@ public AttributeParameters(Patch patch, Object2ObjectMap, String> textureMap, boolean hasGeometry, InputAvailability inputs) { - super(patch, textureMap, hasGeometry); + super(patch, textureMap, hasGeometry, false); this.inputs = inputs; } diff --git a/src/main/java/net/coderbot/iris/pipeline/transform/parameter/GeometryInfoParameters.java b/src/main/java/net/coderbot/iris/pipeline/transform/parameter/GeometryInfoParameters.java index ad57e6add9..dcfec4f283 100644 --- a/src/main/java/net/coderbot/iris/pipeline/transform/parameter/GeometryInfoParameters.java +++ b/src/main/java/net/coderbot/iris/pipeline/transform/parameter/GeometryInfoParameters.java @@ -8,12 +8,14 @@ public abstract class GeometryInfoParameters extends Parameters { public final boolean hasGeometry; + public final boolean hasTesselation; // WARNING: adding new fields requires updating hashCode and equals methods! public GeometryInfoParameters(Patch patch, - Object2ObjectMap, String> textureMap, boolean hasGeometry) { + Object2ObjectMap, String> textureMap, boolean hasGeometry, boolean hasTesselation) { super(patch, textureMap); this.hasGeometry = hasGeometry; + this.hasTesselation = hasTesselation; } @Override diff --git a/src/main/java/net/coderbot/iris/pipeline/transform/parameter/VanillaParameters.java b/src/main/java/net/coderbot/iris/pipeline/transform/parameter/VanillaParameters.java index 86f027b4a9..08f6309aad 100644 --- a/src/main/java/net/coderbot/iris/pipeline/transform/parameter/VanillaParameters.java +++ b/src/main/java/net/coderbot/iris/pipeline/transform/parameter/VanillaParameters.java @@ -19,8 +19,8 @@ public VanillaParameters( Patch patch, Object2ObjectMap, String> textureMap, AlphaTest alpha, boolean isLines, boolean hasChunkOffset, - ShaderAttributeInputs inputs, boolean hasGeometry) { - super(patch, textureMap, hasGeometry); + ShaderAttributeInputs inputs, boolean hasGeometry, boolean hasTesselation) { + super(patch, textureMap, hasGeometry, hasTesselation); this.alpha = alpha; this.isLines = isLines; this.hasChunkOffset = hasChunkOffset; diff --git a/src/main/java/net/coderbot/iris/pipeline/transform/transformer/AttributeTransformer.java b/src/main/java/net/coderbot/iris/pipeline/transform/transformer/AttributeTransformer.java index e140e1bcd5..2057fb79e3 100644 --- a/src/main/java/net/coderbot/iris/pipeline/transform/transformer/AttributeTransformer.java +++ b/src/main/java/net/coderbot/iris/pipeline/transform/transformer/AttributeTransformer.java @@ -167,6 +167,32 @@ public static void patchOverlayColor( // Some shader packs incorrectly ignore the alpha value, and assume that rgb // will be zero if there is no hit flash, we try to emulate that here "entityColor.rgb *= float(entityColor.a != 0.0);"); + } else if (parameters.type.glShaderType == ShaderType.TESSELATION_CONTROL) { + // replace read references to grab the color from the first vertex. + root.replaceReferenceExpressions(t, "entityColor", "entityColor[gl_InvocationID]"); + + // TODO: this is passthrough behavior + tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_DECLARATIONS, + "out vec4 entityColorTCS[];", + "in vec4 entityColor[];", + "out vec4 iris_vertexColorTCS[];", + "in vec4 iris_vertexColor[];"); + tree.prependMainFunctionBody(t, + "entityColorTCS[gl_InvocationID] = entityColor[gl_InvocationID];", + "iris_vertexColorTCS[gl_InvocationID] = iris_vertexColor[gl_InvocationID];"); + } else if (parameters.type.glShaderType == ShaderType.TESSELATION_EVAL) { + // replace read references to grab the color from the first vertex. + root.replaceReferenceExpressions(t, "entityColor", "entityColorTCS[0]"); + + // TODO: this is passthrough behavior + tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_DECLARATIONS, + "out vec4 entityColorTES;", + "in vec4 entityColorTCS[];", + "out vec4 iris_vertexColorTES;", + "in vec4 iris_vertexColorTCS[];"); + tree.prependMainFunctionBody(t, + "entityColorTES = entityColorTCS[0];", + "iris_vertexColorTES = iris_vertexColorTCS[0];"); } else if (parameters.type.glShaderType == ShaderType.GEOMETRY) { // replace read references to grab the color from the first vertex. root.replaceReferenceExpressions(t, "entityColor", "entityColor[0]"); @@ -180,6 +206,11 @@ public static void patchOverlayColor( tree.prependMainFunctionBody(t, "entityColorGS = entityColor[0];", "iris_vertexColorGS = iris_vertexColor[0];"); + + if (parameters.hasTesselation) { + root.rename("iris_vertexColor", "iris_vertexColorTES"); + root.rename("entityColor", "entityColorTES"); + } } else if (parameters.type.glShaderType == ShaderType.FRAGMENT) { tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "in vec4 entityColor;", "in vec4 iris_vertexColor;"); @@ -190,6 +221,9 @@ public static void patchOverlayColor( if (parameters.hasGeometry) { root.rename("entityColor", "entityColorGS"); root.rename("iris_vertexColor", "iris_vertexColorGS"); + } else if (parameters.hasTesselation) { + root.rename("entityColor", "entityColorTES"); + root.rename("iris_vertexColor", "iris_vertexColorTES"); } } } @@ -238,13 +272,32 @@ public static void patchEntityId( // stage. tree.prependMainFunctionBody(t, "iris_entityInfo = iris_Entity;"); + } else if (parameters.type.glShaderType == ShaderType.TESSELATION_CONTROL) { + // TODO: this is passthrough behavior + tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_DECLARATIONS, + "flat out ivec3 iris_entityInfoTCS[];", + "flat in ivec3 iris_entityInfo[];"); + root.replaceReferenceExpressions(t, "iris_entityInfo", "iris_EntityInfo[gl_InvocationID]"); + + tree.prependMainFunctionBody(t, + "iris_entityInfoTCS[gl_InvocationID] = iris_entityInfo[gl_InvocationID];"); + } else if (parameters.type.glShaderType == ShaderType.TESSELATION_EVAL) { + // TODO: this is passthrough behavior + tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_DECLARATIONS, + "flat out ivec3 iris_entityInfoTES;", + "flat in ivec3 iris_entityInfoTCS[];"); + tree.prependMainFunctionBody(t, + "iris_entityInfoTES = iris_entityInfoTCS[0];"); + + root.replaceReferenceExpressions(t, "iris_entityInfo", "iris_EntityInfoTCS[0]"); + } else if (parameters.type.glShaderType == ShaderType.GEOMETRY) { // TODO: this is passthrough behavior tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "flat out ivec3 iris_entityInfoGS;", - "flat in ivec3 iris_entityInfo[];"); + "flat in ivec3 iris_entityInfo" + (parameters.hasTesselation ? "TES" : "") + "[];"); tree.prependMainFunctionBody(t, - "iris_entityInfoGS = iris_entityInfo[0];"); + "iris_entityInfoGS = iris_entityInfo" + (parameters.hasTesselation ? "TES" : "") + "[0];"); } else if (parameters.type.glShaderType == ShaderType.FRAGMENT) { tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "flat in ivec3 iris_entityInfo;"); @@ -252,6 +305,8 @@ public static void patchEntityId( // Different output name to avoid a name collision in the geometry shader. if (parameters.hasGeometry) { root.rename("iris_entityInfo", "iris_EntityInfoGS"); + } else if (parameters.hasTesselation) { + root.rename("iris_entityInfo", "iris_entityInfoTES"); } } }