diff --git a/build.gradle.kts b/build.gradle.kts index e2b7849303..b8f9ad1086 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ plugins { } val MINECRAFT_VERSION by extra { "1.21.1" } -val NEOFORGE_VERSION by extra { "21.1.46" } +val NEOFORGE_VERSION by extra { "21.1.74" } val FABRIC_LOADER_VERSION by extra { "0.16.4" } val FABRIC_API_VERSION by extra { "0.103.0+1.21.1" } diff --git a/common/src/main/java/net/irisshaders/iris/compat/dh/IrisGenericRenderProgram.java b/common/src/main/java/net/irisshaders/iris/compat/dh/IrisGenericRenderProgram.java index 2197af50f2..da6576a127 100644 --- a/common/src/main/java/net/irisshaders/iris/compat/dh/IrisGenericRenderProgram.java +++ b/common/src/main/java/net/irisshaders/iris/compat/dh/IrisGenericRenderProgram.java @@ -139,11 +139,11 @@ private IrisGenericRenderProgram(String name, boolean isShadowPass, boolean tran GL32.glVertexAttribPointer(0, 3, GL32.GL_FLOAT, false, 0, 0); GL32.glEnableVertexAttribArray(0); - projectionUniform = tryGetUniformLocation2("iris_ProjectionMatrix"); - projectionInverseUniform = tryGetUniformLocation2("iris_ProjectionMatrixInverse"); - modelViewUniform = tryGetUniformLocation2("iris_ModelViewMatrix"); - modelViewInverseUniform = tryGetUniformLocation2("iris_ModelViewMatrixInverse"); - normalMatrix3fUniform = tryGetUniformLocation2("iris_NormalMatrix"); + projectionUniform = tryGetUniformLocation2("irisInt_ProjectionMatrix"); + projectionInverseUniform = tryGetUniformLocation2("irisInt_ProjectionMatrixInverse"); + modelViewUniform = tryGetUniformLocation2("irisInt_ModelViewMatrix"); + modelViewInverseUniform = tryGetUniformLocation2("irisInt_ModelViewMatrixInverse"); + normalMatrix3fUniform = tryGetUniformLocation2("irisInt_NormalMatrix"); this.instancedShaderOffsetChunkUniform = this.tryGetUniformLocation2("uOffsetChunk"); this.instancedShaderOffsetSubChunkUniform = this.tryGetUniformLocation2("uOffsetSubChunk"); diff --git a/common/src/main/java/net/irisshaders/iris/compat/dh/IrisLodRenderProgram.java b/common/src/main/java/net/irisshaders/iris/compat/dh/IrisLodRenderProgram.java index 5aa1dd9f90..e7cb37ddb6 100644 --- a/common/src/main/java/net/irisshaders/iris/compat/dh/IrisLodRenderProgram.java +++ b/common/src/main/java/net/irisshaders/iris/compat/dh/IrisLodRenderProgram.java @@ -61,7 +61,7 @@ private IrisLodRenderProgram(String name, boolean isShadowPass, boolean transluc id = GL43C.glCreateProgram(); GL32.glBindAttribLocation(this.id, 0, "vPosition"); - GL32.glBindAttribLocation(this.id, 1, "iris_color"); + GL32.glBindAttribLocation(this.id, 1, "irisInt_color"); GL32.glBindAttribLocation(this.id, 2, "irisExtra"); this.bufferBlendOverrides = bufferBlendOverrides; @@ -124,11 +124,11 @@ private IrisLodRenderProgram(String name, boolean isShadowPass, boolean transluc modelOffsetUniform = tryGetUniformLocation2("modelOffset"); worldYOffsetUniform = tryGetUniformLocation2("worldYOffset"); mircoOffsetUniform = tryGetUniformLocation2("mircoOffset"); - projectionUniform = tryGetUniformLocation2("iris_ProjectionMatrix"); - projectionInverseUniform = tryGetUniformLocation2("iris_ProjectionMatrixInverse"); - modelViewUniform = tryGetUniformLocation2("iris_ModelViewMatrix"); - modelViewInverseUniform = tryGetUniformLocation2("iris_ModelViewMatrixInverse"); - normalMatrix3fUniform = tryGetUniformLocation2("iris_NormalMatrix"); + projectionUniform = tryGetUniformLocation2("irisInt_ProjectionMatrix"); + projectionInverseUniform = tryGetUniformLocation2("irisInt_ProjectionMatrixInverse"); + modelViewUniform = tryGetUniformLocation2("irisInt_ModelViewMatrix"); + modelViewInverseUniform = tryGetUniformLocation2("irisInt_ModelViewMatrixInverse"); + normalMatrix3fUniform = tryGetUniformLocation2("irisInt_NormalMatrix"); // Fog/Clip Uniforms clipDistanceUniform = tryGetUniformLocation2("clipDistance"); diff --git a/common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/MixinBlockRenderer.java b/common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/MixinBlockRenderer.java index 0729c9837a..5ea573d907 100644 --- a/common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/MixinBlockRenderer.java +++ b/common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/MixinBlockRenderer.java @@ -2,9 +2,14 @@ import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.llamalad7.mixinextras.sugar.Local; import net.caffeinemc.mods.sodium.client.render.chunk.compile.pipeline.BlockRenderer; import net.caffeinemc.mods.sodium.client.render.chunk.terrain.TerrainRenderPass; +import net.caffeinemc.mods.sodium.client.render.chunk.terrain.material.Material; +import net.caffeinemc.mods.sodium.client.render.chunk.vertex.builder.ChunkMeshBufferBuilder; +import net.caffeinemc.mods.sodium.client.render.frapi.mesh.MutableQuadViewImpl; import net.irisshaders.iris.shaderpack.materialmap.WorldRenderingSettings; +import net.irisshaders.iris.vertices.sodium.terrain.VertexEncoderInterface; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.core.BlockPos; @@ -32,6 +37,11 @@ public class MixinBlockRenderer { hasOverride = false; } + @Inject(remap = false, method = "bufferQuad", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/client/render/chunk/vertex/builder/ChunkMeshBufferBuilder;push([Lnet/caffeinemc/mods/sodium/client/render/chunk/vertex/format/ChunkVertexEncoder$Vertex;I)V")) + private void iris$setShade(MutableQuadViewImpl quad, float[] brightnesses, Material material, CallbackInfo ci, @Local ChunkMeshBufferBuilder vertexBuffer) { + ((VertexEncoderInterface) vertexBuffer).iris$setShade(quad.hasShade()); + } + @WrapOperation(method = "bufferQuad", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/client/render/chunk/compile/pipeline/BlockRenderer;attemptPassDowngrade(Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;Lnet/caffeinemc/mods/sodium/client/render/chunk/terrain/TerrainRenderPass;)Lnet/caffeinemc/mods/sodium/client/render/chunk/terrain/TerrainRenderPass;")) private TerrainRenderPass iris$skipPassDowngrade(BlockRenderer instance, TextureAtlasSprite textureAtlasSprite, TerrainRenderPass sprite, Operation original) { if (hasOverride) return null; diff --git a/common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/MixinChunkMeshBufferBuilder.java b/common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/MixinChunkMeshBufferBuilder.java index 0e1ec9091d..c0bd27ff17 100644 --- a/common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/MixinChunkMeshBufferBuilder.java +++ b/common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/MixinChunkMeshBufferBuilder.java @@ -20,4 +20,11 @@ public class MixinChunkMeshBufferBuilder implements VertexEncoderInterface { ((VertexEncoderInterface) encoder).iris$setContextHolder(contextHolder); } } + + @Override + public void iris$setShade(boolean shade) { + if (encoder instanceof VertexEncoderInterface) { + ((VertexEncoderInterface) encoder).iris$setShade(shade); + } + } } diff --git a/common/src/main/java/net/irisshaders/iris/features/FeatureFlags.java b/common/src/main/java/net/irisshaders/iris/features/FeatureFlags.java index ea7798f771..a3c172fa83 100644 --- a/common/src/main/java/net/irisshaders/iris/features/FeatureFlags.java +++ b/common/src/main/java/net/irisshaders/iris/features/FeatureFlags.java @@ -20,6 +20,7 @@ public enum FeatureFlags { BLOCK_EMISSION_ATTRIBUTE(() -> true, () -> true), CAN_DISABLE_WEATHER(() -> true, () -> true), SSBO(() -> true, IrisRenderSystem::supportsSSBO), + SEPARATE_AO(() -> true, () -> true), UNKNOWN(() -> false, () -> false); private final BooleanSupplier irisRequirement; diff --git a/common/src/main/java/net/irisshaders/iris/gl/blending/AlphaTest.java b/common/src/main/java/net/irisshaders/iris/gl/blending/AlphaTest.java index 0006b4a288..48ee9f5be1 100644 --- a/common/src/main/java/net/irisshaders/iris/gl/blending/AlphaTest.java +++ b/common/src/main/java/net/irisshaders/iris/gl/blending/AlphaTest.java @@ -6,7 +6,7 @@ public record AlphaTest(AlphaTestFunction function, float reference) { // WARNING: adding new fields requires updating hashCode and equals methods! public String toExpression(String indentation) { - return toExpression("gl_FragData[0].a", "iris_currentAlphaTest", indentation); + return toExpression("gl_FragData[0].a", "irisInt_currentAlphaTest", indentation); } public String toExpression(String alphaAccessor, String alphaThreshold, String indentation) { @@ -15,7 +15,7 @@ public String toExpression(String alphaAccessor, String alphaThreshold, String i if (function == AlphaTestFunction.ALWAYS) { return "// alpha test disabled\n"; } else if (this == AlphaTests.VERTEX_ALPHA) { - return indentation + "if (!(" + alphaAccessor + " > iris_vertexColorAlpha)) {\n" + + return indentation + "if (!(" + alphaAccessor + " > irisInt_vertexColorAlpha)) {\n" + indentation + " discard;\n" + indentation + "}\n"; } else if (function == AlphaTestFunction.NEVER) { diff --git a/common/src/main/java/net/irisshaders/iris/gl/shader/ProgramCreator.java b/common/src/main/java/net/irisshaders/iris/gl/shader/ProgramCreator.java index d86989103c..efadb46d04 100644 --- a/common/src/main/java/net/irisshaders/iris/gl/shader/ProgramCreator.java +++ b/common/src/main/java/net/irisshaders/iris/gl/shader/ProgramCreator.java @@ -16,7 +16,7 @@ public class ProgramCreator { public static int create(String name, GlShader... shaders) { int program = GlStateManager.glCreateProgram(); - GlStateManager._glBindAttribLocation(program, 11, "iris_Entity"); + GlStateManager._glBindAttribLocation(program, 11, "irisInt_Entity"); GlStateManager._glBindAttribLocation(program, 11, "mc_Entity"); GlStateManager._glBindAttribLocation(program, 12, "mc_midTexCoord"); GlStateManager._glBindAttribLocation(program, 13, "at_tangent"); diff --git a/common/src/main/java/net/irisshaders/iris/mixin/MixinShaderInstance.java b/common/src/main/java/net/irisshaders/iris/mixin/MixinShaderInstance.java index 6f2328d125..c10b1a9295 100644 --- a/common/src/main/java/net/irisshaders/iris/mixin/MixinShaderInstance.java +++ b/common/src/main/java/net/irisshaders/iris/mixin/MixinShaderInstance.java @@ -68,7 +68,7 @@ private static boolean shouldOverrideShaders() { @Redirect(method = "*", require = 1, at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/shaders/Uniform;glBindAttribLocation(IILjava/lang/CharSequence;)V")) public void iris$redirectBindAttributeLocation(int i, int j, CharSequence charSequence) { if (((Object) this) instanceof ExtendedShader && ATTRIBUTE_LIST.contains(charSequence)) { - Uniform.glBindAttribLocation(i, j, "iris_" + charSequence); + Uniform.glBindAttribLocation(i, j, "irisInt_" + charSequence); } else { Uniform.glBindAttribLocation(i, j, charSequence); } diff --git a/common/src/main/java/net/irisshaders/iris/pipeline/CompositeRenderer.java b/common/src/main/java/net/irisshaders/iris/pipeline/CompositeRenderer.java index 2ac5b10a84..544af978f6 100644 --- a/common/src/main/java/net/irisshaders/iris/pipeline/CompositeRenderer.java +++ b/common/src/main/java/net/irisshaders/iris/pipeline/CompositeRenderer.java @@ -386,7 +386,7 @@ private Program createProgram(ProgramSource source, ImmutableSet flippe } // TODO: Don't duplicate this with FinalPassRenderer - centerDepthSampler.setUsage(builder.addDynamicSampler(centerDepthSampler::getCenterDepthTexture, "iris_centerDepthSmooth")); + centerDepthSampler.setUsage(builder.addDynamicSampler(centerDepthSampler::getCenterDepthTexture, "irisInt_centerDepthSmooth")); Program build = builder.build(); @@ -442,7 +442,7 @@ private ComputeProgram[] createComputes(ComputeSource[] compute, ImmutableSet flippe } // TODO: Don't duplicate this with CompositeRenderer - centerDepthSampler.setUsage(builder.addDynamicSampler(centerDepthSampler::getCenterDepthTexture, "iris_centerDepthSmooth")); + centerDepthSampler.setUsage(builder.addDynamicSampler(centerDepthSampler::getCenterDepthTexture, "irisInt_centerDepthSmooth")); Program build = builder.build(); @@ -426,7 +426,7 @@ private ComputeProgram[] createComputes(ComputeSource[] compute, ImmutableSet transformed = transformShaders(source, alphaTest, programSet); + Map transformed = transformShaders(source, alphaTest, programSet, pipeline.hasFeature(FeatureFlags.SEPARATE_AO)); GlProgram shader = createShader(pipeline, pass, source, alphaTest, customUniforms, flipState, createGlShaders(pass.name().toLowerCase(Locale.ROOT), transformed)); shaders.put(pass, shader); } @@ -75,7 +76,7 @@ private AlphaTest getAlphaTest(Pass pass, ProgramSource source) { pass == Pass.TERRAIN_CUTOUT || pass == Pass.SHADOW_CUTOUT ? AlphaTests.ONE_TENTH_ALPHA : AlphaTest.ALWAYS); } - private Map transformShaders(ProgramSource source, AlphaTest alphaTest, ProgramSet programSet) { + private Map transformShaders(ProgramSource source, AlphaTest alphaTest, ProgramSet programSet, boolean injectAmbientOcclusion) { Map transformed = TransformPatcher.patchSodium( source.getName(), source.getVertexSource().orElse(null), @@ -84,6 +85,7 @@ private Map transformShaders(ProgramSource source, Alph source.getTessEvalSource().orElse(null), source.getFragmentSource().orElse(null), alphaTest, + injectAmbientOcclusion, programSet.getPackDirectives().getTextureMap()); ShaderPrinter.printProgram("sodium_" + source.getName()).addSources(transformed).print(); @@ -162,13 +164,13 @@ private GlProgram buildProgram(GlProgram.Builder builder, .bindAttribute("mc_Entity", 11) .bindAttribute("mc_midTexCoord", 12) .bindAttribute("at_tangent", 13) - .bindAttribute("iris_Normal", 10) + .bindAttribute("irisInt_Normal", 10) .bindAttribute("at_midBlock", 14) .link((shader) -> { int handle = ((GlObject) shader).handle(); GLDebug.nameObject(GL43C.GL_PROGRAM, handle, "sodium-terrain-" + pass.toString().toLowerCase(Locale.ROOT)); - if (!hasNormal) hasNormal = GL43C.glGetAttribLocation(handle, "iris_Normal") != -1; + if (!hasNormal) hasNormal = GL43C.glGetAttribLocation(handle, "irisInt_Normal") != -1; if (!hasMidBlock) hasMidBlock = GL43C.glGetAttribLocation(handle, "at_midBlock") != -1; if (!hasBlockId) hasBlockId = GL43C.glGetAttribLocation(handle, "mc_Entity") != -1; if (!hasMidUv) hasMidUv = GL43C.glGetAttribLocation(handle, "mc_midTexCoord") != -1; diff --git a/common/src/main/java/net/irisshaders/iris/pipeline/programs/SodiumShader.java b/common/src/main/java/net/irisshaders/iris/pipeline/programs/SodiumShader.java index 43835850d3..833c7c41da 100644 --- a/common/src/main/java/net/irisshaders/iris/pipeline/programs/SodiumShader.java +++ b/common/src/main/java/net/irisshaders/iris/pipeline/programs/SodiumShader.java @@ -52,11 +52,11 @@ public SodiumShader(IrisRenderingPipeline pipeline, SodiumPrograms.Pass pass, Sh List bufferBlendOverrides, CustomUniforms customUniforms, Supplier> flipState, float alphaTest, boolean containsTessellation) { - this.uniformModelViewMatrix = context.bindUniformOptional("iris_ModelViewMatrix", GlUniformMatrix4f::new); - this.uniformModelViewMatrixInv = context.bindUniformOptional("iris_ModelViewMatrixInverse", GlUniformMatrix4f::new); - this.uniformNormalMatrix = context.bindUniformOptional("iris_NormalMatrix", GlUniformMatrix3f::new); - this.uniformProjectionMatrix = context.bindUniformOptional("iris_ProjectionMatrix", GlUniformMatrix4f::new); - this.uniformProjectionMatrixInv = context.bindUniformOptional("iris_ProjectionMatrixInv", GlUniformMatrix4f::new); + this.uniformModelViewMatrix = context.bindUniformOptional("irisInt_ModelViewMatrix", GlUniformMatrix4f::new); + this.uniformModelViewMatrixInv = context.bindUniformOptional("irisInt_ModelViewMatrixInverse", GlUniformMatrix4f::new); + this.uniformNormalMatrix = context.bindUniformOptional("irisInt_NormalMatrix", GlUniformMatrix3f::new); + this.uniformProjectionMatrix = context.bindUniformOptional("irisInt_ProjectionMatrix", GlUniformMatrix4f::new); + this.uniformProjectionMatrixInv = context.bindUniformOptional("irisInt_ProjectionMatrixInv", GlUniformMatrix4f::new); this.uniformRegionOffset = context.bindUniformOptional("u_RegionOffset", GlUniformFloat3v::new); this.alphaTest = alphaTest; diff --git a/common/src/main/java/net/irisshaders/iris/pipeline/transform/TransformPatcher.java b/common/src/main/java/net/irisshaders/iris/pipeline/transform/TransformPatcher.java index 0b9fc91b75..d2311b6fbb 100644 --- a/common/src/main/java/net/irisshaders/iris/pipeline/transform/TransformPatcher.java +++ b/common/src/main/java/net/irisshaders/iris/pipeline/transform/TransformPatcher.java @@ -83,7 +83,7 @@ public boolean isTokenAllowed(Token token) { }; private static final boolean useCache = true; private static final Map> cache = new LRUCache<>(400); - private static final List internalPrefixes = List.of("iris_", "irisMain", "moj_import"); + private static final List internalPrefixes = List.of("irisInt_", "irisMain", "moj_import"); private static final Pattern versionPattern = Pattern.compile("#version\\s+(\\d+)", Pattern.DOTALL); private static final EnumASTTransformer transformer; static Logger LOGGER = LogManager.getLogger(TransformPatcher.class); @@ -125,7 +125,7 @@ public TranslationUnit parseTranslationUnit(Root rootInstance, String input) { .findAny() .ifPresent(id -> { throw new IllegalArgumentException( - "Detected a potential reference to unstable and internal Iris shader interfaces (iris_, irisMain and moj_import). This isn't currently supported. Violation: " + "Detected a potential reference to unstable and internal Iris shader interfaces (irisInt_, irisMain and moj_import). This isn't currently supported. Violation: " + id.getName() + ". See debugging.md for more information."); }); @@ -294,11 +294,11 @@ private static Map transformCompute(String name, String public static Map patchVanilla( String name, String vertex, String geometry, String tessControl, String tessEval, String fragment, AlphaTest alpha, boolean isLines, - boolean hasChunkOffset, + boolean hasChunkOffset, boolean injectAmbientOcclusion, ShaderAttributeInputs inputs, Object2ObjectMap, String> textureMap) { return transform(name, vertex, geometry, tessControl, tessEval, fragment, - new VanillaParameters(Patch.VANILLA, textureMap, alpha, isLines, hasChunkOffset, inputs, geometry != null, tessControl != null || tessEval != null)); + new VanillaParameters(Patch.VANILLA, textureMap, alpha, isLines, hasChunkOffset, inputs, geometry != null, tessControl != null || tessEval != null, injectAmbientOcclusion)); } @@ -319,10 +319,10 @@ public static Map patchDHGeneric( } public static Map patchSodium(String name, String vertex, String geometry, String tessControl, String tessEval, String fragment, - AlphaTest alpha, + AlphaTest alpha, boolean injectAmbientOcclusion, Object2ObjectMap, String> textureMap) { return transform(name, vertex, geometry, tessControl, tessEval, fragment, - new SodiumParameters(Patch.SODIUM, textureMap, alpha)); + new SodiumParameters(Patch.SODIUM, textureMap, alpha, geometry != null, tessControl != null || tessEval != null, injectAmbientOcclusion)); } public static Map patchComposite( diff --git a/common/src/main/java/net/irisshaders/iris/pipeline/transform/parameter/GeometryInfoParameters.java b/common/src/main/java/net/irisshaders/iris/pipeline/transform/parameter/GeometryInfoParameters.java index 68306d36cd..5356557a73 100644 --- a/common/src/main/java/net/irisshaders/iris/pipeline/transform/parameter/GeometryInfoParameters.java +++ b/common/src/main/java/net/irisshaders/iris/pipeline/transform/parameter/GeometryInfoParameters.java @@ -9,13 +9,15 @@ public abstract class GeometryInfoParameters extends Parameters { public final boolean hasGeometry; public final boolean hasTesselation; + public final boolean injectAmbientOcclusion; // WARNING: adding new fields requires updating hashCode and equals methods! public GeometryInfoParameters(Patch patch, - Object2ObjectMap, String> textureMap, boolean hasGeometry, boolean hasTesselation) { + Object2ObjectMap, String> textureMap, boolean hasGeometry, boolean hasTesselation, boolean injectAmbientOcclusion) { super(patch, textureMap); this.hasGeometry = hasGeometry; this.hasTesselation = hasTesselation; + this.injectAmbientOcclusion = injectAmbientOcclusion; } @Override @@ -23,6 +25,8 @@ public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + (hasGeometry ? 1231 : 1237); + result = prime * result + (hasTesselation ? 1231 : 1237); + result = prime * result + (injectAmbientOcclusion ? 1231 : 1237); return result; } @@ -35,6 +39,6 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) return false; GeometryInfoParameters other = (GeometryInfoParameters) obj; - return hasGeometry == other.hasGeometry; + return hasGeometry == other.hasGeometry && hasTesselation == other.hasTesselation && injectAmbientOcclusion == other.injectAmbientOcclusion; } } diff --git a/common/src/main/java/net/irisshaders/iris/pipeline/transform/parameter/SodiumParameters.java b/common/src/main/java/net/irisshaders/iris/pipeline/transform/parameter/SodiumParameters.java index cefc8f12d4..7ed051d39a 100644 --- a/common/src/main/java/net/irisshaders/iris/pipeline/transform/parameter/SodiumParameters.java +++ b/common/src/main/java/net/irisshaders/iris/pipeline/transform/parameter/SodiumParameters.java @@ -7,7 +7,7 @@ import net.irisshaders.iris.pipeline.transform.Patch; import net.irisshaders.iris.shaderpack.texture.TextureStage; -public class SodiumParameters extends Parameters { +public class SodiumParameters extends GeometryInfoParameters { // WARNING: adding new fields requires updating hashCode and equals methods! // DO NOT include this field in hashCode or equals, it's mutable! @@ -16,8 +16,8 @@ public class SodiumParameters extends Parameters { public SodiumParameters(Patch patch, Object2ObjectMap, String> textureMap, - AlphaTest alpha) { - super(patch, textureMap); + AlphaTest alpha, boolean hasGeometry, boolean hasTessellation, boolean injectAmbientOcclusion) { + super(patch, textureMap, hasGeometry, hasTessellation, injectAmbientOcclusion); this.alpha = alpha; } diff --git a/common/src/main/java/net/irisshaders/iris/pipeline/transform/parameter/VanillaParameters.java b/common/src/main/java/net/irisshaders/iris/pipeline/transform/parameter/VanillaParameters.java index 6dccd62f76..dd53d63588 100644 --- a/common/src/main/java/net/irisshaders/iris/pipeline/transform/parameter/VanillaParameters.java +++ b/common/src/main/java/net/irisshaders/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, boolean hasTesselation) { - super(patch, textureMap, hasGeometry, hasTesselation); + ShaderAttributeInputs inputs, boolean hasGeometry, boolean hasTesselation, boolean injectAmbientOcclusion) { + super(patch, textureMap, hasGeometry, hasTesselation, injectAmbientOcclusion); this.alpha = alpha; this.isLines = isLines; this.hasChunkOffset = hasChunkOffset; diff --git a/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/CommonTransformer.java b/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/CommonTransformer.java index 1fa6cf1dd1..f46c898a11 100644 --- a/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/CommonTransformer.java +++ b/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/CommonTransformer.java @@ -156,16 +156,16 @@ public static void transform( boolean core) { // TODO: What if the shader does gl_PerVertex.gl_FogFragCoord ? - root.rename("gl_FogFragCoord", "iris_FogFragCoord"); + root.rename("gl_FogFragCoord", "irisInt_FogFragCoord"); // TODO: This doesn't handle geometry shaders... How do we do that? if (parameters.type.glShaderType == ShaderType.VERTEX) { tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, - "out float iris_FogFragCoord;"); - tree.prependMainFunctionBody(t, "iris_FogFragCoord = 0.0f;"); + "out float irisInt_FogFragCoord;"); + tree.prependMainFunctionBody(t, "irisInt_FogFragCoord = 0.0f;"); } else if (parameters.type.glShaderType == ShaderType.FRAGMENT) { tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, - "in float iris_FogFragCoord;"); + "in float irisInt_FogFragCoord;"); } if (parameters.type.glShaderType == ShaderType.VERTEX) { @@ -174,8 +174,8 @@ public static void transform( // even though they write to it. tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, - "vec4 iris_FrontColor;"); - root.rename("gl_FrontColor", "iris_FrontColor"); + "vec4 irisInt_FrontColor;"); + root.rename("gl_FrontColor", "irisInt_FrontColor"); } if (parameters.type.glShaderType == ShaderType.FRAGMENT) { @@ -195,7 +195,7 @@ public static void transform( tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "in vec4 irs_Color;"); } - // change gl_FragData[i] to iris_FragDatai + // change gl_FragData[i] to irisInt_FragDatai replaceExpressions.clear(); replaceIndexes.clear(); Set replaceIndexesSet = new HashSet<>(); @@ -211,22 +211,22 @@ public static void transform( } for (int i = 0; i < replaceExpressions.size(); i++) { replaceExpressions.get(i).replaceByAndDelete( - new ReferenceExpression(new Identifier("iris_FragData" + replaceIndexes.get(i)))); + new ReferenceExpression(new Identifier("irisInt_FragData" + replaceIndexes.get(i)))); } for (long index : replaceIndexesSet) { tree.injectNode(ASTInjectionPoint.BEFORE_DECLARATIONS, fragDataDeclaration.getInstanceFor(root, new LiteralExpression(Type.INT32, index), - new Identifier("iris_FragData" + index))); + new Identifier("irisInt_FragData" + index))); } replaceExpressions.clear(); replaceIndexes.clear(); - // insert alpha test for iris_FragData0 in the fragment shader + // insert alpha test for irisInt_FragData0 in the fragment shader if ((parameters.getAlphaTest() != AlphaTest.ALWAYS && !core) && replaceIndexesSet.contains(0L)) { - tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "uniform float iris_currentAlphaTest;"); + tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "uniform float irisInt_currentAlphaTest;"); tree.appendMainFunctionBody(t, - parameters.getAlphaTest().toExpression("iris_FragData0.a", "iris_currentAlphaTest", " ")); + parameters.getAlphaTest().toExpression("irisInt_FragData0.a", "irisInt_currentAlphaTest", " ")); } } @@ -269,20 +269,20 @@ public static void transform( // This must be defined and valid in all shader passes, including composite // passes. A shader that relies on this behavior is SEUS v11 - it reads // gl_Fog.color and breaks if it is not properly defined. - root.rename("gl_Fog", "iris_Fog"); + root.rename("gl_Fog", "irisInt_Fog"); tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_DECLARATIONS, - "uniform float iris_FogDensity;", - "uniform float iris_FogStart;", - "uniform float iris_FogEnd;", - "uniform vec4 iris_FogColor;", - "struct iris_FogParameters {" + + "uniform float irisInt_FogDensity;", + "uniform float irisInt_FogStart;", + "uniform float irisInt_FogEnd;", + "uniform vec4 irisInt_FogColor;", + "struct irisInt_FogParameters {" + "vec4 color;" + "float density;" + "float start;" + "float end;" + "float scale;" + "};", - "iris_FogParameters iris_Fog = iris_FogParameters(iris_FogColor, iris_FogDensity, iris_FogStart, iris_FogEnd, 1.0 / (iris_FogEnd - iris_FogStart));"); + "irisInt_FogParameters irisInt_Fog = irisInt_FogParameters(irisInt_FogColor, irisInt_FogDensity, irisInt_FogStart, irisInt_FogEnd, 1.0 / (irisInt_FogEnd - irisInt_FogStart));"); // TODO: Add similar functions for all legacy texture sampling functions renameFunctionCall(root, "texture2D", "texture"); @@ -371,7 +371,7 @@ public static void applyIntelHd4000Workaround(Root root) { // // Note that this happens after we've added our ftransform function - so that // both all the calls and our function are renamed in one go. - root.rename("ftransform", "iris_ftransform"); + root.rename("ftransform", "irisInt_ftransform"); } public static void replaceGlMultiTexCoordBounded( diff --git a/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/CompositeDepthTransformer.java b/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/CompositeDepthTransformer.java index 40ea3b1f69..51ba91dcfc 100644 --- a/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/CompositeDepthTransformer.java +++ b/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/CompositeDepthTransformer.java @@ -44,11 +44,11 @@ public static void transform( } })) { tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, - "uniform sampler2D iris_centerDepthSmooth;"); + "uniform sampler2D irisInt_centerDepthSmooth;"); // if centerDepthSmooth is not declared as a uniform, we don't make it available root.replaceReferenceExpressions(t, "centerDepthSmooth", - "texture(iris_centerDepthSmooth, vec2(0.5)).r"); + "texture(irisInt_centerDepthSmooth, vec2(0.5)).r"); } } } diff --git a/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/DHGenericTransformer.java b/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/DHGenericTransformer.java index eb8474edfe..9c36fbb767 100644 --- a/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/DHGenericTransformer.java +++ b/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/DHGenericTransformer.java @@ -22,7 +22,7 @@ public static void transform( root.replaceExpressionMatches(t, CommonTransformer.glTextureMatrix0, "mat4(1.0)"); root.replaceExpressionMatches(t, CommonTransformer.glTextureMatrix1, "mat4(1.0)"); - root.rename("gl_ProjectionMatrix", "iris_ProjectionMatrix"); + root.rename("gl_ProjectionMatrix", "irisInt_ProjectionMatrix"); if (parameters.type.glShaderType == ShaderType.VERTEX) { // Alias of gl_MultiTexCoord1 on 1.15+ for OptiFine @@ -52,23 +52,23 @@ public static void transform( // TODO: Should probably add the normal matrix as a proper uniform that's // computed on the CPU-side of things root.replaceReferenceExpressions(t, "gl_NormalMatrix", - "iris_NormalMatrix"); + "irisInt_NormalMatrix"); tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, - "uniform mat3 iris_NormalMatrix;"); + "uniform mat3 irisInt_NormalMatrix;"); tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, - "uniform mat4 iris_ModelViewMatrixInverse;"); + "uniform mat4 irisInt_ModelViewMatrixInverse;"); tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, - "uniform mat4 iris_ProjectionMatrixInverse;"); + "uniform mat4 irisInt_ProjectionMatrixInverse;"); Iris.logger.warn("Type is " + parameters.type); // TODO: All of the transformed variants of the input matrices, preferably // computed on the CPU side... - root.rename("gl_ModelViewMatrix", "iris_ModelViewMatrix"); - root.rename("gl_ModelViewMatrixInverse", "iris_ModelViewMatrixInverse"); - root.rename("gl_ProjectionMatrixInverse", "iris_ProjectionMatrixInverse"); + root.rename("gl_ModelViewMatrix", "irisInt_ModelViewMatrix"); + root.rename("gl_ModelViewMatrixInverse", "irisInt_ModelViewMatrixInverse"); + root.rename("gl_ProjectionMatrixInverse", "irisInt_ProjectionMatrixInverse"); if (parameters.type.glShaderType == ShaderType.VERTEX) { // TODO: Vaporwave-Shaderpack expects that vertex positions will be aligned to @@ -78,8 +78,8 @@ public static void transform( "vec4 ftransform() { return gl_ModelViewProjectionMatrix * gl_Vertex; }"); } tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_DECLARATIONS, - "uniform mat4 iris_ProjectionMatrix;", - "uniform mat4 iris_ModelViewMatrix;", + "uniform mat4 irisInt_ProjectionMatrix;", + "uniform mat4 irisInt_ModelViewMatrix;", // _draw_translation replaced with Chunks[_draw_id].offset.xyz "vec4 getVertexPosition() { return vec4(_vert_position, 1.0); }"); root.replaceReferenceExpressions(t, "gl_Vertex", "getVertexPosition()"); @@ -90,12 +90,12 @@ public static void transform( injectVertInit(t, tree, root, parameters); } else { tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_DECLARATIONS, - "uniform mat4 iris_ModelViewMatrix;", - "uniform mat4 iris_ProjectionMatrix;"); + "uniform mat4 irisInt_ModelViewMatrix;", + "uniform mat4 irisInt_ProjectionMatrix;"); } root.replaceReferenceExpressions(t, "gl_ModelViewProjectionMatrix", - "(iris_ProjectionMatrix * iris_ModelViewMatrix)"); + "(irisInt_ProjectionMatrix * irisInt_ModelViewMatrix)"); CommonTransformer.applyIntelHd4000Workaround(root); } @@ -135,10 +135,10 @@ void _vert_init() { float skyLight = (float(uSkyLight)+0.5) / 16.0; _vert_tex_light_coord = vec2(blockLight, skyLight); dhMaterialId = aMaterial; - _vert_color = iris_color; + _vert_color = irisInt_color; } """); - addIfNotExists(root, t, tree, "iris_color", Type.F32VEC4, StorageQualifier.StorageType.IN, 1); + addIfNotExists(root, t, tree, "irisInt_color", Type.F32VEC4, StorageQualifier.StorageType.IN, 1); addIfNotExists(root, t, tree, "aScale", Type.F32VEC3, StorageQualifier.StorageType.IN, 2); addIfNotExists(root, t, tree, "aTranslateChunk", Type.I32VEC3, StorageQualifier.StorageType.IN, 3); addIfNotExists(root, t, tree, "aTranslateSubChunk", Type.F32VEC3, StorageQualifier.StorageType.IN, 4); diff --git a/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/DHTerrainTransformer.java b/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/DHTerrainTransformer.java index b962ac2440..927d6d13b8 100644 --- a/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/DHTerrainTransformer.java +++ b/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/DHTerrainTransformer.java @@ -22,7 +22,7 @@ public static void transform( root.replaceExpressionMatches(t, CommonTransformer.glTextureMatrix0, "mat4(1.0)"); root.replaceExpressionMatches(t, CommonTransformer.glTextureMatrix1, "mat4(1.0)"); - root.rename("gl_ProjectionMatrix", "iris_ProjectionMatrix"); + root.rename("gl_ProjectionMatrix", "irisInt_ProjectionMatrix"); if (parameters.type.glShaderType == ShaderType.VERTEX) { // Alias of gl_MultiTexCoord1 on 1.15+ for OptiFine @@ -52,23 +52,23 @@ public static void transform( // TODO: Should probably add the normal matrix as a proper uniform that's // computed on the CPU-side of things root.replaceReferenceExpressions(t, "gl_NormalMatrix", - "iris_NormalMatrix"); + "irisInt_NormalMatrix"); tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, - "uniform mat3 iris_NormalMatrix;"); + "uniform mat3 irisInt_NormalMatrix;"); tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, - "uniform mat4 iris_ModelViewMatrixInverse;"); + "uniform mat4 irisInt_ModelViewMatrixInverse;"); tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, - "uniform mat4 iris_ProjectionMatrixInverse;"); + "uniform mat4 irisInt_ProjectionMatrixInverse;"); Iris.logger.warn("Type is " + parameters.type); // TODO: All of the transformed variants of the input matrices, preferably // computed on the CPU side... - root.rename("gl_ModelViewMatrix", "iris_ModelViewMatrix"); - root.rename("gl_ModelViewMatrixInverse", "iris_ModelViewMatrixInverse"); - root.rename("gl_ProjectionMatrixInverse", "iris_ProjectionMatrixInverse"); + root.rename("gl_ModelViewMatrix", "irisInt_ModelViewMatrix"); + root.rename("gl_ModelViewMatrixInverse", "irisInt_ModelViewMatrixInverse"); + root.rename("gl_ProjectionMatrixInverse", "irisInt_ProjectionMatrixInverse"); if (parameters.type.glShaderType == ShaderType.VERTEX) { // TODO: Vaporwave-Shaderpack expects that vertex positions will be aligned to @@ -78,8 +78,8 @@ public static void transform( "vec4 ftransform() { return gl_ModelViewProjectionMatrix * gl_Vertex; }"); } tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_DECLARATIONS, - "uniform mat4 iris_ProjectionMatrix;", - "uniform mat4 iris_ModelViewMatrix;", + "uniform mat4 irisInt_ProjectionMatrix;", + "uniform mat4 irisInt_ModelViewMatrix;", // _draw_translation replaced with Chunks[_draw_id].offset.xyz "vec4 getVertexPosition() { return vec4(modelOffset + _vert_position, 1.0); }"); root.replaceReferenceExpressions(t, "gl_Vertex", "getVertexPosition()"); @@ -90,12 +90,12 @@ public static void transform( injectVertInit(t, tree, root, parameters); } else { tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_DECLARATIONS, - "uniform mat4 iris_ModelViewMatrix;", - "uniform mat4 iris_ProjectionMatrix;"); + "uniform mat4 irisInt_ModelViewMatrix;", + "uniform mat4 irisInt_ProjectionMatrix;"); } root.replaceReferenceExpressions(t, "gl_ModelViewProjectionMatrix", - "(iris_ProjectionMatrix * iris_ModelViewMatrix)"); + "(irisInt_ProjectionMatrix * irisInt_ModelViewMatrix)"); CommonTransformer.applyIntelHd4000Workaround(root); } @@ -133,8 +133,8 @@ public static void injectVertInit( "_vert_normal = irisNormals[irisExtra.y];" + "dhMaterialId = int(irisExtra.x);" + "_vert_tex_light_coord = vec2((float(lights/16u)+0.5) / 16.0, (mod(float(lights), 16.0)+0.5) / 16.0);" + - "_vert_color = iris_color; }"); - addIfNotExists(root, t, tree, "iris_color", Type.F32VEC4, StorageQualifier.StorageType.IN); + "_vert_color = irisInt_color; }"); + addIfNotExists(root, t, tree, "irisInt_color", Type.F32VEC4, StorageQualifier.StorageType.IN); addIfNotExists(root, t, tree, "vPosition", Type.U32VEC4, StorageQualifier.StorageType.IN); addIfNotExists(root, t, tree, "irisExtra", Type.U32VEC4, StorageQualifier.StorageType.IN); tree.prependMainFunctionBody(t, "_vert_init();"); diff --git a/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/EntityPatcher.java b/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/EntityPatcher.java index 1ff2115e1f..c9070ca2fb 100644 --- a/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/EntityPatcher.java +++ b/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/EntityPatcher.java @@ -38,18 +38,18 @@ public static void patchOverlayColor( // TODO: We're exposing entityColor to this stage even if it isn't declared in // this stage. But this is needed for the pass-through behavior. tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_DECLARATIONS, - "uniform sampler2D iris_overlay;", + "uniform sampler2D irisInt_overlay;", "out vec4 entityColor;", - "out vec4 iris_vertexColor;", - parameters.inputs.isIE() ? "uniform ivec2 iris_OverlayUV;" : "in ivec2 iris_UV1;"); + "out vec4 irisInt_vertexColor;", + parameters.inputs.isIE() ? "uniform ivec2 irisInt_OverlayUV;" : "in ivec2 irisInt_UV1;"); // Create our own main function to wrap the existing main function, so that we // can pass through the overlay color at the end to the geometry or fragment // stage. tree.prependMainFunctionBody(t, - "vec4 overlayColor = texelFetch(iris_overlay, " + (parameters.inputs.isIE() ? "iris_OverlayUV" : "iris_UV1") + ", 0);", + "vec4 overlayColor = texelFetch(irisInt_overlay, " + (parameters.inputs.isIE() ? "irisInt_OverlayUV" : "irisInt_UV1") + ", 0);", "entityColor = vec4(overlayColor.rgb, 1.0 - overlayColor.a);", - "iris_vertexColor = iris_Color;", + "irisInt_vertexColor = irisInt_Color;", // Workaround for a shader pack bug: // https://github.com/IrisShaders/Iris/issues/1549 // Some shader packs incorrectly ignore the alpha value, and assume that rgb @@ -63,11 +63,11 @@ public static void patchOverlayColor( tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "patch out vec4 entityColorTCS;", "in vec4 entityColor[];", - "out vec4 iris_vertexColorTCS[];", - "in vec4 iris_vertexColor[];"); + "out vec4 irisInt_vertexColorTCS[];", + "in vec4 irisInt_vertexColor[];"); tree.prependMainFunctionBody(t, "entityColorTCS = entityColor[gl_InvocationID];", - "iris_vertexColorTCS[gl_InvocationID] = iris_vertexColor[gl_InvocationID];"); + "irisInt_vertexColorTCS[gl_InvocationID] = irisInt_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"); @@ -76,11 +76,11 @@ public static void patchOverlayColor( tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "out vec4 entityColorTES;", "patch in vec4 entityColorTCS;", - "out vec4 iris_vertexColorTES;", - "in vec4 iris_vertexColorTCS[];"); + "out vec4 irisInt_vertexColorTES;", + "in vec4 irisInt_vertexColorTCS[];"); tree.prependMainFunctionBody(t, "entityColorTES = entityColorTCS;", - "iris_vertexColorTES = iris_vertexColorTCS[0];"); + "irisInt_vertexColorTES = irisInt_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]"); @@ -89,29 +89,29 @@ public static void patchOverlayColor( tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "out vec4 entityColorGS;", "in vec4 entityColor[];", - "out vec4 iris_vertexColorGS;", - "in vec4 iris_vertexColor[];"); + "out vec4 irisInt_vertexColorGS;", + "in vec4 irisInt_vertexColor[];"); tree.prependMainFunctionBody(t, "entityColorGS = entityColor[0];", - "iris_vertexColorGS = iris_vertexColor[0];"); + "irisInt_vertexColorGS = irisInt_vertexColor[0];"); if (parameters.hasTesselation) { - root.rename("iris_vertexColor", "iris_vertexColorTES"); + root.rename("irisInt_vertexColor", "irisInt_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;"); + "in vec4 entityColor;", "in vec4 irisInt_vertexColor;"); - tree.prependMainFunctionBody(t, "float iris_vertexColorAlpha = iris_vertexColor.a;"); + tree.prependMainFunctionBody(t, "float irisInt_vertexColorAlpha = irisInt_vertexColor.a;"); // Different output name to avoid a name collision in the geometry shader. if (parameters.hasGeometry) { root.rename("entityColor", "entityColorGS"); - root.rename("iris_vertexColor", "iris_vertexColorGS"); + root.rename("irisInt_vertexColor", "irisInt_vertexColorGS"); } else if (parameters.hasTesselation) { root.rename("entityColor", "entityColorTES"); - root.rename("iris_vertexColor", "iris_vertexColorTES"); + root.rename("irisInt_vertexColor", "irisInt_vertexColorTES"); } } } @@ -129,22 +129,22 @@ public static void patchEntityId( if (parameters.type.glShaderType == ShaderType.GEOMETRY) { root.replaceReferenceExpressions(t, "entityId", - "iris_entityInfo[0].x"); + "irisInt_entityInfo[0].x"); root.replaceReferenceExpressions(t, "blockEntityId", - "iris_entityInfo[0].y"); + "irisInt_entityInfo[0].y"); root.replaceReferenceExpressions(t, "currentRenderedItemId", - "iris_entityInfo[0].z"); + "irisInt_entityInfo[0].z"); } else { root.replaceReferenceExpressions(t, "entityId", - "iris_entityInfo.x"); + "irisInt_entityInfo.x"); root.replaceReferenceExpressions(t, "blockEntityId", - "iris_entityInfo.y"); + "irisInt_entityInfo.y"); root.replaceReferenceExpressions(t, "currentRenderedItemId", - "iris_entityInfo.z"); + "irisInt_entityInfo.z"); } if (parameters.type.glShaderType == ShaderType.VERTEX) { @@ -152,49 +152,49 @@ public static void patchEntityId( // TODO: We're exposing entityColor to this stage even if it isn't declared in // this stage. But this is needed for the pass-through behavior. tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_DECLARATIONS, - "flat out ivec3 iris_entityInfo;", - "in ivec3 iris_Entity;"); + "flat out ivec3 irisInt_entityInfo;", + "in ivec3 irisInt_Entity;"); // Create our own main function to wrap the existing main function, so that we // can pass through the overlay color at the end to the geometry or fragment // stage. tree.prependMainFunctionBody(t, - "iris_entityInfo = iris_Entity;"); + "irisInt_entityInfo = irisInt_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]"); + "flat out ivec3 irisInt_entityInfoTCS[];", + "flat in ivec3 irisInt_entityInfo[];"); + root.replaceReferenceExpressions(t, "irisInt_entityInfo", "irisInt_EntityInfo[gl_InvocationID]"); tree.prependMainFunctionBody(t, - "iris_entityInfoTCS[gl_InvocationID] = iris_entityInfo[gl_InvocationID];"); + "irisInt_entityInfoTCS[gl_InvocationID] = irisInt_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[];"); + "flat out ivec3 irisInt_entityInfoTES;", + "flat in ivec3 irisInt_entityInfoTCS[];"); tree.prependMainFunctionBody(t, - "iris_entityInfoTES = iris_entityInfoTCS[0];"); + "irisInt_entityInfoTES = irisInt_entityInfoTCS[0];"); - root.replaceReferenceExpressions(t, "iris_entityInfo", "iris_EntityInfoTCS[0]"); + root.replaceReferenceExpressions(t, "irisInt_entityInfo", "irisInt_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" + (parameters.hasTesselation ? "TES" : "") + "[];"); + "flat out ivec3 irisInt_entityInfoGS;", + "flat in ivec3 irisInt_entityInfo" + (parameters.hasTesselation ? "TES" : "") + "[];"); tree.prependMainFunctionBody(t, - "iris_entityInfoGS = iris_entityInfo" + (parameters.hasTesselation ? "TES" : "") + "[0];"); + "irisInt_entityInfoGS = irisInt_entityInfo" + (parameters.hasTesselation ? "TES" : "") + "[0];"); } else if (parameters.type.glShaderType == ShaderType.FRAGMENT) { tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_DECLARATIONS, - "flat in ivec3 iris_entityInfo;"); + "flat in ivec3 irisInt_entityInfo;"); // Different output name to avoid a name collision in the geometry shader. if (parameters.hasGeometry) { - root.rename("iris_entityInfo", "iris_EntityInfoGS"); + root.rename("irisInt_entityInfo", "irisInt_EntityInfoGS"); } else if (parameters.hasTesselation) { - root.rename("iris_entityInfo", "iris_entityInfoTES"); + root.rename("irisInt_entityInfo", "irisInt_entityInfoTES"); } } } diff --git a/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/SodiumCoreTransformer.java b/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/SodiumCoreTransformer.java index 9bc0515882..4a37e0f7a5 100644 --- a/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/SodiumCoreTransformer.java +++ b/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/SodiumCoreTransformer.java @@ -12,12 +12,12 @@ public static void transform( TranslationUnit tree, Root root, SodiumParameters parameters) { - root.rename("alphaTestRef", "iris_currentAlphaTest"); - root.rename("modelViewMatrix", "iris_ModelViewMatrix"); - root.rename("modelViewMatrixInverse", "iris_ModelViewMatrixInverse"); - root.rename("projectionMatrix", "iris_ProjectionMatrix"); - root.rename("projectionMatrixInverse", "iris_ProjectionMatrixInverse"); - root.rename("normalMatrix", "iris_NormalMatrix"); + root.rename("alphaTestRef", "irisInt_currentAlphaTest"); + root.rename("modelViewMatrix", "irisInt_ModelViewMatrix"); + root.rename("modelViewMatrixInverse", "irisInt_ModelViewMatrixInverse"); + root.rename("projectionMatrix", "irisInt_ProjectionMatrix"); + root.rename("projectionMatrixInverse", "irisInt_ProjectionMatrixInverse"); + root.rename("normalMatrix", "irisInt_NormalMatrix"); root.rename("chunkOffset", "u_RegionOffset"); if (parameters.type == PatchShaderType.VERTEX) { boolean needsNormal = root.identifierIndex.has("vaNormal") || root.identifierIndex.has("at_tangent"); @@ -33,7 +33,7 @@ public static void transform( root.replaceReferenceExpressions(t, "textureMatrix", "mat4(1.0)"); SodiumTransformer.replaceMidTexCoord(t, tree, root, 1.0f / 32768.0f); - SodiumTransformer.replaceMCEntity(t, tree, root); + SodiumTransformer.replaceMCEntity(t, tree, root, parameters.injectAmbientOcclusion); SodiumTransformer.injectVertInit(t, tree, root, parameters, needsNormal); } diff --git a/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/SodiumTransformer.java b/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/SodiumTransformer.java index 460d1313c9..7e999ba8a9 100644 --- a/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/SodiumTransformer.java +++ b/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/SodiumTransformer.java @@ -11,6 +11,7 @@ import io.github.douira.glsl_transformer.ast.transform.ASTParser; import io.github.douira.glsl_transformer.util.Type; import net.irisshaders.iris.gl.shader.ShaderType; +import net.irisshaders.iris.pipeline.transform.PatchShaderType; import net.irisshaders.iris.pipeline.transform.parameter.SodiumParameters; import static net.irisshaders.iris.pipeline.transform.transformer.CommonTransformer.addIfNotExists; @@ -23,15 +24,17 @@ public static void transform( SodiumParameters parameters) { CommonTransformer.transform(t, tree, root, parameters, false); - replaceMidTexCoord(t, tree, root, 1.0f / 32768.0f); - replaceMCEntity(t, tree, root); + if (parameters.type == PatchShaderType.VERTEX) { + replaceMidTexCoord(t, tree, root, 1.0f / 32768.0f); + replaceMCEntity(t, tree, root, parameters.injectAmbientOcclusion); + } boolean needsNormal = root.identifierIndex.has("gl_Normal") || root.identifierIndex.has("at_tangent"); root.replaceExpressionMatches(t, CommonTransformer.glTextureMatrix0, "mat4(1.0)"); - root.replaceExpressionMatches(t, CommonTransformer.glTextureMatrix1, "iris_LightmapTextureMatrix"); - tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_FUNCTIONS, "uniform mat4 iris_LightmapTextureMatrix;"); - root.rename("gl_ProjectionMatrix", "iris_ProjectionMatrix"); + root.replaceExpressionMatches(t, CommonTransformer.glTextureMatrix1, "irisInt_LightmapTextureMatrix"); + tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_FUNCTIONS, "uniform mat4 irisInt_LightmapTextureMatrix;"); + root.rename("gl_ProjectionMatrix", "irisInt_ProjectionMatrix"); if (parameters.type.glShaderType == ShaderType.VERTEX) { // Alias of gl_MultiTexCoord1 on 1.15+ for OptiFine @@ -62,21 +65,21 @@ public static void transform( // TODO: Should probably add the normal matrix as a proper uniform that's // computed on the CPU-side of things root.replaceReferenceExpressions(t, "gl_NormalMatrix", - "iris_NormalMatrix"); + "irisInt_NormalMatrix"); tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, - "uniform mat3 iris_NormalMatrix;"); + "uniform mat3 irisInt_NormalMatrix;"); tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, - "uniform mat4 iris_ModelViewMatrixInverse;"); + "uniform mat4 irisInt_ModelViewMatrixInverse;"); tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, - "uniform mat4 iris_ProjectionMatrixInverse;"); + "uniform mat4 irisInt_ProjectionMatrixInverse;"); // TODO: All of the transformed variants of the input matrices, preferably // computed on the CPU side... - root.rename("gl_ModelViewMatrix", "iris_ModelViewMatrix"); - root.rename("gl_ModelViewMatrixInverse", "iris_ModelViewMatrixInverse"); - root.rename("gl_ProjectionMatrixInverse", "iris_ProjectionMatrixInverse"); + root.rename("gl_ModelViewMatrix", "irisInt_ModelViewMatrix"); + root.rename("gl_ModelViewMatrixInverse", "irisInt_ModelViewMatrixInverse"); + root.rename("gl_ProjectionMatrixInverse", "irisInt_ProjectionMatrixInverse"); if (parameters.type.glShaderType == ShaderType.VERTEX) { // TODO: Vaporwave-Shaderpack expects that vertex positions will be aligned to @@ -86,8 +89,8 @@ public static void transform( "vec4 ftransform() { return gl_ModelViewProjectionMatrix * gl_Vertex; }"); } tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_DECLARATIONS, - "uniform mat4 iris_ProjectionMatrix;", - "uniform mat4 iris_ModelViewMatrix;", + "uniform mat4 irisInt_ProjectionMatrix;", + "uniform mat4 irisInt_ModelViewMatrix;", "uniform vec3 u_RegionOffset;", // _draw_translation replaced with Chunks[_draw_id].offset.xyz "vec4 getVertexPosition() { return vec4(_vert_position + u_RegionOffset + _get_draw_translation(_draw_id), 1.0); }"); @@ -99,12 +102,12 @@ public static void transform( injectVertInit(t, tree, root, parameters, needsNormal); } else { tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_DECLARATIONS, - "uniform mat4 iris_ModelViewMatrix;", - "uniform mat4 iris_ProjectionMatrix;"); + "uniform mat4 irisInt_ModelViewMatrix;", + "uniform mat4 irisInt_ProjectionMatrix;"); } root.replaceReferenceExpressions(t, "gl_ModelViewProjectionMatrix", - "(iris_ProjectionMatrix * iris_ModelViewMatrix)"); + "(irisInt_ProjectionMatrix * irisInt_ModelViewMatrix)"); CommonTransformer.applyIntelHd4000Workaround(root); } @@ -182,8 +185,8 @@ vec2 _get_texcoord_bias() { "_vert_tex_diffuse_coord = _get_texcoord() + _get_texcoord_bias();" + "_vert_tex_light_coord = vec2(a_LightAndData.xy);" + "_vert_color = a_Color;" + - (needsNormal ? "irs_Normal = oct_to_vec3(iris_Normal.xy);" : "") + - (needsNormal ? "irs_Tangent = tangent_decode(iris_Normal.zw);" : "") + + (needsNormal ? "irs_Normal = oct_to_vec3(irisInt_Normal.xy);" : "") + + (needsNormal ? "irs_Tangent = tangent_decode(irisInt_Normal.zw);" : "") + "_draw_id = a_LightAndData[3]; }", "uvec3 _get_relative_chunk_coord(uint pos) {\n" + @@ -197,13 +200,13 @@ vec2 _get_texcoord_bias() { addIfNotExists(root, t, tree, "a_TexCoord", Type.U32VEC2, StorageQualifier.StorageType.IN); addIfNotExists(root, t, tree, "a_Color", Type.F32VEC4, StorageQualifier.StorageType.IN); addIfNotExists(root, t, tree, "a_LightAndData", Type.U32VEC4, StorageQualifier.StorageType.IN); - if (needsNormal) addIfNotExists(root, t, tree, "iris_Normal", Type.F32VEC4, StorageQualifier.StorageType.IN); + if (needsNormal) addIfNotExists(root, t, tree, "irisInt_Normal", Type.F32VEC4, StorageQualifier.StorageType.IN); tree.prependMainFunctionBody(t, "_vert_init();"); } public static void replaceMCEntity(ASTParser t, - TranslationUnit tree, Root root) { + TranslationUnit tree, Root root, boolean injectAO) { Type dimension = Type.BOOL; for (Identifier id : root.identifierIndex.get("mc_Entity")) { TypeAndInitDeclaration initDeclaration = (TypeAndInitDeclaration) id.getAncestor( @@ -227,39 +230,44 @@ public static void replaceMCEntity(ASTParser t, } - root.replaceReferenceExpressions(t, "mc_Entity", "iris_Entity"); + root.replaceReferenceExpressions(t, "mc_Entity", "irisInt_Entity"); switch (dimension) { case BOOL: - return; + break; case FLOAT32: - tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "float iris_Entity = int(mc_Entity >> 1u) - 1;"); + tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "float irisInt_Entity = int(mc_Entity >> 10u) - 1;"); break; case F32VEC2: - tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "vec2 iris_Entity = vec2(int(mc_Entity >> 1u) - 1, mc_Entity & 1u);"); + tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "vec2 irisInt_Entity = vec2(int(mc_Entity >> 10u) - 1, mc_Entity >> 9u & 1u);"); break; case F32VEC3: - tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "vec3 iris_Entity = vec3(int(mc_Entity >> 1u) - 1, mc_Entity & 1u, 0.0);"); + tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "vec3 irisInt_Entity = vec3(int(mc_Entity >> 10u) - 1, mc_Entity >> 9u & 1u, 0.0);"); break; case F32VEC4: - tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "vec4 iris_Entity = vec4(int(mc_Entity >> 1u) - 1, mc_Entity & 1u, 0.0, 1.0);"); + tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "vec4 irisInt_Entity = vec4(int(mc_Entity >> 10u) - 1, mc_Entity >> 9u & 1u, 0.0, 1.0);"); break; case INT32: - tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "uint iris_Entity = int(mc_Entity >> 1u) - 1;"); + tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "uint irisInt_Entity = int(mc_Entity >> 10u) - 1;"); break; case I32VEC2: - tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "ivec2 iris_Entity = ivec2(int(mc_Entity >> 1u) - 1, mc_Entity & 1u);"); + tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "ivec2 irisInt_Entity = ivec2(int(mc_Entity >> 10u) - 1, mc_Entity >> 9u & 1u);"); break; case I32VEC3: - tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "ivec3 iris_Entity = ivec3(int(mc_Entity >> 1u) - 1, mc_Entity & 1u, 0);"); + tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "ivec3 irisInt_Entity = ivec3(int(mc_Entity >> 10u) - 1, mc_Entity >> 9u & 1u, 0);"); break; case I32VEC4: - tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "ivec4 iris_Entity = ivec4(int(mc_Entity >> 1u) - 1, mc_Entity & 1u, 0, 1);"); + tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "ivec4 irisInt_Entity = ivec4(int(mc_Entity >> 10u) - 1, mc_Entity >> 9u & 1u, 0, 1);"); break; default: throw new IllegalStateException("Got an invalid format mc_Entity (" + dimension.getCompactName() + ")."); } + if (injectAO) { + tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "float iris_ambientOcclusion = float((mc_Entity >> 1u) & 0xFFu) / 255.0;"); + tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "bool iris_Shade = bool(int(mc_Entity & 1u));"); + } + tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "in uint mc_Entity;"); } @@ -289,22 +297,22 @@ public static void replaceMidTexCoord(ASTParser t, } - root.replaceReferenceExpressions(t, "mc_midTexCoord", "iris_MidTex"); + root.replaceReferenceExpressions(t, "mc_midTexCoord", "irisInt_MidTex"); switch (dimension) { case BOOL: return; case FLOAT32: - tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "float iris_MidTex = (mc_midTexCoord.x * " + textureScale + ");"); + tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "float irisInt_MidTex = (mc_midTexCoord.x * " + textureScale + ");"); break; case F32VEC2: - tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "vec2 iris_MidTex = (mc_midTexCoord.xy * " + textureScale + ").xy;"); + tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "vec2 irisInt_MidTex = (mc_midTexCoord.xy * " + textureScale + ").xy;"); break; case F32VEC3: - tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "vec3 iris_MidTex = vec3(mc_midTexCoord.xy * " + textureScale + ", 0.0);"); + tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "vec3 irisInt_MidTex = vec3(mc_midTexCoord.xy * " + textureScale + ", 0.0);"); break; case F32VEC4: - tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "vec4 iris_MidTex = vec4(mc_midTexCoord.xy * " + textureScale + ", 0.0, 1.0);"); + tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "vec4 irisInt_MidTex = vec4(mc_midTexCoord.xy * " + textureScale + ", 0.0, 1.0);"); break; default: throw new IllegalStateException("Somehow got a midTexCoord that is *above* 4 dimensions???"); diff --git a/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/VanillaCoreTransformer.java b/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/VanillaCoreTransformer.java index ea86d4fa95..1b5e4d52f3 100644 --- a/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/VanillaCoreTransformer.java +++ b/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/VanillaCoreTransformer.java @@ -3,6 +3,7 @@ import io.github.douira.glsl_transformer.ast.node.TranslationUnit; import io.github.douira.glsl_transformer.ast.node.type.qualifier.StorageQualifier.StorageType; import io.github.douira.glsl_transformer.ast.query.Root; +import io.github.douira.glsl_transformer.ast.transform.ASTInjectionPoint; import io.github.douira.glsl_transformer.ast.transform.ASTParser; import io.github.douira.glsl_transformer.util.Type; import net.irisshaders.iris.pipeline.transform.PatchShaderType; @@ -23,69 +24,70 @@ public static void transform( } EntityPatcher.patchEntityId(t, tree, root, parameters); } + tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "float s_ambientOcclusion = 1.0f;"); CommonTransformer.transform(t, tree, root, parameters, true); - root.rename("alphaTestRef", "iris_currentAlphaTest"); - root.rename("modelViewMatrix", "iris_ModelViewMat"); - root.rename("gl_ModelViewMatrix", "iris_ModelViewMat"); - root.rename("modelViewMatrixInverse", "iris_ModelViewMatInverse"); - root.rename("gl_ModelViewMatrixInverse", "iris_ModelViewMatInverse"); - root.rename("projectionMatrix", "iris_ProjMat"); - root.rename("gl_ProjectionMatrix", "iris_ProjMat"); - root.rename("projectionMatrixInverse", "iris_ProjMatInverse"); - root.rename("gl_ProjectionMatrixInverse", "iris_ProjMatInverse"); - root.rename("textureMatrix", "iris_TextureMat"); + root.rename("alphaTestRef", "irisInt_currentAlphaTest"); + root.rename("modelViewMatrix", "irisInt_ModelViewMat"); + root.rename("gl_ModelViewMatrix", "irisInt_ModelViewMat"); + root.rename("modelViewMatrixInverse", "irisInt_ModelViewMatInverse"); + root.rename("gl_ModelViewMatrixInverse", "irisInt_ModelViewMatInverse"); + root.rename("projectionMatrix", "irisInt_ProjMat"); + root.rename("gl_ProjectionMatrix", "irisInt_ProjMat"); + root.rename("projectionMatrixInverse", "irisInt_ProjMatInverse"); + root.rename("gl_ProjectionMatrixInverse", "irisInt_ProjMatInverse"); + root.rename("textureMatrix", "irisInt_TextureMat"); - root.replaceExpressionMatches(t, CommonTransformer.glTextureMatrix0, "iris_TextureMat"); + root.replaceExpressionMatches(t, CommonTransformer.glTextureMatrix0, "irisInt_TextureMat"); root.replaceExpressionMatches(t, CommonTransformer.glTextureMatrix1, "mat4(vec4(0.00390625, 0.0, 0.0, 0.0), vec4(0.0, 0.00390625, 0.0, 0.0), vec4(0.0, 0.0, 0.00390625, 0.0), vec4(0.03125, 0.03125, 0.03125, 1.0))"); root.replaceExpressionMatches(t, CommonTransformer.glTextureMatrix2, "mat4(vec4(0.00390625, 0.0, 0.0, 0.0), vec4(0.0, 0.00390625, 0.0, 0.0), vec4(0.0, 0.0, 0.00390625, 0.0), vec4(0.03125, 0.03125, 0.03125, 1.0))"); - addIfNotExists(root, t, tree, "iris_TextureMat", Type.F32MAT4X4, StorageType.UNIFORM); - addIfNotExists(root, t, tree, "iris_ProjMat", Type.F32MAT4X4, StorageType.UNIFORM); - addIfNotExists(root, t, tree, "iris_ProjMatInverse", Type.F32MAT4X4, StorageType.UNIFORM); - addIfNotExists(root, t, tree, "iris_ModelViewMat", Type.F32MAT4X4, StorageType.UNIFORM); - addIfNotExists(root, t, tree, "iris_ModelViewMatInverse", Type.F32MAT4X4, StorageType.UNIFORM); - root.rename("normalMatrix", "iris_NormalMat"); - root.rename("gl_NormalMatrix", "iris_NormalMat"); - addIfNotExists(root, t, tree, "iris_NormalMat", Type.F32MAT3X3, StorageType.UNIFORM); - root.rename("chunkOffset", "iris_ChunkOffset"); - addIfNotExists(root, t, tree, "iris_ChunkOffset", Type.F32VEC3, StorageType.UNIFORM); + addIfNotExists(root, t, tree, "irisInt_TextureMat", Type.F32MAT4X4, StorageType.UNIFORM); + addIfNotExists(root, t, tree, "irisInt_ProjMat", Type.F32MAT4X4, StorageType.UNIFORM); + addIfNotExists(root, t, tree, "irisInt_ProjMatInverse", Type.F32MAT4X4, StorageType.UNIFORM); + addIfNotExists(root, t, tree, "irisInt_ModelViewMat", Type.F32MAT4X4, StorageType.UNIFORM); + addIfNotExists(root, t, tree, "irisInt_ModelViewMatInverse", Type.F32MAT4X4, StorageType.UNIFORM); + root.rename("normalMatrix", "irisInt_NormalMat"); + root.rename("gl_NormalMatrix", "irisInt_NormalMat"); + addIfNotExists(root, t, tree, "irisInt_NormalMat", Type.F32MAT3X3, StorageType.UNIFORM); + root.rename("chunkOffset", "irisInt_ChunkOffset"); + addIfNotExists(root, t, tree, "irisInt_ChunkOffset", Type.F32VEC3, StorageType.UNIFORM); CommonTransformer.upgradeStorageQualifiers(t, tree, root, parameters); if (parameters.type == PatchShaderType.VERTEX) { - root.replaceReferenceExpressions(t, "gl_Vertex", "vec4(iris_Position, 1.0)"); - root.rename("vaPosition", "iris_Position"); + root.replaceReferenceExpressions(t, "gl_Vertex", "vec4(irisInt_Position, 1.0)"); + root.rename("vaPosition", "irisInt_Position"); if (parameters.inputs.hasColor()) { - root.replaceReferenceExpressions(t, "vaColor", "iris_Color * iris_ColorModulator"); - root.replaceReferenceExpressions(t, "gl_Color", "iris_Color * iris_ColorModulator"); + root.replaceReferenceExpressions(t, "vaColor", "irisInt_Color * irisInt_ColorModulator"); + root.replaceReferenceExpressions(t, "gl_Color", "irisInt_Color * irisInt_ColorModulator"); } else { - root.replaceReferenceExpressions(t, "vaColor", "iris_ColorModulator"); - root.replaceReferenceExpressions(t, "gl_Color", "iris_ColorModulator"); + root.replaceReferenceExpressions(t, "vaColor", "irisInt_ColorModulator"); + root.replaceReferenceExpressions(t, "gl_Color", "irisInt_ColorModulator"); } - root.rename("vaNormal", "iris_Normal"); - root.rename("gl_Normal", "iris_Normal"); - root.rename("vaUV0", "iris_UV0"); - root.replaceReferenceExpressions(t, "gl_MultiTexCoord0", "vec4(iris_UV0, 0.0, 1.0)"); + root.rename("vaNormal", "irisInt_Normal"); + root.rename("gl_Normal", "irisInt_Normal"); + root.rename("vaUV0", "irisInt_UV0"); + root.replaceReferenceExpressions(t, "gl_MultiTexCoord0", "vec4(irisInt_UV0, 0.0, 1.0)"); if (parameters.inputs.hasLight()) { - root.replaceReferenceExpressions(t, "gl_MultiTexCoord1", "vec4(iris_UV2, 0.0, 1.0)"); - root.replaceReferenceExpressions(t, "gl_MultiTexCoord2", "vec4(iris_UV2, 0.0, 1.0)"); - root.rename("vaUV2", "iris_UV2"); + root.replaceReferenceExpressions(t, "gl_MultiTexCoord1", "vec4(irisInt_UV2, 0.0, 1.0)"); + root.replaceReferenceExpressions(t, "gl_MultiTexCoord2", "vec4(irisInt_UV2, 0.0, 1.0)"); + root.rename("vaUV2", "irisInt_UV2"); } else { root.replaceReferenceExpressions(t, "gl_MultiTexCoord1", "vec4(240.0, 240.0, 0.0, 1.0)"); root.replaceReferenceExpressions(t, "gl_MultiTexCoord2", "vec4(240.0, 240.0, 0.0, 1.0)"); - root.rename("vaUV2", "iris_UV2"); + root.rename("vaUV2", "irisInt_UV2"); } - root.rename("vaUV1", "iris_UV1"); + root.rename("vaUV1", "irisInt_UV1"); - addIfNotExists(root, t, tree, "iris_Color", Type.F32VEC4, StorageType.IN); - addIfNotExists(root, t, tree, "iris_ColorModulator", Type.F32VEC4, StorageType.UNIFORM); - addIfNotExists(root, t, tree, "iris_Position", Type.F32VEC3, StorageType.IN); - addIfNotExists(root, t, tree, "iris_Normal", Type.F32VEC3, StorageType.IN); - addIfNotExists(root, t, tree, "iris_UV0", Type.F32VEC2, StorageType.IN); - addIfNotExists(root, t, tree, "iris_UV1", Type.F32VEC2, StorageType.IN); - addIfNotExists(root, t, tree, "iris_UV2", Type.F32VEC2, StorageType.IN); + addIfNotExists(root, t, tree, "irisInt_Color", Type.F32VEC4, StorageType.IN); + addIfNotExists(root, t, tree, "irisInt_ColorModulator", Type.F32VEC4, StorageType.UNIFORM); + addIfNotExists(root, t, tree, "irisInt_Position", Type.F32VEC3, StorageType.IN); + addIfNotExists(root, t, tree, "irisInt_Normal", Type.F32VEC3, StorageType.IN); + addIfNotExists(root, t, tree, "irisInt_UV0", Type.F32VEC2, StorageType.IN); + addIfNotExists(root, t, tree, "irisInt_UV1", Type.F32VEC2, StorageType.IN); + addIfNotExists(root, t, tree, "irisInt_UV2", Type.F32VEC2, StorageType.IN); } } } diff --git a/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/VanillaTransformer.java b/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/VanillaTransformer.java index 03ef8a23a9..8bc287b2cd 100644 --- a/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/VanillaTransformer.java +++ b/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/VanillaTransformer.java @@ -27,15 +27,20 @@ public static void transform( CommonTransformer.transform(t, tree, root, parameters, false); if (parameters.type.glShaderType == ShaderType.VERTEX) { + if (parameters.injectAmbientOcclusion) { + tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "float iris_ambientOcclusion = 1.0f;"); + tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "bool iris_Shade = true;"); + } + // Alias of gl_MultiTexCoord1 on 1.15+ for OptiFine // See https://github.com/IrisShaders/Iris/issues/1149 root.rename("gl_MultiTexCoord2", "gl_MultiTexCoord1"); if (parameters.inputs.hasTex()) { root.replaceReferenceExpressions(t, "gl_MultiTexCoord0", - "vec4(iris_UV0, 0.0, 1.0)"); + "vec4(irisInt_UV0, 0.0, 1.0)"); tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, - "in vec2 iris_UV0;"); + "in vec2 irisInt_UV0;"); } else { root.replaceReferenceExpressions(t, "gl_MultiTexCoord0", "vec4(0.5, 0.5, 0.0, 1.0)"); @@ -43,16 +48,16 @@ public static void transform( if (parameters.inputs.isIE()) { root.replaceReferenceExpressions(t, "gl_MultiTexCoord1", - "vec4(iris_LightUV, 0.0, 1.0)"); + "vec4(irisInt_LightUV, 0.0, 1.0)"); tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, - "uniform ivec2 iris_LightUV;"); + "uniform ivec2 irisInt_LightUV;"); } else if (parameters.inputs.hasLight()) { root.replaceReferenceExpressions(t, "gl_MultiTexCoord1", - "vec4(iris_UV2, 0.0, 1.0)"); + "vec4(irisInt_UV2, 0.0, 1.0)"); tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, - "in ivec2 iris_UV2;"); + "in ivec2 irisInt_UV2;"); } else { root.replaceReferenceExpressions(t, "gl_MultiTexCoord1", "vec4(240.0, 240.0, 0.0, 1.0)"); @@ -67,43 +72,43 @@ public static void transform( } tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, - "uniform vec4 iris_ColorModulator;"); + "uniform vec4 irisInt_ColorModulator;"); if (parameters.inputs.hasColor() && parameters.type == PatchShaderType.VERTEX) { // TODO: Handle the fragment / geometry shader here if (parameters.alpha == AlphaTests.VERTEX_ALPHA) { root.replaceReferenceExpressions(t, "gl_Color", - "vec4((iris_Color * iris_ColorModulator).rgb, iris_ColorModulator.a)"); + "vec4((irisInt_Color * irisInt_ColorModulator).rgb, irisInt_ColorModulator.a)"); } else { root.replaceReferenceExpressions(t, "gl_Color", - "(iris_Color * iris_ColorModulator)"); + "(irisInt_Color * irisInt_ColorModulator)"); } if (parameters.type.glShaderType == ShaderType.VERTEX) { tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, - "in vec4 iris_Color;"); + "in vec4 irisInt_Color;"); } } else if (parameters.inputs.isGlint()) { tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, - "uniform float iris_GlintAlpha;"); - // iris_ColorModulator should be applied regardless of the alpha test state. - root.replaceReferenceExpressions(t, "gl_Color", "vec4(iris_ColorModulator.rgb, iris_ColorModulator.a * iris_GlintAlpha)"); + "uniform float irisInt_GlintAlpha;"); + // irisInt_ColorModulator should be applied regardless of the alpha test state. + root.replaceReferenceExpressions(t, "gl_Color", "vec4(irisInt_ColorModulator.rgb, irisInt_ColorModulator.a * irisInt_GlintAlpha)"); } else { - // iris_ColorModulator should be applied regardless of the alpha test state. - root.rename("gl_Color", "iris_ColorModulator"); + // irisInt_ColorModulator should be applied regardless of the alpha test state. + root.rename("gl_Color", "irisInt_ColorModulator"); } if (parameters.type.glShaderType == ShaderType.VERTEX) { if (parameters.inputs.hasNormal()) { if (!parameters.inputs.isNewLines()) { - root.rename("gl_Normal", "iris_Normal"); + root.rename("gl_Normal", "irisInt_Normal"); } else { root.replaceReferenceExpressions(t, "gl_Normal", "vec3(0.0, 0.0, 1.0)"); } tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, - "in vec3 iris_Normal;"); + "in vec3 irisInt_Normal;"); } else { root.replaceReferenceExpressions(t, "gl_Normal", "vec3(0.0, 0.0, 1.0)"); @@ -111,31 +116,31 @@ public static void transform( } tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_DECLARATIONS, - "uniform mat4 iris_LightmapTextureMatrix;", - "uniform mat4 iris_TextureMat;", - "uniform mat4 iris_ModelViewMat;"); + "uniform mat4 irisInt_LightmapTextureMatrix;", + "uniform mat4 irisInt_TextureMat;", + "uniform mat4 irisInt_ModelViewMat;"); // TODO: More solid way to handle texture matrices - root.replaceExpressionMatches(t, CommonTransformer.glTextureMatrix0, "iris_TextureMat"); - root.replaceExpressionMatches(t, CommonTransformer.glTextureMatrix1, "iris_LightmapTextureMatrix"); + root.replaceExpressionMatches(t, CommonTransformer.glTextureMatrix0, "irisInt_TextureMat"); + root.replaceExpressionMatches(t, CommonTransformer.glTextureMatrix1, "irisInt_LightmapTextureMatrix"); // TODO: Should probably add the normal matrix as a proper uniform that's // computed on the CPU-side of things root.replaceReferenceExpressions(t, "gl_NormalMatrix", - "iris_NormalMat"); + "irisInt_NormalMat"); root.replaceReferenceExpressions(t, "gl_ModelViewMatrixInverse", - "iris_ModelViewMatInverse"); + "irisInt_ModelViewMatInverse"); root.replaceReferenceExpressions(t, "gl_ProjectionMatrixInverse", - "iris_ProjMatInverse"); - tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "uniform mat3 iris_NormalMat;"); - tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "uniform mat4 iris_ProjMatInverse;"); - tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "uniform mat4 iris_ModelViewMatInverse;"); + "irisInt_ProjMatInverse"); + tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "uniform mat3 irisInt_NormalMat;"); + tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "uniform mat4 irisInt_ProjMatInverse;"); + tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "uniform mat4 irisInt_ModelViewMatInverse;"); if (parameters.type.glShaderType == ShaderType.VERTEX) { tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_DECLARATIONS, - "in vec3 iris_Position;"); + "in vec3 irisInt_Position;"); if (root.identifierIndex.has("ftransform")) { tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_FUNCTIONS, "vec4 ftransform() { return gl_ModelViewProjectionMatrix * gl_Vertex; }"); @@ -143,7 +148,7 @@ public static void transform( if (parameters.inputs.isNewLines()) { root.replaceReferenceExpressions(t, "gl_Vertex", - "vec4(iris_Position + iris_vertex_offset, 1.0)"); + "vec4(irisInt_Position + irisInt_vertex_offset, 1.0)"); // Create our own main function to wrap the existing main function, so that we // can do our line shenanigans. @@ -151,15 +156,15 @@ public static void transform( // in the vertex shader root.rename("main", "irisMain"); tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_DECLARATIONS, - "vec3 iris_vertex_offset = vec3(0.0);"); + "vec3 irisInt_vertex_offset = vec3(0.0);"); tree.parseAndInjectNodes(t, ASTInjectionPoint.END, - "uniform vec2 iris_ScreenSize;", - "uniform float iris_LineWidth;", - "void iris_widen_lines(vec4 linePosStart, vec4 linePosEnd) {" + + "uniform vec2 irisInt_ScreenSize;", + "uniform float irisInt_LineWidth;", + "void irisInt_widen_lines(vec4 linePosStart, vec4 linePosEnd) {" + "vec3 ndc1 = linePosStart.xyz / linePosStart.w;" + "vec3 ndc2 = linePosEnd.xyz / linePosEnd.w;" + - "vec2 lineScreenDirection = normalize((ndc2.xy - ndc1.xy) * iris_ScreenSize);" + - "vec2 lineOffset = vec2(-lineScreenDirection.y, lineScreenDirection.x) * iris_LineWidth / iris_ScreenSize;" + "vec2 lineScreenDirection = normalize((ndc2.xy - ndc1.xy) * irisInt_ScreenSize);" + + "vec2 lineOffset = vec2(-lineScreenDirection.y, lineScreenDirection.x) * irisInt_LineWidth / irisInt_ScreenSize;" + "if (lineOffset.x < 0.0) {" + " lineOffset *= -1.0;" + @@ -170,16 +175,16 @@ public static void transform( " gl_Position = vec4((ndc1 - vec3(lineOffset, 0.0)) * linePosStart.w, linePosStart.w);" + "}}", "void main() {" + - "iris_vertex_offset = iris_Normal;" + + "irisInt_vertex_offset = irisInt_Normal;" + "irisMain();" + "vec4 linePosEnd = gl_Position;" + "gl_Position = vec4(0.0);" + - "iris_vertex_offset = vec3(0.0);" + + "irisInt_vertex_offset = vec3(0.0);" + "irisMain();" + "vec4 linePosStart = gl_Position;" + - "iris_widen_lines(linePosStart, linePosEnd);}"); + "irisInt_widen_lines(linePosStart, linePosEnd);}"); } else { - root.replaceReferenceExpressions(t, "gl_Vertex", "vec4(iris_Position, 1.0)"); + root.replaceReferenceExpressions(t, "gl_Vertex", "vec4(irisInt_Position, 1.0)"); } } @@ -190,11 +195,11 @@ public static void transform( if (parameters.hasChunkOffset) { boolean doInjection = root.replaceReferenceExpressionsReport(t, "gl_ModelViewMatrix", - "(iris_ModelViewMat * _iris_internal_translate(iris_ChunkOffset))"); + "(irisInt_ModelViewMat * _irisInt_internal_translate(irisInt_ChunkOffset))"); if (doInjection) { tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_FUNCTIONS, - "uniform vec3 iris_ChunkOffset;", - "mat4 _iris_internal_translate(vec3 offset) {" + + "uniform vec3 irisInt_ChunkOffset;", + "mat4 _irisInt_internal_translate(vec3 offset) {" + "return mat4(1.0, 0.0, 0.0, 0.0," + "0.0, 1.0, 0.0, 0.0," + "0.0, 0.0, 1.0, 0.0," + @@ -202,20 +207,20 @@ public static void transform( } } else if (parameters.inputs.isNewLines()) { tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_DECLARATIONS, - "const float iris_VIEW_SHRINK = 1.0 - (1.0 / 256.0);", - "const mat4 iris_VIEW_SCALE = mat4(" + - "iris_VIEW_SHRINK, 0.0, 0.0, 0.0," + - "0.0, iris_VIEW_SHRINK, 0.0, 0.0," + - "0.0, 0.0, iris_VIEW_SHRINK, 0.0," + + "const float irisInt_VIEW_SHRINK = 1.0 - (1.0 / 256.0);", + "const mat4 irisInt_VIEW_SCALE = mat4(" + + "irisInt_VIEW_SHRINK, 0.0, 0.0, 0.0," + + "0.0, irisInt_VIEW_SHRINK, 0.0, 0.0," + + "0.0, 0.0, irisInt_VIEW_SHRINK, 0.0," + "0.0, 0.0, 0.0, 1.0);"); root.replaceReferenceExpressions(t, "gl_ModelViewMatrix", - "(iris_VIEW_SCALE * iris_ModelViewMat)"); + "(irisInt_VIEW_SCALE * irisInt_ModelViewMat)"); } else { - root.rename("gl_ModelViewMatrix", "iris_ModelViewMat"); + root.rename("gl_ModelViewMatrix", "irisInt_ModelViewMat"); } - root.rename("gl_ProjectionMatrix", "iris_ProjMat"); + root.rename("gl_ProjectionMatrix", "irisInt_ProjMat"); tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, - "uniform mat4 iris_ProjMat;"); + "uniform mat4 irisInt_ProjMat;"); } } diff --git a/common/src/main/java/net/irisshaders/iris/samplers/IrisSamplers.java b/common/src/main/java/net/irisshaders/iris/samplers/IrisSamplers.java index cb6cb8f592..643dc4bf39 100644 --- a/common/src/main/java/net/irisshaders/iris/samplers/IrisSamplers.java +++ b/common/src/main/java/net/irisshaders/iris/samplers/IrisSamplers.java @@ -193,9 +193,9 @@ public static void addLevelSamplers(SamplerHolder samplers, WorldRenderingPipeli } if (hasOverlay) { - samplers.addExternalSampler(OVERLAY_TEXTURE_UNIT, "iris_overlay"); + samplers.addExternalSampler(OVERLAY_TEXTURE_UNIT, "irisInt_overlay"); } else { - samplers.addDynamicSampler(whitePixel::getId, "iris_overlay"); + samplers.addDynamicSampler(whitePixel::getId, "irisInt_overlay"); } samplers.addDynamicSampler(pipeline::getCurrentNormalTexture, StateUpdateNotifiers.normalTextureChangeNotifier, "normals"); diff --git a/common/src/main/java/net/irisshaders/iris/shaderpack/materialmap/WorldRenderingSettings.java b/common/src/main/java/net/irisshaders/iris/shaderpack/materialmap/WorldRenderingSettings.java index 80b05f375c..2e79e6675c 100644 --- a/common/src/main/java/net/irisshaders/iris/shaderpack/materialmap/WorldRenderingSettings.java +++ b/common/src/main/java/net/irisshaders/iris/shaderpack/materialmap/WorldRenderingSettings.java @@ -25,6 +25,7 @@ public class WorldRenderingSettings { private boolean separateEntityDraws; private boolean voxelizeLightBlocks; private ChunkVertexType chunkVertexFormat; + private boolean shouldPutInAlpha; public WorldRenderingSettings() { reloadRequired = false; @@ -171,4 +172,18 @@ public void setSeparateEntityDraws(boolean separateEntityDraws) { public boolean hasVillagerConversionId() { return hasVillagerConversionId; } + + public boolean shouldPutInAlpha() { + return shouldPutInAlpha; + } + + public void setPutInAlpha(boolean shouldPutInAlpha) { + if (useSeparateAo && this.shouldPutInAlpha == shouldPutInAlpha) { + return; + } + + this.reloadRequired = true; + + this.shouldPutInAlpha = shouldPutInAlpha; + } } diff --git a/common/src/main/java/net/irisshaders/iris/uniforms/ExternallyManagedUniforms.java b/common/src/main/java/net/irisshaders/iris/uniforms/ExternallyManagedUniforms.java index 9a2becc4db..8974011e3c 100644 --- a/common/src/main/java/net/irisshaders/iris/uniforms/ExternallyManagedUniforms.java +++ b/common/src/main/java/net/irisshaders/iris/uniforms/ExternallyManagedUniforms.java @@ -9,9 +9,9 @@ private ExternallyManagedUniforms() { } public static void addExternallyManagedUniforms(UniformHolder uniformHolder) { - addMat4(uniformHolder, "iris_ModelViewMatrix"); + addMat4(uniformHolder, "irisInt_ModelViewMatrix"); addMat4(uniformHolder, "u_ModelViewProjectionMatrix"); - addMat3(uniformHolder, "iris_NormalMatrix"); + addMat3(uniformHolder, "irisInt_NormalMatrix"); // Exclusive to pre-1.19 addFloat(uniformHolder, "darknessFactor"); addFloat(uniformHolder, "darknessLightFactor"); @@ -28,32 +28,32 @@ public static void addExternallyManagedUniforms117(UniformHolder uniformHolder) addExternallyManagedUniforms(uniformHolder); // Sodium - addFloat(uniformHolder, "iris_FogStart"); - addFloat(uniformHolder, "iris_FogEnd"); - addVec4(uniformHolder, "iris_FogColor"); - addMat4(uniformHolder, "iris_ProjectionMatrix"); - addMat4(uniformHolder, "iris_ModelViewMatrix"); - addMat3(uniformHolder, "iris_NormalMatrix"); - addFloat(uniformHolder, "iris_TextureScale"); - addFloat(uniformHolder, "iris_GlintAlpha"); - addFloat(uniformHolder, "iris_ModelScale"); - addFloat(uniformHolder, "iris_ModelOffset"); - addVec3(uniformHolder, "iris_CameraTranslation"); + addFloat(uniformHolder, "irisInt_FogStart"); + addFloat(uniformHolder, "irisInt_FogEnd"); + addVec4(uniformHolder, "irisInt_FogColor"); + addMat4(uniformHolder, "irisInt_ProjectionMatrix"); + addMat4(uniformHolder, "irisInt_ModelViewMatrix"); + addMat3(uniformHolder, "irisInt_NormalMatrix"); + addFloat(uniformHolder, "irisInt_TextureScale"); + addFloat(uniformHolder, "irisInt_GlintAlpha"); + addFloat(uniformHolder, "irisInt_ModelScale"); + addFloat(uniformHolder, "irisInt_ModelOffset"); + addVec3(uniformHolder, "irisInt_CameraTranslation"); addVec3(uniformHolder, "u_RegionOffset"); // Vanilla - uniformHolder.externallyManagedUniform("iris_TextureMat", UniformType.MAT4); - uniformHolder.externallyManagedUniform("iris_ModelViewMat", UniformType.MAT4); - uniformHolder.externallyManagedUniform("iris_ProjMat", UniformType.MAT4); - uniformHolder.externallyManagedUniform("iris_ChunkOffset", UniformType.VEC3); - uniformHolder.externallyManagedUniform("iris_ColorModulator", UniformType.VEC4); - uniformHolder.externallyManagedUniform("iris_NormalMat", UniformType.MAT3); - uniformHolder.externallyManagedUniform("iris_FogStart", UniformType.FLOAT); - uniformHolder.externallyManagedUniform("iris_FogEnd", UniformType.FLOAT); - uniformHolder.externallyManagedUniform("iris_FogDensity", UniformType.FLOAT); - uniformHolder.externallyManagedUniform("iris_LineWidth", UniformType.FLOAT); - uniformHolder.externallyManagedUniform("iris_ScreenSize", UniformType.VEC2); - uniformHolder.externallyManagedUniform("iris_FogColor", UniformType.VEC4); + uniformHolder.externallyManagedUniform("irisInt_TextureMat", UniformType.MAT4); + uniformHolder.externallyManagedUniform("irisInt_ModelViewMat", UniformType.MAT4); + uniformHolder.externallyManagedUniform("irisInt_ProjMat", UniformType.MAT4); + uniformHolder.externallyManagedUniform("irisInt_ChunkOffset", UniformType.VEC3); + uniformHolder.externallyManagedUniform("irisInt_ColorModulator", UniformType.VEC4); + uniformHolder.externallyManagedUniform("irisInt_NormalMat", UniformType.MAT3); + uniformHolder.externallyManagedUniform("irisInt_FogStart", UniformType.FLOAT); + uniformHolder.externallyManagedUniform("irisInt_FogEnd", UniformType.FLOAT); + uniformHolder.externallyManagedUniform("irisInt_FogDensity", UniformType.FLOAT); + uniformHolder.externallyManagedUniform("irisInt_LineWidth", UniformType.FLOAT); + uniformHolder.externallyManagedUniform("irisInt_ScreenSize", UniformType.VEC2); + uniformHolder.externallyManagedUniform("irisInt_FogColor", UniformType.VEC4); } private static void addMat3(UniformHolder uniformHolder, String name) { diff --git a/common/src/main/java/net/irisshaders/iris/uniforms/IrisInternalUniforms.java b/common/src/main/java/net/irisshaders/iris/uniforms/IrisInternalUniforms.java index 4d008eead5..adf7130066 100644 --- a/common/src/main/java/net/irisshaders/iris/uniforms/IrisInternalUniforms.java +++ b/common/src/main/java/net/irisshaders/iris/uniforms/IrisInternalUniforms.java @@ -17,21 +17,21 @@ private IrisInternalUniforms() { public static void addFogUniforms(DynamicUniformHolder uniforms, FogMode fogMode) { uniforms - .uniform4f(PER_FRAME, "iris_FogColor", () -> { + .uniform4f(PER_FRAME, "irisInt_FogColor", () -> { float[] fogColor = RenderSystem.getShaderFogColor(); return new Vector4f(fogColor[0], fogColor[1], fogColor[2], fogColor[3]); }); - uniforms.uniform1f(PER_FRAME, "iris_FogStart", RenderSystem::getShaderFogStart) - .uniform1f(PER_FRAME, "iris_FogEnd", RenderSystem::getShaderFogEnd); + uniforms.uniform1f(PER_FRAME, "irisInt_FogStart", RenderSystem::getShaderFogStart) + .uniform1f(PER_FRAME, "irisInt_FogEnd", RenderSystem::getShaderFogEnd); - uniforms.uniform1f("iris_FogDensity", () -> { + uniforms.uniform1f("irisInt_FogDensity", () -> { // ensure that the minimum value is 0.0 return Math.max(0.0F, CapturedRenderingState.INSTANCE.getFogDensity()); }, notifier -> { }); - uniforms.uniform1f("iris_currentAlphaTest", CapturedRenderingState.INSTANCE::getCurrentAlphaTest, notifier -> { + uniforms.uniform1f("irisInt_currentAlphaTest", CapturedRenderingState.INSTANCE::getCurrentAlphaTest, notifier -> { }); // Optifine compatibility diff --git a/common/src/main/java/net/irisshaders/iris/uniforms/VanillaUniforms.java b/common/src/main/java/net/irisshaders/iris/uniforms/VanillaUniforms.java index c03a7777ec..9a7fdf463d 100644 --- a/common/src/main/java/net/irisshaders/iris/uniforms/VanillaUniforms.java +++ b/common/src/main/java/net/irisshaders/iris/uniforms/VanillaUniforms.java @@ -9,9 +9,9 @@ public class VanillaUniforms { public static void addVanillaUniforms(DynamicUniformHolder uniforms) { Vector2f cachedScreenSize = new Vector2f(); // listener -> {} dictates we want this to run on every shader update, not just on a new frame. These are dynamic. - uniforms.uniform1f("iris_LineWidth", RenderSystem::getShaderLineWidth, listener -> { + uniforms.uniform1f("irisInt_LineWidth", RenderSystem::getShaderLineWidth, listener -> { }); - uniforms.uniform2f("iris_ScreenSize", () -> cachedScreenSize.set(GlStateManager.Viewport.width(), GlStateManager.Viewport.height()), listener -> { + uniforms.uniform2f("irisInt_ScreenSize", () -> cachedScreenSize.set(GlStateManager.Viewport.width(), GlStateManager.Viewport.height()), listener -> { }); } } diff --git a/common/src/main/java/net/irisshaders/iris/uniforms/builtin/BuiltinReplacementUniforms.java b/common/src/main/java/net/irisshaders/iris/uniforms/builtin/BuiltinReplacementUniforms.java index 1bca1a7b14..c8c639f1bd 100644 --- a/common/src/main/java/net/irisshaders/iris/uniforms/builtin/BuiltinReplacementUniforms.java +++ b/common/src/main/java/net/irisshaders/iris/uniforms/builtin/BuiltinReplacementUniforms.java @@ -13,7 +13,7 @@ public class BuiltinReplacementUniforms { } public static void addBuiltinReplacementUniforms(UniformHolder uniforms) { - uniforms.uniformMatrix(UniformUpdateFrequency.ONCE, "iris_LightmapTextureMatrix", () -> { + uniforms.uniformMatrix(UniformUpdateFrequency.ONCE, "irisInt_LightmapTextureMatrix", () -> { //Iris.logger.warn("A shader appears to require the lightmap texture matrix even after transformations have occurred"); //Iris.logger.warn("Iris handles this correctly but it indicates that the shader is doing weird things with lightmap coordinates"); diff --git a/common/src/main/java/net/irisshaders/iris/vertices/sodium/terrain/VertexEncoderInterface.java b/common/src/main/java/net/irisshaders/iris/vertices/sodium/terrain/VertexEncoderInterface.java index 4e4d1ecfbd..f07fa0e00e 100644 --- a/common/src/main/java/net/irisshaders/iris/vertices/sodium/terrain/VertexEncoderInterface.java +++ b/common/src/main/java/net/irisshaders/iris/vertices/sodium/terrain/VertexEncoderInterface.java @@ -2,4 +2,6 @@ public interface VertexEncoderInterface { void iris$setContextHolder(BlockContextHolder contextHolder); + + void iris$setShade(boolean shade); } diff --git a/common/src/main/java/net/irisshaders/iris/vertices/sodium/terrain/XHFPTerrainVertex.java b/common/src/main/java/net/irisshaders/iris/vertices/sodium/terrain/XHFPTerrainVertex.java index ad9ed21afd..ea098d5c3a 100644 --- a/common/src/main/java/net/irisshaders/iris/vertices/sodium/terrain/XHFPTerrainVertex.java +++ b/common/src/main/java/net/irisshaders/iris/vertices/sodium/terrain/XHFPTerrainVertex.java @@ -1,6 +1,7 @@ package net.irisshaders.iris.vertices.sodium.terrain; import net.caffeinemc.mods.sodium.api.util.ColorABGR; +import net.caffeinemc.mods.sodium.api.util.ColorU8; import net.caffeinemc.mods.sodium.client.render.chunk.vertex.format.ChunkVertexEncoder; import net.caffeinemc.mods.sodium.client.render.frapi.helper.ColorHelper; import net.irisshaders.iris.shaderpack.materialmap.WorldRenderingSettings; @@ -37,6 +38,7 @@ public class XHFPTerrainVertex implements ChunkVertexEncoder, VertexEncoderInter private final Vector2f normEncoded = new Vector2f(); private final Vector2f tangEncoded = new Vector2f(); private BlockContextHolder contextHolder; + private boolean shade; public XHFPTerrainVertex(int blockIdOffset, int normalOffset, int midUvOffset, int midBlockOffset, int stride) { this.blockIdOffset = blockIdOffset; @@ -104,6 +106,11 @@ private static int floorInt(float x) { this.contextHolder = holder; } + @Override + public void iris$setShade(boolean shade) { + this.shade = shade; + } + @Override public long write(long ptr, int material, Vertex[] vertices, int section) { @@ -150,12 +157,14 @@ public long write(long ptr, MemoryUtil.memPutInt(ptr, packPositionHi(x, y, z)); MemoryUtil.memPutInt(ptr + 4L, packPositionLo(x, y, z)); - MemoryUtil.memPutInt(ptr + 8L, WorldRenderingSettings.INSTANCE.shouldUseSeparateAo() ? ColorABGR.withAlpha(vertex.color, vertex.ao) : ColorHelper.multiplyRGB(vertex.color, vertex.ao)); + MemoryUtil.memPutInt(ptr + 8L, WorldRenderingSettings.INSTANCE.shouldUseSeparateAo() ? + (WorldRenderingSettings.INSTANCE.shouldPutInAlpha() ? ColorABGR.withAlpha(vertex.color, vertex.ao) : vertex.color) + : ColorHelper.multiplyRGB(vertex.color, vertex.ao)); MemoryUtil.memPutInt(ptr + 12L, packTexture(u, v)); MemoryUtil.memPutInt(ptr + 16L, packLightAndData(light, material, section)); if (blockIdOffset != 0) { - MemoryUtil.memPutInt(ptr + blockIdOffset, packBlockId(contextHolder)); + MemoryUtil.memPutInt(ptr + blockIdOffset, packBlockId(contextHolder, (byte) ColorU8.normalizedFloatToByte(vertex.ao))); } if (midBlockOffset != 0) { @@ -194,7 +203,10 @@ private int computeTangentForQuad(Vector3f normal, Vertex[] vertices) { return tangent; } - private int packBlockId(BlockContextHolder contextHolder) { - return ((contextHolder.getBlockId() + 1) << 1) | (contextHolder.getRenderType() & 1); + private int packBlockId(BlockContextHolder contextHolder, byte ambientOcclusion) { + return (((contextHolder.getBlockId() + 1) & 0x3FFFFF) << 10) // 22 bits for Block ID + | ((contextHolder.getRenderType() & 1) << 9) // fluid or block + | ((ambientOcclusion & 0xFF) << 1) // 8 bits for AO + | ((shade ? 1 : 0) & 1); } } diff --git a/common/src/main/resources/centerDepth.vsh b/common/src/main/resources/centerDepth.vsh index d8939081b8..aae7b68972 100644 --- a/common/src/main/resources/centerDepth.vsh +++ b/common/src/main/resources/centerDepth.vsh @@ -1,8 +1,8 @@ #version 150 core -in vec3 iris_Position; +in vec3 irisInt_Position; uniform mat4 projection; void main() { - gl_Position = projection * vec4(iris_Position, 1.0); + gl_Position = projection * vec4(irisInt_Position, 1.0); } diff --git a/common/src/main/resources/colorSpace.vsh b/common/src/main/resources/colorSpace.vsh index ecb0e84688..a7497282f6 100644 --- a/common/src/main/resources/colorSpace.vsh +++ b/common/src/main/resources/colorSpace.vsh @@ -1,11 +1,11 @@ #version 330 core -in vec3 iris_Position; -in vec2 iris_UV0; +in vec3 irisInt_Position; +in vec2 irisInt_UV0; uniform mat4 projection; out vec2 uv; void main() { - gl_Position = projection * vec4(iris_Position, 1.0); - uv = iris_UV0; + gl_Position = projection * vec4(irisInt_Position, 1.0); + uv = irisInt_UV0; }