From 0e47ca12f589b71293df4aa2c49b24a9c8b02033 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Mon, 11 Sep 2023 10:01:48 -0700 Subject: [PATCH 01/56] 1.20.2 p1 --- buildscript/src/main/java/Buildscript.java | 2 +- .../mixin/MixinRenderBuffers.java | 6 ++-- ... => SectionBufferBuilderPackAccessor.java} | 6 ++-- .../iris/gui/FeatureMissingErrorScreen.java | 2 +- .../gui/debug/DebugLoadFailedGridScreen.java | 10 ------- .../iris/gui/screen/ShaderPackScreen.java | 2 +- .../MixinElytraLayer.java | 3 +- .../net/coderbot/iris/mixin/gui/MixinGui.java | 7 ++++- .../iris/mixin/shadows/ChunkInfoAccessor.java | 12 -------- .../MixinPreventRebuildNearInShadowPass.java | 29 ++++--------------- .../MixinChunkRebuildTask.java | 16 +++++----- .../iris/pipeline/ShadowRenderer.java | 2 +- .../texture/pbr/loader/AtlasPBRLoader.java | 9 +++--- .../iris-batched-entity-rendering.mixins.json | 2 +- src/main/resources/iris.accesswidener | 4 +-- src/main/resources/mixins.iris.json | 1 - 16 files changed, 38 insertions(+), 75 deletions(-) rename src/main/java/net/coderbot/batchedentityrendering/mixin/{ChunkBufferBuilderPackAccessor.java => SectionBufferBuilderPackAccessor.java} (67%) delete mode 100644 src/main/java/net/coderbot/iris/mixin/shadows/ChunkInfoAccessor.java diff --git a/buildscript/src/main/java/Buildscript.java b/buildscript/src/main/java/Buildscript.java index ebbf31a64b..af6aedbd73 100644 --- a/buildscript/src/main/java/Buildscript.java +++ b/buildscript/src/main/java/Buildscript.java @@ -45,7 +45,7 @@ public class Buildscript extends SimpleFabricProject { static final boolean SODIUM = true; static final boolean CUSTOM_SODIUM = false; - static final String MC_VERSION = "1.20.1"; + static final String MC_VERSION = "1.20.2-pre2"; static final String customSodiumName = "sodium-fabric-mc1.20.1-0.5.1-beta1.jar"; private static final String[] SOURCE_SETS = new String[] { diff --git a/src/main/java/net/coderbot/batchedentityrendering/mixin/MixinRenderBuffers.java b/src/main/java/net/coderbot/batchedentityrendering/mixin/MixinRenderBuffers.java index 35f8f3484c..4c7d60535c 100644 --- a/src/main/java/net/coderbot/batchedentityrendering/mixin/MixinRenderBuffers.java +++ b/src/main/java/net/coderbot/batchedentityrendering/mixin/MixinRenderBuffers.java @@ -6,7 +6,7 @@ import net.coderbot.batchedentityrendering.impl.MemoryTrackingBuffer; import net.coderbot.batchedentityrendering.impl.MemoryTrackingRenderBuffers; import net.coderbot.batchedentityrendering.impl.RenderBuffersExt; -import net.minecraft.client.renderer.ChunkBufferBuilderPack; +import net.minecraft.client.renderer.SectionBufferBuilderPack; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.OutlineBufferSource; import net.minecraft.client.renderer.RenderBuffers; @@ -45,7 +45,7 @@ public class MixinRenderBuffers implements RenderBuffersExt, MemoryTrackingRende @Shadow @Final - private ChunkBufferBuilderPack fixedBufferPack; + private SectionBufferBuilderPack fixedBufferPack; @Shadow @Final @@ -125,7 +125,7 @@ public int getMaxBegins() { @Override public void freeAndDeleteBuffers() { buffered.freeAndDeleteBuffer(); - ((ChunkBufferBuilderPackAccessor) this.fixedBufferPack).getBuilders().values().forEach(bufferBuilder -> ((MemoryTrackingBuffer) bufferBuilder).freeAndDeleteBuffer()); + ((SectionBufferBuilderPackAccessor) this.fixedBufferPack).getBuilders().values().forEach(bufferBuilder -> ((MemoryTrackingBuffer) bufferBuilder).freeAndDeleteBuffer()); fixedBuffers.values().forEach(bufferBuilder -> ((MemoryTrackingBuffer) bufferBuilder).freeAndDeleteBuffer()); ((MemoryTrackingBuffer) ((OutlineBufferSourceAccessor) outlineBufferSource).getOutlineBufferSource()).freeAndDeleteBuffer(); } diff --git a/src/main/java/net/coderbot/batchedentityrendering/mixin/ChunkBufferBuilderPackAccessor.java b/src/main/java/net/coderbot/batchedentityrendering/mixin/SectionBufferBuilderPackAccessor.java similarity index 67% rename from src/main/java/net/coderbot/batchedentityrendering/mixin/ChunkBufferBuilderPackAccessor.java rename to src/main/java/net/coderbot/batchedentityrendering/mixin/SectionBufferBuilderPackAccessor.java index 378cbb2c59..beddf3444f 100644 --- a/src/main/java/net/coderbot/batchedentityrendering/mixin/ChunkBufferBuilderPackAccessor.java +++ b/src/main/java/net/coderbot/batchedentityrendering/mixin/SectionBufferBuilderPackAccessor.java @@ -1,15 +1,15 @@ package net.coderbot.batchedentityrendering.mixin; import com.mojang.blaze3d.vertex.BufferBuilder; -import net.minecraft.client.renderer.ChunkBufferBuilderPack; +import net.minecraft.client.renderer.SectionBufferBuilderPack; import net.minecraft.client.renderer.RenderType; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; import java.util.Map; -@Mixin(ChunkBufferBuilderPack.class) -public interface ChunkBufferBuilderPackAccessor { +@Mixin(SectionBufferBuilderPack.class) +public interface SectionBufferBuilderPackAccessor { @Accessor Map getBuilders(); } diff --git a/src/main/java/net/coderbot/iris/gui/FeatureMissingErrorScreen.java b/src/main/java/net/coderbot/iris/gui/FeatureMissingErrorScreen.java index a3e2861861..b00c410a19 100644 --- a/src/main/java/net/coderbot/iris/gui/FeatureMissingErrorScreen.java +++ b/src/main/java/net/coderbot/iris/gui/FeatureMissingErrorScreen.java @@ -30,7 +30,7 @@ protected void init() { @Override public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) { - this.renderBackground(guiGraphics); + this.renderBackground(guiGraphics, mouseX, mouseY, delta); guiGraphics.drawCenteredString(this.font, this.title, this.width / 2, 90, 0xFFFFFF); message.renderCentered(guiGraphics, this.width / 2, 110, 9, 0xFFFFFF); super.render(guiGraphics, mouseX, mouseY, delta); diff --git a/src/main/java/net/coderbot/iris/gui/debug/DebugLoadFailedGridScreen.java b/src/main/java/net/coderbot/iris/gui/debug/DebugLoadFailedGridScreen.java index bd31623e34..f01fd9e664 100644 --- a/src/main/java/net/coderbot/iris/gui/debug/DebugLoadFailedGridScreen.java +++ b/src/main/java/net/coderbot/iris/gui/debug/DebugLoadFailedGridScreen.java @@ -56,14 +56,4 @@ protected void init() { widget.visitWidgets(this::addRenderableWidget); } - - @Override - public void render(GuiGraphics guiGraphics, int i, int j, float f) { - if (this.minecraft.level == null) { - this.renderBackground(guiGraphics); - } else { - guiGraphics.fillGradient(0, 0, width, height, 0x4F232323, 0x4F232323); - } - super.render(guiGraphics, i, j, f); - } } diff --git a/src/main/java/net/coderbot/iris/gui/screen/ShaderPackScreen.java b/src/main/java/net/coderbot/iris/gui/screen/ShaderPackScreen.java index a7149b2073..f55f27290c 100644 --- a/src/main/java/net/coderbot/iris/gui/screen/ShaderPackScreen.java +++ b/src/main/java/net/coderbot/iris/gui/screen/ShaderPackScreen.java @@ -108,7 +108,7 @@ public ShaderPackScreen(Screen parent) { @Override public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) { if (this.minecraft.level == null) { - this.renderBackground(guiGraphics); + this.renderBackground(guiGraphics, mouseX, mouseY, delta); } else if (!this.guiHidden) { guiGraphics.fillGradient(0, 0, width, height, 0x4F232323, 0x4F232323); } diff --git a/src/main/java/net/coderbot/iris/mixin/entity_render_context/MixinElytraLayer.java b/src/main/java/net/coderbot/iris/mixin/entity_render_context/MixinElytraLayer.java index ca2cc45da4..8851b67d33 100644 --- a/src/main/java/net/coderbot/iris/mixin/entity_render_context/MixinElytraLayer.java +++ b/src/main/java/net/coderbot/iris/mixin/entity_render_context/MixinElytraLayer.java @@ -41,8 +41,7 @@ public MixinElytraLayer(RenderLayerParent pRenderLayer0) { private void changeId(PoseStack pElytraLayer0, MultiBufferSource pMultiBufferSource1, int pInt2, T pLivingEntity3, float pFloat4, float pFloat5, float pFloat6, float pFloat7, float pFloat8, float pFloat9, CallbackInfo ci, ItemStack lvItemStack11, ResourceLocation lvResourceLocation12) { if (BlockRenderingSettings.INSTANCE.getItemIds() == null) return; - if (pLivingEntity3 instanceof AbstractClientPlayer player && player.isCapeLoaded() - && player.getCloakTextureLocation() != null + if (pLivingEntity3 instanceof AbstractClientPlayer player && player.getSkin().capeTexture() != null && player.isModelPartShown(PlayerModelPart.CAPE)) { CapturedRenderingState.INSTANCE.setCurrentRenderedItem(BlockRenderingSettings.INSTANCE.getItemIds().applyAsInt(ELYTRA_CAPE_LOCATION)); return; diff --git a/src/main/java/net/coderbot/iris/mixin/gui/MixinGui.java b/src/main/java/net/coderbot/iris/mixin/gui/MixinGui.java index 3a2b64d820..c9ac21f451 100644 --- a/src/main/java/net/coderbot/iris/mixin/gui/MixinGui.java +++ b/src/main/java/net/coderbot/iris/mixin/gui/MixinGui.java @@ -10,6 +10,7 @@ import net.minecraft.client.gui.Font; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.components.DebugScreenOverlay; import net.minecraft.client.gui.screens.Screen; import net.minecraft.world.entity.Entity; import org.spongepowered.asm.mixin.Final; @@ -26,6 +27,10 @@ public class MixinGui { @Shadow @Final private Minecraft minecraft; + @Shadow + @Final + private DebugScreenOverlay debugOverlay; + @Inject(method = "render", at = @At("HEAD"), cancellable = true) public void iris$handleHudHidingScreens(GuiGraphics pGui0, float pFloat1, CallbackInfo ci) { Screen screen = this.minecraft.screen; @@ -39,7 +44,7 @@ public class MixinGui { @Inject(method = "render", at = @At("RETURN")) public void iris$displayBigSodiumWarning(GuiGraphics guiGraphics, float pFloat1, CallbackInfo ci) { if (Iris.isSodiumInstalled() - || Minecraft.getInstance().options.renderDebug + || debugOverlay.showDebugScreen() || !Iris.getCurrentPack().isPresent()) { return; } diff --git a/src/main/java/net/coderbot/iris/mixin/shadows/ChunkInfoAccessor.java b/src/main/java/net/coderbot/iris/mixin/shadows/ChunkInfoAccessor.java deleted file mode 100644 index ec3933cc77..0000000000 --- a/src/main/java/net/coderbot/iris/mixin/shadows/ChunkInfoAccessor.java +++ /dev/null @@ -1,12 +0,0 @@ -package net.coderbot.iris.mixin.shadows; - -import net.minecraft.client.renderer.LevelRenderer; -import net.minecraft.client.renderer.chunk.ChunkRenderDispatcher; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -@Mixin(LevelRenderer.RenderChunkInfo.class) -public interface ChunkInfoAccessor { - @Accessor("chunk") - ChunkRenderDispatcher.RenderChunk getChunk(); -} diff --git a/src/main/java/net/coderbot/iris/mixin/shadows/MixinPreventRebuildNearInShadowPass.java b/src/main/java/net/coderbot/iris/mixin/shadows/MixinPreventRebuildNearInShadowPass.java index f45e5d9744..0d18f56c2c 100644 --- a/src/main/java/net/coderbot/iris/mixin/shadows/MixinPreventRebuildNearInShadowPass.java +++ b/src/main/java/net/coderbot/iris/mixin/shadows/MixinPreventRebuildNearInShadowPass.java @@ -6,6 +6,7 @@ import net.minecraft.client.Camera; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.LevelRenderer; +import net.minecraft.client.renderer.chunk.SectionRenderDispatcher; import net.minecraft.client.renderer.culling.Frustum; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -31,35 +32,15 @@ public abstract class MixinPreventRebuildNearInShadowPass { @Shadow @Final - private ObjectArrayList renderChunksInFrustum; + private ObjectArrayList visibleSections; - @Shadow - protected abstract void applyFrustum(Frustum frustum); - - @Group(name = "iris_MixinPreventRebuildNearInShadowPass", min = 1, max = 1) @Inject(method = "setupRender", - at = @At(value = "INVOKE", - target = "Ljava/util/concurrent/atomic/AtomicReference;get()Ljava/lang/Object;"), - cancellable = true, - require = 0) + at = @At(value = "TAIL")) private void iris$preventRebuildNearInShadowPass(Camera camera, Frustum frustum, boolean bl, boolean bl2, CallbackInfo ci) { if (ShadowRenderer.ACTIVE) { - for (LevelRenderer.RenderChunkInfo chunk : this.renderChunksInFrustum) { - ShadowRenderer.visibleBlockEntities.addAll(((ChunkInfoAccessor) chunk).getChunk().getCompiledChunk().getRenderableBlockEntities()); + for (SectionRenderDispatcher.RenderSection chunk : this.visibleSections) { + ShadowRenderer.visibleBlockEntities.addAll(chunk.getCompiled().getRenderableBlockEntities()); } - Minecraft.getInstance().getProfiler().pop(); - this.applyFrustum(frustum); - ci.cancel(); } } - - @Group(name = "iris_MixinPreventRebuildNearInShadowPass", min = 1, max = 1) - @Inject(method = "setupRender", - at = @At(value = "INVOKE", - target = "me/jellysquid/mods/sodium/client/gl/device/RenderDevice.enterManagedCode ()V", - remap = false), - require = 0) - private void iris$cannotInject(Camera camera, Frustum frustum, boolean bl, boolean bl2, CallbackInfo ci) { - // Dummy injection just to assert that either Sodium is present, or the vanilla injection passed. - } } diff --git a/src/main/java/net/coderbot/iris/mixin/vertices/block_rendering/MixinChunkRebuildTask.java b/src/main/java/net/coderbot/iris/mixin/vertices/block_rendering/MixinChunkRebuildTask.java index efaa9f2fb8..fc2849dead 100644 --- a/src/main/java/net/coderbot/iris/mixin/vertices/block_rendering/MixinChunkRebuildTask.java +++ b/src/main/java/net/coderbot/iris/mixin/vertices/block_rendering/MixinChunkRebuildTask.java @@ -7,10 +7,10 @@ import net.coderbot.iris.block_rendering.BlockRenderingSettings; import net.coderbot.iris.vertices.BlockSensitiveBufferBuilder; import net.coderbot.iris.vertices.ExtendedDataHelper; -import net.minecraft.client.renderer.ChunkBufferBuilderPack; +import net.minecraft.client.renderer.SectionBufferBuilderPack; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.block.BlockRenderDispatcher; -import net.minecraft.client.renderer.chunk.ChunkRenderDispatcher; +import net.minecraft.client.renderer.chunk.SectionRenderDispatcher; import net.minecraft.client.renderer.chunk.RenderChunkRegion; import net.minecraft.client.renderer.chunk.VisGraph; import net.minecraft.core.BlockPos; @@ -34,9 +34,9 @@ * * Uses a priority of 999 so that we apply before Indigo's mixins. */ -@Mixin(targets = "net.minecraft.client.renderer.chunk.ChunkRenderDispatcher$RenderChunk$RebuildTask", priority = 999) +@Mixin(targets = "net.minecraft.client.renderer.chunk.SectionRenderDispatcher$RenderSection$RebuildTask", priority = 999) public class MixinChunkRebuildTask { - private static final String RENDER = "Lnet/minecraft/client/renderer/chunk/ChunkRenderDispatcher$RenderChunk$RebuildTask;compile(FFFLnet/minecraft/client/renderer/ChunkBufferBuilderPack;)Lnet/minecraft/client/renderer/chunk/ChunkRenderDispatcher$RenderChunk$RebuildTask$CompileResults;"; + private static final String RENDER = "Lnet/minecraft/client/renderer/chunk/SectionRenderDispatcher$RenderSection$RebuildTask;compile(FFFLnet/minecraft/client/renderer/SectionBufferBuilderPack;)Lnet/minecraft/client/renderer/chunk/SectionRenderDispatcher$RenderSection$RebuildTask$CompileResults;"; @Unique private BlockSensitiveBufferBuilder lastBufferBuilder; @@ -60,7 +60,7 @@ private short resolveBlockId(BlockState state) { } @Inject(method = RENDER, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/block/BlockRenderDispatcher;renderLiquid(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/BlockAndTintGetter;Lcom/mojang/blaze3d/vertex/VertexConsumer;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/material/FluidState;)V"), locals = LocalCapture.CAPTURE_FAILHARD) - private void iris$onRenderLiquid(float cameraX, float cameraY, float cameraZ, ChunkBufferBuilderPack buffers, CallbackInfoReturnable cir, ChunkRenderDispatcher.RenderChunk.RebuildTask.CompileResults results,int i, BlockPos blockPos, BlockPos blockPos2, VisGraph chunkOcclusionDataBuilder,RenderChunkRegion chunkRendererRegion, PoseStack poseStack, Set set2, RandomSource random, BlockRenderDispatcher blockRenderManager, Iterator var15, BlockPos blockPos3, BlockState blockState, BlockState state2, FluidState fluidState, RenderType renderType, BufferBuilder bufferBuilder2) { + private void iris$onRenderLiquid(float cameraX, float cameraY, float cameraZ, SectionBufferBuilderPack buffers, CallbackInfoReturnable cir, SectionRenderDispatcher.RenderSection.RebuildTask.CompileResults results,int i, BlockPos blockPos, BlockPos blockPos2, VisGraph chunkOcclusionDataBuilder, RenderChunkRegion chunkRendererRegion, PoseStack poseStack, Set set2, RandomSource random, BlockRenderDispatcher blockRenderManager, Iterator var15, BlockPos blockPos3, BlockState blockState, FluidState fluidState, RenderType renderType, BufferBuilder bufferBuilder2) { if (bufferBuilder2 instanceof BlockSensitiveBufferBuilder) { lastBufferBuilder = ((BlockSensitiveBufferBuilder) bufferBuilder2); // All fluids have a ShadersMod render type of 1, to match behavior of Minecraft 1.7 and earlier. @@ -70,7 +70,7 @@ private short resolveBlockId(BlockState state) { } @Inject(method = RENDER, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/block/BlockRenderDispatcher;renderLiquid(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/BlockAndTintGetter;Lcom/mojang/blaze3d/vertex/VertexConsumer;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/material/FluidState;)V", shift = At.Shift.AFTER)) - private void iris$finishRenderingLiquid(float cameraX, float cameraY, float cameraZ, ChunkBufferBuilderPack buffers, CallbackInfoReturnable cir) { + private void iris$finishRenderingLiquid(float cameraX, float cameraY, float cameraZ, SectionBufferBuilderPack buffers, CallbackInfoReturnable cir) { if (lastBufferBuilder != null) { lastBufferBuilder.endBlock(); lastBufferBuilder = null; @@ -78,7 +78,7 @@ private short resolveBlockId(BlockState state) { } @Inject(method = RENDER, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/block/BlockRenderDispatcher;renderBatched(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/BlockAndTintGetter;Lcom/mojang/blaze3d/vertex/PoseStack;Lcom/mojang/blaze3d/vertex/VertexConsumer;ZLnet/minecraft/util/RandomSource;)V"), locals = LocalCapture.CAPTURE_FAILHARD) - private void iris$onRenderBlock(float cameraX, float cameraY, float cameraZ, ChunkBufferBuilderPack buffers, CallbackInfoReturnable cir, ChunkRenderDispatcher.RenderChunk.RebuildTask.CompileResults results, int i, BlockPos blockPos, BlockPos blockPos2, VisGraph chunkOcclusionDataBuilder,RenderChunkRegion chunkRendererRegion, PoseStack poseStack, Set set2, RandomSource random, BlockRenderDispatcher blockRenderManager, Iterator var15, BlockPos blockPos3, BlockState blockState, BlockState state2, FluidState fluidState, RenderType renderType2, BufferBuilder bufferBuilder2) { + private void iris$onRenderBlock(float cameraX, float cameraY, float cameraZ, SectionBufferBuilderPack buffers, CallbackInfoReturnable cir, SectionRenderDispatcher.RenderSection.RebuildTask.CompileResults results, int i, BlockPos blockPos, BlockPos blockPos2, VisGraph chunkOcclusionDataBuilder,RenderChunkRegion chunkRendererRegion, PoseStack poseStack, Set set2, RandomSource random, BlockRenderDispatcher blockRenderManager, Iterator var15, BlockPos blockPos3, BlockState blockState, FluidState fluidState, RenderType renderType2, BufferBuilder bufferBuilder2) { if (bufferBuilder2 instanceof BlockSensitiveBufferBuilder) { lastBufferBuilder = ((BlockSensitiveBufferBuilder) bufferBuilder2); // TODO: Resolve render types for normal blocks? @@ -87,7 +87,7 @@ private short resolveBlockId(BlockState state) { } @Inject(method = RENDER, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/block/BlockRenderDispatcher;renderBatched(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/BlockAndTintGetter;Lcom/mojang/blaze3d/vertex/PoseStack;Lcom/mojang/blaze3d/vertex/VertexConsumer;ZLnet/minecraft/util/RandomSource;)V", shift = At.Shift.AFTER)) - private void iris$finishRenderingBlock(float cameraX, float cameraY, float cameraZ, ChunkBufferBuilderPack buffers, CallbackInfoReturnable cir) { + private void iris$finishRenderingBlock(float cameraX, float cameraY, float cameraZ, SectionBufferBuilderPack buffers, CallbackInfoReturnable cir) { if (lastBufferBuilder != null) { lastBufferBuilder.endBlock(); lastBufferBuilder = null; diff --git a/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java b/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java index 721f3ce467..427aa36a10 100644 --- a/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java +++ b/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java @@ -544,7 +544,7 @@ public void renderShadows(LevelRendererAccessor levelRenderer, Camera playerCame IrisRenderSystem.restorePlayerProjection(); - debugStringTerrain = ((LevelRenderer) levelRenderer).getChunkStatistics(); + debugStringTerrain = ((LevelRenderer) levelRenderer).getSectionStatistics(); levelRenderer.getLevel().getProfiler().popPush("generate mipmaps"); diff --git a/src/main/java/net/coderbot/iris/texture/pbr/loader/AtlasPBRLoader.java b/src/main/java/net/coderbot/iris/texture/pbr/loader/AtlasPBRLoader.java index 8c6ddb3223..4049aed258 100644 --- a/src/main/java/net/coderbot/iris/texture/pbr/loader/AtlasPBRLoader.java +++ b/src/main/java/net/coderbot/iris/texture/pbr/loader/AtlasPBRLoader.java @@ -22,6 +22,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.server.packs.resources.Resource; import net.minecraft.server.packs.resources.ResourceManager; +import net.minecraft.server.packs.resources.ResourceMetadata; import net.minecraft.util.Mth; import org.jetbrains.annotations.Nullable; @@ -90,9 +91,9 @@ protected PBRTextureAtlasSprite createPBRSprite(TextureAtlasSprite sprite, Resou } Resource resource = optionalResource.get(); - AnimationMetadataSection animationMetadata; + ResourceMetadata animationMetadata; try { - animationMetadata = resource.metadata().getSection(AnimationMetadataSection.SERIALIZER).orElse(AnimationMetadataSection.EMPTY); + animationMetadata = resource.metadata(); } catch (Exception e) { Iris.logger.error("Unable to parse metadata from {}", pbrImageLocation, e); return null; @@ -108,7 +109,7 @@ protected PBRTextureAtlasSprite createPBRSprite(TextureAtlasSprite sprite, Resou int imageWidth = nativeImage.getWidth(); int imageHeight = nativeImage.getHeight(); - FrameSize frameSize = animationMetadata.calculateFrameSize(imageWidth, imageHeight); + FrameSize frameSize = animationMetadata.getSection(AnimationMetadataSection.SERIALIZER).orElse(AnimationMetadataSection.EMPTY).calculateFrameSize(imageWidth, imageHeight); int frameWidth = frameSize.width(); int frameHeight = frameSize.height(); if (!Mth.isMultipleOf(imageWidth, frameWidth) || !Mth.isMultipleOf(imageHeight, frameHeight)) { @@ -168,7 +169,7 @@ protected ResourceLocation getPBRImageLocation(ResourceLocation spriteName, PBRT protected static class PBRSpriteContents extends SpriteContents implements CustomMipmapGenerator.Provider { protected final PBRType pbrType; - public PBRSpriteContents(ResourceLocation name, FrameSize size, NativeImage image, AnimationMetadataSection metadata, PBRType pbrType) { + public PBRSpriteContents(ResourceLocation name, FrameSize size, NativeImage image, ResourceMetadata metadata, PBRType pbrType) { super(name, size, image, metadata); this.pbrType = pbrType; } diff --git a/src/main/resources/iris-batched-entity-rendering.mixins.json b/src/main/resources/iris-batched-entity-rendering.mixins.json index a631e9714e..5f54654b42 100644 --- a/src/main/resources/iris-batched-entity-rendering.mixins.json +++ b/src/main/resources/iris-batched-entity-rendering.mixins.json @@ -4,7 +4,7 @@ "package": "net.coderbot.batchedentityrendering.mixin", "compatibilityLevel": "JAVA_8", "client": [ - "ChunkBufferBuilderPackAccessor", + "SectionBufferBuilderPackAccessor", "OutlineBufferSourceAccessor", "MixinBufferBuilder", "MixinBufferBuilder_SegmentRendering", diff --git a/src/main/resources/iris.accesswidener b/src/main/resources/iris.accesswidener index edaf35905d..9263dbd754 100644 --- a/src/main/resources/iris.accesswidener +++ b/src/main/resources/iris.accesswidener @@ -17,9 +17,9 @@ accessible class net/minecraft/client/renderer/texture/SpriteContents$FrameInfo accessible class net/minecraft/client/renderer/texture/SpriteContents$Ticker accessible class net/minecraft/client/OptionInstance$ValueSet extendable class net/minecraft/client/OptionInstance -accessible class net/minecraft/client/renderer/chunk/ChunkRenderDispatcher$RenderChunk$RebuildTask +accessible class net/minecraft/client/renderer/chunk/SectionRenderDispatcher$RenderSection$RebuildTask extendable class net/minecraft/core/RegistryAccess$RegistryEntry -accessible class net/minecraft/client/renderer/chunk/ChunkRenderDispatcher$RenderChunk$RebuildTask$CompileResults +accessible class net/minecraft/client/renderer/chunk/SectionRenderDispatcher$RenderSection$RebuildTask$CompileResults accessible method net/minecraft/client/renderer/RenderType create (Ljava/lang/String;Lcom/mojang/blaze3d/vertex/VertexFormat;Lcom/mojang/blaze3d/vertex/VertexFormat$Mode;IZZLnet/minecraft/client/renderer/RenderType$CompositeState;)Lnet/minecraft/client/renderer/RenderType$CompositeRenderType; accessible field com/mojang/blaze3d/platform/NativeImage pixels J mutable field net/minecraft/client/renderer/ShaderInstance PROJECTION_MATRIX Lcom/mojang/blaze3d/shaders/Uniform; diff --git a/src/main/resources/mixins.iris.json b/src/main/resources/mixins.iris.json index 9f9e1ab27b..8ac286a560 100644 --- a/src/main/resources/mixins.iris.json +++ b/src/main/resources/mixins.iris.json @@ -68,7 +68,6 @@ "rendertype.RenderTypeAccessor", "rendertype.RenderStateShardAccessor", "rendertype.RenderTypeAccessor", - "shadows.ChunkInfoAccessor", "shadows.MixinBeaconRenderer", "shadows.MixinLevelRenderer", "shadows.MixinPreventRebuildNearInShadowPass", From c3037b61481805d48791799817d114262a172c0d Mon Sep 17 00:00:00 2001 From: IMS212 Date: Mon, 11 Sep 2023 10:06:36 -0700 Subject: [PATCH 02/56] one --- .../net/coderbot/iris/gui/OldImageButton.java | 95 +++++++++++++++++++ .../iris/gui/screen/ShaderPackScreen.java | 3 +- 2 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 src/main/java/net/coderbot/iris/gui/OldImageButton.java diff --git a/src/main/java/net/coderbot/iris/gui/OldImageButton.java b/src/main/java/net/coderbot/iris/gui/OldImageButton.java new file mode 100644 index 0000000000..f95ae5cf88 --- /dev/null +++ b/src/main/java/net/coderbot/iris/gui/OldImageButton.java @@ -0,0 +1,95 @@ +package net.coderbot.iris.gui; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.components.Button; +import net.minecraft.network.chat.CommonComponents; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; + +@Environment(EnvType.CLIENT) +public class OldImageButton extends Button { + protected final ResourceLocation resourceLocation; + protected final int xTexStart; + protected final int yTexStart; + protected final int yDiffTex; + protected final int textureWidth; + protected final int textureHeight; + + public OldImageButton( + int pImageButton0, int pInt1, int pInt2, int pInt3, int pInt4, int pInt5, ResourceLocation pResourceLocation6, Button.OnPress pButton$OnPress7 + ) { + this(pImageButton0, pInt1, pInt2, pInt3, pInt4, pInt5, pInt3, pResourceLocation6, 256, 256, pButton$OnPress7); + } + + public OldImageButton( + int pImageButton0, + int pInt1, + int pInt2, + int pInt3, + int pInt4, + int pInt5, + int pInt6, + ResourceLocation pResourceLocation7, + Button.OnPress pButton$OnPress8 + ) { + this(pImageButton0, pInt1, pInt2, pInt3, pInt4, pInt5, pInt6, pResourceLocation7, 256, 256, pButton$OnPress8); + } + + public OldImageButton( + int pImageButton0, + int pInt1, + int pInt2, + int pInt3, + int pInt4, + int pInt5, + int pInt6, + ResourceLocation pResourceLocation7, + int pInt8, + int pInt9, + Button.OnPress pButton$OnPress10 + ) { + this(pImageButton0, pInt1, pInt2, pInt3, pInt4, pInt5, pInt6, pResourceLocation7, pInt8, pInt9, pButton$OnPress10, CommonComponents.EMPTY); + } + + public OldImageButton( + int pImageButton0, + int pInt1, + int pInt2, + int pInt3, + int pInt4, + int pInt5, + int pInt6, + ResourceLocation pResourceLocation7, + int pInt8, + int pInt9, + Button.OnPress pButton$OnPress10, + Component pComponent11 + ) { + super(pImageButton0, pInt1, pInt2, pInt3, pComponent11, pButton$OnPress10, DEFAULT_NARRATION); + this.textureWidth = pInt8; + this.textureHeight = pInt9; + this.xTexStart = pInt4; + this.yTexStart = pInt5; + this.yDiffTex = pInt6; + this.resourceLocation = pResourceLocation7; + } + + @Override + public void renderWidget(GuiGraphics pImageButton0, int pInt1, int pInt2, float pFloat3) { + this.renderTexture( + pImageButton0, + this.resourceLocation, + this.getX(), + this.getY(), + this.xTexStart, + this.yTexStart, + this.yDiffTex, + this.width, + this.height, + this.textureWidth, + this.textureHeight + ); + } +} diff --git a/src/main/java/net/coderbot/iris/gui/screen/ShaderPackScreen.java b/src/main/java/net/coderbot/iris/gui/screen/ShaderPackScreen.java index f55f27290c..808abd255e 100644 --- a/src/main/java/net/coderbot/iris/gui/screen/ShaderPackScreen.java +++ b/src/main/java/net/coderbot/iris/gui/screen/ShaderPackScreen.java @@ -5,6 +5,7 @@ import net.coderbot.iris.Iris; import net.coderbot.iris.gui.GuiUtil; import net.coderbot.iris.gui.NavigationController; +import net.coderbot.iris.gui.OldImageButton; import net.coderbot.iris.gui.element.ShaderPackOptionList; import net.coderbot.iris.gui.element.ShaderPackSelectionList; import net.coderbot.iris.gui.element.widget.AbstractElementWidget; @@ -284,7 +285,7 @@ protected void init() { x = (int) (endOfLastButton + (freeSpace / 2.0f)) - 10; } - ImageButton showHideButton = new ImageButton( + OldImageButton showHideButton = new OldImageButton( x, this.height - 39, 20, 20, this.guiHidden ? 20 : 0, 146, 20, From d8f78e901508262241694e0f1e5d397b2424e3e8 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Mon, 11 Sep 2023 10:18:57 -0700 Subject: [PATCH 03/56] Fix crashes --- buildscript/src/main/java/Buildscript.java | 7 ++-- .../net/coderbot/iris/gui/OldImageButton.java | 25 ++++++++++++ .../iris/mixin/LevelRendererAccessor.java | 5 +-- .../iris/mixin/MixinClientPacketListener.java | 9 ++--- .../iris/mixin/MixinLevelRenderer.java | 4 +- .../MixinMinecraft_PipelineManagement.java | 2 +- .../entity_render_context/MixinCapeLayer.java | 3 +- .../mixin/shadows/MixinLevelRenderer.java | 39 ++----------------- .../iris/pipeline/ShadowRenderer.java | 14 ++----- 9 files changed, 46 insertions(+), 62 deletions(-) diff --git a/buildscript/src/main/java/Buildscript.java b/buildscript/src/main/java/Buildscript.java index af6aedbd73..4561163bd2 100644 --- a/buildscript/src/main/java/Buildscript.java +++ b/buildscript/src/main/java/Buildscript.java @@ -44,9 +44,9 @@ public class Buildscript extends SimpleFabricProject { static final boolean SODIUM = true; - static final boolean CUSTOM_SODIUM = false; + static final boolean CUSTOM_SODIUM = true; static final String MC_VERSION = "1.20.2-pre2"; - static final String customSodiumName = "sodium-fabric-mc1.20.1-0.5.1-beta1.jar"; + static final String customSodiumName = "sodium-fabric-mc1.20.2-pre1-0.5.2+git.d9371a4-dirty.jar"; private static final String[] SOURCE_SETS = new String[] { "main", @@ -106,7 +106,8 @@ public void getModDependencies(ModDependencyCollector d) { d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", "fabric-api-base", "0.4.17+93d8cb8253"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", "fabric-rendering-data-attachment-v1", "0.3.21+12bfe4ea53"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", "fabric-rendering-fluids-v1", "3.0.13+fbde993d53"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); - d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", "fabric-resource-loader-v0", "0.10.8+12a6ba2c17"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); + d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", "fabric-resource-loader-v0", "0.11.10+86b1264599"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); + d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", "fabric-block-view-api-v2", "1.0.0+73761d2e99"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); if (CUSTOM_SODIUM) { d.add(new JavaJarDependency(getProjectDir().resolve("custom_sodium").resolve(customSodiumName).toAbsolutePath(), null, new MavenId("me.jellysquid.mods", "sodium-fabric", customSodiumName.replace("sodium-fabric-", ""))), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); diff --git a/src/main/java/net/coderbot/iris/gui/OldImageButton.java b/src/main/java/net/coderbot/iris/gui/OldImageButton.java index f95ae5cf88..91611ddc82 100644 --- a/src/main/java/net/coderbot/iris/gui/OldImageButton.java +++ b/src/main/java/net/coderbot/iris/gui/OldImageButton.java @@ -1,5 +1,6 @@ package net.coderbot.iris.gui; +import com.mojang.blaze3d.systems.RenderSystem; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.gui.GuiGraphics; @@ -92,4 +93,28 @@ public void renderWidget(GuiGraphics pImageButton0, int pInt1, int pInt2, float this.textureHeight ); } + + public void renderTexture( + GuiGraphics pAbstractWidget0, + ResourceLocation pResourceLocation1, + int pInt2, + int pInt3, + int pInt4, + int pInt5, + int pInt6, + int pInt7, + int pInt8, + int pInt9, + int pInt10 + ) { + int lvInt12 = pInt5; + if (!this.isActive()) { + lvInt12 = pInt5 + pInt6 * 2; + } else if (this.isHoveredOrFocused()) { + lvInt12 = pInt5 + pInt6; + } + + RenderSystem.enableDepthTest(); + pAbstractWidget0.blit(pResourceLocation1, pInt2, pInt3, (float)pInt4, (float)lvInt12, pInt7, pInt8, pInt9, pInt10); + } } diff --git a/src/main/java/net/coderbot/iris/mixin/LevelRendererAccessor.java b/src/main/java/net/coderbot/iris/mixin/LevelRendererAccessor.java index 5ee95095aa..ee51d5cd0a 100644 --- a/src/main/java/net/coderbot/iris/mixin/LevelRendererAccessor.java +++ b/src/main/java/net/coderbot/iris/mixin/LevelRendererAccessor.java @@ -1,7 +1,6 @@ package net.coderbot.iris.mixin; import com.mojang.blaze3d.vertex.PoseStack; -import it.unimi.dsi.fastutil.objects.ObjectList; import net.minecraft.client.Camera; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.renderer.LevelRenderer; @@ -21,8 +20,8 @@ public interface LevelRendererAccessor { @Accessor("entityRenderDispatcher") EntityRenderDispatcher getEntityRenderDispatcher(); - @Invoker("renderChunkLayer") - void invokeRenderChunkLayer(RenderType terrainLayer, PoseStack modelView, double cameraX, double cameraY, double cameraZ, Matrix4f projectionMatrix); + @Invoker("renderSectionLayer") + void invokeRenderSectionLayer(RenderType terrainLayer, PoseStack modelView, double cameraX, double cameraY, double cameraZ, Matrix4f projectionMatrix); @Invoker("setupRender") void invokeSetupRender(Camera camera, Frustum frustum, boolean hasForcedFrustum, boolean spectator); diff --git a/src/main/java/net/coderbot/iris/mixin/MixinClientPacketListener.java b/src/main/java/net/coderbot/iris/mixin/MixinClientPacketListener.java index e3e9e0a91a..3b4fce9838 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinClientPacketListener.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinClientPacketListener.java @@ -16,19 +16,16 @@ @Mixin(ClientPacketListener.class) public class MixinClientPacketListener { - @Shadow - private Minecraft minecraft; - @Inject(method = "handleLogin", at = @At("TAIL")) private void iris$showUpdateMessage(ClientboundLoginPacket a, CallbackInfo ci) { - if (this.minecraft.player == null) { + if (Minecraft.getInstance().player == null) { return; } Iris.getUpdateChecker().getUpdateMessage().ifPresent(msg -> - this.minecraft.player.displayClientMessage(msg, false)); + Minecraft.getInstance().player.displayClientMessage(msg, false)); Iris.getStoredError().ifPresent(e -> - this.minecraft.player.displayClientMessage(Component.translatable(e instanceof ShaderCompileException ? "iris.load.failure.shader" : "iris.load.failure.generic").append(Component.literal("Copy Info").withStyle(arg -> arg.withUnderlined(true).withColor(ChatFormatting.BLUE).withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, e.getMessage())))), false)); + Minecraft.getInstance().player.displayClientMessage(Component.translatable(e instanceof ShaderCompileException ? "iris.load.failure.shader" : "iris.load.failure.generic").append(Component.literal("Copy Info").withStyle(arg -> arg.withUnderlined(true).withColor(ChatFormatting.BLUE).withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, e.getMessage())))), false)); } } diff --git a/src/main/java/net/coderbot/iris/mixin/MixinLevelRenderer.java b/src/main/java/net/coderbot/iris/mixin/MixinLevelRenderer.java index bd4bc232f5..cc40ed1c78 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinLevelRenderer.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinLevelRenderer.java @@ -198,12 +198,12 @@ public class MixinLevelRenderer { } - @Inject(method = "renderChunkLayer", at = @At("HEAD")) + @Inject(method = "renderSectionLayer", at = @At("HEAD")) private void iris$beginTerrainLayer(RenderType renderType, PoseStack poseStack, double d, double e, double f, Matrix4f projectionMatrix, CallbackInfo ci) { pipeline.setPhase(WorldRenderingPhase.fromTerrainRenderType(renderType)); } - @Inject(method = "renderChunkLayer", at = @At("RETURN")) + @Inject(method = "renderSectionLayer", at = @At("RETURN")) private void iris$endTerrainLayer(RenderType renderType, PoseStack poseStack, double d, double e, double f, Matrix4f projectionMatrix, CallbackInfo ci) { pipeline.setPhase(WorldRenderingPhase.NONE); } diff --git a/src/main/java/net/coderbot/iris/mixin/MixinMinecraft_PipelineManagement.java b/src/main/java/net/coderbot/iris/mixin/MixinMinecraft_PipelineManagement.java index d35576ea3f..7804295e3f 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinMinecraft_PipelineManagement.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinMinecraft_PipelineManagement.java @@ -18,7 +18,7 @@ public class MixinMinecraft_PipelineManagement { /** * Should run before the Minecraft.level field is updated after disconnecting from a server or leaving a singleplayer world */ - @Inject(method = "clearLevel(Lnet/minecraft/client/gui/screens/Screen;)V", at = @At("HEAD")) + @Inject(method = "clearClientLevel", at = @At("HEAD")) public void iris$trackLastDimensionOnLeave(Screen arg, CallbackInfo ci) { Iris.lastDimension = Iris.getCurrentDimension(); } diff --git a/src/main/java/net/coderbot/iris/mixin/entity_render_context/MixinCapeLayer.java b/src/main/java/net/coderbot/iris/mixin/entity_render_context/MixinCapeLayer.java index 0f69a4b5fb..c543eb46f1 100644 --- a/src/main/java/net/coderbot/iris/mixin/entity_render_context/MixinCapeLayer.java +++ b/src/main/java/net/coderbot/iris/mixin/entity_render_context/MixinCapeLayer.java @@ -7,6 +7,7 @@ import net.minecraft.client.player.AbstractClientPlayer; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.entity.layers.CapeLayer; +import net.minecraft.client.resources.PlayerSkin; import net.minecraft.core.Registry; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; @@ -22,7 +23,7 @@ public class MixinCapeLayer { private static final NamespacedId CAPE_LOCATION = new NamespacedId("minecraft", "player_cape"); @Inject(method = "render(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;ILnet/minecraft/client/player/AbstractClientPlayer;FFFFFF)V", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;pushPose()V"), locals = LocalCapture.CAPTURE_FAILHARD) - private void changeId(PoseStack pCapeLayer0, MultiBufferSource pMultiBufferSource1, int pInt2, AbstractClientPlayer pAbstractClientPlayer3, float pFloat4, float pFloat5, float pFloat6, float pFloat7, float pFloat8, float pFloat9, CallbackInfo ci, ItemStack lvItemStack11) { + private void changeId(PoseStack pCapeLayer0, MultiBufferSource pMultiBufferSource1, int pInt2, AbstractClientPlayer pAbstractClientPlayer3, float pFloat4, float pFloat5, float pFloat6, float pFloat7, float pFloat8, float pFloat9, CallbackInfo ci, PlayerSkin lvPlayerSkin11, ItemStack lvItemStack12) { if (BlockRenderingSettings.INSTANCE.getItemIds() == null) return; CapturedRenderingState.INSTANCE.setCurrentRenderedItem(BlockRenderingSettings.INSTANCE.getItemIds().applyAsInt(CAPE_LOCATION)); diff --git a/src/main/java/net/coderbot/iris/mixin/shadows/MixinLevelRenderer.java b/src/main/java/net/coderbot/iris/mixin/shadows/MixinLevelRenderer.java index 03e9529029..704084fc65 100644 --- a/src/main/java/net/coderbot/iris/mixin/shadows/MixinLevelRenderer.java +++ b/src/main/java/net/coderbot/iris/mixin/shadows/MixinLevelRenderer.java @@ -14,25 +14,11 @@ public class MixinLevelRenderer implements CullingDataCache { @Shadow @Final @Mutable - private ObjectArrayList renderChunksInFrustum; + private ObjectArrayList visibleSections; @Unique private ObjectArrayList savedRenderChunks = new ObjectArrayList(69696); - @Shadow - private boolean needsFullRenderChunkUpdate; - - @Unique - private boolean savedNeedsTerrainUpdate; - - @Shadow - private double lastCameraX; - - @Shadow - private double lastCameraY; - - @Shadow - private double lastCameraZ; @Shadow private double prevCamRotX; @@ -67,30 +53,11 @@ public void restoreState() { @Unique private void swap() { - ObjectArrayList tmpList = renderChunksInFrustum; - renderChunksInFrustum = savedRenderChunks; + ObjectArrayList tmpList = visibleSections; + visibleSections = savedRenderChunks; savedRenderChunks = tmpList; - - // TODO: If the normal chunks need a terrain update, these chunks probably do too... - // We probably should copy it over - boolean tmpBool = needsFullRenderChunkUpdate; - needsFullRenderChunkUpdate = savedNeedsTerrainUpdate; - savedNeedsTerrainUpdate = tmpBool; - double tmp; - tmp = lastCameraX; - lastCameraX = savedLastCameraX; - savedLastCameraX = tmp; - - tmp = lastCameraY; - lastCameraY = savedLastCameraY; - savedLastCameraY = tmp; - - tmp = lastCameraZ; - lastCameraZ = savedLastCameraZ; - savedLastCameraZ = tmp; - tmp = prevCamRotX; prevCamRotX = savedLastCameraPitch; savedLastCameraPitch = tmp; diff --git a/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java b/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java index 427aa36a10..79b69b908a 100644 --- a/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java +++ b/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java @@ -11,19 +11,14 @@ import net.coderbot.batchedentityrendering.impl.RenderBuffersExt; import net.coderbot.iris.Iris; import net.coderbot.iris.gl.IrisRenderSystem; -import net.coderbot.iris.gl.program.ComputeProgram; -import net.coderbot.iris.gl.texture.DepthCopyStrategy; import net.coderbot.iris.gui.option.IrisVideoSettings; import net.coderbot.iris.mixin.LevelRendererAccessor; -import net.coderbot.iris.shaderpack.ComputeSource; -import net.coderbot.iris.shaderpack.OptionalBoolean; import net.coderbot.iris.shaderpack.PackDirectives; import net.coderbot.iris.shaderpack.PackShadowDirectives; import net.coderbot.iris.shaderpack.ProgramSource; import net.coderbot.iris.shaderpack.ShadowCullState; import net.coderbot.iris.shadows.ShadowMatrices; import net.coderbot.iris.shadows.CullingDataCache; -import net.coderbot.iris.shadows.Matrix4fAccess; import net.coderbot.iris.shadows.ShadowCompositeRenderer; import net.coderbot.iris.shadows.ShadowRenderTargets; import net.coderbot.iris.shadows.ShadowRenderingState; @@ -57,7 +52,6 @@ import org.lwjgl.opengl.ARBTextureSwizzle; import org.lwjgl.opengl.GL20C; import org.lwjgl.opengl.GL30C; -import org.lwjgl.opengl.GL43C; import java.util.ArrayList; import java.util.Comparator; @@ -460,9 +454,9 @@ public void renderShadows(LevelRendererAccessor levelRenderer, Camera playerCame // Render all opaque terrain unless pack requests not to if (shouldRenderTerrain) { - levelRenderer.invokeRenderChunkLayer(RenderType.solid(), modelView, cameraX, cameraY, cameraZ, shadowProjection); - levelRenderer.invokeRenderChunkLayer(RenderType.cutout(), modelView, cameraX, cameraY, cameraZ, shadowProjection); - levelRenderer.invokeRenderChunkLayer(RenderType.cutoutMipped(), modelView, cameraX, cameraY, cameraZ, shadowProjection); + levelRenderer.invokeRenderSectionLayer(RenderType.solid(), modelView, cameraX, cameraY, cameraZ, shadowProjection); + levelRenderer.invokeRenderSectionLayer(RenderType.cutout(), modelView, cameraX, cameraY, cameraZ, shadowProjection); + levelRenderer.invokeRenderSectionLayer(RenderType.cutoutMipped(), modelView, cameraX, cameraY, cameraZ, shadowProjection); } // Reset our viewport in case Sodium overrode it @@ -532,7 +526,7 @@ public void renderShadows(LevelRendererAccessor levelRenderer, Camera playerCame // It doesn't matter a ton, since this just means that they won't be sorted in the normal rendering pass. // Just something to watch out for, however... if (shouldRenderTranslucent) { - levelRenderer.invokeRenderChunkLayer(RenderType.translucent(), modelView, cameraX, cameraY, cameraZ, shadowProjection); + levelRenderer.invokeRenderSectionLayer(RenderType.translucent(), modelView, cameraX, cameraY, cameraZ, shadowProjection); } // Note: Apparently tripwire isn't rendered in the shadow pass. From a5397dd879a9ac3837d37be5e9a5750948e6732d Mon Sep 17 00:00:00 2001 From: IMS212 Date: Mon, 11 Sep 2023 10:24:13 -0700 Subject: [PATCH 04/56] Finally fix all the issues --- .../iris/gui/element/ShaderPackOptionList.java | 15 +++++++++++++++ .../gui/element/ShaderPackSelectionList.java | 16 ++++++++++++++++ .../iris/gui/screen/ShaderPackScreen.java | 5 +++++ 3 files changed, 36 insertions(+) diff --git a/src/main/java/net/coderbot/iris/gui/element/ShaderPackOptionList.java b/src/main/java/net/coderbot/iris/gui/element/ShaderPackOptionList.java index 3fbbbe2cc3..9df2e00650 100644 --- a/src/main/java/net/coderbot/iris/gui/element/ShaderPackOptionList.java +++ b/src/main/java/net/coderbot/iris/gui/element/ShaderPackOptionList.java @@ -23,6 +23,7 @@ import net.minecraft.client.gui.navigation.ScreenDirection; import net.minecraft.client.gui.navigation.ScreenRectangle; import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.renderer.RenderType; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.network.chat.TextColor; @@ -53,6 +54,20 @@ public ShaderPackOptionList(ShaderPackScreen screen, NavigationController naviga applyShaderPack(pack); } + @Override + protected void renderDecorations(GuiGraphics pAbstractSelectionList0, int pInt1, int pInt2) { + // Renders top/bottom dirt + int lvInt9 = 32; + pAbstractSelectionList0.setColor(0.25F, 0.25F, 0.25F, 1.0F); + pAbstractSelectionList0.blit(Screen.BACKGROUND_LOCATION, this.x0, 0, 0.0F, 0.0F, this.width, this.y0, 32, 32); + pAbstractSelectionList0.blit(Screen.BACKGROUND_LOCATION, this.x0, this.y1, 0.0F, (float)this.y1, this.width, this.height - this.y1, 32, 32); + pAbstractSelectionList0.setColor(1.0F, 1.0F, 1.0F, 1.0F); + int lvInt10 = 4; + pAbstractSelectionList0.fillGradient(RenderType.guiOverlay(), this.x0, this.y0, this.x1, this.y0 + 4, -16777216, 0, 0); + pAbstractSelectionList0.fillGradient(RenderType.guiOverlay(), this.x0, this.y1 - 4, this.x1, this.y1, 0, -16777216, 0); + super.renderDecorations(pAbstractSelectionList0, pInt1, pInt2); + } + public void applyShaderPack(ShaderPack pack) { this.container = pack.getMenuContainer(); } diff --git a/src/main/java/net/coderbot/iris/gui/element/ShaderPackSelectionList.java b/src/main/java/net/coderbot/iris/gui/element/ShaderPackSelectionList.java index dbd6d4ee4e..e2cbdebbc4 100644 --- a/src/main/java/net/coderbot/iris/gui/element/ShaderPackSelectionList.java +++ b/src/main/java/net/coderbot/iris/gui/element/ShaderPackSelectionList.java @@ -19,6 +19,8 @@ import net.minecraft.client.gui.narration.NarratableEntry; import net.minecraft.client.gui.navigation.FocusNavigationEvent; import net.minecraft.client.gui.navigation.ScreenRectangle; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.renderer.RenderType; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.network.chat.TextColor; @@ -176,6 +178,20 @@ public void addPackEntry(int index, String name) { this.addEntry(entry); } + @Override + protected void renderDecorations(GuiGraphics pAbstractSelectionList0, int pInt1, int pInt2) { + // Renders top/bottom dirt + int lvInt9 = 32; + pAbstractSelectionList0.setColor(0.25F, 0.25F, 0.25F, 1.0F); + pAbstractSelectionList0.blit(Screen.BACKGROUND_LOCATION, this.x0, 0, 0.0F, 0.0F, this.width, this.y0, 32, 32); + pAbstractSelectionList0.blit(Screen.BACKGROUND_LOCATION, this.x0, this.y1, 0.0F, (float)this.y1, this.width, this.height - this.y1, 32, 32); + pAbstractSelectionList0.setColor(1.0F, 1.0F, 1.0F, 1.0F); + int lvInt10 = 4; + pAbstractSelectionList0.fillGradient(RenderType.guiOverlay(), this.x0, this.y0, this.x1, this.y0 + 4, -16777216, 0, 0); + pAbstractSelectionList0.fillGradient(RenderType.guiOverlay(), this.x0, this.y1 - 4, this.x1, this.y1, 0, -16777216, 0); + super.renderDecorations(pAbstractSelectionList0, pInt1, pInt2); + } + public void addLabelEntries(Component ... lines) { for (Component text : lines) { this.addEntry(new LabelEntry(text)); diff --git a/src/main/java/net/coderbot/iris/gui/screen/ShaderPackScreen.java b/src/main/java/net/coderbot/iris/gui/screen/ShaderPackScreen.java index 808abd255e..e631520291 100644 --- a/src/main/java/net/coderbot/iris/gui/screen/ShaderPackScreen.java +++ b/src/main/java/net/coderbot/iris/gui/screen/ShaderPackScreen.java @@ -198,6 +198,11 @@ public boolean mouseClicked(double d, double e, int i) { return super.mouseClicked(d, e, i); } + @Override + public void renderTransparentBackground(GuiGraphics pScreen0) { + // Nope + } + @Override protected void init() { super.init(); From c844940fa15a433d08c3f99df38cb5c2d1787091 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Mon, 11 Sep 2023 22:50:35 -0700 Subject: [PATCH 05/56] Fix 1.20.2 --- buildscript/src/main/java/Buildscript.java | 2 +- .../iris/compat/sodium/mixin/clouds/MixinCloudRenderer.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/buildscript/src/main/java/Buildscript.java b/buildscript/src/main/java/Buildscript.java index 4561163bd2..973212b4ac 100644 --- a/buildscript/src/main/java/Buildscript.java +++ b/buildscript/src/main/java/Buildscript.java @@ -46,7 +46,7 @@ public class Buildscript extends SimpleFabricProject { static final boolean SODIUM = true; static final boolean CUSTOM_SODIUM = true; static final String MC_VERSION = "1.20.2-pre2"; - static final String customSodiumName = "sodium-fabric-mc1.20.2-pre1-0.5.2+git.d9371a4-dirty.jar"; + static final String customSodiumName = "sodium-fabric-mc1.20.2-pre1-0.5.2+git.a275424.jar"; private static final String[] SOURCE_SETS = new String[] { "main", diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/clouds/MixinCloudRenderer.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/clouds/MixinCloudRenderer.java index cab9aadef0..72b84b0ba4 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/clouds/MixinCloudRenderer.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/clouds/MixinCloudRenderer.java @@ -42,7 +42,7 @@ public abstract class MixinCloudRenderer { protected abstract void rebuildGeometry(BufferBuilder bufferBuilder, int cloudDistance, int centerCellX, int centerCellZ); @Shadow - private ShaderInstance clouds; + private ShaderInstance shader; @Shadow protected abstract void applyFogModifiers(ClientLevel world, FogRenderer.FogData fogData, LocalPlayer player, int cloudDistance, float tickDelta); @@ -198,6 +198,6 @@ private ShaderInstance getClouds() { return ((CoreWorldRenderingPipeline) pipeline).getShaderMap().getShader(ShaderKey.CLOUDS_SODIUM); } - return clouds; + return shader; } } From 05a461bdc902b4d1de36c4401bf7081c47adacaa Mon Sep 17 00:00:00 2001 From: IMS212 Date: Tue, 19 Sep 2023 20:48:57 -0700 Subject: [PATCH 06/56] Get ready for 1.20.2 --- buildscript/src/main/java/Buildscript.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/buildscript/src/main/java/Buildscript.java b/buildscript/src/main/java/Buildscript.java index 3195ad7217..8be8ef1675 100644 --- a/buildscript/src/main/java/Buildscript.java +++ b/buildscript/src/main/java/Buildscript.java @@ -45,8 +45,8 @@ public class Buildscript extends SimpleFabricProject { static final boolean SODIUM = true; static final boolean CUSTOM_SODIUM = true; - static final String MC_VERSION = "1.20.2-pre2"; - static final String customSodiumName = "sodium-fabric-mc1.20.2-pre1-0.5.2+git.a275424.jar"; + static final String MC_VERSION = "1.20.2-rc2"; + static final String customSodiumName = "sodium-fabric-mc1.20.2-rc2-0.5.3+git.63b0ad2.jar"; private static final String[] SOURCE_SETS = new String[] { "main", From 1241de860ada20afa76911703fc81bdebc334b19 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Thu, 21 Sep 2023 08:53:53 -0700 Subject: [PATCH 07/56] 1.20.2 final --- buildscript/src/main/java/Buildscript.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/buildscript/src/main/java/Buildscript.java b/buildscript/src/main/java/Buildscript.java index 8be8ef1675..fd13154bb2 100644 --- a/buildscript/src/main/java/Buildscript.java +++ b/buildscript/src/main/java/Buildscript.java @@ -44,8 +44,8 @@ public class Buildscript extends SimpleFabricProject { static final boolean SODIUM = true; - static final boolean CUSTOM_SODIUM = true; - static final String MC_VERSION = "1.20.2-rc2"; + static final boolean CUSTOM_SODIUM = false; + static final String MC_VERSION = "1.20.2"; static final String customSodiumName = "sodium-fabric-mc1.20.2-rc2-0.5.3+git.63b0ad2.jar"; private static final String[] SOURCE_SETS = new String[] { @@ -113,10 +113,10 @@ public void getModDependencies(ModDependencyCollector d) { if (CUSTOM_SODIUM) { d.add(new JavaJarDependency(getProjectDir().resolve("custom_sodium").resolve(customSodiumName).toAbsolutePath(), null, new MavenId("me.jellysquid.mods", "sodium-fabric", customSodiumName.replace("sodium-fabric-", ""))), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); } else { - d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "sodium", "mc1.20.1-0.5.3"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); + d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "sodium", "mc1.20.2-0.5.3"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); } } else { - d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "sodium", "mc1.20.1-0.5.3"), ModDependencyFlag.COMPILE); + d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "sodium", "mc1.20.2-0.5.3"), ModDependencyFlag.COMPILE); } } From 5d2f95a53a9859669b487e85ee2195cb0327c457 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Thu, 21 Sep 2023 08:54:15 -0700 Subject: [PATCH 08/56] i forgor --- src/main/resources/fabric.mod.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 01f0658c3f..1ee5d94e3e 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -44,7 +44,7 @@ "depends": { "fabricloader": ">=0.12.3", - "minecraft": "1.20.x", + "minecraft": "1.20.2", "sodium": "0.5.3" }, From 30fca7c4eead2c2ad1c12188abced89f9b06d6a9 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Sat, 23 Sep 2023 19:24:03 -0700 Subject: [PATCH 09/56] Fix PBR textures --- .../texture/pbr/loader/AtlasPBRLoader.java | 58 ++++++++++--------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/src/main/java/net/coderbot/iris/texture/pbr/loader/AtlasPBRLoader.java b/src/main/java/net/coderbot/iris/texture/pbr/loader/AtlasPBRLoader.java index 4049aed258..22605aa590 100644 --- a/src/main/java/net/coderbot/iris/texture/pbr/loader/AtlasPBRLoader.java +++ b/src/main/java/net/coderbot/iris/texture/pbr/loader/AtlasPBRLoader.java @@ -109,7 +109,8 @@ protected PBRTextureAtlasSprite createPBRSprite(TextureAtlasSprite sprite, Resou int imageWidth = nativeImage.getWidth(); int imageHeight = nativeImage.getHeight(); - FrameSize frameSize = animationMetadata.getSection(AnimationMetadataSection.SERIALIZER).orElse(AnimationMetadataSection.EMPTY).calculateFrameSize(imageWidth, imageHeight); + AnimationMetadataSection metadataSection = animationMetadata.getSection(AnimationMetadataSection.SERIALIZER).orElse(AnimationMetadataSection.EMPTY); + FrameSize frameSize = metadataSection.calculateFrameSize(imageWidth, imageHeight); int frameWidth = frameSize.width(); int frameHeight = frameSize.height(); if (!Mth.isMultipleOf(imageWidth, frameWidth) || !Mth.isMultipleOf(imageHeight, frameHeight)) { @@ -121,33 +122,38 @@ protected PBRTextureAtlasSprite createPBRSprite(TextureAtlasSprite sprite, Resou int targetFrameWidth = sprite.contents().width(); int targetFrameHeight = sprite.contents().height(); if (frameWidth != targetFrameWidth || frameHeight != targetFrameHeight) { - // We can assume the following is always true: - // imageWidth % frameWidth == 0 && imageHeight % frameHeight == 0 - int targetImageWidth = imageWidth / frameWidth * targetFrameWidth; - int targetImageHeight = imageHeight / frameHeight * targetFrameHeight; - - NativeImage scaledImage; - if (targetImageWidth % imageWidth == 0 && targetImageHeight % imageHeight == 0) { - scaledImage = ImageManipulationUtil.scaleNearestNeighbor(nativeImage, targetImageWidth, targetImageHeight); - } else { - scaledImage = ImageManipulationUtil.scaleBilinear(nativeImage, targetImageWidth, targetImageHeight); - } - nativeImage.close(); - nativeImage = scaledImage; - - frameWidth = targetFrameWidth; - frameHeight = targetFrameHeight; - - if (animationMetadata != AnimationMetadataSection.EMPTY) { - AnimationMetadataSectionAccessor animationAccessor = (AnimationMetadataSectionAccessor) animationMetadata; - int internalFrameWidth = animationAccessor.getFrameWidth(); - int internalFrameHeight = animationAccessor.getFrameHeight(); - if (internalFrameWidth != -1) { - animationAccessor.setFrameWidth(frameWidth); + try { + // We can assume the following is always true: + // imageWidth % frameWidth == 0 && imageHeight % frameHeight == 0 + int targetImageWidth = imageWidth / frameWidth * targetFrameWidth; + int targetImageHeight = imageHeight / frameHeight * targetFrameHeight; + + NativeImage scaledImage; + if (targetImageWidth % imageWidth == 0 && targetImageHeight % imageHeight == 0) { + scaledImage = ImageManipulationUtil.scaleNearestNeighbor(nativeImage, targetImageWidth, targetImageHeight); + } else { + scaledImage = ImageManipulationUtil.scaleBilinear(nativeImage, targetImageWidth, targetImageHeight); } - if (internalFrameHeight != -1) { - animationAccessor.setFrameHeight(frameHeight); + nativeImage.close(); + nativeImage = scaledImage; + + frameWidth = targetFrameWidth; + frameHeight = targetFrameHeight; + + if (metadataSection != AnimationMetadataSection.EMPTY) { + AnimationMetadataSectionAccessor animationAccessor = (AnimationMetadataSectionAccessor) metadataSection; + int internalFrameWidth = animationAccessor.getFrameWidth(); + int internalFrameHeight = animationAccessor.getFrameHeight(); + if (internalFrameWidth != -1) { + animationAccessor.setFrameWidth(frameWidth); + } + if (internalFrameHeight != -1) { + animationAccessor.setFrameHeight(frameHeight); + } } + } catch (Exception e) { + Iris.logger.error("Something bad happened trying to load PBR texture " + spriteName.getPath() + pbrType.getSuffix() + "!", e); + throw e; } } From 05df827d45f2f573e76760788bdf653d9fa93d44 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Wed, 4 Oct 2023 13:53:24 -0700 Subject: [PATCH 10/56] 23w40a --- buildscript/src/main/java/Buildscript.java | 2 +- .../net/coderbot/iris/mixin/MixinEntityRenderDispatcher.java | 5 +++-- src/main/java/net/coderbot/iris/mixin/MixinTitleScreen.java | 1 - src/main/resources/fabric.mod.json | 1 - 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/buildscript/src/main/java/Buildscript.java b/buildscript/src/main/java/Buildscript.java index fd13154bb2..04d859d983 100644 --- a/buildscript/src/main/java/Buildscript.java +++ b/buildscript/src/main/java/Buildscript.java @@ -45,7 +45,7 @@ public class Buildscript extends SimpleFabricProject { static final boolean SODIUM = true; static final boolean CUSTOM_SODIUM = false; - static final String MC_VERSION = "1.20.2"; + static final String MC_VERSION = "23w40a"; static final String customSodiumName = "sodium-fabric-mc1.20.2-rc2-0.5.3+git.63b0ad2.jar"; private static final String[] SOURCE_SETS = new String[] { diff --git a/src/main/java/net/coderbot/iris/mixin/MixinEntityRenderDispatcher.java b/src/main/java/net/coderbot/iris/mixin/MixinEntityRenderDispatcher.java index 5c1c1de25f..f3881b7647 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinEntityRenderDispatcher.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinEntityRenderDispatcher.java @@ -15,6 +15,7 @@ import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.chunk.ChunkAccess; import net.minecraft.world.phys.Vec3; +import org.joml.Quaternionf; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -60,7 +61,7 @@ private static void restoreShadow(PoseStack pPoseStack0, MultiBufferSource pMult } @Inject(method = "renderFlame", at = @At("HEAD")) - private void iris$setFlameId(PoseStack pEntityRenderDispatcher0, MultiBufferSource pMultiBufferSource1, Entity pEntity2, CallbackInfo ci) { + private void iris$setFlameId(PoseStack pEntityRenderDispatcher0, MultiBufferSource pMultiBufferSource1, Entity pEntity2, Quaternionf pQuaternionf3, CallbackInfo ci) { Object2IntFunction entityIds = BlockRenderingSettings.INSTANCE.getEntityIds(); if (entityIds == null) { @@ -72,7 +73,7 @@ private static void restoreShadow(PoseStack pPoseStack0, MultiBufferSource pMult } @Inject(method = "renderFlame", at = @At("RETURN")) - private void restoreFlameId(PoseStack pEntityRenderDispatcher0, MultiBufferSource pMultiBufferSource1, Entity pEntity2, CallbackInfo ci) { + private void restoreFlameId(PoseStack pEntityRenderDispatcher0, MultiBufferSource pMultiBufferSource1, Entity pEntity2, Quaternionf pQuaternionf3, CallbackInfo ci) { CapturedRenderingState.INSTANCE.setCurrentEntity(cachedId); cachedId = 0; } diff --git a/src/main/java/net/coderbot/iris/mixin/MixinTitleScreen.java b/src/main/java/net/coderbot/iris/mixin/MixinTitleScreen.java index 1dad30b435..c142a39f56 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinTitleScreen.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinTitleScreen.java @@ -10,7 +10,6 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.AlertScreen; import net.minecraft.client.gui.screens.ConfirmScreen; -import net.minecraft.client.gui.screens.PopupScreen; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.TitleScreen; diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 1ee5d94e3e..74190da034 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -44,7 +44,6 @@ "depends": { "fabricloader": ">=0.12.3", - "minecraft": "1.20.2", "sodium": "0.5.3" }, From aa066d4a931cf437350c33fc2f6aff34380c3879 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Wed, 18 Oct 2023 19:18:50 -0700 Subject: [PATCH 11/56] 23w42a --- buildscript/src/main/java/Buildscript.java | 8 ++++---- .../mixin/BufferSourceAccessor.java | 15 +++++++++++++++ .../mixin/MixinRenderBuffers.java | 7 ++----- src/main/java/net/coderbot/iris/Iris.java | 2 +- .../coderbot/iris/pipeline/ShadowRenderer.java | 4 +++- .../iris-batched-entity-rendering.mixins.json | 1 + 6 files changed, 26 insertions(+), 11 deletions(-) create mode 100644 src/main/java/net/coderbot/batchedentityrendering/mixin/BufferSourceAccessor.java diff --git a/buildscript/src/main/java/Buildscript.java b/buildscript/src/main/java/Buildscript.java index a14458e05b..f2f6b7f9dd 100644 --- a/buildscript/src/main/java/Buildscript.java +++ b/buildscript/src/main/java/Buildscript.java @@ -44,9 +44,9 @@ public class Buildscript extends SimpleFabricProject { static final boolean SODIUM = true; - static final boolean CUSTOM_SODIUM = false; - static final String MC_VERSION = "23w40a"; - static final String customSodiumName = "sodium-fabric-mc1.20.2-rc2-0.5.3+git.63b0ad2.jar"; + static final boolean CUSTOM_SODIUM = true; + static final String MC_VERSION = "23w42a"; + static final String customSodiumName = "sodium-fabric-mc23w42a-0.5.3+git.b1ba94f.jar"; private static final String[] SOURCE_SETS = new String[] { "main", @@ -107,7 +107,7 @@ public void getModDependencies(ModDependencyCollector d) { d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", "fabric-rendering-data-attachment-v1", "0.3.21+12bfe4ea53"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", "fabric-block-view-api-v2", "1.0.0+92a0d36777"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", "fabric-rendering-fluids-v1", "3.0.13+fbde993d53"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); - d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", "fabric-resource-loader-v0", "0.11.10+86b1264599"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); + d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", "fabric-resource-loader-v0", "0.11.12+2148f3b9cb"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", "fabric-block-view-api-v2", "1.0.0+73761d2e99"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); if (CUSTOM_SODIUM) { diff --git a/src/main/java/net/coderbot/batchedentityrendering/mixin/BufferSourceAccessor.java b/src/main/java/net/coderbot/batchedentityrendering/mixin/BufferSourceAccessor.java new file mode 100644 index 0000000000..3596a0fba0 --- /dev/null +++ b/src/main/java/net/coderbot/batchedentityrendering/mixin/BufferSourceAccessor.java @@ -0,0 +1,15 @@ +package net.coderbot.batchedentityrendering.mixin; + +import com.mojang.blaze3d.vertex.BufferBuilder; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderType; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import java.util.Map; + +@Mixin(MultiBufferSource.BufferSource.class) +public interface BufferSourceAccessor { + @Accessor + Map getFixedBuffers(); +} diff --git a/src/main/java/net/coderbot/batchedentityrendering/mixin/MixinRenderBuffers.java b/src/main/java/net/coderbot/batchedentityrendering/mixin/MixinRenderBuffers.java index 4c7d60535c..aabd3b6be4 100644 --- a/src/main/java/net/coderbot/batchedentityrendering/mixin/MixinRenderBuffers.java +++ b/src/main/java/net/coderbot/batchedentityrendering/mixin/MixinRenderBuffers.java @@ -47,10 +47,6 @@ public class MixinRenderBuffers implements RenderBuffersExt, MemoryTrackingRende @Final private SectionBufferBuilderPack fixedBufferPack; - @Shadow - @Final - private SortedMap fixedBuffers; - @Inject(method = "bufferSource", at = @At("HEAD"), cancellable = true) private void batchedentityrendering$replaceBufferSource(CallbackInfoReturnable cir) { if (begins == 0) { @@ -126,7 +122,8 @@ public int getMaxBegins() { public void freeAndDeleteBuffers() { buffered.freeAndDeleteBuffer(); ((SectionBufferBuilderPackAccessor) this.fixedBufferPack).getBuilders().values().forEach(bufferBuilder -> ((MemoryTrackingBuffer) bufferBuilder).freeAndDeleteBuffer()); - fixedBuffers.values().forEach(bufferBuilder -> ((MemoryTrackingBuffer) bufferBuilder).freeAndDeleteBuffer()); + ((BufferSourceAccessor) bufferSource).getFixedBuffers().forEach((renderType, bufferBuilder) -> ((MemoryTrackingBuffer) bufferBuilder).freeAndDeleteBuffer()); + ((BufferSourceAccessor) bufferSource).getFixedBuffers().clear(); ((MemoryTrackingBuffer) ((OutlineBufferSourceAccessor) outlineBufferSource).getOutlineBufferSource()).freeAndDeleteBuffer(); } diff --git a/src/main/java/net/coderbot/iris/Iris.java b/src/main/java/net/coderbot/iris/Iris.java index 065f8ddb7b..0900177688 100644 --- a/src/main/java/net/coderbot/iris/Iris.java +++ b/src/main/java/net/coderbot/iris/Iris.java @@ -101,7 +101,7 @@ public class Iris { private static boolean fallback; // Change this for snapshots! - private static String backupVersionNumber = "1.19.4"; + private static String backupVersionNumber = "1.20.3"; /** * Called very early on in Minecraft initialization. At this point we *cannot* safely access OpenGL, but we can do diff --git a/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java b/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java index 63c39158f9..75b8da481e 100644 --- a/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java +++ b/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java @@ -138,7 +138,9 @@ public ShadowRenderer(ProgramSource shadow, PackDirectives directives, this.sunPathRotation = directives.getSunPathRotation(); - this.buffers = new RenderBuffers(); + int processors = Runtime.getRuntime().availableProcessors(); + int threads = Minecraft.getInstance().is64Bit() ? processors : Math.min(processors, 4); + this.buffers = new RenderBuffers(threads); if (this.buffers instanceof RenderBuffersExt) { this.renderBuffersExt = (RenderBuffersExt) buffers; diff --git a/src/main/resources/iris-batched-entity-rendering.mixins.json b/src/main/resources/iris-batched-entity-rendering.mixins.json index 5f54654b42..32c2d62f33 100644 --- a/src/main/resources/iris-batched-entity-rendering.mixins.json +++ b/src/main/resources/iris-batched-entity-rendering.mixins.json @@ -17,6 +17,7 @@ "MixinCompositeRenderType", "MixinLevelRenderer", "MixinLevelRenderer_EntityListSorting", + "BufferSourceAccessor", "CompositeStateAccessor", "RenderTypeAccessor", "RenderStateShardAccessor" From cb0d56dc3e0434b6d9662e9a0fcb1abaebf68c79 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Wed, 25 Oct 2023 08:31:16 -0700 Subject: [PATCH 12/56] Allow dynamic tick rate shadows --- buildscript/src/main/java/Buildscript.java | 4 ++-- .../iris/mixin/MixinLevelRenderer.java | 18 ++++++------------ .../coderbot/iris/pipeline/ShadowRenderer.java | 12 ++++++++---- .../iris/uniforms/CapturedRenderingState.java | 10 +++++++++- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/buildscript/src/main/java/Buildscript.java b/buildscript/src/main/java/Buildscript.java index f2f6b7f9dd..c222494267 100644 --- a/buildscript/src/main/java/Buildscript.java +++ b/buildscript/src/main/java/Buildscript.java @@ -45,8 +45,8 @@ public class Buildscript extends SimpleFabricProject { static final boolean SODIUM = true; static final boolean CUSTOM_SODIUM = true; - static final String MC_VERSION = "23w42a"; - static final String customSodiumName = "sodium-fabric-mc23w42a-0.5.3+git.b1ba94f.jar"; + static final String MC_VERSION = "23w43a"; + static final String customSodiumName = "sodium-fabric-mc23w42a-0.5.3git.b1ba94f.jar"; private static final String[] SOURCE_SETS = new String[] { "main", diff --git a/src/main/java/net/coderbot/iris/mixin/MixinLevelRenderer.java b/src/main/java/net/coderbot/iris/mixin/MixinLevelRenderer.java index cc40ed1c78..d18cfbf347 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinLevelRenderer.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinLevelRenderer.java @@ -4,10 +4,9 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Axis; import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.world.TickRateManager; import org.joml.Matrix4f; import net.coderbot.iris.Iris; -import net.coderbot.iris.fantastic.WrappingMultiBufferSource; -import net.coderbot.iris.gl.program.Program; import net.coderbot.iris.layer.IsOutlineRenderStateShard; import net.coderbot.iris.layer.OuterWrappedRenderType; import net.coderbot.iris.pipeline.HandRenderer; @@ -16,22 +15,15 @@ import net.coderbot.iris.shadows.frustum.fallback.NonCullingFrustum; import net.coderbot.iris.uniforms.CapturedRenderingState; import net.coderbot.iris.uniforms.SystemTimeUniforms; -import org.joml.Vector3d; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; import net.minecraft.client.Camera; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.renderer.LevelRenderer; import net.minecraft.client.renderer.LightTexture; -import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.RenderBuffers; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.culling.Frustum; -import net.minecraft.core.BlockPos; -import net.minecraft.world.phys.Vec3; import org.spongepowered.asm.mixin.Final; -import net.minecraft.client.Options; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -40,7 +32,6 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.ModifyVariable; -import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.Slice; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -83,8 +74,11 @@ public class MixinLevelRenderer { CapturedRenderingState.INSTANCE.setGbufferModelView(poseStack.last().pose()); CapturedRenderingState.INSTANCE.setGbufferProjection(projection); - CapturedRenderingState.INSTANCE.setTickDelta(tickDelta); - CapturedRenderingState.INSTANCE.setCloudTime((ticks + tickDelta) * 0.03F); + TickRateManager lvTickRateManager10 = this.minecraft.level.tickRateManager(); + float fakeTickDelta = lvTickRateManager10.runsNormally() ? tickDelta : 1.0F; + CapturedRenderingState.INSTANCE.setTickDelta(fakeTickDelta); + CapturedRenderingState.INSTANCE.setRealTickDelta(tickDelta); + CapturedRenderingState.INSTANCE.setCloudTime((ticks + fakeTickDelta) * 0.03F); SystemTimeUniforms.COUNTER.beginFrame(); SystemTimeUniforms.TIMER.beginFrame(startTime); diff --git a/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java b/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java index 75b8da481e..78f603b6ad 100644 --- a/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java +++ b/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java @@ -623,7 +623,8 @@ private int renderEntities(LevelRendererAccessor levelRenderer, EntityRenderDisp levelRenderer.getLevel().getProfiler().popPush("build entity geometry"); for (Entity entity : renderedEntities) { - levelRenderer.invokeRenderEntity(entity, cameraX, cameraY, cameraZ, tickDelta, modelView, bufferSource); + float realTickDelta = Minecraft.getInstance().level.tickRateManager().isEntityFrozen(entity) ? tickDelta : CapturedRenderingState.INSTANCE.getRealTickDelta(); + levelRenderer.invokeRenderEntity(entity, cameraX, cameraY, cameraZ, realTickDelta, modelView, bufferSource); } levelRenderer.getLevel().getProfiler().pop(); @@ -647,17 +648,20 @@ private int renderPlayerEntity(LevelRendererAccessor levelRenderer, EntityRender if (!player.getPassengers().isEmpty()) { for (int i = 0; i < player.getPassengers().size(); i++) { - levelRenderer.invokeRenderEntity(player.getPassengers().get(i), cameraX, cameraY, cameraZ, tickDelta, modelView, bufferSource); + float realTickDelta = Minecraft.getInstance().level.tickRateManager().isEntityFrozen(player.getPassengers().get(i)) ? tickDelta : CapturedRenderingState.INSTANCE.getRealTickDelta(); + levelRenderer.invokeRenderEntity(player.getPassengers().get(i), cameraX, cameraY, cameraZ, realTickDelta, modelView, bufferSource); shadowEntities++; } } if (player.getVehicle() != null) { - levelRenderer.invokeRenderEntity(player.getVehicle(), cameraX, cameraY, cameraZ, tickDelta, modelView, bufferSource); + float realTickDelta = Minecraft.getInstance().level.tickRateManager().isEntityFrozen(player.getVehicle()) ? tickDelta : CapturedRenderingState.INSTANCE.getRealTickDelta(); + levelRenderer.invokeRenderEntity(player.getVehicle(), cameraX, cameraY, cameraZ, realTickDelta, modelView, bufferSource); shadowEntities++; } - levelRenderer.invokeRenderEntity(player, cameraX, cameraY, cameraZ, tickDelta, modelView, bufferSource); + float realTickDelta = Minecraft.getInstance().level.tickRateManager().isEntityFrozen(player) ? tickDelta : CapturedRenderingState.INSTANCE.getRealTickDelta(); + levelRenderer.invokeRenderEntity(player, cameraX, cameraY, cameraZ, realTickDelta, modelView, bufferSource); shadowEntities++; diff --git a/src/main/java/net/coderbot/iris/uniforms/CapturedRenderingState.java b/src/main/java/net/coderbot/iris/uniforms/CapturedRenderingState.java index 40e0301ea7..06070953b5 100644 --- a/src/main/java/net/coderbot/iris/uniforms/CapturedRenderingState.java +++ b/src/main/java/net/coderbot/iris/uniforms/CapturedRenderingState.java @@ -1,6 +1,5 @@ package net.coderbot.iris.uniforms; -import net.coderbot.iris.gl.state.ValueUpdateNotifier; import net.minecraft.client.Minecraft; import org.joml.Matrix4f; import org.joml.Vector3d; @@ -16,6 +15,7 @@ public class CapturedRenderingState { private float fogDensity; private float darknessLightFactor; private float tickDelta; + private float realTickDelta; private int currentRenderedBlockEntity; private int currentRenderedEntity = -1; @@ -67,10 +67,18 @@ public void setTickDelta(float tickDelta) { this.tickDelta = tickDelta; } + public void setRealTickDelta(float tickDelta) { + this.realTickDelta = tickDelta; + } + public float getTickDelta() { return tickDelta; } + public float getRealTickDelta() { + return realTickDelta; + } + public void setCurrentBlockEntity(int entity) { this.currentRenderedBlockEntity = entity; } From ac1b25877c0ea3532dfe11ebdb180be1a570245c Mon Sep 17 00:00:00 2001 From: IMS212 Date: Wed, 8 Nov 2023 12:31:29 -0800 Subject: [PATCH 13/56] Breeze wind --- buildscript/src/main/java/Buildscript.java | 2 +- src/main/java/net/coderbot/iris/mixin/MixinGameRenderer.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/buildscript/src/main/java/Buildscript.java b/buildscript/src/main/java/Buildscript.java index c222494267..a209692114 100644 --- a/buildscript/src/main/java/Buildscript.java +++ b/buildscript/src/main/java/Buildscript.java @@ -45,7 +45,7 @@ public class Buildscript extends SimpleFabricProject { static final boolean SODIUM = true; static final boolean CUSTOM_SODIUM = true; - static final String MC_VERSION = "23w43a"; + static final String MC_VERSION = "23w45a"; static final String customSodiumName = "sodium-fabric-mc23w42a-0.5.3git.b1ba94f.jar"; private static final String[] SOURCE_SETS = new String[] { diff --git a/src/main/java/net/coderbot/iris/mixin/MixinGameRenderer.java b/src/main/java/net/coderbot/iris/mixin/MixinGameRenderer.java index bb5bd0504e..6e5f736102 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinGameRenderer.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinGameRenderer.java @@ -178,6 +178,7 @@ public class MixinGameRenderer { @Inject(method = { "getRendertypeEntityCutoutShader", + "getRendertypeBreezeWindShader", "getRendertypeEntityCutoutNoCullShader", "getRendertypeEntityCutoutNoCullZOffsetShader", "getRendertypeEntityDecalShader", From c2b54d47f66ef69b0fe72bf7b9104a65db0a88b5 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Thu, 9 Nov 2023 06:12:13 -0800 Subject: [PATCH 14/56] Fix some wind issues --- buildscript/src/main/java/Buildscript.java | 2 +- src/main/java/net/coderbot/iris/mixin/MixinGameRenderer.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/buildscript/src/main/java/Buildscript.java b/buildscript/src/main/java/Buildscript.java index a209692114..36806cd8da 100644 --- a/buildscript/src/main/java/Buildscript.java +++ b/buildscript/src/main/java/Buildscript.java @@ -107,7 +107,7 @@ public void getModDependencies(ModDependencyCollector d) { d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", "fabric-rendering-data-attachment-v1", "0.3.21+12bfe4ea53"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", "fabric-block-view-api-v2", "1.0.0+92a0d36777"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", "fabric-rendering-fluids-v1", "3.0.13+fbde993d53"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); - d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", "fabric-resource-loader-v0", "0.11.12+2148f3b9cb"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); + d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", "fabric-resource-loader-v0", "0.11.14+f31bf881a9"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", "fabric-block-view-api-v2", "1.0.0+73761d2e99"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); if (CUSTOM_SODIUM) { diff --git a/src/main/java/net/coderbot/iris/mixin/MixinGameRenderer.java b/src/main/java/net/coderbot/iris/mixin/MixinGameRenderer.java index 6e5f736102..89e3ab0552 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinGameRenderer.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinGameRenderer.java @@ -178,7 +178,6 @@ public class MixinGameRenderer { @Inject(method = { "getRendertypeEntityCutoutShader", - "getRendertypeBreezeWindShader", "getRendertypeEntityCutoutNoCullShader", "getRendertypeEntityCutoutNoCullZOffsetShader", "getRendertypeEntityDecalShader", @@ -201,6 +200,7 @@ public class MixinGameRenderer { "getRendertypeEntityTranslucentShader", "getRendertypeEntityTranslucentCullShader", "getRendertypeItemEntityTranslucentCullShader", + "getRendertypeBreezeWindShader", "getRendertypeEntityNoOutlineShader" }, at = @At("HEAD"), cancellable = true) private static void iris$overrideEntityTranslucentShader(CallbackInfoReturnable cir) { From e2a0d7dd9e175b1b65a67baa55ff8df3f63cc32c Mon Sep 17 00:00:00 2001 From: IMS212 Date: Thu, 16 Nov 2023 08:54:25 -0800 Subject: [PATCH 15/56] here's source --- buildscript/src/main/java/Buildscript.java | 4 ++-- .../element/IrisContainerObjectSelectionList.java | 5 +---- .../iris/gui/element/IrisObjectSelectionList.java | 7 ++----- .../iris/gui/element/ShaderPackOptionList.java | 9 +++++---- .../iris/gui/element/ShaderPackSelectionList.java | 13 +++++++------ 5 files changed, 17 insertions(+), 21 deletions(-) diff --git a/buildscript/src/main/java/Buildscript.java b/buildscript/src/main/java/Buildscript.java index 36806cd8da..8a4345ce84 100644 --- a/buildscript/src/main/java/Buildscript.java +++ b/buildscript/src/main/java/Buildscript.java @@ -45,8 +45,8 @@ public class Buildscript extends SimpleFabricProject { static final boolean SODIUM = true; static final boolean CUSTOM_SODIUM = true; - static final String MC_VERSION = "23w45a"; - static final String customSodiumName = "sodium-fabric-mc23w42a-0.5.3git.b1ba94f.jar"; + static final String MC_VERSION = "23w46a"; + static final String customSodiumName = "sodium-fabric-mc23w45a-0.5.3git.86b69d2-dirty.jar"; private static final String[] SOURCE_SETS = new String[] { "main", diff --git a/src/main/java/net/coderbot/iris/gui/element/IrisContainerObjectSelectionList.java b/src/main/java/net/coderbot/iris/gui/element/IrisContainerObjectSelectionList.java index ec1a70589d..c292005552 100644 --- a/src/main/java/net/coderbot/iris/gui/element/IrisContainerObjectSelectionList.java +++ b/src/main/java/net/coderbot/iris/gui/element/IrisContainerObjectSelectionList.java @@ -8,10 +8,7 @@ public class IrisContainerObjectSelectionList> extends ContainerObjectSelectionList { public IrisContainerObjectSelectionList(Minecraft client, int width, int height, int top, int bottom, int left, int right, int itemHeight) { - super(client, width, height, top, bottom, itemHeight); - - this.x0 = left; - this.x1 = right; + super(client, width, height, top, itemHeight); } @Override diff --git a/src/main/java/net/coderbot/iris/gui/element/IrisObjectSelectionList.java b/src/main/java/net/coderbot/iris/gui/element/IrisObjectSelectionList.java index 91f48c415d..618f2dcbb7 100644 --- a/src/main/java/net/coderbot/iris/gui/element/IrisObjectSelectionList.java +++ b/src/main/java/net/coderbot/iris/gui/element/IrisObjectSelectionList.java @@ -8,10 +8,7 @@ public class IrisObjectSelectionList> extends AbstractSelectionList { public IrisObjectSelectionList(Minecraft client, int width, int height, int top, int bottom, int left, int right, int itemHeight) { - super(client, width, height, top, bottom, itemHeight); - - this.x0 = left; - this.x1 = right; + super(client, width, height, top, itemHeight); } @Override @@ -26,7 +23,7 @@ public void select(int entry) { } @Override - public void updateNarration(NarrationElementOutput p0) { + public void updateWidgetNarration(NarrationElementOutput p0) { } } diff --git a/src/main/java/net/coderbot/iris/gui/element/ShaderPackOptionList.java b/src/main/java/net/coderbot/iris/gui/element/ShaderPackOptionList.java index 9df2e00650..8aad40fe20 100644 --- a/src/main/java/net/coderbot/iris/gui/element/ShaderPackOptionList.java +++ b/src/main/java/net/coderbot/iris/gui/element/ShaderPackOptionList.java @@ -50,6 +50,7 @@ public ShaderPackOptionList(ShaderPackScreen screen, NavigationController naviga super(client, width, height, top, bottom, left, right, 24); this.navigation = navigation; this.screen = screen; + this.setRenderBackground(false); applyShaderPack(pack); } @@ -59,12 +60,12 @@ protected void renderDecorations(GuiGraphics pAbstractSelectionList0, int pInt1, // Renders top/bottom dirt int lvInt9 = 32; pAbstractSelectionList0.setColor(0.25F, 0.25F, 0.25F, 1.0F); - pAbstractSelectionList0.blit(Screen.BACKGROUND_LOCATION, this.x0, 0, 0.0F, 0.0F, this.width, this.y0, 32, 32); - pAbstractSelectionList0.blit(Screen.BACKGROUND_LOCATION, this.x0, this.y1, 0.0F, (float)this.y1, this.width, this.height - this.y1, 32, 32); + pAbstractSelectionList0.blit(Screen.BACKGROUND_LOCATION, this.getX(), 0, 0.0F, 0.0F, this.width, this.getY(), 32, 32); + pAbstractSelectionList0.blit(Screen.BACKGROUND_LOCATION, this.getX(), this.getBottom(), 0.0F, (float)this.getBottom(), this.width, this.height - this.getBottom(), 32, 32); pAbstractSelectionList0.setColor(1.0F, 1.0F, 1.0F, 1.0F); int lvInt10 = 4; - pAbstractSelectionList0.fillGradient(RenderType.guiOverlay(), this.x0, this.y0, this.x1, this.y0 + 4, -16777216, 0, 0); - pAbstractSelectionList0.fillGradient(RenderType.guiOverlay(), this.x0, this.y1 - 4, this.x1, this.y1, 0, -16777216, 0); + pAbstractSelectionList0.fillGradient(RenderType.guiOverlay(), this.getX(), this.getY(), this.getRight(), this.getY() + 4, -16777216, 0, 0); + pAbstractSelectionList0.fillGradient(RenderType.guiOverlay(), this.getX(), this.getBottom() - 4, this.getRight(), this.getBottom(), 0, -16777216, 0); super.renderDecorations(pAbstractSelectionList0, pInt1, pInt2); } diff --git a/src/main/java/net/coderbot/iris/gui/element/ShaderPackSelectionList.java b/src/main/java/net/coderbot/iris/gui/element/ShaderPackSelectionList.java index e2cbdebbc4..d51d06199e 100644 --- a/src/main/java/net/coderbot/iris/gui/element/ShaderPackSelectionList.java +++ b/src/main/java/net/coderbot/iris/gui/element/ShaderPackSelectionList.java @@ -52,6 +52,7 @@ public ShaderPackSelectionList(ShaderPackScreen screen, Minecraft client, int wi super(client, width, height, top, bottom, left, right, 20); WatchKey key1; WatchService watcher1; + this.setRenderBackground(false); this.screen = screen; this.topButtonRow = new TopButtonRowEntry(this, Iris.getIrisConfig().areShadersEnabled()); @@ -84,7 +85,7 @@ public boolean keyPressed(int pContainerEventHandler0, int pInt1, int pInt2) { } @Override - public void render(GuiGraphics pAbstractSelectionList0, int pInt1, int pInt2, float pFloat3) { + public void renderWidget(GuiGraphics pAbstractSelectionList0, int pInt1, int pInt2, float pFloat3) { if (keyValid) { for (WatchEvent event : key.pollEvents()) { if (event.kind() == StandardWatchEventKinds.OVERFLOW) continue; @@ -96,7 +97,7 @@ public void render(GuiGraphics pAbstractSelectionList0, int pInt1, int pInt2, fl keyValid = key.reset(); } - super.render(pAbstractSelectionList0, pInt1, pInt2, pFloat3); + super.renderWidget(pAbstractSelectionList0, pInt1, pInt2, pFloat3); } public void close() throws IOException { @@ -183,12 +184,12 @@ protected void renderDecorations(GuiGraphics pAbstractSelectionList0, int pInt1, // Renders top/bottom dirt int lvInt9 = 32; pAbstractSelectionList0.setColor(0.25F, 0.25F, 0.25F, 1.0F); - pAbstractSelectionList0.blit(Screen.BACKGROUND_LOCATION, this.x0, 0, 0.0F, 0.0F, this.width, this.y0, 32, 32); - pAbstractSelectionList0.blit(Screen.BACKGROUND_LOCATION, this.x0, this.y1, 0.0F, (float)this.y1, this.width, this.height - this.y1, 32, 32); + pAbstractSelectionList0.blit(Screen.BACKGROUND_LOCATION, this.getX(), 0, 0.0F, 0.0F, this.width, this.getHeight(), 32, 32); + pAbstractSelectionList0.blit(Screen.BACKGROUND_LOCATION, this.getX(), this.getBottom(), 0.0F, (float)this.getBottom(), this.width, this.height - this.getBottom(), 32, 32); pAbstractSelectionList0.setColor(1.0F, 1.0F, 1.0F, 1.0F); int lvInt10 = 4; - pAbstractSelectionList0.fillGradient(RenderType.guiOverlay(), this.x0, this.y0, this.x1, this.y0 + 4, -16777216, 0, 0); - pAbstractSelectionList0.fillGradient(RenderType.guiOverlay(), this.x0, this.y1 - 4, this.x1, this.y1, 0, -16777216, 0); + pAbstractSelectionList0.fillGradient(RenderType.guiOverlay(), this.getX(), this.getHeight(), this.getRight(), this.getHeight() + 4, -16777216, 0, 0); + pAbstractSelectionList0.fillGradient(RenderType.guiOverlay(), this.getX(), this.getBottom() - 4, this.getRight(), this.getBottom(), 0, -16777216, 0); super.renderDecorations(pAbstractSelectionList0, pInt1, pInt2); } From e8af88f7c3b8264ca4c8a140d746bc9c5c4f9195 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Tue, 21 Nov 2023 16:39:42 -1000 Subject: [PATCH 16/56] a --- buildscript/src/main/java/Buildscript.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildscript/src/main/java/Buildscript.java b/buildscript/src/main/java/Buildscript.java index 8a4345ce84..809cba7e91 100644 --- a/buildscript/src/main/java/Buildscript.java +++ b/buildscript/src/main/java/Buildscript.java @@ -45,7 +45,7 @@ public class Buildscript extends SimpleFabricProject { static final boolean SODIUM = true; static final boolean CUSTOM_SODIUM = true; - static final String MC_VERSION = "23w46a"; + static final String MC_VERSION = "1.20.3-pre1"; static final String customSodiumName = "sodium-fabric-mc23w45a-0.5.3git.86b69d2-dirty.jar"; private static final String[] SOURCE_SETS = new String[] { From 131d754474f7aec0adbf7e1ef6773060e0229672 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Tue, 21 Nov 2023 18:35:09 -1000 Subject: [PATCH 17/56] Fix shader pack screen --- .../iris/gui/element/ShaderPackOptionList.java | 4 ++-- .../iris/gui/element/ShaderPackSelectionList.java | 10 +++++----- .../net/coderbot/iris/gui/screen/ShaderPackScreen.java | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/coderbot/iris/gui/element/ShaderPackOptionList.java b/src/main/java/net/coderbot/iris/gui/element/ShaderPackOptionList.java index 8aad40fe20..999f524b70 100644 --- a/src/main/java/net/coderbot/iris/gui/element/ShaderPackOptionList.java +++ b/src/main/java/net/coderbot/iris/gui/element/ShaderPackOptionList.java @@ -47,7 +47,7 @@ public class ShaderPackOptionList extends IrisContainerObjectSelectionList Date: Sat, 2 Dec 2023 20:31:13 -0800 Subject: [PATCH 18/56] Sodium 0.5.4 beginnings --- buildscript/src/main/java/Buildscript.java | 4 +- .../mixin/vertices/MixinBufferBuilder.java | 94 +++++---- .../IrisCommonVertexAttributes.java | 1 + .../entity_xhfp/EntityVertex.java | 10 +- .../entity_xhfp/GlyphVertexExt.java | 10 +- .../mixin/copyEntity/ModelPartMixin.java | 145 ++++++++------ .../shadows/EntityRenderDispatcherMixin.java | 3 +- .../sodium/mixin/fast_render/MixinCube.java | 28 --- .../mixin/fast_render/MixinModelPart.java | 184 ------------------ .../MixinCommonVertexAttributes.java | 5 +- .../entity/MixinEntityRenderDispatcher.java | 3 +- .../entity/MixinModelVertex.java | 2 +- 12 files changed, 155 insertions(+), 334 deletions(-) delete mode 100644 src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/fast_render/MixinCube.java delete mode 100644 src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/fast_render/MixinModelPart.java diff --git a/buildscript/src/main/java/Buildscript.java b/buildscript/src/main/java/Buildscript.java index ebbc79b3a7..a4952ecc3f 100644 --- a/buildscript/src/main/java/Buildscript.java +++ b/buildscript/src/main/java/Buildscript.java @@ -44,9 +44,9 @@ public class Buildscript extends SimpleFabricProject { static final boolean SODIUM = true; - static final boolean CUSTOM_SODIUM = false; + static final boolean CUSTOM_SODIUM = true; static final String MC_VERSION = "1.20.2"; - static final String customSodiumName = "sodium-fabric-mc1.20.2-rc2-0.5.3+git.63b0ad2.jar"; + static final String customSodiumName = "sodium-fabric-mc1.20.2-0.5.3+git.e228d59.jar"; private static final String[] SOURCE_SETS = new String[] { "main", diff --git a/src/main/java/net/coderbot/iris/mixin/vertices/MixinBufferBuilder.java b/src/main/java/net/coderbot/iris/mixin/vertices/MixinBufferBuilder.java index 5b8ae15471..00b477e7ff 100644 --- a/src/main/java/net/coderbot/iris/mixin/vertices/MixinBufferBuilder.java +++ b/src/main/java/net/coderbot/iris/mixin/vertices/MixinBufferBuilder.java @@ -7,7 +7,11 @@ import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.blaze3d.vertex.VertexFormat; import com.mojang.blaze3d.vertex.VertexFormatElement; +import net.caffeinemc.mods.sodium.api.vertex.attributes.CommonVertexAttribute; +import net.caffeinemc.mods.sodium.api.vertex.format.VertexFormatDescription; +import net.caffeinemc.mods.sodium.api.vertex.format.VertexFormatRegistry; import net.coderbot.iris.block_rendering.BlockRenderingSettings; +import net.coderbot.iris.compat.sodium.impl.vertex_format.IrisCommonVertexAttributes; import org.joml.Vector3f; import net.coderbot.iris.vertices.NormI8; import org.jetbrains.annotations.NotNull; @@ -19,6 +23,7 @@ import net.coderbot.iris.vertices.IrisVertexFormats; import net.coderbot.iris.vertices.NormalHelper; import org.jetbrains.annotations.Nullable; +import org.lwjgl.system.MemoryUtil; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; @@ -94,15 +99,9 @@ public abstract class MixinBufferBuilder extends DefaultedVertexConsumer impleme @Shadow public abstract void begin(VertexFormat.Mode drawMode, VertexFormat vertexFormat); - @Shadow - public abstract void putShort(int i, short s); - @Shadow protected abstract void switchFormat(VertexFormat arg); - @Shadow - public abstract void nextElement(); - @Override public void iris$beginWithoutExtending(VertexFormat.Mode drawMode, VertexFormat vertexFormat) { iris$shouldNotExtend = true; @@ -171,12 +170,35 @@ public abstract class MixinBufferBuilder extends DefaultedVertexConsumer impleme vertexCount = 0; } + @Unique + private int uv1Offset, normalOffset, tangentOffset, midTexOffset, midBlockOffset, blockIdOffset, entityIdOffset; + @Inject(method = "switchFormat", at = @At("RETURN")) private void iris$preventHardcodedVertexWriting(VertexFormat format, CallbackInfo ci) { if (!extending) { return; } + VertexFormatDescription formatDescription = VertexFormatRegistry.instance() + .get(format); + + this.uv1Offset = formatDescription.getElementOffset(CommonVertexAttribute.OVERLAY); + this.normalOffset = formatDescription.getElementOffset(CommonVertexAttribute.NORMAL); + if (formatDescription.containsElement(IrisCommonVertexAttributes.TANGENT)) { + this.tangentOffset = formatDescription.getElementOffset(IrisCommonVertexAttributes.TANGENT); + } + if (formatDescription.containsElement(IrisCommonVertexAttributes.MID_TEX_COORD)) { + this.midTexOffset = formatDescription.getElementOffset(IrisCommonVertexAttributes.MID_TEX_COORD); + } + if (formatDescription.containsElement(IrisCommonVertexAttributes.BLOCK_ID)) { + this.blockIdOffset = formatDescription.getElementOffset(IrisCommonVertexAttributes.BLOCK_ID); + } + if (formatDescription.containsElement(IrisCommonVertexAttributes.ENTITY_ID)) { + this.entityIdOffset = formatDescription.getElementOffset(IrisCommonVertexAttributes.ENTITY_ID); + } + if (formatDescription.containsElement(IrisCommonVertexAttributes.MID_BLOCK)) { + this.midBlockOffset = formatDescription.getElementOffset(IrisCommonVertexAttributes.MID_BLOCK); + } fastFormat = false; fullFormat = false; } @@ -188,38 +210,29 @@ public abstract class MixinBufferBuilder extends DefaultedVertexConsumer impleme } if (injectNormalAndUV1 && currentElement == DefaultVertexFormat.ELEMENT_NORMAL) { - this.putInt(0, 0); - this.nextElement(); + MemoryUtil.memPutInt(MemoryUtil.memAddress(buffer, nextElementByte + uv1Offset), 0); } if (iris$isTerrain) { // ENTITY_ELEMENT - this.putShort(0, currentBlock); - this.putShort(2, currentRenderType); + long offset = MemoryUtil.memAddress(buffer, nextElementByte + blockIdOffset); + MemoryUtil.memPutShort(offset, currentBlock); + MemoryUtil.memPutShort(offset + 2, currentRenderType); } else { // ENTITY_ELEMENT - this.putShort(0, (short) CapturedRenderingState.INSTANCE.getCurrentRenderedEntity()); - this.putShort(2, (short) CapturedRenderingState.INSTANCE.getCurrentRenderedBlockEntity()); - this.putShort(4, (short) CapturedRenderingState.INSTANCE.getCurrentRenderedItem()); + long offset = MemoryUtil.memAddress(buffer, nextElementByte + entityIdOffset); + MemoryUtil.memPutShort(offset, (short) CapturedRenderingState.INSTANCE.getCurrentRenderedEntity()); + MemoryUtil.memPutShort(offset + 2, (short) CapturedRenderingState.INSTANCE.getCurrentRenderedBlockEntity()); + MemoryUtil.memPutShort(offset + 4, (short) CapturedRenderingState.INSTANCE.getCurrentRenderedItem()); } - this.nextElement(); - - // MID_TEXTURE_ELEMENT - this.putFloat(0, 0); - this.putFloat(4, 0); - this.nextElement(); - // TANGENT_ELEMENT - this.putInt(0, 0); - this.nextElement(); if (iris$isTerrain) { // MID_BLOCK_ELEMENT - int posIndex = this.nextElementByte - 48; - float x = buffer.getFloat(posIndex); - float y = buffer.getFloat(posIndex + 4); - float z = buffer.getFloat(posIndex + 8); - this.putInt(0, ExtendedDataHelper.computeMidBlock(x, y, z, currentLocalPosX, currentLocalPosY, currentLocalPosZ)); - this.nextElement(); + long bufferIndex = MemoryUtil.memAddress(buffer, nextElementByte); + float x = MemoryUtil.memGetFloat(bufferIndex); + float y = MemoryUtil.memGetFloat(bufferIndex + 4); + float z = MemoryUtil.memGetFloat(bufferIndex + 8); + MemoryUtil.memPutInt(MemoryUtil.memAddress(buffer, nextElementByte + midBlockOffset), ExtendedDataHelper.computeMidBlock(x, y, z, currentLocalPosX, currentLocalPosY, currentLocalPosZ)); } vertexCount++; @@ -235,7 +248,9 @@ private void fillExtendedData(int vertexAmount) { int stride = format.getVertexSize(); - polygon.setup(buffer, nextElementByte, stride, vertexAmount); + int offset = nextElementByte + stride; + + polygon.setup(buffer, offset, stride, vertexAmount); float midU = 0; float midV = 0; @@ -268,13 +283,13 @@ private void fillExtendedData(int vertexAmount) { // NormalHelper.computeFaceNormalTri(normal, polygon); // Removed to enable smooth shaded triangles. Mods rendering triangles with bad normals need to recalculate their normals manually or otherwise shading might be inconsistent. for (int vertex = 0; vertex < vertexAmount; vertex++) { - int packedNormal = buffer.getInt(nextElementByte - normalOffset - stride * vertex); // retrieve per-vertex normal + int packedNormal = buffer.getInt(offset - normalOffset - stride * vertex); // retrieve per-vertex normal int tangent = NormalHelper.computeTangentSmooth(NormI8.unpackX(packedNormal), NormI8.unpackY(packedNormal), NormI8.unpackZ(packedNormal), polygon); - buffer.putFloat(nextElementByte - midUOffset - stride * vertex, midU); - buffer.putFloat(nextElementByte - midVOffset - stride * vertex, midV); - buffer.putInt(nextElementByte - tangentOffset - stride * vertex, tangent); + buffer.putFloat(offset - midUOffset - stride * vertex, midU); + buffer.putFloat(offset - midVOffset - stride * vertex, midV); + buffer.putInt(offset - tangentOffset - stride * vertex, tangent); } } else { NormalHelper.computeFaceNormal(normal, polygon); @@ -282,10 +297,10 @@ private void fillExtendedData(int vertexAmount) { int tangent = NormalHelper.computeTangent(normal.x, normal.y, normal.z, polygon); for (int vertex = 0; vertex < vertexAmount; vertex++) { - buffer.putFloat(nextElementByte - midUOffset - stride * vertex, midU); - buffer.putFloat(nextElementByte - midVOffset - stride * vertex, midV); - buffer.putInt(nextElementByte - normalOffset - stride * vertex, packedNormal); - buffer.putInt(nextElementByte - tangentOffset - stride * vertex, tangent); + buffer.putFloat(offset - midUOffset - stride * vertex, midU); + buffer.putFloat(offset - midVOffset - stride * vertex, midV); + buffer.putInt(offset - normalOffset - stride * vertex, packedNormal); + buffer.putInt(offset - tangentOffset - stride * vertex, tangent); } } } @@ -307,9 +322,4 @@ public void endBlock() { this.currentLocalPosY = 0; this.currentLocalPosZ = 0; } - - @Unique - private void putInt(int i, int value) { - this.buffer.putInt(this.nextElementByte + i, value); - } } diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/IrisCommonVertexAttributes.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/IrisCommonVertexAttributes.java index a2febf0126..020ca51936 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/IrisCommonVertexAttributes.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/IrisCommonVertexAttributes.java @@ -9,5 +9,6 @@ public class IrisCommonVertexAttributes { public static CommonVertexAttribute TANGENT; public static CommonVertexAttribute MID_TEX_COORD; public static CommonVertexAttribute BLOCK_ID; + public static CommonVertexAttribute ENTITY_ID; public static CommonVertexAttribute MID_BLOCK; } diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/EntityVertex.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/EntityVertex.java index 99dc7ed331..bed3f4274b 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/EntityVertex.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/EntityVertex.java @@ -95,12 +95,10 @@ public static void writeQuadVertices(VertexBufferWriter writer, PoseStack.Pose m long ptr = buffer; // The packed normal vector - var n = quad.getNormal(); - - // The normal vector - float nx = NormI8.unpackX(n); - float ny = NormI8.unpackY(n); - float nz = NormI8.unpackZ(n); + var n = quad.getLightFace().step(); + float nx = n.x; + float ny = n.y; + float nz = n.z; float midU = ((quad.getTexU(0) + quad.getTexU(1) + quad.getTexU(2) + quad.getTexU(3)) * 0.25f); float midV = ((quad.getTexV(0) + quad.getTexV(1) + quad.getTexV(2) + quad.getTexV(3)) * 0.25f); diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/GlyphVertexExt.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/GlyphVertexExt.java index 618d9d7fc8..ca438be236 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/GlyphVertexExt.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/GlyphVertexExt.java @@ -102,12 +102,10 @@ public static void writeQuadVertices(VertexBufferWriter writer, PoseStack.Pose m long ptr = buffer; // The packed normal vector - var n = quad.getNormal(); - - // The normal vector - float nx = NormI8.unpackX(n); - float ny = NormI8.unpackY(n); - float nz = NormI8.unpackZ(n); + var n = quad.getLightFace().step(); + float nx = n.x; + float ny = n.y; + float nz = n.z; // The transformed normal vector float nxt = (matNormal.m00() * nx) + (matNormal.m10() * ny) + (matNormal.m20() * nz); diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/copyEntity/ModelPartMixin.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/copyEntity/ModelPartMixin.java index a5c2885e0f..af28bf8eb6 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/copyEntity/ModelPartMixin.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/copyEntity/ModelPartMixin.java @@ -3,37 +3,63 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; import me.jellysquid.mods.sodium.client.model.ModelCuboidAccessor; -import me.jellysquid.mods.sodium.client.render.vertex.VertexConsumerUtils; +import me.jellysquid.mods.sodium.client.render.immediate.model.EntityRenderer; import me.jellysquid.mods.sodium.client.render.immediate.model.ModelCuboid; -import net.caffeinemc.mods.sodium.api.vertex.format.common.ModelVertex; -import net.caffeinemc.mods.sodium.api.util.ColorABGR; +import me.jellysquid.mods.sodium.client.render.immediate.model.ModelPartData; +import me.jellysquid.mods.sodium.client.render.vertex.VertexConsumerUtils; import net.caffeinemc.mods.sodium.api.math.MatrixHelper; +import net.caffeinemc.mods.sodium.api.util.ColorABGR; +import net.caffeinemc.mods.sodium.api.vertex.buffer.VertexBufferWriter; import net.minecraft.client.model.geom.ModelPart; -import org.lwjgl.system.MemoryStack; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.*; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import java.util.Collections; import java.util.List; import java.util.Map; @Mixin(ModelPart.class) -public class ModelPartMixin { - @Shadow public float x; - @Shadow public float y; - @Shadow public float z; +public class ModelPartMixin implements ModelPartData { + @Shadow + public float x; + @Shadow + public float y; + @Shadow + public float z; + + @Shadow + public float xScale; + @Shadow + public float yScale; + @Shadow + public float zScale; + + @Shadow + public float yRot; + @Shadow + public float xRot; + @Shadow + public float zRot; + + @Shadow + public boolean visible; + @Shadow + public boolean skipDraw; + + @Mutable + @Shadow + @Final + private List cubes; + + @Mutable + @Shadow + @Final + private Map children; - @Shadow public float yRot; - @Shadow public float xRot; - @Shadow public float zRot; - - @Shadow public float xScale; - @Shadow public float yScale; - @Shadow public float zScale; + @Unique + private ModelPart[] sodium$children; @Unique private ModelCuboid[] sodium$cuboids; @@ -48,52 +74,25 @@ private void onInit(List cuboids, Map childre } this.sodium$cuboids = copies; + this.sodium$children = children.values() + .toArray(ModelPart[]::new); + + // Try to catch errors caused by mods touching the collections after we've copied everything. + this.cubes = Collections.unmodifiableList(this.cubes); + this.children = Collections.unmodifiableMap(this.children); } - /** - * @author JellySquid - * @reason Use optimized vertex writer, avoid allocations, use quick matrix transformations - */ - @Inject(method = "compile", at = @At("HEAD"), cancellable = true) - private void renderCuboidsFast(PoseStack.Pose matrices, VertexConsumer vertexConsumer, int light, int overlay, float red, float green, float blue, float alpha, CallbackInfo ci) { - var writer = VertexConsumerUtils.convertOrLog(vertexConsumer); - if(writer == null) { + @Inject(method = "render(Lcom/mojang/blaze3d/vertex/PoseStack;Lcom/mojang/blaze3d/vertex/VertexConsumer;IIFFFF)V", at = @At("HEAD"), cancellable = true) + private void onRender(PoseStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha, CallbackInfo ci) { + VertexBufferWriter writer = VertexConsumerUtils.convertOrLog(vertices); + + if (writer == null) { return; } ci.cancel(); - int color = ColorABGR.pack(red, green, blue, alpha); - - for (ModelCuboid cuboid : this.sodium$cuboids) { - cuboid.updateVertices(matrices.pose()); - - try (MemoryStack stack = MemoryStack.stackPush()) { - long buffer = stack.nmalloc(4 * 6 * ModelVertex.STRIDE); - long ptr = buffer; - - int count = 0; - - for (ModelCuboid.Quad quad : cuboid.quads) { - if (quad == null) continue; - - var normal = quad.getNormal(matrices.normal()); - - for (int i = 0; i < 4; i++) { - var pos = quad.positions[i]; - var tex = quad.textures[i]; - - ModelVertex.write(ptr, pos.x, pos.y, pos.z, color, tex.x, tex.y, overlay, light, normal); - - ptr += ModelVertex.STRIDE; - } - - count += 4; - } - - writer.push(stack, buffer, count, ModelVertex.FORMAT); - } - } + EntityRenderer.render(matrices, writer, (ModelPart) (Object) this, light, overlay, ColorABGR.pack(red, green, blue, alpha)); } /** @@ -101,15 +100,37 @@ private void renderCuboidsFast(PoseStack.Pose matrices, VertexConsumer vertexCon * @reason Apply transform more quickly */ @Overwrite - public void translateAndRotate(PoseStack matrices) { - matrices.translate(this.x * (1.0F / 16.0F), this.y * (1.0F / 16.0F), this.z * (1.0F / 16.0F)); + public void translateAndRotate(PoseStack matrixStack) { + if (this.x != 0.0F || this.y != 0.0F || this.z != 0.0F) { + matrixStack.translate(this.x * (1.0f / 16.0f), this.y * (1.0f / 16.0f), this.z * (1.0f / 16.0f)); + } if (this.xRot != 0.0F || this.yRot != 0.0F || this.zRot != 0.0F) { - MatrixHelper.rotateZYX(matrices.last(), this.zRot, this.yRot, this.xRot); + MatrixHelper.rotateZYX(matrixStack.last(), this.zRot, this.yRot, this.xRot); } if (this.xScale != 1.0F || this.yScale != 1.0F || this.zScale != 1.0F) { - matrices.scale(this.xScale, this.yScale, this.zScale); + matrixStack.scale(this.xScale, this.yScale, this.zScale); } } + + @Override + public ModelCuboid[] getCuboids() { + return this.sodium$cuboids; + } + + @Override + public boolean isVisible() { + return this.visible; + } + + @Override + public boolean isHidden() { + return this.skipDraw; + } + + @Override + public ModelPart[] getChildren() { + return this.sodium$children; + } } diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/copyEntity/shadows/EntityRenderDispatcherMixin.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/copyEntity/shadows/EntityRenderDispatcherMixin.java index b7add70524..93d46e7306 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/copyEntity/shadows/EntityRenderDispatcherMixin.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/copyEntity/shadows/EntityRenderDispatcherMixin.java @@ -15,6 +15,7 @@ import net.minecraft.client.renderer.entity.EntityRenderDispatcher; import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.block.RenderShape; import net.minecraft.world.level.block.state.BlockState; @@ -93,7 +94,7 @@ private static void renderShadowPart(PoseStack.Pose matrices, VertexConsumer ver var matPosition = matrices.pose(); var color = ColorABGR.withAlpha(SHADOW_COLOR, alpha); - var normal = MatrixHelper.transformNormal(matNormal, 0.0f, 1.0f, 0.0f); + var normal = MatrixHelper.transformNormal(matNormal, Direction.UP); boolean extended = shouldBeExtended(); diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/fast_render/MixinCube.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/fast_render/MixinCube.java deleted file mode 100644 index 00dda413b4..0000000000 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/fast_render/MixinCube.java +++ /dev/null @@ -1,28 +0,0 @@ -package net.coderbot.iris.compat.sodium.mixin.fast_render; - -import me.jellysquid.mods.sodium.client.model.ModelCuboidAccessor; -import me.jellysquid.mods.sodium.client.render.immediate.model.ModelCuboid; -import net.minecraft.client.model.geom.ModelPart; -import net.minecraft.core.Direction; -import org.objectweb.asm.Opcodes; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.util.Set; - -@Mixin(ModelPart.Cube.class) -public class MixinCube implements ModelCuboidAccessor { - private ModelCuboid sodium$cuboid; - - @Inject(method = "", at = @At(value = "FIELD", opcode = Opcodes.PUTFIELD, target = "Lnet/minecraft/client/model/geom/ModelPart$Cube;polygons:[Lnet/minecraft/client/model/geom/ModelPart$Polygon;", ordinal = 0)) - private void onInit(int u, int v, float x, float y, float z, float sizeX, float sizeY, float sizeZ, float extraX, float extraY, float extraZ, boolean mirror, float textureWidth, float textureHeight, Set directions, CallbackInfo ci) { - this.sodium$cuboid = new ModelCuboid(u, v, x, y, z, sizeX, sizeY, sizeZ, extraX, extraY, extraZ, mirror, textureWidth, textureHeight, directions); - } - - @Override - public ModelCuboid sodium$copy() { - return this.sodium$cuboid; - } -} diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/fast_render/MixinModelPart.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/fast_render/MixinModelPart.java deleted file mode 100644 index 4d833e7d34..0000000000 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/fast_render/MixinModelPart.java +++ /dev/null @@ -1,184 +0,0 @@ -package net.coderbot.iris.compat.sodium.mixin.fast_render; - -import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.blaze3d.vertex.VertexConsumer; -import me.jellysquid.mods.sodium.client.model.ModelCuboidAccessor; -import me.jellysquid.mods.sodium.client.render.immediate.model.ModelCuboid; -import net.caffeinemc.mods.sodium.api.util.ColorABGR; -import net.caffeinemc.mods.sodium.api.vertex.buffer.VertexBufferWriter; -import net.caffeinemc.mods.sodium.api.vertex.format.common.ModelVertex; -import net.coderbot.iris.compat.sodium.impl.vertex_format.entity_xhfp.EntityVertex; -import net.coderbot.iris.vertices.ImmediateState; -import net.coderbot.iris.vertices.NormI8; -import net.irisshaders.iris.api.v0.IrisApi; -import net.minecraft.client.model.geom.ModelPart; -import org.lwjgl.system.MemoryStack; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.util.List; -import java.util.Map; - -@Mixin(ModelPart.class) -public class MixinModelPart { - private ModelCuboid[] sodium$cuboids; - - private static float rsqrt(float value) { - if (value == 0.0f) { - // You heard it here first, folks: 1 divided by 0 equals 1 - // In actuality, this is a workaround for normalizing a zero length vector (leaving it as zero length) - return 1.0f; - } else { - return (float) (1.0 / Math.sqrt(value)); - } - } - - private static boolean shouldExtend() { - return IrisApi.getInstance().isShaderPackInUse() && ImmediateState.renderWithExtendedVertexFormat; - } - - @Inject(method = "", at = @At("RETURN")) - private void onInit(List cuboids, Map children, CallbackInfo ci) { - var copies = new ModelCuboid[cuboids.size()]; - - for (int i = 0; i < cuboids.size(); i++) { - var accessor = (ModelCuboidAccessor) cuboids.get(i); - copies[i] = accessor.sodium$copy(); - } - - this.sodium$cuboids = copies; - } - - /** - * @author JellySquid - * @reason Use optimized vertex writer, avoid allocations, use quick matrix transformations - */ - @Overwrite - private void compile(PoseStack.Pose matrices, VertexConsumer vertexConsumer, int light, int overlay, float red, float green, float blue, float alpha) { - var writer = VertexBufferWriter.of(vertexConsumer); - int color = ColorABGR.pack(red, green, blue, alpha); - - boolean extend = shouldExtend(); - for (ModelCuboid cuboid : this.sodium$cuboids) { - cuboid.updateVertices(matrices.pose()); - - - try (MemoryStack stack = MemoryStack.stackPush()) { - long buffer = stack.nmalloc(4 * 6 * (extend ? EntityVertex.STRIDE : ModelVertex.STRIDE)); - long ptr = buffer; - - for (ModelCuboid.Quad quad : cuboid.quads) { - if (quad == null) continue; - var normal = quad.getNormal(matrices.normal()); - - float midU = 0, midV = 0; - int tangent = 0; - - if (extend) { - for (int i = 0; i < 4; i++) { - midU += quad.textures[i].x; - midV += quad.textures[i].y; - } - - midU *= 0.25; - midV *= 0.25; - - tangent = getTangent(normal, quad.positions[0].x, quad.positions[0].y, quad.positions[0].z, quad.textures[0].x, quad.textures[0].y, - quad.positions[1].x, quad.positions[1].y, quad.positions[1].z, quad.textures[1].x, quad.textures[1].y, - quad.positions[2].x, quad.positions[2].y, quad.positions[2].z, quad.textures[2].x, quad.textures[2].y - ); - } - - for (int i = 0; i < 4; i++) { - var pos = quad.positions[i]; - var tex = quad.textures[i]; - - if (extend) { - EntityVertex.write(ptr, pos.x, pos.y, pos.z, color, tex.x, tex.y, midU, midV, light, overlay, normal, tangent); - } else { - ModelVertex.write(ptr, pos.x, pos.y, pos.z, color, tex.x, tex.y, light, overlay, normal); - } - - ptr += extend ? EntityVertex.STRIDE : ModelVertex.STRIDE; - } - } - - writer.push(stack, buffer, 4 * 6, extend ? EntityVertex.FORMAT : ModelVertex.FORMAT); - } - } - } - - private int getTangent(int normal, float x0, float y0, float z0, float u0, float v0, float x1, float y1, float z1, float u1, float v1, float x2, float y2, float z2, float u2, float v2) { - // Capture all of the relevant vertex positions - - float normalX = NormI8.unpackX(normal); - float normalY = NormI8.unpackY(normal); - float normalZ = NormI8.unpackZ(normal); - - float edge1x = x1 - x0; - float edge1y = y1 - y0; - float edge1z = z1 - z0; - - float edge2x = x2 - x0; - float edge2y = y2 - y0; - float edge2z = z2 - z0; - - float deltaU1 = u1 - u0; - float deltaV1 = v1 - v0; - float deltaU2 = u2 - u0; - float deltaV2 = v2 - v0; - - float fdenom = deltaU1 * deltaV2 - deltaU2 * deltaV1; - float f; - - if (fdenom == 0.0) { - f = 1.0f; - } else { - f = 1.0f / fdenom; - } - - float tangentx = f * (deltaV2 * edge1x - deltaV1 * edge2x); - float tangenty = f * (deltaV2 * edge1y - deltaV1 * edge2y); - float tangentz = f * (deltaV2 * edge1z - deltaV1 * edge2z); - float tcoeff = rsqrt(tangentx * tangentx + tangenty * tangenty + tangentz * tangentz); - tangentx *= tcoeff; - tangenty *= tcoeff; - tangentz *= tcoeff; - - float bitangentx = f * (-deltaU2 * edge1x + deltaU1 * edge2x); - float bitangenty = f * (-deltaU2 * edge1y + deltaU1 * edge2y); - float bitangentz = f * (-deltaU2 * edge1z + deltaU1 * edge2z); - float bitcoeff = rsqrt(bitangentx * bitangentx + bitangenty * bitangenty + bitangentz * bitangentz); - bitangentx *= bitcoeff; - bitangenty *= bitcoeff; - bitangentz *= bitcoeff; - - // predicted bitangent = tangent × normal - // Compute the determinant of the following matrix to get the cross product - // i j k - // tx ty tz - // nx ny nz - - // Be very careful when writing out complex multi-step calculations - // such as vector cross products! The calculation for pbitangentz - // used to be broken because it multiplied values in the wrong order. - - float pbitangentx = tangenty * normalZ - tangentz * normalY; - float pbitangenty = tangentz * normalX - tangentx * normalZ; - float pbitangentz = tangentx * normalY - tangenty * normalX; - - float dot = (bitangentx * pbitangentx) + (bitangenty * pbitangenty) + (bitangentz * pbitangentz); - float tangentW; - - if (dot < 0) { - tangentW = -1.0F; - } else { - tangentW = 1.0F; - } - - return NormI8.pack(tangentx, tangenty, tangentz, tangentW); - } -} diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/MixinCommonVertexAttributes.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/MixinCommonVertexAttributes.java index 99e941e004..4742e86d88 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/MixinCommonVertexAttributes.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/MixinCommonVertexAttributes.java @@ -40,13 +40,16 @@ public class MixinCommonVertexAttributes { = CommonVertexAttributeAccessor.createCommonVertexElement("MID_TEX_COORD", baseOrdinal + 1, IrisVertexFormats.MID_TEXTURE_ELEMENT); IrisCommonVertexAttributes.BLOCK_ID = CommonVertexAttributeAccessor.createCommonVertexElement("BLOCK_ID", baseOrdinal + 2, IrisVertexFormats.ENTITY_ELEMENT); + IrisCommonVertexAttributes.ENTITY_ID + = CommonVertexAttributeAccessor.createCommonVertexElement("ENTITY_ID", baseOrdinal + 3, IrisVertexFormats.ENTITY_ID_ELEMENT); IrisCommonVertexAttributes.MID_BLOCK - = CommonVertexAttributeAccessor.createCommonVertexElement("MID_BLOCK", baseOrdinal + 3, IrisVertexFormats.MID_BLOCK_ELEMENT); + = CommonVertexAttributeAccessor.createCommonVertexElement("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/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/entity/MixinEntityRenderDispatcher.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/entity/MixinEntityRenderDispatcher.java index f100803fd9..e94fcda9c5 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/entity/MixinEntityRenderDispatcher.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/entity/MixinEntityRenderDispatcher.java @@ -13,6 +13,7 @@ import net.minecraft.client.renderer.LightTexture; import net.minecraft.client.renderer.entity.EntityRenderDispatcher; import net.minecraft.client.renderer.texture.OverlayTexture; +import net.minecraft.core.Direction; import org.joml.Matrix4f; import org.lwjgl.system.MemoryStack; import org.spongepowered.asm.mixin.Mixin; @@ -42,7 +43,7 @@ private static void renderShadowPart(PoseStack.Pose matrices, VertexConsumer ver var matPosition = matrices.pose(); var color = ColorABGR.withAlpha(SHADOW_COLOR, alpha); - var normal = MatrixHelper.transformNormal(matNormal, 0.0f, 1.0f, 0.0f); + var normal = MatrixHelper.transformNormal(matNormal, Direction.UP); boolean extended = shouldBeExtended(); diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/entity/MixinModelVertex.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/entity/MixinModelVertex.java index f70778713e..6a0ff36414 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/entity/MixinModelVertex.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/entity/MixinModelVertex.java @@ -45,7 +45,7 @@ public static void writeQuadVertices(VertexBufferWriter writer, PoseStack.Pose m try { long buffer = stack.nmalloc(144); long ptr = buffer; - int normal = MatrixHelper.transformNormal(matNormal, quad.getNormal()); + int normal = MatrixHelper.transformNormal(matNormal, quad.getLightFace()); for(int i = 0; i < 4; ++i) { float x = quad.getX(i); From 081a836b8db262c245069e5f435954f64cdb6d9f Mon Sep 17 00:00:00 2001 From: IMS212 Date: Sun, 3 Dec 2023 08:54:46 -0800 Subject: [PATCH 19/56] Fixed BB issues --- buildscript/src/main/java/Buildscript.java | 2 +- .../iris/mixin/vertices/MixinBufferBuilder.java | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/buildscript/src/main/java/Buildscript.java b/buildscript/src/main/java/Buildscript.java index 2b147977d8..f6ff3efe43 100644 --- a/buildscript/src/main/java/Buildscript.java +++ b/buildscript/src/main/java/Buildscript.java @@ -46,7 +46,7 @@ public class Buildscript extends SimpleFabricProject { static final boolean SODIUM = true; static final boolean CUSTOM_SODIUM = true; static final String MC_VERSION = "1.20.2"; - static final String customSodiumName = "sodium-fabric-mc1.20.2-0.5.3+git.e228d59.jar"; + static final String customSodiumName = "sodium-fabric-mc1.20.2-0.5.3+git.43e53c4.jar"; private static final String[] SOURCE_SETS = new String[] { "main", diff --git a/src/main/java/net/coderbot/iris/mixin/vertices/MixinBufferBuilder.java b/src/main/java/net/coderbot/iris/mixin/vertices/MixinBufferBuilder.java index 00b477e7ff..486716965e 100644 --- a/src/main/java/net/coderbot/iris/mixin/vertices/MixinBufferBuilder.java +++ b/src/main/java/net/coderbot/iris/mixin/vertices/MixinBufferBuilder.java @@ -182,8 +182,12 @@ public abstract class MixinBufferBuilder extends DefaultedVertexConsumer impleme VertexFormatDescription formatDescription = VertexFormatRegistry.instance() .get(format); - this.uv1Offset = formatDescription.getElementOffset(CommonVertexAttribute.OVERLAY); - this.normalOffset = formatDescription.getElementOffset(CommonVertexAttribute.NORMAL); + if (formatDescription.containsElement(CommonVertexAttribute.OVERLAY)) { + this.uv1Offset = formatDescription.getElementOffset(CommonVertexAttribute.OVERLAY); + } + if (formatDescription.containsElement(CommonVertexAttribute.NORMAL)) { + this.normalOffset = formatDescription.getElementOffset(CommonVertexAttribute.NORMAL); + } if (formatDescription.containsElement(IrisCommonVertexAttributes.TANGENT)) { this.tangentOffset = formatDescription.getElementOffset(IrisCommonVertexAttributes.TANGENT); } @@ -209,8 +213,8 @@ public abstract class MixinBufferBuilder extends DefaultedVertexConsumer impleme return; } - if (injectNormalAndUV1 && currentElement == DefaultVertexFormat.ELEMENT_NORMAL) { - MemoryUtil.memPutInt(MemoryUtil.memAddress(buffer, nextElementByte + uv1Offset), 0); + if (injectNormalAndUV1) { + this.normal(0, 0, 0); } if (iris$isTerrain) { From 9e6465ee7bebb43c23c532e109239f35f4a2f49a Mon Sep 17 00:00:00 2001 From: IMS212 Date: Tue, 5 Dec 2023 16:04:00 -0800 Subject: [PATCH 20/56] Fix build --- buildscript/src/main/java/Buildscript.java | 8 ++++---- src/main/resources/fabric.mod.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/buildscript/src/main/java/Buildscript.java b/buildscript/src/main/java/Buildscript.java index f6ff3efe43..af713fc781 100644 --- a/buildscript/src/main/java/Buildscript.java +++ b/buildscript/src/main/java/Buildscript.java @@ -44,7 +44,7 @@ public class Buildscript extends SimpleFabricProject { static final boolean SODIUM = true; - static final boolean CUSTOM_SODIUM = true; + static final boolean CUSTOM_SODIUM = false; static final String MC_VERSION = "1.20.2"; static final String customSodiumName = "sodium-fabric-mc1.20.2-0.5.3+git.43e53c4.jar"; @@ -101,7 +101,7 @@ public void getModDependencies(ModDependencyCollector d) { jij(d.addMaven(Maven.MAVEN_CENTRAL, new MavenId("io.github.douira:glsl-transformer:2.0.0-pre13"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME)); jij(d.addMaven(Maven.MAVEN_CENTRAL, new MavenId("org.antlr:antlr4-runtime:4.11.1"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME)); - d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "distanthorizons", "2.0.0-a-1.18.2"), ModDependencyFlag.COMPILE); + d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "distanthorizons", "2.0.0-a-1.20.2"), ModDependencyFlag.COMPILE); if (SODIUM) { d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", "fabric-api-base", "0.4.17+93d8cb8253"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); @@ -114,10 +114,10 @@ public void getModDependencies(ModDependencyCollector d) { if (CUSTOM_SODIUM) { d.add(new JavaJarDependency(getProjectDir().resolve("custom_sodium").resolve(customSodiumName).toAbsolutePath(), null, new MavenId("me.jellysquid.mods", "sodium-fabric", customSodiumName.replace("sodium-fabric-", ""))), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); } else { - d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "sodium", "mc1.20.2-0.5.3"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); + d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "sodium", "mc1.20.2-0.5.4"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); } } else { - d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "sodium", "mc1.20.2-0.5.3"), ModDependencyFlag.COMPILE); + d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "sodium", "mc1.20.2-0.5.4"), ModDependencyFlag.COMPILE); } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index cb1b2f39e9..418f34286e 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -46,7 +46,7 @@ "depends": { "fabricloader": ">=0.12.3", "minecraft": "1.20.2", - "sodium": "0.5.3" + "sodium": "0.5.4" }, "breaks": { From 6f19634aca97ac449de20cf1d7cd73a626b7c83b Mon Sep 17 00:00:00 2001 From: IMS212 Date: Tue, 5 Dec 2023 16:16:55 -0800 Subject: [PATCH 21/56] Fix 1.20.3 --- buildscript/src/main/java/Buildscript.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/buildscript/src/main/java/Buildscript.java b/buildscript/src/main/java/Buildscript.java index 809cba7e91..2526a69e5c 100644 --- a/buildscript/src/main/java/Buildscript.java +++ b/buildscript/src/main/java/Buildscript.java @@ -44,8 +44,8 @@ public class Buildscript extends SimpleFabricProject { static final boolean SODIUM = true; - static final boolean CUSTOM_SODIUM = true; - static final String MC_VERSION = "1.20.3-pre1"; + static final boolean CUSTOM_SODIUM = false; + static final String MC_VERSION = "1.20.3"; static final String customSodiumName = "sodium-fabric-mc23w45a-0.5.3git.86b69d2-dirty.jar"; private static final String[] SOURCE_SETS = new String[] { @@ -71,7 +71,7 @@ public MappingTree createMappings() { @Override public FabricLoader getLoader() { - return new FabricLoader(FabricMaven.URL, FabricMaven.loader("0.14.22")); + return new FabricLoader(FabricMaven.URL, FabricMaven.loader("0.14.24")); } @Override @@ -101,6 +101,7 @@ public void getModDependencies(ModDependencyCollector d) { jij(d.addMaven(Maven.MAVEN_CENTRAL, new MavenId("io.github.douira:glsl-transformer:2.0.0-pre13"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME)); jij(d.addMaven(Maven.MAVEN_CENTRAL, new MavenId("org.antlr:antlr4-runtime:4.11.1"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME)); + d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "distanthorizons", "2.0.0-a-1.18.2"), ModDependencyFlag.COMPILE); if (SODIUM) { d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", "fabric-api-base", "0.4.17+93d8cb8253"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); @@ -113,10 +114,10 @@ public void getModDependencies(ModDependencyCollector d) { if (CUSTOM_SODIUM) { d.add(new JavaJarDependency(getProjectDir().resolve("custom_sodium").resolve(customSodiumName).toAbsolutePath(), null, new MavenId("me.jellysquid.mods", "sodium-fabric", customSodiumName.replace("sodium-fabric-", ""))), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); } else { - d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "sodium", "mc1.20.2-0.5.3"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); + d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "sodium", "mc1.20.3-0.5.4"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); } } else { - d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "sodium", "mc1.20.2-0.5.3"), ModDependencyFlag.COMPILE); + d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "sodium", "mc1.20.3-0.5.4"), ModDependencyFlag.COMPILE); } } From 2e5ed767b19a5dbe95b01e6492f209c3bbdc642a Mon Sep 17 00:00:00 2001 From: IMS212 Date: Wed, 6 Dec 2023 05:08:07 -0800 Subject: [PATCH 22/56] Fix UV2 override, 1.6.12 --- .../coderbot/iris/mixin/vertices/MixinBufferBuilder.java | 6 ------ src/main/resources/fabric.mod.json | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/main/java/net/coderbot/iris/mixin/vertices/MixinBufferBuilder.java b/src/main/java/net/coderbot/iris/mixin/vertices/MixinBufferBuilder.java index 486716965e..1402a9893a 100644 --- a/src/main/java/net/coderbot/iris/mixin/vertices/MixinBufferBuilder.java +++ b/src/main/java/net/coderbot/iris/mixin/vertices/MixinBufferBuilder.java @@ -138,12 +138,6 @@ public abstract class MixinBufferBuilder extends DefaultedVertexConsumer impleme } } - @Override - public @NotNull VertexConsumer uv2(int pBufferVertexConsumer0, int pInt1) { - - return BufferVertexConsumer.super.uv2(pBufferVertexConsumer0, pInt1); - } - @ModifyArg(method = "begin", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/BufferBuilder;switchFormat(Lcom/mojang/blaze3d/vertex/VertexFormat;)V")) private VertexFormat iris$afterBeginSwitchFormat(VertexFormat arg) { if (extending) { diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 418f34286e..239048e484 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,7 +1,7 @@ { "schemaVersion": 1, "id": "iris", - "version": "1.6.11-development-environment", + "version": "1.6.12-development-environment", "name": "Iris", "description": "A modern shaders mod for Minecraft intended to be compatible with existing OptiFine shader packs", From c1eaf73033af5c3c785099c84ff343e3580378f9 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Thu, 7 Dec 2023 07:40:57 -0800 Subject: [PATCH 23/56] 1.20.4 --- buildscript/src/main/java/Buildscript.java | 2 +- src/main/resources/fabric.mod.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/buildscript/src/main/java/Buildscript.java b/buildscript/src/main/java/Buildscript.java index 2526a69e5c..f4c3c1aa91 100644 --- a/buildscript/src/main/java/Buildscript.java +++ b/buildscript/src/main/java/Buildscript.java @@ -45,7 +45,7 @@ public class Buildscript extends SimpleFabricProject { static final boolean SODIUM = true; static final boolean CUSTOM_SODIUM = false; - static final String MC_VERSION = "1.20.3"; + static final String MC_VERSION = "1.20.4"; static final String customSodiumName = "sodium-fabric-mc23w45a-0.5.3git.86b69d2-dirty.jar"; private static final String[] SOURCE_SETS = new String[] { diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 1e980911b2..4ffb60417f 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -45,7 +45,7 @@ "depends": { "fabricloader": ">=0.12.3", - "minecraft": "1.20.3", + "minecraft": ["1.20.3", "1.20.4"], "sodium": "0.5.4" }, From 7eb51e772d3ab4a0f44db857e6e7d8ed26694ec1 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Thu, 7 Dec 2023 08:34:57 -0800 Subject: [PATCH 24/56] Remove offending code --- .../entity/MixinEntityRenderDispatcher.java | 66 ------------------- 1 file changed, 66 deletions(-) diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/entity/MixinEntityRenderDispatcher.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/entity/MixinEntityRenderDispatcher.java index e94fcda9c5..cf7082bbb0 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/entity/MixinEntityRenderDispatcher.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/entity/MixinEntityRenderDispatcher.java @@ -29,72 +29,6 @@ public class MixinEntityRenderDispatcher { * @author IMS * @reason Overwrite shadow rendering with our own */ - @Overwrite(remap = false) - private static void renderShadowPart(PoseStack.Pose matrices, VertexConsumer vertices, float radius, float alpha, float minX, float maxX, float minY, float minZ, float maxZ) { - float size = 0.5F * (1.0F / radius); - - float u1 = (-minX * size) + 0.5F; - float u2 = (-maxX * size) + 0.5F; - - float v1 = (-minZ * size) + 0.5F; - float v2 = (-maxZ * size) + 0.5F; - - var matNormal = matrices.normal(); - var matPosition = matrices.pose(); - - var color = ColorABGR.withAlpha(SHADOW_COLOR, alpha); - var normal = MatrixHelper.transformNormal(matNormal, Direction.UP); - - boolean extended = shouldBeExtended(); - - int tangent = 0; - - if (extended) { - tangent = getTangent(normal, minX, minY, minZ, u1, v1, - minX, minY, maxZ, u1, v2, - maxX, minY, maxZ, u2, v2 - ); - } - - float midU = (u1 + u2) / 2; - float midV = (v1 + v2) / 2; - - int stride = extended ? EntityVertex.STRIDE : ModelVertex.STRIDE; - try (MemoryStack stack = MemoryStack.stackPush()) { - long buffer = stack.nmalloc(4 * stride); - long ptr = buffer; - - if (extended) { - writeShadowVertexIris(ptr, matPosition, minX, minY, minZ, u1, v1, color, midU, midV, normal, tangent); - ptr += stride; - - writeShadowVertexIris(ptr, matPosition, minX, minY, maxZ, u1, v2, color, midU, midV, normal, tangent); - ptr += stride; - - writeShadowVertexIris(ptr, matPosition, maxX, minY, maxZ, u2, v2, color, midU, midV, normal, tangent); - ptr += stride; - - writeShadowVertexIris(ptr, matPosition, maxX, minY, minZ, u2, v1, color, midU, midV, normal, tangent); - ptr += stride; - } else { - writeShadowVertex(ptr, matPosition, minX, minY, minZ, u1, v1, color, normal); - ptr += stride; - - writeShadowVertex(ptr, matPosition, minX, minY, maxZ, u1, v2, color, normal); - ptr += stride; - - writeShadowVertex(ptr, matPosition, maxX, minY, maxZ, u2, v2, color, normal); - ptr += stride; - - writeShadowVertex(ptr, matPosition, maxX, minY, minZ, u2, v1, color, normal); - ptr += stride; - } - - VertexBufferWriter.of(vertices) - .push(stack, buffer, 4, extended ? EntityVertex.FORMAT : ModelVertex.FORMAT); - } - } - private static void writeShadowVertexIris(long ptr, Matrix4f matPosition, float x, float y, float z, float u, float v, int color, float midU, float midV, int normal, int tangent) { // The transformed position vector float xt = MatrixHelper.transformPositionX(matPosition, x, y, z); From 75344defe3d346e5dfb07d947609e641e782e982 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Thu, 7 Dec 2023 08:43:09 -0800 Subject: [PATCH 25/56] Fix entity shadows --- .../shadows/EntityRenderDispatcherMixin.java | 266 +++++------------- 1 file changed, 73 insertions(+), 193 deletions(-) diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/copyEntity/shadows/EntityRenderDispatcherMixin.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/copyEntity/shadows/EntityRenderDispatcherMixin.java index 93d46e7306..4d78b1de07 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/copyEntity/shadows/EntityRenderDispatcherMixin.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/copyEntity/shadows/EntityRenderDispatcherMixin.java @@ -2,15 +2,11 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; +import me.jellysquid.mods.sodium.client.render.vertex.VertexConsumerUtils; import net.caffeinemc.mods.sodium.api.vertex.buffer.VertexBufferWriter; import net.caffeinemc.mods.sodium.api.vertex.format.common.ModelVertex; import net.caffeinemc.mods.sodium.api.util.ColorABGR; import net.caffeinemc.mods.sodium.api.math.MatrixHelper; -import net.coderbot.iris.compat.sodium.impl.vertex_format.entity_xhfp.EntityVertex; -import net.coderbot.iris.vertices.ImmediateState; -import net.coderbot.iris.vertices.NormI8; -import net.coderbot.iris.vertices.NormalHelper; -import net.irisshaders.iris.api.v0.IrisApi; import net.minecraft.client.renderer.LightTexture; import net.minecraft.client.renderer.entity.EntityRenderDispatcher; import net.minecraft.client.renderer.texture.OverlayTexture; @@ -25,230 +21,114 @@ import org.joml.Matrix4f; import org.lwjgl.system.MemoryStack; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; 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(EntityRenderDispatcher.class) public class EntityRenderDispatcherMixin { - @Unique - private static final int SHADOW_COLOR = ColorABGR.pack(1.0f, 1.0f, 1.0f); - - /** - * @author JellySquid - * @reason Reduce vertex assembly overhead for shadow rendering - */ - @Overwrite - private static void renderBlockShadow(PoseStack.Pose entry, VertexConsumer vertices, ChunkAccess chunk, LevelReader world, BlockPos pos, double x, double y, double z, float radius, float opacity) { - BlockPos blockPos = pos.below(); - BlockState blockState = world.getBlockState(blockPos); - - if (blockState.getRenderShape() == RenderShape.INVISIBLE || !blockState.isCollisionShapeFullBlock(world, blockPos)) { - return; - } - - var light = world.getMaxLocalRawBrightness(pos); - - if (light <= 3) { - return; - } - - VoxelShape voxelShape = blockState.getShape(world, blockPos); - - if (voxelShape.isEmpty()) { - return; - } - - float brightness = LightTexture.getBrightness(world.dimensionType(), light); - float alpha = (float) (((double) opacity - ((y - (double) pos.getY()) / 2.0)) * 0.5 * (double) brightness); + @Unique + private static final int SHADOW_COLOR = ColorABGR.pack(1.0f, 1.0f, 1.0f); + + /** + * @author JellySquid + * @reason Reduce vertex assembly overhead for shadow rendering + */ + @Inject(method = "renderBlockShadow", at = @At("HEAD"), cancellable = true) + private static void renderShadowPartFast(PoseStack.Pose entry, VertexConsumer vertices, ChunkAccess chunk, LevelReader world, BlockPos pos, double x, double y, double z, float radius, float opacity, CallbackInfo ci) { + var writer = VertexConsumerUtils.convertOrLog(vertices); + + if (writer == null) { + return; + } - if (alpha >= 0.0F) { - if (alpha > 1.0F) { - alpha = 1.0F; - } + ci.cancel(); - AABB box = voxelShape.bounds(); + BlockPos blockPos = pos.below(); + BlockState blockState = world.getBlockState(blockPos); - float minX = (float) ((pos.getX() + box.minX) - x); - float maxX = (float) ((pos.getX() + box.maxX) - x); + if (blockState.getRenderShape() == RenderShape.INVISIBLE || !blockState.isCollisionShapeFullBlock(world, blockPos)) { + return; + } - float minY = (float) ((pos.getY() + box.minY) - y); + var light = world.getMaxLocalRawBrightness(pos); - float minZ = (float) ((pos.getZ() + box.minZ) - z); - float maxZ = (float) ((pos.getZ() + box.maxZ) - z); + if (light <= 3) { + return; + } - renderShadowPart(entry, vertices, radius, alpha, minX, maxX, minY, minZ, maxZ); - } - } + VoxelShape voxelShape = blockState.getShape(world, blockPos); - @Unique - private static void renderShadowPart(PoseStack.Pose matrices, VertexConsumer vertices, float radius, float alpha, float minX, float maxX, float minY, float minZ, float maxZ) { - float size = 0.5F * (1.0F / radius); + if (voxelShape.isEmpty()) { + return; + } - float u1 = (-minX * size) + 0.5F; - float u2 = (-maxX * size) + 0.5F; + float brightness = LightTexture.getBrightness(world.dimensionType(), light); + float alpha = (float) (((double) opacity - ((y - (double) pos.getY()) / 2.0)) * 0.5 * (double) brightness); - float v1 = (-minZ * size) + 0.5F; - float v2 = (-maxZ * size) + 0.5F; + if (alpha >= 0.0F) { + if (alpha > 1.0F) { + alpha = 1.0F; + } - var matNormal = matrices.normal(); - var matPosition = matrices.pose(); + AABB box = voxelShape.bounds(); - var color = ColorABGR.withAlpha(SHADOW_COLOR, alpha); - var normal = MatrixHelper.transformNormal(matNormal, Direction.UP); + float minX = (float) ((pos.getX() + box.minX) - x); + float maxX = (float) ((pos.getX() + box.maxX) - x); - boolean extended = shouldBeExtended(); + float minY = (float) ((pos.getY() + box.minY) - y); - int tangent = 0; + float minZ = (float) ((pos.getZ() + box.minZ) - z); + float maxZ = (float) ((pos.getZ() + box.maxZ) - z); - if (extended) { - tangent = getTangent(normal, minX, minY, minZ, u1, v1, - minX, minY, maxZ, u1, v2, - maxX, minY, maxZ, u2, v2 - ); + renderShadowPart(entry, writer, radius, alpha, minX, maxX, minY, minZ, maxZ); } + } - float midU = (u1 + u2) / 2; - float midV = (v1 + v2) / 2; - - int stride = extended ? EntityVertex.STRIDE : ModelVertex.STRIDE; - - try (MemoryStack stack = MemoryStack.stackPush()) { - long buffer = stack.nmalloc(4 * stride); - long ptr = buffer; + @Unique + private static void renderShadowPart(PoseStack.Pose matrices, VertexBufferWriter writer, float radius, float alpha, float minX, float maxX, float minY, float minZ, float maxZ) { + float size = 0.5F * (1.0F / radius); - if (extended) { - writeShadowVertexIris(ptr, matPosition, minX, minY, minZ, u1, v1, color, midU, midV, normal, tangent); - ptr += stride; + float u1 = (-minX * size) + 0.5F; + float u2 = (-maxX * size) + 0.5F; - writeShadowVertexIris(ptr, matPosition, minX, minY, maxZ, u1, v2, color, midU, midV, normal, tangent); - ptr += stride; + float v1 = (-minZ * size) + 0.5F; + float v2 = (-maxZ * size) + 0.5F; - writeShadowVertexIris(ptr, matPosition, maxX, minY, maxZ, u2, v2, color, midU, midV, normal, tangent); - ptr += stride; + var matNormal = matrices.normal(); + var matPosition = matrices.pose(); - writeShadowVertexIris(ptr, matPosition, maxX, minY, minZ, u2, v1, color, midU, midV, normal, tangent); - ptr += stride; - } else { - writeShadowVertex(ptr, matPosition, minX, minY, minZ, u1, v1, color, normal); - ptr += stride; + var color = ColorABGR.withAlpha(SHADOW_COLOR, alpha); + var normal = MatrixHelper.transformNormal(matNormal, Direction.UP); - writeShadowVertex(ptr, matPosition, minX, minY, maxZ, u1, v2, color, normal); - ptr += stride; + try (MemoryStack stack = MemoryStack.stackPush()) { + long buffer = stack.nmalloc(4 * ModelVertex.STRIDE); + long ptr = buffer; - writeShadowVertex(ptr, matPosition, maxX, minY, maxZ, u2, v2, color, normal); - ptr += stride; + writeShadowVertex(ptr, matPosition, minX, minY, minZ, u1, v1, color, normal); + ptr += ModelVertex.STRIDE; - writeShadowVertex(ptr, matPosition, maxX, minY, minZ, u2, v1, color, normal); - ptr += stride; - } + writeShadowVertex(ptr, matPosition, minX, minY, maxZ, u1, v2, color, normal); + ptr += ModelVertex.STRIDE; - VertexBufferWriter.of(vertices) - .push(stack, buffer, 4, ModelVertex.FORMAT); - } - } + writeShadowVertex(ptr, matPosition, maxX, minY, maxZ, u2, v2, color, normal); + ptr += ModelVertex.STRIDE; - @Unique - private static void writeShadowVertex(long ptr, Matrix4f matPosition, float x, float y, float z, float u, float v, int color, int normal) { - // The transformed position vector - float xt = MatrixHelper.transformPositionX(matPosition, x, y, z); - float yt = MatrixHelper.transformPositionY(matPosition, x, y, z); - float zt = MatrixHelper.transformPositionZ(matPosition, x, y, z); + writeShadowVertex(ptr, matPosition, maxX, minY, minZ, u2, v1, color, normal); + ptr += ModelVertex.STRIDE; - ModelVertex.write(ptr, xt, yt, zt, color, u, v, LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY, normal); - } + writer.push(stack, buffer, 4, ModelVertex.FORMAT); + } + } @Unique - private static void writeShadowVertexIris(long ptr, Matrix4f matPosition, float x, float y, float z, float u, float v, int color, float midU, float midV, int normal, int tangent) { + private static void writeShadowVertex(long ptr, Matrix4f matPosition, float x, float y, float z, float u, float v, int color, int normal) { // The transformed position vector float xt = MatrixHelper.transformPositionX(matPosition, x, y, z); float yt = MatrixHelper.transformPositionY(matPosition, x, y, z); float zt = MatrixHelper.transformPositionZ(matPosition, x, y, z); - EntityVertex.write(ptr, xt, yt, zt, color, u, v, midU, midV, OverlayTexture.NO_OVERLAY, LightTexture.FULL_BRIGHT, normal, tangent); - } - - private static boolean shouldBeExtended() { - return IrisApi.getInstance().isShaderPackInUse() && ImmediateState.renderWithExtendedVertexFormat; - } - - private static int getTangent(int normal, float x0, float y0, float z0, float u0, float v0, float x1, float y1, float z1, float u1, float v1, float x2, float y2, float z2, float u2, float v2) { - // Capture all of the relevant vertex positions - - float normalX = NormI8.unpackX(normal); - float normalY = NormI8.unpackY(normal); - float normalZ = NormI8.unpackZ(normal); - - float edge1x = x1 - x0; - float edge1y = y1 - y0; - float edge1z = z1 - z0; - - float edge2x = x2 - x0; - float edge2y = y2 - y0; - float edge2z = z2 - z0; - - float deltaU1 = u1 - u0; - float deltaV1 = v1 - v0; - float deltaU2 = u2 - u0; - float deltaV2 = v2 - v0; - - float fdenom = deltaU1 * deltaV2 - deltaU2 * deltaV1; - float f; - - if (fdenom == 0.0) { - f = 1.0f; - } else { - f = 1.0f / fdenom; - } - - float tangentx = f * (deltaV2 * edge1x - deltaV1 * edge2x); - float tangenty = f * (deltaV2 * edge1y - deltaV1 * edge2y); - float tangentz = f * (deltaV2 * edge1z - deltaV1 * edge2z); - float tcoeff = rsqrt(tangentx * tangentx + tangenty * tangenty + tangentz * tangentz); - tangentx *= tcoeff; - tangenty *= tcoeff; - tangentz *= tcoeff; - - float bitangentx = f * (-deltaU2 * edge1x + deltaU1 * edge2x); - float bitangenty = f * (-deltaU2 * edge1y + deltaU1 * edge2y); - float bitangentz = f * (-deltaU2 * edge1z + deltaU1 * edge2z); - float bitcoeff = rsqrt(bitangentx * bitangentx + bitangenty * bitangenty + bitangentz * bitangentz); - bitangentx *= bitcoeff; - bitangenty *= bitcoeff; - bitangentz *= bitcoeff; - - // predicted bitangent = tangent × normal - // Compute the determinant of the following matrix to get the cross product - // i j k - // tx ty tz - // nx ny nz - - // Be very careful when writing out complex multi-step calculations - // such as vector cross products! The calculation for pbitangentz - // used to be broken because it multiplied values in the wrong order. - - float pbitangentx = tangenty * normalZ - tangentz * normalY; - float pbitangenty = tangentz * normalX - tangentx * normalZ; - float pbitangentz = tangentx * normalY - tangenty * normalX; - - float dot = (bitangentx * pbitangentx) + (bitangenty * pbitangenty) + (bitangentz * pbitangentz); - float tangentW; - - if (dot < 0) { - tangentW = -1.0F; - } else { - tangentW = 1.0F; - } - - return NormI8.pack(tangentx, tangenty, tangentz, tangentW); - } - - private static float rsqrt(float value) { - if (value == 0.0f) { - // You heard it here first, folks: 1 divided by 0 equals 1 - // In actuality, this is a workaround for normalizing a zero length vector (leaving it as zero length) - return 1.0f; - } else { - return (float) (1.0 / Math.sqrt(value)); - } + ModelVertex.write(ptr, xt, yt, zt, color, u, v, LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY, normal); } } From c97653e2938efbbace9cf6efd9743917ae984a1f Mon Sep 17 00:00:00 2001 From: IMS212 Date: Sat, 9 Dec 2023 07:49:05 -0800 Subject: [PATCH 26/56] 1.6.14 --- buildscript/src/main/java/Buildscript.java | 4 ++-- src/main/resources/fabric.mod.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/buildscript/src/main/java/Buildscript.java b/buildscript/src/main/java/Buildscript.java index af713fc781..db98421da1 100644 --- a/buildscript/src/main/java/Buildscript.java +++ b/buildscript/src/main/java/Buildscript.java @@ -114,10 +114,10 @@ public void getModDependencies(ModDependencyCollector d) { if (CUSTOM_SODIUM) { d.add(new JavaJarDependency(getProjectDir().resolve("custom_sodium").resolve(customSodiumName).toAbsolutePath(), null, new MavenId("me.jellysquid.mods", "sodium-fabric", customSodiumName.replace("sodium-fabric-", ""))), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); } else { - d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "sodium", "mc1.20.2-0.5.4"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); + d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "sodium", "mc1.20.2-0.5.5"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); } } else { - d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "sodium", "mc1.20.2-0.5.4"), ModDependencyFlag.COMPILE); + d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "sodium", "mc1.20.2-0.5.5"), ModDependencyFlag.COMPILE); } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 2d83a9dc27..4072883cc0 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,7 +1,7 @@ { "schemaVersion": 1, "id": "iris", - "version": "1.6.13-development-environment", + "version": "1.6.14-development-environment", "name": "Iris", "description": "A modern shaders mod for Minecraft intended to be compatible with existing OptiFine shader packs", @@ -46,7 +46,7 @@ "depends": { "fabricloader": ">=0.12.3", "minecraft": "1.20.2", - "sodium": "0.5.4" + "sodium": "0.5.5" }, "breaks": { From 27d46449f960701fd6ce9a2c03b730ea40008b4c Mon Sep 17 00:00:00 2001 From: IMS212 Date: Tue, 12 Dec 2023 16:38:15 -0800 Subject: [PATCH 27/56] The final boss: Tessellation Shaders --- .../coderbot/iris/gl/shader/ShaderType.java | 4 +- .../iris/mixin/MixinGameRenderer.java | 2 + ...ixinGlStateManager_DepthColorOverride.java | 17 +++++ .../iris/mixin/MixinProgramManager.java | 6 ++ .../coderbot/iris/mixin/MixinProgramType.java | 9 ++- .../iris/mixin/MixinShaderInstance.java | 11 +-- .../DeferredWorldRenderingPipeline.java | 14 +--- .../iris/pipeline/SodiumTerrainPipeline.java | 66 +++++++++++++++++ .../pipeline/newshader/ExtendedShader.java | 47 +++++++++++- .../pipeline/newshader/IrisProgramTypes.java | 2 + .../pipeline/newshader/NewShaderTests.java | 26 ++++++- .../newshader/ShaderInstanceInterface.java | 2 +- .../pipeline/transform/PatchShaderType.java | 6 ++ .../pipeline/transform/TransformPatcher.java | 46 +++++++----- .../coderbot/iris/shaderpack/ProgramSet.java | 8 +- .../iris/shaderpack/ProgramSource.java | 20 ++++- .../include/ShaderPackSourceNames.java | 2 + .../iris/vertices/ImmediateState.java | 3 +- .../IrisChunkProgramOverrides.java | 74 ++++++++++++++++++- .../IrisChunkShaderInterface.java | 9 ++- .../shader_overrides/IrisShaderTypes.java | 2 + .../shader_overrides/MixinChunkProgram.java | 0 .../MixinChunkRenderShaderBackend.java | 0 .../shader_overrides/MixinGlRenderDevice.java | 18 +++++ .../shader_overrides/MixinShaderType.java | 7 +- .../resources/mixins.iris.compat.sodium.json | 1 + 26 files changed, 345 insertions(+), 57 deletions(-) delete mode 100644 src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinChunkProgram.java delete mode 100644 src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinChunkRenderShaderBackend.java create mode 100644 src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinGlRenderDevice.java diff --git a/src/main/java/net/coderbot/iris/gl/shader/ShaderType.java b/src/main/java/net/coderbot/iris/gl/shader/ShaderType.java index 8368c41b22..0bcc1c52f7 100644 --- a/src/main/java/net/coderbot/iris/gl/shader/ShaderType.java +++ b/src/main/java/net/coderbot/iris/gl/shader/ShaderType.java @@ -13,7 +13,9 @@ public enum ShaderType { VERTEX(GL20.GL_VERTEX_SHADER), GEOMETRY(GL32C.GL_GEOMETRY_SHADER), FRAGMENT(GL20.GL_FRAGMENT_SHADER), - COMPUTE(GL43C.GL_COMPUTE_SHADER); + COMPUTE(GL43C.GL_COMPUTE_SHADER), + TESSELATION_CONTROL(GL43C.GL_TESS_CONTROL_SHADER), + TESSELATION_EVAL(GL43C.GL_TESS_EVALUATION_SHADER); public final int id; diff --git a/src/main/java/net/coderbot/iris/mixin/MixinGameRenderer.java b/src/main/java/net/coderbot/iris/mixin/MixinGameRenderer.java index cea7e40e54..511b4ed747 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinGameRenderer.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinGameRenderer.java @@ -66,6 +66,8 @@ public class MixinGameRenderer { private ArrayList iris$reloadGeometryShaders() { ArrayList programs = Lists.newArrayList(); programs.addAll(IrisProgramTypes.GEOMETRY.getPrograms().values()); + programs.addAll(IrisProgramTypes.TESS_CONTROL.getPrograms().values()); + programs.addAll(IrisProgramTypes.TESS_EVAL.getPrograms().values()); return programs; } diff --git a/src/main/java/net/coderbot/iris/mixin/MixinGlStateManager_DepthColorOverride.java b/src/main/java/net/coderbot/iris/mixin/MixinGlStateManager_DepthColorOverride.java index 1581e44318..6834b94547 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinGlStateManager_DepthColorOverride.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinGlStateManager_DepthColorOverride.java @@ -2,9 +2,12 @@ import com.mojang.blaze3d.platform.GlStateManager; import net.coderbot.iris.gl.blending.DepthColorStorage; +import net.coderbot.iris.vertices.ImmediateState; +import org.lwjgl.opengl.GL43C; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(GlStateManager.class) @@ -24,4 +27,18 @@ public class MixinGlStateManager_DepthColorOverride { ci.cancel(); } } + + @Redirect(method = "_drawElements", at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glDrawElements(IIIJ)V")) + private static void iris$modify(int mode, int count, int type, long indices) { + if (mode == GL43C.GL_TRIANGLES && ImmediateState.usingTessellation) { + mode = GL43C.GL_PATCHES; + } + + GL43C.glDrawElements(mode, count, type, indices); + } + + @Inject(method = "_glUseProgram", at = @At("TAIL")) + private static void iris$resetTessellation(int pInt0, CallbackInfo ci) { + ImmediateState.usingTessellation = false; + } } diff --git a/src/main/java/net/coderbot/iris/mixin/MixinProgramManager.java b/src/main/java/net/coderbot/iris/mixin/MixinProgramManager.java index 6768728d96..a41ba8d0a9 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinProgramManager.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinProgramManager.java @@ -15,5 +15,11 @@ public class MixinProgramManager { if (shader instanceof ExtendedShader && ((ExtendedShader) shader).getGeometry() != null) { ((ExtendedShader) shader).getGeometry().close(); } + if (shader instanceof ExtendedShader && ((ExtendedShader) shader).getTessControl() != null) { + ((ExtendedShader) shader).getTessControl().close(); + } + if (shader instanceof ExtendedShader && ((ExtendedShader) shader).getTessEval() != null) { + ((ExtendedShader) shader).getTessEval().close(); + } } } diff --git a/src/main/java/net/coderbot/iris/mixin/MixinProgramType.java b/src/main/java/net/coderbot/iris/mixin/MixinProgramType.java index 5e0bdc5744..44316a1ff2 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinProgramType.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinProgramType.java @@ -4,6 +4,7 @@ import net.coderbot.iris.pipeline.newshader.IrisProgramTypes; import org.apache.commons.lang3.ArrayUtils; import org.lwjgl.opengl.GL32C; +import org.lwjgl.opengl.GL42C; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mutable; @@ -23,6 +24,12 @@ public class MixinProgramType { IrisProgramTypes.GEOMETRY = ProgramTypeAccessor.createProgramType("GEOMETRY", baseOrdinal, "geometry", ".gsh", GL32C.GL_GEOMETRY_SHADER); - $VALUES = ArrayUtils.addAll($VALUES, IrisProgramTypes.GEOMETRY); + IrisProgramTypes.TESS_CONTROL + = ProgramTypeAccessor.createProgramType("TESS_CONTROL", baseOrdinal + 1, "tess_control", ".tcs", GL42C.GL_TESS_CONTROL_SHADER); + + IrisProgramTypes.TESS_EVAL + = ProgramTypeAccessor.createProgramType("TESS_EVAL", baseOrdinal + 2, "tess_eval", ".tes", GL42C.GL_TESS_EVALUATION_SHADER); + + $VALUES = ArrayUtils.addAll($VALUES, IrisProgramTypes.GEOMETRY, IrisProgramTypes.TESS_CONTROL, IrisProgramTypes.TESS_EVAL); } } diff --git a/src/main/java/net/coderbot/iris/mixin/MixinShaderInstance.java b/src/main/java/net/coderbot/iris/mixin/MixinShaderInstance.java index 37d0b46f6c..3baa14ba62 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinShaderInstance.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinShaderInstance.java @@ -4,7 +4,6 @@ import com.mojang.blaze3d.shaders.Uniform; import com.mojang.blaze3d.vertex.VertexFormat; import net.coderbot.iris.Iris; -import net.coderbot.iris.gl.IrisRenderSystem; import net.coderbot.iris.gl.blending.DepthColorStorage; import net.coderbot.iris.pipeline.WorldRenderingPipeline; import net.coderbot.iris.pipeline.newshader.CoreWorldRenderingPipeline; @@ -13,9 +12,6 @@ import net.coderbot.iris.pipeline.newshader.fallback.FallbackShader; import net.minecraft.client.renderer.ShaderInstance; import net.minecraft.server.packs.resources.ResourceProvider; -import org.lwjgl.opengl.ARBTextureSwizzle; -import org.lwjgl.opengl.GL20C; -import org.lwjgl.opengl.GL30C; import org.slf4j.Logger; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -24,9 +20,6 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -import java.util.Objects; @Mixin(ShaderInstance.class) public abstract class MixinShaderInstance implements ShaderInstanceInterface { @@ -85,11 +78,11 @@ private static boolean shouldOverrideShaders() { @Inject(method = "", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/GsonHelper;parse(Ljava/io/Reader;)Lcom/google/gson/JsonObject;")) public void iris$setupGeometryShader(ResourceProvider resourceProvider, String string, VertexFormat vertexFormat, CallbackInfo ci) { - this.iris$createGeometryShader(resourceProvider, string); + this.iris$createExtraShaders(resourceProvider, string); } @Override - public void iris$createGeometryShader(ResourceProvider provider, String name) { + public void iris$createExtraShaders(ResourceProvider provider, String name) { //no-op, used for ExtendedShader to call before the super constructor } } diff --git a/src/main/java/net/coderbot/iris/pipeline/DeferredWorldRenderingPipeline.java b/src/main/java/net/coderbot/iris/pipeline/DeferredWorldRenderingPipeline.java index 858528c985..580f6b5e34 100644 --- a/src/main/java/net/coderbot/iris/pipeline/DeferredWorldRenderingPipeline.java +++ b/src/main/java/net/coderbot/iris/pipeline/DeferredWorldRenderingPipeline.java @@ -684,21 +684,9 @@ private Pass createDefaultPass() { private Pass createPass(ProgramSource source, InputAvailability availability, boolean shadow, ProgramId id) { // TODO: Properly handle empty shaders? - Map transformed = TransformPatcher.patchAttributes( - source.getVertexSource().orElseThrow(NullPointerException::new), - source.getGeometrySource().orElse(null), - source.getFragmentSource().orElseThrow(NullPointerException::new), - availability, customTextureMap); - String vertex = transformed.get(PatchShaderType.VERTEX); - String geometry = transformed.get(PatchShaderType.GEOMETRY); - String fragment = transformed.get(PatchShaderType.FRAGMENT); - ShaderPrinter.printProgram(source.getName()).addSources(transformed).print(); - ProgramBuilder builder = ProgramBuilder.begin(source.getName(), vertex, geometry, fragment, - IrisSamplers.WORLD_RESERVED_TEXTURE_UNITS); - - return createPassInner(builder, source.getParent().getPack().getIdMap(), source.getDirectives(), source.getParent().getPackDirectives(), availability, shadow, id); + return createPassInner(null, source.getParent().getPack().getIdMap(), source.getDirectives(), source.getParent().getPackDirectives(), availability, shadow, id); } private Pass createPassInner(ProgramBuilder builder, IdMap map, ProgramDirectives programDirectives, diff --git a/src/main/java/net/coderbot/iris/pipeline/SodiumTerrainPipeline.java b/src/main/java/net/coderbot/iris/pipeline/SodiumTerrainPipeline.java index 8370e0b8c0..1b014fc10e 100644 --- a/src/main/java/net/coderbot/iris/pipeline/SodiumTerrainPipeline.java +++ b/src/main/java/net/coderbot/iris/pipeline/SodiumTerrainPipeline.java @@ -39,6 +39,8 @@ public class SodiumTerrainPipeline { Optional terrainSolidVertex; Optional terrainSolidGeometry; + Optional terrainSolidTessControl; + Optional terrainSolidTessEval; Optional terrainSolidFragment; GlFramebuffer terrainSolidFramebuffer; BlendModeOverride terrainSolidBlendOverride; @@ -46,6 +48,8 @@ public class SodiumTerrainPipeline { Optional terrainCutoutVertex; Optional terrainCutoutGeometry; + Optional terrainCutoutTessControl; + Optional terrainCutoutTessEval; Optional terrainCutoutFragment; GlFramebuffer terrainCutoutFramebuffer; BlendModeOverride terrainCutoutBlendOverride; @@ -54,6 +58,8 @@ public class SodiumTerrainPipeline { Optional translucentVertex; Optional translucentGeometry; + Optional translucentTessControl; + Optional translucentTessEval; Optional translucentFragment; GlFramebuffer translucentFramebuffer; BlendModeOverride translucentBlendOverride; @@ -62,6 +68,8 @@ public class SodiumTerrainPipeline { Optional shadowVertex; Optional shadowGeometry; + Optional shadowTessControl; + Optional shadowTessEval; Optional shadowFragment; Optional shadowCutoutFragment; GlFramebuffer shadowFramebuffer; @@ -147,11 +155,15 @@ public void patchShaders(ChunkVertexType vertexType) { Map transformed = TransformPatcher.patchSodium( sources.getVertexSource().orElse(null), sources.getGeometrySource().orElse(null), + sources.getTessControlSource().orElse(null), + sources.getTessEvalSource().orElse(null), sources.getFragmentSource().orElse(null), AlphaTest.ALWAYS, inputs, vertexType.getPositionScale(), vertexType.getPositionOffset(), vertexType.getTextureScale(), parent.getTextureMap()); terrainSolidVertex = Optional.ofNullable(transformed.get(PatchShaderType.VERTEX)); terrainSolidGeometry = Optional.ofNullable(transformed.get(PatchShaderType.GEOMETRY)); + terrainSolidTessControl = Optional.ofNullable(transformed.get(PatchShaderType.TESS_CONTROL)); + terrainSolidTessEval = Optional.ofNullable(transformed.get(PatchShaderType.TESS_EVAL)); terrainSolidFragment = Optional.ofNullable(transformed.get(PatchShaderType.FRAGMENT)); ShaderPrinter.printProgram(sources.getName() + "_sodium_solid").addSources(transformed).print(); @@ -160,6 +172,8 @@ public void patchShaders(ChunkVertexType vertexType) { terrainSolidBufferOverrides = Collections.emptyList(); terrainSolidVertex = Optional.empty(); terrainSolidGeometry = Optional.empty(); + terrainSolidTessControl = Optional.empty(); + terrainSolidTessEval = Optional.empty(); terrainSolidFragment = Optional.empty(); }); @@ -177,11 +191,15 @@ public void patchShaders(ChunkVertexType vertexType) { Map transformed = TransformPatcher.patchSodium( sources.getVertexSource().orElse(null), sources.getGeometrySource().orElse(null), + sources.getTessControlSource().orElse(null), + sources.getTessEvalSource().orElse(null), sources.getFragmentSource().orElse(null), terrainCutoutAlpha.orElse(AlphaTests.ONE_TENTH_ALPHA), inputs, vertexType.getPositionScale(), vertexType.getPositionOffset(), vertexType.getTextureScale(), parent.getTextureMap()); terrainCutoutVertex = Optional.ofNullable(transformed.get(PatchShaderType.VERTEX)); terrainCutoutGeometry = Optional.ofNullable(transformed.get(PatchShaderType.GEOMETRY)); + terrainCutoutTessControl = Optional.ofNullable(transformed.get(PatchShaderType.TESS_CONTROL)); + terrainCutoutTessEval = Optional.ofNullable(transformed.get(PatchShaderType.TESS_EVAL)); terrainCutoutFragment = Optional.ofNullable(transformed.get(PatchShaderType.FRAGMENT)); ShaderPrinter.printProgram(sources.getName() + "_sodium_cutout").addSources(transformed).print(); @@ -191,6 +209,8 @@ public void patchShaders(ChunkVertexType vertexType) { terrainCutoutAlpha = terrainCutoutDefault.get(); terrainCutoutVertex = Optional.empty(); terrainCutoutGeometry = Optional.empty(); + terrainCutoutTessControl = Optional.empty(); + terrainCutoutTessEval = Optional.empty(); terrainCutoutFragment = Optional.empty(); }); @@ -209,11 +229,15 @@ public void patchShaders(ChunkVertexType vertexType) { Map transformed = TransformPatcher.patchSodium( sources.getVertexSource().orElse(null), sources.getGeometrySource().orElse(null), + sources.getTessControlSource().orElse(null), + sources.getTessEvalSource().orElse(null), sources.getFragmentSource().orElse(null), translucentAlpha.orElse(AlphaTest.ALWAYS), inputs, vertexType.getPositionScale(), vertexType.getPositionOffset(), vertexType.getTextureScale(), parent.getTextureMap()); translucentVertex = Optional.ofNullable(transformed.get(PatchShaderType.VERTEX)); translucentGeometry = Optional.ofNullable(transformed.get(PatchShaderType.GEOMETRY)); + translucentTessControl = Optional.ofNullable(transformed.get(PatchShaderType.TESS_CONTROL)); + translucentTessEval = Optional.ofNullable(transformed.get(PatchShaderType.TESS_EVAL)); translucentFragment = Optional.ofNullable(transformed.get(PatchShaderType.FRAGMENT)); ShaderPrinter.printProgram(sources.getName() + "_sodium").addSources(transformed).print(); @@ -223,6 +247,8 @@ public void patchShaders(ChunkVertexType vertexType) { translucentAlpha = translucentDefault.get(); translucentVertex = Optional.empty(); translucentGeometry = Optional.empty(); + translucentTessControl = Optional.empty(); + translucentTessEval = Optional.empty(); translucentFragment = Optional.empty(); }); @@ -240,17 +266,23 @@ public void patchShaders(ChunkVertexType vertexType) { Map transformed = TransformPatcher.patchSodium( sources.getVertexSource().orElse(null), sources.getGeometrySource().orElse(null), + sources.getTessControlSource().orElse(null), + sources.getTessEvalSource().orElse(null), sources.getFragmentSource().orElse(null), AlphaTest.ALWAYS, inputs, vertexType.getPositionScale(), vertexType.getPositionOffset(), vertexType.getTextureScale(), parent.getTextureMap()); Map transformedCutout = TransformPatcher.patchSodium( sources.getVertexSource().orElse(null), sources.getGeometrySource().orElse(null), + sources.getTessControlSource().orElse(null), + sources.getTessEvalSource().orElse(null), sources.getFragmentSource().orElse(null), shadowAlpha.get(), inputs, vertexType.getPositionScale(), vertexType.getPositionOffset(), vertexType.getTextureScale(), parent.getTextureMap()); shadowVertex = Optional.ofNullable(transformed.get(PatchShaderType.VERTEX)); shadowGeometry = Optional.ofNullable(transformed.get(PatchShaderType.GEOMETRY)); + shadowTessControl = Optional.ofNullable(transformed.get(PatchShaderType.TESS_CONTROL)); + shadowTessEval = Optional.ofNullable(transformed.get(PatchShaderType.TESS_EVAL)); shadowCutoutFragment = Optional.ofNullable(transformedCutout.get(PatchShaderType.FRAGMENT)); shadowFragment = Optional.ofNullable(transformed.get(PatchShaderType.FRAGMENT)); @@ -265,6 +297,8 @@ public void patchShaders(ChunkVertexType vertexType) { shadowAlpha = shadowDefault.get(); shadowVertex = Optional.empty(); shadowGeometry = Optional.empty(); + shadowTessControl = Optional.empty(); + shadowTessEval = Optional.empty(); shadowCutoutFragment = Optional.empty(); shadowFragment = Optional.empty(); }); @@ -278,6 +312,14 @@ public Optional getTerrainSolidGeometryShaderSource() { return terrainSolidGeometry; } + public Optional getTerrainSolidTessControlShaderSource() { + return terrainSolidTessControl; + } + + public Optional getTerrainSolidTessEvalShaderSource() { + return terrainSolidTessEval; + } + public Optional getTerrainSolidFragmentShaderSource() { return terrainSolidFragment; } @@ -290,6 +332,14 @@ public Optional getTerrainCutoutGeometryShaderSource() { return terrainCutoutGeometry; } + public Optional getTerrainCutoutTessControlShaderSource() { + return terrainCutoutTessControl; + } + + public Optional getTerrainCutoutTessEvalShaderSource() { + return terrainCutoutTessEval; + } + public Optional getTerrainCutoutFragmentShaderSource() { return terrainCutoutFragment; } @@ -329,6 +379,14 @@ public Optional getTranslucentGeometryShaderSource() { return translucentGeometry; } + public Optional getTranslucentTessControlShaderSource() { + return translucentTessControl; + } + + public Optional getTranslucentTessEvalShaderSource() { + return translucentTessEval; + } + public Optional getTranslucentFragmentShaderSource() { return translucentFragment; } @@ -357,6 +415,14 @@ public Optional getShadowGeometryShaderSource() { return shadowGeometry; } + public Optional getShadowTessControlShaderSource() { + return shadowTessControl; + } + + public Optional getShadowTessEvalShaderSource() { + return shadowTessEval; + } + public Optional getShadowFragmentShaderSource() { return shadowFragment; } diff --git a/src/main/java/net/coderbot/iris/pipeline/newshader/ExtendedShader.java b/src/main/java/net/coderbot/iris/pipeline/newshader/ExtendedShader.java index b60755acec..c6cb9df05b 100644 --- a/src/main/java/net/coderbot/iris/pipeline/newshader/ExtendedShader.java +++ b/src/main/java/net/coderbot/iris/pipeline/newshader/ExtendedShader.java @@ -31,6 +31,7 @@ import net.coderbot.iris.uniforms.custom.CustomUniforms; import net.coderbot.iris.vendored.joml.FrustumRayBuilder; import net.coderbot.iris.vendored.joml.Vector3f; +import net.coderbot.iris.vertices.ImmediateState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.ShaderInstance; import net.minecraft.resources.ResourceLocation; @@ -71,13 +72,14 @@ public class ExtendedShader extends ShaderInstance implements ShaderInstanceInte GlFramebuffer baseline; BlendModeOverride blendModeOverride; float alphaTest; - private Program geometry; + boolean usesTessellation; + private Program geometry, tessControl, tessEval; private final ShaderAttributeInputs inputs; private static ExtendedShader lastApplied; private final Vector3f chunkOffset = new Vector3f(); - public ExtendedShader(ResourceProvider resourceFactory, String string, VertexFormat vertexFormat, + public ExtendedShader(ResourceProvider resourceFactory, String string, VertexFormat vertexFormat, boolean usesTessellation, GlFramebuffer writingToBeforeTranslucent, GlFramebuffer writingToAfterTranslucent, GlFramebuffer baseline, BlendModeOverride blendModeOverride, AlphaTest alphaTest, Consumer uniformCreator, BiConsumer samplerCreator, boolean isIntensity, @@ -92,6 +94,7 @@ public ExtendedShader(ResourceProvider resourceFactory, String string, VertexFor ProgramImages.Builder builder = ProgramImages.builder(programId); samplerCreator.accept(samplerBuilder, builder); customUniforms.mapholderToPass(uniformBuilder, this); + this.usesTessellation = usesTessellation; uniforms = uniformBuilder.buildUniforms(); this.customUniforms = customUniforms; @@ -161,6 +164,8 @@ public void apply() { IrisRenderSystem.bindTextureToUnit(TextureType.TEXTURE_2D.getGlType(), IrisSamplers.OVERLAY_TEXTURE_UNIT, RenderSystem.getShaderTexture(1)); IrisRenderSystem.bindTextureToUnit(TextureType.TEXTURE_2D.getGlType(), IrisSamplers.LIGHTMAP_TEXTURE_UNIT, RenderSystem.getShaderTexture(2)); + ImmediateState.usingTessellation = usesTessellation; + if (PROJECTION_MATRIX != null) { if (projectionInverse != null) { projectionInverse.set(tempMatrix4f.set(PROJECTION_MATRIX.getFloatBuffer()).invert().get(tempFloats)); @@ -245,10 +250,16 @@ public void attachToProgram() { if (this.geometry != null) { this.geometry.attachToShader(this); } + if (this.tessControl != null) { + this.tessControl.attachToShader(this); + } + if (this.tessEval != null) { + this.tessEval.attachToShader(this); + } } @Override - public void iris$createGeometryShader(ResourceProvider factory, String name) throws IOException { + public void iris$createExtraShaders(ResourceProvider factory, String name) throws IOException { Resource geometry = factory.getResource(new ResourceLocation("minecraft", name + "_geometry.gsh")); if (geometry != null) { this.geometry = Program.compileShader(IrisProgramTypes.GEOMETRY, name, geometry.getInputStream(), geometry.getSourceName(), new GlslPreprocessor() { @@ -259,12 +270,42 @@ public String applyImport(boolean bl, String string) { } }); } + + Resource tessControl = factory.getResource(new ResourceLocation("minecraft", name + "_tessControl.tcs")); + if (tessControl != null) { + this.tessControl = Program.compileShader(IrisProgramTypes.TESS_CONTROL, name, tessControl.getInputStream(), tessControl.getSourceName(), new GlslPreprocessor() { + @Nullable + @Override + public String applyImport(boolean bl, String string) { + return null; + } + }); + } + + Resource tessEval = factory.getResource(new ResourceLocation("minecraft", name + "_tessEval.tes")); + if (tessEval != null) { + this.tessEval = Program.compileShader(IrisProgramTypes.TESS_EVAL, name, tessEval.getInputStream(), tessEval.getSourceName(), new GlslPreprocessor() { + @Nullable + @Override + public String applyImport(boolean bl, String string) { + return null; + } + }); + } } public Program getGeometry() { return this.geometry; } + public Program getTessControl() { + return this.tessControl; + } + + public Program getTessEval() { + return this.tessEval; + } + public boolean hasActiveImages() { return images.getActiveImages() > 0; } diff --git a/src/main/java/net/coderbot/iris/pipeline/newshader/IrisProgramTypes.java b/src/main/java/net/coderbot/iris/pipeline/newshader/IrisProgramTypes.java index 43ddb734dd..2ab068c930 100644 --- a/src/main/java/net/coderbot/iris/pipeline/newshader/IrisProgramTypes.java +++ b/src/main/java/net/coderbot/iris/pipeline/newshader/IrisProgramTypes.java @@ -4,4 +4,6 @@ public class IrisProgramTypes { public static Program.Type GEOMETRY; + public static Program.Type TESS_CONTROL; + public static Program.Type TESS_EVAL; } diff --git a/src/main/java/net/coderbot/iris/pipeline/newshader/NewShaderTests.java b/src/main/java/net/coderbot/iris/pipeline/newshader/NewShaderTests.java index 6c7d761bb8..30251f8b8d 100644 --- a/src/main/java/net/coderbot/iris/pipeline/newshader/NewShaderTests.java +++ b/src/main/java/net/coderbot/iris/pipeline/newshader/NewShaderTests.java @@ -49,10 +49,14 @@ public static ExtendedShader create(WorldRenderingPipeline pipeline, String name Map transformed = TransformPatcher.patchVanilla( source.getVertexSource().orElseThrow(RuntimeException::new), source.getGeometrySource().orElse(null), + source.getTessControlSource().orElse(null), + source.getTessEvalSource().orElse(null), source.getFragmentSource().orElseThrow(RuntimeException::new), alpha, isLines, true, inputs, pipeline.getTextureMap()); String vertex = transformed.get(PatchShaderType.VERTEX); String geometry = transformed.get(PatchShaderType.GEOMETRY); + String tessControl = transformed.get(PatchShaderType.TESS_CONTROL); + String tessEval = transformed.get(PatchShaderType.TESS_EVAL); String fragment = transformed.get(PatchShaderType.FRAGMENT); StringBuilder shaderJson = new StringBuilder("{\n" + @@ -90,7 +94,7 @@ public static ExtendedShader create(WorldRenderingPipeline pipeline, String name ShaderPrinter.printProgram(name).addSources(transformed).addJson(shaderJsonString).print(); - ResourceProvider shaderResourceFactory = new IrisProgramResourceFactory(shaderJsonString, vertex, geometry, fragment); + ResourceProvider shaderResourceFactory = new IrisProgramResourceFactory(shaderJsonString, vertex, geometry, tessControl, tessEval, fragment); List overrides = new ArrayList<>(); source.getDirectives().getBufferBlendOverrides().forEach(information -> { @@ -100,7 +104,7 @@ public static ExtendedShader create(WorldRenderingPipeline pipeline, String name } }); - return new ExtendedShader(shaderResourceFactory, name, vertexFormat, writingToBeforeTranslucent, writingToAfterTranslucent, baseline, blendModeOverride, alpha, uniforms -> { + return new ExtendedShader(shaderResourceFactory, name, vertexFormat, tessControl != null || tessEval != null, writingToBeforeTranslucent, writingToAfterTranslucent, baseline, blendModeOverride, alpha, uniforms -> { CommonUniforms.addDynamicUniforms(uniforms, FogMode.PER_VERTEX); customUniforms.assignTo(uniforms); //SamplerUniforms.addWorldSamplerUniforms(uniforms); @@ -166,7 +170,7 @@ public static FallbackShader createFallback(String name, GlFramebuffer writingTo .addJson(shaderJsonString) .print(); - ResourceProvider shaderResourceFactory = new IrisProgramResourceFactory(shaderJsonString, vertex, null, fragment); + ResourceProvider shaderResourceFactory = new IrisProgramResourceFactory(shaderJsonString, vertex, null, null, null, fragment); return new FallbackShader(shaderResourceFactory, name, vertexFormat, writingToBeforeTranslucent, writingToAfterTranslucent, blendModeOverride, alpha.getReference(), parent); @@ -176,12 +180,16 @@ private static class IrisProgramResourceFactory implements ResourceProvider { private final String json; private final String vertex; private final String geometry; + private final String tessControl; + private final String tessEval; private final String fragment; - public IrisProgramResourceFactory(String json, String vertex, String geometry, String fragment) { + public IrisProgramResourceFactory(String json, String vertex, String geometry, String tessControl, String tessEval, String fragment) { this.json = json; this.vertex = vertex; this.geometry = geometry; + this.tessControl = tessControl; + this.tessEval = tessEval; this.fragment = fragment; } @@ -198,6 +206,16 @@ public Resource getResource(ResourceLocation id) throws IOException { return null; } return new StringResource(id, geometry); + } else if (path.endsWith("tcs")) { + if (tessControl == null) { + return null; + } + return new StringResource(id, tessControl); + } else if (path.endsWith("tes")) { + if (tessEval == null) { + return null; + } + return new StringResource(id, tessEval); } else if (path.endsWith("fsh")) { return new StringResource(id, fragment); } diff --git a/src/main/java/net/coderbot/iris/pipeline/newshader/ShaderInstanceInterface.java b/src/main/java/net/coderbot/iris/pipeline/newshader/ShaderInstanceInterface.java index eda7a42905..a06505c06d 100644 --- a/src/main/java/net/coderbot/iris/pipeline/newshader/ShaderInstanceInterface.java +++ b/src/main/java/net/coderbot/iris/pipeline/newshader/ShaderInstanceInterface.java @@ -5,5 +5,5 @@ import java.io.IOException; public interface ShaderInstanceInterface { - void iris$createGeometryShader(ResourceProvider factory, String name) throws IOException; + void iris$createExtraShaders(ResourceProvider factory, String name) throws IOException; } diff --git a/src/main/java/net/coderbot/iris/pipeline/transform/PatchShaderType.java b/src/main/java/net/coderbot/iris/pipeline/transform/PatchShaderType.java index 7bfb08fd26..a3c8474b69 100644 --- a/src/main/java/net/coderbot/iris/pipeline/transform/PatchShaderType.java +++ b/src/main/java/net/coderbot/iris/pipeline/transform/PatchShaderType.java @@ -5,6 +5,8 @@ public enum PatchShaderType { VERTEX(ShaderType.VERTEX, ".vsh"), GEOMETRY(ShaderType.GEOMETRY, ".gsh"), + TESS_CONTROL(ShaderType.TESSELATION_CONTROL, ".tcs"), + TESS_EVAL(ShaderType.TESSELATION_EVAL, ".tes"), FRAGMENT(ShaderType.FRAGMENT, ".fsh"), COMPUTE(ShaderType.COMPUTE, ".csh"); @@ -22,6 +24,10 @@ public static PatchShaderType[] fromGlShaderType(ShaderType glShaderType) { return new PatchShaderType[] { VERTEX }; case GEOMETRY: return new PatchShaderType[] { GEOMETRY }; + case TESSELATION_CONTROL: + return new PatchShaderType[] { TESS_CONTROL }; + case TESSELATION_EVAL: + return new PatchShaderType[] { TESS_EVAL }; case COMPUTE: return new PatchShaderType[] { COMPUTE }; case FRAGMENT: diff --git a/src/main/java/net/coderbot/iris/pipeline/transform/TransformPatcher.java b/src/main/java/net/coderbot/iris/pipeline/transform/TransformPatcher.java index 7e11c69722..abe112019f 100644 --- a/src/main/java/net/coderbot/iris/pipeline/transform/TransformPatcher.java +++ b/src/main/java/net/coderbot/iris/pipeline/transform/TransformPatcher.java @@ -77,13 +77,17 @@ private static class CacheKey { final Parameters parameters; final String vertex; final String geometry; + final String tessControl; + final String tessEval; final String fragment; final String compute; - public CacheKey(Parameters parameters, String vertex, String geometry, String fragment) { + public CacheKey(Parameters parameters, String vertex, String geometry, String tessControl, String tessEval, String fragment) { this.parameters = parameters; this.vertex = vertex; this.geometry = geometry; + this.tessControl = tessControl; + this.tessEval = tessEval; this.fragment = fragment; this.compute = null; } @@ -92,6 +96,8 @@ public CacheKey(Parameters parameters, String compute) { this.parameters = parameters; this.vertex = null; this.geometry = null; + this.tessControl = null; + this.tessEval = null; this.fragment = null; this.compute = compute; } @@ -103,6 +109,8 @@ public int hashCode() { result = prime * result + ((parameters == null) ? 0 : parameters.hashCode()); result = prime * result + ((vertex == null) ? 0 : vertex.hashCode()); result = prime * result + ((geometry == null) ? 0 : geometry.hashCode()); + result = prime * result + ((tessControl == null) ? 0 : tessControl.hashCode()); + result = prime * result + ((tessEval == null) ? 0 : tessEval.hashCode()); result = prime * result + ((fragment == null) ? 0 : fragment.hashCode()); result = prime * result + ((compute == null) ? 0 : compute.hashCode()); return result; @@ -132,6 +140,16 @@ public boolean equals(Object obj) { return false; } else if (!geometry.equals(other.geometry)) return false; + if (tessControl == null) { + if (other.tessControl != null) + return false; + } else if (!tessControl.equals(other.tessControl)) + return false; + if (tessEval == null) { + if (other.tessEval != null) + return false; + } else if (!tessEval.equals(other.tessEval)) + return false; if (fragment == null) { if (other.fragment != null) return false; @@ -300,10 +318,10 @@ private static Map transformInternal( } } - private static Map transform(String vertex, String geometry, String fragment, + private static Map transform(String vertex, String geometry, String tessControl, String tessEval, String fragment, Parameters parameters) { // stop if all are null - if (vertex == null && geometry == null && fragment == null) { + if (vertex == null && geometry == null && tessControl == null && tessEval == null && fragment == null) { return null; } @@ -311,7 +329,7 @@ private static Map transform(String vertex, String geom CacheKey key; Map result = null; if (useCache) { - key = new CacheKey(parameters, vertex, geometry, fragment); + key = new CacheKey(parameters, vertex, geometry, tessControl, tessEval, fragment); if (cache.containsKey(key)) { result = cache.get(key); } @@ -323,6 +341,8 @@ private static Map transform(String vertex, String geom EnumMap inputs = new EnumMap<>(PatchShaderType.class); inputs.put(PatchShaderType.VERTEX, vertex); inputs.put(PatchShaderType.GEOMETRY, geometry); + inputs.put(PatchShaderType.TESS_CONTROL, tessControl); + inputs.put(PatchShaderType.TESS_EVAL, tessEval); inputs.put(PatchShaderType.FRAGMENT, fragment); result = transformInternal(inputs, parameters); @@ -363,29 +383,21 @@ private static Map transformCompute(String compute, Par return result; } - public static Map patchAttributes( - String vertex, String geometry, String fragment, - InputAvailability inputs, - Object2ObjectMap, String> textureMap) { - return transform(vertex, geometry, fragment, - new AttributeParameters(Patch.ATTRIBUTES, textureMap, geometry != null, inputs)); - } - public static Map patchVanilla( - String vertex, String geometry, String fragment, + String vertex, String geometry, String tessControl, String tessEval, String fragment, AlphaTest alpha, boolean isLines, boolean hasChunkOffset, ShaderAttributeInputs inputs, Object2ObjectMap, String> textureMap) { - return transform(vertex, geometry, fragment, + return transform(vertex, geometry, tessControl, tessEval, fragment, new VanillaParameters(Patch.VANILLA, textureMap, alpha, isLines, hasChunkOffset, inputs, geometry != null)); } - public static Map patchSodium(String vertex, String geometry, String fragment, + public static Map patchSodium(String vertex, String geometry, String tessControl, String tessEval, String fragment, AlphaTest alpha, ShaderAttributeInputs inputs, float positionScale, float positionOffset, float textureScale, Object2ObjectMap, String> textureMap) { - return transform(vertex, geometry, fragment, + return transform(vertex, geometry, tessControl, tessEval, fragment, new SodiumParameters(Patch.SODIUM, textureMap, alpha, inputs, positionScale, positionOffset, textureScale)); } @@ -394,7 +406,7 @@ public static Map patchComposite( String vertex, String geometry, String fragment, TextureStage stage, Object2ObjectMap, String> textureMap) { - return transform(vertex, geometry, fragment, new TextureStageParameters(Patch.COMPOSITE, stage, textureMap)); + return transform(vertex, geometry, null, null, fragment, new TextureStageParameters(Patch.COMPOSITE, stage, textureMap)); } public static String patchCompute( diff --git a/src/main/java/net/coderbot/iris/shaderpack/ProgramSet.java b/src/main/java/net/coderbot/iris/shaderpack/ProgramSet.java index 00c54305c1..e7794cfd3d 100644 --- a/src/main/java/net/coderbot/iris/shaderpack/ProgramSet.java +++ b/src/main/java/net/coderbot/iris/shaderpack/ProgramSet.java @@ -516,6 +516,12 @@ private static ProgramSource readProgramSource(AbsolutePackPath directory, AbsolutePackPath geometryPath = directory.resolve(program + ".gsh"); String geometrySource = sourceProvider.apply(geometryPath); + AbsolutePackPath tessControlPath = directory.resolve(program + ".tcs"); + String tessControlSource = sourceProvider.apply(tessControlPath); + + AbsolutePackPath tessEvalPath = directory.resolve(program + ".tes"); + String tessEvalSource = sourceProvider.apply(tessEvalPath); + AbsolutePackPath fragmentPath = directory.resolve(program + ".fsh"); String fragmentSource = sourceProvider.apply(fragmentPath); @@ -538,7 +544,7 @@ void main() { """; } - return new ProgramSource(program, vertexSource, geometrySource, fragmentSource, programSet, properties, + return new ProgramSource(program, vertexSource, geometrySource, tessControlSource, tessEvalSource, fragmentSource, programSet, properties, defaultBlendModeOverride); } diff --git a/src/main/java/net/coderbot/iris/shaderpack/ProgramSource.java b/src/main/java/net/coderbot/iris/shaderpack/ProgramSource.java index 9ef8500a73..c519567dc8 100644 --- a/src/main/java/net/coderbot/iris/shaderpack/ProgramSource.java +++ b/src/main/java/net/coderbot/iris/shaderpack/ProgramSource.java @@ -8,25 +8,31 @@ public class ProgramSource { private final String name; private final String vertexSource; private final String geometrySource; + private final String tessControlSource; + private final String tessEvalSource; private final String fragmentSource; private final ProgramDirectives directives; private final ProgramSet parent; - private ProgramSource(String name, String vertexSource, String geometrySource, String fragmentSource, + private ProgramSource(String name, String vertexSource, String geometrySource, String tessControlSource, String tessEvalSource, String fragmentSource, ProgramDirectives directives, ProgramSet parent) { this.name = name; this.vertexSource = vertexSource; this.geometrySource = geometrySource; + this.tessControlSource = tessControlSource; + this.tessEvalSource = tessEvalSource; this.fragmentSource = fragmentSource; this.directives = directives; this.parent = parent; } - public ProgramSource(String name, String vertexSource, String geometrySource, String fragmentSource, + public ProgramSource(String name, String vertexSource, String geometrySource, String tessControlSource, String tessEvalSource, String fragmentSource, ProgramSet parent, ShaderProperties properties, BlendModeOverride defaultBlendModeOverride) { this.name = name; this.vertexSource = vertexSource; this.geometrySource = geometrySource; + this.tessControlSource = tessControlSource; + this.tessEvalSource = tessEvalSource; this.fragmentSource = fragmentSource; this.parent = parent; this.directives = new ProgramDirectives(this, properties, @@ -34,7 +40,7 @@ public ProgramSource(String name, String vertexSource, String geometrySource, St } public ProgramSource withDirectiveOverride(ProgramDirectives overrideDirectives) { - return new ProgramSource(name, vertexSource, geometrySource, fragmentSource, overrideDirectives, parent); + return new ProgramSource(name, vertexSource, geometrySource, tessControlSource, tessEvalSource, fragmentSource, overrideDirectives, parent); } public String getName() { @@ -49,6 +55,14 @@ public Optional getGeometrySource() { return Optional.ofNullable(geometrySource); } + public Optional getTessControlSource() { + return Optional.ofNullable(tessControlSource); + } + + public Optional getTessEvalSource() { + return Optional.ofNullable(tessEvalSource); + } + public Optional getFragmentSource() { return Optional.ofNullable(fragmentSource); } diff --git a/src/main/java/net/coderbot/iris/shaderpack/include/ShaderPackSourceNames.java b/src/main/java/net/coderbot/iris/shaderpack/include/ShaderPackSourceNames.java index 7709618e0e..31556ab7c9 100644 --- a/src/main/java/net/coderbot/iris/shaderpack/include/ShaderPackSourceNames.java +++ b/src/main/java/net/coderbot/iris/shaderpack/include/ShaderPackSourceNames.java @@ -74,6 +74,8 @@ private static ImmutableList findPotentialStarts() { private static void addStarts(ImmutableList.Builder potentialFileNames, String baseName) { potentialFileNames.add(baseName + ".vsh"); + potentialFileNames.add(baseName + ".tcs"); + potentialFileNames.add(baseName + ".tes"); potentialFileNames.add(baseName + ".gsh"); potentialFileNames.add(baseName + ".fsh"); } diff --git a/src/main/java/net/coderbot/iris/vertices/ImmediateState.java b/src/main/java/net/coderbot/iris/vertices/ImmediateState.java index 2762c6bda0..7e13ce2970 100644 --- a/src/main/java/net/coderbot/iris/vertices/ImmediateState.java +++ b/src/main/java/net/coderbot/iris/vertices/ImmediateState.java @@ -1,9 +1,10 @@ package net.coderbot.iris.vertices; /** - * Some annoying global state needed for the extended vertex format disabling optimization. + * Some annoying global state needed for rendering. */ public class ImmediateState { public static boolean isRenderingLevel = false; + public static boolean usingTessellation = false; public static boolean renderWithExtendedVertexFormat = true; } diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/shader_overrides/IrisChunkProgramOverrides.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/shader_overrides/IrisChunkProgramOverrides.java index 7c5542480b..154b8895c6 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/shader_overrides/IrisChunkProgramOverrides.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/shader_overrides/IrisChunkProgramOverrides.java @@ -80,6 +80,56 @@ private GlShader createGeometryShader(IrisTerrainPass pass, SodiumTerrainPipelin "sodium-terrain-" + pass.toString().toLowerCase(Locale.ROOT) + ".gsh"), source); } + private GlShader createTessControlShader(IrisTerrainPass pass, SodiumTerrainPipeline pipeline) { + Optional irisTessControlShader; + + if (pass == IrisTerrainPass.SHADOW || pass == IrisTerrainPass.SHADOW_CUTOUT) { + irisTessControlShader = pipeline.getShadowTessControlShaderSource(); + } else if (pass == IrisTerrainPass.GBUFFER_SOLID) { + irisTessControlShader = pipeline.getTerrainSolidTessControlShaderSource(); + } else if (pass == IrisTerrainPass.GBUFFER_CUTOUT) { + irisTessControlShader = pipeline.getTerrainCutoutTessControlShaderSource(); + } else if (pass == IrisTerrainPass.GBUFFER_TRANSLUCENT) { + irisTessControlShader = pipeline.getTranslucentTessControlShaderSource(); + } else { + throw new IllegalArgumentException("Unknown pass type " + pass); + } + + String source = irisTessControlShader.orElse(null); + + if (source == null) { + return null; + } + + return new GlShader(IrisShaderTypes.TESS_CONTROL, new ResourceLocation("iris", + "sodium-terrain-" + pass.toString().toLowerCase(Locale.ROOT) + ".tcs"), source); + } + + private GlShader createTessEvalShader(IrisTerrainPass pass, SodiumTerrainPipeline pipeline) { + Optional irisTessEvalShader; + + if (pass == IrisTerrainPass.SHADOW || pass == IrisTerrainPass.SHADOW_CUTOUT) { + irisTessEvalShader = pipeline.getShadowTessEvalShaderSource(); + } else if (pass == IrisTerrainPass.GBUFFER_SOLID) { + irisTessEvalShader = pipeline.getTerrainSolidTessEvalShaderSource(); + } else if (pass == IrisTerrainPass.GBUFFER_CUTOUT) { + irisTessEvalShader = pipeline.getTerrainCutoutTessEvalShaderSource(); + } else if (pass == IrisTerrainPass.GBUFFER_TRANSLUCENT) { + irisTessEvalShader = pipeline.getTranslucentTessEvalShaderSource(); + } else { + throw new IllegalArgumentException("Unknown pass type " + pass); + } + + String source = irisTessEvalShader.orElse(null); + + if (source == null) { + return null; + } + + return new GlShader(IrisShaderTypes.TESS_EVAL, new ResourceLocation("iris", + "sodium-terrain-" + pass.toString().toLowerCase(Locale.ROOT) + ".tes"), source); + } + private GlShader createFragmentShader(IrisTerrainPass pass, SodiumTerrainPipeline pipeline) { Optional irisFragmentShader; @@ -139,6 +189,8 @@ private List getBufferBlendOverride(IrisTerrainPass pass, S private GlProgram createShader(IrisTerrainPass pass, SodiumTerrainPipeline pipeline) { GlShader vertShader = createVertexShader(pass, pipeline); GlShader geomShader = createGeometryShader(pass, pipeline); + GlShader tessCShader = createTessControlShader(pass, pipeline); + GlShader tessEShader = createTessEvalShader(pass, pipeline); GlShader fragShader = createFragmentShader(pass, pipeline); BlendModeOverride blendOverride = getBlendOverride(pass, pipeline); List bufferOverrides = getBufferBlendOverride(pass, pipeline); @@ -153,6 +205,14 @@ private GlProgram createShader(IrisTerrainPass pass, S geomShader.delete(); } + if (tessCShader != null) { + tessCShader.delete(); + } + + if (tessEShader != null) { + tessEShader.delete(); + } + if (fragShader != null) { fragShader.delete(); } @@ -168,6 +228,12 @@ private GlProgram createShader(IrisTerrainPass pass, S if (geomShader != null) { builder.attachShader(geomShader); } + if (tessCShader != null) { + builder.attachShader(tessCShader); + } + if (tessEShader != null) { + builder.attachShader(tessEShader); + } return builder.attachShader(vertShader) .attachShader(fragShader) @@ -187,13 +253,19 @@ private GlProgram createShader(IrisTerrainPass pass, S ShaderBindingContextExt contextExt = (ShaderBindingContextExt) shader; return new IrisChunkShaderInterface(handle, contextExt, pipeline, - pass == IrisTerrainPass.SHADOW || pass == IrisTerrainPass.SHADOW_CUTOUT, blendOverride, bufferOverrides, alpha, pipeline.getCustomUniforms()); + tessCShader != null || tessEShader != null, pass == IrisTerrainPass.SHADOW || pass == IrisTerrainPass.SHADOW_CUTOUT, blendOverride, bufferOverrides, alpha, pipeline.getCustomUniforms()); }); } finally { vertShader.delete(); if (geomShader != null) { geomShader.delete(); } + if (tessCShader != null) { + tessCShader.delete(); + } + if (tessEShader != null) { + tessEShader.delete(); + } fragShader.delete(); } } diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/shader_overrides/IrisChunkShaderInterface.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/shader_overrides/IrisChunkShaderInterface.java index 8dd1600d6b..2651f017ed 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/shader_overrides/IrisChunkShaderInterface.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/shader_overrides/IrisChunkShaderInterface.java @@ -17,6 +17,7 @@ import net.coderbot.iris.samplers.IrisSamplers; import net.coderbot.iris.uniforms.CapturedRenderingState; import net.coderbot.iris.uniforms.custom.CustomUniforms; +import net.coderbot.iris.vertices.ImmediateState; import org.jetbrains.annotations.Nullable; import org.joml.Matrix3f; import org.joml.Matrix4f; @@ -48,10 +49,11 @@ public class IrisChunkShaderInterface { private final ProgramImages irisProgramImages; private final List bufferBlendOverrides; private final boolean hasOverrides; + private final boolean isTess; private CustomUniforms customUniforms; public IrisChunkShaderInterface(int handle, ShaderBindingContextExt contextExt, SodiumTerrainPipeline pipeline, - boolean isShadowPass, BlendModeOverride blendModeOverride, List bufferOverrides, float alpha, CustomUniforms customUniforms) { + boolean isTess, boolean isShadowPass, BlendModeOverride blendModeOverride, List bufferOverrides, float alpha, CustomUniforms customUniforms) { this.uniformModelViewMatrix = contextExt.bindUniformIfPresent("iris_ModelViewMatrix", GlUniformMatrix4f::new); this.uniformModelViewMatrixInverse = contextExt.bindUniformIfPresent("iris_ModelViewMatrixInverse", GlUniformMatrix4f::new); this.uniformProjectionMatrix = contextExt.bindUniformIfPresent("iris_ProjectionMatrix", GlUniformMatrix4f::new); @@ -60,6 +62,7 @@ public IrisChunkShaderInterface(int handle, ShaderBindingContextExt contextExt, this.uniformNormalMatrix = contextExt.bindUniformIfPresent("iris_NormalMatrix", GlUniformMatrix3f::new); this.uniformBlockDrawParameters = contextExt.bindUniformBlockIfPresent("ubo_DrawParameters", 0); this.customUniforms = customUniforms; + this.isTess = isTess; this.alpha = alpha; @@ -87,6 +90,8 @@ public void setup() { blendModeOverride.apply(); } + ImmediateState.usingTessellation = isTess; + if (hasOverrides) { bufferBlendOverrides.forEach(BufferBlendOverride::apply); } @@ -102,6 +107,8 @@ public void setup() { } public void restore() { + ImmediateState.usingTessellation = false; + if (blendModeOverride != null || hasOverrides) { BlendModeOverride.restore(); } diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/shader_overrides/IrisShaderTypes.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/shader_overrides/IrisShaderTypes.java index ef30b90648..18c8980d2c 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/shader_overrides/IrisShaderTypes.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/shader_overrides/IrisShaderTypes.java @@ -7,4 +7,6 @@ */ public class IrisShaderTypes { public static ShaderType GEOMETRY; + public static ShaderType TESS_CONTROL; + public static ShaderType TESS_EVAL; } diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinChunkProgram.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinChunkProgram.java deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinChunkRenderShaderBackend.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinChunkRenderShaderBackend.java deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinGlRenderDevice.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinGlRenderDevice.java new file mode 100644 index 0000000000..ca9dd80f2b --- /dev/null +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinGlRenderDevice.java @@ -0,0 +1,18 @@ +package net.coderbot.iris.compat.sodium.mixin.shader_overrides; + +import me.jellysquid.mods.sodium.client.gl.tessellation.GlPrimitiveType; +import net.coderbot.iris.vertices.ImmediateState; +import org.lwjgl.opengl.GL43C; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(targets = "me.jellysquid.mods.sodium.client.gl.device.GLRenderDevice$ImmediateDrawCommandList", remap = false) +public class MixinGlRenderDevice { + @Redirect(method = "multiDrawElementsBaseVertex", at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/gl/tessellation/GlPrimitiveType;getId()I")) + private int replaceId(GlPrimitiveType instance) { + if (ImmediateState.usingTessellation) return GL43C.GL_PATCHES; + + return instance.getId(); + } +} diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinShaderType.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinShaderType.java index 56af4d60d0..0b42012993 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinShaderType.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinShaderType.java @@ -4,6 +4,7 @@ import net.coderbot.iris.compat.sodium.impl.shader_overrides.IrisShaderTypes; import org.apache.commons.lang3.ArrayUtils; import org.lwjgl.opengl.GL32C; +import org.lwjgl.opengl.GL42C; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mutable; @@ -22,7 +23,11 @@ public class MixinShaderType { IrisShaderTypes.GEOMETRY = ShaderTypeAccessor.createShaderType("GEOMETRY", baseOrdinal, GL32C.GL_GEOMETRY_SHADER); + IrisShaderTypes.TESS_CONTROL + = ShaderTypeAccessor.createShaderType("TESS_CONTROL", baseOrdinal + 1, GL42C.GL_TESS_CONTROL_SHADER); + IrisShaderTypes.TESS_EVAL + = ShaderTypeAccessor.createShaderType("TESS_EVAL", baseOrdinal + 2, GL42C.GL_TESS_EVALUATION_SHADER); - $VALUES = ArrayUtils.addAll($VALUES, IrisShaderTypes.GEOMETRY); + $VALUES = ArrayUtils.addAll($VALUES, IrisShaderTypes.GEOMETRY, IrisShaderTypes.TESS_CONTROL, IrisShaderTypes.TESS_EVAL); } } diff --git a/src/sodiumCompatibility/resources/mixins.iris.compat.sodium.json b/src/sodiumCompatibility/resources/mixins.iris.compat.sodium.json index e5b7faa62d..8751ae30fb 100644 --- a/src/sodiumCompatibility/resources/mixins.iris.compat.sodium.json +++ b/src/sodiumCompatibility/resources/mixins.iris.compat.sodium.json @@ -25,6 +25,7 @@ "separate_ao.MixinFluidRenderer", "shader_overrides.MixinBlockRenderPass", "shader_overrides.MixinGlProgram", + "shader_overrides.MixinGlRenderDevice", "shader_overrides.MixinRegionChunkRenderer", "shader_overrides.MixinShaderChunkRenderer", "shader_overrides.MixinShaderType", From 3d69f1beb7be7b18cb695b4016a42c550cf67f90 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Wed, 13 Dec 2023 16:30:25 -0800 Subject: [PATCH 28/56] Wireflamin --- src/main/java/net/coderbot/iris/Iris.java | 6 ++++++ .../coderbot/iris/mixin/MixinLevelRenderer.java | 14 ++++++++++++++ src/main/resources/assets/iris/lang/en_us.json | 1 + 3 files changed, 21 insertions(+) diff --git a/src/main/java/net/coderbot/iris/Iris.java b/src/main/java/net/coderbot/iris/Iris.java index c543735a80..5ee77b93bc 100644 --- a/src/main/java/net/coderbot/iris/Iris.java +++ b/src/main/java/net/coderbot/iris/Iris.java @@ -79,6 +79,7 @@ public class Iris { private static KeyMapping reloadKeybind; private static KeyMapping toggleShadersKeybind; private static KeyMapping shaderpackScreenKeybind; + private static KeyMapping wireframeKeybind; private static final Map shaderPackOptionQueue = new HashMap<>(); // Flag variable used when reloading @@ -130,6 +131,7 @@ public void onEarlyInitialize() { reloadKeybind = KeyBindingHelper.registerKeyBinding(new KeyMapping("iris.keybind.reload", InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_R, "iris.keybinds")); toggleShadersKeybind = KeyBindingHelper.registerKeyBinding(new KeyMapping("iris.keybind.toggleShaders", InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_K, "iris.keybinds")); shaderpackScreenKeybind = KeyBindingHelper.registerKeyBinding(new KeyMapping("iris.keybind.shaderPackSelection", InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_O, "iris.keybinds")); + wireframeKeybind = KeyBindingHelper.registerKeyBinding(new KeyMapping("iris.keybind.wireframe", InputConstants.Type.KEYSYM, InputConstants.UNKNOWN.getValue(), "iris.keybinds")); setupCommands(Minecraft.getInstance()); @@ -240,6 +242,10 @@ public static void handleKeybinds(Minecraft minecraft) { } } + public static boolean shouldActivateWireframe() { + return wireframeKeybind.isDown(); + } + public static void toggleShaders(Minecraft minecraft, boolean enabled) throws IOException { irisConfig.setShadersEnabled(enabled); irisConfig.save(); diff --git a/src/main/java/net/coderbot/iris/mixin/MixinLevelRenderer.java b/src/main/java/net/coderbot/iris/mixin/MixinLevelRenderer.java index 5355426038..eaba334871 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinLevelRenderer.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinLevelRenderer.java @@ -21,6 +21,7 @@ import net.fabricmc.api.Environment; import net.minecraft.client.Camera; import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.renderer.LevelRenderer; import net.minecraft.client.renderer.LightTexture; @@ -30,6 +31,8 @@ import net.minecraft.client.renderer.culling.Frustum; import net.minecraft.core.BlockPos; import net.minecraft.world.phys.Vec3; +import org.jetbrains.annotations.Nullable; +import org.lwjgl.opengl.GL43C; import org.spongepowered.asm.mixin.Final; import net.minecraft.client.Options; @@ -65,6 +68,9 @@ public class MixinLevelRenderer { @Shadow private Frustum cullingFrustum; + @Shadow + private @Nullable ClientLevel level; + @Inject(method = "renderLevel", at = @At("HEAD")) private void iris$setupPipeline(PoseStack poseStack, float tickDelta, long startTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, @@ -81,6 +87,10 @@ public class MixinLevelRenderer { if (pipeline.shouldDisableFrustumCulling()) { this.cullingFrustum = new NonCullingFrustum(); } + + if (Iris.shouldActivateWireframe() && this.minecraft.isLocalServer()) { + GL43C.glPolygonMode(GL43C.GL_FRONT_AND_BACK, GL43C.GL_LINE); + } } // Begin shader rendering after buffers have been cleared. @@ -104,6 +114,10 @@ public class MixinLevelRenderer { Minecraft.getInstance().getProfiler().popPush("iris_final"); pipeline.finalizeLevelRendering(); pipeline = null; + + if (Iris.shouldActivateWireframe() && this.minecraft.isLocalServer()) { + GL43C.glPolygonMode(GL43C.GL_FRONT_AND_BACK, GL43C.GL_FILL); + } } // Setup shadow terrain & render shadows before the main terrain setup. We need to do things in this order to diff --git a/src/main/resources/assets/iris/lang/en_us.json b/src/main/resources/assets/iris/lang/en_us.json index 510ac759ec..0f14f7f7db 100644 --- a/src/main/resources/assets/iris/lang/en_us.json +++ b/src/main/resources/assets/iris/lang/en_us.json @@ -9,6 +9,7 @@ "iris.shaders.ssbofailure": "The shader requested a specific feature (SSBO) that is not supported by your GPU, it may not work correctly.", "iris.keybind.reload": "Reload Shaders", "iris.keybind.shaderPackSelection": "Shaderpack Selection Screen", + "iris.keybind.wireframe": "Wireframe (SP only)", "iris.keybind.toggleShaders": "Toggle Shaders", "iris.keybinds": "Iris", "iris.shaders.reloaded.failure": "Failed to reload shaders! Reason: %s", From 540a45f22546407965b2047b50a1242db29bedbc Mon Sep 17 00:00:00 2001 From: IMS212 Date: Wed, 13 Dec 2023 10:25:31 -0800 Subject: [PATCH 29/56] Fix patching --- .../pipeline/transform/TransformPatcher.java | 2 +- .../parameter/AttributeParameters.java | 2 +- .../parameter/GeometryInfoParameters.java | 4 +- .../parameter/VanillaParameters.java | 4 +- .../transformer/AttributeTransformer.java | 59 ++++++++++++++++++- 5 files changed, 64 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/coderbot/iris/pipeline/transform/TransformPatcher.java b/src/main/java/net/coderbot/iris/pipeline/transform/TransformPatcher.java index abe112019f..ebfcec90d1 100644 --- a/src/main/java/net/coderbot/iris/pipeline/transform/TransformPatcher.java +++ b/src/main/java/net/coderbot/iris/pipeline/transform/TransformPatcher.java @@ -390,7 +390,7 @@ public static Map patchVanilla( ShaderAttributeInputs inputs, Object2ObjectMap, String> textureMap) { return transform(vertex, geometry, tessControl, tessEval, fragment, - new VanillaParameters(Patch.VANILLA, textureMap, alpha, isLines, hasChunkOffset, inputs, geometry != null)); + new VanillaParameters(Patch.VANILLA, textureMap, alpha, isLines, hasChunkOffset, inputs, geometry != null, tessControl != null || tessEval != null)); } public static Map patchSodium(String vertex, String geometry, String tessControl, String tessEval, String fragment, diff --git a/src/main/java/net/coderbot/iris/pipeline/transform/parameter/AttributeParameters.java b/src/main/java/net/coderbot/iris/pipeline/transform/parameter/AttributeParameters.java index 83b6659530..fd9a81ecfe 100644 --- a/src/main/java/net/coderbot/iris/pipeline/transform/parameter/AttributeParameters.java +++ b/src/main/java/net/coderbot/iris/pipeline/transform/parameter/AttributeParameters.java @@ -15,7 +15,7 @@ public AttributeParameters(Patch patch, Object2ObjectMap, String> textureMap, boolean hasGeometry, InputAvailability inputs) { - super(patch, textureMap, hasGeometry); + super(patch, textureMap, hasGeometry, false); this.inputs = inputs; } diff --git a/src/main/java/net/coderbot/iris/pipeline/transform/parameter/GeometryInfoParameters.java b/src/main/java/net/coderbot/iris/pipeline/transform/parameter/GeometryInfoParameters.java index ad57e6add9..dcfec4f283 100644 --- a/src/main/java/net/coderbot/iris/pipeline/transform/parameter/GeometryInfoParameters.java +++ b/src/main/java/net/coderbot/iris/pipeline/transform/parameter/GeometryInfoParameters.java @@ -8,12 +8,14 @@ public abstract class GeometryInfoParameters extends Parameters { public final boolean hasGeometry; + public final boolean hasTesselation; // WARNING: adding new fields requires updating hashCode and equals methods! public GeometryInfoParameters(Patch patch, - Object2ObjectMap, String> textureMap, boolean hasGeometry) { + Object2ObjectMap, String> textureMap, boolean hasGeometry, boolean hasTesselation) { super(patch, textureMap); this.hasGeometry = hasGeometry; + this.hasTesselation = hasTesselation; } @Override diff --git a/src/main/java/net/coderbot/iris/pipeline/transform/parameter/VanillaParameters.java b/src/main/java/net/coderbot/iris/pipeline/transform/parameter/VanillaParameters.java index 86f027b4a9..08f6309aad 100644 --- a/src/main/java/net/coderbot/iris/pipeline/transform/parameter/VanillaParameters.java +++ b/src/main/java/net/coderbot/iris/pipeline/transform/parameter/VanillaParameters.java @@ -19,8 +19,8 @@ public VanillaParameters( Patch patch, Object2ObjectMap, String> textureMap, AlphaTest alpha, boolean isLines, boolean hasChunkOffset, - ShaderAttributeInputs inputs, boolean hasGeometry) { - super(patch, textureMap, hasGeometry); + ShaderAttributeInputs inputs, boolean hasGeometry, boolean hasTesselation) { + super(patch, textureMap, hasGeometry, hasTesselation); this.alpha = alpha; this.isLines = isLines; this.hasChunkOffset = hasChunkOffset; diff --git a/src/main/java/net/coderbot/iris/pipeline/transform/transformer/AttributeTransformer.java b/src/main/java/net/coderbot/iris/pipeline/transform/transformer/AttributeTransformer.java index e140e1bcd5..2057fb79e3 100644 --- a/src/main/java/net/coderbot/iris/pipeline/transform/transformer/AttributeTransformer.java +++ b/src/main/java/net/coderbot/iris/pipeline/transform/transformer/AttributeTransformer.java @@ -167,6 +167,32 @@ public static void patchOverlayColor( // Some shader packs incorrectly ignore the alpha value, and assume that rgb // will be zero if there is no hit flash, we try to emulate that here "entityColor.rgb *= float(entityColor.a != 0.0);"); + } else if (parameters.type.glShaderType == ShaderType.TESSELATION_CONTROL) { + // replace read references to grab the color from the first vertex. + root.replaceReferenceExpressions(t, "entityColor", "entityColor[gl_InvocationID]"); + + // TODO: this is passthrough behavior + tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_DECLARATIONS, + "out vec4 entityColorTCS[];", + "in vec4 entityColor[];", + "out vec4 iris_vertexColorTCS[];", + "in vec4 iris_vertexColor[];"); + tree.prependMainFunctionBody(t, + "entityColorTCS[gl_InvocationID] = entityColor[gl_InvocationID];", + "iris_vertexColorTCS[gl_InvocationID] = iris_vertexColor[gl_InvocationID];"); + } else if (parameters.type.glShaderType == ShaderType.TESSELATION_EVAL) { + // replace read references to grab the color from the first vertex. + root.replaceReferenceExpressions(t, "entityColor", "entityColorTCS[0]"); + + // TODO: this is passthrough behavior + tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_DECLARATIONS, + "out vec4 entityColorTES;", + "in vec4 entityColorTCS[];", + "out vec4 iris_vertexColorTES;", + "in vec4 iris_vertexColorTCS[];"); + tree.prependMainFunctionBody(t, + "entityColorTES = entityColorTCS[0];", + "iris_vertexColorTES = iris_vertexColorTCS[0];"); } else if (parameters.type.glShaderType == ShaderType.GEOMETRY) { // replace read references to grab the color from the first vertex. root.replaceReferenceExpressions(t, "entityColor", "entityColor[0]"); @@ -180,6 +206,11 @@ public static void patchOverlayColor( tree.prependMainFunctionBody(t, "entityColorGS = entityColor[0];", "iris_vertexColorGS = iris_vertexColor[0];"); + + if (parameters.hasTesselation) { + root.rename("iris_vertexColor", "iris_vertexColorTES"); + root.rename("entityColor", "entityColorTES"); + } } else if (parameters.type.glShaderType == ShaderType.FRAGMENT) { tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "in vec4 entityColor;", "in vec4 iris_vertexColor;"); @@ -190,6 +221,9 @@ public static void patchOverlayColor( if (parameters.hasGeometry) { root.rename("entityColor", "entityColorGS"); root.rename("iris_vertexColor", "iris_vertexColorGS"); + } else if (parameters.hasTesselation) { + root.rename("entityColor", "entityColorTES"); + root.rename("iris_vertexColor", "iris_vertexColorTES"); } } } @@ -238,13 +272,32 @@ public static void patchEntityId( // stage. tree.prependMainFunctionBody(t, "iris_entityInfo = iris_Entity;"); + } else if (parameters.type.glShaderType == ShaderType.TESSELATION_CONTROL) { + // TODO: this is passthrough behavior + tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_DECLARATIONS, + "flat out ivec3 iris_entityInfoTCS[];", + "flat in ivec3 iris_entityInfo[];"); + root.replaceReferenceExpressions(t, "iris_entityInfo", "iris_EntityInfo[gl_InvocationID]"); + + tree.prependMainFunctionBody(t, + "iris_entityInfoTCS[gl_InvocationID] = iris_entityInfo[gl_InvocationID];"); + } else if (parameters.type.glShaderType == ShaderType.TESSELATION_EVAL) { + // TODO: this is passthrough behavior + tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_DECLARATIONS, + "flat out ivec3 iris_entityInfoTES;", + "flat in ivec3 iris_entityInfoTCS[];"); + tree.prependMainFunctionBody(t, + "iris_entityInfoTES = iris_entityInfoTCS[0];"); + + root.replaceReferenceExpressions(t, "iris_entityInfo", "iris_EntityInfoTCS[0]"); + } else if (parameters.type.glShaderType == ShaderType.GEOMETRY) { // TODO: this is passthrough behavior tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "flat out ivec3 iris_entityInfoGS;", - "flat in ivec3 iris_entityInfo[];"); + "flat in ivec3 iris_entityInfo" + (parameters.hasTesselation ? "TES" : "") + "[];"); tree.prependMainFunctionBody(t, - "iris_entityInfoGS = iris_entityInfo[0];"); + "iris_entityInfoGS = iris_entityInfo" + (parameters.hasTesselation ? "TES" : "") + "[0];"); } else if (parameters.type.glShaderType == ShaderType.FRAGMENT) { tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "flat in ivec3 iris_entityInfo;"); @@ -252,6 +305,8 @@ public static void patchEntityId( // Different output name to avoid a name collision in the geometry shader. if (parameters.hasGeometry) { root.rename("iris_entityInfo", "iris_EntityInfoGS"); + } else if (parameters.hasTesselation) { + root.rename("iris_entityInfo", "iris_entityInfoTES"); } } } From d01aa71bdc81492fcaf8addf81d84e5bf6898915 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Wed, 13 Dec 2023 16:33:55 -0800 Subject: [PATCH 30/56] douira's turn --- .../transform/transformer/AttributeTransformer.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/coderbot/iris/pipeline/transform/transformer/AttributeTransformer.java b/src/main/java/net/coderbot/iris/pipeline/transform/transformer/AttributeTransformer.java index 2057fb79e3..c99c490ff2 100644 --- a/src/main/java/net/coderbot/iris/pipeline/transform/transformer/AttributeTransformer.java +++ b/src/main/java/net/coderbot/iris/pipeline/transform/transformer/AttributeTransformer.java @@ -173,7 +173,7 @@ public static void patchOverlayColor( // TODO: this is passthrough behavior tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_DECLARATIONS, - "out vec4 entityColorTCS[];", + "patch out vec4 entityColorTCS[];", "in vec4 entityColor[];", "out vec4 iris_vertexColorTCS[];", "in vec4 iris_vertexColor[];"); @@ -182,16 +182,16 @@ public static void patchOverlayColor( "iris_vertexColorTCS[gl_InvocationID] = iris_vertexColor[gl_InvocationID];"); } else if (parameters.type.glShaderType == ShaderType.TESSELATION_EVAL) { // replace read references to grab the color from the first vertex. - root.replaceReferenceExpressions(t, "entityColor", "entityColorTCS[0]"); + root.replaceReferenceExpressions(t, "entityColor", "entityColorTCS"); // TODO: this is passthrough behavior tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "out vec4 entityColorTES;", - "in vec4 entityColorTCS[];", + "patch in vec4 entityColorTCS;", "out vec4 iris_vertexColorTES;", "in vec4 iris_vertexColorTCS[];"); tree.prependMainFunctionBody(t, - "entityColorTES = entityColorTCS[0];", + "entityColorTES = entityColorTCS;", "iris_vertexColorTES = iris_vertexColorTCS[0];"); } else if (parameters.type.glShaderType == ShaderType.GEOMETRY) { // replace read references to grab the color from the first vertex. From 5eb3d9afd5580d1522e979cb5e1a6b903f55331a Mon Sep 17 00:00:00 2001 From: IMS212 Date: Wed, 13 Dec 2023 16:35:02 -0800 Subject: [PATCH 31/56] fix --- .../pipeline/transform/transformer/AttributeTransformer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/coderbot/iris/pipeline/transform/transformer/AttributeTransformer.java b/src/main/java/net/coderbot/iris/pipeline/transform/transformer/AttributeTransformer.java index c99c490ff2..baa53ad1d8 100644 --- a/src/main/java/net/coderbot/iris/pipeline/transform/transformer/AttributeTransformer.java +++ b/src/main/java/net/coderbot/iris/pipeline/transform/transformer/AttributeTransformer.java @@ -173,12 +173,12 @@ public static void patchOverlayColor( // TODO: this is passthrough behavior tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_DECLARATIONS, - "patch out vec4 entityColorTCS[];", + "patch out vec4 entityColorTCS;", "in vec4 entityColor[];", "out vec4 iris_vertexColorTCS[];", "in vec4 iris_vertexColor[];"); tree.prependMainFunctionBody(t, - "entityColorTCS[gl_InvocationID] = entityColor[gl_InvocationID];", + "entityColorTCS = entityColor[gl_InvocationID];", "iris_vertexColorTCS[gl_InvocationID] = iris_vertexColor[gl_InvocationID];"); } else if (parameters.type.glShaderType == ShaderType.TESSELATION_EVAL) { // replace read references to grab the color from the first vertex. From 8bc3a7ef7da23d082592f2c356a5ae313d4f4ccd Mon Sep 17 00:00:00 2001 From: IMS212 Date: Wed, 13 Dec 2023 21:22:30 -0800 Subject: [PATCH 32/56] Fix wireframe and patch stuff --- .../coderbot/iris/gl/IrisRenderSystem.java | 19 +++++++++++++++++++ .../iris/mixin/MixinLevelRenderer.java | 5 +++-- .../pipeline/transform/TransformPatcher.java | 6 +----- .../postprocess/FullScreenQuadRenderer.java | 3 +++ 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/coderbot/iris/gl/IrisRenderSystem.java b/src/main/java/net/coderbot/iris/gl/IrisRenderSystem.java index 6d54d86f4d..971fd3a48d 100644 --- a/src/main/java/net/coderbot/iris/gl/IrisRenderSystem.java +++ b/src/main/java/net/coderbot/iris/gl/IrisRenderSystem.java @@ -41,6 +41,8 @@ public class IrisRenderSystem { private static DSAAccess dsaState; private static boolean hasMultibind; private static boolean supportsCompute; + private static int polygonMode = GL43C.GL_FILL; + private static int backupPolygonMode = GL43C.GL_FILL; private static int[] samplers; public static void initRenderer() { @@ -424,6 +426,23 @@ public static void deleteBuffers(int glId) { GL43C.glDeleteBuffers(glId); } + public static void setPolygonMode(int mode) { + if (mode != polygonMode) { + polygonMode = mode; + GL43C.glPolygonMode(GL43C.GL_FRONT_AND_BACK, mode); + } + } + + public static void overridePolygonMode() { + backupPolygonMode = polygonMode; + setPolygonMode(GL43C.GL_FILL); + } + + public static void restorePolygonMode() { + setPolygonMode(backupPolygonMode); + backupPolygonMode = GL43C.GL_FILL; + } + public interface DSAAccess { void generateMipmaps(int texture, int target); diff --git a/src/main/java/net/coderbot/iris/mixin/MixinLevelRenderer.java b/src/main/java/net/coderbot/iris/mixin/MixinLevelRenderer.java index eaba334871..1b564909ce 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinLevelRenderer.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinLevelRenderer.java @@ -6,6 +6,7 @@ import com.mojang.math.Vector3f; import net.coderbot.iris.Iris; import net.coderbot.iris.fantastic.WrappingMultiBufferSource; +import net.coderbot.iris.gl.IrisRenderSystem; import net.coderbot.iris.gl.program.Program; import net.coderbot.iris.layer.IsOutlineRenderStateShard; import net.coderbot.iris.layer.OuterWrappedRenderType; @@ -89,7 +90,7 @@ public class MixinLevelRenderer { } if (Iris.shouldActivateWireframe() && this.minecraft.isLocalServer()) { - GL43C.glPolygonMode(GL43C.GL_FRONT_AND_BACK, GL43C.GL_LINE); + IrisRenderSystem.setPolygonMode(GL43C.GL_LINE); } } @@ -116,7 +117,7 @@ public class MixinLevelRenderer { pipeline = null; if (Iris.shouldActivateWireframe() && this.minecraft.isLocalServer()) { - GL43C.glPolygonMode(GL43C.GL_FRONT_AND_BACK, GL43C.GL_FILL); + IrisRenderSystem.setPolygonMode(GL43C.GL_FILL); } } diff --git a/src/main/java/net/coderbot/iris/pipeline/transform/TransformPatcher.java b/src/main/java/net/coderbot/iris/pipeline/transform/TransformPatcher.java index ebfcec90d1..a3c62b0a2c 100644 --- a/src/main/java/net/coderbot/iris/pipeline/transform/TransformPatcher.java +++ b/src/main/java/net/coderbot/iris/pipeline/transform/TransformPatcher.java @@ -194,11 +194,7 @@ public TranslationUnit parseTranslationUnit(Root rootInstance, String input) { throw new IllegalArgumentException( "No #version directive found in source code! See debugging.md for more information."); } - Version version = Version.fromNumber(Integer.parseInt(matcher.group(1))); - if (version.number >= 200) { - version = Version.GLSL33; - } - transformer.getLexer().version = version; + transformer.getLexer().version = Version.fromNumber(Integer.parseInt(matcher.group(1))); return super.parseTranslationUnit(rootInstance, input); } diff --git a/src/main/java/net/coderbot/iris/postprocess/FullScreenQuadRenderer.java b/src/main/java/net/coderbot/iris/postprocess/FullScreenQuadRenderer.java index 3d3554ea81..6af4f42051 100644 --- a/src/main/java/net/coderbot/iris/postprocess/FullScreenQuadRenderer.java +++ b/src/main/java/net/coderbot/iris/postprocess/FullScreenQuadRenderer.java @@ -7,6 +7,7 @@ import com.mojang.blaze3d.vertex.VertexBuffer; import com.mojang.blaze3d.vertex.VertexFormat; import net.coderbot.iris.fantastic.VertexBufferHelper; +import net.coderbot.iris.gl.IrisRenderSystem; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL20C; @@ -51,7 +52,9 @@ public void begin() { } public void renderQuad() { + IrisRenderSystem.overridePolygonMode(); quad.drawChunkLayer(); + IrisRenderSystem.restorePolygonMode(); } public void end() { From de9d9699ba241c6ae90d233e56387856b74bf0e9 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Sat, 16 Dec 2023 08:43:39 -0800 Subject: [PATCH 33/56] fix --- .../iris/pipeline/newshader/FakeChainedJsonException.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/coderbot/iris/pipeline/newshader/FakeChainedJsonException.java b/src/main/java/net/coderbot/iris/pipeline/newshader/FakeChainedJsonException.java index ebf79e12a2..5d387a45b9 100644 --- a/src/main/java/net/coderbot/iris/pipeline/newshader/FakeChainedJsonException.java +++ b/src/main/java/net/coderbot/iris/pipeline/newshader/FakeChainedJsonException.java @@ -7,7 +7,7 @@ public class FakeChainedJsonException extends ChainedJsonException { private final ShaderCompileException trueException; public FakeChainedJsonException(ShaderCompileException e) { - super(""); + super("", e); this.trueException = e; } From 2a0dd70224d6bae54df89ed08801120cb9361ece Mon Sep 17 00:00:00 2001 From: IMS212 Date: Sat, 16 Dec 2023 11:30:12 -0800 Subject: [PATCH 34/56] Minor optimizations --- .../MixinGlStateManager_FramebufferBinding.java | 10 ++++++++++ .../coderbot/iris/postprocess/CompositeRenderer.java | 7 +++++-- .../coderbot/iris/postprocess/FinalPassRenderer.java | 7 +++++-- .../mixin/shader_overrides/MixinGlProgram.java | 12 ++++++++++++ 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/coderbot/iris/mixin/MixinGlStateManager_FramebufferBinding.java b/src/main/java/net/coderbot/iris/mixin/MixinGlStateManager_FramebufferBinding.java index 91c5b7141b..1ec636a8f0 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinGlStateManager_FramebufferBinding.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinGlStateManager_FramebufferBinding.java @@ -16,6 +16,7 @@ public class MixinGlStateManager_FramebufferBinding { private static int iris$drawFramebuffer = 0; private static int iris$readFramebuffer = 0; + private static int iris$program = 0; @Inject(method = "_glBindFramebuffer(II)V", at = @At("HEAD"), cancellable = true, remap = false) private static void iris$avoidRedundantBind(int target, int framebuffer, CallbackInfo ci) { @@ -43,6 +44,15 @@ public class MixinGlStateManager_FramebufferBinding { } } + @Inject(method = "_glUseProgram", at = @At("HEAD"), cancellable = true, remap = false) + private static void iris$avoidRedundantBind2(int pInt0, CallbackInfo ci) { + if (iris$program == pInt0) { + ci.cancel(); + } else { + iris$program = pInt0; + } + } + @Inject(method = "_glDeleteFramebuffers(I)V", at = @At("HEAD"), remap = false) private static void iris$trackFramebufferDelete(int framebuffer, CallbackInfo ci) { if (iris$drawFramebuffer == framebuffer) { diff --git a/src/main/java/net/coderbot/iris/postprocess/CompositeRenderer.java b/src/main/java/net/coderbot/iris/postprocess/CompositeRenderer.java index 9b3c67b432..18473dc9d2 100644 --- a/src/main/java/net/coderbot/iris/postprocess/CompositeRenderer.java +++ b/src/main/java/net/coderbot/iris/postprocess/CompositeRenderer.java @@ -26,6 +26,7 @@ import net.coderbot.iris.gl.program.ProgramUniforms; import net.coderbot.iris.gl.sampler.SamplerLimits; import net.coderbot.iris.gl.texture.TextureAccess; +import net.coderbot.iris.mixin.GlStateManagerAccessor; import net.coderbot.iris.pipeline.DeferredWorldRenderingPipeline; import net.coderbot.iris.pipeline.WorldRenderingPipeline; import net.coderbot.iris.rendertarget.RenderTarget; @@ -302,8 +303,10 @@ public void renderAll() { for (int i = 0; i < SamplerLimits.get().getMaxTextureUnits(); i++) { // Unbind all textures that we may have used. // NB: This is necessary for shader pack reloading to work propely - RenderSystem.activeTexture(GL15C.GL_TEXTURE0 + i); - RenderSystem.bindTexture(0); + if (GlStateManagerAccessor.getTEXTURES()[i].binding != 0) { + RenderSystem.activeTexture(GL15C.GL_TEXTURE0 + i); + RenderSystem.bindTexture(0); + } } RenderSystem.activeTexture(GL15C.GL_TEXTURE0); diff --git a/src/main/java/net/coderbot/iris/postprocess/FinalPassRenderer.java b/src/main/java/net/coderbot/iris/postprocess/FinalPassRenderer.java index b272e2b7a3..304580be3c 100644 --- a/src/main/java/net/coderbot/iris/postprocess/FinalPassRenderer.java +++ b/src/main/java/net/coderbot/iris/postprocess/FinalPassRenderer.java @@ -17,6 +17,7 @@ import net.coderbot.iris.gl.program.ProgramUniforms; import net.coderbot.iris.gl.sampler.SamplerLimits; import net.coderbot.iris.gl.texture.TextureAccess; +import net.coderbot.iris.mixin.GlStateManagerAccessor; import net.coderbot.iris.pipeline.DeferredWorldRenderingPipeline; import net.coderbot.iris.pipeline.ShaderPrinter; import net.coderbot.iris.pipeline.WorldRenderingPipeline; @@ -274,8 +275,10 @@ public void renderFinalPass() { for (int i = 0; i < SamplerLimits.get().getMaxTextureUnits(); i++) { // Unbind all textures that we may have used. // NB: This is necessary for shader pack reloading to work properly - RenderSystem.activeTexture(GL15C.GL_TEXTURE0 + i); - RenderSystem.bindTexture(0); + if (GlStateManagerAccessor.getTEXTURES()[i].binding != 0) { + RenderSystem.activeTexture(GL15C.GL_TEXTURE0 + i); + RenderSystem.bindTexture(0); + } } RenderSystem.activeTexture(GL15C.GL_TEXTURE0); diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinGlProgram.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinGlProgram.java index 8c7603e187..f96d9a8002 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinGlProgram.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinGlProgram.java @@ -8,6 +8,8 @@ import net.coderbot.iris.compat.sodium.impl.shader_overrides.ShaderBindingContextExt; import net.coderbot.iris.gl.IrisRenderSystem; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; import java.util.function.IntFunction; @@ -22,6 +24,16 @@ public > U bindUniformIfPresent(String name, IntFunction< } } + @Redirect(method = "bind", at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL20C;glUseProgram(I)V")) + private void iris$useGlStateManager(int i) { + GlStateManager._glUseProgram(i); + } + + @Redirect(method = "unbind", at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL20C;glUseProgram(I)V")) + private void iris$useGlStateManager2(int i) { + GlStateManager._glUseProgram(i); + } + public GlUniformBlock bindUniformBlockIfPresent(String name, int bindingPoint) { int index = IrisRenderSystem.getUniformBlockIndex(this.handle(), name); if (index < 0) { From d339b861b2a1fac475327eebf5e02440031ed25c Mon Sep 17 00:00:00 2001 From: IMS212 Date: Tue, 19 Dec 2023 13:47:44 -0800 Subject: [PATCH 35/56] Add tesselation shader feature flag --- .../coderbot/iris/features/FeatureFlags.java | 1 + .../coderbot/iris/gl/IrisRenderSystem.java | 6 ++ .../coderbot/iris/shaderpack/ProgramSet.java | 92 ++++++++++--------- 3 files changed, 57 insertions(+), 42 deletions(-) diff --git a/src/main/java/net/coderbot/iris/features/FeatureFlags.java b/src/main/java/net/coderbot/iris/features/FeatureFlags.java index 99a9ef7dff..01ca0059ff 100644 --- a/src/main/java/net/coderbot/iris/features/FeatureFlags.java +++ b/src/main/java/net/coderbot/iris/features/FeatureFlags.java @@ -14,6 +14,7 @@ public enum FeatureFlags { CUSTOM_IMAGES(() -> true, IrisRenderSystem::supportsImageLoadStore), PER_BUFFER_BLENDING(() -> true, IrisRenderSystem::supportsBufferBlending), COMPUTE_SHADERS(() -> true, IrisRenderSystem::supportsCompute), + TESSELATION_SHADERS(() -> true, IrisRenderSystem::supportsTesselation), ENTITY_TRANSLUCENT(() -> true, () -> true), REVERSED_CULLING(() -> true, () -> true), SSBO(() -> true, IrisRenderSystem::supportsSSBO), diff --git a/src/main/java/net/coderbot/iris/gl/IrisRenderSystem.java b/src/main/java/net/coderbot/iris/gl/IrisRenderSystem.java index 971fd3a48d..5014a30f36 100644 --- a/src/main/java/net/coderbot/iris/gl/IrisRenderSystem.java +++ b/src/main/java/net/coderbot/iris/gl/IrisRenderSystem.java @@ -41,6 +41,7 @@ public class IrisRenderSystem { private static DSAAccess dsaState; private static boolean hasMultibind; private static boolean supportsCompute; + private static boolean supportsTesselation; private static int polygonMode = GL43C.GL_FILL; private static int backupPolygonMode = GL43C.GL_FILL; private static int[] samplers; @@ -60,6 +61,7 @@ public static void initRenderer() { hasMultibind = GL.getCapabilities().OpenGL45 || GL.getCapabilities().GL_ARB_multi_bind; supportsCompute = GL.getCapabilities().glDispatchCompute != MemoryUtil.NULL; + supportsTesselation = GL.getCapabilities().GL_ARB_tessellation_shader || GL.getCapabilities().OpenGL40; samplers = new int[SamplerLimits.get().getMaxTextureUnits()]; } @@ -366,6 +368,10 @@ public static boolean supportsCompute() { return supportsCompute; } + public static boolean supportsTesselation() { + return supportsTesselation; + } + public static int genSampler() { return GL33C.glGenSamplers(); } diff --git a/src/main/java/net/coderbot/iris/shaderpack/ProgramSet.java b/src/main/java/net/coderbot/iris/shaderpack/ProgramSet.java index e7794cfd3d..d82f658523 100644 --- a/src/main/java/net/coderbot/iris/shaderpack/ProgramSet.java +++ b/src/main/java/net/coderbot/iris/shaderpack/ProgramSet.java @@ -1,6 +1,7 @@ package net.coderbot.iris.shaderpack; import net.coderbot.iris.Iris; +import net.coderbot.iris.features.FeatureFlags; import net.coderbot.iris.gl.blending.BlendMode; import net.coderbot.iris.gl.blending.BlendModeFunction; import net.coderbot.iris.gl.blending.BlendModeOverride; @@ -82,11 +83,13 @@ public ProgramSet(AbsolutePackPath directory, Function // // - https://github.com/IrisShaders/Iris/issues/483 // - https://github.com/IrisShaders/Iris/issues/987 + boolean readTesselation = pack.hasFeature(FeatureFlags.TESSELATION_SHADERS); + this.shadow = readProgramSource(directory, sourceProvider, "shadow", this, shaderProperties, - BlendModeOverride.OFF); + BlendModeOverride.OFF, readTesselation); this.shadowCompute = readComputeArray(directory, sourceProvider, "shadow"); - this.shadowcomp = readProgramArray(directory, sourceProvider, "shadowcomp", shaderProperties); + this.shadowcomp = readProgramArray(directory, sourceProvider, "shadowcomp", shaderProperties, readTesselation); this.shadowCompCompute = new ComputeSource[shadowcomp.length][]; for (int i = 0; i < shadowcomp.length; i++) { @@ -95,57 +98,57 @@ public ProgramSet(AbsolutePackPath directory, Function this.setup = readProgramArray(directory, sourceProvider, "setup"); - this.begin = readProgramArray(directory, sourceProvider, "begin", shaderProperties); + this.begin = readProgramArray(directory, sourceProvider, "begin", shaderProperties, readTesselation); this.beginCompute = new ComputeSource[begin.length][]; for (int i = 0; i < begin.length; i++) { this.beginCompute[i] = readComputeArray(directory, sourceProvider, "begin" + ((i == 0) ? "" : i)); } - this.prepare = readProgramArray(directory, sourceProvider, "prepare", shaderProperties); + this.prepare = readProgramArray(directory, sourceProvider, "prepare", shaderProperties, readTesselation); this.prepareCompute = new ComputeSource[prepare.length][]; for (int i = 0; i < prepare.length; i++) { this.prepareCompute[i] = readComputeArray(directory, sourceProvider, "prepare" + ((i == 0) ? "" : i)); } - this.gbuffersBasic = readProgramSource(directory, sourceProvider, "gbuffers_basic", this, shaderProperties); - this.gbuffersLine = readProgramSource(directory, sourceProvider, "gbuffers_line", this, shaderProperties); - this.gbuffersBeaconBeam = readProgramSource(directory, sourceProvider, "gbuffers_beaconbeam", this, shaderProperties); - this.gbuffersTextured = readProgramSource(directory, sourceProvider, "gbuffers_textured", this, shaderProperties); - this.gbuffersTexturedLit = readProgramSource(directory, sourceProvider, "gbuffers_textured_lit", this, shaderProperties); - this.gbuffersTerrain = readProgramSource(directory, sourceProvider, "gbuffers_terrain", this, shaderProperties); - this.gbuffersTerrainSolid = readProgramSource(directory, sourceProvider, "gbuffers_terrain_solid", this, shaderProperties); - this.gbuffersTerrainCutout = readProgramSource(directory, sourceProvider, "gbuffers_terrain_cutout", this, shaderProperties); - this.gbuffersDamagedBlock = readProgramSource(directory, sourceProvider, "gbuffers_damagedblock", this, shaderProperties); - this.gbuffersSkyBasic = readProgramSource(directory, sourceProvider, "gbuffers_skybasic", this, shaderProperties); - this.gbuffersSkyTextured = readProgramSource(directory, sourceProvider, "gbuffers_skytextured", this, shaderProperties); - this.gbuffersClouds = readProgramSource(directory, sourceProvider, "gbuffers_clouds", this, shaderProperties); - this.gbuffersWeather = readProgramSource(directory, sourceProvider, "gbuffers_weather", this, shaderProperties); - this.gbuffersEntities = readProgramSource(directory, sourceProvider, "gbuffers_entities", this, shaderProperties); - this.gbuffersEntitiesTrans = readProgramSource(directory, sourceProvider, "gbuffers_entities_translucent", this, shaderProperties); - this.gbuffersParticles = readProgramSource(directory, sourceProvider, "gbuffers_particles", this, shaderProperties); - this.gbuffersParticlesTrans = readProgramSource(directory, sourceProvider, "gbuffers_particles_translucent", this, shaderProperties); - this.gbuffersEntitiesGlowing = readProgramSource(directory, sourceProvider, "gbuffers_entities_glowing", this, shaderProperties); - this.gbuffersGlint = readProgramSource(directory, sourceProvider, "gbuffers_armor_glint", this, shaderProperties); - this.gbuffersEntityEyes = readProgramSource(directory, sourceProvider, "gbuffers_spidereyes", this, shaderProperties); - this.gbuffersBlock = readProgramSource(directory, sourceProvider, "gbuffers_block", this, shaderProperties); - this.gbuffersBlockTrans = readProgramSource(directory, sourceProvider, "gbuffers_block_translucent", this, shaderProperties); - this.gbuffersHand = readProgramSource(directory, sourceProvider, "gbuffers_hand", this, shaderProperties); - - this.deferred = readProgramArray(directory, sourceProvider, "deferred", shaderProperties); + this.gbuffersBasic = readProgramSource(directory, sourceProvider, "gbuffers_basic", this, shaderProperties, readTesselation); + this.gbuffersLine = readProgramSource(directory, sourceProvider, "gbuffers_line", this, shaderProperties, readTesselation); + this.gbuffersBeaconBeam = readProgramSource(directory, sourceProvider, "gbuffers_beaconbeam", this, shaderProperties, readTesselation); + this.gbuffersTextured = readProgramSource(directory, sourceProvider, "gbuffers_textured", this, shaderProperties, readTesselation); + this.gbuffersTexturedLit = readProgramSource(directory, sourceProvider, "gbuffers_textured_lit", this, shaderProperties, readTesselation); + this.gbuffersTerrain = readProgramSource(directory, sourceProvider, "gbuffers_terrain", this, shaderProperties, readTesselation); + this.gbuffersTerrainSolid = readProgramSource(directory, sourceProvider, "gbuffers_terrain_solid", this, shaderProperties, readTesselation); + this.gbuffersTerrainCutout = readProgramSource(directory, sourceProvider, "gbuffers_terrain_cutout", this, shaderProperties, readTesselation); + this.gbuffersDamagedBlock = readProgramSource(directory, sourceProvider, "gbuffers_damagedblock", this, shaderProperties, readTesselation); + this.gbuffersSkyBasic = readProgramSource(directory, sourceProvider, "gbuffers_skybasic", this, shaderProperties, readTesselation); + this.gbuffersSkyTextured = readProgramSource(directory, sourceProvider, "gbuffers_skytextured", this, shaderProperties, readTesselation); + this.gbuffersClouds = readProgramSource(directory, sourceProvider, "gbuffers_clouds", this, shaderProperties, readTesselation); + this.gbuffersWeather = readProgramSource(directory, sourceProvider, "gbuffers_weather", this, shaderProperties, readTesselation); + this.gbuffersEntities = readProgramSource(directory, sourceProvider, "gbuffers_entities", this, shaderProperties, readTesselation); + this.gbuffersEntitiesTrans = readProgramSource(directory, sourceProvider, "gbuffers_entities_translucent", this, shaderProperties, readTesselation); + this.gbuffersParticles = readProgramSource(directory, sourceProvider, "gbuffers_particles", this, shaderProperties, readTesselation); + this.gbuffersParticlesTrans = readProgramSource(directory, sourceProvider, "gbuffers_particles_translucent", this, shaderProperties, readTesselation); + this.gbuffersEntitiesGlowing = readProgramSource(directory, sourceProvider, "gbuffers_entities_glowing", this, shaderProperties, readTesselation); + this.gbuffersGlint = readProgramSource(directory, sourceProvider, "gbuffers_armor_glint", this, shaderProperties, readTesselation); + this.gbuffersEntityEyes = readProgramSource(directory, sourceProvider, "gbuffers_spidereyes", this, shaderProperties, readTesselation); + this.gbuffersBlock = readProgramSource(directory, sourceProvider, "gbuffers_block", this, shaderProperties, readTesselation); + this.gbuffersBlockTrans = readProgramSource(directory, sourceProvider, "gbuffers_block_translucent", this, shaderProperties, readTesselation); + this.gbuffersHand = readProgramSource(directory, sourceProvider, "gbuffers_hand", this, shaderProperties, readTesselation); + + this.deferred = readProgramArray(directory, sourceProvider, "deferred", shaderProperties, readTesselation); this.deferredCompute = new ComputeSource[deferred.length][]; for (int i = 0; i < deferred.length; i++) { this.deferredCompute[i] = readComputeArray(directory, sourceProvider, "deferred" + ((i == 0) ? "" : i)); } - this.gbuffersWater = readProgramSource(directory, sourceProvider, "gbuffers_water", this, shaderProperties); - this.gbuffersHandWater = readProgramSource(directory, sourceProvider, "gbuffers_hand_water", this, shaderProperties); + this.gbuffersWater = readProgramSource(directory, sourceProvider, "gbuffers_water", this, shaderProperties, readTesselation); + this.gbuffersHandWater = readProgramSource(directory, sourceProvider, "gbuffers_hand_water", this, shaderProperties, readTesselation); - this.composite = readProgramArray(directory, sourceProvider, "composite", shaderProperties); + this.composite = readProgramArray(directory, sourceProvider, "composite", shaderProperties, readTesselation); this.compositeCompute = new ComputeSource[composite.length][]; for (int i = 0; i < deferred.length; i++) { this.compositeCompute[i] = readComputeArray(directory, sourceProvider, "composite" + ((i == 0) ? "" : i)); } - this.compositeFinal = readProgramSource(directory, sourceProvider, "final", this, shaderProperties); + this.compositeFinal = readProgramSource(directory, sourceProvider, "final", this, shaderProperties, readTesselation); this.finalCompute = readComputeArray(directory, sourceProvider, "final"); locateDirectives(); @@ -174,13 +177,13 @@ private static Optional first(Optional... candidates) { private ProgramSource[] readProgramArray(AbsolutePackPath directory, Function sourceProvider, String name, - ShaderProperties shaderProperties) { + ShaderProperties shaderProperties, boolean readTesselation) { ProgramSource[] programs = new ProgramSource[100]; for (int i = 0; i < programs.length; i++) { String suffix = i == 0 ? "" : Integer.toString(i); - programs[i] = readProgramSource(directory, sourceProvider, name + suffix, this, shaderProperties); + programs[i] = readProgramSource(directory, sourceProvider, name + suffix, this, shaderProperties, readTesselation); } return programs; @@ -502,25 +505,30 @@ public ShaderPack getPack() { private static ProgramSource readProgramSource(AbsolutePackPath directory, Function sourceProvider, String program, - ProgramSet programSet, ShaderProperties properties) { - return readProgramSource(directory, sourceProvider, program, programSet, properties, null); + ProgramSet programSet, ShaderProperties properties, boolean readTesselation) { + return readProgramSource(directory, sourceProvider, program, programSet, properties, null, readTesselation); } private static ProgramSource readProgramSource(AbsolutePackPath directory, Function sourceProvider, String program, ProgramSet programSet, ShaderProperties properties, - BlendModeOverride defaultBlendModeOverride) { + BlendModeOverride defaultBlendModeOverride, boolean readTesselation) { AbsolutePackPath vertexPath = directory.resolve(program + ".vsh"); String vertexSource = sourceProvider.apply(vertexPath); AbsolutePackPath geometryPath = directory.resolve(program + ".gsh"); String geometrySource = sourceProvider.apply(geometryPath); - AbsolutePackPath tessControlPath = directory.resolve(program + ".tcs"); - String tessControlSource = sourceProvider.apply(tessControlPath); + String tessControlSource = null; + String tessEvalSource = null; + + if (readTesselation) { + AbsolutePackPath tessControlPath = directory.resolve(program + ".tcs"); + tessControlSource = sourceProvider.apply(tessControlPath); - AbsolutePackPath tessEvalPath = directory.resolve(program + ".tes"); - String tessEvalSource = sourceProvider.apply(tessEvalPath); + AbsolutePackPath tessEvalPath = directory.resolve(program + ".tes"); + tessEvalSource = sourceProvider.apply(tessEvalPath); + } AbsolutePackPath fragmentPath = directory.resolve(program + ".fsh"); String fragmentSource = sourceProvider.apply(fragmentPath); From da9011df971502e8526ec164d754c1994dd71c1a Mon Sep 17 00:00:00 2001 From: IMS212 Date: Wed, 20 Dec 2023 18:16:19 -0800 Subject: [PATCH 36/56] Change texture encoding --- buildscript/src/main/java/Buildscript.java | 4 ++-- .../transformer/SodiumTransformer.java | 4 ++-- .../terrain_xhfp/XHFPModelVertexType.java | 7 ++++--- .../terrain_xhfp/XHFPTerrainVertex.java | 19 ++++++------------- 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/buildscript/src/main/java/Buildscript.java b/buildscript/src/main/java/Buildscript.java index a4808ba3cd..15ddc59234 100644 --- a/buildscript/src/main/java/Buildscript.java +++ b/buildscript/src/main/java/Buildscript.java @@ -114,10 +114,10 @@ public void getModDependencies(ModDependencyCollector d) { if (CUSTOM_SODIUM) { d.add(new JavaJarDependency(getProjectDir().resolve("custom_sodium").resolve(customSodiumName).toAbsolutePath(), null, new MavenId("me.jellysquid.mods", "sodium-fabric", customSodiumName.replace("sodium-fabric-", ""))), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); } else { - d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "sodium", "mc1.20.3-0.5.6"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); + d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "sodium", "mc1.20.3-0.5.5"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); } } else { - d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "sodium", "mc1.20.3-0.5.6"), ModDependencyFlag.COMPILE); + d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "sodium", "mc1.20.3-0.5.5"), ModDependencyFlag.COMPILE); } } diff --git a/src/main/java/net/coderbot/iris/pipeline/transform/transformer/SodiumTransformer.java b/src/main/java/net/coderbot/iris/pipeline/transform/transformer/SodiumTransformer.java index 1ca0780d55..f0cd0f0511 100644 --- a/src/main/java/net/coderbot/iris/pipeline/transform/transformer/SodiumTransformer.java +++ b/src/main/java/net/coderbot/iris/pipeline/transform/transformer/SodiumTransformer.java @@ -28,7 +28,7 @@ public static void transform( SodiumParameters parameters) { CommonTransformer.transform(t, tree, root, parameters, false); - replaceMidTexCoord(t, tree, root, 1.0f / 65536.0f); + replaceMidTexCoord(t, tree, root, 1.0f / 32768.0f); root.replaceExpressionMatches(t, CommonTransformer.glTextureMatrix0, "mat4(1.0)"); root.replaceExpressionMatches(t, CommonTransformer.glTextureMatrix1, "iris_LightmapTextureMatrix"); @@ -150,7 +150,7 @@ public static void injectVertInit( "void _vert_init() {" + "_vert_position = (vec3(a_PosId.xyz) * 0.00048828125 + -8.0" + ");" + - "_vert_tex_diffuse_coord = (a_TexCoord * 1.52587891E-5);" + + "_vert_tex_diffuse_coord = (a_TexCoord * " + (1.0f / 32768.0f) + ");" + "_vert_tex_light_coord = a_LightCoord;" + "_vert_color = " + separateAo + ";" + "_draw_id = (a_PosId.w >> 8u) & 0xFFu; }", diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPModelVertexType.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPModelVertexType.java index 827aab09fa..5588199216 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPModelVertexType.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPModelVertexType.java @@ -27,7 +27,7 @@ public class XHFPModelVertexType implements ChunkVertexType { .build(); private static final int POSITION_MAX_VALUE = 65536; - private static final int TEXTURE_MAX_VALUE = 65536; + private static final int TEXTURE_MAX_VALUE = 32768; private static final float MODEL_ORIGIN = 8.0f; private static final float MODEL_RANGE = 32.0f; @@ -47,8 +47,9 @@ public ChunkVertexEncoder getEncoder() { return new XHFPTerrainVertex(); } - static short encodeBlockTexture(float value) { - return (short) (Math.min(0.99999997F, value) * TEXTURE_MAX_VALUE); + public static int encodeTexture(float u, float v) { + return ((Math.round(u * TEXTURE_MAX_VALUE) & 0xFFFF) << 0) | + ((Math.round(v * TEXTURE_MAX_VALUE) & 0xFFFF) << 16); } static float decodeBlockTexture(short raw) { diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPTerrainVertex.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPTerrainVertex.java index c29be96ab5..a70b2edb81 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPTerrainVertex.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPTerrainVertex.java @@ -74,8 +74,7 @@ public long write(long ptr, MemoryUtil.memPutInt(ptr + 8, vertex.color); - MemoryUtil.memPutShort(ptr + 12, XHFPModelVertexType.encodeBlockTexture(vertex.u)); - MemoryUtil.memPutShort(ptr + 14, XHFPModelVertexType.encodeBlockTexture(vertex.v)); + MemoryUtil.memPutInt(ptr + 12, XHFPModelVertexType.encodeTexture(vertex.u, vertex.v)); MemoryUtil.memPutInt(ptr + 16, vertex.light); @@ -116,18 +115,12 @@ public long write(long ptr, uSum *= 0.25f; vSum *= 0.25f; - short midU = XHFPModelVertexType.encodeBlockTexture(uSum); - short midV = XHFPModelVertexType.encodeBlockTexture(vSum); + int midUV = XHFPModelVertexType.encodeTexture(uSum, vSum); - MemoryUtil.memPutShort(ptr + 20, midU); - MemoryUtil.memPutShort(ptr + 20 - STRIDE, midU); - MemoryUtil.memPutShort(ptr + 20 - STRIDE * 2, midU); - MemoryUtil.memPutShort(ptr + 20 - STRIDE * 3, midU); - - MemoryUtil.memPutShort(ptr + 22, midV); - MemoryUtil.memPutShort(ptr + 22 - STRIDE, midV); - MemoryUtil.memPutShort(ptr + 22 - STRIDE * 2, midV); - MemoryUtil.memPutShort(ptr + 22 - STRIDE * 3, midV); + MemoryUtil.memPutInt(ptr + 20, midUV); + MemoryUtil.memPutInt(ptr + 20 - STRIDE, midUV); + MemoryUtil.memPutInt(ptr + 20 - STRIDE * 2, midUV); + MemoryUtil.memPutInt(ptr + 20 - STRIDE * 3, midUV); uSum = 0; vSum = 0; From 64d3dfa22dfa5333467e22de12fbd5ca1b0e3169 Mon Sep 17 00:00:00 2001 From: snowfallin <140451338+snowfallin@users.noreply.github.com> Date: Thu, 21 Dec 2023 21:08:16 -0500 Subject: [PATCH 37/56] Added support for armor as a uniform -currentArmor uniform -maxArmor uniform (50) --- .../iris/uniforms/IrisExclusiveUniforms.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/coderbot/iris/uniforms/IrisExclusiveUniforms.java b/src/main/java/net/coderbot/iris/uniforms/IrisExclusiveUniforms.java index fa60aa597a..83f6273f4d 100644 --- a/src/main/java/net/coderbot/iris/uniforms/IrisExclusiveUniforms.java +++ b/src/main/java/net/coderbot/iris/uniforms/IrisExclusiveUniforms.java @@ -31,8 +31,10 @@ public static void addIrisExclusiveUniforms(UniformHolder uniforms) { uniforms.uniform1f(UniformUpdateFrequency.PER_FRAME, "thunderStrength", IrisExclusiveUniforms::getThunderStrength); uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "currentPlayerHealth", IrisExclusiveUniforms::getCurrentHealth); uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "maxPlayerHealth", IrisExclusiveUniforms::getMaxHealth); - uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "currentPlayerHunger", IrisExclusiveUniforms::getCurrentHunger); + uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "currentPlayerHunger", IrisExclusiveUniforms::getCurrentHunger); uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "maxPlayerHunger", () -> 20); + uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "currentPlayerArmor", IrisExclusiveUniforms::getCurrentArmor); + uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "maxPlayerArmor", () -> 50); uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "currentPlayerAir", IrisExclusiveUniforms::getCurrentAir); uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "maxPlayerAir", IrisExclusiveUniforms::getMaxAir); uniforms.uniform1b(UniformUpdateFrequency.PER_FRAME, "firstPersonCamera", IrisExclusiveUniforms::isFirstPersonCamera); @@ -91,6 +93,14 @@ private static float getCurrentAir() { return (float) Minecraft.getInstance().player.getAirSupply() / (float) Minecraft.getInstance().player.getMaxAirSupply(); } + private static float getCurrentArmor() { + if (Minecraft.getInstance().player == null || !Minecraft.getInstance().gameMode.getPlayerMode().isSurvival()) { + return -1; + } + + return (float) Minecraft.getInstance().player.getArmor() / (float) 50.0); + } + private static float getMaxAir() { if (Minecraft.getInstance().player == null || !Minecraft.getInstance().gameMode.getPlayerMode().isSurvival()) { return -1; @@ -107,6 +117,8 @@ private static float getMaxHealth() { return Minecraft.getInstance().player.getMaxHealth(); } + + private static boolean isFirstPersonCamera() { // If camera type is not explicitly third-person, assume it's first-person. switch (Minecraft.getInstance().options.getCameraType()) { From 0b8ff9927c7dbcef016ccf3a4bfbdff076c36026 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Sat, 23 Dec 2023 15:42:26 -0800 Subject: [PATCH 38/56] Fix my own sins --- src/main/java/net/coderbot/iris/Iris.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/net/coderbot/iris/Iris.java b/src/main/java/net/coderbot/iris/Iris.java index 5ee77b93bc..830f4e1c1c 100644 --- a/src/main/java/net/coderbot/iris/Iris.java +++ b/src/main/java/net/coderbot/iris/Iris.java @@ -3,6 +3,7 @@ import com.google.common.base.Throwables; import com.mojang.blaze3d.platform.GlDebug; import com.mojang.blaze3d.platform.InputConstants; +import com.sun.jna.platform.unix.LibC; import net.coderbot.iris.compat.sodium.SodiumVersionCheck; import net.coderbot.iris.config.IrisConfig; import net.coderbot.iris.gl.GLDebug; @@ -29,12 +30,14 @@ import net.fabricmc.loader.api.ModContainer; import net.fabricmc.loader.api.Version; import net.minecraft.ChatFormatting; +import net.minecraft.Util; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.network.chat.TranslatableComponent; import org.jetbrains.annotations.NotNull; import org.lwjgl.glfw.GLFW; +import org.lwjgl.system.Configuration; import java.io.IOException; import java.io.InputStream; @@ -91,6 +94,13 @@ public class Iris { private static UpdateChecker updateChecker; private static boolean fallback; + static { + // Custom fix only for me for Plasma 6 + if (FabricLoader.getInstance().isDevelopmentEnvironment() && Util.getPlatform() == Util.OS.LINUX && System.getProperty("user.name").contains("ims")) { + LibC.INSTANCE.setenv("__GL_THREADED_OPTIMIZATIONS", "0", 1); + Configuration.GLFW_LIBRARY_NAME.set("/usr/lib/libglfw.so"); + } + } /** * 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. From dbbb3debe59b7efa741829aefa5dfb25ff2bfd18 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Sun, 24 Dec 2023 08:58:52 -0800 Subject: [PATCH 39/56] Fix tesselation --- .../pipeline/newshader/ExtendedShader.java | 28 ++++++++++++++++++- .../pipeline/newshader/NewShaderTests.java | 10 +++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/coderbot/iris/pipeline/newshader/ExtendedShader.java b/src/main/java/net/coderbot/iris/pipeline/newshader/ExtendedShader.java index e536c4798b..1e10c602f0 100644 --- a/src/main/java/net/coderbot/iris/pipeline/newshader/ExtendedShader.java +++ b/src/main/java/net/coderbot/iris/pipeline/newshader/ExtendedShader.java @@ -259,7 +259,7 @@ public void attachToProgram() { } @Override - public void iris$createGeometryShader(ResourceProvider factory, String name) throws IOException { + public void iris$createExtraShaders(ResourceProvider factory, String name) throws IOException { factory.getResource(new ResourceLocation("minecraft", name + "_geometry.gsh")).ifPresent(geometry -> { try { this.geometry = Program.compileShader(IrisProgramTypes.GEOMETRY, name, geometry.open(), geometry.sourcePackId(), new GlslPreprocessor() { @@ -273,6 +273,32 @@ public String applyImport(boolean bl, String string) { e.printStackTrace(); } }); + factory.getResource(new ResourceLocation("minecraft", name + "_tessControl.tcs")).ifPresent(tessControl -> { + try { + this.tessControl = Program.compileShader(IrisProgramTypes.TESS_CONTROL, name, tessControl.open(), tessControl.sourcePackId(), new GlslPreprocessor() { + @Nullable + @Override + public String applyImport(boolean bl, String string) { + return null; + } + }); + } catch (IOException e) { + e.printStackTrace(); + } + }); + factory.getResource(new ResourceLocation("minecraft", name + "_tessEval.tes")).ifPresent(tessEval -> { + try { + this.tessEval = Program.compileShader(IrisProgramTypes.TESS_EVAL, name, tessEval.open(), tessEval.sourcePackId(), new GlslPreprocessor() { + @Nullable + @Override + public String applyImport(boolean bl, String string) { + return null; + } + }); + } catch (IOException e) { + e.printStackTrace(); + } + }); } public Program getGeometry() { diff --git a/src/main/java/net/coderbot/iris/pipeline/newshader/NewShaderTests.java b/src/main/java/net/coderbot/iris/pipeline/newshader/NewShaderTests.java index 19d3a87f4e..2545c3b7ab 100644 --- a/src/main/java/net/coderbot/iris/pipeline/newshader/NewShaderTests.java +++ b/src/main/java/net/coderbot/iris/pipeline/newshader/NewShaderTests.java @@ -205,6 +205,16 @@ public Optional getResource(ResourceLocation id) { return Optional.empty(); } return Optional.of(new StringResource(id, geometry)); + } else if (path.endsWith("tcs")) { + if (tessControl == null) { + return Optional.empty(); + } + return Optional.of(new StringResource(id, tessControl)); + } else if (path.endsWith("tes")) { + if (tessEval == null) { + return Optional.empty(); + } + return Optional.of(new StringResource(id, tessEval)); } else if (path.endsWith("fsh")) { return Optional.of(new StringResource(id, fragment)); } From cc4d2bed0cc7e58cbb6de1011fbfb1d05a23c38e Mon Sep 17 00:00:00 2001 From: IMS212 Date: Sun, 24 Dec 2023 09:02:41 -0800 Subject: [PATCH 40/56] Fixed tesselation compat patcher --- .../transform/transformer/CompatibilityTransformer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/coderbot/iris/pipeline/transform/transformer/CompatibilityTransformer.java b/src/main/java/net/coderbot/iris/pipeline/transform/transformer/CompatibilityTransformer.java index a6f4c13a7b..bf669988b0 100644 --- a/src/main/java/net/coderbot/iris/pipeline/transform/transformer/CompatibilityTransformer.java +++ b/src/main/java/net/coderbot/iris/pipeline/transform/transformer/CompatibilityTransformer.java @@ -307,7 +307,7 @@ public boolean matchesExtract(ExternalDeclaration tree) { } } - private static final ShaderType[] pipeline = { ShaderType.VERTEX, ShaderType.GEOMETRY, ShaderType.FRAGMENT }; + private static final ShaderType[] pipeline = { ShaderType.VERTEX, ShaderType.TESSELATION_CONTROL, ShaderType.TESSELATION_EVAL, ShaderType.GEOMETRY, ShaderType.FRAGMENT }; private static final Matcher outDeclarationMatcher = new DeclarationMatcher( StorageType.OUT); private static final Matcher inDeclarationMatcher = new DeclarationMatcher( From 8cfda32749e4bf4acfa6e7ce0d3acba4b5777458 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Mon, 25 Dec 2023 05:45:20 -0800 Subject: [PATCH 41/56] Basic debug anticheat --- src/main/java/net/coderbot/iris/Iris.java | 7 ++++++- .../iris/mixin/MixinGlStateManager_DepthColorOverride.java | 4 ++-- .../sodium/mixin/shader_overrides/MixinGlProgram.java | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/coderbot/iris/Iris.java b/src/main/java/net/coderbot/iris/Iris.java index 830f4e1c1c..d3e4579a77 100644 --- a/src/main/java/net/coderbot/iris/Iris.java +++ b/src/main/java/net/coderbot/iris/Iris.java @@ -34,6 +34,7 @@ import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.TranslatableComponent; import org.jetbrains.annotations.NotNull; import org.lwjgl.glfw.GLFW; @@ -249,11 +250,15 @@ public static void handleKeybinds(Minecraft minecraft) { } } else if (shaderpackScreenKeybind.consumeClick()) { minecraft.setScreen(new ShaderPackScreen(null)); + } else if (wireframeKeybind.consumeClick()) { + if (irisConfig.areDebugOptionsEnabled() && minecraft.player != null && !Minecraft.getInstance().isLocalServer()) { + minecraft.player.displayClientMessage(new TextComponent("No cheating; wireframe only in singleplayer!"), false); + } } } public static boolean shouldActivateWireframe() { - return wireframeKeybind.isDown(); + return irisConfig.areDebugOptionsEnabled() && wireframeKeybind.isDown(); } public static void toggleShaders(Minecraft minecraft, boolean enabled) throws IOException { diff --git a/src/main/java/net/coderbot/iris/mixin/MixinGlStateManager_DepthColorOverride.java b/src/main/java/net/coderbot/iris/mixin/MixinGlStateManager_DepthColorOverride.java index 6834b94547..3eca1cf158 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinGlStateManager_DepthColorOverride.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinGlStateManager_DepthColorOverride.java @@ -28,7 +28,7 @@ public class MixinGlStateManager_DepthColorOverride { } } - @Redirect(method = "_drawElements", at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glDrawElements(IIIJ)V")) + @Redirect(method = "_drawElements", at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glDrawElements(IIIJ)V"), remap = false) private static void iris$modify(int mode, int count, int type, long indices) { if (mode == GL43C.GL_TRIANGLES && ImmediateState.usingTessellation) { mode = GL43C.GL_PATCHES; @@ -37,7 +37,7 @@ public class MixinGlStateManager_DepthColorOverride { GL43C.glDrawElements(mode, count, type, indices); } - @Inject(method = "_glUseProgram", at = @At("TAIL")) + @Inject(method = "_glUseProgram", at = @At("TAIL"), remap = false) private static void iris$resetTessellation(int pInt0, CallbackInfo ci) { ImmediateState.usingTessellation = false; } diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinGlProgram.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinGlProgram.java index f96d9a8002..9fdb33ff51 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinGlProgram.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinGlProgram.java @@ -13,7 +13,7 @@ import java.util.function.IntFunction; -@Mixin(GlProgram.class) +@Mixin(value = GlProgram.class, remap = false) public class MixinGlProgram extends GlObject implements ShaderBindingContextExt { public > U bindUniformIfPresent(String name, IntFunction factory) { int index = GlStateManager._glGetUniformLocation(this.handle(), name); From 7c90451188df79271a91ac6d1c290fbb60ebb6e7 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Mon, 25 Dec 2023 15:30:22 -0800 Subject: [PATCH 42/56] Fix build --- src/main/java/net/coderbot/iris/Iris.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/coderbot/iris/Iris.java b/src/main/java/net/coderbot/iris/Iris.java index 03edb851d0..f5d719b766 100644 --- a/src/main/java/net/coderbot/iris/Iris.java +++ b/src/main/java/net/coderbot/iris/Iris.java @@ -255,7 +255,7 @@ public static void handleKeybinds(Minecraft minecraft) { minecraft.setScreen(new ShaderPackScreen(null)); } else if (wireframeKeybind.consumeClick()) { if (irisConfig.areDebugOptionsEnabled() && minecraft.player != null && !Minecraft.getInstance().isLocalServer()) { - minecraft.player.displayClientMessage(new TextComponent("No cheating; wireframe only in singleplayer!"), false); + minecraft.player.displayClientMessage(Component.literal("No cheating; wireframe only in singleplayer!"), false); } } } From af6897c3cb5abde8fb969735e408ff6d53707825 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Mon, 25 Dec 2023 21:39:31 -0800 Subject: [PATCH 43/56] Add viewport offsets --- .../iris/gl/framebuffer/ViewportData.java | 9 +++++++++ .../iris/postprocess/CompositeRenderer.java | 11 +++++++---- .../iris/shaderpack/ProgramDirectives.java | 11 ++++++----- .../iris/shaderpack/ShaderProperties.java | 19 +++++++++++++------ .../iris/shadows/ShadowCompositeRenderer.java | 11 +++++++---- 5 files changed, 42 insertions(+), 19 deletions(-) create mode 100644 src/main/java/net/coderbot/iris/gl/framebuffer/ViewportData.java diff --git a/src/main/java/net/coderbot/iris/gl/framebuffer/ViewportData.java b/src/main/java/net/coderbot/iris/gl/framebuffer/ViewportData.java new file mode 100644 index 0000000000..0b33fdbd69 --- /dev/null +++ b/src/main/java/net/coderbot/iris/gl/framebuffer/ViewportData.java @@ -0,0 +1,9 @@ +package net.coderbot.iris.gl.framebuffer; + +public record ViewportData(float scale, float viewportX, float viewportY) { + private static ViewportData DEFAULT = new ViewportData(1.0f, 0.0f, 0.0f); + + public static ViewportData defaultValue() { + return DEFAULT; + } +} diff --git a/src/main/java/net/coderbot/iris/postprocess/CompositeRenderer.java b/src/main/java/net/coderbot/iris/postprocess/CompositeRenderer.java index 18473dc9d2..649217797e 100644 --- a/src/main/java/net/coderbot/iris/postprocess/CompositeRenderer.java +++ b/src/main/java/net/coderbot/iris/postprocess/CompositeRenderer.java @@ -18,6 +18,7 @@ import net.coderbot.iris.gl.IrisRenderSystem; import net.coderbot.iris.gl.blending.BlendModeOverride; import net.coderbot.iris.gl.framebuffer.GlFramebuffer; +import net.coderbot.iris.gl.framebuffer.ViewportData; import net.coderbot.iris.gl.image.GlImage; import net.coderbot.iris.gl.program.ComputeProgram; import net.coderbot.iris.gl.program.Program; @@ -212,7 +213,7 @@ private static class Pass { ImmutableSet flippedAtLeastOnce; ImmutableSet stageReadsFromAlt; ImmutableSet mipmappedBuffers; - float viewportScale; + ViewportData viewportScale; protected void destroy() { this.program.destroy(); @@ -270,9 +271,11 @@ public void renderAll() { } } - float scaledWidth = renderPass.viewWidth * renderPass.viewportScale; - float scaledHeight = renderPass.viewHeight * renderPass.viewportScale; - RenderSystem.viewport(0, 0, (int) scaledWidth, (int) scaledHeight); + float scaledWidth = renderPass.viewWidth * renderPass.viewportScale.scale(); + float scaledHeight = renderPass.viewHeight * renderPass.viewportScale.scale(); + int beginWidth = (int) (renderPass.viewWidth * renderPass.viewportScale.viewportX()); + int beginHeight = (int) (renderPass.viewHeight * renderPass.viewportScale.viewportY()); + RenderSystem.viewport(beginWidth, beginHeight, (int) scaledWidth, (int) scaledHeight); renderPass.framebuffer.bind(); renderPass.program.use(); diff --git a/src/main/java/net/coderbot/iris/shaderpack/ProgramDirectives.java b/src/main/java/net/coderbot/iris/shaderpack/ProgramDirectives.java index 618977d06f..6f93cea169 100644 --- a/src/main/java/net/coderbot/iris/shaderpack/ProgramDirectives.java +++ b/src/main/java/net/coderbot/iris/shaderpack/ProgramDirectives.java @@ -11,6 +11,7 @@ import net.coderbot.iris.gl.blending.BlendMode; import net.coderbot.iris.gl.blending.BlendModeOverride; import net.coderbot.iris.gl.blending.BufferBlendInformation; +import net.coderbot.iris.gl.framebuffer.ViewportData; import org.jetbrains.annotations.Nullable; import java.util.Arrays; @@ -24,7 +25,7 @@ public class ProgramDirectives { private static final ImmutableList LEGACY_RENDER_TARGETS = PackRenderTargetDirectives.LEGACY_RENDER_TARGETS; private final int[] drawBuffers; - private final float viewportScale; + private final ViewportData viewportScale; @Nullable private final AlphaTest alphaTestOverride; @@ -34,7 +35,7 @@ public class ProgramDirectives { private final ImmutableMap explicitFlips; private boolean unknownDrawBuffers; - private ProgramDirectives(int[] drawBuffers, float viewportScale, @Nullable AlphaTest alphaTestOverride, + private ProgramDirectives(int[] drawBuffers, ViewportData viewportScale, @Nullable AlphaTest alphaTestOverride, Optional blendModeOverride, List bufferBlendInformations, ImmutableSet mipmappedBuffers, ImmutableMap explicitFlips) { this.drawBuffers = drawBuffers; @@ -74,7 +75,7 @@ private ProgramDirectives(int[] drawBuffers, float viewportScale, @Nullable Alph }); if (properties != null) { - viewportScale = properties.getViewportScaleOverrides().getOrDefault(source.getName(), 1.0f); + viewportScale = properties.getViewportScaleOverrides().getOrDefault(source.getName(), ViewportData.defaultValue()); alphaTestOverride = properties.getAlphaTestOverrides().get(source.getName()); BlendModeOverride blendModeOverride = properties.getBlendModeOverrides().get(source.getName()); @@ -84,7 +85,7 @@ private ProgramDirectives(int[] drawBuffers, float viewportScale, @Nullable Alph explicitFlips = source.getParent().getPackDirectives().getExplicitFlips(source.getName()); } else { - viewportScale = 1.0f; + viewportScale = ViewportData.defaultValue(); alphaTestOverride = null; blendModeOverride = Optional.ofNullable(defaultBlendOverride); bufferBlendInformations = Collections.emptyList(); @@ -173,7 +174,7 @@ public boolean hasUnknownDrawBuffers() { return unknownDrawBuffers; } - public float getViewportScale() { + public ViewportData getViewportScale() { return viewportScale; } diff --git a/src/main/java/net/coderbot/iris/shaderpack/ShaderProperties.java b/src/main/java/net/coderbot/iris/shaderpack/ShaderProperties.java index 6276c953e3..732750bb83 100644 --- a/src/main/java/net/coderbot/iris/shaderpack/ShaderProperties.java +++ b/src/main/java/net/coderbot/iris/shaderpack/ShaderProperties.java @@ -17,6 +17,7 @@ import net.coderbot.iris.gl.blending.BlendModeFunction; import net.coderbot.iris.gl.blending.BlendModeOverride; import net.coderbot.iris.gl.buffer.ShaderStorageInfo; +import net.coderbot.iris.gl.framebuffer.ViewportData; import net.coderbot.iris.gl.texture.InternalTextureFormat; import net.coderbot.iris.gl.texture.PixelFormat; import net.coderbot.iris.gl.texture.PixelType; @@ -92,7 +93,7 @@ public class ShaderProperties { // TODO: private Map optifineVersionRequirements; // TODO: Parse custom uniforms / variables private final Object2ObjectMap alphaTestOverrides = new Object2ObjectOpenHashMap<>(); - private final Object2FloatMap viewportScaleOverrides = new Object2FloatOpenHashMap<>(); + private final Object2ObjectMap viewportScaleOverrides = new Object2ObjectOpenHashMap<>(); private final Object2ObjectMap textureScaleOverrides = new Object2ObjectOpenHashMap<>(); private final Object2ObjectMap blendModeOverrides = new Object2ObjectOpenHashMap<>(); private final Object2ObjectMap> bufferBlendOverrides = new Object2ObjectOpenHashMap<>(); @@ -212,16 +213,22 @@ public ShaderProperties(String contents, ShaderPackOptions shaderPackOptions, It // TODO: Custom uniforms handlePassDirective("scale.", key, value, pass -> { - float scale; + float scale, offsetX = 0.0f, offsetY = 0.0f; + String[] parts = value.split(" "); try { - scale = Float.parseFloat(value); - } catch (NumberFormatException e) { + scale = Float.parseFloat(parts[0]); + + if (parts.length > 1) { + offsetX = Float.parseFloat(parts[1]); + offsetY = Float.parseFloat(parts[2]); + } + } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) { Iris.logger.error("Unable to parse scale directive for " + pass + ": " + value, e); return; } - viewportScaleOverrides.put(pass, scale); + viewportScaleOverrides.put(pass, new ViewportData(scale, offsetX, offsetY)); }); handlePassDirective("size.buffer.", key, value, pass -> { @@ -793,7 +800,7 @@ public OptionalBoolean getPrepareBeforeShadow() { return prepareBeforeShadow; } - public Object2FloatMap getViewportScaleOverrides() { + public Object2ObjectMap getViewportScaleOverrides() { return viewportScaleOverrides; } diff --git a/src/main/java/net/coderbot/iris/shadows/ShadowCompositeRenderer.java b/src/main/java/net/coderbot/iris/shadows/ShadowCompositeRenderer.java index 7e4a096d95..a6efdd83bc 100644 --- a/src/main/java/net/coderbot/iris/shadows/ShadowCompositeRenderer.java +++ b/src/main/java/net/coderbot/iris/shadows/ShadowCompositeRenderer.java @@ -7,6 +7,7 @@ import com.mojang.blaze3d.systems.RenderSystem; import it.unimi.dsi.fastutil.objects.Object2ObjectMap; import net.coderbot.iris.Iris; +import net.coderbot.iris.gl.framebuffer.ViewportData; import net.coderbot.iris.gl.image.GlImage; import net.coderbot.iris.features.FeatureFlags; import net.coderbot.iris.gl.IrisRenderSystem; @@ -154,7 +155,7 @@ private static class Pass { ImmutableSet flippedAtLeastOnce; ImmutableSet stageReadsFromAlt; ImmutableSet mipmappedBuffers; - float viewportScale; + ViewportData viewportScale; ComputeProgram[] computes; protected void destroy() { @@ -213,9 +214,11 @@ public void renderAll() { } } - float scaledWidth = renderTargets.getResolution() * renderPass.viewportScale; - float scaledHeight = renderTargets.getResolution() * renderPass.viewportScale; - RenderSystem.viewport(0, 0, (int) scaledWidth, (int) scaledHeight); + float scaledWidth = renderTargets.getResolution() * renderPass.viewportScale.scale(); + float scaledHeight = renderTargets.getResolution() * renderPass.viewportScale.scale(); + int beginWidth = (int) (renderTargets.getResolution() * renderPass.viewportScale.viewportX()); + int beginHeight = (int) (renderTargets.getResolution() * renderPass.viewportScale.viewportY()); + RenderSystem.viewport(beginWidth, beginHeight, (int) scaledWidth, (int) scaledHeight); renderPass.framebuffer.bind(); renderPass.program.use(); From 6c880cd377d97ffd5de648ba4dfac7ea88897b4f Mon Sep 17 00:00:00 2001 From: IMS212 Date: Mon, 25 Dec 2023 21:51:02 -0800 Subject: [PATCH 44/56] Fix armor uniform --- .../net/coderbot/iris/uniforms/IrisExclusiveUniforms.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/coderbot/iris/uniforms/IrisExclusiveUniforms.java b/src/main/java/net/coderbot/iris/uniforms/IrisExclusiveUniforms.java index 83f6273f4d..1037ae4fb5 100644 --- a/src/main/java/net/coderbot/iris/uniforms/IrisExclusiveUniforms.java +++ b/src/main/java/net/coderbot/iris/uniforms/IrisExclusiveUniforms.java @@ -31,7 +31,7 @@ public static void addIrisExclusiveUniforms(UniformHolder uniforms) { uniforms.uniform1f(UniformUpdateFrequency.PER_FRAME, "thunderStrength", IrisExclusiveUniforms::getThunderStrength); uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "currentPlayerHealth", IrisExclusiveUniforms::getCurrentHealth); uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "maxPlayerHealth", IrisExclusiveUniforms::getMaxHealth); - uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "currentPlayerHunger", IrisExclusiveUniforms::getCurrentHunger); + uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "currentPlayerHunger", IrisExclusiveUniforms::getCurrentHunger); uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "maxPlayerHunger", () -> 20); uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "currentPlayerArmor", IrisExclusiveUniforms::getCurrentArmor); uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "maxPlayerArmor", () -> 50); @@ -98,7 +98,7 @@ private static float getCurrentArmor() { return -1; } - return (float) Minecraft.getInstance().player.getArmor() / (float) 50.0); + return (float) (Minecraft.getInstance().player.getArmorValue() / 50.0f); } private static float getMaxAir() { @@ -117,7 +117,7 @@ private static float getMaxHealth() { return Minecraft.getInstance().player.getMaxHealth(); } - + private static boolean isFirstPersonCamera() { // If camera type is not explicitly third-person, assume it's first-person. From a994da403a0c157a7027b5300cb81b0aad8587e7 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Fri, 29 Dec 2023 06:10:08 -0800 Subject: [PATCH 45/56] Fix empty terrain shader --- .../net/coderbot/iris/pipeline/SodiumTerrainPipeline.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/coderbot/iris/pipeline/SodiumTerrainPipeline.java b/src/main/java/net/coderbot/iris/pipeline/SodiumTerrainPipeline.java index b1b854e0a2..c8e445f593 100644 --- a/src/main/java/net/coderbot/iris/pipeline/SodiumTerrainPipeline.java +++ b/src/main/java/net/coderbot/iris/pipeline/SodiumTerrainPipeline.java @@ -135,7 +135,10 @@ float _material_alpha_cutoff(uint material) { void _vert_init() { _vert_position = (vec3(a_PosId.xyz) * 4.8828125E-4f + -8.0f); - _vert_tex_diffuse_coord = (a_TexCoord * 1.52587891E-5f); + + """ + + "_vert_tex_diffuse_coord = (a_TexCoord * " + (1.0f / 32768.0f) + ");" + + """ _vert_tex_light_coord = a_LightCoord; _vert_color = a_Color; _draw_id = (a_PosId.w >> 8u) & 0xffu; From a3f561b1d8951fc375d9aa5435f83ebc5c91cc58 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Fri, 26 Jan 2024 05:34:57 -0800 Subject: [PATCH 46/56] Sodium 0.5.6 support --- buildscript/src/main/java/Buildscript.java | 4 +- .../mixin/vertices/MixinBufferBuilder.java | 106 ++++++++---------- src/main/resources/fabric.mod.json | 2 +- .../IrisChunkProgramOverrides.java | 2 +- .../IrisChunkMeshAttributes.java | 4 - .../terrain_xhfp/XHFPModelVertexType.java | 24 +++- .../mixin/options/MixinSodiumGameOptions.java | 4 +- .../MixinChunkMeshAttribute.java | 22 +--- .../MixinRegionChunkRenderer.java | 9 +- 9 files changed, 84 insertions(+), 93 deletions(-) diff --git a/buildscript/src/main/java/Buildscript.java b/buildscript/src/main/java/Buildscript.java index 15ddc59234..c540e5da0b 100644 --- a/buildscript/src/main/java/Buildscript.java +++ b/buildscript/src/main/java/Buildscript.java @@ -44,9 +44,9 @@ public class Buildscript extends SimpleFabricProject { static final boolean SODIUM = true; - static final boolean CUSTOM_SODIUM = false; + static final boolean CUSTOM_SODIUM = true; static final String MC_VERSION = "1.20.4"; - static final String customSodiumName = "sodium-fabric-mc23w45a-0.5.3git.86b69d2-dirty.jar"; + static final String customSodiumName = "sodium-fabric-mc1.20.3-0.5.6git.7a62284.jar"; private static final String[] SOURCE_SETS = new String[] { "main", diff --git a/src/main/java/net/coderbot/iris/mixin/vertices/MixinBufferBuilder.java b/src/main/java/net/coderbot/iris/mixin/vertices/MixinBufferBuilder.java index 1402a9893a..5b8ae15471 100644 --- a/src/main/java/net/coderbot/iris/mixin/vertices/MixinBufferBuilder.java +++ b/src/main/java/net/coderbot/iris/mixin/vertices/MixinBufferBuilder.java @@ -7,11 +7,7 @@ import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.blaze3d.vertex.VertexFormat; import com.mojang.blaze3d.vertex.VertexFormatElement; -import net.caffeinemc.mods.sodium.api.vertex.attributes.CommonVertexAttribute; -import net.caffeinemc.mods.sodium.api.vertex.format.VertexFormatDescription; -import net.caffeinemc.mods.sodium.api.vertex.format.VertexFormatRegistry; import net.coderbot.iris.block_rendering.BlockRenderingSettings; -import net.coderbot.iris.compat.sodium.impl.vertex_format.IrisCommonVertexAttributes; import org.joml.Vector3f; import net.coderbot.iris.vertices.NormI8; import org.jetbrains.annotations.NotNull; @@ -23,7 +19,6 @@ import net.coderbot.iris.vertices.IrisVertexFormats; import net.coderbot.iris.vertices.NormalHelper; import org.jetbrains.annotations.Nullable; -import org.lwjgl.system.MemoryUtil; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; @@ -99,9 +94,15 @@ public abstract class MixinBufferBuilder extends DefaultedVertexConsumer impleme @Shadow public abstract void begin(VertexFormat.Mode drawMode, VertexFormat vertexFormat); + @Shadow + public abstract void putShort(int i, short s); + @Shadow protected abstract void switchFormat(VertexFormat arg); + @Shadow + public abstract void nextElement(); + @Override public void iris$beginWithoutExtending(VertexFormat.Mode drawMode, VertexFormat vertexFormat) { iris$shouldNotExtend = true; @@ -138,6 +139,12 @@ public abstract class MixinBufferBuilder extends DefaultedVertexConsumer impleme } } + @Override + public @NotNull VertexConsumer uv2(int pBufferVertexConsumer0, int pInt1) { + + return BufferVertexConsumer.super.uv2(pBufferVertexConsumer0, pInt1); + } + @ModifyArg(method = "begin", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/BufferBuilder;switchFormat(Lcom/mojang/blaze3d/vertex/VertexFormat;)V")) private VertexFormat iris$afterBeginSwitchFormat(VertexFormat arg) { if (extending) { @@ -164,39 +171,12 @@ public abstract class MixinBufferBuilder extends DefaultedVertexConsumer impleme vertexCount = 0; } - @Unique - private int uv1Offset, normalOffset, tangentOffset, midTexOffset, midBlockOffset, blockIdOffset, entityIdOffset; - @Inject(method = "switchFormat", at = @At("RETURN")) private void iris$preventHardcodedVertexWriting(VertexFormat format, CallbackInfo ci) { if (!extending) { return; } - VertexFormatDescription formatDescription = VertexFormatRegistry.instance() - .get(format); - - if (formatDescription.containsElement(CommonVertexAttribute.OVERLAY)) { - this.uv1Offset = formatDescription.getElementOffset(CommonVertexAttribute.OVERLAY); - } - if (formatDescription.containsElement(CommonVertexAttribute.NORMAL)) { - this.normalOffset = formatDescription.getElementOffset(CommonVertexAttribute.NORMAL); - } - if (formatDescription.containsElement(IrisCommonVertexAttributes.TANGENT)) { - this.tangentOffset = formatDescription.getElementOffset(IrisCommonVertexAttributes.TANGENT); - } - if (formatDescription.containsElement(IrisCommonVertexAttributes.MID_TEX_COORD)) { - this.midTexOffset = formatDescription.getElementOffset(IrisCommonVertexAttributes.MID_TEX_COORD); - } - if (formatDescription.containsElement(IrisCommonVertexAttributes.BLOCK_ID)) { - this.blockIdOffset = formatDescription.getElementOffset(IrisCommonVertexAttributes.BLOCK_ID); - } - if (formatDescription.containsElement(IrisCommonVertexAttributes.ENTITY_ID)) { - this.entityIdOffset = formatDescription.getElementOffset(IrisCommonVertexAttributes.ENTITY_ID); - } - if (formatDescription.containsElement(IrisCommonVertexAttributes.MID_BLOCK)) { - this.midBlockOffset = formatDescription.getElementOffset(IrisCommonVertexAttributes.MID_BLOCK); - } fastFormat = false; fullFormat = false; } @@ -207,30 +187,39 @@ public abstract class MixinBufferBuilder extends DefaultedVertexConsumer impleme return; } - if (injectNormalAndUV1) { - this.normal(0, 0, 0); + if (injectNormalAndUV1 && currentElement == DefaultVertexFormat.ELEMENT_NORMAL) { + this.putInt(0, 0); + this.nextElement(); } if (iris$isTerrain) { // ENTITY_ELEMENT - long offset = MemoryUtil.memAddress(buffer, nextElementByte + blockIdOffset); - MemoryUtil.memPutShort(offset, currentBlock); - MemoryUtil.memPutShort(offset + 2, currentRenderType); + this.putShort(0, currentBlock); + this.putShort(2, currentRenderType); } else { // ENTITY_ELEMENT - long offset = MemoryUtil.memAddress(buffer, nextElementByte + entityIdOffset); - MemoryUtil.memPutShort(offset, (short) CapturedRenderingState.INSTANCE.getCurrentRenderedEntity()); - MemoryUtil.memPutShort(offset + 2, (short) CapturedRenderingState.INSTANCE.getCurrentRenderedBlockEntity()); - MemoryUtil.memPutShort(offset + 4, (short) CapturedRenderingState.INSTANCE.getCurrentRenderedItem()); + this.putShort(0, (short) CapturedRenderingState.INSTANCE.getCurrentRenderedEntity()); + this.putShort(2, (short) CapturedRenderingState.INSTANCE.getCurrentRenderedBlockEntity()); + this.putShort(4, (short) CapturedRenderingState.INSTANCE.getCurrentRenderedItem()); } + this.nextElement(); + + // MID_TEXTURE_ELEMENT + this.putFloat(0, 0); + this.putFloat(4, 0); + this.nextElement(); + // TANGENT_ELEMENT + this.putInt(0, 0); + this.nextElement(); if (iris$isTerrain) { // MID_BLOCK_ELEMENT - long bufferIndex = MemoryUtil.memAddress(buffer, nextElementByte); - float x = MemoryUtil.memGetFloat(bufferIndex); - float y = MemoryUtil.memGetFloat(bufferIndex + 4); - float z = MemoryUtil.memGetFloat(bufferIndex + 8); - MemoryUtil.memPutInt(MemoryUtil.memAddress(buffer, nextElementByte + midBlockOffset), ExtendedDataHelper.computeMidBlock(x, y, z, currentLocalPosX, currentLocalPosY, currentLocalPosZ)); + int posIndex = this.nextElementByte - 48; + float x = buffer.getFloat(posIndex); + float y = buffer.getFloat(posIndex + 4); + float z = buffer.getFloat(posIndex + 8); + this.putInt(0, ExtendedDataHelper.computeMidBlock(x, y, z, currentLocalPosX, currentLocalPosY, currentLocalPosZ)); + this.nextElement(); } vertexCount++; @@ -246,9 +235,7 @@ private void fillExtendedData(int vertexAmount) { int stride = format.getVertexSize(); - int offset = nextElementByte + stride; - - polygon.setup(buffer, offset, stride, vertexAmount); + polygon.setup(buffer, nextElementByte, stride, vertexAmount); float midU = 0; float midV = 0; @@ -281,13 +268,13 @@ private void fillExtendedData(int vertexAmount) { // NormalHelper.computeFaceNormalTri(normal, polygon); // Removed to enable smooth shaded triangles. Mods rendering triangles with bad normals need to recalculate their normals manually or otherwise shading might be inconsistent. for (int vertex = 0; vertex < vertexAmount; vertex++) { - int packedNormal = buffer.getInt(offset - normalOffset - stride * vertex); // retrieve per-vertex normal + int packedNormal = buffer.getInt(nextElementByte - normalOffset - stride * vertex); // retrieve per-vertex normal int tangent = NormalHelper.computeTangentSmooth(NormI8.unpackX(packedNormal), NormI8.unpackY(packedNormal), NormI8.unpackZ(packedNormal), polygon); - buffer.putFloat(offset - midUOffset - stride * vertex, midU); - buffer.putFloat(offset - midVOffset - stride * vertex, midV); - buffer.putInt(offset - tangentOffset - stride * vertex, tangent); + buffer.putFloat(nextElementByte - midUOffset - stride * vertex, midU); + buffer.putFloat(nextElementByte - midVOffset - stride * vertex, midV); + buffer.putInt(nextElementByte - tangentOffset - stride * vertex, tangent); } } else { NormalHelper.computeFaceNormal(normal, polygon); @@ -295,10 +282,10 @@ private void fillExtendedData(int vertexAmount) { int tangent = NormalHelper.computeTangent(normal.x, normal.y, normal.z, polygon); for (int vertex = 0; vertex < vertexAmount; vertex++) { - buffer.putFloat(offset - midUOffset - stride * vertex, midU); - buffer.putFloat(offset - midVOffset - stride * vertex, midV); - buffer.putInt(offset - normalOffset - stride * vertex, packedNormal); - buffer.putInt(offset - tangentOffset - stride * vertex, tangent); + buffer.putFloat(nextElementByte - midUOffset - stride * vertex, midU); + buffer.putFloat(nextElementByte - midVOffset - stride * vertex, midV); + buffer.putInt(nextElementByte - normalOffset - stride * vertex, packedNormal); + buffer.putInt(nextElementByte - tangentOffset - stride * vertex, tangent); } } } @@ -320,4 +307,9 @@ public void endBlock() { this.currentLocalPosY = 0; this.currentLocalPosZ = 0; } + + @Unique + private void putInt(int i, int value) { + this.buffer.putInt(this.nextElementByte + i, value); + } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 89e0e7fcee..7d05651d15 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -46,7 +46,7 @@ "depends": { "fabricloader": ">=0.12.3", "minecraft": ["1.20.3", "1.20.4"], - "sodium": "0.5.5" + "sodium": "0.5.6" }, "breaks": { diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/shader_overrides/IrisChunkProgramOverrides.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/shader_overrides/IrisChunkProgramOverrides.java index 521440be24..af9baecec9 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/shader_overrides/IrisChunkProgramOverrides.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/shader_overrides/IrisChunkProgramOverrides.java @@ -255,7 +255,7 @@ private GlProgram createShader(IrisTerrainPass pass, S int handle = ((GlObject) shader).handle(); ShaderBindingContextExt contextExt = (ShaderBindingContextExt) shader; - return new IrisChunkShaderInterface(handle, contextExt, pipeline, new ChunkShaderOptions(ChunkFogMode.SMOOTH, pass.toTerrainPass()), + return new IrisChunkShaderInterface(handle, contextExt, pipeline, new ChunkShaderOptions(ChunkFogMode.SMOOTH, pass.toTerrainPass(), vertexType), tessCShader != null || tessEShader != null, pass == IrisTerrainPass.SHADOW || pass == IrisTerrainPass.SHADOW_CUTOUT, blendOverride, bufferOverrides, alpha, pipeline.getCustomUniforms()); }); } finally { diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/IrisChunkMeshAttributes.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/IrisChunkMeshAttributes.java index 7acc12ee5d..e51bcbde08 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/IrisChunkMeshAttributes.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/IrisChunkMeshAttributes.java @@ -6,10 +6,6 @@ * Initialized by {@link net.coderbot.iris.compat.sodium.mixin.vertex_format.MixinChunkMeshAttribute} */ public class IrisChunkMeshAttributes { - public static ChunkMeshAttribute POSITION_MATERIAL_MESH; - public static ChunkMeshAttribute COLOR_SHADE; - public static ChunkMeshAttribute BLOCK_TEXTURE; - public static ChunkMeshAttribute LIGHT_TEXTURE; public static ChunkMeshAttribute NORMAL; public static ChunkMeshAttribute TANGENT; public static ChunkMeshAttribute MID_TEX_COORD; diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPModelVertexType.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPModelVertexType.java index 5588199216..c4c282362b 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPModelVertexType.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPModelVertexType.java @@ -14,16 +14,15 @@ public class XHFPModelVertexType implements ChunkVertexType { public static final int STRIDE = 40; public static final GlVertexFormat VERTEX_FORMAT = GlVertexFormat.builder(ChunkMeshAttribute.class, STRIDE) - .addElement(IrisChunkMeshAttributes.POSITION_MATERIAL_MESH, 0, GlVertexAttributeFormat.UNSIGNED_SHORT, 4, false, true) - .addElement(IrisChunkMeshAttributes.COLOR_SHADE, 8, GlVertexAttributeFormat.UNSIGNED_BYTE, 4, true, false) - .addElement(IrisChunkMeshAttributes.BLOCK_TEXTURE, 12, GlVertexAttributeFormat.UNSIGNED_SHORT, 2, false, false) - .addElement(IrisChunkMeshAttributes.LIGHT_TEXTURE, 16, GlVertexAttributeFormat.UNSIGNED_SHORT, 2, false, true) + .addElement(ChunkMeshAttribute.POSITION_MATERIAL_MESH, 0, GlVertexAttributeFormat.UNSIGNED_SHORT, 4, false, true) + .addElement(ChunkMeshAttribute.COLOR_SHADE, 8, GlVertexAttributeFormat.UNSIGNED_BYTE, 4, true, false) + .addElement(ChunkMeshAttribute.BLOCK_TEXTURE, 12, GlVertexAttributeFormat.UNSIGNED_SHORT, 2, false, false) + .addElement(ChunkMeshAttribute.LIGHT_TEXTURE, 16, GlVertexAttributeFormat.UNSIGNED_SHORT, 2, false, true) .addElement(IrisChunkMeshAttributes.MID_TEX_COORD, 20, GlVertexAttributeFormat.UNSIGNED_SHORT, 2, false, false) .addElement(IrisChunkMeshAttributes.TANGENT, 24, IrisGlVertexAttributeFormat.BYTE, 4, true, false) .addElement(IrisChunkMeshAttributes.NORMAL, 28, IrisGlVertexAttributeFormat.BYTE, 3, true, false) .addElement(IrisChunkMeshAttributes.BLOCK_ID, 32, IrisGlVertexAttributeFormat.SHORT, 2, false, false) .addElement(IrisChunkMeshAttributes.MID_BLOCK, 36, IrisGlVertexAttributeFormat.BYTE, 3, false, false) - .addElement(ChunkMeshAttribute.VERTEX_DATA, 40, IrisGlVertexAttributeFormat.BYTE, 0, false, false) .build(); private static final int POSITION_MAX_VALUE = 65536; @@ -37,6 +36,21 @@ public class XHFPModelVertexType implements ChunkVertexType { private static final float TEXTURE_SCALE = (1.0f / TEXTURE_MAX_VALUE); + @Override + public float getTextureScale() { + return TEXTURE_SCALE; + } + + @Override + public float getPositionScale() { + return MODEL_SCALE; + } + + @Override + public float getPositionOffset() { + return -MODEL_ORIGIN; + } + @Override public GlVertexFormat getVertexFormat() { return VERTEX_FORMAT; diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/options/MixinSodiumGameOptions.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/options/MixinSodiumGameOptions.java index 75310208d8..8c41771e50 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/options/MixinSodiumGameOptions.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/options/MixinSodiumGameOptions.java @@ -15,8 +15,8 @@ */ @Mixin(SodiumGameOptions.class) public class MixinSodiumGameOptions { - @Inject(method = "writeChanges()V", at = @At("RETURN"), remap = false) - public void iris$writeIrisConfig(CallbackInfo ci) { + @Inject(method = "writeToDisk", at = @At("RETURN"), remap = false) + private static void iris$writeIrisConfig(CallbackInfo ci) { try { if (Iris.getIrisConfig() != null) { Iris.getIrisConfig().save(); diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/MixinChunkMeshAttribute.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/MixinChunkMeshAttribute.java index 1131b34869..1d40f2374a 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/MixinChunkMeshAttribute.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/MixinChunkMeshAttribute.java @@ -25,30 +25,18 @@ public class MixinChunkMeshAttribute { static { int baseOrdinal = $VALUES.length; - IrisChunkMeshAttributes.POSITION_MATERIAL_MESH - = ChunkMeshAttributeAccessor.createChunkMeshAttribute("POSITION_MATERIAL_MESH", baseOrdinal); - IrisChunkMeshAttributes.COLOR_SHADE - = ChunkMeshAttributeAccessor.createChunkMeshAttribute("COLOR_SHADE", baseOrdinal + 1); - IrisChunkMeshAttributes.BLOCK_TEXTURE - = ChunkMeshAttributeAccessor.createChunkMeshAttribute("BLOCK_TEXTURE", baseOrdinal + 2); - IrisChunkMeshAttributes.LIGHT_TEXTURE - = ChunkMeshAttributeAccessor.createChunkMeshAttribute("LIGHT_TEXTURE", baseOrdinal + 3); IrisChunkMeshAttributes.NORMAL - = ChunkMeshAttributeAccessor.createChunkMeshAttribute("NORMAL", baseOrdinal + 4); + = ChunkMeshAttributeAccessor.createChunkMeshAttribute("NORMAL", baseOrdinal); IrisChunkMeshAttributes.TANGENT - = ChunkMeshAttributeAccessor.createChunkMeshAttribute("TANGENT", baseOrdinal + 5); + = ChunkMeshAttributeAccessor.createChunkMeshAttribute("TANGENT", baseOrdinal + 1); IrisChunkMeshAttributes.MID_TEX_COORD - = ChunkMeshAttributeAccessor.createChunkMeshAttribute("MID_TEX_COORD", baseOrdinal + 6); + = ChunkMeshAttributeAccessor.createChunkMeshAttribute("MID_TEX_COORD", baseOrdinal + 2); IrisChunkMeshAttributes.BLOCK_ID - = ChunkMeshAttributeAccessor.createChunkMeshAttribute("BLOCK_ID", baseOrdinal + 7); + = ChunkMeshAttributeAccessor.createChunkMeshAttribute("BLOCK_ID", baseOrdinal + 3); IrisChunkMeshAttributes.MID_BLOCK - = ChunkMeshAttributeAccessor.createChunkMeshAttribute("MID_BLOCK", baseOrdinal + 8); + = ChunkMeshAttributeAccessor.createChunkMeshAttribute("MID_BLOCK", baseOrdinal + 4); $VALUES = ArrayUtils.addAll($VALUES, - IrisChunkMeshAttributes.POSITION_MATERIAL_MESH, - IrisChunkMeshAttributes.COLOR_SHADE, - IrisChunkMeshAttributes.BLOCK_TEXTURE, - IrisChunkMeshAttributes.LIGHT_TEXTURE, IrisChunkMeshAttributes.NORMAL, IrisChunkMeshAttributes.TANGENT, IrisChunkMeshAttributes.MID_TEX_COORD, diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/MixinRegionChunkRenderer.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/MixinRegionChunkRenderer.java index 3ab5cf1e6a..d20099ebe6 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/MixinRegionChunkRenderer.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/MixinRegionChunkRenderer.java @@ -7,6 +7,7 @@ import me.jellysquid.mods.sodium.client.gl.tessellation.TessellationBinding; import me.jellysquid.mods.sodium.client.render.chunk.DefaultChunkRenderer; import me.jellysquid.mods.sodium.client.render.chunk.ShaderChunkRenderer; +import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ChunkMeshAttribute; import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ChunkVertexType; import net.coderbot.iris.block_rendering.BlockRenderingSettings; import net.coderbot.iris.compat.sodium.impl.IrisChunkShaderBindingPoints; @@ -36,13 +37,13 @@ public MixinRegionChunkRenderer(RenderDevice device, ChunkVertexType vertexType) attributes = new GlVertexAttributeBinding[]{ new GlVertexAttributeBinding(IrisChunkShaderBindingPoints.ATTRIBUTE_POSITION_ID, - vertexFormat.getAttribute(IrisChunkMeshAttributes.POSITION_MATERIAL_MESH)), + vertexFormat.getAttribute(ChunkMeshAttribute.POSITION_MATERIAL_MESH)), new GlVertexAttributeBinding(IrisChunkShaderBindingPoints.ATTRIBUTE_COLOR, - vertexFormat.getAttribute(IrisChunkMeshAttributes.COLOR_SHADE)), + vertexFormat.getAttribute(ChunkMeshAttribute.COLOR_SHADE)), new GlVertexAttributeBinding(IrisChunkShaderBindingPoints.ATTRIBUTE_BLOCK_TEXTURE, - vertexFormat.getAttribute(IrisChunkMeshAttributes.BLOCK_TEXTURE)), + vertexFormat.getAttribute(ChunkMeshAttribute.BLOCK_TEXTURE)), new GlVertexAttributeBinding(IrisChunkShaderBindingPoints.ATTRIBUTE_LIGHT_TEXTURE, - vertexFormat.getAttribute(IrisChunkMeshAttributes.LIGHT_TEXTURE)), + vertexFormat.getAttribute(ChunkMeshAttribute.LIGHT_TEXTURE)), new GlVertexAttributeBinding(IrisChunkShaderBindingPoints.MID_BLOCK, vertexFormat.getAttribute(IrisChunkMeshAttributes.MID_BLOCK)), new GlVertexAttributeBinding(IrisChunkShaderBindingPoints.BLOCK_ID, From 87dad022e85ded1a90832623b1e6010f6a8f1215 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Fri, 26 Jan 2024 05:34:57 -0800 Subject: [PATCH 47/56] Sodium 0.5.6 support --- buildscript/src/main/java/Buildscript.java | 4 +- .../mixin/vertices/MixinBufferBuilder.java | 106 ++++++++---------- src/main/resources/fabric.mod.json | 2 +- .../IrisChunkMeshAttributes.java | 4 - .../terrain_xhfp/XHFPModelVertexType.java | 24 +++- .../mixin/options/MixinSodiumGameOptions.java | 4 +- .../MixinChunkMeshAttribute.java | 22 +--- .../MixinRegionChunkRenderer.java | 9 +- 8 files changed, 83 insertions(+), 92 deletions(-) diff --git a/buildscript/src/main/java/Buildscript.java b/buildscript/src/main/java/Buildscript.java index f4c3c1aa91..fb94245c95 100644 --- a/buildscript/src/main/java/Buildscript.java +++ b/buildscript/src/main/java/Buildscript.java @@ -44,9 +44,9 @@ public class Buildscript extends SimpleFabricProject { static final boolean SODIUM = true; - static final boolean CUSTOM_SODIUM = false; + static final boolean CUSTOM_SODIUM = true; static final String MC_VERSION = "1.20.4"; - static final String customSodiumName = "sodium-fabric-mc23w45a-0.5.3git.86b69d2-dirty.jar"; + static final String customSodiumName = "sodium-fabric-mc1.20.3-0.5.6git.7a62284.jar"; private static final String[] SOURCE_SETS = new String[] { "main", diff --git a/src/main/java/net/coderbot/iris/mixin/vertices/MixinBufferBuilder.java b/src/main/java/net/coderbot/iris/mixin/vertices/MixinBufferBuilder.java index 1402a9893a..5b8ae15471 100644 --- a/src/main/java/net/coderbot/iris/mixin/vertices/MixinBufferBuilder.java +++ b/src/main/java/net/coderbot/iris/mixin/vertices/MixinBufferBuilder.java @@ -7,11 +7,7 @@ import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.blaze3d.vertex.VertexFormat; import com.mojang.blaze3d.vertex.VertexFormatElement; -import net.caffeinemc.mods.sodium.api.vertex.attributes.CommonVertexAttribute; -import net.caffeinemc.mods.sodium.api.vertex.format.VertexFormatDescription; -import net.caffeinemc.mods.sodium.api.vertex.format.VertexFormatRegistry; import net.coderbot.iris.block_rendering.BlockRenderingSettings; -import net.coderbot.iris.compat.sodium.impl.vertex_format.IrisCommonVertexAttributes; import org.joml.Vector3f; import net.coderbot.iris.vertices.NormI8; import org.jetbrains.annotations.NotNull; @@ -23,7 +19,6 @@ import net.coderbot.iris.vertices.IrisVertexFormats; import net.coderbot.iris.vertices.NormalHelper; import org.jetbrains.annotations.Nullable; -import org.lwjgl.system.MemoryUtil; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; @@ -99,9 +94,15 @@ public abstract class MixinBufferBuilder extends DefaultedVertexConsumer impleme @Shadow public abstract void begin(VertexFormat.Mode drawMode, VertexFormat vertexFormat); + @Shadow + public abstract void putShort(int i, short s); + @Shadow protected abstract void switchFormat(VertexFormat arg); + @Shadow + public abstract void nextElement(); + @Override public void iris$beginWithoutExtending(VertexFormat.Mode drawMode, VertexFormat vertexFormat) { iris$shouldNotExtend = true; @@ -138,6 +139,12 @@ public abstract class MixinBufferBuilder extends DefaultedVertexConsumer impleme } } + @Override + public @NotNull VertexConsumer uv2(int pBufferVertexConsumer0, int pInt1) { + + return BufferVertexConsumer.super.uv2(pBufferVertexConsumer0, pInt1); + } + @ModifyArg(method = "begin", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/BufferBuilder;switchFormat(Lcom/mojang/blaze3d/vertex/VertexFormat;)V")) private VertexFormat iris$afterBeginSwitchFormat(VertexFormat arg) { if (extending) { @@ -164,39 +171,12 @@ public abstract class MixinBufferBuilder extends DefaultedVertexConsumer impleme vertexCount = 0; } - @Unique - private int uv1Offset, normalOffset, tangentOffset, midTexOffset, midBlockOffset, blockIdOffset, entityIdOffset; - @Inject(method = "switchFormat", at = @At("RETURN")) private void iris$preventHardcodedVertexWriting(VertexFormat format, CallbackInfo ci) { if (!extending) { return; } - VertexFormatDescription formatDescription = VertexFormatRegistry.instance() - .get(format); - - if (formatDescription.containsElement(CommonVertexAttribute.OVERLAY)) { - this.uv1Offset = formatDescription.getElementOffset(CommonVertexAttribute.OVERLAY); - } - if (formatDescription.containsElement(CommonVertexAttribute.NORMAL)) { - this.normalOffset = formatDescription.getElementOffset(CommonVertexAttribute.NORMAL); - } - if (formatDescription.containsElement(IrisCommonVertexAttributes.TANGENT)) { - this.tangentOffset = formatDescription.getElementOffset(IrisCommonVertexAttributes.TANGENT); - } - if (formatDescription.containsElement(IrisCommonVertexAttributes.MID_TEX_COORD)) { - this.midTexOffset = formatDescription.getElementOffset(IrisCommonVertexAttributes.MID_TEX_COORD); - } - if (formatDescription.containsElement(IrisCommonVertexAttributes.BLOCK_ID)) { - this.blockIdOffset = formatDescription.getElementOffset(IrisCommonVertexAttributes.BLOCK_ID); - } - if (formatDescription.containsElement(IrisCommonVertexAttributes.ENTITY_ID)) { - this.entityIdOffset = formatDescription.getElementOffset(IrisCommonVertexAttributes.ENTITY_ID); - } - if (formatDescription.containsElement(IrisCommonVertexAttributes.MID_BLOCK)) { - this.midBlockOffset = formatDescription.getElementOffset(IrisCommonVertexAttributes.MID_BLOCK); - } fastFormat = false; fullFormat = false; } @@ -207,30 +187,39 @@ public abstract class MixinBufferBuilder extends DefaultedVertexConsumer impleme return; } - if (injectNormalAndUV1) { - this.normal(0, 0, 0); + if (injectNormalAndUV1 && currentElement == DefaultVertexFormat.ELEMENT_NORMAL) { + this.putInt(0, 0); + this.nextElement(); } if (iris$isTerrain) { // ENTITY_ELEMENT - long offset = MemoryUtil.memAddress(buffer, nextElementByte + blockIdOffset); - MemoryUtil.memPutShort(offset, currentBlock); - MemoryUtil.memPutShort(offset + 2, currentRenderType); + this.putShort(0, currentBlock); + this.putShort(2, currentRenderType); } else { // ENTITY_ELEMENT - long offset = MemoryUtil.memAddress(buffer, nextElementByte + entityIdOffset); - MemoryUtil.memPutShort(offset, (short) CapturedRenderingState.INSTANCE.getCurrentRenderedEntity()); - MemoryUtil.memPutShort(offset + 2, (short) CapturedRenderingState.INSTANCE.getCurrentRenderedBlockEntity()); - MemoryUtil.memPutShort(offset + 4, (short) CapturedRenderingState.INSTANCE.getCurrentRenderedItem()); + this.putShort(0, (short) CapturedRenderingState.INSTANCE.getCurrentRenderedEntity()); + this.putShort(2, (short) CapturedRenderingState.INSTANCE.getCurrentRenderedBlockEntity()); + this.putShort(4, (short) CapturedRenderingState.INSTANCE.getCurrentRenderedItem()); } + this.nextElement(); + + // MID_TEXTURE_ELEMENT + this.putFloat(0, 0); + this.putFloat(4, 0); + this.nextElement(); + // TANGENT_ELEMENT + this.putInt(0, 0); + this.nextElement(); if (iris$isTerrain) { // MID_BLOCK_ELEMENT - long bufferIndex = MemoryUtil.memAddress(buffer, nextElementByte); - float x = MemoryUtil.memGetFloat(bufferIndex); - float y = MemoryUtil.memGetFloat(bufferIndex + 4); - float z = MemoryUtil.memGetFloat(bufferIndex + 8); - MemoryUtil.memPutInt(MemoryUtil.memAddress(buffer, nextElementByte + midBlockOffset), ExtendedDataHelper.computeMidBlock(x, y, z, currentLocalPosX, currentLocalPosY, currentLocalPosZ)); + int posIndex = this.nextElementByte - 48; + float x = buffer.getFloat(posIndex); + float y = buffer.getFloat(posIndex + 4); + float z = buffer.getFloat(posIndex + 8); + this.putInt(0, ExtendedDataHelper.computeMidBlock(x, y, z, currentLocalPosX, currentLocalPosY, currentLocalPosZ)); + this.nextElement(); } vertexCount++; @@ -246,9 +235,7 @@ private void fillExtendedData(int vertexAmount) { int stride = format.getVertexSize(); - int offset = nextElementByte + stride; - - polygon.setup(buffer, offset, stride, vertexAmount); + polygon.setup(buffer, nextElementByte, stride, vertexAmount); float midU = 0; float midV = 0; @@ -281,13 +268,13 @@ private void fillExtendedData(int vertexAmount) { // NormalHelper.computeFaceNormalTri(normal, polygon); // Removed to enable smooth shaded triangles. Mods rendering triangles with bad normals need to recalculate their normals manually or otherwise shading might be inconsistent. for (int vertex = 0; vertex < vertexAmount; vertex++) { - int packedNormal = buffer.getInt(offset - normalOffset - stride * vertex); // retrieve per-vertex normal + int packedNormal = buffer.getInt(nextElementByte - normalOffset - stride * vertex); // retrieve per-vertex normal int tangent = NormalHelper.computeTangentSmooth(NormI8.unpackX(packedNormal), NormI8.unpackY(packedNormal), NormI8.unpackZ(packedNormal), polygon); - buffer.putFloat(offset - midUOffset - stride * vertex, midU); - buffer.putFloat(offset - midVOffset - stride * vertex, midV); - buffer.putInt(offset - tangentOffset - stride * vertex, tangent); + buffer.putFloat(nextElementByte - midUOffset - stride * vertex, midU); + buffer.putFloat(nextElementByte - midVOffset - stride * vertex, midV); + buffer.putInt(nextElementByte - tangentOffset - stride * vertex, tangent); } } else { NormalHelper.computeFaceNormal(normal, polygon); @@ -295,10 +282,10 @@ private void fillExtendedData(int vertexAmount) { int tangent = NormalHelper.computeTangent(normal.x, normal.y, normal.z, polygon); for (int vertex = 0; vertex < vertexAmount; vertex++) { - buffer.putFloat(offset - midUOffset - stride * vertex, midU); - buffer.putFloat(offset - midVOffset - stride * vertex, midV); - buffer.putInt(offset - normalOffset - stride * vertex, packedNormal); - buffer.putInt(offset - tangentOffset - stride * vertex, tangent); + buffer.putFloat(nextElementByte - midUOffset - stride * vertex, midU); + buffer.putFloat(nextElementByte - midVOffset - stride * vertex, midV); + buffer.putInt(nextElementByte - normalOffset - stride * vertex, packedNormal); + buffer.putInt(nextElementByte - tangentOffset - stride * vertex, tangent); } } } @@ -320,4 +307,9 @@ public void endBlock() { this.currentLocalPosY = 0; this.currentLocalPosZ = 0; } + + @Unique + private void putInt(int i, int value) { + this.buffer.putInt(this.nextElementByte + i, value); + } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 4ffb60417f..46ddfee56e 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -46,7 +46,7 @@ "depends": { "fabricloader": ">=0.12.3", "minecraft": ["1.20.3", "1.20.4"], - "sodium": "0.5.4" + "sodium": "0.5.6" }, "breaks": { diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/IrisChunkMeshAttributes.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/IrisChunkMeshAttributes.java index 7acc12ee5d..e51bcbde08 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/IrisChunkMeshAttributes.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/IrisChunkMeshAttributes.java @@ -6,10 +6,6 @@ * Initialized by {@link net.coderbot.iris.compat.sodium.mixin.vertex_format.MixinChunkMeshAttribute} */ public class IrisChunkMeshAttributes { - public static ChunkMeshAttribute POSITION_MATERIAL_MESH; - public static ChunkMeshAttribute COLOR_SHADE; - public static ChunkMeshAttribute BLOCK_TEXTURE; - public static ChunkMeshAttribute LIGHT_TEXTURE; public static ChunkMeshAttribute NORMAL; public static ChunkMeshAttribute TANGENT; public static ChunkMeshAttribute MID_TEX_COORD; diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPModelVertexType.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPModelVertexType.java index 827aab09fa..3c3e70b529 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPModelVertexType.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPModelVertexType.java @@ -14,16 +14,15 @@ public class XHFPModelVertexType implements ChunkVertexType { public static final int STRIDE = 40; public static final GlVertexFormat VERTEX_FORMAT = GlVertexFormat.builder(ChunkMeshAttribute.class, STRIDE) - .addElement(IrisChunkMeshAttributes.POSITION_MATERIAL_MESH, 0, GlVertexAttributeFormat.UNSIGNED_SHORT, 4, false, true) - .addElement(IrisChunkMeshAttributes.COLOR_SHADE, 8, GlVertexAttributeFormat.UNSIGNED_BYTE, 4, true, false) - .addElement(IrisChunkMeshAttributes.BLOCK_TEXTURE, 12, GlVertexAttributeFormat.UNSIGNED_SHORT, 2, false, false) - .addElement(IrisChunkMeshAttributes.LIGHT_TEXTURE, 16, GlVertexAttributeFormat.UNSIGNED_SHORT, 2, false, true) + .addElement(ChunkMeshAttribute.POSITION_MATERIAL_MESH, 0, GlVertexAttributeFormat.UNSIGNED_SHORT, 4, false, true) + .addElement(ChunkMeshAttribute.COLOR_SHADE, 8, GlVertexAttributeFormat.UNSIGNED_BYTE, 4, true, false) + .addElement(ChunkMeshAttribute.BLOCK_TEXTURE, 12, GlVertexAttributeFormat.UNSIGNED_SHORT, 2, false, false) + .addElement(ChunkMeshAttribute.LIGHT_TEXTURE, 16, GlVertexAttributeFormat.UNSIGNED_SHORT, 2, false, true) .addElement(IrisChunkMeshAttributes.MID_TEX_COORD, 20, GlVertexAttributeFormat.UNSIGNED_SHORT, 2, false, false) .addElement(IrisChunkMeshAttributes.TANGENT, 24, IrisGlVertexAttributeFormat.BYTE, 4, true, false) .addElement(IrisChunkMeshAttributes.NORMAL, 28, IrisGlVertexAttributeFormat.BYTE, 3, true, false) .addElement(IrisChunkMeshAttributes.BLOCK_ID, 32, IrisGlVertexAttributeFormat.SHORT, 2, false, false) .addElement(IrisChunkMeshAttributes.MID_BLOCK, 36, IrisGlVertexAttributeFormat.BYTE, 3, false, false) - .addElement(ChunkMeshAttribute.VERTEX_DATA, 40, IrisGlVertexAttributeFormat.BYTE, 0, false, false) .build(); private static final int POSITION_MAX_VALUE = 65536; @@ -37,6 +36,21 @@ public class XHFPModelVertexType implements ChunkVertexType { private static final float TEXTURE_SCALE = (1.0f / TEXTURE_MAX_VALUE); + @Override + public float getTextureScale() { + return TEXTURE_SCALE; + } + + @Override + public float getPositionScale() { + return MODEL_SCALE; + } + + @Override + public float getPositionOffset() { + return -MODEL_ORIGIN; + } + @Override public GlVertexFormat getVertexFormat() { return VERTEX_FORMAT; diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/options/MixinSodiumGameOptions.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/options/MixinSodiumGameOptions.java index 75310208d8..8c41771e50 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/options/MixinSodiumGameOptions.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/options/MixinSodiumGameOptions.java @@ -15,8 +15,8 @@ */ @Mixin(SodiumGameOptions.class) public class MixinSodiumGameOptions { - @Inject(method = "writeChanges()V", at = @At("RETURN"), remap = false) - public void iris$writeIrisConfig(CallbackInfo ci) { + @Inject(method = "writeToDisk", at = @At("RETURN"), remap = false) + private static void iris$writeIrisConfig(CallbackInfo ci) { try { if (Iris.getIrisConfig() != null) { Iris.getIrisConfig().save(); diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/MixinChunkMeshAttribute.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/MixinChunkMeshAttribute.java index 1131b34869..1d40f2374a 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/MixinChunkMeshAttribute.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/MixinChunkMeshAttribute.java @@ -25,30 +25,18 @@ public class MixinChunkMeshAttribute { static { int baseOrdinal = $VALUES.length; - IrisChunkMeshAttributes.POSITION_MATERIAL_MESH - = ChunkMeshAttributeAccessor.createChunkMeshAttribute("POSITION_MATERIAL_MESH", baseOrdinal); - IrisChunkMeshAttributes.COLOR_SHADE - = ChunkMeshAttributeAccessor.createChunkMeshAttribute("COLOR_SHADE", baseOrdinal + 1); - IrisChunkMeshAttributes.BLOCK_TEXTURE - = ChunkMeshAttributeAccessor.createChunkMeshAttribute("BLOCK_TEXTURE", baseOrdinal + 2); - IrisChunkMeshAttributes.LIGHT_TEXTURE - = ChunkMeshAttributeAccessor.createChunkMeshAttribute("LIGHT_TEXTURE", baseOrdinal + 3); IrisChunkMeshAttributes.NORMAL - = ChunkMeshAttributeAccessor.createChunkMeshAttribute("NORMAL", baseOrdinal + 4); + = ChunkMeshAttributeAccessor.createChunkMeshAttribute("NORMAL", baseOrdinal); IrisChunkMeshAttributes.TANGENT - = ChunkMeshAttributeAccessor.createChunkMeshAttribute("TANGENT", baseOrdinal + 5); + = ChunkMeshAttributeAccessor.createChunkMeshAttribute("TANGENT", baseOrdinal + 1); IrisChunkMeshAttributes.MID_TEX_COORD - = ChunkMeshAttributeAccessor.createChunkMeshAttribute("MID_TEX_COORD", baseOrdinal + 6); + = ChunkMeshAttributeAccessor.createChunkMeshAttribute("MID_TEX_COORD", baseOrdinal + 2); IrisChunkMeshAttributes.BLOCK_ID - = ChunkMeshAttributeAccessor.createChunkMeshAttribute("BLOCK_ID", baseOrdinal + 7); + = ChunkMeshAttributeAccessor.createChunkMeshAttribute("BLOCK_ID", baseOrdinal + 3); IrisChunkMeshAttributes.MID_BLOCK - = ChunkMeshAttributeAccessor.createChunkMeshAttribute("MID_BLOCK", baseOrdinal + 8); + = ChunkMeshAttributeAccessor.createChunkMeshAttribute("MID_BLOCK", baseOrdinal + 4); $VALUES = ArrayUtils.addAll($VALUES, - IrisChunkMeshAttributes.POSITION_MATERIAL_MESH, - IrisChunkMeshAttributes.COLOR_SHADE, - IrisChunkMeshAttributes.BLOCK_TEXTURE, - IrisChunkMeshAttributes.LIGHT_TEXTURE, IrisChunkMeshAttributes.NORMAL, IrisChunkMeshAttributes.TANGENT, IrisChunkMeshAttributes.MID_TEX_COORD, diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/MixinRegionChunkRenderer.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/MixinRegionChunkRenderer.java index 3ab5cf1e6a..d20099ebe6 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/MixinRegionChunkRenderer.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/MixinRegionChunkRenderer.java @@ -7,6 +7,7 @@ import me.jellysquid.mods.sodium.client.gl.tessellation.TessellationBinding; import me.jellysquid.mods.sodium.client.render.chunk.DefaultChunkRenderer; import me.jellysquid.mods.sodium.client.render.chunk.ShaderChunkRenderer; +import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ChunkMeshAttribute; import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ChunkVertexType; import net.coderbot.iris.block_rendering.BlockRenderingSettings; import net.coderbot.iris.compat.sodium.impl.IrisChunkShaderBindingPoints; @@ -36,13 +37,13 @@ public MixinRegionChunkRenderer(RenderDevice device, ChunkVertexType vertexType) attributes = new GlVertexAttributeBinding[]{ new GlVertexAttributeBinding(IrisChunkShaderBindingPoints.ATTRIBUTE_POSITION_ID, - vertexFormat.getAttribute(IrisChunkMeshAttributes.POSITION_MATERIAL_MESH)), + vertexFormat.getAttribute(ChunkMeshAttribute.POSITION_MATERIAL_MESH)), new GlVertexAttributeBinding(IrisChunkShaderBindingPoints.ATTRIBUTE_COLOR, - vertexFormat.getAttribute(IrisChunkMeshAttributes.COLOR_SHADE)), + vertexFormat.getAttribute(ChunkMeshAttribute.COLOR_SHADE)), new GlVertexAttributeBinding(IrisChunkShaderBindingPoints.ATTRIBUTE_BLOCK_TEXTURE, - vertexFormat.getAttribute(IrisChunkMeshAttributes.BLOCK_TEXTURE)), + vertexFormat.getAttribute(ChunkMeshAttribute.BLOCK_TEXTURE)), new GlVertexAttributeBinding(IrisChunkShaderBindingPoints.ATTRIBUTE_LIGHT_TEXTURE, - vertexFormat.getAttribute(IrisChunkMeshAttributes.LIGHT_TEXTURE)), + vertexFormat.getAttribute(ChunkMeshAttribute.LIGHT_TEXTURE)), new GlVertexAttributeBinding(IrisChunkShaderBindingPoints.MID_BLOCK, vertexFormat.getAttribute(IrisChunkMeshAttributes.MID_BLOCK)), new GlVertexAttributeBinding(IrisChunkShaderBindingPoints.BLOCK_ID, From ca63688e89e171418b453918c258f218eb44beb6 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Sat, 27 Jan 2024 14:12:22 -0800 Subject: [PATCH 48/56] Yay --- buildscript/src/main/java/Buildscript.java | 6 +++--- src/main/resources/fabric.mod.json | 2 +- .../impl/shader_overrides/IrisChunkProgramOverrides.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/buildscript/src/main/java/Buildscript.java b/buildscript/src/main/java/Buildscript.java index fb94245c95..7b65d16927 100644 --- a/buildscript/src/main/java/Buildscript.java +++ b/buildscript/src/main/java/Buildscript.java @@ -44,7 +44,7 @@ public class Buildscript extends SimpleFabricProject { static final boolean SODIUM = true; - static final boolean CUSTOM_SODIUM = true; + static final boolean CUSTOM_SODIUM = false; static final String MC_VERSION = "1.20.4"; static final String customSodiumName = "sodium-fabric-mc1.20.3-0.5.6git.7a62284.jar"; @@ -114,10 +114,10 @@ public void getModDependencies(ModDependencyCollector d) { if (CUSTOM_SODIUM) { d.add(new JavaJarDependency(getProjectDir().resolve("custom_sodium").resolve(customSodiumName).toAbsolutePath(), null, new MavenId("me.jellysquid.mods", "sodium-fabric", customSodiumName.replace("sodium-fabric-", ""))), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); } else { - d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "sodium", "mc1.20.3-0.5.4"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); + d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "sodium", "mc1.20.3-0.5.6"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); } } else { - d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "sodium", "mc1.20.3-0.5.4"), ModDependencyFlag.COMPILE); + d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "sodium", "mc1.20.3-0.5.6"), ModDependencyFlag.COMPILE); } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 46ddfee56e..1cdb2af8ed 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,7 +1,7 @@ { "schemaVersion": 1, "id": "iris", - "version": "1.6.13-development-environment", + "version": "1.6.15-development-environment", "name": "Iris", "description": "A modern shaders mod for Minecraft intended to be compatible with existing OptiFine shader packs", diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/shader_overrides/IrisChunkProgramOverrides.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/shader_overrides/IrisChunkProgramOverrides.java index 56bcd1cd3e..c5b3db58a1 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/shader_overrides/IrisChunkProgramOverrides.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/shader_overrides/IrisChunkProgramOverrides.java @@ -189,7 +189,7 @@ private GlProgram createShader(IrisTerrainPass pass, S int handle = ((GlObject) shader).handle(); ShaderBindingContextExt contextExt = (ShaderBindingContextExt) shader; - return new IrisChunkShaderInterface(handle, contextExt, pipeline, new ChunkShaderOptions(ChunkFogMode.SMOOTH, pass.toTerrainPass()), + return new IrisChunkShaderInterface(handle, contextExt, pipeline, new ChunkShaderOptions(ChunkFogMode.SMOOTH, pass.toTerrainPass(), vertexType), pass == IrisTerrainPass.SHADOW || pass == IrisTerrainPass.SHADOW_CUTOUT, blendOverride, bufferOverrides, alpha, pipeline.getCustomUniforms()); }); } finally { From 5e14adb02345e6d27a1f8a127c76f43a93cb7cf0 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Sat, 27 Jan 2024 14:00:05 -0800 Subject: [PATCH 49/56] Part 1 --- buildscript/src/main/java/Buildscript.java | 6 ++-- .../mixin/MixinRenderBuffers.java | 4 +-- .../SectionBufferBuilderPackAccessor.java | 4 +-- .../iris/mixin/MixinLevelRenderer.java | 7 ++--- .../entity_render_context/MixinCapeLayer.java | 5 ++-- .../iris/mixin/shadows/ChunkInfoAccessor.java | 12 ++++++++ .../MixinPreventRebuildNearInShadowPass.java | 29 +++++++++++++++---- .../MixinChunkRebuildTask.java | 16 +++++----- .../iris/pipeline/ShadowRenderer.java | 2 +- .../texture/pbr/loader/AtlasPBRLoader.java | 10 +++---- src/main/resources/iris.accesswidener | 4 +-- src/main/resources/mixins.iris.json | 1 + 12 files changed, 63 insertions(+), 37 deletions(-) create mode 100644 src/main/java/net/coderbot/iris/mixin/shadows/ChunkInfoAccessor.java diff --git a/buildscript/src/main/java/Buildscript.java b/buildscript/src/main/java/Buildscript.java index 7b65d16927..38d34e364a 100644 --- a/buildscript/src/main/java/Buildscript.java +++ b/buildscript/src/main/java/Buildscript.java @@ -45,7 +45,7 @@ public class Buildscript extends SimpleFabricProject { static final boolean SODIUM = true; static final boolean CUSTOM_SODIUM = false; - static final String MC_VERSION = "1.20.4"; + static final String MC_VERSION = "1.20.1"; static final String customSodiumName = "sodium-fabric-mc1.20.3-0.5.6git.7a62284.jar"; private static final String[] SOURCE_SETS = new String[] { @@ -114,10 +114,10 @@ public void getModDependencies(ModDependencyCollector d) { if (CUSTOM_SODIUM) { d.add(new JavaJarDependency(getProjectDir().resolve("custom_sodium").resolve(customSodiumName).toAbsolutePath(), null, new MavenId("me.jellysquid.mods", "sodium-fabric", customSodiumName.replace("sodium-fabric-", ""))), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); } else { - d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "sodium", "mc1.20.3-0.5.6"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); + d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "sodium", "mc1.20.1-0.5.6"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); } } else { - d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "sodium", "mc1.20.3-0.5.6"), ModDependencyFlag.COMPILE); + d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "sodium", "mc1.20.1-0.5.6"), ModDependencyFlag.COMPILE); } } diff --git a/src/main/java/net/coderbot/batchedentityrendering/mixin/MixinRenderBuffers.java b/src/main/java/net/coderbot/batchedentityrendering/mixin/MixinRenderBuffers.java index aabd3b6be4..92e4b810ae 100644 --- a/src/main/java/net/coderbot/batchedentityrendering/mixin/MixinRenderBuffers.java +++ b/src/main/java/net/coderbot/batchedentityrendering/mixin/MixinRenderBuffers.java @@ -6,7 +6,7 @@ import net.coderbot.batchedentityrendering.impl.MemoryTrackingBuffer; import net.coderbot.batchedentityrendering.impl.MemoryTrackingRenderBuffers; import net.coderbot.batchedentityrendering.impl.RenderBuffersExt; -import net.minecraft.client.renderer.SectionBufferBuilderPack; +import net.minecraft.client.renderer.ChunkBufferBuilderPack; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.OutlineBufferSource; import net.minecraft.client.renderer.RenderBuffers; @@ -45,7 +45,7 @@ public class MixinRenderBuffers implements RenderBuffersExt, MemoryTrackingRende @Shadow @Final - private SectionBufferBuilderPack fixedBufferPack; + private ChunkBufferBuilderPack fixedBufferPack; @Inject(method = "bufferSource", at = @At("HEAD"), cancellable = true) private void batchedentityrendering$replaceBufferSource(CallbackInfoReturnable cir) { diff --git a/src/main/java/net/coderbot/batchedentityrendering/mixin/SectionBufferBuilderPackAccessor.java b/src/main/java/net/coderbot/batchedentityrendering/mixin/SectionBufferBuilderPackAccessor.java index beddf3444f..132b01bb5e 100644 --- a/src/main/java/net/coderbot/batchedentityrendering/mixin/SectionBufferBuilderPackAccessor.java +++ b/src/main/java/net/coderbot/batchedentityrendering/mixin/SectionBufferBuilderPackAccessor.java @@ -1,14 +1,14 @@ package net.coderbot.batchedentityrendering.mixin; import com.mojang.blaze3d.vertex.BufferBuilder; -import net.minecraft.client.renderer.SectionBufferBuilderPack; +import net.minecraft.client.renderer.ChunkBufferBuilderPack; import net.minecraft.client.renderer.RenderType; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; import java.util.Map; -@Mixin(SectionBufferBuilderPack.class) +@Mixin(ChunkBufferBuilderPack.class) public interface SectionBufferBuilderPackAccessor { @Accessor Map getBuilders(); diff --git a/src/main/java/net/coderbot/iris/mixin/MixinLevelRenderer.java b/src/main/java/net/coderbot/iris/mixin/MixinLevelRenderer.java index 6da751fae5..81cf5fb466 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinLevelRenderer.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinLevelRenderer.java @@ -4,7 +4,6 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Axis; import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.world.TickRateManager; import org.joml.Matrix4f; import net.coderbot.iris.Iris; import net.coderbot.iris.layer.IsOutlineRenderStateShard; @@ -71,11 +70,9 @@ public class MixinLevelRenderer { IrisTimeUniforms.updateTime(); CapturedRenderingState.INSTANCE.setGbufferModelView(poseStack.last().pose()); CapturedRenderingState.INSTANCE.setGbufferProjection(projection); - TickRateManager lvTickRateManager10 = this.minecraft.level.tickRateManager(); - float fakeTickDelta = lvTickRateManager10.runsNormally() ? tickDelta : 1.0F; - CapturedRenderingState.INSTANCE.setTickDelta(fakeTickDelta); + CapturedRenderingState.INSTANCE.setTickDelta(tickDelta); CapturedRenderingState.INSTANCE.setRealTickDelta(tickDelta); - CapturedRenderingState.INSTANCE.setCloudTime((ticks + fakeTickDelta) * 0.03F); + CapturedRenderingState.INSTANCE.setCloudTime((ticks + tickDelta) * 0.03F); SystemTimeUniforms.COUNTER.beginFrame(); SystemTimeUniforms.TIMER.beginFrame(startTime); diff --git a/src/main/java/net/coderbot/iris/mixin/entity_render_context/MixinCapeLayer.java b/src/main/java/net/coderbot/iris/mixin/entity_render_context/MixinCapeLayer.java index c543eb46f1..dfcf899165 100644 --- a/src/main/java/net/coderbot/iris/mixin/entity_render_context/MixinCapeLayer.java +++ b/src/main/java/net/coderbot/iris/mixin/entity_render_context/MixinCapeLayer.java @@ -7,7 +7,6 @@ import net.minecraft.client.player.AbstractClientPlayer; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.entity.layers.CapeLayer; -import net.minecraft.client.resources.PlayerSkin; import net.minecraft.core.Registry; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; @@ -22,8 +21,8 @@ public class MixinCapeLayer { private static final NamespacedId CAPE_LOCATION = new NamespacedId("minecraft", "player_cape"); - @Inject(method = "render(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;ILnet/minecraft/client/player/AbstractClientPlayer;FFFFFF)V", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;pushPose()V"), locals = LocalCapture.CAPTURE_FAILHARD) - private void changeId(PoseStack pCapeLayer0, MultiBufferSource pMultiBufferSource1, int pInt2, AbstractClientPlayer pAbstractClientPlayer3, float pFloat4, float pFloat5, float pFloat6, float pFloat7, float pFloat8, float pFloat9, CallbackInfo ci, PlayerSkin lvPlayerSkin11, ItemStack lvItemStack12) { + @Inject(method = "render(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;ILnet/minecraft/client/player/AbstractClientPlayer;FFFFFF)V", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;pushPose()V")) + private void changeId(PoseStack pCapeLayer0, MultiBufferSource pMultiBufferSource1, int pInt2, AbstractClientPlayer pAbstractClientPlayer3, float pFloat4, float pFloat5, float pFloat6, float pFloat7, float pFloat8, float pFloat9, CallbackInfo ci) { if (BlockRenderingSettings.INSTANCE.getItemIds() == null) return; CapturedRenderingState.INSTANCE.setCurrentRenderedItem(BlockRenderingSettings.INSTANCE.getItemIds().applyAsInt(CAPE_LOCATION)); diff --git a/src/main/java/net/coderbot/iris/mixin/shadows/ChunkInfoAccessor.java b/src/main/java/net/coderbot/iris/mixin/shadows/ChunkInfoAccessor.java new file mode 100644 index 0000000000..ec3933cc77 --- /dev/null +++ b/src/main/java/net/coderbot/iris/mixin/shadows/ChunkInfoAccessor.java @@ -0,0 +1,12 @@ +package net.coderbot.iris.mixin.shadows; + +import net.minecraft.client.renderer.LevelRenderer; +import net.minecraft.client.renderer.chunk.ChunkRenderDispatcher; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(LevelRenderer.RenderChunkInfo.class) +public interface ChunkInfoAccessor { + @Accessor("chunk") + ChunkRenderDispatcher.RenderChunk getChunk(); +} diff --git a/src/main/java/net/coderbot/iris/mixin/shadows/MixinPreventRebuildNearInShadowPass.java b/src/main/java/net/coderbot/iris/mixin/shadows/MixinPreventRebuildNearInShadowPass.java index 0d18f56c2c..f5777e4481 100644 --- a/src/main/java/net/coderbot/iris/mixin/shadows/MixinPreventRebuildNearInShadowPass.java +++ b/src/main/java/net/coderbot/iris/mixin/shadows/MixinPreventRebuildNearInShadowPass.java @@ -6,7 +6,6 @@ import net.minecraft.client.Camera; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.LevelRenderer; -import net.minecraft.client.renderer.chunk.SectionRenderDispatcher; import net.minecraft.client.renderer.culling.Frustum; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -32,15 +31,35 @@ public abstract class MixinPreventRebuildNearInShadowPass { @Shadow @Final - private ObjectArrayList visibleSections; + private ObjectArrayList renderChunksInFrustum; + @Shadow + protected abstract void applyFrustum(Frustum frustum); + + @Group(name = "iris_MixinPreventRebuildNearInShadowPass", min = 1, max = 1) @Inject(method = "setupRender", - at = @At(value = "TAIL")) + at = @At(value = "INVOKE", + target = "Ljava/util/concurrent/atomic/AtomicReference;get()Ljava/lang/Object;"), + cancellable = true, + require = 0) private void iris$preventRebuildNearInShadowPass(Camera camera, Frustum frustum, boolean bl, boolean bl2, CallbackInfo ci) { if (ShadowRenderer.ACTIVE) { - for (SectionRenderDispatcher.RenderSection chunk : this.visibleSections) { - ShadowRenderer.visibleBlockEntities.addAll(chunk.getCompiled().getRenderableBlockEntities()); + for (LevelRenderer.RenderChunkInfo chunk : this.renderChunksInFrustum) { + ShadowRenderer.visibleBlockEntities.addAll(((ChunkInfoAccessor) chunk).getChunk().getCompiledChunk().getRenderableBlockEntities()); } + Minecraft.getInstance().getProfiler().pop(); + this.applyFrustum(frustum); + ci.cancel(); } } + + @Group(name = "iris_MixinPreventRebuildNearInShadowPass", min = 1, max = 1) + @Inject(method = "setupRender", + at = @At(value = "INVOKE", + target = "me/jellysquid/mods/sodium/client/gl/device/RenderDevice.enterManagedCode ()V", + remap = false), + require = 0) + private void iris$cannotInject(Camera camera, Frustum frustum, boolean bl, boolean bl2, CallbackInfo ci) { + // Dummy injection just to assert that either Sodium is present, or the vanilla injection passed. + } } diff --git a/src/main/java/net/coderbot/iris/mixin/vertices/block_rendering/MixinChunkRebuildTask.java b/src/main/java/net/coderbot/iris/mixin/vertices/block_rendering/MixinChunkRebuildTask.java index 2c1cadd5f6..05c96297ae 100644 --- a/src/main/java/net/coderbot/iris/mixin/vertices/block_rendering/MixinChunkRebuildTask.java +++ b/src/main/java/net/coderbot/iris/mixin/vertices/block_rendering/MixinChunkRebuildTask.java @@ -7,10 +7,10 @@ import net.coderbot.iris.block_rendering.BlockRenderingSettings; import net.coderbot.iris.vertices.BlockSensitiveBufferBuilder; import net.coderbot.iris.vertices.ExtendedDataHelper; -import net.minecraft.client.renderer.SectionBufferBuilderPack; +import net.minecraft.client.renderer.ChunkBufferBuilderPack; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.block.BlockRenderDispatcher; -import net.minecraft.client.renderer.chunk.SectionRenderDispatcher; +import net.minecraft.client.renderer.chunk.ChunkRenderDispatcher; import net.minecraft.client.renderer.chunk.RenderChunkRegion; import net.minecraft.client.renderer.chunk.VisGraph; import net.minecraft.core.BlockPos; @@ -34,9 +34,9 @@ * * Uses a priority of 999 so that we apply before Indigo's mixins. */ -@Mixin(targets = "net.minecraft.client.renderer.chunk.SectionRenderDispatcher$RenderSection$RebuildTask", priority = 999) +@Mixin(targets = "net.minecraft.client.renderer.chunk.ChunkRenderDispatcher$RenderChunk$RebuildTask", priority = 999) public class MixinChunkRebuildTask { - private static final String RENDER = "Lnet/minecraft/client/renderer/chunk/SectionRenderDispatcher$RenderSection$RebuildTask;compile(FFFLnet/minecraft/client/renderer/SectionBufferBuilderPack;)Lnet/minecraft/client/renderer/chunk/SectionRenderDispatcher$RenderSection$RebuildTask$CompileResults;"; + private static final String RENDER = "Lnet/minecraft/client/renderer/chunk/ChunkRenderDispatcher$RenderChunk$RebuildTask;compile(FFFLnet/minecraft/client/renderer/ChunkBufferBuilderPack;)Lnet/minecraft/client/renderer/chunk/ChunkRenderDispatcher$RenderChunk$RebuildTask$CompileResults;"; @Unique private BlockSensitiveBufferBuilder lastBufferBuilder; @@ -60,7 +60,7 @@ private short resolveBlockId(BlockState state) { } @Inject(method = RENDER, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/block/BlockRenderDispatcher;renderLiquid(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/BlockAndTintGetter;Lcom/mojang/blaze3d/vertex/VertexConsumer;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/material/FluidState;)V"), locals = LocalCapture.CAPTURE_FAILHARD) - private void iris$onRenderLiquid(float cameraX, float cameraY, float cameraZ, SectionBufferBuilderPack buffers, CallbackInfoReturnable cir, SectionRenderDispatcher.RenderSection.RebuildTask.CompileResults results,int i, BlockPos blockPos, BlockPos blockPos2, VisGraph chunkOcclusionDataBuilder, RenderChunkRegion chunkRendererRegion, PoseStack poseStack, Set set2, RandomSource random, BlockRenderDispatcher blockRenderManager, Iterator var15, BlockPos blockPos3, BlockState blockState, FluidState fluidState, RenderType renderType, BufferBuilder bufferBuilder2) { + private void iris$onRenderLiquid(float cameraX, float cameraY, float cameraZ, ChunkBufferBuilderPack buffers, CallbackInfoReturnable cir, ChunkRenderDispatcher.RenderChunk.RebuildTask.CompileResults results,int i, BlockPos blockPos, BlockPos blockPos2, VisGraph chunkOcclusionDataBuilder,RenderChunkRegion chunkRendererRegion, PoseStack poseStack, Set set2, RandomSource random, BlockRenderDispatcher blockRenderManager, Iterator var15, BlockPos blockPos3, BlockState blockState, BlockState state2, FluidState fluidState, RenderType renderType, BufferBuilder bufferBuilder2) { if (bufferBuilder2 instanceof BlockSensitiveBufferBuilder) { lastBufferBuilder = ((BlockSensitiveBufferBuilder) bufferBuilder2); // All fluids have a ShadersMod render type of 1, to match behavior of Minecraft 1.7 and earlier. @@ -69,7 +69,7 @@ private short resolveBlockId(BlockState state) { } @Inject(method = RENDER, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/block/BlockRenderDispatcher;renderLiquid(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/BlockAndTintGetter;Lcom/mojang/blaze3d/vertex/VertexConsumer;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/material/FluidState;)V", shift = At.Shift.AFTER)) - private void iris$finishRenderingLiquid(float cameraX, float cameraY, float cameraZ, SectionBufferBuilderPack buffers, CallbackInfoReturnable cir) { + private void iris$finishRenderingLiquid(float cameraX, float cameraY, float cameraZ, ChunkBufferBuilderPack buffers, CallbackInfoReturnable cir) { if (lastBufferBuilder != null) { lastBufferBuilder.endBlock(); lastBufferBuilder = null; @@ -77,7 +77,7 @@ private short resolveBlockId(BlockState state) { } @Inject(method = RENDER, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/block/BlockRenderDispatcher;renderBatched(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/BlockAndTintGetter;Lcom/mojang/blaze3d/vertex/PoseStack;Lcom/mojang/blaze3d/vertex/VertexConsumer;ZLnet/minecraft/util/RandomSource;)V"), locals = LocalCapture.CAPTURE_FAILHARD) - private void iris$onRenderBlock(float cameraX, float cameraY, float cameraZ, SectionBufferBuilderPack buffers, CallbackInfoReturnable cir, SectionRenderDispatcher.RenderSection.RebuildTask.CompileResults results, int i, BlockPos blockPos, BlockPos blockPos2, VisGraph chunkOcclusionDataBuilder,RenderChunkRegion chunkRendererRegion, PoseStack poseStack, Set set2, RandomSource random, BlockRenderDispatcher blockRenderManager, Iterator var15, BlockPos blockPos3, BlockState blockState, FluidState fluidState, RenderType renderType2, BufferBuilder bufferBuilder2) { + private void iris$onRenderBlock(float cameraX, float cameraY, float cameraZ, ChunkBufferBuilderPack buffers, CallbackInfoReturnable cir, ChunkRenderDispatcher.RenderChunk.RebuildTask.CompileResults results, int i, BlockPos blockPos, BlockPos blockPos2, VisGraph chunkOcclusionDataBuilder,RenderChunkRegion chunkRendererRegion, PoseStack poseStack, Set set2, RandomSource random, BlockRenderDispatcher blockRenderManager, Iterator var15, BlockPos blockPos3, BlockState blockState, BlockState state2, FluidState fluidState, RenderType renderType2, BufferBuilder bufferBuilder2) { if (bufferBuilder2 instanceof BlockSensitiveBufferBuilder) { lastBufferBuilder = ((BlockSensitiveBufferBuilder) bufferBuilder2); // TODO: Resolve render types for normal blocks? @@ -86,7 +86,7 @@ private short resolveBlockId(BlockState state) { } @Inject(method = RENDER, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/block/BlockRenderDispatcher;renderBatched(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/BlockAndTintGetter;Lcom/mojang/blaze3d/vertex/PoseStack;Lcom/mojang/blaze3d/vertex/VertexConsumer;ZLnet/minecraft/util/RandomSource;)V", shift = At.Shift.AFTER)) - private void iris$finishRenderingBlock(float cameraX, float cameraY, float cameraZ, SectionBufferBuilderPack buffers, CallbackInfoReturnable cir) { + private void iris$finishRenderingBlock(float cameraX, float cameraY, float cameraZ, ChunkBufferBuilderPack buffers, CallbackInfoReturnable cir) { if (lastBufferBuilder != null) { lastBufferBuilder.endBlock(); lastBufferBuilder = null; diff --git a/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java b/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java index 78f603b6ad..7a2e62d905 100644 --- a/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java +++ b/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java @@ -540,7 +540,7 @@ public void renderShadows(LevelRendererAccessor levelRenderer, Camera playerCame IrisRenderSystem.restorePlayerProjection(); - debugStringTerrain = ((LevelRenderer) levelRenderer).getSectionStatistics(); + debugStringTerrain = ((LevelRenderer) levelRenderer).getChunkStatistics(); levelRenderer.getLevel().getProfiler().popPush("generate mipmaps"); diff --git a/src/main/java/net/coderbot/iris/texture/pbr/loader/AtlasPBRLoader.java b/src/main/java/net/coderbot/iris/texture/pbr/loader/AtlasPBRLoader.java index 22605aa590..1c8396a71f 100644 --- a/src/main/java/net/coderbot/iris/texture/pbr/loader/AtlasPBRLoader.java +++ b/src/main/java/net/coderbot/iris/texture/pbr/loader/AtlasPBRLoader.java @@ -22,7 +22,6 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.server.packs.resources.Resource; import net.minecraft.server.packs.resources.ResourceManager; -import net.minecraft.server.packs.resources.ResourceMetadata; import net.minecraft.util.Mth; import org.jetbrains.annotations.Nullable; @@ -91,9 +90,9 @@ protected PBRTextureAtlasSprite createPBRSprite(TextureAtlasSprite sprite, Resou } Resource resource = optionalResource.get(); - ResourceMetadata animationMetadata; + AnimationMetadataSection animationMetadata; try { - animationMetadata = resource.metadata(); + animationMetadata = resource.metadata().getSection(AnimationMetadataSection.SERIALIZER).orElse(AnimationMetadataSection.EMPTY); } catch (Exception e) { Iris.logger.error("Unable to parse metadata from {}", pbrImageLocation, e); return null; @@ -109,8 +108,7 @@ protected PBRTextureAtlasSprite createPBRSprite(TextureAtlasSprite sprite, Resou int imageWidth = nativeImage.getWidth(); int imageHeight = nativeImage.getHeight(); - AnimationMetadataSection metadataSection = animationMetadata.getSection(AnimationMetadataSection.SERIALIZER).orElse(AnimationMetadataSection.EMPTY); - FrameSize frameSize = metadataSection.calculateFrameSize(imageWidth, imageHeight); + FrameSize frameSize = animationMetadata.calculateFrameSize(imageWidth, imageHeight); int frameWidth = frameSize.width(); int frameHeight = frameSize.height(); if (!Mth.isMultipleOf(imageWidth, frameWidth) || !Mth.isMultipleOf(imageHeight, frameHeight)) { @@ -175,7 +173,7 @@ protected ResourceLocation getPBRImageLocation(ResourceLocation spriteName, PBRT protected static class PBRSpriteContents extends SpriteContents implements CustomMipmapGenerator.Provider { protected final PBRType pbrType; - public PBRSpriteContents(ResourceLocation name, FrameSize size, NativeImage image, ResourceMetadata metadata, PBRType pbrType) { + public PBRSpriteContents(ResourceLocation name, FrameSize size, NativeImage image, AnimationMetadataSection metadata, PBRType pbrType) { super(name, size, image, metadata); this.pbrType = pbrType; } diff --git a/src/main/resources/iris.accesswidener b/src/main/resources/iris.accesswidener index 44206808e9..6d3e780aea 100644 --- a/src/main/resources/iris.accesswidener +++ b/src/main/resources/iris.accesswidener @@ -18,9 +18,9 @@ accessible class net/minecraft/client/renderer/texture/SpriteContents$FrameInfo accessible class net/minecraft/client/renderer/texture/SpriteContents$Ticker accessible class net/minecraft/client/OptionInstance$ValueSet extendable class net/minecraft/client/OptionInstance -accessible class net/minecraft/client/renderer/chunk/SectionRenderDispatcher$RenderSection$RebuildTask +accessible class net/minecraft/client/renderer/chunk/ChunkRenderDispatcher$RenderChunk$RebuildTask extendable class net/minecraft/core/RegistryAccess$RegistryEntry -accessible class net/minecraft/client/renderer/chunk/SectionRenderDispatcher$RenderSection$RebuildTask$CompileResults +accessible class net/minecraft/client/renderer/chunk/ChunkRenderDispatcher$RenderChunk$RebuildTask$CompileResults accessible method net/minecraft/client/renderer/RenderType create (Ljava/lang/String;Lcom/mojang/blaze3d/vertex/VertexFormat;Lcom/mojang/blaze3d/vertex/VertexFormat$Mode;IZZLnet/minecraft/client/renderer/RenderType$CompositeState;)Lnet/minecraft/client/renderer/RenderType$CompositeRenderType; accessible field com/mojang/blaze3d/platform/NativeImage pixels J mutable field net/minecraft/client/renderer/ShaderInstance PROJECTION_MATRIX Lcom/mojang/blaze3d/shaders/Uniform; diff --git a/src/main/resources/mixins.iris.json b/src/main/resources/mixins.iris.json index 27cffc5703..99e154acc0 100644 --- a/src/main/resources/mixins.iris.json +++ b/src/main/resources/mixins.iris.json @@ -69,6 +69,7 @@ "rendertype.RenderTypeAccessor", "rendertype.RenderStateShardAccessor", "rendertype.RenderTypeAccessor", + "shadows.ChunkInfoAccessor", "shadows.MixinBeaconRenderer", "shadows.MixinLevelRenderer", "shadows.MixinPreventRebuildNearInShadowPass", From b9c457a4b8d71eba51e66a4e1748e7d0acd9e767 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Sat, 27 Jan 2024 14:00:08 -0800 Subject: [PATCH 50/56] Revert "Fix shader pack screen" This reverts commit 131d754474f7aec0adbf7e1ef6773060e0229672. --- .../iris/gui/element/ShaderPackOptionList.java | 4 ++-- .../iris/gui/element/ShaderPackSelectionList.java | 10 +++++----- .../net/coderbot/iris/gui/screen/ShaderPackScreen.java | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/coderbot/iris/gui/element/ShaderPackOptionList.java b/src/main/java/net/coderbot/iris/gui/element/ShaderPackOptionList.java index 999f524b70..8aad40fe20 100644 --- a/src/main/java/net/coderbot/iris/gui/element/ShaderPackOptionList.java +++ b/src/main/java/net/coderbot/iris/gui/element/ShaderPackOptionList.java @@ -47,7 +47,7 @@ public class ShaderPackOptionList extends IrisContainerObjectSelectionList Date: Sat, 27 Jan 2024 14:05:53 -0800 Subject: [PATCH 51/56] Part 2 --- buildscript/src/main/java/Buildscript.java | 2 +- .../iris/gui/FeatureMissingErrorScreen.java | 2 +- .../IrisContainerObjectSelectionList.java | 5 +- .../gui/element/IrisObjectSelectionList.java | 7 ++- .../gui/element/ShaderPackOptionList.java | 9 ++- .../gui/element/ShaderPackSelectionList.java | 13 ++--- .../iris/gui/screen/ShaderPackScreen.java | 7 +-- .../mixin/MixinEntityRenderDispatcher.java | 4 +- .../MixinMinecraft_PipelineManagement.java | 2 +- .../MixinElytraLayer.java | 2 +- .../mixin/shadows/MixinLevelRenderer.java | 39 ++++++++++++- .../iris/pipeline/ShadowRenderer.java | 16 ++---- .../texture/pbr/loader/AtlasPBRLoader.java | 55 +++++++++---------- src/main/resources/fabric.mod.json | 2 +- 14 files changed, 93 insertions(+), 72 deletions(-) diff --git a/buildscript/src/main/java/Buildscript.java b/buildscript/src/main/java/Buildscript.java index 38d34e364a..8d1ef0286e 100644 --- a/buildscript/src/main/java/Buildscript.java +++ b/buildscript/src/main/java/Buildscript.java @@ -108,7 +108,7 @@ public void getModDependencies(ModDependencyCollector d) { d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", "fabric-rendering-data-attachment-v1", "0.3.21+12bfe4ea53"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", "fabric-block-view-api-v2", "1.0.0+92a0d36777"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", "fabric-rendering-fluids-v1", "3.0.13+fbde993d53"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); - d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", "fabric-resource-loader-v0", "0.11.14+f31bf881a9"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); + d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", "fabric-resource-loader-v0", "0.10.8+12a6ba2c17"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", "fabric-block-view-api-v2", "1.0.0+73761d2e99"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); if (CUSTOM_SODIUM) { diff --git a/src/main/java/net/coderbot/iris/gui/FeatureMissingErrorScreen.java b/src/main/java/net/coderbot/iris/gui/FeatureMissingErrorScreen.java index b00c410a19..a3e2861861 100644 --- a/src/main/java/net/coderbot/iris/gui/FeatureMissingErrorScreen.java +++ b/src/main/java/net/coderbot/iris/gui/FeatureMissingErrorScreen.java @@ -30,7 +30,7 @@ protected void init() { @Override public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) { - this.renderBackground(guiGraphics, mouseX, mouseY, delta); + this.renderBackground(guiGraphics); guiGraphics.drawCenteredString(this.font, this.title, this.width / 2, 90, 0xFFFFFF); message.renderCentered(guiGraphics, this.width / 2, 110, 9, 0xFFFFFF); super.render(guiGraphics, mouseX, mouseY, delta); diff --git a/src/main/java/net/coderbot/iris/gui/element/IrisContainerObjectSelectionList.java b/src/main/java/net/coderbot/iris/gui/element/IrisContainerObjectSelectionList.java index c292005552..ec1a70589d 100644 --- a/src/main/java/net/coderbot/iris/gui/element/IrisContainerObjectSelectionList.java +++ b/src/main/java/net/coderbot/iris/gui/element/IrisContainerObjectSelectionList.java @@ -8,7 +8,10 @@ public class IrisContainerObjectSelectionList> extends ContainerObjectSelectionList { public IrisContainerObjectSelectionList(Minecraft client, int width, int height, int top, int bottom, int left, int right, int itemHeight) { - super(client, width, height, top, itemHeight); + super(client, width, height, top, bottom, itemHeight); + + this.x0 = left; + this.x1 = right; } @Override diff --git a/src/main/java/net/coderbot/iris/gui/element/IrisObjectSelectionList.java b/src/main/java/net/coderbot/iris/gui/element/IrisObjectSelectionList.java index 618f2dcbb7..91f48c415d 100644 --- a/src/main/java/net/coderbot/iris/gui/element/IrisObjectSelectionList.java +++ b/src/main/java/net/coderbot/iris/gui/element/IrisObjectSelectionList.java @@ -8,7 +8,10 @@ public class IrisObjectSelectionList> extends AbstractSelectionList { public IrisObjectSelectionList(Minecraft client, int width, int height, int top, int bottom, int left, int right, int itemHeight) { - super(client, width, height, top, itemHeight); + super(client, width, height, top, bottom, itemHeight); + + this.x0 = left; + this.x1 = right; } @Override @@ -23,7 +26,7 @@ public void select(int entry) { } @Override - public void updateWidgetNarration(NarrationElementOutput p0) { + public void updateNarration(NarrationElementOutput p0) { } } diff --git a/src/main/java/net/coderbot/iris/gui/element/ShaderPackOptionList.java b/src/main/java/net/coderbot/iris/gui/element/ShaderPackOptionList.java index 8aad40fe20..9df2e00650 100644 --- a/src/main/java/net/coderbot/iris/gui/element/ShaderPackOptionList.java +++ b/src/main/java/net/coderbot/iris/gui/element/ShaderPackOptionList.java @@ -50,7 +50,6 @@ public ShaderPackOptionList(ShaderPackScreen screen, NavigationController naviga super(client, width, height, top, bottom, left, right, 24); this.navigation = navigation; this.screen = screen; - this.setRenderBackground(false); applyShaderPack(pack); } @@ -60,12 +59,12 @@ protected void renderDecorations(GuiGraphics pAbstractSelectionList0, int pInt1, // Renders top/bottom dirt int lvInt9 = 32; pAbstractSelectionList0.setColor(0.25F, 0.25F, 0.25F, 1.0F); - pAbstractSelectionList0.blit(Screen.BACKGROUND_LOCATION, this.getX(), 0, 0.0F, 0.0F, this.width, this.getY(), 32, 32); - pAbstractSelectionList0.blit(Screen.BACKGROUND_LOCATION, this.getX(), this.getBottom(), 0.0F, (float)this.getBottom(), this.width, this.height - this.getBottom(), 32, 32); + pAbstractSelectionList0.blit(Screen.BACKGROUND_LOCATION, this.x0, 0, 0.0F, 0.0F, this.width, this.y0, 32, 32); + pAbstractSelectionList0.blit(Screen.BACKGROUND_LOCATION, this.x0, this.y1, 0.0F, (float)this.y1, this.width, this.height - this.y1, 32, 32); pAbstractSelectionList0.setColor(1.0F, 1.0F, 1.0F, 1.0F); int lvInt10 = 4; - pAbstractSelectionList0.fillGradient(RenderType.guiOverlay(), this.getX(), this.getY(), this.getRight(), this.getY() + 4, -16777216, 0, 0); - pAbstractSelectionList0.fillGradient(RenderType.guiOverlay(), this.getX(), this.getBottom() - 4, this.getRight(), this.getBottom(), 0, -16777216, 0); + pAbstractSelectionList0.fillGradient(RenderType.guiOverlay(), this.x0, this.y0, this.x1, this.y0 + 4, -16777216, 0, 0); + pAbstractSelectionList0.fillGradient(RenderType.guiOverlay(), this.x0, this.y1 - 4, this.x1, this.y1, 0, -16777216, 0); super.renderDecorations(pAbstractSelectionList0, pInt1, pInt2); } diff --git a/src/main/java/net/coderbot/iris/gui/element/ShaderPackSelectionList.java b/src/main/java/net/coderbot/iris/gui/element/ShaderPackSelectionList.java index d51d06199e..e2cbdebbc4 100644 --- a/src/main/java/net/coderbot/iris/gui/element/ShaderPackSelectionList.java +++ b/src/main/java/net/coderbot/iris/gui/element/ShaderPackSelectionList.java @@ -52,7 +52,6 @@ public ShaderPackSelectionList(ShaderPackScreen screen, Minecraft client, int wi super(client, width, height, top, bottom, left, right, 20); WatchKey key1; WatchService watcher1; - this.setRenderBackground(false); this.screen = screen; this.topButtonRow = new TopButtonRowEntry(this, Iris.getIrisConfig().areShadersEnabled()); @@ -85,7 +84,7 @@ public boolean keyPressed(int pContainerEventHandler0, int pInt1, int pInt2) { } @Override - public void renderWidget(GuiGraphics pAbstractSelectionList0, int pInt1, int pInt2, float pFloat3) { + public void render(GuiGraphics pAbstractSelectionList0, int pInt1, int pInt2, float pFloat3) { if (keyValid) { for (WatchEvent event : key.pollEvents()) { if (event.kind() == StandardWatchEventKinds.OVERFLOW) continue; @@ -97,7 +96,7 @@ public void renderWidget(GuiGraphics pAbstractSelectionList0, int pInt1, int pIn keyValid = key.reset(); } - super.renderWidget(pAbstractSelectionList0, pInt1, pInt2, pFloat3); + super.render(pAbstractSelectionList0, pInt1, pInt2, pFloat3); } public void close() throws IOException { @@ -184,12 +183,12 @@ protected void renderDecorations(GuiGraphics pAbstractSelectionList0, int pInt1, // Renders top/bottom dirt int lvInt9 = 32; pAbstractSelectionList0.setColor(0.25F, 0.25F, 0.25F, 1.0F); - pAbstractSelectionList0.blit(Screen.BACKGROUND_LOCATION, this.getX(), 0, 0.0F, 0.0F, this.width, this.getHeight(), 32, 32); - pAbstractSelectionList0.blit(Screen.BACKGROUND_LOCATION, this.getX(), this.getBottom(), 0.0F, (float)this.getBottom(), this.width, this.height - this.getBottom(), 32, 32); + pAbstractSelectionList0.blit(Screen.BACKGROUND_LOCATION, this.x0, 0, 0.0F, 0.0F, this.width, this.y0, 32, 32); + pAbstractSelectionList0.blit(Screen.BACKGROUND_LOCATION, this.x0, this.y1, 0.0F, (float)this.y1, this.width, this.height - this.y1, 32, 32); pAbstractSelectionList0.setColor(1.0F, 1.0F, 1.0F, 1.0F); int lvInt10 = 4; - pAbstractSelectionList0.fillGradient(RenderType.guiOverlay(), this.getX(), this.getHeight(), this.getRight(), this.getHeight() + 4, -16777216, 0, 0); - pAbstractSelectionList0.fillGradient(RenderType.guiOverlay(), this.getX(), this.getBottom() - 4, this.getRight(), this.getBottom(), 0, -16777216, 0); + pAbstractSelectionList0.fillGradient(RenderType.guiOverlay(), this.x0, this.y0, this.x1, this.y0 + 4, -16777216, 0, 0); + pAbstractSelectionList0.fillGradient(RenderType.guiOverlay(), this.x0, this.y1 - 4, this.x1, this.y1, 0, -16777216, 0); super.renderDecorations(pAbstractSelectionList0, pInt1, pInt2); } diff --git a/src/main/java/net/coderbot/iris/gui/screen/ShaderPackScreen.java b/src/main/java/net/coderbot/iris/gui/screen/ShaderPackScreen.java index e631520291..3d403d0a1e 100644 --- a/src/main/java/net/coderbot/iris/gui/screen/ShaderPackScreen.java +++ b/src/main/java/net/coderbot/iris/gui/screen/ShaderPackScreen.java @@ -109,7 +109,7 @@ public ShaderPackScreen(Screen parent) { @Override public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) { if (this.minecraft.level == null) { - this.renderBackground(guiGraphics, mouseX, mouseY, delta); + this.renderBackground(guiGraphics); } else if (!this.guiHidden) { guiGraphics.fillGradient(0, 0, width, height, 0x4F232323, 0x4F232323); } @@ -198,11 +198,6 @@ public boolean mouseClicked(double d, double e, int i) { return super.mouseClicked(d, e, i); } - @Override - public void renderTransparentBackground(GuiGraphics pScreen0) { - // Nope - } - @Override protected void init() { super.init(); diff --git a/src/main/java/net/coderbot/iris/mixin/MixinEntityRenderDispatcher.java b/src/main/java/net/coderbot/iris/mixin/MixinEntityRenderDispatcher.java index f3881b7647..742661ca7e 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinEntityRenderDispatcher.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinEntityRenderDispatcher.java @@ -61,7 +61,7 @@ private static void restoreShadow(PoseStack pPoseStack0, MultiBufferSource pMult } @Inject(method = "renderFlame", at = @At("HEAD")) - private void iris$setFlameId(PoseStack pEntityRenderDispatcher0, MultiBufferSource pMultiBufferSource1, Entity pEntity2, Quaternionf pQuaternionf3, CallbackInfo ci) { + private void iris$setFlameId(PoseStack pEntityRenderDispatcher0, MultiBufferSource pMultiBufferSource1, Entity pEntity2, CallbackInfo ci) { Object2IntFunction entityIds = BlockRenderingSettings.INSTANCE.getEntityIds(); if (entityIds == null) { @@ -73,7 +73,7 @@ private static void restoreShadow(PoseStack pPoseStack0, MultiBufferSource pMult } @Inject(method = "renderFlame", at = @At("RETURN")) - private void restoreFlameId(PoseStack pEntityRenderDispatcher0, MultiBufferSource pMultiBufferSource1, Entity pEntity2, Quaternionf pQuaternionf3, CallbackInfo ci) { + private void restoreFlameId(PoseStack pEntityRenderDispatcher0, MultiBufferSource pMultiBufferSource1, Entity pEntity2, CallbackInfo ci) { CapturedRenderingState.INSTANCE.setCurrentEntity(cachedId); cachedId = 0; } diff --git a/src/main/java/net/coderbot/iris/mixin/MixinMinecraft_PipelineManagement.java b/src/main/java/net/coderbot/iris/mixin/MixinMinecraft_PipelineManagement.java index 7804295e3f..d35576ea3f 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinMinecraft_PipelineManagement.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinMinecraft_PipelineManagement.java @@ -18,7 +18,7 @@ public class MixinMinecraft_PipelineManagement { /** * Should run before the Minecraft.level field is updated after disconnecting from a server or leaving a singleplayer world */ - @Inject(method = "clearClientLevel", at = @At("HEAD")) + @Inject(method = "clearLevel(Lnet/minecraft/client/gui/screens/Screen;)V", at = @At("HEAD")) public void iris$trackLastDimensionOnLeave(Screen arg, CallbackInfo ci) { Iris.lastDimension = Iris.getCurrentDimension(); } diff --git a/src/main/java/net/coderbot/iris/mixin/entity_render_context/MixinElytraLayer.java b/src/main/java/net/coderbot/iris/mixin/entity_render_context/MixinElytraLayer.java index 8851b67d33..069668dece 100644 --- a/src/main/java/net/coderbot/iris/mixin/entity_render_context/MixinElytraLayer.java +++ b/src/main/java/net/coderbot/iris/mixin/entity_render_context/MixinElytraLayer.java @@ -41,7 +41,7 @@ public MixinElytraLayer(RenderLayerParent pRenderLayer0) { private void changeId(PoseStack pElytraLayer0, MultiBufferSource pMultiBufferSource1, int pInt2, T pLivingEntity3, float pFloat4, float pFloat5, float pFloat6, float pFloat7, float pFloat8, float pFloat9, CallbackInfo ci, ItemStack lvItemStack11, ResourceLocation lvResourceLocation12) { if (BlockRenderingSettings.INSTANCE.getItemIds() == null) return; - if (pLivingEntity3 instanceof AbstractClientPlayer player && player.getSkin().capeTexture() != null + if (pLivingEntity3 instanceof AbstractClientPlayer player && player.getCloakTextureLocation() != null && player.isModelPartShown(PlayerModelPart.CAPE)) { CapturedRenderingState.INSTANCE.setCurrentRenderedItem(BlockRenderingSettings.INSTANCE.getItemIds().applyAsInt(ELYTRA_CAPE_LOCATION)); return; diff --git a/src/main/java/net/coderbot/iris/mixin/shadows/MixinLevelRenderer.java b/src/main/java/net/coderbot/iris/mixin/shadows/MixinLevelRenderer.java index 704084fc65..03e9529029 100644 --- a/src/main/java/net/coderbot/iris/mixin/shadows/MixinLevelRenderer.java +++ b/src/main/java/net/coderbot/iris/mixin/shadows/MixinLevelRenderer.java @@ -14,11 +14,25 @@ public class MixinLevelRenderer implements CullingDataCache { @Shadow @Final @Mutable - private ObjectArrayList visibleSections; + private ObjectArrayList renderChunksInFrustum; @Unique private ObjectArrayList savedRenderChunks = new ObjectArrayList(69696); + @Shadow + private boolean needsFullRenderChunkUpdate; + + @Unique + private boolean savedNeedsTerrainUpdate; + + @Shadow + private double lastCameraX; + + @Shadow + private double lastCameraY; + + @Shadow + private double lastCameraZ; @Shadow private double prevCamRotX; @@ -53,11 +67,30 @@ public void restoreState() { @Unique private void swap() { - ObjectArrayList tmpList = visibleSections; - visibleSections = savedRenderChunks; + ObjectArrayList tmpList = renderChunksInFrustum; + renderChunksInFrustum = savedRenderChunks; savedRenderChunks = tmpList; + + // TODO: If the normal chunks need a terrain update, these chunks probably do too... + // We probably should copy it over + boolean tmpBool = needsFullRenderChunkUpdate; + needsFullRenderChunkUpdate = savedNeedsTerrainUpdate; + savedNeedsTerrainUpdate = tmpBool; + double tmp; + tmp = lastCameraX; + lastCameraX = savedLastCameraX; + savedLastCameraX = tmp; + + tmp = lastCameraY; + lastCameraY = savedLastCameraY; + savedLastCameraY = tmp; + + tmp = lastCameraZ; + lastCameraZ = savedLastCameraZ; + savedLastCameraZ = tmp; + tmp = prevCamRotX; prevCamRotX = savedLastCameraPitch; savedLastCameraPitch = tmp; diff --git a/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java b/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java index 7a2e62d905..fe3d5a7d76 100644 --- a/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java +++ b/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java @@ -138,9 +138,7 @@ public ShadowRenderer(ProgramSource shadow, PackDirectives directives, this.sunPathRotation = directives.getSunPathRotation(); - int processors = Runtime.getRuntime().availableProcessors(); - int threads = Minecraft.getInstance().is64Bit() ? processors : Math.min(processors, 4); - this.buffers = new RenderBuffers(threads); + this.buffers = new RenderBuffers(); if (this.buffers instanceof RenderBuffersExt) { this.renderBuffersExt = (RenderBuffersExt) buffers; @@ -623,8 +621,7 @@ private int renderEntities(LevelRendererAccessor levelRenderer, EntityRenderDisp levelRenderer.getLevel().getProfiler().popPush("build entity geometry"); for (Entity entity : renderedEntities) { - float realTickDelta = Minecraft.getInstance().level.tickRateManager().isEntityFrozen(entity) ? tickDelta : CapturedRenderingState.INSTANCE.getRealTickDelta(); - levelRenderer.invokeRenderEntity(entity, cameraX, cameraY, cameraZ, realTickDelta, modelView, bufferSource); + levelRenderer.invokeRenderEntity(entity, cameraX, cameraY, cameraZ, tickDelta, modelView, bufferSource); } levelRenderer.getLevel().getProfiler().pop(); @@ -648,20 +645,17 @@ private int renderPlayerEntity(LevelRendererAccessor levelRenderer, EntityRender if (!player.getPassengers().isEmpty()) { for (int i = 0; i < player.getPassengers().size(); i++) { - float realTickDelta = Minecraft.getInstance().level.tickRateManager().isEntityFrozen(player.getPassengers().get(i)) ? tickDelta : CapturedRenderingState.INSTANCE.getRealTickDelta(); - levelRenderer.invokeRenderEntity(player.getPassengers().get(i), cameraX, cameraY, cameraZ, realTickDelta, modelView, bufferSource); + levelRenderer.invokeRenderEntity(player.getPassengers().get(i), cameraX, cameraY, cameraZ, tickDelta, modelView, bufferSource); shadowEntities++; } } if (player.getVehicle() != null) { - float realTickDelta = Minecraft.getInstance().level.tickRateManager().isEntityFrozen(player.getVehicle()) ? tickDelta : CapturedRenderingState.INSTANCE.getRealTickDelta(); - levelRenderer.invokeRenderEntity(player.getVehicle(), cameraX, cameraY, cameraZ, realTickDelta, modelView, bufferSource); + levelRenderer.invokeRenderEntity(player.getVehicle(), cameraX, cameraY, cameraZ, tickDelta, modelView, bufferSource); shadowEntities++; } - float realTickDelta = Minecraft.getInstance().level.tickRateManager().isEntityFrozen(player) ? tickDelta : CapturedRenderingState.INSTANCE.getRealTickDelta(); - levelRenderer.invokeRenderEntity(player, cameraX, cameraY, cameraZ, realTickDelta, modelView, bufferSource); + levelRenderer.invokeRenderEntity(player, cameraX, cameraY, cameraZ, tickDelta, modelView, bufferSource); shadowEntities++; diff --git a/src/main/java/net/coderbot/iris/texture/pbr/loader/AtlasPBRLoader.java b/src/main/java/net/coderbot/iris/texture/pbr/loader/AtlasPBRLoader.java index 1c8396a71f..8c6ddb3223 100644 --- a/src/main/java/net/coderbot/iris/texture/pbr/loader/AtlasPBRLoader.java +++ b/src/main/java/net/coderbot/iris/texture/pbr/loader/AtlasPBRLoader.java @@ -120,38 +120,33 @@ protected PBRTextureAtlasSprite createPBRSprite(TextureAtlasSprite sprite, Resou int targetFrameWidth = sprite.contents().width(); int targetFrameHeight = sprite.contents().height(); if (frameWidth != targetFrameWidth || frameHeight != targetFrameHeight) { - try { - // We can assume the following is always true: - // imageWidth % frameWidth == 0 && imageHeight % frameHeight == 0 - int targetImageWidth = imageWidth / frameWidth * targetFrameWidth; - int targetImageHeight = imageHeight / frameHeight * targetFrameHeight; - - NativeImage scaledImage; - if (targetImageWidth % imageWidth == 0 && targetImageHeight % imageHeight == 0) { - scaledImage = ImageManipulationUtil.scaleNearestNeighbor(nativeImage, targetImageWidth, targetImageHeight); - } else { - scaledImage = ImageManipulationUtil.scaleBilinear(nativeImage, targetImageWidth, targetImageHeight); + // We can assume the following is always true: + // imageWidth % frameWidth == 0 && imageHeight % frameHeight == 0 + int targetImageWidth = imageWidth / frameWidth * targetFrameWidth; + int targetImageHeight = imageHeight / frameHeight * targetFrameHeight; + + NativeImage scaledImage; + if (targetImageWidth % imageWidth == 0 && targetImageHeight % imageHeight == 0) { + scaledImage = ImageManipulationUtil.scaleNearestNeighbor(nativeImage, targetImageWidth, targetImageHeight); + } else { + scaledImage = ImageManipulationUtil.scaleBilinear(nativeImage, targetImageWidth, targetImageHeight); + } + nativeImage.close(); + nativeImage = scaledImage; + + frameWidth = targetFrameWidth; + frameHeight = targetFrameHeight; + + if (animationMetadata != AnimationMetadataSection.EMPTY) { + AnimationMetadataSectionAccessor animationAccessor = (AnimationMetadataSectionAccessor) animationMetadata; + int internalFrameWidth = animationAccessor.getFrameWidth(); + int internalFrameHeight = animationAccessor.getFrameHeight(); + if (internalFrameWidth != -1) { + animationAccessor.setFrameWidth(frameWidth); } - nativeImage.close(); - nativeImage = scaledImage; - - frameWidth = targetFrameWidth; - frameHeight = targetFrameHeight; - - if (metadataSection != AnimationMetadataSection.EMPTY) { - AnimationMetadataSectionAccessor animationAccessor = (AnimationMetadataSectionAccessor) metadataSection; - int internalFrameWidth = animationAccessor.getFrameWidth(); - int internalFrameHeight = animationAccessor.getFrameHeight(); - if (internalFrameWidth != -1) { - animationAccessor.setFrameWidth(frameWidth); - } - if (internalFrameHeight != -1) { - animationAccessor.setFrameHeight(frameHeight); - } + if (internalFrameHeight != -1) { + animationAccessor.setFrameHeight(frameHeight); } - } catch (Exception e) { - Iris.logger.error("Something bad happened trying to load PBR texture " + spriteName.getPath() + pbrType.getSuffix() + "!", e); - throw e; } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 1cdb2af8ed..0e255c15e8 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -45,7 +45,7 @@ "depends": { "fabricloader": ">=0.12.3", - "minecraft": ["1.20.3", "1.20.4"], + "minecraft": ["1.20.1"], "sodium": "0.5.6" }, From e33444e2428c2e6de7282c573f0aefa4bff59843 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Sat, 27 Jan 2024 14:05:56 -0800 Subject: [PATCH 52/56] Revert "Finally fix all the issues" This reverts commit a5397dd879a9ac3837d37be5e9a5750948e6732d. --- .../iris/gui/element/ShaderPackOptionList.java | 15 --------------- .../gui/element/ShaderPackSelectionList.java | 16 ---------------- 2 files changed, 31 deletions(-) diff --git a/src/main/java/net/coderbot/iris/gui/element/ShaderPackOptionList.java b/src/main/java/net/coderbot/iris/gui/element/ShaderPackOptionList.java index 9df2e00650..3fbbbe2cc3 100644 --- a/src/main/java/net/coderbot/iris/gui/element/ShaderPackOptionList.java +++ b/src/main/java/net/coderbot/iris/gui/element/ShaderPackOptionList.java @@ -23,7 +23,6 @@ import net.minecraft.client.gui.navigation.ScreenDirection; import net.minecraft.client.gui.navigation.ScreenRectangle; import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.renderer.RenderType; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.network.chat.TextColor; @@ -54,20 +53,6 @@ public ShaderPackOptionList(ShaderPackScreen screen, NavigationController naviga applyShaderPack(pack); } - @Override - protected void renderDecorations(GuiGraphics pAbstractSelectionList0, int pInt1, int pInt2) { - // Renders top/bottom dirt - int lvInt9 = 32; - pAbstractSelectionList0.setColor(0.25F, 0.25F, 0.25F, 1.0F); - pAbstractSelectionList0.blit(Screen.BACKGROUND_LOCATION, this.x0, 0, 0.0F, 0.0F, this.width, this.y0, 32, 32); - pAbstractSelectionList0.blit(Screen.BACKGROUND_LOCATION, this.x0, this.y1, 0.0F, (float)this.y1, this.width, this.height - this.y1, 32, 32); - pAbstractSelectionList0.setColor(1.0F, 1.0F, 1.0F, 1.0F); - int lvInt10 = 4; - pAbstractSelectionList0.fillGradient(RenderType.guiOverlay(), this.x0, this.y0, this.x1, this.y0 + 4, -16777216, 0, 0); - pAbstractSelectionList0.fillGradient(RenderType.guiOverlay(), this.x0, this.y1 - 4, this.x1, this.y1, 0, -16777216, 0); - super.renderDecorations(pAbstractSelectionList0, pInt1, pInt2); - } - public void applyShaderPack(ShaderPack pack) { this.container = pack.getMenuContainer(); } diff --git a/src/main/java/net/coderbot/iris/gui/element/ShaderPackSelectionList.java b/src/main/java/net/coderbot/iris/gui/element/ShaderPackSelectionList.java index e2cbdebbc4..dbd6d4ee4e 100644 --- a/src/main/java/net/coderbot/iris/gui/element/ShaderPackSelectionList.java +++ b/src/main/java/net/coderbot/iris/gui/element/ShaderPackSelectionList.java @@ -19,8 +19,6 @@ import net.minecraft.client.gui.narration.NarratableEntry; import net.minecraft.client.gui.navigation.FocusNavigationEvent; import net.minecraft.client.gui.navigation.ScreenRectangle; -import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.renderer.RenderType; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.network.chat.TextColor; @@ -178,20 +176,6 @@ public void addPackEntry(int index, String name) { this.addEntry(entry); } - @Override - protected void renderDecorations(GuiGraphics pAbstractSelectionList0, int pInt1, int pInt2) { - // Renders top/bottom dirt - int lvInt9 = 32; - pAbstractSelectionList0.setColor(0.25F, 0.25F, 0.25F, 1.0F); - pAbstractSelectionList0.blit(Screen.BACKGROUND_LOCATION, this.x0, 0, 0.0F, 0.0F, this.width, this.y0, 32, 32); - pAbstractSelectionList0.blit(Screen.BACKGROUND_LOCATION, this.x0, this.y1, 0.0F, (float)this.y1, this.width, this.height - this.y1, 32, 32); - pAbstractSelectionList0.setColor(1.0F, 1.0F, 1.0F, 1.0F); - int lvInt10 = 4; - pAbstractSelectionList0.fillGradient(RenderType.guiOverlay(), this.x0, this.y0, this.x1, this.y0 + 4, -16777216, 0, 0); - pAbstractSelectionList0.fillGradient(RenderType.guiOverlay(), this.x0, this.y1 - 4, this.x1, this.y1, 0, -16777216, 0); - super.renderDecorations(pAbstractSelectionList0, pInt1, pInt2); - } - public void addLabelEntries(Component ... lines) { for (Component text : lines) { this.addEntry(new LabelEntry(text)); From 5b87775246ed3aa3afdfea6b4c4eee748fd5a6a6 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Sat, 27 Jan 2024 14:06:05 -0800 Subject: [PATCH 53/56] Revert "Fix crashes" This reverts commit d8f78e90 --- .../net/coderbot/iris/gui/OldImageButton.java | 25 ------------------- .../iris/mixin/LevelRendererAccessor.java | 5 ++-- .../iris/mixin/MixinClientPacketListener.java | 9 ++++--- .../iris/mixin/MixinLevelRenderer.java | 4 +-- .../iris/pipeline/ShadowRenderer.java | 14 ++++++++--- 5 files changed, 21 insertions(+), 36 deletions(-) diff --git a/src/main/java/net/coderbot/iris/gui/OldImageButton.java b/src/main/java/net/coderbot/iris/gui/OldImageButton.java index 91611ddc82..f95ae5cf88 100644 --- a/src/main/java/net/coderbot/iris/gui/OldImageButton.java +++ b/src/main/java/net/coderbot/iris/gui/OldImageButton.java @@ -1,6 +1,5 @@ package net.coderbot.iris.gui; -import com.mojang.blaze3d.systems.RenderSystem; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.gui.GuiGraphics; @@ -93,28 +92,4 @@ public void renderWidget(GuiGraphics pImageButton0, int pInt1, int pInt2, float this.textureHeight ); } - - public void renderTexture( - GuiGraphics pAbstractWidget0, - ResourceLocation pResourceLocation1, - int pInt2, - int pInt3, - int pInt4, - int pInt5, - int pInt6, - int pInt7, - int pInt8, - int pInt9, - int pInt10 - ) { - int lvInt12 = pInt5; - if (!this.isActive()) { - lvInt12 = pInt5 + pInt6 * 2; - } else if (this.isHoveredOrFocused()) { - lvInt12 = pInt5 + pInt6; - } - - RenderSystem.enableDepthTest(); - pAbstractWidget0.blit(pResourceLocation1, pInt2, pInt3, (float)pInt4, (float)lvInt12, pInt7, pInt8, pInt9, pInt10); - } } diff --git a/src/main/java/net/coderbot/iris/mixin/LevelRendererAccessor.java b/src/main/java/net/coderbot/iris/mixin/LevelRendererAccessor.java index ee51d5cd0a..5ee95095aa 100644 --- a/src/main/java/net/coderbot/iris/mixin/LevelRendererAccessor.java +++ b/src/main/java/net/coderbot/iris/mixin/LevelRendererAccessor.java @@ -1,6 +1,7 @@ package net.coderbot.iris.mixin; import com.mojang.blaze3d.vertex.PoseStack; +import it.unimi.dsi.fastutil.objects.ObjectList; import net.minecraft.client.Camera; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.renderer.LevelRenderer; @@ -20,8 +21,8 @@ public interface LevelRendererAccessor { @Accessor("entityRenderDispatcher") EntityRenderDispatcher getEntityRenderDispatcher(); - @Invoker("renderSectionLayer") - void invokeRenderSectionLayer(RenderType terrainLayer, PoseStack modelView, double cameraX, double cameraY, double cameraZ, Matrix4f projectionMatrix); + @Invoker("renderChunkLayer") + void invokeRenderChunkLayer(RenderType terrainLayer, PoseStack modelView, double cameraX, double cameraY, double cameraZ, Matrix4f projectionMatrix); @Invoker("setupRender") void invokeSetupRender(Camera camera, Frustum frustum, boolean hasForcedFrustum, boolean spectator); diff --git a/src/main/java/net/coderbot/iris/mixin/MixinClientPacketListener.java b/src/main/java/net/coderbot/iris/mixin/MixinClientPacketListener.java index 3b4fce9838..e3e9e0a91a 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinClientPacketListener.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinClientPacketListener.java @@ -16,16 +16,19 @@ @Mixin(ClientPacketListener.class) public class MixinClientPacketListener { + @Shadow + private Minecraft minecraft; + @Inject(method = "handleLogin", at = @At("TAIL")) private void iris$showUpdateMessage(ClientboundLoginPacket a, CallbackInfo ci) { - if (Minecraft.getInstance().player == null) { + if (this.minecraft.player == null) { return; } Iris.getUpdateChecker().getUpdateMessage().ifPresent(msg -> - Minecraft.getInstance().player.displayClientMessage(msg, false)); + this.minecraft.player.displayClientMessage(msg, false)); Iris.getStoredError().ifPresent(e -> - Minecraft.getInstance().player.displayClientMessage(Component.translatable(e instanceof ShaderCompileException ? "iris.load.failure.shader" : "iris.load.failure.generic").append(Component.literal("Copy Info").withStyle(arg -> arg.withUnderlined(true).withColor(ChatFormatting.BLUE).withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, e.getMessage())))), false)); + this.minecraft.player.displayClientMessage(Component.translatable(e instanceof ShaderCompileException ? "iris.load.failure.shader" : "iris.load.failure.generic").append(Component.literal("Copy Info").withStyle(arg -> arg.withUnderlined(true).withColor(ChatFormatting.BLUE).withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, e.getMessage())))), false)); } } diff --git a/src/main/java/net/coderbot/iris/mixin/MixinLevelRenderer.java b/src/main/java/net/coderbot/iris/mixin/MixinLevelRenderer.java index 81cf5fb466..ac1ba28a31 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinLevelRenderer.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinLevelRenderer.java @@ -186,12 +186,12 @@ public class MixinLevelRenderer { } - @Inject(method = "renderSectionLayer", at = @At("HEAD")) + @Inject(method = "renderChunkLayer", at = @At("HEAD")) private void iris$beginTerrainLayer(RenderType renderType, PoseStack poseStack, double d, double e, double f, Matrix4f projectionMatrix, CallbackInfo ci) { pipeline.setPhase(WorldRenderingPhase.fromTerrainRenderType(renderType)); } - @Inject(method = "renderSectionLayer", at = @At("RETURN")) + @Inject(method = "renderChunkLayer", at = @At("RETURN")) private void iris$endTerrainLayer(RenderType renderType, PoseStack poseStack, double d, double e, double f, Matrix4f projectionMatrix, CallbackInfo ci) { pipeline.setPhase(WorldRenderingPhase.NONE); } diff --git a/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java b/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java index fe3d5a7d76..cdba7eacd4 100644 --- a/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java +++ b/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java @@ -11,14 +11,19 @@ import net.coderbot.batchedentityrendering.impl.RenderBuffersExt; import net.coderbot.iris.Iris; import net.coderbot.iris.gl.IrisRenderSystem; +import net.coderbot.iris.gl.program.ComputeProgram; +import net.coderbot.iris.gl.texture.DepthCopyStrategy; import net.coderbot.iris.gui.option.IrisVideoSettings; import net.coderbot.iris.mixin.LevelRendererAccessor; +import net.coderbot.iris.shaderpack.ComputeSource; +import net.coderbot.iris.shaderpack.OptionalBoolean; import net.coderbot.iris.shaderpack.PackDirectives; import net.coderbot.iris.shaderpack.PackShadowDirectives; import net.coderbot.iris.shaderpack.ProgramSource; import net.coderbot.iris.shaderpack.ShadowCullState; import net.coderbot.iris.shadows.ShadowMatrices; import net.coderbot.iris.shadows.CullingDataCache; +import net.coderbot.iris.shadows.Matrix4fAccess; import net.coderbot.iris.shadows.ShadowCompositeRenderer; import net.coderbot.iris.shadows.ShadowRenderTargets; import net.coderbot.iris.shadows.ShadowRenderingState; @@ -52,6 +57,7 @@ import org.lwjgl.opengl.ARBTextureSwizzle; import org.lwjgl.opengl.GL20C; import org.lwjgl.opengl.GL30C; +import org.lwjgl.opengl.GL43C; import java.util.ArrayList; import java.util.Comparator; @@ -454,9 +460,9 @@ public void renderShadows(LevelRendererAccessor levelRenderer, Camera playerCame // Render all opaque terrain unless pack requests not to if (shouldRenderTerrain) { - levelRenderer.invokeRenderSectionLayer(RenderType.solid(), modelView, cameraX, cameraY, cameraZ, shadowProjection); - levelRenderer.invokeRenderSectionLayer(RenderType.cutout(), modelView, cameraX, cameraY, cameraZ, shadowProjection); - levelRenderer.invokeRenderSectionLayer(RenderType.cutoutMipped(), modelView, cameraX, cameraY, cameraZ, shadowProjection); + levelRenderer.invokeRenderChunkLayer(RenderType.solid(), modelView, cameraX, cameraY, cameraZ, shadowProjection); + levelRenderer.invokeRenderChunkLayer(RenderType.cutout(), modelView, cameraX, cameraY, cameraZ, shadowProjection); + levelRenderer.invokeRenderChunkLayer(RenderType.cutoutMipped(), modelView, cameraX, cameraY, cameraZ, shadowProjection); } // Reset our viewport in case Sodium overrode it @@ -526,7 +532,7 @@ public void renderShadows(LevelRendererAccessor levelRenderer, Camera playerCame // It doesn't matter a ton, since this just means that they won't be sorted in the normal rendering pass. // Just something to watch out for, however... if (shouldRenderTranslucent) { - levelRenderer.invokeRenderSectionLayer(RenderType.translucent(), modelView, cameraX, cameraY, cameraZ, shadowProjection); + levelRenderer.invokeRenderChunkLayer(RenderType.translucent(), modelView, cameraX, cameraY, cameraZ, shadowProjection); } // Note: Apparently tripwire isn't rendered in the shadow pass. From 7806827cbf6f0bf56e269f81e896c8d26e738a92 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Sat, 27 Jan 2024 14:07:52 -0800 Subject: [PATCH 54/56] Finish backport --- src/main/java/net/coderbot/iris/mixin/gui/MixinGui.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/net/coderbot/iris/mixin/gui/MixinGui.java b/src/main/java/net/coderbot/iris/mixin/gui/MixinGui.java index a6cd3f90db..6fba9fe008 100644 --- a/src/main/java/net/coderbot/iris/mixin/gui/MixinGui.java +++ b/src/main/java/net/coderbot/iris/mixin/gui/MixinGui.java @@ -27,9 +27,6 @@ public class MixinGui { @Shadow @Final private Minecraft minecraft; - @Shadow - @Final - private DebugScreenOverlay debugOverlay; @Inject(method = "render", at = @At("HEAD"), cancellable = true) public void iris$handleHudHidingScreens(GuiGraphics pGui0, float pFloat1, CallbackInfo ci) { From b618bfa5871149b9ec49cb4e11193551b9eb050b Mon Sep 17 00:00:00 2001 From: IMS212 Date: Sat, 27 Jan 2024 14:39:41 -0800 Subject: [PATCH 55/56] Fix a few issues --- .../mixin/clouds/MixinCloudRenderer.java | 8 ++++++-- .../sodium/mixin/font/MixinGlyphRenderer.java | 18 ++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/clouds/MixinCloudRenderer.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/clouds/MixinCloudRenderer.java index 72b84b0ba4..ed3b733858 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/clouds/MixinCloudRenderer.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/clouds/MixinCloudRenderer.java @@ -17,6 +17,7 @@ import net.coderbot.iris.pipeline.newshader.ShaderKey; import net.coderbot.iris.vertices.IrisVertexFormats; import net.irisshaders.iris.api.v0.IrisApi; +import net.minecraft.client.CloudStatus; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.player.LocalPlayer; @@ -50,6 +51,8 @@ public abstract class MixinCloudRenderer { @Shadow @Final private FogRenderer.FogData fogData; + @Shadow + private CloudStatus cloudRenderMode; @Unique private VertexBuffer vertexBufferWithNormals; @@ -83,9 +86,10 @@ public void renderIris(@Nullable ClientLevel world, LocalPlayer player, PoseStac int centerCellX = (int) (Math.floor(cloudCenterX / 12)); int centerCellZ = (int) (Math.floor(cloudCenterZ / 12)); - if (this.vertexBufferWithNormals == null || this.prevCenterCellXIris != centerCellX || this.prevCenterCellYIris != centerCellZ || this.cachedRenderDistanceIris != renderDistance) { + if (this.vertexBufferWithNormals == null || this.prevCenterCellXIris != centerCellX || this.prevCenterCellYIris != centerCellZ || this.cachedRenderDistanceIris != renderDistance || this.cloudRenderMode != Minecraft.getInstance().options.getCloudsType()) { BufferBuilder bufferBuilder = Tesselator.getInstance().getBuilder(); bufferBuilder.begin(VertexFormat.Mode.QUADS, IrisVertexFormats.CLOUDS); + this.cloudRenderMode = Minecraft.getInstance().options.getCloudsType(); // Give some space for shaders this.rebuildGeometry(bufferBuilder, cloudDistance + 4, centerCellX, centerCellZ); @@ -124,7 +128,7 @@ public void renderIris(@Nullable ClientLevel world, LocalPlayer player, PoseStac boolean insideClouds = cameraY < cloudHeight + 4.5f && cameraY > cloudHeight - 0.5f; - if (insideClouds) { + if (insideClouds || (cloudRenderMode == CloudStatus.FAST)) { RenderSystem.disableCull(); } else { RenderSystem.enableCull(); diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/font/MixinGlyphRenderer.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/font/MixinGlyphRenderer.java index eb36d14635..eab6105938 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/font/MixinGlyphRenderer.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/font/MixinGlyphRenderer.java @@ -1,6 +1,7 @@ package net.coderbot.iris.compat.sodium.mixin.font; import com.mojang.blaze3d.vertex.VertexConsumer; +import me.jellysquid.mods.sodium.client.render.vertex.VertexConsumerUtils; import net.caffeinemc.mods.sodium.api.util.ColorABGR; import net.caffeinemc.mods.sodium.api.vertex.buffer.VertexBufferWriter; import net.caffeinemc.mods.sodium.api.vertex.format.common.GlyphVertex; @@ -15,6 +16,9 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(BakedGlyph.class) public class MixinGlyphRenderer { @@ -54,8 +58,16 @@ public class MixinGlyphRenderer { * @reason Use intrinsics * @author JellySquid */ - @Overwrite - public void render(boolean italic, float x, float y, Matrix4f matrix, VertexConsumer vertexConsumer, float red, float green, float blue, float alpha, int light) { + @Inject(method = "render", at = @At("HEAD"), cancellable = true) + public void render(boolean italic, float x, float y, Matrix4f matrix, VertexConsumer vertexConsumer, float red, float green, float blue, float alpha, int light, CallbackInfo ci) { + var writer = VertexConsumerUtils.convertOrLog(vertexConsumer); + + if (writer == null) { + return; + } + + ci.cancel(); + float x1 = x + this.left; float x2 = x + this.right; float y1 = this.up - 3.0F; @@ -67,8 +79,6 @@ public void render(boolean italic, float x, float y, Matrix4f matrix, VertexCons int color = ColorABGR.pack(red, green, blue, alpha); - var writer = VertexBufferWriter.of(vertexConsumer); - boolean ext = extend(); int stride = ext ? GlyphVertexExt.STRIDE : GlyphVertex.STRIDE; try (MemoryStack stack = MemoryStack.stackPush()) { From c4fed7fdd56cd7b02460e6993079826ebc96746f Mon Sep 17 00:00:00 2001 From: IMS212 Date: Sun, 28 Jan 2024 18:11:56 -0800 Subject: [PATCH 56/56] Test --- buildscript/src/main/java/Buildscript.java | 4 ++-- src/main/resources/fabric.mod.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/buildscript/src/main/java/Buildscript.java b/buildscript/src/main/java/Buildscript.java index 7b65d16927..8ef4936fdd 100644 --- a/buildscript/src/main/java/Buildscript.java +++ b/buildscript/src/main/java/Buildscript.java @@ -114,10 +114,10 @@ public void getModDependencies(ModDependencyCollector d) { if (CUSTOM_SODIUM) { d.add(new JavaJarDependency(getProjectDir().resolve("custom_sodium").resolve(customSodiumName).toAbsolutePath(), null, new MavenId("me.jellysquid.mods", "sodium-fabric", customSodiumName.replace("sodium-fabric-", ""))), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); } else { - d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "sodium", "mc1.20.3-0.5.6"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); + d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "sodium", "mc1.20.3-0.5.7"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); } } else { - d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "sodium", "mc1.20.3-0.5.6"), ModDependencyFlag.COMPILE); + d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "sodium", "mc1.20.3-0.5.7"), ModDependencyFlag.COMPILE); } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 1cdb2af8ed..5a4bfe25b0 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -46,7 +46,7 @@ "depends": { "fabricloader": ">=0.12.3", "minecraft": ["1.20.3", "1.20.4"], - "sodium": "0.5.6" + "sodium": "0.5.7" }, "breaks": {