From 0e47ca12f589b71293df4aa2c49b24a9c8b02033 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Mon, 11 Sep 2023 10:01:48 -0700 Subject: [PATCH 01/27] 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/27] 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/27] 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/27] 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/27] 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/27] 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/27] 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/27] 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/27] 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/27] 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/27] 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/27] 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/27] 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/27] 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/27] 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/27] 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/27] 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/27] 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/27] 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/27] 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/27] 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/27] 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/27] 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/27] 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/27] 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/27] 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 da9011df971502e8526ec164d754c1994dd71c1a Mon Sep 17 00:00:00 2001 From: IMS212 Date: Wed, 20 Dec 2023 18:16:19 -0800 Subject: [PATCH 27/27] 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;