diff --git a/build.gradle.kts b/build.gradle.kts index c012c0fbae..c88694fe94 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ val MINECRAFT_VERSION by extra { "1.21.1" } val NEOFORGE_VERSION by extra { "21.1.19" } val FABRIC_LOADER_VERSION by extra { "0.16.0" } val FABRIC_API_VERSION by extra { "0.102.0+1.21.1" } -val SODIUM_FILE by extra { "sodium-LOADER-0.6.0-beta.1+mc1.21.jar" } +val SODIUM_FILE by extra { "sodium-LOADER-0.6.0-snapshot+mc1.21-local.jar" } // https://semver.org/ val MOD_VERSION by extra { "1.8.0-beta.2" } diff --git a/common/src/main/java/net/irisshaders/iris/Iris.java b/common/src/main/java/net/irisshaders/iris/Iris.java index 8d0c811a56..b8e0a0e0bc 100644 --- a/common/src/main/java/net/irisshaders/iris/Iris.java +++ b/common/src/main/java/net/irisshaders/iris/Iris.java @@ -117,10 +117,10 @@ public static void onRenderSystemInit() { PBRTextureManager.INSTANCE.init(); - VertexSerializerRegistry.instance().registerSerializer(VertexFormatRegistry.instance().get(DefaultVertexFormat.NEW_ENTITY), VertexFormatRegistry.instance().get(IrisVertexFormats.TERRAIN), new EntityToTerrainVertexSerializer()); - VertexSerializerRegistry.instance().registerSerializer(VertexFormatRegistry.instance().get(IrisVertexFormats.ENTITY), VertexFormatRegistry.instance().get(IrisVertexFormats.TERRAIN), new IrisEntityToTerrainVertexSerializer()); - VertexSerializerRegistry.instance().registerSerializer(VertexFormatRegistry.instance().get(DefaultVertexFormat.POSITION_COLOR_TEX_LIGHTMAP), VertexFormatRegistry.instance().get(IrisVertexFormats.GLYPH), new GlyphExtVertexSerializer()); - VertexSerializerRegistry.instance().registerSerializer(VertexFormatRegistry.instance().get(DefaultVertexFormat.NEW_ENTITY), VertexFormatRegistry.instance().get(IrisVertexFormats.ENTITY), new ModelToEntityVertexSerializer()); + VertexSerializerRegistry.instance().registerSerializer(DefaultVertexFormat.NEW_ENTITY, IrisVertexFormats.TERRAIN, new EntityToTerrainVertexSerializer()); + VertexSerializerRegistry.instance().registerSerializer(IrisVertexFormats.ENTITY, IrisVertexFormats.TERRAIN, new IrisEntityToTerrainVertexSerializer()); + VertexSerializerRegistry.instance().registerSerializer(DefaultVertexFormat.POSITION_COLOR_TEX_LIGHTMAP, IrisVertexFormats.GLYPH, new GlyphExtVertexSerializer()); + VertexSerializerRegistry.instance().registerSerializer(DefaultVertexFormat.NEW_ENTITY, IrisVertexFormats.ENTITY, new ModelToEntityVertexSerializer()); // Only load the shader pack when we can access OpenGL loadShaderpack(); @@ -713,7 +713,11 @@ public static boolean loadedIncompatiblePack() { return DHCompat.lastPackIncompatible(); } - /** + public static boolean isPackInUseQuick() { + return getPipelineManager().getPipelineNullable() instanceof IrisRenderingPipeline; + } + + /** * Called very early on in Minecraft initialization. At this point we *cannot* safely access OpenGL, but we can do * some very basic setup, config loading, and environment checks. * diff --git a/common/src/main/java/net/irisshaders/iris/compat/dh/DHCompatInternal.java b/common/src/main/java/net/irisshaders/iris/compat/dh/DHCompatInternal.java index 6f304135e9..0481e99e44 100644 --- a/common/src/main/java/net/irisshaders/iris/compat/dh/DHCompatInternal.java +++ b/common/src/main/java/net/irisshaders/iris/compat/dh/DHCompatInternal.java @@ -141,7 +141,7 @@ public static boolean checkFrame() { if (DhApi.Delayed.configs == null) return dhEnabled; if ((dhEnabled != DhApi.Delayed.configs.graphics().renderingEnabled().getValue() || guiScale != Minecraft.getInstance().options.guiScale().get()) - && IrisApi.getInstance().isShaderPackInUse()) { + && Iris.isPackInUseQuick()) { guiScale = Minecraft.getInstance().options.guiScale().get(); dhEnabled = DhApi.Delayed.configs.graphics().renderingEnabled().getValue(); try { 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 7a4ce859b1..13a5daa21a 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 @@ -12,6 +12,7 @@ import com.seibel.distanthorizons.api.objects.math.DhApiVec3i; import com.seibel.distanthorizons.api.objects.render.DhApiRenderableBox; import com.seibel.distanthorizons.api.objects.render.DhApiRenderableBoxGroupShading; +import net.irisshaders.iris.Iris; import net.irisshaders.iris.api.v0.IrisApi; import net.irisshaders.iris.gl.IrisRenderSystem; import net.irisshaders.iris.gl.blending.BlendModeOverride; @@ -269,7 +270,7 @@ public void bindVertexBuffer(int i) { @Override public boolean overrideThisFrame() { - return IrisApi.getInstance().isShaderPackInUse(); + return Iris.isPackInUseQuick(); } @Override diff --git a/common/src/main/java/net/irisshaders/iris/compat/dh/LodRendererEvents.java b/common/src/main/java/net/irisshaders/iris/compat/dh/LodRendererEvents.java index 3d5e8ece6f..9cdec9f665 100644 --- a/common/src/main/java/net/irisshaders/iris/compat/dh/LodRendererEvents.java +++ b/common/src/main/java/net/irisshaders/iris/compat/dh/LodRendererEvents.java @@ -85,7 +85,7 @@ private static void setupSetDeferredBeforeRenderingEvent() { @Override public void beforeRender(DhApiCancelableEventParam event) { - DhApi.Delayed.renderProxy.setDeferTransparentRendering(IrisApi.getInstance().isShaderPackInUse() && getInstance().shouldOverride); + DhApi.Delayed.renderProxy.setDeferTransparentRendering(Iris.isPackInUseQuick() && getInstance().shouldOverride); DhApi.Delayed.configs.graphics().fog().drawMode().setValue(getInstance().shouldOverride ? EDhApiFogDrawMode.FOG_DISABLED : EDhApiFogDrawMode.FOG_ENABLED); } }; @@ -365,7 +365,7 @@ private static void setupBeforeApplyShaderEvent() { DhApiBeforeApplyShaderRenderEvent beforeApplyShaderEvent = new DhApiBeforeApplyShaderRenderEvent() { @Override public void beforeRender(DhApiCancelableEventParam event) { - if (IrisApi.getInstance().isShaderPackInUse()) { + if (Iris.isPackInUseQuick()) { DHCompatInternal instance = getInstance(); OverrideInjector.INSTANCE.unbind(IDhApiShadowCullingFrustum.class, (IDhApiOverrideable) ShadowRenderer.FRUSTUM); 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 new file mode 100644 index 0000000000..4909ff8fdb --- /dev/null +++ b/common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/MixinBlockRenderer.java @@ -0,0 +1,42 @@ +package net.irisshaders.iris.compat.sodium.mixin; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +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.frapi.mesh.MutableQuadViewImpl; +import net.irisshaders.iris.shaderpack.materialmap.WorldRenderingSettings; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.state.BlockState; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(BlockRenderer.class) +public class MixinBlockRenderer { + @Unique + private boolean hasOverride; + + @Inject(method = "renderModel", at = @At("HEAD")) + private void iris$renderModelHead(BakedModel model, BlockState state, BlockPos pos, BlockPos origin, CallbackInfo ci) { + if (WorldRenderingSettings.INSTANCE.getBlockTypeIds().containsKey(state.getBlock())) { + hasOverride = true; + } + } + + @Inject(method = "renderModel", at = @At("TAIL")) + private void iris$renderModelTail(BakedModel model, BlockState state, BlockPos pos, BlockPos origin, CallbackInfo ci) { + hasOverride = false; + } + + @WrapOperation(method = "bufferQuad", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/client/render/chunk/compile/pipeline/BlockRenderer;attemptPassDowngrade(Lnet/caffeinemc/mods/sodium/client/render/frapi/mesh/MutableQuadViewImpl;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, MutableQuadViewImpl mutableQuadView, TextureAtlasSprite quad, TerrainRenderPass sprite, Operation original) { + if (hasOverride) return null; + + return original.call(instance, mutableQuadView, quad, sprite); + } +} diff --git a/common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/MixinCloudRenderer.java b/common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/MixinCloudRenderer.java index 6600c057fa..dfa75f232b 100644 --- a/common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/MixinCloudRenderer.java +++ b/common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/MixinCloudRenderer.java @@ -4,7 +4,6 @@ import com.mojang.blaze3d.vertex.VertexFormat; import net.caffeinemc.mods.sodium.api.util.NormI8; import net.caffeinemc.mods.sodium.api.vertex.buffer.VertexBufferWriter; -import net.caffeinemc.mods.sodium.api.vertex.format.VertexFormatDescription; import net.caffeinemc.mods.sodium.api.vertex.format.common.ColorVertex; import net.caffeinemc.mods.sodium.client.render.immediate.CloudRenderer; import net.irisshaders.iris.Iris; @@ -53,7 +52,7 @@ public abstract class MixinCloudRenderer { @Inject(method = "writeVertex", at = @At("HEAD"), cancellable = true, remap = false) private static void writeIrisVertex(long buffer, float x, float y, float z, int color, CallbackInfoReturnable cir) { - if (IrisApi.getInstance().isShaderPackInUse()) { + if (Iris.isPackInUseQuick()) { CloudVertex.put(buffer, x, y, z, color, computedNormal); cir.setReturnValue(buffer + 20L); } @@ -71,18 +70,18 @@ private static void computeNormal3D(VertexBufferWriter writer, int visibleFaces, @ModifyArg(remap = false, method = "emitCellGeometry3D", at = @At(value = "INVOKE", target = "Lorg/lwjgl/system/MemoryStack;nmalloc(I)J")) private static int allocateNewSize(int size) { - return IrisApi.getInstance().isShaderPackInUse() ? 480 : size; + return Iris.isPackInUseQuick() ? 480 : size; } @ModifyArg(method = "rebuildGeometry", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/Tesselator;begin(Lcom/mojang/blaze3d/vertex/VertexFormat$Mode;Lcom/mojang/blaze3d/vertex/VertexFormat;)Lcom/mojang/blaze3d/vertex/BufferBuilder;"), index = 1) private static VertexFormat rebuild(VertexFormat p_350837_) { - return IrisApi.getInstance().isShaderPackInUse() ? IrisVertexFormats.CLOUDS : p_350837_; + return Iris.isPackInUseQuick() ? IrisVertexFormats.CLOUDS : p_350837_; } - @ModifyArg(remap = false, method = "emitCellGeometry3D", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/api/vertex/buffer/VertexBufferWriter;push(Lorg/lwjgl/system/MemoryStack;JILnet/caffeinemc/mods/sodium/api/vertex/format/VertexFormatDescription;)V"), index = 3) - private static VertexFormatDescription modifyArgIris(VertexFormatDescription vertexFormatDescription) { - if (IrisApi.getInstance().isShaderPackInUse()) { - return CloudVertex.FORMAT; + @ModifyArg(remap = false, method = "emitCellGeometry3D", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/api/vertex/buffer/VertexBufferWriter;push(Lorg/lwjgl/system/MemoryStack;JILcom/mojang/blaze3d/vertex/VertexFormat;)V"), index = 3) + private static VertexFormat modifyArgIris(VertexFormat vertexFormatDescription) { + if (Iris.isPackInUseQuick()) { + return IrisVertexFormats.CLOUDS; } else { return ColorVertex.FORMAT; } @@ -90,13 +89,13 @@ private static VertexFormatDescription modifyArgIris(VertexFormatDescription ver @ModifyArg(remap = false, method = "emitCellGeometry2D", at = @At(value = "INVOKE", target = "Lorg/lwjgl/system/MemoryStack;nmalloc(I)J")) private static int allocateNewSize2D(int size) { - return IrisApi.getInstance().isShaderPackInUse() ? 80 : size; + return Iris.isPackInUseQuick() ? 80 : size; } - @ModifyArg(remap = false, method = "emitCellGeometry2D", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/api/vertex/buffer/VertexBufferWriter;push(Lorg/lwjgl/system/MemoryStack;JILnet/caffeinemc/mods/sodium/api/vertex/format/VertexFormatDescription;)V"), index = 3) - private static VertexFormatDescription modifyArgIris2D(VertexFormatDescription vertexFormatDescription) { - if (IrisApi.getInstance().isShaderPackInUse()) { - return CloudVertex.FORMAT; + @ModifyArg(remap = false, method = "emitCellGeometry2D", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/api/vertex/buffer/VertexBufferWriter;push(Lorg/lwjgl/system/MemoryStack;JILcom/mojang/blaze3d/vertex/VertexFormat;)V"), index = 3) + private static VertexFormat modifyArgIris2D(VertexFormat vertexFormatDescription) { + if (Iris.isPackInUseQuick()) { + return IrisVertexFormats.CLOUDS; } else { return ColorVertex.FORMAT; } @@ -104,7 +103,7 @@ private static VertexFormatDescription modifyArgIris2D(VertexFormatDescription v @Redirect(method = "render", at = @At(remap = false, value = "FIELD", target = "Lnet/caffeinemc/mods/sodium/client/render/immediate/CloudRenderer;cachedGeometry:Lnet/caffeinemc/mods/sodium/client/render/immediate/CloudRenderer$CloudGeometry;", ordinal = 0)) private CloudRenderer.@Nullable CloudGeometry changeGeometry(CloudRenderer instance) { - if (IrisApi.getInstance().isShaderPackInUse()) { + if (Iris.isPackInUseQuick()) { return cachedGeometryIris; } else { return cachedGeometry; @@ -113,7 +112,7 @@ private static VertexFormatDescription modifyArgIris2D(VertexFormatDescription v @Redirect(method = "render", at = @At(remap = false, value = "FIELD", target = "Lnet/caffeinemc/mods/sodium/client/render/immediate/CloudRenderer;cachedGeometry:Lnet/caffeinemc/mods/sodium/client/render/immediate/CloudRenderer$CloudGeometry;", ordinal = 1)) private void changeGeometry2(CloudRenderer instance, CloudRenderer.CloudGeometry value) { - if (IrisApi.getInstance().isShaderPackInUse()) { + if (Iris.isPackInUseQuick()) { cachedGeometryIris = value; } else { cachedGeometry = value; diff --git a/common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/MixinRenderRegionArenas.java b/common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/MixinRenderRegionArenas.java index 1326d92fbb..2b105b80d7 100644 --- a/common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/MixinRenderRegionArenas.java +++ b/common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/MixinRenderRegionArenas.java @@ -16,6 +16,6 @@ public class MixinRenderRegionArenas { target = "Lnet/caffeinemc/mods/sodium/client/render/chunk/vertex/format/ChunkMeshFormats;COMPACT:Lnet/caffeinemc/mods/sodium/client/render/chunk/vertex/format/ChunkVertexType;", remap = false)) private ChunkVertexType iris$useExtendedStride() { - return WorldRenderingSettings.INSTANCE.shouldUseExtendedVertexFormat() ? IrisModelVertexFormats.MODEL_VERTEX_XHFP : ChunkMeshFormats.COMPACT; + return WorldRenderingSettings.INSTANCE.getVertexFormat(); } } diff --git a/common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/MixinRenderSectionManager.java b/common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/MixinRenderSectionManager.java index fcae907507..0fb85ecbbd 100644 --- a/common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/MixinRenderSectionManager.java +++ b/common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/MixinRenderSectionManager.java @@ -17,14 +17,14 @@ public class MixinRenderSectionManager { at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/client/render/chunk/DefaultChunkRenderer;(Lnet/caffeinemc/mods/sodium/client/gl/device/RenderDevice;Lnet/caffeinemc/mods/sodium/client/render/chunk/vertex/format/ChunkVertexType;)V")) private ChunkVertexType iris$useExtendedVertexFormat$1(ChunkVertexType vertexType) { - return WorldRenderingSettings.INSTANCE.shouldUseExtendedVertexFormat() ? IrisModelVertexFormats.MODEL_VERTEX_XHFP : vertexType; + return WorldRenderingSettings.INSTANCE.getVertexFormat(); } @ModifyArg(method = "", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/client/render/chunk/compile/executor/ChunkBuilder;(Lnet/minecraft/client/multiplayer/ClientLevel;Lnet/caffeinemc/mods/sodium/client/render/chunk/vertex/format/ChunkVertexType;)V")) private ChunkVertexType iris$useExtendedVertexFormat$2(ChunkVertexType vertexType) { - return WorldRenderingSettings.INSTANCE.shouldUseExtendedVertexFormat() ? IrisModelVertexFormats.MODEL_VERTEX_XHFP : vertexType; + return WorldRenderingSettings.INSTANCE.getVertexFormat(); } @Redirect(method = "getSearchDistance", remap = false, diff --git a/common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/entity/CommonVertexAttributeInterface.java b/common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/entity/CommonVertexAttributeInterface.java deleted file mode 100644 index 3c613f0421..0000000000 --- a/common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/entity/CommonVertexAttributeInterface.java +++ /dev/null @@ -1,14 +0,0 @@ -package net.irisshaders.iris.compat.sodium.mixin.entity; - -import com.mojang.blaze3d.vertex.VertexFormatElement; -import net.caffeinemc.mods.sodium.api.vertex.attributes.CommonVertexAttribute; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Invoker; - -@Mixin(CommonVertexAttribute.class) -public interface CommonVertexAttributeInterface { - @Invoker(value = "") - static CommonVertexAttribute createAttribute(String name, int ordinal, VertexFormatElement element) { - throw new AssertionError(); - } -} diff --git a/common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/entity/MixinCommonVertexAttribute.java b/common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/entity/MixinCommonVertexAttribute.java deleted file mode 100644 index c5347fb0d9..0000000000 --- a/common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/entity/MixinCommonVertexAttribute.java +++ /dev/null @@ -1,48 +0,0 @@ -package net.irisshaders.iris.compat.sodium.mixin.entity; - -import net.caffeinemc.mods.sodium.api.vertex.attributes.CommonVertexAttribute; -import net.irisshaders.iris.vertices.IrisVertexFormats; -import net.irisshaders.iris.vertices.sodium.IrisCommonVertexAttributes; -import org.apache.commons.lang3.ArrayUtils; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Mutable; -import org.spongepowered.asm.mixin.Shadow; - -@Mixin(CommonVertexAttribute.class) -public class MixinCommonVertexAttribute { - @Mutable - @Shadow(remap = false) - @Final - public static int COUNT; - - @SuppressWarnings("target") - @Shadow(remap = false) - @Final - @Mutable - private static CommonVertexAttribute[] $VALUES; - - static { - int baseOrdinal = $VALUES.length; - - IrisCommonVertexAttributes.TANGENT - = CommonVertexAttributeInterface.createAttribute("TANGENT", baseOrdinal, IrisVertexFormats.TANGENT_ELEMENT); - IrisCommonVertexAttributes.MID_TEX_COORD - = CommonVertexAttributeInterface.createAttribute("MID_TEX_COORD", baseOrdinal + 1, IrisVertexFormats.MID_TEXTURE_ELEMENT); - IrisCommonVertexAttributes.BLOCK_ID - = CommonVertexAttributeInterface.createAttribute("BLOCK_ID", baseOrdinal + 2, IrisVertexFormats.ENTITY_ELEMENT); - IrisCommonVertexAttributes.ENTITY_ID - = CommonVertexAttributeInterface.createAttribute("ENTITY_ID", baseOrdinal + 3, IrisVertexFormats.ENTITY_ID_ELEMENT); - IrisCommonVertexAttributes.MID_BLOCK - = CommonVertexAttributeInterface.createAttribute("MID_BLOCK", baseOrdinal + 4, IrisVertexFormats.MID_BLOCK_ELEMENT); - - $VALUES = ArrayUtils.addAll($VALUES, - IrisCommonVertexAttributes.TANGENT, - IrisCommonVertexAttributes.MID_TEX_COORD, - IrisCommonVertexAttributes.BLOCK_ID, - IrisCommonVertexAttributes.ENTITY_ID, - IrisCommonVertexAttributes.MID_BLOCK); - - COUNT = $VALUES.length; - } -} diff --git a/common/src/main/java/net/irisshaders/iris/mixin/MixinGameRenderer.java b/common/src/main/java/net/irisshaders/iris/mixin/MixinGameRenderer.java index bccacc56b6..dd5286ecbb 100644 --- a/common/src/main/java/net/irisshaders/iris/mixin/MixinGameRenderer.java +++ b/common/src/main/java/net/irisshaders/iris/mixin/MixinGameRenderer.java @@ -469,7 +469,7 @@ private static void override(ShaderKey key, CallbackInfoReturnable cir) { - Map idMap = WorldRenderingSettings.INSTANCE.getBlockTypeIds(); - if (idMap != null) { - BlockRenderType type = idMap.get(arg.getBlock()); - if (type != null) { - cir.setReturnValue(LAYER_SET_VANILLA[type.ordinal()]); - } + BlockRenderType type = WorldRenderingSettings.INSTANCE.getBlockTypeIds().get(arg.getBlock()); + if (type != null) { + cir.setReturnValue(LAYER_SET_VANILLA[type.ordinal()]); } } } diff --git a/common/src/main/java/net/irisshaders/iris/mixin/MixinItemInHandRenderer.java b/common/src/main/java/net/irisshaders/iris/mixin/MixinItemInHandRenderer.java index 2e7c019d71..9ef29ec59f 100644 --- a/common/src/main/java/net/irisshaders/iris/mixin/MixinItemInHandRenderer.java +++ b/common/src/main/java/net/irisshaders/iris/mixin/MixinItemInHandRenderer.java @@ -1,6 +1,7 @@ package net.irisshaders.iris.mixin; import com.mojang.blaze3d.vertex.PoseStack; +import net.irisshaders.iris.Iris; import net.irisshaders.iris.api.v0.IrisApi; import net.irisshaders.iris.pathways.HandRenderer; import net.minecraft.client.player.AbstractClientPlayer; @@ -17,7 +18,7 @@ public class MixinItemInHandRenderer { @Inject(method = "renderArmWithItem", at = @At("HEAD"), cancellable = true) private void iris$skipTranslucentHands(AbstractClientPlayer abstractClientPlayer, float f, float g, InteractionHand interactionHand, float h, ItemStack itemStack, float i, PoseStack poseStack, MultiBufferSource multiBufferSource, int j, CallbackInfo ci) { - if (IrisApi.getInstance().isShaderPackInUse()) { + if (Iris.isPackInUseQuick()) { if (HandRenderer.INSTANCE.isRenderingSolid() && HandRenderer.INSTANCE.isHandTranslucent(interactionHand)) { ci.cancel(); } else if (!HandRenderer.INSTANCE.isRenderingSolid() && !HandRenderer.INSTANCE.isHandTranslucent(interactionHand)) { diff --git a/common/src/main/java/net/irisshaders/iris/mixin/MixinModelViewBobbing.java b/common/src/main/java/net/irisshaders/iris/mixin/MixinModelViewBobbing.java index c411248c4d..6833bd3320 100644 --- a/common/src/main/java/net/irisshaders/iris/mixin/MixinModelViewBobbing.java +++ b/common/src/main/java/net/irisshaders/iris/mixin/MixinModelViewBobbing.java @@ -1,6 +1,7 @@ package net.irisshaders.iris.mixin; import com.mojang.blaze3d.vertex.PoseStack; +import net.irisshaders.iris.Iris; import net.irisshaders.iris.api.v0.IrisApi; import net.minecraft.client.Camera; import net.minecraft.client.DeltaTracker; @@ -54,7 +55,7 @@ public abstract class MixinModelViewBobbing { @Inject(method = "renderLevel", at = @At("HEAD")) private void iris$saveShadersOn(DeltaTracker deltaTracker, CallbackInfo ci) { - areShadersOn = IrisApi.getInstance().isShaderPackInUse(); + areShadersOn = Iris.isPackInUseQuick(); } @ModifyArg(method = "renderLevel", index = 0, diff --git a/common/src/main/java/net/irisshaders/iris/mixin/vertices/MixinBufferBuilder.java b/common/src/main/java/net/irisshaders/iris/mixin/vertices/MixinBufferBuilder.java index bdbd7aa1df..3e6d5a40b4 100644 --- a/common/src/main/java/net/irisshaders/iris/mixin/vertices/MixinBufferBuilder.java +++ b/common/src/main/java/net/irisshaders/iris/mixin/vertices/MixinBufferBuilder.java @@ -6,6 +6,8 @@ import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.blaze3d.vertex.VertexFormat; import com.mojang.blaze3d.vertex.VertexFormatElement; +import net.irisshaders.iris.Iris; +import net.irisshaders.iris.api.v0.IrisApi; import net.irisshaders.iris.shaderpack.materialmap.WorldRenderingSettings; import net.irisshaders.iris.uniforms.CapturedRenderingState; import net.irisshaders.iris.vertices.BlockSensitiveBufferBuilder; @@ -95,7 +97,7 @@ public abstract class MixinBufferBuilder implements VertexConsumer, BlockSensiti boolean iris$isTerrain = false; injectNormalAndUV1 = false; - if (ImmediateState.skipExtension.get() || !WorldRenderingSettings.INSTANCE.shouldUseExtendedVertexFormat()) { + if (ImmediateState.skipExtension.get() || !Iris.isPackInUseQuick()) { return format; } diff --git a/common/src/main/java/net/irisshaders/iris/mixin/vertices/MixinVertexFormat.java b/common/src/main/java/net/irisshaders/iris/mixin/vertices/MixinVertexFormat.java index ce89f333ba..3e1ed1ee81 100644 --- a/common/src/main/java/net/irisshaders/iris/mixin/vertices/MixinVertexFormat.java +++ b/common/src/main/java/net/irisshaders/iris/mixin/vertices/MixinVertexFormat.java @@ -2,6 +2,8 @@ import com.mojang.blaze3d.vertex.DefaultVertexFormat; import com.mojang.blaze3d.vertex.VertexFormat; +import net.irisshaders.iris.Iris; +import net.irisshaders.iris.api.v0.IrisApi; import net.irisshaders.iris.shaderpack.materialmap.WorldRenderingSettings; import net.irisshaders.iris.vertices.ImmediateState; import net.irisshaders.iris.vertices.IrisVertexFormats; @@ -17,7 +19,7 @@ public class MixinVertexFormat { @Inject(method = "setupBufferState", at = @At("HEAD"), cancellable = true) private void iris$onSetupBufferState(CallbackInfo ci) { - if (WorldRenderingSettings.INSTANCE.shouldUseExtendedVertexFormat() && ImmediateState.renderWithExtendedVertexFormat) { + if (Iris.isPackInUseQuick() && ImmediateState.renderWithExtendedVertexFormat) { if ((Object) this == DefaultVertexFormat.BLOCK) { IrisVertexFormats.TERRAIN.setupBufferState(); @@ -36,7 +38,7 @@ public class MixinVertexFormat { @Inject(method = "clearBufferState", at = @At("HEAD"), cancellable = true) private void iris$onClearBufferState(CallbackInfo ci) { - if (WorldRenderingSettings.INSTANCE.shouldUseExtendedVertexFormat() && ImmediateState.renderWithExtendedVertexFormat) { + if (Iris.isPackInUseQuick() && ImmediateState.renderWithExtendedVertexFormat) { if ((Object) this == DefaultVertexFormat.BLOCK) { IrisVertexFormats.TERRAIN.clearBufferState(); diff --git a/common/src/main/java/net/irisshaders/iris/pathways/HandRenderer.java b/common/src/main/java/net/irisshaders/iris/pathways/HandRenderer.java index 4187d726b1..73f0f9c317 100644 --- a/common/src/main/java/net/irisshaders/iris/pathways/HandRenderer.java +++ b/common/src/main/java/net/irisshaders/iris/pathways/HandRenderer.java @@ -3,6 +3,7 @@ import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import net.irisshaders.batchedentityrendering.impl.FullyBufferedMultiBufferSource; +import net.irisshaders.iris.Iris; import net.irisshaders.iris.api.v0.IrisApi; import net.irisshaders.iris.mixin.GameRendererAccessor; import net.irisshaders.iris.pipeline.WorldRenderingPhase; @@ -74,7 +75,7 @@ public boolean isAnyHandTranslucent() { } public void renderSolid(Matrix4fc modelMatrix, float tickDelta, Camera camera, GameRenderer gameRenderer, WorldRenderingPipeline pipeline) { - if (!canRender(camera, gameRenderer) || !IrisApi.getInstance().isShaderPackInUse()) { + if (!canRender(camera, gameRenderer) || !Iris.isPackInUseQuick()) { return; } @@ -115,7 +116,7 @@ public void renderSolid(Matrix4fc modelMatrix, float tickDelta, Camera camera, G } public void renderTranslucent(Matrix4fc modelMatrix, float tickDelta, Camera camera, GameRenderer gameRenderer, WorldRenderingPipeline pipeline) { - if (!canRender(camera, gameRenderer) || !isAnyHandTranslucent() || !IrisApi.getInstance().isShaderPackInUse()) { + if (!canRender(camera, gameRenderer) || !isAnyHandTranslucent() || !Iris.isPackInUseQuick()) { return; } diff --git a/common/src/main/java/net/irisshaders/iris/pipeline/IrisRenderingPipeline.java b/common/src/main/java/net/irisshaders/iris/pipeline/IrisRenderingPipeline.java index 2154a8b439..79f3f235a3 100644 --- a/common/src/main/java/net/irisshaders/iris/pipeline/IrisRenderingPipeline.java +++ b/common/src/main/java/net/irisshaders/iris/pipeline/IrisRenderingPipeline.java @@ -408,7 +408,6 @@ public IrisRenderingPipeline(ProgramSet programSet) { WorldRenderingSettings.INSTANCE.setUseSeparateAo(programSet.getPackDirectives().shouldUseSeparateAo()); WorldRenderingSettings.INSTANCE.setVoxelizeLightBlocks(programSet.getPackDirectives().shouldVoxelizeLightBlocks()); WorldRenderingSettings.INSTANCE.setSeparateEntityDraws(programSet.getPackDirectives().shouldUseSeparateEntityDraws()); - WorldRenderingSettings.INSTANCE.setUseExtendedVertexFormat(true); if (shadowRenderTargets != null) { ShaderInstance shader = shaderMap.getShader(ShaderKey.SHADOW_TERRAIN_CUTOUT); diff --git a/common/src/main/java/net/irisshaders/iris/pipeline/VanillaRenderingPipeline.java b/common/src/main/java/net/irisshaders/iris/pipeline/VanillaRenderingPipeline.java index 951a632db2..5528c4ffd2 100644 --- a/common/src/main/java/net/irisshaders/iris/pipeline/VanillaRenderingPipeline.java +++ b/common/src/main/java/net/irisshaders/iris/pipeline/VanillaRenderingPipeline.java @@ -3,6 +3,7 @@ import com.mojang.blaze3d.platform.GlStateManager; import it.unimi.dsi.fastutil.objects.Object2ObjectMap; import it.unimi.dsi.fastutil.objects.Object2ObjectMaps; +import net.caffeinemc.mods.sodium.client.render.chunk.vertex.format.ChunkMeshFormats; import net.irisshaders.iris.compat.dh.DHCompat; import net.irisshaders.iris.features.FeatureFlags; import net.irisshaders.iris.gl.texture.TextureType; @@ -26,9 +27,9 @@ public VanillaRenderingPipeline() { WorldRenderingSettings.INSTANCE.setUseSeparateAo(false); WorldRenderingSettings.INSTANCE.setSeparateEntityDraws(false); WorldRenderingSettings.INSTANCE.setAmbientOcclusionLevel(1.0f); - WorldRenderingSettings.INSTANCE.setUseExtendedVertexFormat(false); + WorldRenderingSettings.INSTANCE.setVertexFormat(ChunkMeshFormats.COMPACT); WorldRenderingSettings.INSTANCE.setVoxelizeLightBlocks(false); - WorldRenderingSettings.INSTANCE.setBlockTypeIds(null); + WorldRenderingSettings.INSTANCE.setBlockTypeIds(Object2ObjectMaps.emptyMap()); } @Override diff --git a/common/src/main/java/net/irisshaders/iris/pipeline/programs/SodiumPrograms.java b/common/src/main/java/net/irisshaders/iris/pipeline/programs/SodiumPrograms.java index e7eb3ad605..8f945ec5af 100644 --- a/common/src/main/java/net/irisshaders/iris/pipeline/programs/SodiumPrograms.java +++ b/common/src/main/java/net/irisshaders/iris/pipeline/programs/SodiumPrograms.java @@ -20,6 +20,7 @@ import net.irisshaders.iris.pipeline.transform.ShaderPrinter; import net.irisshaders.iris.pipeline.transform.TransformPatcher; import net.irisshaders.iris.shaderpack.loading.ProgramId; +import net.irisshaders.iris.shaderpack.materialmap.WorldRenderingSettings; import net.irisshaders.iris.shaderpack.programs.ProgramFallbackResolver; import net.irisshaders.iris.shaderpack.programs.ProgramSet; import net.irisshaders.iris.shaderpack.programs.ProgramSource; @@ -27,10 +28,13 @@ import net.irisshaders.iris.shadows.ShadowRenderingState; import net.irisshaders.iris.targets.RenderTargets; import net.irisshaders.iris.uniforms.custom.CustomUniforms; +import net.irisshaders.iris.vertices.sodium.terrain.FormatAnalyzer; import net.irisshaders.iris.vertices.sodium.terrain.IrisModelVertexFormats; import net.minecraft.resources.ResourceLocation; import org.lwjgl.opengl.GL43C; +import org.lwjgl.system.MemoryStack; +import java.nio.IntBuffer; import java.util.ArrayList; import java.util.EnumMap; import java.util.List; @@ -42,6 +46,12 @@ public class SodiumPrograms { private final EnumMap framebuffers = new EnumMap<>(Pass.class); private final EnumMap> shaders = new EnumMap<>(Pass.class); + private boolean hasBlockId; + private boolean hasMidUv; + private boolean hasNormal; + private boolean hasTangent; + private boolean hasMidBlock; + public SodiumPrograms(IrisRenderingPipeline pipeline, ProgramSet programSet, ProgramFallbackResolver resolver, RenderTargets renderTargets, Supplier shadowRenderTargets, CustomUniforms customUniforms) { @@ -60,6 +70,8 @@ public SodiumPrograms(IrisRenderingPipeline pipeline, ProgramSet programSet, Pro GlProgram shader = createShader(pipeline, pass, source, alphaTest, customUniforms, flipState, createGlShaders(pass.name().toLowerCase(Locale.ROOT), transformed)); shaders.put(pass, shader); } + + WorldRenderingSettings.INSTANCE.setVertexFormat(FormatAnalyzer.createFormat(hasBlockId, hasNormal, hasMidUv, hasTangent, hasMidBlock)); } private AlphaTest getAlphaTest(Pass pass, ProgramSource source) { @@ -75,7 +87,7 @@ private Map transformShaders(ProgramSource source, Alph source.getTessControlSource().orElse(null), source.getTessEvalSource().orElse(null), source.getFragmentSource().orElse(null), - alphaTest, IrisModelVertexFormats.MODEL_VERTEX_XHFP, + alphaTest, programSet.getPackDirectives().getTextureMap()); ShaderPrinter.printProgram("sodium_" + source.getName()).addSources(transformed).print(); @@ -160,6 +172,13 @@ private GlProgram buildProgram(GlProgram.Builder builder, .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 (!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; + if (!hasTangent) hasTangent = GL43C.glGetAttribLocation(handle, "at_tangent") != -1; + return new SodiumShader(pipeline, pass, shader, handle, source.getDirectives().getBlendModeOverride(), createBufferBlendOverrides(source), customUniforms, flipState, alphaTest.reference(), containsTessellation); 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 45ac978cad..d40dbdcf6c 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 @@ -328,10 +328,10 @@ public TextureStage getTextureStage() { } public static Map patchSodium(String name, String vertex, String geometry, String tessControl, String tessEval, String fragment, - AlphaTest alpha, ChunkVertexType vertexType, + AlphaTest alpha, Object2ObjectMap, String> textureMap) { return transform(name, vertex, geometry, tessControl, tessEval, fragment, - new SodiumParameters(Patch.SODIUM, textureMap, alpha, vertexType)); + new SodiumParameters(Patch.SODIUM, textureMap, alpha)); } public static Map patchComposite( 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 7b12b63548..cecd59351d 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 @@ -9,7 +9,6 @@ import net.irisshaders.iris.shaderpack.texture.TextureStage; public class SodiumParameters extends Parameters { - public final ChunkVertexType vertexType; // WARNING: adding new fields requires updating hashCode and equals methods! // DO NOT include this field in hashCode or equals, it's mutable! @@ -18,9 +17,8 @@ public class SodiumParameters extends Parameters { public SodiumParameters(Patch patch, Object2ObjectMap, String> textureMap, - AlphaTest alpha, ChunkVertexType vertexType) { + AlphaTest alpha) { super(patch, textureMap); - this.vertexType = vertexType; this.alpha = alpha; } @@ -35,15 +33,11 @@ public TextureStage getTextureStage() { return TextureStage.GBUFFERS_AND_SHADOW; } - public ChunkVertexType getVertexType() { - return vertexType; - } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); - result = prime * result + ((vertexType == null) ? 0 : vertexType.hashCode()); result = prime * result + ((alpha == null) ? 0 : alpha.hashCode()); return result; } @@ -57,11 +51,6 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) return false; SodiumParameters other = (SodiumParameters) obj; - if (vertexType == null) { - if (other.vertexType != null) - return false; - } else if (!vertexType.equals(other.vertexType)) - return false; if (alpha == null) { return other.alpha == null; } else return alpha.equals(other.alpha); 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 e4bf4f6e0c..3540d1be0c 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 @@ -51,7 +51,7 @@ public static void transform( root.rename("gl_Color", "_vert_color"); - if (parameters.type.glShaderType == ShaderType.VERTEX) { + if (parameters.type.glShaderType == ShaderType.VERTEX && root.identifierIndex.has("gl_Normal")) { root.rename("gl_Normal", "iris_Normal"); tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "in vec3 iris_Normal;"); } diff --git a/common/src/main/java/net/irisshaders/iris/shaderpack/materialmap/BlockMaterialMapping.java b/common/src/main/java/net/irisshaders/iris/shaderpack/materialmap/BlockMaterialMapping.java index 9098231e20..8f5f2c4e7b 100644 --- a/common/src/main/java/net/irisshaders/iris/shaderpack/materialmap/BlockMaterialMapping.java +++ b/common/src/main/java/net/irisshaders/iris/shaderpack/materialmap/BlockMaterialMapping.java @@ -3,6 +3,7 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectLinkedOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2IntLinkedOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2IntMap; +import it.unimi.dsi.fastutil.objects.Object2ObjectMaps; import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap; import net.irisshaders.iris.Iris; import net.minecraft.client.renderer.RenderType; @@ -97,6 +98,8 @@ private static void addTag(TagEntry tagEntry, Object2IntMap idMap, i } public static Map createBlockTypeMap(Map blockPropertiesMap) { + if (blockPropertiesMap.isEmpty()) return Object2ObjectMaps.emptyMap(); + Map blockTypeIds = new Reference2ReferenceOpenHashMap<>(); blockPropertiesMap.forEach((id, blockType) -> { 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 6fc236fe27..80b05f375c 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 @@ -2,6 +2,8 @@ import it.unimi.dsi.fastutil.objects.Object2IntFunction; import it.unimi.dsi.fastutil.objects.Object2IntMap; +import net.caffeinemc.mods.sodium.client.render.chunk.vertex.format.ChunkMeshFormats; +import net.caffeinemc.mods.sodium.client.render.chunk.vertex.format.ChunkVertexType; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.Nullable; @@ -20,9 +22,9 @@ public class WorldRenderingSettings { private boolean disableDirectionalShading; private boolean hasVillagerConversionId; private boolean useSeparateAo; - private boolean useExtendedVertexFormat; private boolean separateEntityDraws; private boolean voxelizeLightBlocks; + private ChunkVertexType chunkVertexFormat; public WorldRenderingSettings() { reloadRequired = false; @@ -31,7 +33,7 @@ public WorldRenderingSettings() { ambientOcclusionLevel = 1.0F; disableDirectionalShading = false; useSeparateAo = false; - useExtendedVertexFormat = false; + chunkVertexFormat = ChunkMeshFormats.COMPACT; separateEntityDraws = false; voxelizeLightBlocks = false; hasVillagerConversionId = false; @@ -59,7 +61,6 @@ public void setBlockStateIds(Object2IntMap blockStateIds) { this.blockStateIds = blockStateIds; } - @Nullable public Map getBlockTypeIds() { return blockTypeIds; } @@ -133,17 +134,17 @@ public void setUseSeparateAo(boolean useSeparateAo) { this.useSeparateAo = useSeparateAo; } - public boolean shouldUseExtendedVertexFormat() { - return useExtendedVertexFormat; + public ChunkVertexType getVertexFormat() { + return chunkVertexFormat; } - public void setUseExtendedVertexFormat(boolean useExtendedVertexFormat) { - if (useExtendedVertexFormat == this.useExtendedVertexFormat) { + public void setVertexFormat(ChunkVertexType chunkVertexFormat) { + if (chunkVertexFormat == this.chunkVertexFormat) { return; } this.reloadRequired = true; - this.useExtendedVertexFormat = useExtendedVertexFormat; + this.chunkVertexFormat = chunkVertexFormat; } public boolean shouldVoxelizeLightBlocks() { diff --git a/common/src/main/java/net/irisshaders/iris/vertices/sodium/CloudVertex.java b/common/src/main/java/net/irisshaders/iris/vertices/sodium/CloudVertex.java index df0acd0757..bfbfde0f54 100644 --- a/common/src/main/java/net/irisshaders/iris/vertices/sodium/CloudVertex.java +++ b/common/src/main/java/net/irisshaders/iris/vertices/sodium/CloudVertex.java @@ -4,15 +4,11 @@ import net.caffeinemc.mods.sodium.api.vertex.attributes.common.ColorAttribute; import net.caffeinemc.mods.sodium.api.vertex.attributes.common.NormalAttribute; import net.caffeinemc.mods.sodium.api.vertex.attributes.common.PositionAttribute; -import net.caffeinemc.mods.sodium.api.vertex.format.VertexFormatDescription; -import net.caffeinemc.mods.sodium.api.vertex.format.VertexFormatRegistry; + import net.caffeinemc.mods.sodium.api.vertex.format.VertexFormatRegistry; import net.irisshaders.iris.vertices.IrisVertexFormats; import org.joml.Matrix4f; public final class CloudVertex { - public static final VertexFormatDescription FORMAT = VertexFormatRegistry.instance() - .get(IrisVertexFormats.CLOUDS); - public static final int STRIDE = 20; private static final int OFFSET_POSITION = 0; diff --git a/common/src/main/java/net/irisshaders/iris/vertices/sodium/EntityToTerrainVertexSerializer.java b/common/src/main/java/net/irisshaders/iris/vertices/sodium/EntityToTerrainVertexSerializer.java index bf59a8c260..0b200c04f2 100644 --- a/common/src/main/java/net/irisshaders/iris/vertices/sodium/EntityToTerrainVertexSerializer.java +++ b/common/src/main/java/net/irisshaders/iris/vertices/sodium/EntityToTerrainVertexSerializer.java @@ -2,7 +2,7 @@ import net.caffeinemc.mods.sodium.api.memory.MemoryIntrinsics; import net.caffeinemc.mods.sodium.api.util.NormI8; -import net.caffeinemc.mods.sodium.api.vertex.format.common.ModelVertex; +import net.caffeinemc.mods.sodium.api.vertex.format.common.EntityVertex; import net.caffeinemc.mods.sodium.api.vertex.serializer.VertexSerializer; import net.irisshaders.iris.uniforms.CapturedRenderingState; import net.irisshaders.iris.vertices.IrisVertexFormats; @@ -17,12 +17,12 @@ public void serialize(long src, long dst, int vertexCount) { for (int i = 0; i < quadCount; i++) { int normal = MemoryUtil.memGetInt(src + 32); int tangent = NormalHelper.computeTangent(NormI8.unpackX(normal), NormI8.unpackY(normal), NormI8.unpackZ(normal), MemoryUtil.memGetFloat(src), MemoryUtil.memGetFloat(src + 4), MemoryUtil.memGetFloat(src + 8), MemoryUtil.memGetFloat(src + 16), MemoryUtil.memGetFloat(src + 20), - MemoryUtil.memGetFloat(src + ModelVertex.STRIDE), MemoryUtil.memGetFloat(src + 4 + ModelVertex.STRIDE), MemoryUtil.memGetFloat(src + 8 + ModelVertex.STRIDE), MemoryUtil.memGetFloat(src + 16 + ModelVertex.STRIDE), MemoryUtil.memGetFloat(src + 20 + ModelVertex.STRIDE), - MemoryUtil.memGetFloat(src + ModelVertex.STRIDE + ModelVertex.STRIDE), MemoryUtil.memGetFloat(src + 4 + ModelVertex.STRIDE + ModelVertex.STRIDE), MemoryUtil.memGetFloat(src + 8 + ModelVertex.STRIDE + ModelVertex.STRIDE), MemoryUtil.memGetFloat(src + 16 + ModelVertex.STRIDE + ModelVertex.STRIDE), MemoryUtil.memGetFloat(src + 20 + ModelVertex.STRIDE + ModelVertex.STRIDE)); + MemoryUtil.memGetFloat(src + EntityVertex.STRIDE), MemoryUtil.memGetFloat(src + 4 + EntityVertex.STRIDE), MemoryUtil.memGetFloat(src + 8 + EntityVertex.STRIDE), MemoryUtil.memGetFloat(src + 16 + EntityVertex.STRIDE), MemoryUtil.memGetFloat(src + 20 + EntityVertex.STRIDE), + MemoryUtil.memGetFloat(src + EntityVertex.STRIDE + EntityVertex.STRIDE), MemoryUtil.memGetFloat(src + 4 + EntityVertex.STRIDE + EntityVertex.STRIDE), MemoryUtil.memGetFloat(src + 8 + EntityVertex.STRIDE + EntityVertex.STRIDE), MemoryUtil.memGetFloat(src + 16 + EntityVertex.STRIDE + EntityVertex.STRIDE), MemoryUtil.memGetFloat(src + 20 + EntityVertex.STRIDE + EntityVertex.STRIDE)); float midU = 0, midV = 0; for (int vertex = 0; vertex < 4; vertex++) { - midU += MemoryUtil.memGetFloat(src + 16 + (ModelVertex.STRIDE * vertex)); - midV += MemoryUtil.memGetFloat(src + 20 + (ModelVertex.STRIDE * vertex)); + midU += MemoryUtil.memGetFloat(src + 16 + (EntityVertex.STRIDE * vertex)); + midV += MemoryUtil.memGetFloat(src + 20 + (EntityVertex.STRIDE * vertex)); } midU /= 4; @@ -39,7 +39,7 @@ public void serialize(long src, long dst, int vertexCount) { MemoryUtil.memPutInt(dst + 44, tangent); MemoryUtil.memPutInt(dst + 48, 0); - src += ModelVertex.STRIDE; + src += EntityVertex.STRIDE; dst += IrisVertexFormats.TERRAIN.getVertexSize(); } } diff --git a/common/src/main/java/net/irisshaders/iris/vertices/sodium/IrisCommonVertexAttributes.java b/common/src/main/java/net/irisshaders/iris/vertices/sodium/IrisCommonVertexAttributes.java deleted file mode 100644 index cecccb1c16..0000000000 --- a/common/src/main/java/net/irisshaders/iris/vertices/sodium/IrisCommonVertexAttributes.java +++ /dev/null @@ -1,7 +0,0 @@ -package net.irisshaders.iris.vertices.sodium; - -import net.caffeinemc.mods.sodium.api.vertex.attributes.CommonVertexAttribute; - -public class IrisCommonVertexAttributes { - public static CommonVertexAttribute TANGENT, MID_TEX_COORD, BLOCK_ID, MID_BLOCK, ENTITY_ID; -} diff --git a/common/src/main/java/net/irisshaders/iris/vertices/sodium/ModelToEntityVertexSerializer.java b/common/src/main/java/net/irisshaders/iris/vertices/sodium/ModelToEntityVertexSerializer.java index c2b5673ab5..c2e76a7e47 100644 --- a/common/src/main/java/net/irisshaders/iris/vertices/sodium/ModelToEntityVertexSerializer.java +++ b/common/src/main/java/net/irisshaders/iris/vertices/sodium/ModelToEntityVertexSerializer.java @@ -2,7 +2,7 @@ import net.caffeinemc.mods.sodium.api.memory.MemoryIntrinsics; import net.caffeinemc.mods.sodium.api.util.NormI8; -import net.caffeinemc.mods.sodium.api.vertex.format.common.ModelVertex; +import net.caffeinemc.mods.sodium.api.vertex.format.common.EntityVertex; import net.caffeinemc.mods.sodium.api.vertex.serializer.VertexSerializer; import net.irisshaders.iris.uniforms.CapturedRenderingState; import net.irisshaders.iris.vertices.IrisVertexFormats; @@ -17,12 +17,12 @@ public void serialize(long src, long dst, int vertexCount) { for (int i = 0; i < quadCount; i++) { int normal = MemoryUtil.memGetInt(src + 32); int tangent = NormalHelper.computeTangent(NormI8.unpackX(normal), NormI8.unpackY(normal), NormI8.unpackZ(normal), MemoryUtil.memGetFloat(src), MemoryUtil.memGetFloat(src + 4), MemoryUtil.memGetFloat(src + 8), MemoryUtil.memGetFloat(src + 16), MemoryUtil.memGetFloat(src + 20), - MemoryUtil.memGetFloat(src + ModelVertex.STRIDE), MemoryUtil.memGetFloat(src + 4 + ModelVertex.STRIDE), MemoryUtil.memGetFloat(src + 8 + ModelVertex.STRIDE), MemoryUtil.memGetFloat(src + 16 + ModelVertex.STRIDE), MemoryUtil.memGetFloat(src + 20 + ModelVertex.STRIDE), - MemoryUtil.memGetFloat(src + ModelVertex.STRIDE + ModelVertex.STRIDE), MemoryUtil.memGetFloat(src + 4 + ModelVertex.STRIDE + ModelVertex.STRIDE), MemoryUtil.memGetFloat(src + 8 + ModelVertex.STRIDE + ModelVertex.STRIDE), MemoryUtil.memGetFloat(src + 16 + ModelVertex.STRIDE + ModelVertex.STRIDE), MemoryUtil.memGetFloat(src + 20 + ModelVertex.STRIDE + ModelVertex.STRIDE)); + MemoryUtil.memGetFloat(src + EntityVertex.STRIDE), MemoryUtil.memGetFloat(src + 4 + EntityVertex.STRIDE), MemoryUtil.memGetFloat(src + 8 + EntityVertex.STRIDE), MemoryUtil.memGetFloat(src + 16 + EntityVertex.STRIDE), MemoryUtil.memGetFloat(src + 20 + EntityVertex.STRIDE), + MemoryUtil.memGetFloat(src + EntityVertex.STRIDE + EntityVertex.STRIDE), MemoryUtil.memGetFloat(src + 4 + EntityVertex.STRIDE + EntityVertex.STRIDE), MemoryUtil.memGetFloat(src + 8 + EntityVertex.STRIDE + EntityVertex.STRIDE), MemoryUtil.memGetFloat(src + 16 + EntityVertex.STRIDE + EntityVertex.STRIDE), MemoryUtil.memGetFloat(src + 20 + EntityVertex.STRIDE + EntityVertex.STRIDE)); float midU = 0, midV = 0; for (int vertex = 0; vertex < 4; vertex++) { - midU += MemoryUtil.memGetFloat(src + 16 + (ModelVertex.STRIDE * vertex)); - midV += MemoryUtil.memGetFloat(src + 20 + (ModelVertex.STRIDE * vertex)); + midU += MemoryUtil.memGetFloat(src + 16 + (EntityVertex.STRIDE * vertex)); + midV += MemoryUtil.memGetFloat(src + 20 + (EntityVertex.STRIDE * vertex)); } midU /= 4; @@ -37,7 +37,7 @@ public void serialize(long src, long dst, int vertexCount) { MemoryUtil.memPutFloat(dst + 46, midV); MemoryUtil.memPutInt(dst + 50, tangent); - src += ModelVertex.STRIDE; + src += EntityVertex.STRIDE; dst += IrisVertexFormats.ENTITY.getVertexSize(); } } diff --git a/common/src/main/java/net/irisshaders/iris/vertices/sodium/terrain/FormatAnalyzer.java b/common/src/main/java/net/irisshaders/iris/vertices/sodium/terrain/FormatAnalyzer.java new file mode 100644 index 0000000000..4973c1fcce --- /dev/null +++ b/common/src/main/java/net/irisshaders/iris/vertices/sodium/terrain/FormatAnalyzer.java @@ -0,0 +1,109 @@ +package net.irisshaders.iris.vertices.sodium.terrain; + +import it.unimi.dsi.fastutil.bytes.Byte2ObjectMap; +import it.unimi.dsi.fastutil.bytes.Byte2ObjectOpenHashMap; +import net.caffeinemc.mods.sodium.client.gl.attribute.GlVertexFormat; +import net.caffeinemc.mods.sodium.client.render.chunk.shader.ChunkShaderBindingPoints; +import net.caffeinemc.mods.sodium.client.render.chunk.vertex.format.ChunkMeshFormats; +import net.caffeinemc.mods.sodium.client.render.chunk.vertex.format.ChunkVertexType; +import net.caffeinemc.mods.sodium.client.render.chunk.vertex.format.impl.DefaultChunkMeshAttributes; + +public class FormatAnalyzer { + private static final Byte2ObjectMap classMap = new Byte2ObjectOpenHashMap<>(); + + static { + classMap.put((byte) 0, ChunkMeshFormats.COMPACT); + } + + public static ChunkVertexType createFormat(boolean blockId, boolean normal, boolean midUV, boolean tangent, boolean midBlock) { + byte key = 0; + if (blockId) { + key |= 1; + } + if (normal) { + key |= 2; + } + if (midUV) { + key |= 4; + } + if (tangent) { + key |= 8; + } + if (midBlock) { + key |= 16; + } + + if (classMap.containsKey(key)) { + return classMap.get(key); + } + + int offset = 20; // Normal Sodium stuff + + int blockIdOffset, normalOffset, tangentOffset, midUvOffset, midBlockOffset; + + if (blockId) { + blockIdOffset = offset; + offset += 4; + } else { + blockIdOffset = 0; + } + + if (normal) { + normalOffset = offset; + offset += 4; + } else { + normalOffset = 0; + } + + if (midUV) { + midUvOffset = offset; + offset += 4; + } else { + midUvOffset = 0; + } + + if (tangent) { + tangentOffset = offset; + offset += 4; + } else { + tangentOffset = 0; + } + + if (midBlock) { + midBlockOffset = offset; + offset += 4; + } else { + midBlockOffset = 0; + } + + GlVertexFormat.Builder VERTEX_FORMAT = GlVertexFormat.builder(offset) + .addElement(DefaultChunkMeshAttributes.POSITION_HI, ChunkShaderBindingPoints.ATTRIBUTE_POSITION_HI, 0) + .addElement(DefaultChunkMeshAttributes.POSITION_LO, ChunkShaderBindingPoints.ATTRIBUTE_POSITION_LO, 4) + .addElement(DefaultChunkMeshAttributes.COLOR, ChunkShaderBindingPoints.ATTRIBUTE_COLOR, 8) + .addElement(DefaultChunkMeshAttributes.TEXTURE, ChunkShaderBindingPoints.ATTRIBUTE_TEXTURE, 12) + .addElement(DefaultChunkMeshAttributes.LIGHT_MATERIAL_INDEX, ChunkShaderBindingPoints.ATTRIBUTE_LIGHT_MATERIAL_INDEX, 16); + + if (blockId) { + VERTEX_FORMAT.addElement(IrisChunkMeshAttributes.BLOCK_ID, 11, blockIdOffset); + } + + if (normal) { + VERTEX_FORMAT.addElement(IrisChunkMeshAttributes.NORMAL, 10, normalOffset); + } + + if (midUV) { + VERTEX_FORMAT.addElement(IrisChunkMeshAttributes.MID_TEX_COORD, 12, midUvOffset); + } + + if (tangent) { + VERTEX_FORMAT.addElement(IrisChunkMeshAttributes.TANGENT, 13, tangentOffset); + } + + if (midBlock) { + VERTEX_FORMAT.addElement(IrisChunkMeshAttributes.MID_BLOCK, 14, midBlockOffset); + } + + + return classMap.computeIfAbsent(key, k -> new XHFPModelVertexType(VERTEX_FORMAT.build(), blockIdOffset, normalOffset, tangentOffset, midUvOffset, midBlockOffset)); + } +} diff --git a/common/src/main/java/net/irisshaders/iris/vertices/sodium/terrain/IrisModelVertexFormats.java b/common/src/main/java/net/irisshaders/iris/vertices/sodium/terrain/IrisModelVertexFormats.java index ebaf99d816..c77e88e336 100644 --- a/common/src/main/java/net/irisshaders/iris/vertices/sodium/terrain/IrisModelVertexFormats.java +++ b/common/src/main/java/net/irisshaders/iris/vertices/sodium/terrain/IrisModelVertexFormats.java @@ -3,5 +3,4 @@ import net.caffeinemc.mods.sodium.client.render.chunk.vertex.format.ChunkVertexType; public class IrisModelVertexFormats { - public static final ChunkVertexType MODEL_VERTEX_XHFP = new XHFPModelVertexType(); } diff --git a/common/src/main/java/net/irisshaders/iris/vertices/sodium/terrain/XHFPModelVertexType.java b/common/src/main/java/net/irisshaders/iris/vertices/sodium/terrain/XHFPModelVertexType.java index 6328026df1..1b8b51f4bb 100644 --- a/common/src/main/java/net/irisshaders/iris/vertices/sodium/terrain/XHFPModelVertexType.java +++ b/common/src/main/java/net/irisshaders/iris/vertices/sodium/terrain/XHFPModelVertexType.java @@ -5,25 +5,30 @@ import net.caffeinemc.mods.sodium.client.render.chunk.vertex.format.ChunkVertexEncoder; import net.caffeinemc.mods.sodium.client.render.chunk.vertex.format.ChunkVertexType; import net.caffeinemc.mods.sodium.client.render.chunk.vertex.format.impl.DefaultChunkMeshAttributes; +import net.irisshaders.iris.vertices.NormI8; +import net.irisshaders.iris.vertices.NormalHelper; +import net.minecraft.util.Mth; +import org.joml.Vector3f; /** * Like HFPModelVertexType, but extended to support Iris. The extensions aren't particularly efficient right now. */ public class XHFPModelVertexType implements ChunkVertexType { - public static final int STRIDE = 40; - - public static final GlVertexFormat VERTEX_FORMAT = GlVertexFormat.builder(STRIDE) - .addElement(DefaultChunkMeshAttributes.POSITION_HI, ChunkShaderBindingPoints.ATTRIBUTE_POSITION_HI, 0) - .addElement(DefaultChunkMeshAttributes.POSITION_LO, ChunkShaderBindingPoints.ATTRIBUTE_POSITION_LO, 4) - .addElement(DefaultChunkMeshAttributes.COLOR, ChunkShaderBindingPoints.ATTRIBUTE_COLOR, 8) - .addElement(DefaultChunkMeshAttributes.TEXTURE, ChunkShaderBindingPoints.ATTRIBUTE_TEXTURE, 12) - .addElement(DefaultChunkMeshAttributes.LIGHT_MATERIAL_INDEX, ChunkShaderBindingPoints.ATTRIBUTE_LIGHT_MATERIAL_INDEX, 16) - .addElement(IrisChunkMeshAttributes.MID_TEX_COORD, 12, 20) - .addElement(IrisChunkMeshAttributes.TANGENT, 13, 24) - .addElement(IrisChunkMeshAttributes.NORMAL, 10, 28) - .addElement(IrisChunkMeshAttributes.BLOCK_ID, 11, 32) - .addElement(IrisChunkMeshAttributes.MID_BLOCK, 14, 36) - .build(); + private final GlVertexFormat format; + private final int normalOffset; + private final int blockIdOffset; + private final int tangentOffset; + private final int midBlockOffset; + private final int midUvOffset; + + public XHFPModelVertexType(GlVertexFormat format, int blockIdOffset, int normalOffset, int tangentOffset, int midUvOffset, int midBlockOffset) { + this.format = format; + this.blockIdOffset = blockIdOffset; + this.normalOffset = normalOffset; + this.tangentOffset = tangentOffset; + this.midUvOffset = midUvOffset; + this.midBlockOffset = midBlockOffset; + } private static final int POSITION_MAX_VALUE = 65536; private static final int TEXTURE_MAX_VALUE = 32768; @@ -43,11 +48,11 @@ public static int encodeOld(float u, float v) { @Override public GlVertexFormat getVertexFormat() { - return VERTEX_FORMAT; + return format; } @Override public ChunkVertexEncoder getEncoder() { - return new XHFPTerrainVertex(); + return new XHFPTerrainVertex(blockIdOffset, normalOffset, tangentOffset, midUvOffset, midBlockOffset, format.getStride()); } } 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 025d76fadd..44b4cf0890 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 @@ -18,8 +18,23 @@ public class XHFPTerrainVertex implements ChunkVertexEncoder, VertexEncoderInter private static final float MODEL_ORIGIN = 8.0f; private static final float MODEL_RANGE = 32.0f; private final Vector3f normal = new Vector3f(); + private final int blockIdOffset; + private final int normalOffset; + private final int tangentOffset; + private final int midBlockOffset; + private final int midUvOffset; + private final int stride; private BlockContextHolder contextHolder; + public XHFPTerrainVertex(int blockIdOffset, int normalOffset, int tangentOffset, int midUvOffset, int midBlockOffset, int stride) { + this.blockIdOffset = blockIdOffset; + this.normalOffset = normalOffset; + this.tangentOffset = tangentOffset; + this.midUvOffset = midUvOffset; + this.midBlockOffset = midBlockOffset; + this.stride = stride; + } + private static int packPositionHi(int x, int y, int z) { return (x >>> 10 & 1023) << 0 | (y >>> 10 & 1023) << 10 | (z >>> 10 & 1023) << 20; } @@ -80,7 +95,7 @@ private static int floorInt(float x) { @Override public long write(long ptr, - Material material, Vertex[] vertices, int section) { + int material, Vertex[] vertices, int section) { // Calculate the center point of the texture region which is mapped to the quad float texCentroidU = 0.0f; float texCentroidV = 0.0f; @@ -93,22 +108,29 @@ public long write(long ptr, texCentroidU *= (1.0f / 4.0f); texCentroidV *= (1.0f / 4.0f); int midUV = XHFPModelVertexType.encodeOld(texCentroidU, texCentroidV); - NormalHelper.computeFaceNormalManual(normal, vertices[0].x, vertices[0].y, vertices[0].z, - vertices[1].x, vertices[1].y, vertices[1].z, - vertices[2].x, vertices[2].y, vertices[2].z, - vertices[3].x, vertices[3].y, vertices[3].z); - int packedNormal = NormI8.pack(normal); - int tangent = NormalHelper.computeTangent(normal.x, normal.y, normal.z, - vertices[0].x, vertices[0].y, vertices[0].z, vertices[0].u, vertices[0].v, - vertices[1].x, vertices[1].y, vertices[1].z, vertices[1].u, vertices[1].v, - vertices[2].x, vertices[2].y, vertices[2].z, vertices[2].u, vertices[2].v); - - if (tangent == -1) { - // Try calculating the second triangle + int packedNormal = 0; + if (normalOffset != 0 || tangentOffset != 0) { + NormalHelper.computeFaceNormalManual(normal, vertices[0].x, vertices[0].y, vertices[0].z, + vertices[1].x, vertices[1].y, vertices[1].z, + vertices[2].x, vertices[2].y, vertices[2].z, + vertices[3].x, vertices[3].y, vertices[3].z); + packedNormal = NormI8.pack(normal); + } + int tangent = 0; + + if (tangentOffset != 0) { tangent = NormalHelper.computeTangent(normal.x, normal.y, normal.z, - vertices[2].x, vertices[2].y, vertices[2].z, vertices[2].u, vertices[2].v, - vertices[3].x, vertices[3].y, vertices[3].z, vertices[3].u, vertices[3].v, - vertices[0].x, vertices[0].y, vertices[0].z, vertices[0].u, vertices[0].v); + vertices[0].x, vertices[0].y, vertices[0].z, vertices[0].u, vertices[0].v, + vertices[1].x, vertices[1].y, vertices[1].z, vertices[1].u, vertices[1].v, + vertices[2].x, vertices[2].y, vertices[2].z, vertices[2].u, vertices[2].v); + + if (tangent == -1) { + // Try calculating the second triangle + tangent = NormalHelper.computeTangent(normal.x, normal.y, normal.z, + vertices[2].x, vertices[2].y, vertices[2].z, vertices[2].u, vertices[2].v, + vertices[3].x, vertices[3].y, vertices[3].z, vertices[3].u, vertices[3].v, + vertices[0].x, vertices[0].y, vertices[0].z, vertices[0].u, vertices[0].v); + } } for (int i = 0; i < 4; i++) { @@ -127,18 +149,30 @@ public long write(long ptr, 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 + 12L, packTexture(u, v)); - MemoryUtil.memPutInt(ptr + 16L, packLightAndData(light, material.bits(), section)); - - MemoryUtil.memPutShort(ptr + 32, contextHolder.getBlockId()); - MemoryUtil.memPutShort(ptr + 34, contextHolder.getRenderType()); - MemoryUtil.memPutInt(ptr + 36, contextHolder.ignoreMidBlock() ? 0 : ExtendedDataHelper.computeMidBlock(vertex.x, vertex.y, vertex.z, contextHolder.getLocalPosX(), contextHolder.getLocalPosY(), contextHolder.getLocalPosZ())); - MemoryUtil.memPutByte(ptr + 39, contextHolder.getBlockEmission()); - - MemoryUtil.memPutInt(ptr + 20, midUV); - MemoryUtil.memPutInt(ptr + 28, packedNormal); - MemoryUtil.memPutInt(ptr + 24, tangent); - - ptr += XHFPModelVertexType.STRIDE; + MemoryUtil.memPutInt(ptr + 16L, packLightAndData(light, material, section)); + + if (blockIdOffset != 0) { + MemoryUtil.memPutShort(ptr + blockIdOffset, contextHolder.getBlockId()); + MemoryUtil.memPutShort(ptr + blockIdOffset + 2, contextHolder.getRenderType()); + } + + if (midBlockOffset != 0) { + MemoryUtil.memPutInt(ptr + midBlockOffset, contextHolder.ignoreMidBlock() ? 0 : ExtendedDataHelper.computeMidBlock(vertex.x, vertex.y, vertex.z, contextHolder.getLocalPosX(), contextHolder.getLocalPosY(), contextHolder.getLocalPosZ())); + MemoryUtil.memPutByte(ptr + midBlockOffset + 3, contextHolder.getBlockEmission()); + } + + if (midUvOffset != 0) { + MemoryUtil.memPutInt(ptr + midUvOffset, midUV); + } + + if (normalOffset != 0) { + MemoryUtil.memPutInt(ptr + normalOffset, packedNormal); + } + if (tangentOffset != 0) { + MemoryUtil.memPutInt(ptr + tangentOffset, tangent); + } + + ptr += stride; } return ptr; diff --git a/common/src/main/resources/mixins.iris.compat.sodium.json b/common/src/main/resources/mixins.iris.compat.sodium.json index 41aeeaf7ad..66fc7ad1a8 100644 --- a/common/src/main/resources/mixins.iris.compat.sodium.json +++ b/common/src/main/resources/mixins.iris.compat.sodium.json @@ -5,8 +5,7 @@ "refmap": "iris.refmap.json", "compatibilityLevel": "JAVA_8", "client": [ - "entity.CommonVertexAttributeInterface", - "entity.MixinCommonVertexAttribute", + "MixinBlockRenderer", "MixinChunkBuildBuffers", "MixinChunkMeshBuildTask", "MixinCloudRenderer", diff --git a/neoforge/src/main/java/net/irisshaders/iris/mixin/forge/MixinItemBlockRenderTypes.java b/neoforge/src/main/java/net/irisshaders/iris/mixin/forge/MixinItemBlockRenderTypes.java index 4b7d80eadf..2b2a3cc7ea 100644 --- a/neoforge/src/main/java/net/irisshaders/iris/mixin/forge/MixinItemBlockRenderTypes.java +++ b/neoforge/src/main/java/net/irisshaders/iris/mixin/forge/MixinItemBlockRenderTypes.java @@ -31,12 +31,9 @@ public class MixinItemBlockRenderTypes { @Inject(method = "getRenderLayers", at = @At("HEAD"), cancellable = true) private static void iris$setCustomRenderType(BlockState arg, CallbackInfoReturnable cir) { - Map idMap = WorldRenderingSettings.INSTANCE.getBlockTypeIds(); - if (idMap != null) { - BlockRenderType type = idMap.get(arg.getBlock()); - if (type != null) { - cir.setReturnValue(LAYER_SET[type.ordinal()]); - } + BlockRenderType type = WorldRenderingSettings.INSTANCE.getBlockTypeIds().get(arg.getBlock()); + if (type != null) { + cir.setReturnValue(LAYER_SET[type.ordinal()]); } } } diff --git a/neoforge/src/main/java/net/irisshaders/iris/mixin/forge/MixinRenderFlame.java b/neoforge/src/main/java/net/irisshaders/iris/mixin/forge/MixinRenderFlame.java index 3b4ec841d4..7e3928ac15 100644 --- a/neoforge/src/main/java/net/irisshaders/iris/mixin/forge/MixinRenderFlame.java +++ b/neoforge/src/main/java/net/irisshaders/iris/mixin/forge/MixinRenderFlame.java @@ -29,7 +29,7 @@ public class MixinRenderFlame { "render(Lmekanism/common/entity/EntityFlame;FFLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V" }, at = @At(value = "FIELD", target = "Lmekanism/client/render/MekanismRenderType;FLAME:Ljava/util/function/Function;")) private Function doNotSwitchShaders() { - if (IrisApi.getInstance().isShaderPackInUse()) { + if (Iris.isPackInUseQuick()) { return LightningHandler.MEKANISM_FLAME; } else { return (Function) MEKANISM_FLAME; diff --git a/neoforge/src/main/java/net/irisshaders/iris/mixin/forge/MixinRenderMekasuit.java b/neoforge/src/main/java/net/irisshaders/iris/mixin/forge/MixinRenderMekasuit.java index e95b74ebe0..c03d3f1fc1 100644 --- a/neoforge/src/main/java/net/irisshaders/iris/mixin/forge/MixinRenderMekasuit.java +++ b/neoforge/src/main/java/net/irisshaders/iris/mixin/forge/MixinRenderMekasuit.java @@ -28,7 +28,7 @@ public class MixinRenderMekasuit { "Lmekanism/client/render/armor/MekaSuitArmor;render(Lnet/minecraft/client/model/HumanoidModel;Lnet/minecraft/client/renderer/MultiBufferSource;Lcom/mojang/blaze3d/vertex/PoseStack;IILmekanism/common/lib/Color;ZLnet/minecraft/world/entity/LivingEntity;Ljava/util/Map;Z)V" }, at = @At(value = "FIELD", target = "Lmekanism/client/render/MekanismRenderType;MEKASUIT:Lnet/minecraft/client/renderer/RenderType;")) private RenderType doNotSwitchShaders() { - if (IrisApi.getInstance().isShaderPackInUse() && ImmediateState.isRenderingLevel) { + if (Iris.isPackInUseQuick() && ImmediateState.isRenderingLevel) { return LightningHandler.MEKASUIT; } else { return (RenderType) MEKASUIT; diff --git a/neoforge/src/main/java/net/irisshaders/iris/mixin/forge/MixinVBOIE.java b/neoforge/src/main/java/net/irisshaders/iris/mixin/forge/MixinVBOIE.java index 4a89ed562a..bd508519e1 100644 --- a/neoforge/src/main/java/net/irisshaders/iris/mixin/forge/MixinVBOIE.java +++ b/neoforge/src/main/java/net/irisshaders/iris/mixin/forge/MixinVBOIE.java @@ -1,5 +1,6 @@ package net.irisshaders.iris.mixin.forge; +import net.irisshaders.iris.Iris; import net.irisshaders.iris.api.v0.IrisApi; import net.irisshaders.iris.pipeline.programs.FallbackShader; import net.irisshaders.iris.pipeline.programs.ShaderAccess; @@ -17,7 +18,7 @@ public class MixinVBOIE { @Overwrite public static ShaderInstance getVboShader() { - if (!IrisApi.getInstance().isShaderPackInUse()) { + if (!Iris.isPackInUseQuick()) { return vboShader; } else { ShaderInstance shader = ShaderAccess.getIEVBOShader();